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;
  }
Verifies (with a timeout of {@link #UI_ACTION_EFFECT_TIMEOUT_MILLIS}) that an activity launch
has been attempted and returns the {@link Intent} with which the attempt occurred.

<p><b>NOTE: This method assumes that the {@link DependencyInjector} was configured using {@link
#withLaunchPreventingStartActivityListenerInDependencyResolver()}.</b>
javatests/com/google/android/apps/authenticator/testing/TestUtilities.java