Fix live tile regression in quick switch mode

We registered a hook to call updateFinalShift() when recents view has scroll change to support scrolling recents side to side during swipe up from an app (ag/5514447). This breaks the current flow of quick switch in live tile mode where we close the LauncherLayoutListener upon quickswitch transition is finished. (Since updateFinalShift is called, we reopen LauncherLayoutListener.)

Further, live tile previously had an assumption that live tile can only go off screen on the right. Because getGlobalVisibleRect() has the limitation of only getting coordinates on the screen, our calculation to fill the missing offscreen part to transform app window does not work for the case when live tile is going off screen on the left (e.g. quick switch).

Fixes: 123915937
Test: Turn off quick switch and scrub from an app. Verify that live tile rendering is correct.

Change-Id: I5fa7e38b80309f083227240c24847f88a2c1cc28
diff --git a/quickstep/src/com/android/quickstep/QuickScrubController.java b/quickstep/src/com/android/quickstep/QuickScrubController.java
index db0150e..ab5fce1 100644
--- a/quickstep/src/com/android/quickstep/QuickScrubController.java
+++ b/quickstep/src/com/android/quickstep/QuickScrubController.java
@@ -267,6 +267,10 @@
         return mWaitingForTaskLaunch;
     }
 
+    public boolean hasFinishedTransitionToQuickScrub() {
+        return mFinishedTransitionToQuickScrub;
+    }
+
     /**
      * Attempts to go to normal overview or back to home, so UI doesn't prevent user interaction.
      */
diff --git a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
index 0e9ddee..d4375b5 100644
--- a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
+++ b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
@@ -703,7 +703,9 @@
         }
 
         if (ENABLE_QUICKSTEP_LIVE_TILE.get()) {
-            if (mRecentsAnimationWrapper.getController() != null && mLayoutListener != null) {
+            if (mRecentsAnimationWrapper.getController() != null && mLayoutListener != null &&
+                    (mInteractionType == INTERACTION_NORMAL
+                            || !mQuickScrubController.hasFinishedTransitionToQuickScrub())) {
                 mLayoutListener.open();
                 mLayoutListener.update(mCurrentShift.value > 1, mLongSwipeMode,
                         mClipAnimationHelper.getCurrentRectWithInsets(),
diff --git a/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java b/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java
index 5c8f53c..ba4aadc 100644
--- a/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/LauncherRecentsView.java
@@ -216,7 +216,11 @@
             int offsetY = (int) (mTaskHeight * taskView.getScaleY() * getScaleY()
                     - mTempRect.height());
             if (((mCurrentPage != 0) || mightNeedToRefill) && offsetX > 0) {
-                mTempRect.right += offsetX;
+                if (mTempRect.left - offsetX < 0) {
+                    mTempRect.left -= offsetX;
+                } else {
+                    mTempRect.right += offsetX;
+                }
             }
             if (mightNeedToRefill && offsetY > 0) {
                 mTempRect.top -= offsetY;