Swipe interaction changes on home screen

> Increasing the distance to travel for the first swipe
> Adding support for custom interpolators when building an animation
> When quickly swiping twice from home, finished the first animation

Change-Id: Ibc3c8667e9b927376fd99f08f0ca027f2398914b
diff --git a/src/com/android/launcher3/LauncherState.java b/src/com/android/launcher3/LauncherState.java
index 6185844..5c16ca9 100644
--- a/src/com/android/launcher3/LauncherState.java
+++ b/src/com/android/launcher3/LauncherState.java
@@ -180,8 +180,8 @@
         return new float[] {1, 0, 0};
     }
 
-    public float getOverviewTranslationX(Launcher launcher) {
-        return launcher.getDragLayer().getMeasuredWidth();
+    public float getOverviewTranslationFactor(Launcher launcher) {
+        return 1;
     }
 
     public void onStateEnabled(Launcher launcher) {
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
index fbd23d1..9be123f 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -3,6 +3,7 @@
 import static com.android.launcher3.LauncherState.ALL_APPS_CONTENT;
 import static com.android.launcher3.LauncherState.ALL_APPS_HEADER;
 import static com.android.launcher3.LauncherState.ALL_APPS_HEADER_EXTRA;
+import static com.android.launcher3.anim.AnimatorSetBuilder.ANIM_VERTICAL_PROGRESS;
 import static com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN;
 import static com.android.launcher3.anim.Interpolators.LINEAR;
 import static com.android.launcher3.anim.PropertySetter.NO_ANIM_PROPERTY_SETTER;
@@ -55,8 +56,6 @@
         }
     };
 
-    public static final float PARALLAX_COEFFICIENT = .125f;
-
     private AllAppsContainerView mAppsView;
 
     private final Launcher mLauncher;
@@ -169,7 +168,7 @@
         ObjectAnimator anim =
                 ObjectAnimator.ofFloat(this, ALL_APPS_PROGRESS, mProgress, targetProgress);
         anim.setDuration(config.duration);
-        anim.setInterpolator(interpolator);
+        anim.setInterpolator(builder.getInterpolator(ANIM_VERTICAL_PROGRESS, interpolator));
         anim.addListener(getProgressAnimatorListener());
 
         builder.play(anim);
diff --git a/src/com/android/launcher3/anim/AnimatorSetBuilder.java b/src/com/android/launcher3/anim/AnimatorSetBuilder.java
index 7cd9651..9191048 100644
--- a/src/com/android/launcher3/anim/AnimatorSetBuilder.java
+++ b/src/com/android/launcher3/anim/AnimatorSetBuilder.java
@@ -17,6 +17,8 @@
 
 import android.animation.Animator;
 import android.animation.AnimatorSet;
+import android.util.SparseArray;
+import android.view.animation.Interpolator;
 
 import com.android.launcher3.LauncherAnimUtils;
 
@@ -27,7 +29,12 @@
  */
 public class AnimatorSetBuilder {
 
+    public static final int ANIM_VERTICAL_PROGRESS = 0;
+    public static final int ANIM_OVERVIEW_TRANSLATION = 1;
+
     protected final ArrayList<Animator> mAnims = new ArrayList<>();
+
+    private final SparseArray<Interpolator> mInterpolators = new SparseArray<>();
     private long mStartDelay = 0;
 
     /**
@@ -49,4 +56,12 @@
         anim.setStartDelay(mStartDelay);
         return anim;
     }
+
+    public Interpolator getInterpolator(int animId, Interpolator fallback) {
+        return mInterpolators.get(animId, fallback);
+    }
+
+    public void setInterpolator(int animId, Interpolator interpolator) {
+        mInterpolators.put(animId, interpolator);
+    }
 }
diff --git a/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java b/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java
index db53634..a22f450 100644
--- a/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java
+++ b/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java
@@ -19,6 +19,7 @@
 
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
+import android.animation.TimeInterpolator;
 import android.animation.ValueAnimator;
 import android.util.Log;
 import android.view.MotionEvent;
@@ -140,10 +141,14 @@
     @Override
     public boolean onDrag(float displacement, float velocity) {
         float deltaProgress = mProgressMultiplier * displacement;
-        mCurrentAnimation.setPlayFraction(deltaProgress + mStartProgress);
+        updateProgress(deltaProgress + mStartProgress);
         return true;
     }
 
+    protected void updateProgress(float fraction) {
+        mCurrentAnimation.setPlayFraction(fraction);
+    }
+
     @Override
     public void onDragEnd(float velocity, boolean fling) {
         final int logAction;
@@ -173,7 +178,7 @@
                 startProgress = 1;
             } else {
                 startProgress = Utilities.boundToRange(
-                        progress + velocity * SINGLE_FRAME_MS / getShiftRange(), 0f, 1f);
+                        progress + velocity * SINGLE_FRAME_MS * mProgressMultiplier, 0f, 1f);
                 duration = SwipeDetector.calculateDuration(velocity,
                         endProgress - Math.max(progress, 0));
             }
@@ -184,7 +189,7 @@
                 startProgress = 0;
             } else {
                 startProgress = Utilities.boundToRange(
-                        progress + velocity * SINGLE_FRAME_MS / getShiftRange(), 0f, 1f);
+                        progress + velocity * SINGLE_FRAME_MS * mProgressMultiplier, 0f, 1f);
                 duration = SwipeDetector.calculateDuration(velocity,
                         Math.min(progress, 1) - endProgress);
             }
@@ -193,10 +198,16 @@
         mCurrentAnimation.setEndAction(() -> onSwipeInteractionCompleted(targetState, logAction));
         ValueAnimator anim = mCurrentAnimation.getAnimationPlayer();
         anim.setFloatValues(startProgress, endProgress);
-        anim.setDuration(duration).setInterpolator(scrollInterpolatorForVelocity(velocity));
+        updateSwipeCompleteAnimation(anim, duration, targetState, velocity, fling);
         anim.start();
     }
 
+    protected void updateSwipeCompleteAnimation(ValueAnimator animator, long expectedDuration,
+            LauncherState targetState, float velocity, boolean isFling) {
+        animator.setDuration(expectedDuration)
+                .setInterpolator(scrollInterpolatorForVelocity(velocity));
+    }
+
     protected int getDirectionForLog() {
         return mToState.ordinal > mFromState.ordinal ? Direction.UP : Direction.DOWN;
     }