Add springs when user clicks on caret / all apps snaps to top.

Bug: 65373058
Change-Id: I9cc5c4c98fd3e5b53d597c4493f2dcef6d9be94a
diff --git a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
index 1f60fcc..f7ce8c1 100644
--- a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
+++ b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
@@ -424,6 +424,9 @@
         // The amount by which each adjacent rows' stiffness will differ.
         private static final float ROW_STIFFNESS_COEFFICIENT = 50f;
 
+        // The percentage by which we multiply each row to create the row factor.
+        private static final float ROW_PERCENTAGE = 0.3f;
+
         @Override
         public SpringAnimation initialize(ViewHolder vh) {
             return SpringAnimationHandler.forView(vh.itemView, DynamicAnimation.TRANSLATION_Y, 0);
@@ -462,7 +465,7 @@
          * effect.
          */
         private void calculateSpringValues(SpringAnimation spring, int row, int col) {
-            float rowFactor = (1 + row) * 0.5f;
+            float rowFactor = (1 + row) * ROW_PERCENTAGE;
             float colFactor = getColumnFactor(col, mAppsPerRow);
 
             float minValue = DEFAULT_MIN_VALUE_PX * (rowFactor + colFactor);
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
index 743b16e..3364c61 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -394,6 +394,11 @@
         animationOut.play(driftAndAlpha);
 
         animationOut.addListener(new AnimatorListenerAdapter() {
+            // Spring values used when the user has not flung all apps.
+            private final float MAX_RELEASE_VELOCITY = 10000;
+            // The delay (as a % of the animation duration) to start the springs.
+            private final float DELAY = 0.3f;
+
             boolean canceled = false;
 
             @Override
@@ -402,6 +407,21 @@
             }
 
             @Override
+            public void onAnimationStart(Animator animation) {
+                // Add springs for cases where the user has not flung.
+                // ie. clicking on the caret, releasing all apps so it snaps up.
+                mAppsView.postDelayed(new Runnable() {
+                    @Override
+                    public void run() {
+                        if (!canceled && !mSpringAnimationHandler.isRunning()) {
+                            float velocity = mProgress * MAX_RELEASE_VELOCITY;
+                            mSpringAnimationHandler.animateToPositionWithVelocity(0, 1, velocity);
+                        }
+                    }
+                }, (long) (mAnimationDuration * DELAY));
+            }
+
+            @Override
             public void onAnimationEnd(Animator animation) {
                 if (canceled) {
                     return;