Merge "Reland "Update Split button visibility based on DeviceProfile change"" into 24D1-dev
diff --git a/quickstep/res/layout/overview_actions_container.xml b/quickstep/res/layout/overview_actions_container.xml
index 5d489f5..d086da4 100644
--- a/quickstep/res/layout/overview_actions_container.xml
+++ b/quickstep/res/layout/overview_actions_container.xml
@@ -21,10 +21,9 @@
 
     <LinearLayout
         android:id="@+id/action_buttons"
-        android:layout_width="match_parent"
+        android:layout_width="wrap_content"
         android:layout_height="@dimen/overview_actions_height"
-        android:layout_gravity="bottom"
-        android:gravity="center_horizontal"
+        android:layout_gravity="bottom|center_horizontal"
         android:orientation="horizontal">
 
         <Button
@@ -36,17 +35,12 @@
             android:text="@string/action_screenshot"
             android:theme="@style/ThemeControlHighlightWorkspaceColor" />
 
-        <Space
-            android:id="@+id/action_split_space"
-            android:layout_width="@dimen/overview_actions_button_spacing"
-            android:layout_height="1dp"
-            android:visibility="gone" />
-
         <Button
             android:id="@+id/action_split"
             style="@style/OverviewActionButton"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
+            android:layout_marginStart="@dimen/overview_actions_button_spacing"
             android:text="@string/action_split"
             android:theme="@style/ThemeControlHighlightWorkspaceColor"
             android:visibility="gone" />
diff --git a/quickstep/src/com/android/quickstep/views/OverviewActionsView.java b/quickstep/src/com/android/quickstep/views/OverviewActionsView.java
index 384a8d8..5188d4a 100644
--- a/quickstep/src/com/android/quickstep/views/OverviewActionsView.java
+++ b/quickstep/src/com/android/quickstep/views/OverviewActionsView.java
@@ -24,6 +24,7 @@
 import android.view.View.OnClickListener;
 import android.widget.Button;
 import android.widget.FrameLayout;
+import android.widget.LinearLayout;
 
 import androidx.annotation.IntDef;
 import androidx.annotation.Nullable;
@@ -107,6 +108,7 @@
 
     private MultiValueAlpha mMultiValueAlpha;
 
+    protected LinearLayout mActionButtons;
     // The screenshot button is implemented as a Button in launcher3 and NexusLauncher, but is an
     // ImageButton in go launcher (does not share a common class with Button). Take care when
     // casting this.
@@ -151,7 +153,8 @@
     @Override
     protected void onFinishInflate() {
         super.onFinishInflate();
-        mMultiValueAlpha = new MultiValueAlpha(findViewById(R.id.action_buttons), NUM_ALPHAS);
+        mActionButtons = findViewById(R.id.action_buttons);
+        mMultiValueAlpha = new MultiValueAlpha(mActionButtons, NUM_ALPHAS);
         mMultiValueAlpha.setUpdateVisibility(true);
 
         mScreenshotButton = findViewById(R.id.action_screenshot);
@@ -243,13 +246,13 @@
 
     /**
      * Updates a batch of flags to hide and show actions buttons for tablet/non tablet case.
-     * @param isSmallScreen True if the current display is a small screen.
      */
-    public void updateForSmallScreen(boolean isSmallScreen) {
+    private void updateForIsTablet() {
+        assert mDp != null;
         // Update flags to see if split button should be hidden.
-        updateSplitButtonHiddenFlags(FLAG_SMALL_SCREEN_HIDE_SPLIT, isSmallScreen);
+        updateSplitButtonHiddenFlags(FLAG_SMALL_SCREEN_HIDE_SPLIT, !mDp.isTablet);
         // Update flags to see if save app pair button should be hidden.
-        updateAppPairButtonHiddenFlags(FLAG_SMALL_SCREEN_HIDE_APP_PAIR, isSmallScreen);
+        updateAppPairButtonHiddenFlags(FLAG_SMALL_SCREEN_HIDE_APP_PAIR, !mDp.isTablet);
     }
 
     /**
@@ -274,7 +277,10 @@
             mScreenshotButtonHiddenFlags &= ~flag;
         }
         int desiredVisibility = mScreenshotButtonHiddenFlags == 0 ? VISIBLE : GONE;
-        mScreenshotButton.setVisibility(desiredVisibility);
+        if (mScreenshotButton.getVisibility() != desiredVisibility) {
+            mScreenshotButton.setVisibility(desiredVisibility);
+            mActionButtons.requestLayout();
+        }
     }
 
     /**
@@ -292,8 +298,10 @@
             mSplitButtonHiddenFlags &= ~flag;
         }
         int desiredVisibility = mSplitButtonHiddenFlags == 0 ? VISIBLE : GONE;
-        mSplitButton.setVisibility(desiredVisibility);
-        findViewById(R.id.action_split_space).setVisibility(desiredVisibility);
+        if (mSplitButton.getVisibility() != desiredVisibility) {
+            mSplitButton.setVisibility(desiredVisibility);
+            mActionButtons.requestLayout();
+        }
     }
 
     /**
@@ -315,7 +323,10 @@
             mAppPairButtonHiddenFlags &= ~flag;
         }
         int desiredVisibility = mAppPairButtonHiddenFlags == 0 ? VISIBLE : GONE;
-        mSaveAppPairButton.setVisibility(desiredVisibility);
+        if (mSaveAppPairButton.getVisibility() != desiredVisibility) {
+            mSaveAppPairButton.setVisibility(desiredVisibility);
+            mActionButtons.requestLayout();
+        }
     }
 
     public MultiProperty getContentAlpha() {
@@ -342,7 +353,7 @@
      * Returns the visibility of the overview actions buttons.
      */
     public @Visibility int getActionsButtonVisibility() {
-        return findViewById(R.id.action_buttons).getVisibility();
+        return mActionButtons.getVisibility();
     }
 
     /**
@@ -358,8 +369,7 @@
         if (mDp == null) {
             return;
         }
-        LayoutParams actionParams = (LayoutParams) findViewById(
-                R.id.action_buttons).getLayoutParams();
+        LayoutParams actionParams = (LayoutParams) mActionButtons.getLayoutParams();
         actionParams.setMargins(
                 actionParams.leftMargin, mDp.overviewActionsTopMarginPx,
                 actionParams.rightMargin, getBottomMargin());
@@ -386,6 +396,7 @@
         mDp = dp;
         mTaskSize.set(taskSize);
         updateVerticalMargin(DisplayController.getNavigationMode(getContext()));
+        updateForIsTablet();
 
         requestLayout();
 
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index 7733fe2..c42bad3 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -1062,6 +1062,8 @@
             @Nullable DesktopRecentsTransitionController desktopRecentsTransitionController) {
         mActionsView = actionsView;
         mActionsView.updateHiddenFlags(HIDDEN_NO_TASKS, getTaskViewCount() == 0);
+        // Update flags for 1p/3p launchers
+        mActionsView.updateFor3pLauncher(!supportsAppPairs());
         mSplitSelectStateController = splitController;
         mDesktopRecentsTransitionController = desktopRecentsTransitionController;
     }
@@ -4020,10 +4022,6 @@
         // Update flags to see if actions bar should show buttons for a single task or a pair of
         // tasks.
         mActionsView.updateForGroupedTask(isCurrentSplit);
-        // Update flags to see if actions bar should show buttons for tablets or phones.
-        mActionsView.updateForSmallScreen(!mActivity.getDeviceProfile().isTablet);
-        // Update flags for 1p/3p launchers
-        mActionsView.updateFor3pLauncher(!supportsAppPairs());
 
         if (isDesktopModeSupported()) {
             boolean isCurrentDesktop = getCurrentPageTaskView() instanceof DesktopTaskView;
diff --git a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java
index 4f20c57..777e7b3 100644
--- a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java
+++ b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java
@@ -401,8 +401,9 @@
         if (isTablet && Math.abs(task.getExactCenterX() - mLauncher.getExactScreenCenterX()) >= 1) {
             return false;
         }
-        if (!mLauncher.isAppPairsEnabled() && task.isTaskSplit()) {
-            // Overview actions aren't visible for split screen tasks.
+        if (task.isTaskSplit() && (!mLauncher.isAppPairsEnabled() || !isTablet)) {
+            // Overview actions aren't visible for split screen tasks, except for save app pair
+            // button on tablets.
             return false;
         }
         return true;