Fix screen rounded corner flicker.

We've previously always played transitions with a fixed start corner
radius. This should however be an interpolated value based on gesture
progress.

Bug: 230115505
Test: Turn on predictive animations. Try completing a back swipe as well
as canceling a back swipe. Observe corner radius to make sure there's no
flicker.

Change-Id: Iae2517d969ed1b779bced866407b939b3a011b68
diff --git a/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java b/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java
index 0f3474e..9f35401 100644
--- a/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java
+++ b/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java
@@ -1354,7 +1354,7 @@
      */
     private RectFSpringAnim getClosingWindowAnimators(AnimatorSet animation,
             RemoteAnimationTargetCompat[] targets, View launcherView, PointF velocityPxPerS,
-            RectF closingWindowStartRect) {
+            RectF closingWindowStartRect, float startWindowCornerRadius) {
         FloatingIconView floatingIconView = null;
         FloatingWidgetView floatingWidget = null;
         RectF targetRect = new RectF();
@@ -1403,7 +1403,7 @@
             final float windowAlphaThreshold = 1f - SHAPE_PROGRESS_DURATION;
 
             RectFSpringAnim.OnUpdateListener runner = new SpringAnimRunner(targets, targetRect,
-                    windowTargetBounds) {
+                    windowTargetBounds, startWindowCornerRadius) {
                 @Override
                 public void onUpdate(RectF currentRectF, float progress) {
                     finalFloatingIconView.update(1f, 255 /* fgAlpha */, currentRectF, progress,
@@ -1421,7 +1421,7 @@
             final float floatingWidgetAlpha = isTransluscent ? 0 : 1;
             FloatingWidgetView finalFloatingWidget = floatingWidget;
             RectFSpringAnim.OnUpdateListener runner = new SpringAnimRunner(targets, targetRect,
-                    windowTargetBounds) {
+                    windowTargetBounds, startWindowCornerRadius) {
                 @Override
                 public void onUpdate(RectF currentRectF, float progress) {
                     final float fallbackBackgroundAlpha =
@@ -1438,7 +1438,8 @@
         } else {
             // If no floating icon or widget is present, animate the to the default window
             // target rect.
-            anim.addOnUpdateListener(new SpringAnimRunner(targets, targetRect, windowTargetBounds));
+            anim.addOnUpdateListener(new SpringAnimRunner(
+                    targets, targetRect, windowTargetBounds, startWindowCornerRadius));
         }
 
         // Use a fixed velocity to start the animation.
@@ -1580,7 +1581,8 @@
             RemoteAnimationTargetCompat[] appTargets,
             RemoteAnimationTargetCompat[] wallpaperTargets,
             boolean fromUnlock,
-            RectF startRect) {
+            RectF startRect,
+            float startWindowCornerRadius) {
         AnimatorSet anim = null;
         RectFSpringAnim rectFSpringAnim = null;
 
@@ -1612,7 +1614,8 @@
                         .getDimension(R.dimen.unlock_staggered_velocity_dp_per_s);
                 PointF velocity = new PointF(0, -velocityPxPerS);
                 rectFSpringAnim = getClosingWindowAnimators(
-                        anim, appTargets, launcherView, velocity, startRect);
+                        anim, appTargets, launcherView, velocity, startRect,
+                        startWindowCornerRadius);
                 if (!mLauncher.isInState(LauncherState.ALL_APPS)) {
                     anim.play(new StaggeredWorkspaceAnim(mLauncher, velocity.y,
                             true /* animateOverviewScrim */, launcherView).getAnimators());
@@ -1711,7 +1714,8 @@
 
             Pair<RectFSpringAnim, AnimatorSet> pair = createWallpaperOpenAnimations(
                     appTargets, wallpaperTargets, mFromUnlock,
-                    new RectF(0, 0, mDeviceProfile.widthPx, mDeviceProfile.heightPx));
+                    new RectF(0, 0, mDeviceProfile.widthPx, mDeviceProfile.heightPx),
+                    QuickStepContract.getWindowCornerRadius(mLauncher));
 
             mLauncher.clearForceInvisibleFlag(INVISIBLE_ALL);
             result.setAnimation(pair.second, mLauncher);
@@ -1874,9 +1878,9 @@
         private final Rect mTmpRect = new Rect();
 
         SpringAnimRunner(RemoteAnimationTargetCompat[] appTargets, RectF targetRect,
-                Rect windowTargetBounds) {
+                Rect windowTargetBounds, float startWindowCornerRadius) {
             mAppTargets = appTargets;
-            mStartRadius = QuickStepContract.getWindowCornerRadius(mLauncher);
+            mStartRadius = startWindowCornerRadius;
             mEndRadius = Math.max(1, targetRect.width()) / 2f;
             mSurfaceApplier = new SurfaceTransactionApplier(mDragLayer);
             mWindowTargetBounds.set(windowTargetBounds);
diff --git a/quickstep/src/com/android/quickstep/LauncherBackAnimationController.java b/quickstep/src/com/android/quickstep/LauncherBackAnimationController.java
index 921674a..6e81b6f 100644
--- a/quickstep/src/com/android/quickstep/LauncherBackAnimationController.java
+++ b/quickstep/src/com/android/quickstep/LauncherBackAnimationController.java
@@ -29,7 +29,6 @@
 import android.graphics.Rect;
 import android.graphics.RectF;
 import android.os.Handler;
-import android.util.MathUtils;
 import android.util.Pair;
 import android.view.RemoteAnimationTarget;
 import android.view.SurfaceControl;
@@ -195,10 +194,10 @@
         float followWidth = screenWidth - dX;
         // The 'progress width' is the width of the window if it strictly linearly interpolates
         // to minimum scale base on progress.
-        float progressWidth = MathUtils.lerp(1, MIN_WINDOW_SCALE, progress) * screenWidth;
+        float progressWidth = Utilities.mapRange(progress, 1, MIN_WINDOW_SCALE) * screenWidth;
         // The final width is derived from interpolating between the follow with and progress width
         // using gesture progress.
-        float width = MathUtils.lerp(followWidth, progressWidth, progress);
+        float width = Utilities.mapRange(progress, followWidth, progressWidth);
         float height = screenHeight / screenWidth * width;
         float deltaYRatio = (event.getTouchY() - mInitialTouchPos.y) / screenHeight;
         // Base the window movement in the Y axis on the touch movement in the Y axis.
@@ -221,13 +220,15 @@
             return;
         }
         mCurrentRect.set(
-                MathUtils.lerp(mCancelRect.left, mStartRect.left, progress),
-                MathUtils.lerp(mCancelRect.top, mStartRect.top, progress),
-                MathUtils.lerp(mCancelRect.right, mStartRect.right, progress),
-                MathUtils.lerp(mCancelRect.bottom, mStartRect.bottom, progress));
+                Utilities.mapRange(progress, mCancelRect.left, mStartRect.left),
+                Utilities.mapRange(progress, mCancelRect.top, mStartRect.top),
+                Utilities.mapRange(progress, mCancelRect.right, mStartRect.right),
+                Utilities.mapRange(progress, mCancelRect.bottom, mStartRect.bottom));
 
+        float endCornerRadius = Utilities.mapRange(
+                mBackProgress, mWindowScaleStartCornerRadius, mWindowScaleEndCornerRadius);
         float cornerRadius = Utilities.mapRange(
-                progress, mWindowScaleEndCornerRadius, mWindowScaleStartCornerRadius);
+                progress, endCornerRadius, mWindowScaleStartCornerRadius);
         applyTransform(mCurrentRect, cornerRadius);
     }
 
@@ -267,12 +268,15 @@
             mLauncher.getStateManager().moveToRestState();
         }
 
+        float cornerRadius = Utilities.mapRange(
+                mBackProgress, mWindowScaleStartCornerRadius, mWindowScaleEndCornerRadius);
         Pair<RectFSpringAnim, AnimatorSet> pair =
                 mQuickstepTransitionManager.createWallpaperOpenAnimations(
                     new RemoteAnimationTargetCompat[]{mBackTarget},
                     new RemoteAnimationTargetCompat[]{},
                     false /* fromUnlock */,
-                    mCurrentRect);
+                    mCurrentRect,
+                    cornerRadius);
         startTransitionAnimations(pair.first, pair.second);
         mLauncher.clearForceInvisibleFlag(INVISIBLE_ALL);
     }