Merge "Fix right split screen app going to wrong target" into sc-v2-dev am: 9a0d98f483 am: 9e3792819d

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/15900907

Change-Id: I24e976fd4b8be4cead3569631e4e451e9a84a656
diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
index 47c865f..11b9df0 100644
--- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
+++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
@@ -108,7 +108,6 @@
 import com.android.quickstep.util.SurfaceTransactionApplier;
 import com.android.quickstep.util.SwipePipToHomeAnimator;
 import com.android.quickstep.util.TaskViewSimulator;
-import com.android.quickstep.util.TransformParams;
 import com.android.quickstep.util.VibratorWrapper;
 import com.android.quickstep.views.RecentsView;
 import com.android.quickstep.views.TaskView;
@@ -1342,9 +1341,10 @@
         final int windowRotation = calculateWindowRotation(runningTaskTarget, orientationState);
         final int homeRotation = orientationState.getRecentsActivityRotation();
 
-        final Matrix homeToWindowPositionMap = new Matrix();
-        final RectF startRect = updateProgressForStartRect(homeToWindowPositionMap,
+        final Matrix[] homeToWindowPositionMaps = new Matrix[mRemoteTargetHandles.length];
+        final RectF startRect = updateProgressForStartRect(homeToWindowPositionMaps,
                 startProgress)[0];
+        final Matrix homeToWindowPositionMap = homeToWindowPositionMaps[0];
         // Move the startRect to Launcher space as floatingIconView runs in Launcher
         final Matrix windowToHomePositionMap = new Matrix();
         homeToWindowPositionMap.invert(windowToHomePositionMap);
diff --git a/quickstep/src/com/android/quickstep/SwipeUpAnimationLogic.java b/quickstep/src/com/android/quickstep/SwipeUpAnimationLogic.java
index 2fee945..f64d506 100644
--- a/quickstep/src/com/android/quickstep/SwipeUpAnimationLogic.java
+++ b/quickstep/src/com/android/quickstep/SwipeUpAnimationLogic.java
@@ -227,7 +227,7 @@
      * @param startProgress The progress of {@link #mCurrentShift} to start thw window from.
      * @return {@link RectF} represents the bounds as starting point in window space.
      */
-    protected RectF[] updateProgressForStartRect(Matrix outMatrix, float startProgress) {
+    protected RectF[] updateProgressForStartRect(Matrix[] outMatrix, float startProgress) {
         mCurrentShift.updateValue(startProgress);
         RectF[] startRects = new RectF[mRemoteTargetHandles.length];
         for (int i = 0, mRemoteTargetHandlesLength = mRemoteTargetHandles.length;
@@ -237,7 +237,8 @@
             tvs.apply(remoteHandle.getTransformParams().setProgress(startProgress));
 
             startRects[i] = new RectF(tvs.getCurrentCropRect());
-            tvs.applyWindowToHomeRotation(outMatrix);
+            outMatrix[i] = new Matrix();
+            tvs.applyWindowToHomeRotation(outMatrix[i]);
             tvs.getCurrentMatrix().mapRect(startRects[i]);
         }
         return startRects;
@@ -267,14 +268,14 @@
         // TODO(b/195473584) compute separate end targets for different staged split
         final RectF targetRect = homeAnimationFactory.getWindowTargetRect();
         RectFSpringAnim[] out = new RectFSpringAnim[mRemoteTargetHandles.length];
-        Matrix homeToWindowPositionMap = new Matrix();
+        Matrix[] homeToWindowPositionMap = new Matrix[mRemoteTargetHandles.length];
         RectF[] startRects = updateProgressForStartRect(homeToWindowPositionMap, startProgress);
         for (int i = 0, mRemoteTargetHandlesLength = mRemoteTargetHandles.length;
                 i < mRemoteTargetHandlesLength; i++) {
             RemoteTargetHandle remoteHandle = mRemoteTargetHandles[i];
             out[i] = getWindowAnimationToHomeInternal(homeAnimationFactory,
                     targetRect, remoteHandle.getTransformParams(),
-                    remoteHandle.getTaskViewSimulator(), startRects[i], homeToWindowPositionMap);
+                    remoteHandle.getTaskViewSimulator(), startRects[i], homeToWindowPositionMap[i]);
         }
         return out;
     }
diff --git a/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java b/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java
index 849a7bc..e88ebcf 100644
--- a/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java
+++ b/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java
@@ -256,12 +256,14 @@
      * window coordinate space.
      */
     public void applyWindowToHomeRotation(Matrix matrix) {
-        mMatrix.postTranslate(mDp.windowX, mDp.windowY);
+        matrix.postTranslate(mDp.windowX, mDp.windowY);
         postDisplayRotation(deltaRotation(
                 mOrientationState.getRecentsActivityRotation(),
                 mOrientationState.getDisplayRotation()),
                 mDp.widthPx, mDp.heightPx, matrix);
         matrix.postTranslate(-mRunningTargetWindowPosition.x, -mRunningTargetWindowPosition.y);
+        // Move lower/right split window into correct position
+        matrix.postTranslate(mSplitOffset.x, mSplitOffset.y);
     }
 
     /**
@@ -326,9 +328,6 @@
                 recentsViewPrimaryTranslation.value);
         applyWindowToHomeRotation(mMatrix);
 
-        // Move lower/right split window into correct position
-        mMatrix.postTranslate(mSplitOffset.x, mSplitOffset.y);
-
         // Crop rect is the inverse of thumbnail matrix
         mTempRectF.set(-insets.left, -insets.top,
                 taskWidth + insets.right, taskHeight + insets.bottom);