Merge "Workaround: don't migrate grid when hotseat size or device type changes in multi display" into sc-v2-dev
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index e25a8bc..8ec600d 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -443,6 +443,7 @@
     protected float mTaskViewsSecondarySplitTranslation = 0;
     // Progress from 0 to 1 where 0 is a carousel and 1 is a 2 row grid.
     private float mGridProgress = 0;
+    private boolean mShowAsGridLastOnLayout = false;
     private final IntSet mTopRowIdSet = new IntSet();
 
     // The GestureEndTarget that is still in progress.
@@ -2095,11 +2096,14 @@
                 .displayOverviewTasksAsGrid(mActivity.getDeviceProfile())) {
             TaskView runningTaskView = getRunningTaskView();
             float runningTaskPrimaryGridTranslation = 0;
-            if (runningTaskView != null && indexOfChild(runningTaskView) != getNextPage()) {
-                // Apply the gird translation to running task unless it's being snapped to.
+            if (runningTaskView != null) {
+                // Apply the grid translation to running task unless it's being snapped to
+                // and removes the current translation applied to the running task.
                 runningTaskPrimaryGridTranslation = mOrientationHandler.getPrimaryValue(
                         runningTaskView.getGridTranslationX(),
-                        runningTaskView.getGridTranslationY());
+                        runningTaskView.getGridTranslationY())
+                        - runningTaskView.getPrimaryNonGridTranslationProperty().get(
+                        runningTaskView);
             }
             for (TaskViewSimulator tvs : taskViewSimulators) {
                 if (animatorSet == null) {
@@ -3556,6 +3560,8 @@
             return;
         }
 
+        mShowAsGridLastOnLayout = showAsGrid();
+
         super.onLayout(changed, left, top, right, bottom);
 
         updateEmptyStateUi(changed);
@@ -4377,7 +4383,7 @@
                 return getScrollForPage(mDisallowScrollToClearAll ? indexOfChild(
                         getTaskViewAt(getTaskViewCount() - 1)) : indexOfChild(mClearAllButton));
             } else {
-                TaskView focusedTaskView = showAsGrid() ? getFocusedTaskView() : null;
+                TaskView focusedTaskView = mShowAsGridLastOnLayout ? getFocusedTaskView() : null;
                 return getScrollForPage(focusedTaskView != null ? indexOfChild(focusedTaskView)
                         : mTaskViewStartIndex);
             }
@@ -4389,7 +4395,7 @@
     protected int computeMaxScroll() {
         if (getTaskViewCount() > 0) {
             if (mIsRtl) {
-                TaskView focusedTaskView = showAsGrid() ? getFocusedTaskView() : null;
+                TaskView focusedTaskView = mShowAsGridLastOnLayout ? getFocusedTaskView() : null;
                 return getScrollForPage(focusedTaskView != null ? indexOfChild(focusedTaskView)
                         : mTaskViewStartIndex);
             } else {
diff --git a/src/com/android/launcher3/DropTargetBar.java b/src/com/android/launcher3/DropTargetBar.java
index eb42a65..08cc730 100644
--- a/src/com/android/launcher3/DropTargetBar.java
+++ b/src/com/android/launcher3/DropTargetBar.java
@@ -275,8 +275,20 @@
     @Override
     protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
         super.onVisibilityChanged(changedView, visibility);
-        if (TestProtocol.sDebugTracing && visibility == VISIBLE) {
-            Log.d(TestProtocol.NO_DROP_TARGET, "9");
+        if (TestProtocol.sDebugTracing) {
+            if (visibility == VISIBLE) {
+                Log.d(TestProtocol.NO_DROP_TARGET, "9");
+            } else {
+                Log.d(TestProtocol.NO_DROP_TARGET, "Hiding drop target", new Exception());
+            }
+        }
+    }
+
+    @Override
+    public void onVisibilityAggregated(boolean isVisible) {
+        super.onVisibilityAggregated(isVisible);
+        if (TestProtocol.sDebugTracing) {
+            Log.d(TestProtocol.NO_DROP_TARGET, "onVisibilityAggregated: " + isVisible);
         }
     }
 }