Java 类android.support.test.espresso.ViewAction 实例源码

项目:fullscreen-video-view    文件:CustomChecks.java   
static ViewAction clickNoConstraints() {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isEnabled(); // No constraints, isEnabled and isClickable are checked
        }

        @Override
        public String getDescription() {
            return "Click a view with no constraints.";
        }

        @Override
        public void perform(UiController uiController, View view) {
            view.performClick();
        }
    };
}
项目:starwarsshop    文件:MyViewAction.java   
public static ViewAction clickChildViewWithId(final int id) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return null;
        }

        @Override
        public String getDescription() {
            return "Click on a child view with specified id.";
        }

        @Override
        public void perform(UiController uiController, View view) {
            View v = view.findViewById(id);
            v.performClick();
        }
    };
}
项目:GitHub    文件:StartupTest.java   
public static ViewAction closeSoftKeyboard() {
    return new ViewAction() {
        /**
         * The real {@link CloseKeyboardAction} instance.
         */
        private final ViewAction mCloseSoftKeyboard = new CloseKeyboardAction();

        @Override
        public Matcher<View> getConstraints() {
            return mCloseSoftKeyboard.getConstraints();
        }

        @Override
        public String getDescription() {
            return mCloseSoftKeyboard.getDescription();
        }

        @Override
        public void perform(final UiController uiController, final View view) {
            mCloseSoftKeyboard.perform(uiController, view);
            uiController.loopMainThreadForAtLeast(KEYBOARD_DISMISSAL_DELAY_MILLIS);
        }
    };
}
项目:GitHub    文件:StartupTest.java   
public static ViewAction loopMainThreadFor(final long millis) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isEnabled();
        }

        @Override
        public String getDescription() {
            return "Rturns an action that loops the main thread for at least " + millis +"ms.";
        }

        @Override
        public void perform(final UiController uiController, final View view) {
            uiController.loopMainThreadForAtLeast(millis);
        }
    };
}
项目:GitHub    文件:PubkeyListActivityTest.java   
private ViewAction fillEntropy() {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return allOf(isDisplayed(), isAssignableFrom(EntropyView.class));
        }

        @Override
        public String getDescription() {
            return "Dismisses the 'Gathering entropy...' dialog";
        }

        @Override
        public void perform(final UiController uiController, final View view) {
            ((EntropyView) view).notifyListeners();
        }
    };
}
项目:espresso-commons    文件:RecyclerViewUtils.java   
/**
 * Returns an action that clicks a descendant of the view matched with the given resource id.
 *
 * @param id resource id of the view to click.
 * @return an action that clicks a descendant of the view matched with the given resource id.
 */
public static ViewAction clickDescendantViewWithId(@IdRes final int id) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return hasDescendant(withId(id));
        }

        @Override
        public String getDescription() {
            return "Click on a descendant view with id: " + id;
        }

        @Override
        public void perform(UiController uiController, View view) {
            GeneralClickAction action = new GeneralClickAction(Tap.SINGLE, GeneralLocation.VISIBLE_CENTER, Press.FINGER);
            View target = view.findViewById(id);
            // getConstraints() guarantees that the target never be null.
            action.perform(uiController, target);
        }
    };
}
项目:android-PictureInPicture    文件:MediaSessionPlaybackActivityTest.java   
private static ViewAction showControls() {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(MovieView.class);
        }

        @Override
        public String getDescription() {
            return "Show controls of MovieView";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            ((MovieView) view).showControls();
            uiController.loopMainThreadUntilIdle();
        }
    };
}
项目:android-PictureInPicture    文件:MainActivityTest.java   
private static ViewAction showControls() {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(MovieView.class);
        }

        @Override
        public String getDescription() {
            return "Show controls of MovieView";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            ((MovieView) view).showControls();
            uiController.loopMainThreadUntilIdle();
        }
    };
}
项目:DiscogsBrowser    文件:TestUtils.java   
/**
 * From: http://stackoverflow.com/questions/33505953/espresso-how-to-test-swiperefreshlayout/33516360#33516360
 * <p>
 * ViewPager will throw an error if not 90% of it is displayed. This reduces the restriction.
 *
 * @param action      Action to be done.
 * @param constraints Restrictions on the view.
 * @return Performs an action on the view.
 */
public static ViewAction withCustomConstraints(final ViewAction action, final Matcher<View> constraints)
{
    return new ViewAction()
    {
        @Override
        public Matcher<View> getConstraints()
        {
            return constraints;
        }

        @Override
        public String getDescription()
        {
            return action.getDescription();
        }

        @Override
        public void perform(UiController uiController, View view)
        {
            action.perform(uiController, view);
        }
    };
}
项目:fullscreen-video-view    文件:CustomChecks.java   
static ViewAction setOrientation(final int orientation) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isRoot();
        }

        @Override
        public String getDescription() {
            return "Change orientation";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            changeOrientation(view, orientation);
        }
    };
}
项目:PXLSRT    文件:CameraViewActions.java   
static ViewAction setAspectRatio(@NonNull final AspectRatio ratio) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(CameraView.class);
        }

        @Override
        public String getDescription() {
            return "Set aspect ratio to " + ratio;
        }

        @Override
        public void perform(UiController controller, View view) {
            ((CameraView) view).setAspectRatio(ratio);
        }
    };
}
项目:ChimpCheck    文件:FingerGestures.java   
public static ViewAction swipeOnCoord(final float fromX, final float fromY, final float toX, final float toY) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isRoot();
        }

        @Override
        public String getDescription() {

            return "Swipe from" + fromX + ", " + fromY + " to " + toX + ", " + toY;
        }

        @Override
        public void perform(UiController uiController, final View view) {
            drag(fromX, fromY, toX, toY);
        }
    };
}
项目:ommvplib    文件:TestHelper.java   
public static ViewAction waitFor(final long millis) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isRoot();
        }

        @Override
        public String getDescription() {
            return "Wait for " + millis + " milliseconds.";
        }

        @Override
        public void perform(UiController uiController, final View view) {
            uiController.loopMainThreadForAtLeast(millis);
        }
    };
}
项目:polling-station-app    文件:TestMainActivity.java   
/**
 * Test if the manual input activity opens.
 */
@Test
public void testGoToManual() {
    onView(withId(R.id.manual_input_button)).check(matches(allOf( isEnabled(), isClickable()))).perform(
            new ViewAction() {
                @Override
                public Matcher<View> getConstraints() {
                    return isEnabled(); // no constraints, they are checked above
                }

                @Override
                public String getDescription() {
                    return "click manual input button";
                }

                @Override
                public void perform(UiController uiController, View view) {
                    view.performClick();
                }
            }
    );
    intended(hasComponent(ManualInputActivity.class.getName()));
}
项目:orgzly-android    文件:EspressoUtils.java   
/**
 * Set value for {@link NumberPicker}
 */
public static ViewAction setNumber(final int n) {
    return new ViewAction() {
        @Override
        public void perform(UiController uiController, View view) {
            ((NumberPicker) view).setValue(n);
        }

        @Override
        public String getDescription() {
            return "Set NumberPicker value";
        }

        @Override
        public Matcher<View> getConstraints() {
            return ViewMatchers.isAssignableFrom(NumberPicker.class);
        }
    };
}
项目:ChipsLayoutManager    文件:ColumnTest.java   
@Test
public synchronized void smoothScrollToPosition_ScrollItemIsNotVisible_FirstVisiblePositionsEqualsScrollingTarget() throws Exception {
    //arrange
    InstrumentalUtil.waitForIdle();

    //act
    ViewAction scrollAction = smoothScrollToPosition(18);
    //noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (scrollAction) {
        recyclerView.perform(scrollAction);
        //wait for completion of SmoothScrollAction
        scrollAction.wait();
    }

    //assert
    int actual = layoutManager.findFirstCompletelyVisibleItemPosition();
    assertEquals(18, actual);
}
项目:ChipsLayoutManager    文件:ColumnTest.java   
@Test
public synchronized void smoothScrollToPosition_ScrollItemIsVisible_ScrollItemDockedToStartBorder() throws Exception {
    //arrange
    InstrumentalUtil.waitForIdle();

    //act
    ViewAction scrollAction = smoothScrollToPosition(3);
    //noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (scrollAction) {
        recyclerView.perform(scrollAction);
        //wait for completion of SmoothScrollAction
        scrollAction.wait();
    }

    //assert
    int actual = layoutManager.findFirstCompletelyVisibleItemPosition();
    assertEquals(3, actual);
}
项目:ChipsLayoutManager    文件:RowTest.java   
@Test
public synchronized void smoothScrollToPosition_LMInInitialState_FirstVisiblePositionsEqualsScrollingTarget() throws Exception {
    //arrange
    InstrumentalUtil.waitForIdle();

    //act
    ViewAction scrollAction = smoothScrollToPosition(8);
    //noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (scrollAction) {
        recyclerView.perform(scrollAction);
        //wait for completion of SmoothScrollAction
        scrollAction.wait();
    }

    //assert
    int actual = layoutManager.findFirstCompletelyVisibleItemPosition();
    assertEquals(8, actual);
}
项目:espresso-sample-for-droidkaigi2017    文件:RecyclerViewUtils.java   
/**
 * Returns an action that clicks a descendant of the view matched with the given resource id.
 */
public static ViewAction clickDescendantViewWithId(@IdRes final int id) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return hasDescendant(withId(id));
        }

        @Override
        public String getDescription() {
            return "Click on a descendant view with id: " + id;
        }

        @Override
        public void perform(UiController uiController, View view) {
            GeneralClickAction action = new GeneralClickAction(Tap.SINGLE, GeneralLocation.VISIBLE_CENTER, Press.FINGER);
            View target = view.findViewById(id);
            // getConstraints() guarantees that the target never be null.
            action.perform(uiController, target);
        }
    };
}
项目:Ristretto    文件:OnViewAllOfWithIsDisplayedNoImport.java   
public void fooAllOf() {
    Espresso.onView(AllOf.allOf(ViewMatchers.withId(R.id.some_id), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(AllOf.allOf(ViewMatchers.withText(R.string.some_text), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(AllOf.allOf(ViewMatchers.withText("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(AllOf.allOf(RistrettoViewMatchers.with("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(AllOf.allOf(ViewMatchers.withId(R.id.some_id), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(AllOf.allOf(ViewMatchers.withText(R.string.some_text), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(AllOf.allOf(ViewMatchers.withText("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(AllOf.allOf(RistrettoViewMatchers.with("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());

    Espresso.onView(AllOf.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.some_id))).perform(ViewAction.click());
    Espresso.onView(AllOf.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText(R.string.some_text))).perform(ViewAction.click());
    Espresso.onView(AllOf.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText("some text"))).perform(ViewAction.click());
    Espresso.onView(AllOf.allOf(ViewMatchers.isDisplayed(), RistrettoViewMatchers.with("some text"))).perform(ViewAction.click());
    Ristretto.withView(AllOf.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.some_id))).perform(ViewAction.click());
    Ristretto.withView(AllOf.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText(R.string.some_text))).perform(ViewAction.click());
    Ristretto.withView(AllOf.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText("some text"))).perform(ViewAction.click());
    Ristretto.withView(AllOf.allOf(ViewMatchers.isDisplayed(), RistrettoViewMatchers.with("some text"))).perform(ViewAction.click());
}
项目:Ristretto    文件:OnViewAllOfWithIsDisplayedNoImport.java   
public void fooMatchers() {
    Espresso.onView(Matchers.allOf(ViewMatchers.withId(R.id.some_id), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(Matchers.allOf(ViewMatchers.withText(R.string.some_text), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(Matchers.allOf(ViewMatchers.withText("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(Matchers.allOf(RistrettoViewMatchers.with("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.withId(R.id.some_id), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.withText(R.string.some_text), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.withText("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(RistrettoViewMatchers.with("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());

    Espresso.onView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.some_id))).perform(ViewAction.click());
    Espresso.onView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText(R.string.some_text))).perform(ViewAction.click());
    Espresso.onView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText("some text"))).perform(ViewAction.click());
    Espresso.onView(Matchers.allOf(ViewMatchers.isDisplayed(), RistrettoViewMatchers.with("some text"))).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.some_id))).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText(R.string.some_text))).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText("some text"))).perform(ViewAction.click());
    Ristretto.withView(Matchers.allOf(ViewMatchers.isDisplayed(), RistrettoViewMatchers.with("some text"))).perform(ViewAction.click());
}
项目:Ristretto    文件:OnViewAllOfWithIsDisplayedNoImport.java   
public void fooCoreMatchers() {
    Espresso.onView(CoreMatchers.allOf(ViewMatchers.withId(R.id.some_id), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(CoreMatchers.allOf(ViewMatchers.withText(R.string.some_text), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(CoreMatchers.allOf(ViewMatchers.withText("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Espresso.onView(CoreMatchers.allOf(RistrettoViewMatchers.with("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(CoreMatchers.allOf(ViewMatchers.withId(R.id.some_id), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(CoreMatchers.allOf(ViewMatchers.withText(R.string.some_text), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(CoreMatchers.allOf(ViewMatchers.withText("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());
    Ristretto.withView(CoreMatchers.allOf(RistrettoViewMatchers.with("some text"), ViewMatchers.isDisplayed())).perform(ViewAction.click());

    Espresso.onView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.some_id))).perform(ViewAction.click());
    Espresso.onView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText(R.string.some_text))).perform(ViewAction.click());
    Espresso.onView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText("some text"))).perform(ViewAction.click());
    Espresso.onView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), RistrettoViewMatchers.with("some text"))).perform(ViewAction.click());
    Ristretto.withView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withId(R.id.some_id))).perform(ViewAction.click());
    Ristretto.withView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText(R.string.some_text))).perform(ViewAction.click());
    Ristretto.withView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), ViewMatchers.withText("some text"))).perform(ViewAction.click());
    Ristretto.withView(CoreMatchers.allOf(ViewMatchers.isDisplayed(), RistrettoViewMatchers.with("some text"))).perform(ViewAction.click());
}
项目:Mixtape    文件:RecyclerBodyViewViewActions.java   
public static ViewAction scrollToStart() {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(RecyclerBodyView.class);
        }

        @Override
        public String getDescription() {
            return "scroll to start";
        }

        @Override
        public void perform(final UiController uiController, final View view) {
            ((RecyclerBodyView) view).showItem(0);
        }
    };
}
项目:Mixtape    文件:RecyclerBodyViewViewActions.java   
public static ViewAction scrollToEnd() {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(RecyclerBodyView.class);
        }

        @Override
        public String getDescription() {
            return "scroll to end";
        }

        @Override
        public void perform(final UiController uiController, final View view) {
            final RecyclerBodyView castView = (RecyclerBodyView) view;
            castView.showItem(castView.getItems().size() - 1);
        }
    };
}
项目:EncryptAndroidSample    文件:ExampleInstrumentedTest.java   
/**
 * Try to getText from TextView
 */
private String getText(final Matcher<View> matcher) {
    final String[] stringHolder = { null };
    onView(matcher).perform(new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(TextView.class);
        }

        @Override
        public String getDescription() {
            return "getting text from a TextView";
        }

        @Override
        public void perform(UiController uiController, View view) {
            TextView tv = (TextView) view;
            stringHolder[0] = tv.getText().toString();
        }
    });
    return stringHolder[0];
}
项目:firefox-tv    文件:PullDownToRefreshTest.java   
public static ViewAction withCustomConstraints(final ViewAction action, final Matcher<View> constraints) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return constraints;
        }

        @Override
        public String getDescription() {
            return action.getDescription();
        }

        @Override
        public void perform(UiController uiController, View view) {
            action.perform(uiController, view);
        }
    };
}
项目:espresso-doppio    文件:DoppioActions.java   
/**
 * Action that does nothing
 * <p/>
 * Useful for waiting for idle sync. In some cases waiting for IdlingResource to be idle is
 * crucial for some sync code execution, for example assertions.
 * <p/>
 * Usage:
 * //register desired IdlingResource
 * onView(withText("Yes")).perform(DoppioActions.noAction()); //espresso will stay here until idle
 *
 * @return new ViewAction that does nothing
 */
public static ViewAction noAction() {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return Matchers.any(View.class);
        }

        @Override
        public String getDescription() {
            return "Performs no action, just to satisfy idling resources";
        }

        @Override
        public void perform(UiController uiController, View view) {

        }
    };
}
项目:material-components-android    文件:TextInputLayoutActions.java   
public static ViewAction setCounterEnabled(final boolean enabled) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Sets the counter enabled";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setCounterEnabled(enabled);
    }
  };
}
项目:device-info    文件:EspressoUtils.java   
public static ViewAction checkAttributionView(String library, String author, String description, String license) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return null;
        }

        @Override
        public String getDescription() {
            return null;
        }

        @Override
        public void perform(UiController uiController, View view) {
            TextView txtLibrary = ButterKnife.findById(view, R.id.txt_attribution_library);
            TextView txtAuthor = ButterKnife.findById(view, R.id.txt_attribution_author);
            TextView txtDescription = ButterKnife.findById(view, R.id.txt_attribution_description);
            TextView txtLicense = ButterKnife.findById(view, R.id.txt_attribution_license);

            assertThat(txtLibrary).containsText(library);
            assertThat(txtAuthor).containsText(author);
            assertThat(txtDescription).containsText(description);
            assertThat(txtLicense).containsText(license);
        }
    };
}
项目:material-components-android    文件:ViewPagerActions.java   
/** Moves <code>ViewPager</code> to specific page. */
public static ViewAction scrollToPage(final int page) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isDisplayingAtLeast(90);
    }

    @Override
    public String getDescription() {
      return "ViewPager move to a specific page";
    }

    @Override
    public void perform(UiController uiController, View view) {
      uiController.loopMainThreadUntilIdle();

      ViewPager viewPager = (ViewPager) view;
      viewPager.setCurrentItem(page, false);

      uiController.loopMainThreadUntilIdle();
    }
  };
}
项目:material-components-android    文件:TextInputLayoutActions.java   
public static ViewAction setHelperTextTextAppearance(final int resId) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Sets the helper text appearance";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setHelperTextTextAppearance(resId);
    }
  };
}
项目:nuclei-android    文件:OffsetAdapterTests2.java   
public static ViewAction scrollToPosition(final int position) {
    return new ViewAction() {
        @SuppressWarnings("unchecked")
        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(RecyclerView.class);
        }

        @Override
        public void perform(UiController uiController, View view) {
            ((RecyclerView) view).scrollToPosition(position);
        }

        @Override
        public String getDescription() {
            return "scroll to";
        }
    };
}
项目:cameraview    文件:CameraViewActions.java   
static ViewAction setAspectRatio(@NonNull final AspectRatio ratio) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(CameraView.class);
        }

        @Override
        public String getDescription() {
            return "Set aspect ratio to " + ratio;
        }

        @Override
        public void perform(UiController controller, View view) {
            ((CameraView) view).setAspectRatio(ratio);
        }
    };
}
项目:bigbang    文件:ViewActions.java   
public static ViewAction withCustomConstraints(final ViewAction action, final Matcher<View> constraints) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return constraints;
    }

    @Override
    public String getDescription() {
      return action.getDescription();
    }

    @Override
    public void perform(UiController uiController, View view) {
      action.perform(uiController, view);
    }
  };
}
项目:bigbang    文件:MaterialPickerDialogActions.java   
public static ViewAction setTime(final int hours, final int minutes) {
  return new ViewAction() {
    @Override
    public void perform(UiController uiController, View view) {
      final RadialPickerLayout timePicker = (RadialPickerLayout) view;

      timePicker.setTime(new Timepoint(hours, minutes, 0));
    }

    @Override
    public String getDescription() {
      return "set time";
    }

    @Override
    public Matcher<View> getConstraints() {
      return allOf(isAssignableFrom(RadialPickerLayout.class), isDisplayed());
    }
  };
}
项目:material-components-android    文件:TextInputLayoutActions.java   
public static ViewAction setErrorEnabled(final boolean enabled) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Enables/disables the error";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setErrorEnabled(enabled);
    }
  };
}
项目:material-components-android    文件:TextInputLayoutActions.java   
public static ViewAction setBoxBackgroundColor(@ColorInt final int backgroundColor) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(TextInputLayout.class);
    }

    @Override
    public String getDescription() {
      return "Sets the box's background color";
    }

    @Override
    public void perform(UiController uiController, View view) {
      TextInputLayout layout = (TextInputLayout) view;
      layout.setBoxBackgroundColor(backgroundColor);
    }
  };
}
项目:Voluminotes-App    文件:MainActivityTest.java   
private static ViewAction actionOpenDrawer() {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(DrawerLayout.class);
        }

        @Override
        public String getDescription() {
            return "open drawer";
        }

        @Override
        public void perform(UiController uiController, View view) {
            ((DrawerLayout) view).openDrawer(GravityCompat.START);
        }
    };
}
项目:sunny-reader    文件:ViewActionUtils.java   
public static ViewAction withCustomConstraints(final ViewAction action, final Matcher<View> constraints) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return constraints;
        }

        @Override
        public String getDescription() {
            return action.getDescription();
        }

        @Override
        public void perform(UiController uiController, View view) {
            action.perform(uiController, view);
        }
    };
}
项目:SmoothClicker    文件:ItSelectMultiPointsActivity.java   
/**
 * Custom ViewAction to click on dedicated coordinates
 * @param x -
 * @param y -
 * @return ViewAction -
 */
private ViewAction clickXY( final int x, final int y ){
    return new GeneralClickAction(
            Tap.SINGLE,
            new CoordinatesProvider() {
                @Override
                public float[] calculateCoordinates( View view ){

                    final int[] screenPos = new int[2];
                    view.getLocationOnScreen(screenPos);

                    final float screenX = screenPos[0] + x;
                    final float screenY = screenPos[1] + y;

                    return new float[]{screenX, screenY};

                }
            },
            Press.FINGER);
}