androidx.test.espresso.action.Press Java Examples

The following examples show how to use androidx.test.espresso.action.Press. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestUtilities.java    From google-authenticator-android with Apache License 2.0 6 votes vote down vote up
public static int dragViewToX(View v, int gravity, int toX) {

    if (gravity != Gravity.CENTER) {
      throw new IllegalArgumentException("Can only handle Gravity.CENTER.");
    }
    Point point = getCenterOfViewOnScreen(v);

    final int fromX = point.x;
    final int fromY = point.y;

    int deltaX = Math.abs(fromX - toX);

    onView(equalTo(v))
        .perform(
            new GeneralSwipeAction(
                Swipe.SLOW,
                (view) -> {
                  return new float[] {fromX, fromY};
                },
                (view) -> {
                  return new float[] {toX, fromY};
                },
                Press.FINGER));

    return deltaX;
  }
 
Example #2
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Test
@MediumTest
public void testSwipeUpToExpand() {
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  GeneralLocation.VISIBLE_CENTER,
                  view -> new float[] {view.getWidth() / 2, 0},
                  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_EXPANDED));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example #3
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Test
@MediumTest
public void testNoSwipeUpToExpand() {
  getBehavior().setDraggable(false);
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  GeneralLocation.VISIBLE_CENTER,
                  view -> new float[] {view.getWidth() / 2, 0},
                  Press.FINGER),
              ViewMatchers.isDisplayingAtLeast(5)));

  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
  assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
}
 
Example #4
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Test
@MediumTest
public void testNoDragging() {
  getBehavior().setDraggable(false);
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      // Drag (and not release)
      .perform(
          new DragAction(
              GeneralLocation.VISIBLE_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER))
      // Check that the bottom sheet is NOT in STATE_DRAGGING
      .check(
          (view, e) -> {
            assertThat(view, is(ViewMatchers.isDisplayed()));
            BottomSheetBehavior<?> behavior = BottomSheetBehavior.from(view);
            assertThat(behavior.getState(), not(is(BottomSheetBehavior.STATE_DRAGGING)));
          });
}
 
Example #5
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Test
@MediumTest
public void testHalfExpandedToExpanded() throws Throwable {
  getBehavior().setFitToContents(false);
  checkSetState(BottomSheetBehavior.STATE_HALF_EXPANDED, ViewMatchers.isDisplayed());
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  GeneralLocation.VISIBLE_CENTER,
                  view -> new float[] {view.getWidth() / 2, 0},
                  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_EXPANDED));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example #6
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Test
@MediumTest
public void testCollapsedToExpanded() throws Throwable {
  getBehavior().setFitToContents(false);
  checkSetState(BottomSheetBehavior.STATE_COLLAPSED, ViewMatchers.isDisplayed());
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  GeneralLocation.VISIBLE_CENTER,
                  view -> new float[] {view.getWidth() / 2, 0},
                  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_EXPANDED));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example #7
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Test
@MediumTest
public void testInvisible() throws Throwable {
  // Make the bottomsheet invisible
  activityTestRule.runOnUiThread(
      () -> {
        getBottomSheet().setVisibility(View.INVISIBLE);
        assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
      });
  // Swipe up as if to expand it
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  GeneralLocation.VISIBLE_CENTER,
                  view -> new float[] {view.getWidth() / 2, 0},
                  Press.FINGER),
              not(ViewMatchers.isDisplayed())));
  // Check that the bottom sheet stays the same collapsed state
  activityTestRule.runOnUiThread(
      () -> assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED)));
}
 
Example #8
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Test
@MediumTest
public void testLayoutWhileDragging() {
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      // Drag (and not release)
      .perform(
          new DragAction(
              GeneralLocation.VISIBLE_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER))
      // Check that the bottom sheet is in STATE_DRAGGING
      .check(
          (view, e) -> {
            assertThat(view, is(ViewMatchers.isDisplayed()));
            BottomSheetBehavior<?> behavior = BottomSheetBehavior.from(view);
            assertThat(behavior.getState(), is(BottomSheetBehavior.STATE_DRAGGING));
          })
      // Add a new view
      .perform(new AddViewAction(R.layout.frame_layout))
      // Check that the newly added view is properly laid out
      .check(
          (view, e) -> {
            ViewGroup parent = (ViewGroup) view;
            assertThat(parent.getChildCount(), is(1));
            View child = parent.getChildAt(0);
            assertThat(ViewCompat.isLaidOut(child), is(true));
          });
}
 
Example #9
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Test
@MediumTest
public void testDragOutside() {
  // Swipe up outside of the bottom sheet
  Espresso.onView(ViewMatchers.withId(R.id.coordinator))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  // Just above the bottom sheet
                  view ->
                      new float[] {
                        view.getWidth() / 2, view.getHeight() - getBehavior().getPeekHeight() - 9
                      },
                  // Top of the CoordinatorLayout
                  view -> new float[] {view.getWidth() / 2, 1},
                  Press.FINGER),
              ViewMatchers.isDisplayed()));
  registerIdlingResourceCallback();
  try {
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
        .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    // The bottom sheet should remain collapsed
    assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example #10
Source File: MainActivityTest.java    From kolabnotes-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ClickWithoutDisplayConstraint getLongClickAction() {
    return new ClickWithoutDisplayConstraint(
            Tap.LONG,
            GeneralLocation.CENTER,
            Press.FINGER,
            InputDevice.SOURCE_UNKNOWN,
            MotionEvent.BUTTON_PRIMARY);
}
 
Example #11
Source File: MainActivityTest.java    From kolabnotes-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ClickWithoutDisplayConstraint getClickAction() {
    return new ClickWithoutDisplayConstraint(
            Tap.SINGLE,
            GeneralLocation.VISIBLE_CENTER,
            Press.FINGER,
            InputDevice.SOURCE_UNKNOWN,
            MotionEvent.BUTTON_PRIMARY);
}
 
Example #12
Source File: SwipeUtils.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
public static GeneralSwipeAction swipeDown(
    final int swipeX, final int swipeStartY, final int swipeAmountY) {
  return new GeneralSwipeAction(
      Swipe.SLOW,
      view -> new float[] {swipeX, swipeStartY},
      view -> new float[] {swipeX, swipeStartY + swipeAmountY},
      Press.FINGER);
}
 
Example #13
Source File: SwipeUtils.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
public static GeneralSwipeAction swipeUp(
    final int swipeX, final int swipeStartY, final int swipeAmountY) {
  return new GeneralSwipeAction(
      Swipe.SLOW,
      view -> new float[] {swipeX, swipeStartY},
      view -> new float[] {swipeX, swipeStartY - swipeAmountY},
      Press.FINGER);
}
 
Example #14
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Test
@MediumTest
public void testInvisibleThenVisible() throws Throwable {
  activityTestRule.runOnUiThread(
      () -> {
        // The bottom sheet is initially invisible
        getBottomSheet().setVisibility(View.INVISIBLE);
        // Then it becomes visible when the CoL is touched
        getCoordinatorLayout()
            .setOnTouchListener(
                (view, e) -> {
                  if (e.getAction() == MotionEvent.ACTION_DOWN) {
                    getBottomSheet().setVisibility(View.VISIBLE);
                    return true;
                  }
                  return false;
                });
        assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
      });
  // Drag over the CoL
  Espresso.onView(ViewMatchers.withId(R.id.coordinator))
      // Drag (and not release)
      .perform(
          new DragAction(GeneralLocation.BOTTOM_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER))
      .check(
          (view, e) -> {
            // The bottom sheet should not react to the touch events
            assertThat(getBottomSheet(), is(ViewMatchers.isDisplayed()));
            assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
          });
}
 
Example #15
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Test
@MediumTest
public void testNoSwipeDownToCollapse() throws Throwable {
  checkSetState(BottomSheetBehavior.STATE_EXPANDED, ViewMatchers.isDisplayed());
  getBehavior().setDraggable(false);
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  // Manually calculate the starting coordinates to make sure that the touch
                  // actually falls onto the view on Gingerbread
                  view -> {
                    int[] location = new int[2];
                    view.getLocationInWindow(location);
                    return new float[] {view.getWidth() / 2, location[1] + 1};
                  },
                  // Manually calculate the ending coordinates to make sure that the bottom
                  // sheet is collapsed, not hidden
                  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)));

  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
  assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED));
}
 
Example #16
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@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,
                  // Manually calculate the starting coordinates to make sure that the touch
                  // actually falls onto the view on Gingerbread
                  view -> {
                    int[] location = new int[2];
                    view.getLocationInWindow(location);
                    return new float[] {view.getWidth() / 2, location[1] + 1};
                  },
                  // Manually calculate the ending coordinates to make sure that the bottom
                  // sheet is collapsed, not hidden
                  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 #17
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@Test
@MediumTest
public void testNestedScroll() throws Throwable {
  final ViewGroup bottomSheet = getBottomSheet();
  final BottomSheetBehavior<?> behavior = getBehavior();
  final NestedScrollView scroll = new NestedScrollView(activityTestRule.getActivity());
  // Set up nested scrolling area
  activityTestRule.runOnUiThread(
      () -> {
        bottomSheet.addView(
            scroll,
            new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        View view = new View(activityTestRule.getActivity());
        // Make sure that the NestedScrollView is always scrollable
        view.setMinimumHeight(bottomSheet.getHeight() + 1000);
        scroll.addView(view);

        assertThat(behavior.getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
        // The scroll offset is 0 at first
        assertThat(scroll.getScrollY(), is(0));
      });
  // Swipe from the very bottom of the bottom sheet to the top edge of the screen so that the
  // scrolling content is also scrolled
  Espresso.onView(ViewMatchers.withId(R.id.coordinator))
      .perform(
          new GeneralSwipeAction(
              Swipe.SLOW,
              view -> new float[] {view.getWidth() / 2, view.getHeight() - 1},
              view -> new float[] {view.getWidth() / 2, 1},
              Press.FINGER));
  registerIdlingResourceCallback();
  try {
    Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
        .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    activityTestRule.runOnUiThread(
        () -> {
          assertThat(behavior.getState(), is(BottomSheetBehavior.STATE_EXPANDED));
          // This confirms that the nested scrolling area was scrolled continuously after
          // the bottom sheet is expanded.
          assertThat(scroll.getScrollY(), is(not(0)));
        });
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example #18
Source File: ViewActions.java    From Kore with Apache License 2.0 4 votes vote down vote up
public static ViewAction slideSeekBar(final int progress) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return new TypeSafeMatcher<View>() {
                @Override
                protected boolean matchesSafely(View item) {
                    return item instanceof SeekBar;
                }

                @Override
                public void describeTo(Description description) {
                    description.appendText("is a SeekBar.");
                }
            };
        }

        @Override
        public String getDescription() {
            return "Slides seekbar to progress position " + progress;
        }

        @Override
        public void perform(UiController uiController, View view) {
            SeekBar seekBar = (SeekBar) view;

            int[] seekBarPos = {0,0};
            view.getLocationOnScreen(seekBarPos);
            float[] startPos = {seekBarPos[0], seekBarPos[1]};

            MotionEvents.DownResultHolder downResultHolder =
                    MotionEvents.sendDown(uiController, startPos,
                                          Press.PINPOINT.describePrecision());

            while(seekBar.getProgress() < progress) {
                startPos[0]++;
                MotionEvents.sendMovement(uiController, downResultHolder.down, startPos);
                uiController.loopMainThreadForAtLeast(10);
            }

            MotionEvents.sendUp(uiController, downResultHolder.down, startPos);
        }
    };
}
 
Example #19
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
private void testSkipCollapsed_smallSwipe(int expectedState, float swipeViewHeightPercentage)
    throws Throwable {
  getBehavior().setSkipCollapsed(true);
  checkSetState(BottomSheetBehavior.STATE_EXPANDED, ViewMatchers.isDisplayed());
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.SLOW,
                  // Manually calculate the starting coordinates to make sure that the touch
                  // actually falls onto the view on Gingerbread
                  view -> {
                    int[] location = new int[2];
                    view.getLocationInWindow(location);
                    return new float[] {view.getWidth() / 2, location[1] + 1};
                  },
                  // Manually calculate the ending coordinates to make sure that the bottom
                  // sheet is collapsed, not hidden
                  view -> {
                    return new float[] {
                      // x: center of the bottom sheet
                      view.getWidth() / 2,
                      // y: some percentage down the view
                      view.getHeight() * swipeViewHeightPercentage,
                    };
                  },
                  Press.FINGER),
              ViewMatchers.isDisplayingAtLeast(5)));
  registerIdlingResourceCallback();
  try {
    if (expectedState == BottomSheetBehavior.STATE_HIDDEN) {
      Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
          .check(ViewAssertions.matches(not(ViewMatchers.isDisplayed())));
    } else {
      Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
          .check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
    }
    assertThat(getBehavior().getState(), is(expectedState));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example #20
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@Test
@MediumTest
public void testSkipCollapsed() throws Throwable {
  assertAccessibilityActions(getBehavior(), getBottomSheet());
  getBehavior().setSkipCollapsed(true);
  assertAccessibilityActions(getBehavior(), getBottomSheet());
  checkSetState(BottomSheetBehavior.STATE_EXPANDED, ViewMatchers.isDisplayed());
  Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet))
      .perform(
          DesignViewActions.withCustomConstraints(
              new GeneralSwipeAction(
                  Swipe.FAST,
                  // Manually calculate the starting coordinates to make sure that the touch
                  // actually falls onto the view on Gingerbread
                  view -> {
                    int[] location = new int[2];
                    view.getLocationInWindow(location);
                    return new float[] {view.getWidth() / 2, location[1] + 1};
                  },
                  // Manually calculate the ending coordinates to make sure that the bottom
                  // sheet is collapsed, not hidden
                  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(not(ViewMatchers.isDisplayed())));
    assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_HIDDEN));
  } finally {
    unregisterIdlingResourceCallback();
  }
}
 
Example #21
Source File: ViewPagerActions.java    From android-test with Apache License 2.0 4 votes vote down vote up
/** Clicks between two titles in a <code>ViewPager</code> title strip */
public static ViewAction clickBetweenTwoTitles(final String title1, final String title2) {
  return new GeneralClickAction(
      Tap.SINGLE,
      new CoordinatesProvider() {

        @Override
        public float[] calculateCoordinates(View view) {
          PagerTitleStrip pagerStrip = (PagerTitleStrip) view;

          // Get the screen position of the pager strip
          final int[] viewScreenPosition = new int[2];
          pagerStrip.getLocationOnScreen(viewScreenPosition);

          // Get the left / right of the first title
          int title1Left = 0, title1Right = 0, title2Left = 0, title2Right = 0;
          final int childCount = pagerStrip.getChildCount();
          for (int i = 0; i < childCount; i++) {
            final View child = pagerStrip.getChildAt(i);
            if (child instanceof TextView) {
              final TextView textViewChild = (TextView) child;
              final CharSequence childText = textViewChild.getText();
              if (title1.equals(childText)) {
                title1Left = textViewChild.getLeft();
                title1Right = textViewChild.getRight();
              } else if (title2.equals(childText)) {
                title2Left = textViewChild.getLeft();
                title2Right = textViewChild.getRight();
              }
            }
          }

          if (title1Right < title2Left) {
            // Title 1 is to the left of title 2
            return new float[] {
              viewScreenPosition[0] + (title1Right + title2Left) / 2,
              viewScreenPosition[1] + pagerStrip.getHeight() / 2
            };
          } else {
            // The assumption here is that PagerTitleStrip prevents titles
            // from overlapping, so if we get here it means that title 1
            // is to the right of title 2
            return new float[] {
              viewScreenPosition[0] + (title2Right + title1Left) / 2,
              viewScreenPosition[1] + pagerStrip.getHeight() / 2
            };
          }
        }
      },
      Press.FINGER,
      0,
      0);
}
 
Example #22
Source File: AuthenticatorActivityTest.java    From google-authenticator-android with Apache License 2.0 4 votes vote down vote up
@Test
public void testReorderAccounts() {
  accountDb.add(
      "first", "7777777777777777", OtpType.HOTP, null, null, AccountDb.GOOGLE_ISSUER_NAME);
  accountDb.add("second", "6666666666666666", OtpType.TOTP, null, null, null);
  accountDb.add("third", "5555555555555555", OtpType.TOTP, null, null, "Yahoo");

  activityTestRule.launchActivity(null);

  EmptySpaceClickableDragSortListView userList =
      activityTestRule.getActivity().findViewById(R.id.user_list);
  View firstView = userList.getChildAt(0);
  View thirdView = userList.getChildAt(2);
  View firstDragHandle = firstView.findViewById(R.id.user_row_drag_handle);
  View thirdDragHandle = thirdView.findViewById(R.id.user_row_drag_handle);
  int dragHandleWidth = firstDragHandle.getWidth();
  int dragHandleHeight = firstDragHandle.getHeight();
  int[] firstDragHandleLocation = new int[2];
  int[] thirdDragHandleLocation = new int[2];
  firstDragHandle.getLocationOnScreen(firstDragHandleLocation);
  thirdDragHandle.getLocationOnScreen(thirdDragHandleLocation);
  float fromX = firstDragHandleLocation[0] + (dragHandleWidth / 2.0f);
  float fromY = firstDragHandleLocation[1] + (dragHandleHeight / 2.0f);
  float toX = thirdDragHandleLocation[0] + (dragHandleWidth / 2.0f);
  float toY = thirdDragHandleLocation[1] + (dragHandleHeight / 2.0f);

  onView(equalTo(firstView))
      .perform(longClick())
      .perform(
          new GeneralSwipeAction(
              Swipe.SLOW,
              (view) -> {
                return new float[] {fromX, fromY};
              },
              (view) -> {
                return new float[] {toX, toY};
              },
              Press.FINGER));

  ListAdapter listAdapter = userList.getAdapter();
  PinInfo firstPinInfo = (PinInfo) listAdapter.getItem(0);
  PinInfo secondPinInfo = (PinInfo) listAdapter.getItem(1);
  PinInfo thirdPinInfo = (PinInfo) listAdapter.getItem(2);
  assertThat(firstPinInfo.getIndex().getName()).isEqualTo("second");
  assertThat(secondPinInfo.getIndex().getName()).isEqualTo("third");
  assertThat(thirdPinInfo.getIndex().getName()).isEqualTo("first");
}
 
Example #23
Source File: SwipeOpenItemTouchHelperTest.java    From SwipeOpenItemTouchHelper with Apache License 2.0 2 votes vote down vote up
/**
 * Uses a slow swipe to simulate a scroll
 *
 * @return the view action
 */
private ViewAction scroll() {
  return new GeneralSwipeAction(Swipe.SLOW, GeneralLocation.BOTTOM_CENTER,
      GeneralLocation.TOP_CENTER, Press.FINGER);
}
 
Example #24
Source File: Utils.java    From BottomNavigation with Apache License 2.0 2 votes vote down vote up
/**
 * 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 #25
Source File: Utils.java    From BottomNavigation with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an action that performs a swipe left-to-right 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 swipeRightSlow() {
    return actionWithAssertions(new GeneralSwipeAction(Swipe.SLOW,
            translate(GeneralLocation.CENTER_LEFT, EDGE_FUZZ_FACTOR, 0),
            GeneralLocation.CENTER_RIGHT, Press.FINGER));
}
 
Example #26
Source File: Utils.java    From BottomNavigation with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an action that performs a swipe top-to-bottom across the horizontal center of the view.
 * The swipe doesn't start at the very edge of the view, but has a bit of offset.<br>
 * <br>
 * View constraints:
 * <ul>
 * <li>must be displayed on screen
 * <ul>
 */
public static ViewAction swipeDownSlow() {
    return actionWithAssertions(new GeneralSwipeAction(Swipe.SLOW,
            translate(GeneralLocation.TOP_CENTER, 0, EDGE_FUZZ_FACTOR),
            GeneralLocation.BOTTOM_CENTER, Press.FINGER));
}
 
Example #27
Source File: Utils.java    From BottomNavigation with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an action that performs a swipe bottom-to-top across the horizontal center of the view.
 * The swipe doesn't start at the very edge of the view, but has a bit of offset.<br>
 * <br>
 * View constraints:
 * <ul>
 * <li>must be displayed on screen
 * <ul>
 */
public static ViewAction swipeUpSlow() {
    return actionWithAssertions(new GeneralSwipeAction(Swipe.SLOW,
            translate(GeneralLocation.BOTTOM_CENTER, 0, -EDGE_FUZZ_FACTOR),
            GeneralLocation.TOP_CENTER, Press.FINGER));
}