Update scale logic for desktop tasks in recents animation

When swiping up to overview, we need to calculate a target position for
the desktop tasks. They need to be scaled down and positioned within the
desktop tile.
After recents animation finishes, the tasks will be replaced by
screenshots. To make the replace less flickery, the position of the
tasks should match the position of the screenshots.

TODO: there is a flicker when the task is replaced with recents entry.
      Task is hidden and then, half a second later, the recents tile is
      shown. Enabling live tiles should help with this.

Bug: 298252273
Test: swipe up to recents from desktop
Change-Id: I0c7fba40dc2511c17d0011d0516456de07cfa004
diff --git a/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java b/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java
index 48dadd1..25b9bdc 100644
--- a/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java
+++ b/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java
@@ -146,12 +146,6 @@
             return 1;
         }
 
-        if (mIsDesktopTask) {
-            mTaskRect.set(mThumbnailPosition);
-            mPivot.set(mTaskRect.centerX(), mTaskRect.centerY());
-            return 1;
-        }
-
         if (mIsGridTask) {
             mSizeStrategy.calculateGridTaskSize(mContext, mDp, mTaskRect,
                     mOrientationState.getOrientationHandler());
@@ -169,6 +163,20 @@
             mOrientationState.getOrientationHandler()
                     .setSplitTaskSwipeRect(mDp, mTaskRect, mSplitBounds, mStagePosition);
             mTaskRect.offset(mTaskRectTranslationX, mTaskRectTranslationY);
+        } else if (mIsDesktopTask) {
+            // For desktop, tasks can take up only part of the screen size.
+            // Full task size represents the whole screen size, but scaled down to fit in recents.
+            // Task rect will represent the scaled down thumbnail position and is placed inside
+            // full task size as it is on the home screen.
+            fullTaskSize = new Rect(mTaskRect);
+            PointF fullscreenTaskDimension = new PointF();
+            BaseActivityInterface.getTaskDimension(mContext, mDp, fullscreenTaskDimension);
+            // Calculate the scale down factor used in recents
+            float scale = fullTaskSize.width() / fullscreenTaskDimension.x;
+            mTaskRect.set(mThumbnailPosition);
+            mTaskRect.scale(scale);
+            // Ensure the task rect is inside the full task rect
+            mTaskRect.offset(fullTaskSize.left, fullTaskSize.top);
         } else {
             fullTaskSize = mTaskRect;
         }