From 28ebd1bacd04994ffce00ec20fda83ed09bf6f94 Mon Sep 17 00:00:00 2001 From: Toni Barzic Date: Mon, 11 Nov 2024 01:30:25 +0000 Subject: [PATCH] Account for bubble bar bounds for taskbar overflow When caculating number of icons to show in taskbar, account for bubble bar size (the max size when in collapsed state) when bubble bar has bubbles (even if the bubble bar is stashed). Note that the bubble bar visibility may change, so max number of icons in the taskbar may change during the taskbar view lieftime. TaskbarViewController already had a method called when the bubble bar visibility changed - adapt it to also reclaculate max number of icons to show in the taskbar, and update the list of icons shown in the UI if necessary (if the change in the bubble bar visibility would also cause a change in number of icons shown in the taskbar). Bug: 368119679 Test: Launch enough apps for taskbar to enter overflow, open an app that supports bubbles, and trigger 2 or more bubbles so bubble bar shows up. Verify that the buble bar does not overlap with taskbar bounds, both in transient and persistent taskbar. Remove bubbles, and verify the taskbar bounds expand, allowing more icons to be shown. Flag: com.android.launcher3.taskbar_overflow Change-Id: Ifed4e5e5dd64df5256090f5ba55f24203c09e839 --- .../taskbar/TaskbarActivityContext.java | 2 +- .../launcher3/taskbar/TaskbarView.java | 37 +++++++++++++++---- .../taskbar/TaskbarViewCallbacks.java | 11 ++++++ .../taskbar/TaskbarViewController.java | 11 +++++- .../taskbar/bubbles/BubbleBarView.java | 6 ++- .../bubbles/BubbleBarViewController.java | 7 ++++ 6 files changed, 63 insertions(+), 11 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index 82acc0ce6a..d7e5c61215 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -418,7 +418,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext { /** Called when the visibility of the bubble bar changed. */ public void bubbleBarVisibilityChanged(boolean isVisible) { mControllers.uiController.adjustHotseatForBubbleBar(isVisible); - mControllers.taskbarViewController.resetIconAlignmentController(); + mControllers.taskbarViewController.adjustTaskbarForBubbleBar(); } public void init(@NonNull TaskbarSharedState sharedState) { diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java index 55bcb23c67..8816a6dd00 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java @@ -120,7 +120,8 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar private boolean mShouldTryStartAlign; - private final int mMaxNumIcons; + private int mMaxNumIcons = 0; + private int mIdealNumIcons = 0; private final int mAllAppsButtonTranslationOffset; @@ -188,8 +189,6 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar // TODO: Disable touch events on QSB otherwise it can crash. mQsb = LayoutInflater.from(context).inflate(R.layout.search_container_hotseat, this, false); - - mMaxNumIcons = calculateMaxNumIcons(); } /** @@ -200,11 +199,15 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar int availableWidth = deviceProfile.widthPx; int defaultEdgeMargin = (int) getResources().getDimension(deviceProfile.inv.inlineNavButtonsEndSpacing); + int spaceForBubbleBar = + Math.round(mControllerCallbacks.getBubbleBarMaxCollapsedWidthIfVisible()); // Reserve space required for edge margins, or for navbar if shown. If task bar needs to be // center aligned with nav bar shown, reserve space on both sides. - availableWidth -= Math.max(defaultEdgeMargin, deviceProfile.hotseatBarEndOffset); - availableWidth -= Math.max(defaultEdgeMargin, + availableWidth -= + Math.max(defaultEdgeMargin + spaceForBubbleBar, deviceProfile.hotseatBarEndOffset); + availableWidth -= Math.max( + defaultEdgeMargin + (mShouldTryStartAlign ? 0 : spaceForBubbleBar), mShouldTryStartAlign ? 0 : deviceProfile.hotseatBarEndOffset); // The space taken by an item icon used during layout. @@ -231,6 +234,21 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar return Math.floorDiv(availableWidth, iconSize) + additionalIcons; } + /** + * Recalculates the max number of icons the taskbar view can show without entering overflow. + * Returns whether the max number of icons changed and the change affects the number of icons + * that should be shown in the taskbar. + */ + boolean updateMaxNumIcons() { + if (!Flags.taskbarOverflow()) { + return false; + } + int oldMaxNumIcons = mMaxNumIcons; + mMaxNumIcons = calculateMaxNumIcons(); + return oldMaxNumIcons != mMaxNumIcons + && (mIdealNumIcons > oldMaxNumIcons || mIdealNumIcons > mMaxNumIcons); + } + @Override public void setVisibility(int visibility) { boolean changed = getVisibility() != visibility; @@ -328,6 +346,10 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar && mActivityContext.getTaskbarFeatureEvaluator().getSupportsPinningPopup()) { setOnTouchListener(mControllerCallbacks.getTaskbarTouchListener()); } + + if (Flags.taskbarOverflow()) { + mMaxNumIcons = calculateMaxNumIcons(); + } } private void removeAndRecycle(View view) { @@ -460,8 +482,9 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar } } - overflowSize = - nextViewIndex + numberOfSupportedRecents + nonTaskIconsToBeAdded - mMaxNumIcons; + mIdealNumIcons = nextViewIndex + numberOfSupportedRecents + nonTaskIconsToBeAdded; + overflowSize = mIdealNumIcons - mMaxNumIcons; + if (overflowSize > 0 && mTaskbarOverflowView != null) { addView(mTaskbarOverflowView, nextViewIndex++); } else if (mTaskbarOverflowView != null) { diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarViewCallbacks.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarViewCallbacks.java index 834f92e040..f65f30799d 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarViewCallbacks.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarViewCallbacks.java @@ -137,6 +137,17 @@ public class TaskbarViewCallbacks { return null; } + /** + * Get the max bubble bar collapsed width for the current bubble bar visibility state. Used to + * reserve space for the bubble bar when transitioning taskbar view into overflow. + */ + public float getBubbleBarMaxCollapsedWidthIfVisible() { + return mControllers.bubbleControllers + .filter(c -> !c.bubbleBarViewController.isHiddenForNoBubbles()) + .map(c -> c.bubbleBarViewController.getCollapsedWidthWithMaxVisibleBubbles()) + .orElse(0f); + } + /** Returns true if bubble bar controllers present and enabled in persistent taskbar. */ public boolean isBubbleBarEnabledInPersistentTaskbar() { return Flags.enableBubbleBarInPersistentTaskBar() diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java index 494c472cc9..cebabffa75 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java @@ -779,9 +779,16 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar } } - /** Resets the icon alignment controller so that it can be recreated again later. */ - void resetIconAlignmentController() { + /** + * Resets the icon alignment controller so that it can be recreated again later, and updates + * the list of icons shown in the taskbar if the bubble bar visibility changes the taskbar + * overflow state. + */ + void adjustTaskbarForBubbleBar() { mIconAlignControllerLazy = null; + if (mTaskbarView.updateMaxNumIcons()) { + commitRunningAppsToUI(); + } } /** diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java index c0a76a8114..316763bb2b 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java @@ -1288,10 +1288,14 @@ public class BubbleBarView extends FrameLayout { // If there are more than 2 bubbles, the first 2 should be visible when collapsed, // excluding the overflow. return bubbleChildCount >= MAX_VISIBLE_BUBBLES_COLLAPSED - ? getScaledIconSize() + mIconOverlapAmount + horizontalPadding + ? getCollapsedWidthWithMaxVisibleBubbles() : getScaledIconSize() + horizontalPadding; } + float getCollapsedWidthWithMaxVisibleBubbles() { + return getScaledIconSize() + mIconOverlapAmount + 2 * mBubbleBarPadding; + } + /** Returns the child count excluding the overflow if it's present. */ int getBubbleChildCount() { return hasOverflow() ? getChildCount() - 1 : getChildCount(); diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java index 96fadf7a0e..ce46d7b1ee 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java @@ -470,6 +470,13 @@ public class BubbleBarViewController { return mBarView.getBubbleBarLocation(); } + /** + * @return the max collapsed width for the bubble bar. + */ + public float getCollapsedWidthWithMaxVisibleBubbles() { + return mBarView.getCollapsedWidthWithMaxVisibleBubbles(); + } + /** * @return {@code true} if bubble bar is on the left edge of the screen, {@code false} if on * the right