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
This commit is contained in:
Toni Barzic
2024-11-11 01:30:25 +00:00
parent 0cceb24288
commit 28ebd1bacd
6 changed files with 63 additions and 11 deletions
@@ -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) {