Tuning app close, and turn on flag.

- Tracks centery, slowed things down a bit

* We will be replacing StaggeredWorkspaceAnim with
  another animation, but I'm keeping it here in
  case we decide to turn the flag off later on.

Bug: 173107751
Test: manual
Change-Id: I5cd54ec374ad07c4912aff125a905b3b1dc7ebd5
diff --git a/quickstep/src/com/android/quickstep/LauncherSwipeHandlerV2.java b/quickstep/src/com/android/quickstep/LauncherSwipeHandlerV2.java
index 46cd8a2..b353eee 100644
--- a/quickstep/src/com/android/quickstep/LauncherSwipeHandlerV2.java
+++ b/quickstep/src/com/android/quickstep/LauncherSwipeHandlerV2.java
@@ -335,8 +335,8 @@
 
         @Override
         public void playAtomicAnimation(float velocity) {
-            new StaggeredWorkspaceAnim(mActivity, velocity,
-                    true /* animateOverviewScrim */).start();
+            new StaggeredWorkspaceAnim(mActivity, velocity, true /* animateOverviewScrim */,
+                    !PROTOTYPE_APP_CLOSE.get()).start();
         }
 
         @Override
diff --git a/quickstep/src/com/android/quickstep/util/RectFSpringAnim2.java b/quickstep/src/com/android/quickstep/util/RectFSpringAnim2.java
index 95d56aa..97be2b1 100644
--- a/quickstep/src/com/android/quickstep/util/RectFSpringAnim2.java
+++ b/quickstep/src/com/android/quickstep/util/RectFSpringAnim2.java
@@ -69,12 +69,12 @@
             new FloatPropertyCompat<RectFSpringAnim2>("rectYSpring") {
                 @Override
                 public float getValue(RectFSpringAnim2 anim) {
-                    return anim.mCurrentY;
+                    return anim.mCurrentCenterY;
                 }
 
                 @Override
                 public void setValue(RectFSpringAnim2 anim, float y) {
-                    anim.mCurrentY = y;
+                    anim.mCurrentCenterY = y;
                     anim.onUpdate();
                 }
             };
@@ -100,13 +100,12 @@
     private final List<Animator.AnimatorListener> mAnimatorListeners = new ArrayList<>();
 
     private float mCurrentCenterX;
-    private float mCurrentY;
+    private float mCurrentCenterY;
 
     private float mTargetX;
     private float mTargetY;
 
     // If true, tracking the bottom of the rects, else tracking the top.
-    private final boolean mTrackingBottomY;
     private float mProgress;
     private SpringAnimation mRectXAnim;
     private SpringAnimation mRectYAnim;
@@ -139,11 +138,10 @@
         mStartRect = startRect;
         mTargetRect = targetRect;
 
-        mTrackingBottomY = startRect.bottom < targetRect.bottom;
-        mCurrentY = mTrackingBottomY ? mStartRect.bottom : mStartRect.top;
+        mCurrentCenterY = mStartRect.centerY();
         mCurrentCenterX = mStartRect.centerX();
 
-        mTargetY = mTrackingBottomY ? mTargetRect.bottom : mTargetRect.top;
+        mTargetY = mTargetRect.centerY();
         mTargetX = mTargetRect.centerX();
 
         ResourceProvider rp = DynamicResource.provider(context);
@@ -157,12 +155,6 @@
         mHomeTransYEnd = dpToPx(rp.getFloat(R.dimen.swipe_up_trans_y_dp));
         mScaleStart = rp.getFloat(R.dimen.swipe_up_scale_start);
 
-
-        if (!mTrackingBottomY) {
-            mYStiffness *= rp.getFloat(R.dimen.swipe_up_rect_2_y_stiffness_low_swipe_multiplier);
-            mDuration *= rp.getFloat(R.dimen.swipe_up_low_swipe_duration_multiplier);
-        }
-
         mCloseInterpolator = getAppCloseInterpolator(context);
 
         // End on a "round-enough" radius so that the shape reveal doesn't have to do too much
@@ -180,11 +172,8 @@
         }
 
         if (mRectYAnim != null) {
-            if (mTrackingBottomY && mTargetY != mTargetRect.bottom) {
-                mTargetY = mTargetRect.bottom;
-                mRectYAnim.animateToFinalPosition(mTargetY);
-            } else if (!mTrackingBottomY && mTargetY != mTargetRect.top) {
-                mTargetY = mTargetRect.top;
+            if (mTargetY != mTargetRect.centerY()) {
+                mTargetY = mTargetRect.centerY();
                 mRectYAnim.animateToFinalPosition(mTargetY);
             }
         }
@@ -220,9 +209,9 @@
         }));
 
         mRectYAnim = new SpringAnimation(this, RECT_Y)
-                .setStartValue(mCurrentY)
-                .setMinValue(Math.min(0, mCurrentY))
-                .setMaxValue(Math.max(dp.heightPx, mCurrentY))
+                .setStartValue(mCurrentCenterY)
+                .setMinValue(Math.min(0, mCurrentCenterY))
+                .setMaxValue(Math.max(dp.heightPx, mCurrentCenterY))
                 .setStartVelocity(velocityPxPerMs.y * 1000)
                 .setSpring(new SpringForce(mTargetY)
                         .setStiffness(mYStiffness)
@@ -336,13 +325,11 @@
                     mTargetRect.width());
             float currentHeight = Utilities.mapRange(rectProgress, mStartRect.height(),
                     mTargetRect.height());
-            if (mTrackingBottomY) {
-                mCurrentRect.set(mCurrentCenterX - currentWidth / 2, mCurrentY - currentHeight,
-                        mCurrentCenterX + currentWidth / 2, mCurrentY);
-            } else {
-                mCurrentRect.set(mCurrentCenterX - currentWidth / 2, mCurrentY,
-                        mCurrentCenterX + currentWidth / 2, mCurrentY + currentHeight);
-            }
+
+            mCurrentRect.set(mCurrentCenterX - currentWidth / 2,
+                    mCurrentCenterY - currentHeight / 2,
+                    mCurrentCenterX + currentWidth / 2,
+                    mCurrentCenterY + currentHeight / 2);
 
             float currentPlayTime = mRectScaleAnimEnded ? mRectScaleAnim.getDuration()
                     : mRectScaleAnim.getCurrentPlayTime();
diff --git a/quickstep/src/com/android/quickstep/util/StaggeredWorkspaceAnim.java b/quickstep/src/com/android/quickstep/util/StaggeredWorkspaceAnim.java
index 0ea1fca..d430028 100644
--- a/quickstep/src/com/android/quickstep/util/StaggeredWorkspaceAnim.java
+++ b/quickstep/src/com/android/quickstep/util/StaggeredWorkspaceAnim.java
@@ -20,7 +20,6 @@
 import static com.android.launcher3.LauncherState.NORMAL;
 import static com.android.launcher3.anim.Interpolators.LINEAR;
 import static com.android.launcher3.anim.PropertySetter.NO_ANIM_PROPERTY_SETTER;
-import static com.android.launcher3.config.FeatureFlags.PROTOTYPE_APP_CLOSE;
 import static com.android.launcher3.states.StateAnimationConfig.SKIP_DEPTH_CONTROLLER;
 import static com.android.launcher3.states.StateAnimationConfig.SKIP_OVERVIEW;
 import static com.android.launcher3.states.StateAnimationConfig.SKIP_SCRIM;
@@ -71,6 +70,11 @@
     private final AnimatorSet mAnimators = new AnimatorSet();
 
     public StaggeredWorkspaceAnim(Launcher launcher, float velocity, boolean animateOverviewScrim) {
+        this(launcher, velocity, animateOverviewScrim, true);
+    }
+
+    public StaggeredWorkspaceAnim(Launcher launcher, float velocity, boolean animateOverviewScrim,
+            boolean staggerWorkspace) {
         prepareToAnimate(launcher, animateOverviewScrim);
 
         mVelocity = velocity;
@@ -81,53 +85,66 @@
         mSpringTransY = transFactor * launcher.getResources()
                 .getDimensionPixelSize(R.dimen.swipe_up_max_workspace_trans_y);
 
-        DeviceProfile grid = launcher.getDeviceProfile();
-        Workspace workspace = launcher.getWorkspace();
-        Hotseat hotseat = launcher.getHotseat();
+        if (staggerWorkspace) {
+            DeviceProfile grid = launcher.getDeviceProfile();
+            Workspace workspace = launcher.getWorkspace();
+            Hotseat hotseat = launcher.getHotseat();
 
-        // Hotseat and QSB takes up two additional rows.
-        int totalRows = grid.inv.numRows + (grid.isVerticalBarLayout() ? 0 : 2);
+            // Hotseat and QSB takes up two additional rows.
+            int totalRows = grid.inv.numRows + (grid.isVerticalBarLayout() ? 0 : 2);
 
-        // Add animation for all the visible workspace pages
-        workspace.forEachVisiblePage(page -> addAnimationForPage((CellLayout) page, totalRows));
+            // Add animation for all the visible workspace pages
+            workspace.forEachVisiblePage(page -> addAnimationForPage((CellLayout) page, totalRows));
 
-        boolean workspaceClipChildren = workspace.getClipChildren();
-        boolean workspaceClipToPadding = workspace.getClipToPadding();
-        boolean hotseatClipChildren = hotseat.getClipChildren();
-        boolean hotseatClipToPadding = hotseat.getClipToPadding();
+            boolean workspaceClipChildren = workspace.getClipChildren();
+            boolean workspaceClipToPadding = workspace.getClipToPadding();
+            boolean hotseatClipChildren = hotseat.getClipChildren();
+            boolean hotseatClipToPadding = hotseat.getClipToPadding();
 
-        workspace.setClipChildren(false);
-        workspace.setClipToPadding(false);
-        hotseat.setClipChildren(false);
-        hotseat.setClipToPadding(false);
+            workspace.setClipChildren(false);
+            workspace.setClipToPadding(false);
+            hotseat.setClipChildren(false);
+            hotseat.setClipToPadding(false);
 
-        // Set up springs for the hotseat and qsb.
-        ViewGroup hotseatIcons = hotseat.getShortcutsAndWidgets();
-        if (grid.isVerticalBarLayout()) {
-            for (int i = hotseatIcons.getChildCount() - 1; i >= 0; i--) {
-                View child = hotseatIcons.getChildAt(i);
-                CellLayout.LayoutParams lp = ((CellLayout.LayoutParams) child.getLayoutParams());
-                addStaggeredAnimationForView(child, lp.cellY + 1, totalRows);
-            }
-        } else {
-            final int hotseatRow, qsbRow, taskbarRow;
-            if (grid.isTaskbarPresent) {
-                qsbRow = grid.inv.numRows + 1;
-                hotseatRow = grid.inv.numRows + 2;
+            // Set up springs for the hotseat and qsb.
+            ViewGroup hotseatIcons = hotseat.getShortcutsAndWidgets();
+            if (grid.isVerticalBarLayout()) {
+                for (int i = hotseatIcons.getChildCount() - 1; i >= 0; i--) {
+                    View child = hotseatIcons.getChildAt(i);
+                    CellLayout.LayoutParams lp =
+                            ((CellLayout.LayoutParams) child.getLayoutParams());
+                    addStaggeredAnimationForView(child, lp.cellY + 1, totalRows);
+                }
             } else {
-                hotseatRow = grid.inv.numRows + 1;
-                qsbRow = grid.inv.numRows + 2;
-            }
-            // Taskbar and hotseat overlap.
-            taskbarRow = hotseatRow;
+                final int hotseatRow, qsbRow, taskbarRow;
+                if (grid.isTaskbarPresent) {
+                    qsbRow = grid.inv.numRows + 1;
+                    hotseatRow = grid.inv.numRows + 2;
+                } else {
+                    hotseatRow = grid.inv.numRows + 1;
+                    qsbRow = grid.inv.numRows + 2;
+                }
+                // Taskbar and hotseat overlap.
+                taskbarRow = hotseatRow;
 
-            for (int i = hotseatIcons.getChildCount() - 1; i >= 0; i--) {
-                View child = hotseatIcons.getChildAt(i);
-                addStaggeredAnimationForView(child, hotseatRow, totalRows);
+                for (int i = hotseatIcons.getChildCount() - 1; i >= 0; i--) {
+                    View child = hotseatIcons.getChildAt(i);
+                    addStaggeredAnimationForView(child, hotseatRow, totalRows);
+                }
+
+                addStaggeredAnimationForView(hotseat.getQsb(), qsbRow, totalRows);
+                addStaggeredAnimationForView(hotseat.getTaskbarView(), taskbarRow, totalRows);
             }
 
-            addStaggeredAnimationForView(hotseat.getQsb(), qsbRow, totalRows);
-            addStaggeredAnimationForView(hotseat.getTaskbarView(), taskbarRow, totalRows);
+            mAnimators.addListener(new AnimatorListenerAdapter() {
+                @Override
+                public void onAnimationEnd(Animator animation) {
+                    workspace.setClipChildren(workspaceClipChildren);
+                    workspace.setClipToPadding(workspaceClipToPadding);
+                    hotseat.setClipChildren(hotseatClipChildren);
+                    hotseat.setClipToPadding(hotseatClipToPadding);
+                }
+            });
         }
 
         if (animateOverviewScrim) {
@@ -141,15 +158,6 @@
 
         mAnimators.play(launcher.getRootView().getSysUiScrim().createSysuiMultiplierAnim(0f, 1f)
                 .setDuration(DURATION_MS));
-        mAnimators.addListener(new AnimatorListenerAdapter() {
-            @Override
-            public void onAnimationEnd(Animator animation) {
-                workspace.setClipChildren(workspaceClipChildren);
-                workspace.setClipToPadding(workspaceClipToPadding);
-                hotseat.setClipChildren(hotseatClipChildren);
-                hotseat.setClipToPadding(hotseatClipToPadding);
-            }
-        });
     }
 
     private void addAnimationForPage(CellLayout page, int totalRows) {
@@ -220,9 +228,6 @@
      * @param totalRows Total number of rows.
      */
     private void addStaggeredAnimationForView(View v, int row, int totalRows) {
-        if (PROTOTYPE_APP_CLOSE.get()) {
-            return;
-        }
         // Invert the rows, because we stagger starting from the bottom of the screen.
         int invertedRow = totalRows - row;
         // Add 1 to the inverted row so that the bottom most row has a start delay.
diff --git a/res/values/config.xml b/res/values/config.xml
index e65c652..102d4e0 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -127,12 +127,12 @@
     <item name="swipe_up_rect_xy_fling_friction" type="dimen" format="float">1.5</item>
 
     <item name="swipe_up_scale_start"  type="dimen" format="float">0.98</item>
-    <item name="swipe_up_duration"  type="dimen" format="float">500</item>
+    <item name="swipe_up_duration"  type="dimen" format="float">400</item>
 
-    <item name="swipe_up_trans_y_dp"  type="dimen" format="float">3</item>
+    <item name="swipe_up_trans_y_dp"  type="dimen" format="float">4.5</item>
     <item name="swipe_up_trans_y_dp_per_s" type="dimen" format="float">3</item>
 
-    <item name="swipe_up_trans_y_damping" type="dimen" format="float">0.4</item>
+    <item name="swipe_up_trans_y_damping" type="dimen" format="float">0.45</item>
     <item name="swipe_up_trans_y_stiffness" type="dimen" format="float">200</item>
 
     <item name="swipe_up_rect_xy_damping_ratio" type="dimen" format="float">0.8</item>
@@ -140,12 +140,12 @@
 
 
     <item name="swipe_up_rect_2_x_damping_ratio" type="dimen" format="float">1</item>
-    <item name="swipe_up_rect_2_x_stiffness" type="dimen" format="float">350</item>
+    <item name="swipe_up_rect_2_x_stiffness" type="dimen" format="float">250</item>
 
     <item name="swipe_up_rect_2_y_damping_ratio" type="dimen" format="float">1</item>
-    <item name="swipe_up_rect_2_y_stiffness" type="dimen" format="float">700</item>
+    <item name="swipe_up_rect_2_y_stiffness" type="dimen" format="float">600</item>
 
-    <item name="swipe_up_rect_2_y_stiffness_low_swipe_multiplier" type="dimen" format="float">1</item>
+    <item name="swipe_up_rect_2_y_stiffness_low_swipe_multiplier" type="dimen" format="float">0.8</item>
     <item name="swipe_up_low_swipe_duration_multiplier"  type="dimen" format="float">1</item>
 
     <item name="swipe_up_launcher_alpha_max_progress" type="dimen" format="float">0.85</item>
diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java
index 7ef43ed..0c0c92e 100644
--- a/src/com/android/launcher3/config/FeatureFlags.java
+++ b/src/com/android/launcher3/config/FeatureFlags.java
@@ -238,7 +238,7 @@
             "Sends a notification whenever launcher encounters an uncaught exception.");
 
     public static final BooleanFlag PROTOTYPE_APP_CLOSE = getDebugFlag(
-            "PROTOTYPE_APP_CLOSE", false, "Enables new app close");
+            "PROTOTYPE_APP_CLOSE", true, "Enables new app close");
 
     public static final BooleanFlag ENABLE_WALLPAPER_SCRIM = getDebugFlag(
             "ENABLE_WALLPAPER_SCRIM", false,