Merge "Hide overview and app icon split option when appropriate" into sc-v2-dev
diff --git a/quickstep/src/com/android/quickstep/TaskOverlayFactory.java b/quickstep/src/com/android/quickstep/TaskOverlayFactory.java
index eb5c43f..978fb57 100644
--- a/quickstep/src/com/android/quickstep/TaskOverlayFactory.java
+++ b/quickstep/src/com/android/quickstep/TaskOverlayFactory.java
@@ -107,6 +107,13 @@
 
     public static void addSplitOptions(List<SystemShortcut> outShortcuts,
             BaseDraggingActivity activity, TaskView taskView, DeviceProfile deviceProfile) {
+        int[] taskViewTaskIds = taskView.getTaskIds();
+        boolean alreadyHasMultipleTasks = taskViewTaskIds[0] != -1 &&
+                taskViewTaskIds[1] != -1;
+        if (alreadyHasMultipleTasks) {
+            return;
+        }
+
         PagedOrientationHandler orientationHandler =
                 taskView.getRecentsView().getPagedOrientationHandler();
         List<SplitPositionOption> positions =
diff --git a/quickstep/src/com/android/quickstep/views/OverviewActionsView.java b/quickstep/src/com/android/quickstep/views/OverviewActionsView.java
index 5d1c202..1b28c53 100644
--- a/quickstep/src/com/android/quickstep/views/OverviewActionsView.java
+++ b/quickstep/src/com/android/quickstep/views/OverviewActionsView.java
@@ -223,7 +223,6 @@
         mDp = dp;
         updateVerticalMargin(SysUINavigationMode.getMode(getContext()));
         requestLayout();
-        setSplitButtonVisible(mDp.isTablet);
     }
 
     public void setSplitButtonVisible(boolean visible) {
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index aeb10aa..4420b53 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -1506,7 +1506,7 @@
         mActionsView.setDp(dp);
         mOrientationState.setDeviceProfile(dp);
 
-        // Update RecentsView adn TaskView's DeviceProfile dependent layout.
+        // Update RecentsView and TaskView's DeviceProfile dependent layout.
         updateOrientationHandler();
     }
 
@@ -2599,7 +2599,6 @@
         mFirstFloatingTaskView.setAlpha(1);
         mFirstFloatingTaskView.addAnimation(anim, startingTaskRect,
                 mTempRect, mSplitHiddenTaskView, true /*fadeWithThumbnail*/);
-        anim.addEndListener(aBoolean -> mActionsView.setSplitButtonVisible(false));
     }
 
     /**
@@ -2939,6 +2938,7 @@
                         dispatchScrollChanged();
                     }
                 }
+                updateFocusedSplitButtonVisibility();
                 onDismissAnimationEnds();
                 mPendingAnimation = null;
             }
@@ -2947,6 +2947,19 @@
     }
 
     /**
+     * Shows split button if
+     * * We're in large screen
+     * * We're not already in split
+     * * There are at least 2 tasks to invoke split
+     */
+    private void updateFocusedSplitButtonVisibility() {
+        mActionsView.setSplitButtonVisible(mActivity.getDeviceProfile().isTablet &&
+                !(getRunningTaskView() instanceof GroupedTaskView) &&
+                getTaskViewCount() > 1
+        );
+    }
+
+    /**
      * Returns all the tasks in the top row, without the focused task
      */
     private IntArray getTopRowIdArray() {
@@ -3751,7 +3764,6 @@
             mSecondSplitHiddenTaskView.setVisibility(VISIBLE);
             mSecondSplitHiddenTaskView = null;
         }
-        mActionsView.setSplitButtonVisible(true);
     }
 
     private void updateDeadZoneRects() {
@@ -3966,6 +3978,7 @@
     @Override
     protected void notifyPageSwitchListener(int prevPage) {
         super.notifyPageSwitchListener(prevPage);
+        updateFocusedSplitButtonVisibility();
         loadVisibleTaskData(TaskView.FLAG_UPDATE_ALL);
         updateEnabledOverlays();
     }