androidx.test.espresso.action.CoordinatesProvider Java Examples

The following examples show how to use androidx.test.espresso.action.CoordinatesProvider. 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: Utils.java    From BottomNavigation with Apache License 2.0 5 votes vote down vote up
/**
 * Translates the given coordinates by the given distances. The distances are given in term
 * of the view's size -- 1.0 means to translate by an amount equivalent to the view's length.
 */
static CoordinatesProvider translate(final CoordinatesProvider coords,
                                     final float dx, final float dy) {
    return new CoordinatesProvider() {
        @Override
        public float[] calculateCoordinates(View view) {
            float xy[] = coords.calculateCoordinates(view);
            xy[0] += dx * view.getWidth();
            xy[1] += dy * view.getHeight();
            return xy;
        }
    };
}
 
Example #2
Source File: ClickWithoutDisplayConstraint.java    From kolabnotes-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Deprecated
public ClickWithoutDisplayConstraint(
        Tapper tapper,
        CoordinatesProvider coordinatesProvider,
        PrecisionDescriber precisionDescriber) {
    this(tapper, coordinatesProvider, precisionDescriber, 0, 0, null);
}
 
Example #3
Source File: ClickWithoutDisplayConstraint.java    From kolabnotes-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ClickWithoutDisplayConstraint(
        Tapper tapper,
        CoordinatesProvider coordinatesProvider,
        PrecisionDescriber precisionDescriber,
        int inputDevice,
        int buttonState) {
    this(tapper, coordinatesProvider, precisionDescriber, inputDevice, buttonState, null);
}
 
Example #4
Source File: ClickWithoutDisplayConstraint.java    From kolabnotes-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Deprecated
public ClickWithoutDisplayConstraint(
        Tapper tapper,
        CoordinatesProvider coordinatesProvider,
        PrecisionDescriber precisionDescriber,
        ViewAction rollbackAction) {
    this(tapper, coordinatesProvider, precisionDescriber, 0, 0, rollbackAction);
}
 
Example #5
Source File: ClickWithoutDisplayConstraint.java    From kolabnotes-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ClickWithoutDisplayConstraint(
        Tapper tapper,
        CoordinatesProvider coordinatesProvider,
        PrecisionDescriber precisionDescriber,
        int inputDevice,
        int buttonState,
        ViewAction rollbackAction) {
    this.coordinatesProvider = coordinatesProvider;
    this.tapper = tapper;
    this.precisionDescriber = precisionDescriber;
    this.inputDevice = inputDevice;
    this.buttonState = buttonState;
    this.rollbackAction = Optional.ofNullable(rollbackAction);
}
 
Example #6
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
public DragAction(
    CoordinatesProvider start, CoordinatesProvider end, PrecisionDescriber precisionDescriber) {
  this.start = start;
  this.end = end;
  this.precisionDescriber = precisionDescriber;
}
 
Example #7
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);
}