本文整理汇总了Java中android.support.test.espresso.ViewAction类的典型用法代码示例。如果您正苦于以下问题:Java ViewAction类的具体用法?Java ViewAction怎么用?Java ViewAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ViewAction类属于android.support.test.espresso包,在下文中一共展示了ViewAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clickNoConstraints
import android.support.test.espresso.ViewAction; //导入依赖的package包/类
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();
}
};
}
示例2: clickChildViewWithId
import android.support.test.espresso.ViewAction; //导入依赖的package包/类
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();
}
};
}
示例3: closeSoftKeyboard
import android.support.test.espresso.ViewAction; //导入依赖的package包/类
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);
}
};
}
示例4: loopMainThreadFor
import android.support.test.espresso.ViewAction; //导入依赖的package包/类
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);
}
};
}
示例5: fillEntropy
import android.support.test.espresso.ViewAction; //导入依赖的package包/类
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();
}
};
}
示例6: clickDescendantViewWithId
import android.support.test.espresso.ViewAction; //导入依赖的package包/类
/**
* 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);
}
};
}
示例7: showControls
import android.support.test.espresso.ViewAction; //导入依赖的package包/类
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();
}
};
}
开发者ID:googlesamples,项目名称:android-PictureInPicture,代码行数:21,代码来源:MediaSessionPlaybackActivityTest.java
示例8: withCustomConstraints
import android.support.test.espresso.ViewAction; //导入依赖的package包/类
/**
* 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);
}
};
}
示例9: setOrientation
import android.support.test.espresso.ViewAction; //导入依赖的package包/类
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);
}
};
}
示例10: setAspectRatio
import android.support.test.espresso.ViewAction; //导入依赖的package包/类
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);
}
};
}
示例11: swipeOnCoord
import android.support.test.espresso.ViewAction; //导入依赖的package包/类
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);
}
};
}
示例12: waitFor
import android.support.test.espresso.ViewAction; //导入依赖的package包/类
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);
}
};
}
示例13: testGoToManual
import android.support.test.espresso.ViewAction; //导入依赖的package包/类
/**
* 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()));
}
示例14: setNumber
import android.support.test.espresso.ViewAction; //导入依赖的package包/类
/**
* 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);
}
};
}
示例15: smoothScrollToPosition_ScrollItemIsNotVisible_FirstVisiblePositionsEqualsScrollingTarget
import android.support.test.espresso.ViewAction; //导入依赖的package包/类
@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);
}