Prevent thumbnails from shifting if placeholder view doesn't overlap

Always shift thumbnails when in phone mode.

Bug: 181705607
Test: Placeholder view didn't shift when no thumbnails underneath
it in portrait.

Change-Id: Ib2f066fdf17134b3f5bbd9b465b87868e9ce7583
diff --git a/quickstep/src/com/android/launcher3/uioverrides/BaseRecentsViewStateController.java b/quickstep/src/com/android/launcher3/uioverrides/BaseRecentsViewStateController.java
index e508690..2eb19ec 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/BaseRecentsViewStateController.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/BaseRecentsViewStateController.java
@@ -105,7 +105,7 @@
                 TASK_PRIMARY_SPLIT_TRANSLATION, TASK_SECONDARY_SPLIT_TRANSLATION,
                 mLauncher.getDeviceProfile());
         setter.setFloat(mRecentsView, taskViewsFloat,
-                toState.getOverviewSecondaryTranslation(mLauncher), LINEAR);
+                toState.getSplitSelectTranslation(mLauncher), LINEAR);
 
         setter.setFloat(mRecentsView, getContentAlphaProperty(), toState.overviewUi ? 1 : 0,
                 config.getInterpolator(ANIM_OVERVIEW_FADE, AGGRESSIVE_EASE_IN_OUT));
diff --git a/quickstep/src/com/android/launcher3/uioverrides/states/SplitScreenSelectState.java b/quickstep/src/com/android/launcher3/uioverrides/states/SplitScreenSelectState.java
index 722d74a..6968494 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/states/SplitScreenSelectState.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/states/SplitScreenSelectState.java
@@ -41,11 +41,14 @@
     }
 
     @Override
-    public float getOverviewSecondaryTranslation(Launcher launcher) {
+    public float getSplitSelectTranslation(Launcher launcher) {
         RecentsView recentsView = launcher.getOverviewPanel();
-        PagedOrientationHandler orientationHandler = recentsView.getPagedOrientationHandler();
         int splitPosition = recentsView.getSplitPlaceholder().getSplitController()
                 .getActiveSplitPositionOption().mStagePosition;
+        if (!recentsView.shouldShiftThumbnailsForSplitSelect(splitPosition)) {
+            return 0f;
+        }
+        PagedOrientationHandler orientationHandler = recentsView.getPagedOrientationHandler();
         int direction = orientationHandler.getSplitTranslationDirectionFactor(splitPosition);
         return launcher.getResources().getDimension(R.dimen.split_placeholder_size) * direction;
     }
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index a04b886..cf94d68 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -124,6 +124,7 @@
 import com.android.launcher3.util.IntSet;
 import com.android.launcher3.util.MultiValueAlpha;
 import com.android.launcher3.util.ResourceBasedOverride.Overrides;
+import com.android.launcher3.util.SplitConfigurationOptions;
 import com.android.launcher3.util.SplitConfigurationOptions.SplitPositionOption;
 import com.android.launcher3.util.Themes;
 import com.android.launcher3.util.TranslateEdgeEffect;
@@ -2367,6 +2368,47 @@
         return anim;
     }
 
+    /**
+     * @return {@code true} if one of the task thumbnails would intersect/overlap with the
+     *         {@link #mSplitPlaceholderView}
+     */
+    public boolean shouldShiftThumbnailsForSplitSelect(@SplitConfigurationOptions.StagePosition
+            int stagePosition) {
+        if (!mActivity.getDeviceProfile().isTablet) {
+            // Never enough space on phones
+            return true;
+        } else if (!mActivity.getDeviceProfile().isLandscape) {
+            return false;
+        }
+
+        Rect splitBounds = new Rect();
+        float placeholderSize = getResources().getDimension(R.dimen.split_placeholder_size);
+        // This acts as a best approximation on where the splitplaceholder view would be,
+        // doesn't need to be exact necessarily. This also doesn't need to take translations
+        // into account since placeholder view is not translated
+        if (stagePosition == SplitConfigurationOptions.STAGE_POSITION_BOTTOM_OR_RIGHT) {
+            splitBounds.set((int) (getWidth() - placeholderSize), 0, getWidth(), getHeight());
+        } else {
+            splitBounds.set(0, 0, (int) (placeholderSize), getHeight());
+        }
+        Rect taskBounds = new Rect();
+        int taskCount = getTaskViewCount();
+        for (int i = 0; i < taskCount; i++) {
+            TaskView taskView = getTaskViewAt(i);
+            if (taskView == mSplitHiddenTaskView && taskView != getFocusedTaskView()) {
+                // Case where the hidden task view would have overlapped w/ placeholder,
+                // but because it's going to hide we don't care
+                // TODO (b/187312247) edge case for thumbnails that are off screen but scroll on
+                continue;
+            }
+            taskView.getBoundsOnScreen(taskBounds);
+            if (Rect.intersects(taskBounds, splitBounds)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     protected void onDismissAnimationEnds() {
     }
 
diff --git a/src/com/android/launcher3/LauncherState.java b/src/com/android/launcher3/LauncherState.java
index 9d50edd..8432f4b 100644
--- a/src/com/android/launcher3/LauncherState.java
+++ b/src/com/android/launcher3/LauncherState.java
@@ -237,10 +237,10 @@
     }
 
     /**
-     * For this state, how much additional vertical translation there should be for each of the
-     * child TaskViews.
+     * For this state, how much additional translation there should be for each of the
+     * child TaskViews. Note that the translation can be its primary or secondary dimension.
      */
-    public float getOverviewSecondaryTranslation(Launcher launcher) {
+    public float getSplitSelectTranslation(Launcher launcher) {
         return 0;
     }