public static ViewAction swipeUp(final Swiper swipe) { return ViewActions.actionWithAssertions(new GeneralSwipeAction( swipe, GeneralLocation.CENTER, GeneralLocation.TOP_CENTER, Press.FINGER )); }
public static ViewAction swipeDown(final Swiper swipe) { return ViewActions.actionWithAssertions(new GeneralSwipeAction( swipe, GeneralLocation.CENTER, GeneralLocation.BOTTOM_CENTER, Press.FINGER )); }
public NoConstraintsSwipeAction(Swiper swiper, CoordinatesProvider startCoordinatesProvider, CoordinatesProvider endCoordinatesProvider, PrecisionDescriber precisionDescriber) { this.swiper = swiper; this.startCoordinatesProvider = startCoordinatesProvider; this.endCoordinatesProvider = endCoordinatesProvider; this.precisionDescriber = precisionDescriber; }
/** * Gets a swipe action. * * @param speed the speed of the swipe * @param direction the direction of the swipe * @return the swipe action requested */ public static GeneralSwipeAction getSwipe(Swiper speed, SwipeDirection direction) { Pair<Swiper, SwipeDirection> key = new Pair<>(speed, direction); if (!bufferedSwipeActions.containsKey(key)) bufferedSwipeActions.put(key, generateSwipe(speed, direction)); return bufferedSwipeActions.get(key); }
@Override public void perform(UiController uiController, View view) { float[] startCoordinates = startCoordinatesProvider.calculateCoordinates(view); float[] endCoordinates = endCoordinatesProvider.calculateCoordinates(view); float[] precision = precisionDescriber.describePrecision(); Swiper.Status status = Swiper.Status.FAILURE; for (int tries = 0; tries < MAX_TRIES && status != Swiper.Status.SUCCESS; tries++) { try { status = swiper.sendSwipe(uiController, startCoordinates, endCoordinates, precision); } catch (RuntimeException re) { throw new PerformException.Builder() .withActionDescription(this.getDescription()) .withViewDescription(HumanReadables.describe(view)) .withCause(re) .build(); } int duration = ViewConfiguration.getPressedStateDuration(); // ensures that all work enqueued to process the swipe has been run. if (duration > 0) { uiController.loopMainThreadForAtLeast(duration); } } if (status == Swiper.Status.FAILURE) { throw new PerformException.Builder() .withActionDescription(getDescription()) .withViewDescription(HumanReadables.describe(view)) .withCause(new RuntimeException(String.format( "Couldn't swipe from: %s,%s to: %s,%s precision: %s, %s . Swiper: %s " + "start coordinate provider: %s precision describer: %s. Tried %s times", startCoordinates[0], startCoordinates[1], endCoordinates[0], endCoordinates[1], precision[0], precision[1], swiper, startCoordinatesProvider, precisionDescriber, MAX_TRIES))) .build(); } }
/** * {@link Swipeable#swipe( * android.support.test.espresso.action.Swiper, * com.mindbodyonline.ironhide.Infrastructure.Extensions.SwipeAction.SwipeDirection, * int)} * with {@link Swipeable#DEFAULT_TIMES} */ public T swipe(Swiper speed, SwipeAction.SwipeDirection direction) { return swipe(speed, direction, DEFAULT_TIMES); }
/** * Creates a new swipe action. * * @param speed the speed of the swipe * @param direction the direction of the swipe * @return the swipe action requested */ private static GeneralSwipeAction generateSwipe(Swiper speed, SwipeDirection direction) { return new GeneralSwipeAction(speed, direction.start, direction.end, Press.FINGER); }