Java Code Examples for android.support.test.espresso.action.CoordinatesProvider

The following are top voted examples for showing how to use android.support.test.espresso.action.CoordinatesProvider. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: material-components-android   File: BottomSheetBehaviorTest.java   Source Code and License 7 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,
                  new CoordinatesProvider() {
                    @Override
                    public float[] calculateCoordinates(View view) {
                      return 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 2
Project: ChimpCheck   File: ChimpActionFactory.java   Source Code and License 6 votes vote down vote up
private static CoordinatesProvider getCoordinatesProvider(final int x, final int y){
    return new CoordinatesProvider(){
        @Override
        public float[] calculateCoordinates(View view) {

            final int[] screenPos = new int[2];
            view.getLocationOnScreen(screenPos);

            final float screenX = screenPos[0] + x;
            final float screenY = screenPos[1] + y;
            float[] coordinates = {screenX, screenY};

            return coordinates;
        }
    };
}
 
Example 3
Project: SmoothClicker   File: ItSelectMultiPointsActivity.java   Source Code and License 6 votes vote down vote up
/**
 * Custom ViewAction to click on dedicated coordinates
 * @param x -
 * @param y -
 * @return ViewAction -
 */
private ViewAction clickXY( final int x, final int y ){
    return new GeneralClickAction(
            Tap.SINGLE,
            new CoordinatesProvider() {
                @Override
                public float[] calculateCoordinates( View view ){

                    final int[] screenPos = new int[2];
                    view.getLocationOnScreen(screenPos);

                    final float screenX = screenPos[0] + x;
                    final float screenY = screenPos[1] + y;

                    return new float[]{screenX, screenY};

                }
            },
            Press.FINGER);
}
 
Example 4
Project: Todo.txt-gDrive   File: MainActivityTest.java   Source Code and License 6 votes vote down vote up
private static ViewAction clickXY(final int x, final int y) {
    return new GeneralClickAction(
            Tap.SINGLE,
            new CoordinatesProvider() {
                @Override
                public float[] calculateCoordinates(View view) {

                    final int[] screenPos = new int[2];
                    view.getLocationOnScreen(screenPos);

                    final float screenX = screenPos[0] + x;
                    final float screenY = screenPos[1] + y;
                    float[] coordinates = {screenX, screenY};

                    return coordinates;
                }
            },
            Press.FINGER);
}
 
Example 5
Project: translationRecorder   File: TestUtils.java   Source Code and License 6 votes vote down vote up
public static ViewAction clickXY(final int x, final int y){
    return new GeneralClickAction(
            Tap.SINGLE,
            new CoordinatesProvider() {
                @Override
                public float[] calculateCoordinates(View view) {

                    final int[] screenPos = new int[2];
                    view.getLocationOnScreen(screenPos);

                    final float screenX = screenPos[0] + x;
                    final float screenY = screenPos[1] + y;
                    float[] coordinates = {screenX, screenY};

                    return coordinates;
                }
            },
            Press.FINGER);
}
 
Example 6
Project: GitHub   File: Utils.java   Source Code and License 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 7
Project: SwipeCoordinator   File: ViewActions.java   Source Code and License 5 votes vote down vote up
static ViewAction swipeRightNotReachingThreshold(Context context) {
  final float x = getWidthScreen(context) * 0.3f;
  return new GeneralSwipeAction(Swipe.SLOW, GeneralLocation.TOP_LEFT, new CoordinatesProvider() {
    @Override public float[] calculateCoordinates(View view) {
      return new float[] {x, 0f};
    }
  }, Press.FINGER);
}
 
Example 8
Project: SwipeCoordinator   File: ViewActions.java   Source Code and License 5 votes vote down vote up
static ViewAction swipeRightReachingThreshold(Context context) {
  final float x = getWidthScreen(context) * 0.8f;
  return new GeneralSwipeAction(Swipe.SLOW, GeneralLocation.TOP_LEFT, new CoordinatesProvider() {
    @Override public float[] calculateCoordinates(View view) {
      return new float[] {x, 0f};
    }
  }, Press.FINGER);
}
 
Example 9
Project: SwipeCoordinator   File: ViewActions.java   Source Code and License 5 votes vote down vote up
static ViewAction swipeDownNotReachingThreshold(Context context) {
  final float y = getHeightScreen(context) * 0.3f;
  return new GeneralSwipeAction(Swipe.SLOW, GeneralLocation.TOP_LEFT, new CoordinatesProvider() {
    @Override public float[] calculateCoordinates(View view) {
      return new float[] {0f, y};
    }
  }, Press.FINGER);
}
 
Example 10
Project: SwipeCoordinator   File: ViewActions.java   Source Code and License 5 votes vote down vote up
static ViewAction swipeDownReachingThreshold(Context context) {
  final float y = getHeightScreen(context) * 0.8f;
  return new GeneralSwipeAction(Swipe.SLOW, GeneralLocation.TOP_LEFT, new CoordinatesProvider() {
    @Override public float[] calculateCoordinates(View view) {
      return new float[] {0f, y};
    }
  }, Press.FINGER);
}
 
Example 11
Project: material-components-android   File: BottomSheetBehaviorTest.java   Source Code and License 5 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,
                  new CoordinatesProvider() {
                    @Override
                    public float[] calculateCoordinates(View view) {
                      return 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 12
Project: material-components-android   File: BottomSheetBehaviorTest.java   Source Code and License 5 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,
                  new CoordinatesProvider() {
                    @Override
                    public float[] calculateCoordinates(View view) {
                      return 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 13
Project: material-components-android   File: BottomSheetBehaviorTest.java   Source Code and License 5 votes vote down vote up
@Test
@MediumTest
public void testInvisible() throws Throwable {
  // Make the bottomsheet invisible
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          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,
                  new CoordinatesProvider() {
                    @Override
                    public float[] calculateCoordinates(View view) {
                      return new float[] {view.getWidth() / 2, 0};
                    }
                  },
                  Press.FINGER),
              not(ViewMatchers.isDisplayed())));
  // Check that the bottom sheet stays the same collapsed state
  activityTestRule.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
        }
      });
}
 
Example 14
Project: SmoothClicker   File: ItClickerActivity.java   Source Code and License 5 votes vote down vote up
/**
 * Custom ViewAction to click on dedicated coordinates
 * @param x -
 * @param y -
 * @return ViewAction -
 */
private ViewAction clickXY( final int x, final int y ){
    return new GeneralClickAction(
            Tap.SINGLE,
            new CoordinatesProvider() {
                @Override
                public float[] calculateCoordinates( View view ){

                    final int[] screenPos = new int[2];
                    view.getLocationOnScreen(screenPos);

                    final float screenX = screenPos[0] + x;
                    final float screenY = screenPos[1] + y;

                    return new float[]{screenX, screenY};

                }
            },
            Press.FINGER);
}
 
Example 15
Project: material-activity-chooser   File: NoConstraintsSwipeAction.java   Source Code and License 5 votes vote down vote up
public NoConstraintsSwipeAction(Swiper swiper, CoordinatesProvider startCoordinatesProvider,
                                CoordinatesProvider endCoordinatesProvider, PrecisionDescriber precisionDescriber) {
  this.swiper = swiper;
  this.startCoordinatesProvider = startCoordinatesProvider;
  this.endCoordinatesProvider = endCoordinatesProvider;
  this.precisionDescriber = precisionDescriber;
}
 
Example 16
Project: Bill-Calculator   File: Tester.java   Source Code and License 5 votes vote down vote up
ViewAction swipeAwayRight() {
    return actionWithAssertions(new GeneralSwipeAction(Swipe.FAST,
            GeneralLocation.CENTER,
            new CoordinatesProvider() {
                @Override
                public float[] calculateCoordinates(View view) {
                    float xy[] = GeneralLocation.CENTER_RIGHT.calculateCoordinates(view);
                    xy[0] += 20f * view.getWidth();
                    return xy;
                }
            },
            Press.FINGER));
}
 
Example 17
Project: Ironhide   File: GeneralZoomAction.java   Source Code and License 5 votes vote down vote up
public GeneralZoomAction(Zoomer zoomer,
                         CoordinatesProvider[] startCoordinatesProviders,
                         CoordinatesProvider[] endCoordinatesProviders,
                         PrecisionDescriber precisionDescriber) {
    this.zoomer = zoomer;
    this.startCoordinatesProviders = startCoordinatesProviders;
    this.endCoordinatesProviders = endCoordinatesProviders;
    this.precisionDescriber = precisionDescriber;
}
 
Example 18
Project: material-components-android   File: BottomSheetBehaviorTest.java   Source Code and License 4 votes vote down vote up
public DragAction(
    CoordinatesProvider start, CoordinatesProvider end, PrecisionDescriber precisionDescriber) {
  this.start = start;
  this.end = end;
  this.precisionDescriber = precisionDescriber;
}
 
Example 19
Project: Bill-Calculator   File: CustomClickAction.java   Source Code and License 4 votes vote down vote up
private CustomClickAction(Tapper tapper, CoordinatesProvider coordinatesProvider,
                          PrecisionDescriber precisionDescriber) {
    this.coordinatesProvider = coordinatesProvider;
    this.tapper = tapper;
    this.precisionDescriber = precisionDescriber;
}
 
Example 20
Project: Ironhide   File: SwipeAction.java   Source Code and License 4 votes vote down vote up
private SwipeDirection(CoordinatesProvider start, CoordinatesProvider end) {
    this.start = start;
    this.end = end;
}
 
Example 21
Project: Ironhide   File: ZoomAction.java   Source Code and License 2 votes vote down vote up
/**
 * Variadic parameters to simplify the look of this function.
 * First two assumed to be start locations,
 *  next two assumed to be end location,
 *  and the rest are ignored.
 */
private ZoomDirection(CoordinatesProvider... providers) {
    this.start = new CoordinatesProvider[]{ providers[0], providers[1] };
    this.end = new CoordinatesProvider[]{ providers[2], providers[3] };
}