Fix bug with Taskbar second-app-selection animation

This patch makes it so that the correct animation will play when the user selects a second app from the Taskbar.

Previously, when the user selected a second app from the Taskbar, an animation would play showing the expansion of the app -- but it would come from the wrong place. The error occurred because when we calculate the animation start position, we assume that the starting view is located in the DragLayer, which fills the whole screen. But in cases where the starting view is located in the Taskbar, the root view is actually the TaskbarDragLayer, which only fills an area on the bottom part of the screen.

Fixed by adding a check to see if the starting view is part of the TaskbarActivityContext, and if so, adding an offset to calculate the correct DragLayer coordinates.

Fixes: 258692761
Test: Manual
Change-Id: I4026676fefe1e4c5cdf9d9a47d95c0d6e64672e8
diff --git a/quickstep/src/com/android/quickstep/views/FloatingTaskView.java b/quickstep/src/com/android/quickstep/views/FloatingTaskView.java
index 1d421b2..75a8ea2 100644
--- a/quickstep/src/com/android/quickstep/views/FloatingTaskView.java
+++ b/quickstep/src/com/android/quickstep/views/FloatingTaskView.java
@@ -28,6 +28,7 @@
 import com.android.launcher3.Utilities;
 import com.android.launcher3.anim.PendingAnimation;
 import com.android.launcher3.statemanager.StatefulActivity;
+import com.android.launcher3.taskbar.TaskbarActivityContext;
 import com.android.launcher3.touch.PagedOrientationHandler;
 import com.android.launcher3.util.SplitConfigurationOptions;
 import com.android.launcher3.views.BaseDragLayer;
@@ -85,6 +86,7 @@
     private PagedOrientationHandler mOrientationHandler;
     @SplitConfigurationOptions.StagePosition
     private int mStagePosition;
+    private final Rect mTmpRect = new Rect();
 
     public FloatingTaskView(Context context) {
         this(context, null);
@@ -158,10 +160,24 @@
     }
 
     public void updateInitialPositionForView(View originalView) {
-        Rect viewBounds = new Rect(0, 0, originalView.getWidth(), originalView.getHeight());
-        Utilities.getBoundsForViewInDragLayer(mActivity.getDragLayer(), originalView, viewBounds,
-                false /* ignoreTransform */, null /* recycle */,
-                mStartingPosition);
+        if (originalView.getContext() instanceof TaskbarActivityContext) {
+            // If original View is a button on the Taskbar, find the on-screen bounds and calculate
+            // the equivalent bounds in the DragLayer, so we can set the initial position of
+            // this FloatingTaskView and start the split animation at the correct spot.
+            originalView.getBoundsOnScreen(mTmpRect);
+            mStartingPosition.set(mTmpRect);
+            int[] dragLayerPositionRelativeToScreen =
+                    mActivity.getDragLayer().getLocationOnScreen();
+            mStartingPosition.offset(
+                    -dragLayerPositionRelativeToScreen[0],
+                    -dragLayerPositionRelativeToScreen[1]);
+        } else {
+            Rect viewBounds = new Rect(0, 0, originalView.getWidth(), originalView.getHeight());
+            Utilities.getBoundsForViewInDragLayer(mActivity.getDragLayer(), originalView,
+                    viewBounds, false /* ignoreTransform */, null /* recycle */,
+                    mStartingPosition);
+        }
+
         final BaseDragLayer.LayoutParams lp = new BaseDragLayer.LayoutParams(
                 Math.round(mStartingPosition.width()),
                 Math.round(mStartingPosition.height()));