/**
   * Creates an animator that can be used for x and/or y translations. When interrupted, it sets a
   * tag to keep track of the position so that it may be continued from position.
   *
   * @param view The view being moved. This may be in the overlay for onDisappear.
   * @param values The values containing the view in the view hierarchy.
   * @param viewPosX The x screen coordinate of view
   * @param startX The start translation x of view
   * @param endX The end translation x of view
   * @param interpolator The interpolator to use with this animator.
   * @return An animator that moves from (startX, startY) to (endX, endY) unless there was a
   *     previous interruption, in which case it moves from the current position to (endX, endY).
   */
  static Animator createAnimation(
      View view,
      TransitionValues values,
      int viewPosX,
      float startX,
      float endX,
      TimeInterpolator interpolator,
      Transition transition) {
    float terminalX = view.getTranslationX();
    Integer startPosition = (Integer) values.view.getTag(R.id.transitionPosition);
    if (startPosition != null) {
      startX = startPosition - viewPosX + terminalX;
    }
    // Initial position is at translation startX, startY, so position is offset by that
    // amount
    int startPosX = viewPosX + Math.round(startX - terminalX);

    view.setTranslationX(startX);
    if (startX == endX) {
      return null;
    }
    Path path = new Path();
    path.moveTo(startX, 0);
    path.lineTo(endX, 0);
    ObjectAnimator anim =
        ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y, path);

    TransitionPositionListener listener =
        new TransitionPositionListener(view, values.view, startPosX, terminalX);
    transition.addListener(listener);
    anim.addListener(listener);
    anim.addPauseListener(listener);
    anim.setInterpolator(interpolator);
    return anim;
  }