Java Code Examples for androidx.test.espresso.action.Press#FINGER

The following examples show how to use androidx.test.espresso.action.Press#FINGER . 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: 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 2
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 3
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 4
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 5
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 6
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);
}