Java Examples for android.support.test.espresso.action.Swipe

The following java examples will help you to understand the usage of android.support.test.espresso.action.Swipe. These source code samples are taken from different open source projects.

Example 1
Project: platform_frameworks_support-master  File: DrawerLayoutTest.java View source code
@Test
@MediumTest
public void testDrawerOpenCloseViaSwipes() {
    assertFalse("Initial state", mDrawerLayout.isDrawerOpen(GravityCompat.START));
    // open / close state. This is done in DrawerLayoutActions.wrap method.
    for (int i = 0; i < 5; i++) {
        onView(withId(R.id.drawer_layout)).perform(wrap(new GeneralSwipeAction(Swipe.FAST, GeneralLocation.CENTER_LEFT, GeneralLocation.CENTER_RIGHT, Press.FINGER)));
        assertTrue("Opened drawer #" + i, mDrawerLayout.isDrawerOpen(GravityCompat.START));
        onView(withId(R.id.drawer_layout)).perform(wrap(new GeneralSwipeAction(Swipe.FAST, GeneralLocation.CENTER_RIGHT, GeneralLocation.CENTER_LEFT, Press.FINGER)));
        assertFalse("Closed drawer #" + i, mDrawerLayout.isDrawerOpen(GravityCompat.START));
    }
}
Example 2
Project: orgzly-android-master  File: NewNoteTest.java View source code
@Test
public void testNewNoteFromQuickMenuWhenCabIsDisplayed() {
    shelfTestUtils.setupBook("booky", "Booky Preface\n* 1\n** 2\n*** 3\n*** 4\n** 5\n* 6");
    activityRule.launchActivity(null);
    onView(allOf(withText("booky"), isDisplayed())).perform(click());
    onView(withId(R.id.action_context_bar)).check(matches(not(isDisplayed())));
    onListItem(2).perform(longClick());
    /* Swipe left. */
    onListItem(2).perform(new GeneralSwipeAction(Swipe.FAST, GeneralLocation.CENTER, GeneralLocation.CENTER_LEFT, Press.FINGER));
    onView(withId(R.id.action_context_bar)).check(matches(isDisplayed()));
    onListItem(2).onChildView(withId(R.id.item_menu_new_under_btn)).perform(click());
    onView(withId(R.id.fragment_note_title)).check(matches(isDisplayed()));
    onView(withId(R.id.done)).check(matches(isDisplayed()));
    onView(withId(R.id.action_context_bar)).check(matches(not(isDisplayed())));
}
Example 3
Project: CompactCalendarView-master  File: ApplicationTest.java View source code
public ViewAction scroll(final int startX, final int startY, final int endX, final int endY) {
    final DisplayMetrics dm = activity.getResources().getDisplayMetrics();
    final float spStartX = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, startX, dm);
    final float spStartY = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, startY, dm);
    final float spEndX = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, endX, dm);
    final float spEndY = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, endY, dm);
    return new GeneralSwipeAction(Swipe.FAST, new CoordinatesProvider() {

        @Override
        public float[] calculateCoordinates(View view) {
            final int[] screenPos = new int[2];
            view.getLocationOnScreen(screenPos);
            final float screenX = screenPos[0] + spStartX;
            final float screenY = screenPos[1] + spStartY;
            float[] coordinates = { screenX, screenY };
            return coordinates;
        }
    }, new CoordinatesProvider() {

        @Override
        public float[] calculateCoordinates(View view) {
            final int[] screenPos = new int[2];
            view.getLocationOnScreen(screenPos);
            final float screenX = screenPos[0] + spEndX;
            final float screenY = screenPos[1] + spEndY;
            float[] coordinates = { screenX, screenY };
            return coordinates;
        }
    }, Press.FINGER);
}
Example 4
Project: material-components-android-master  File: BottomSheetBehaviorTest.java View source code
@Test
@MediumTest
public void testSwipeDownToCollapse() throws Throwable {
    checkSetState(BottomSheetBehavior.STATE_EXPANDED, ViewMatchers.isDisplayed());
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)).perform(DesignViewActions.withCustomConstraints(new GeneralSwipeAction(Swipe.FAST, // actually falls onto the view on Gingerbread
    new CoordinatesProvider() {

        @Override
        public float[] calculateCoordinates(View view) {
            int[] location = new int[2];
            view.getLocationInWindow(location);
            return new float[] { view.getWidth() / 2, location[1] + 1 };
        }
    }, // sheet is collapsed, not hidden
    new CoordinatesProvider() {

        @Override
        public float[] calculateCoordinates(View view) {
            BottomSheetBehavior behavior = getBehavior();
            return new float[] { // x: center of the bottom sheet
            view.getWidth() / 2, // y: just above the peek height
            view.getHeight() - behavior.getPeekHeight() };
        }
    }, Press.FINGER), ViewMatchers.isDisplayingAtLeast(5)));
    registerIdlingResourceCallback();
    try {
        Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
        assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
    } finally {
        unregisterIdlingResourceCallback();
    }
}
Example 5
Project: RxBinding-master  File: RxSwipeDismissBehaviorTest.java View source code
private static ViewAction swipeRight() {
    return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.CENTER_LEFT, GeneralLocation.CENTER_RIGHT, Press.FINGER);
}
Example 6
Project: u2020-mvp-master  File: ViewActions.java View source code
public static ViewAction swipeTop() {
    return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.BOTTOM_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER);
}
Example 7
Project: PrettyBundle-master  File: ExtViewActions.java View source code
public static ViewAction swipeTop() {
    return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.BOTTOM_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER);
}
Example 8
Project: BottomNavigation-master  File: Utils.java View source code
/**
     * Returns an action that performs a swipe right-to-left across the vertical center of the
     * view. The swipe doesn't start at the very edge of the view, but is a bit offset.<br>
     * <br>
     * View constraints:
     * <ul>
     * <li>must be displayed on screen
     * <ul>
     */
public static ViewAction swipeLeftSlow() {
    return actionWithAssertions(new GeneralSwipeAction(Swipe.SLOW, translate(GeneralLocation.CENTER_RIGHT, -EDGE_FUZZ_FACTOR, 0), GeneralLocation.CENTER_LEFT, Press.FINGER));
}
Example 9
Project: agera-master  File: MainActivityTest.java View source code
private static ViewAction swipeDown() {
    return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.TOP_CENTER, GeneralLocation.BOTTOM_CENTER, Press.FINGER);
}