Use AllAppsTransitionController to animate the hotseat & scrim.

Bug: 70220260
Change-Id: I69bff4234c2fd0c76cb43cdd89342dcc04f2db40
diff --git a/quickstep/res/values/dimens.xml b/quickstep/res/values/dimens.xml
index 9cc7973..bdc7c36 100644
--- a/quickstep/res/values/dimens.xml
+++ b/quickstep/res/values/dimens.xml
@@ -37,6 +37,4 @@
     <!-- Launcher app transition -->
     <dimen name="content_trans_y">25dp</dimen>
     <dimen name="workspace_trans_y">80dp</dimen>
-
-    <dimen name="shelf_min_value">-2.857dp</dimen>
 </resources>
diff --git a/quickstep/src/com/android/launcher3/LauncherAppTransitionManager.java b/quickstep/src/com/android/launcher3/LauncherAppTransitionManager.java
index 256e926..47179c5 100644
--- a/quickstep/src/com/android/launcher3/LauncherAppTransitionManager.java
+++ b/quickstep/src/com/android/launcher3/LauncherAppTransitionManager.java
@@ -16,7 +16,7 @@
 
 package com.android.launcher3;
 
-import static com.android.launcher3.views.AllAppsScrim.SCRIM_PROGRESS;
+import static com.android.launcher3.allapps.AllAppsTransitionController.ALL_APPS_PROGRESS;
 import static com.android.systemui.shared.recents.utilities.Utilities.getNextFrameNumber;
 import static com.android.systemui.shared.recents.utilities.Utilities.getSurface;
 import static com.android.systemui.shared.recents.utilities.Utilities.postAtFrontOfQueueAsynchronously;
@@ -40,9 +40,9 @@
 import android.widget.ImageView;
 
 import com.android.launcher3.InsettableFrameLayout.LayoutParams;
+import com.android.launcher3.allapps.AllAppsTransitionController;
 import com.android.launcher3.anim.Interpolators;
 import com.android.launcher3.dragndrop.DragLayer;
-import com.android.launcher3.views.AllAppsScrim;
 import com.android.systemui.shared.system.ActivityCompat;
 import com.android.systemui.shared.system.ActivityOptionsCompat;
 import com.android.systemui.shared.system.RemoteAnimationAdapterCompat;
@@ -62,14 +62,16 @@
 
     private static final int CLOSING_TRANSITION_DURATION_MS = 350;
 
+    // Progress = 0: All apps is fully pulled up, Progress = 1: All apps is fully pulled down.
+    private static final float ALL_APPS_PROGRESS_START = 1.3059858f;
+    private static final float ALL_APPS_PROGRESS_SLIDE_END = 0.99581414f;
+
     private final DragLayer mDragLayer;
     private final Launcher mLauncher;
     private final DeviceProfile mDeviceProfile;
 
     private final float mContentTransY;
     private final float mWorkspaceTransY;
-    // The smallest y-value the shelf will reach on screen, before overshooting back down to 0.
-    private final float mShelfMinValue;
 
     private ImageView mFloatingView;
     private boolean mIsRtl;
@@ -84,7 +86,6 @@
         Resources res = launcher.getResources();
         mContentTransY = res.getDimensionPixelSize(R.dimen.content_trans_y);
         mWorkspaceTransY = res.getDimensionPixelSize(R.dimen.workspace_trans_y);
-        mShelfMinValue = res.getDimensionPixelSize(R.dimen.shelf_min_value);
     }
 
     /**
@@ -477,31 +478,29 @@
             workspaceAnimator.setDuration(333);
             workspaceAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
 
-            // Animate the shelf
-            AllAppsScrim allAppsScrim = mLauncher.findViewById(R.id.all_apps_scrim);
-            View hotseat = mLauncher.getHotseat();
-            final float endY = mShelfMinValue;
-            int startY = hotseat.getMeasuredHeight()
-                    + (allAppsScrim.getShadowBitmap().getHeight() / 2);
-            hotseat.setTranslationY(startY);
-            allAppsScrim.setTranslationY(startY);
+            // Animate the shelf in two parts: slide in, and overeshoot.
+            AllAppsTransitionController allAppsController = mLauncher.getAllAppsController();
+            // The shelf will start offscreen
+            final float startY = ALL_APPS_PROGRESS_START;
+            // And will end slightly pulled up, so that there is something to overshoot back to 1f.
+            final float slideEnd = ALL_APPS_PROGRESS_SLIDE_END;
 
-            AnimatorSet hotseatSlideIn = new AnimatorSet();
-            hotseatSlideIn.play(ObjectAnimator.ofFloat(hotseat, View.TRANSLATION_Y, startY, endY));
-            hotseatSlideIn.play(ObjectAnimator.ofFloat(allAppsScrim, SCRIM_PROGRESS, startY, endY));
-            hotseatSlideIn.setStartDelay(150);
-            hotseatSlideIn.setDuration(317);
-            hotseatSlideIn.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
+            allAppsController.setProgress(startY);
 
-            AnimatorSet hotseatOvershoot = new AnimatorSet();
-            hotseatOvershoot.play(ObjectAnimator.ofFloat(hotseat, View.TRANSLATION_Y, endY, 0));
-            hotseatOvershoot.play(ObjectAnimator.ofFloat(allAppsScrim, SCRIM_PROGRESS, endY, 0));
-            hotseatOvershoot.setDuration(153);
-            hotseatOvershoot.setInterpolator(Interpolators.OVERSHOOT_0);
+            Animator allAppsSlideIn =
+                    ObjectAnimator.ofFloat(allAppsController, ALL_APPS_PROGRESS, startY, slideEnd);
+            allAppsSlideIn.setStartDelay(150);
+            allAppsSlideIn.setDuration(317);
+            allAppsSlideIn.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
+
+            Animator allAppsOvershoot =
+                    ObjectAnimator.ofFloat(allAppsController, ALL_APPS_PROGRESS, slideEnd, 1f);
+            allAppsOvershoot.setDuration(153);
+            allAppsOvershoot.setInterpolator(Interpolators.OVERSHOOT_0);
 
             AnimatorSet resumeLauncherAnimation = new AnimatorSet();
             resumeLauncherAnimation.play(workspaceAnimator);
-            resumeLauncherAnimation.playSequentially(hotseatSlideIn, hotseatOvershoot);
+            resumeLauncherAnimation.playSequentially(allAppsSlideIn, allAppsOvershoot);
             return resumeLauncherAnimation;
         }
     }
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
index c02f2df..dadc6cd 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -37,8 +37,8 @@
 public class AllAppsTransitionController
         implements SearchUiManager.OnScrollRangeChangeListener, LauncherStateManager.StateHandler {
 
-    private static final Property<AllAppsTransitionController, Float> PROGRESS =
-            new Property<AllAppsTransitionController, Float>(Float.class, "progress") {
+    public static final Property<AllAppsTransitionController, Float> ALL_APPS_PROGRESS =
+            new Property<AllAppsTransitionController, Float>(Float.class, "allAppsProgress") {
 
         @Override
         public Float get(AllAppsTransitionController controller) {
@@ -164,7 +164,8 @@
         }
 
         Interpolator interpolator = config.userControlled ? LINEAR : FAST_OUT_SLOW_IN;
-        ObjectAnimator anim = ObjectAnimator.ofFloat(this, PROGRESS, mProgress, targetProgress);
+        ObjectAnimator anim =
+                ObjectAnimator.ofFloat(this, ALL_APPS_PROGRESS, mProgress, targetProgress);
         anim.setDuration(config.duration);
         anim.setInterpolator(interpolator);
         anim.addListener(getProgressAnimatorListener());
diff --git a/src/com/android/launcher3/views/AllAppsScrim.java b/src/com/android/launcher3/views/AllAppsScrim.java
index 6cd40fd..662f99c 100644
--- a/src/com/android/launcher3/views/AllAppsScrim.java
+++ b/src/com/android/launcher3/views/AllAppsScrim.java
@@ -61,25 +61,11 @@
 
     private final NinePatchDrawHelper mShadowHelper = new NinePatchDrawHelper();
 
-    private float mProgress;
     private int mFillAlpha;
 
     private float mDrawHeight;
     private float mDrawOffsetY;
 
-    public static final Property<AllAppsScrim, Float> SCRIM_PROGRESS =
-            new Property<AllAppsScrim, Float>(Float.class, "allAppsScrimProgress") {
-                @Override
-                public Float get(AllAppsScrim allAppsScrim) {
-                    return allAppsScrim.getProgress();
-                }
-
-                @Override
-                public void set(AllAppsScrim allAppsScrim, Float progress) {
-                    allAppsScrim.setProgress(progress);
-                }
-            };
-
     public AllAppsScrim(Context context) {
         this(context, null);
     }
@@ -174,23 +160,17 @@
 
     public void setProgress(float translateY, float alpha) {
         int newAlpha = Math.round(alpha * mAlphaRange + mMinAlpha);
-        if (newAlpha != mFillAlpha) {
-            mFillAlpha = newAlpha;
-            mFillPaint.setAlpha(mFillAlpha);
-            invalidateDrawRect();
-        }
-
-        setProgress(translateY);
-    }
-
-    public void setProgress(float translateY) {
         // Negative translation means the scrim is moving up. For negative translation, we change
         // draw offset as it requires redraw (since more area of the scrim needs to be shown). For
         // position translation, we simply translate the scrim down as it avoids invalidate and
         // hence could be optimized by the platform.
         float drawOffsetY = Math.min(translateY, 0);
 
-        if (drawOffsetY != mDrawOffsetY) {
+        if (newAlpha != mFillAlpha || drawOffsetY != mDrawOffsetY) {
+            invalidateDrawRect();
+
+            mFillAlpha = newAlpha;
+            mFillPaint.setAlpha(mFillAlpha);
             mDrawOffsetY = drawOffsetY;
             invalidateDrawRect();
         }
@@ -198,10 +178,6 @@
         setTranslationY(Math.max(translateY, 0));
     }
 
-    public float getProgress() {
-        return mProgress;
-    }
-
     private void invalidateDrawRect() {
         mDrawRect.top = (int) (getHeight()
                 + mDrawOffsetY - mDrawHeight + mPadding.top - mShadowBlur - 0.5f);