From 518ca4609cd68fc5ba75946b54d3184e66b8a989 Mon Sep 17 00:00:00 2001 From: Toni Barzic Date: Fri, 11 Oct 2024 05:38:36 +0000 Subject: [PATCH] Optimize updating hotseat items in overflown taskbar The logic for updating hotseat items in taskbar involved adding all available recent items to the view, and then removing ones that overflow. It also preemptively added overflow icon, and then removed it when no overflow was detected. This cl updates logic to stop adding recent items before they cause overflow, and add overflow icon only when needed. Bug: 368119679 Test: Keep opening apps until taskbar enters overflow, and verify that expected number of app icons is displayed, and overflow icon is shown in the correct place. Flag: com.android.launcher3.taskbar_overflow Change-Id: Icaad4386b54bbfccba8ace5876d7fe5c90cb7798 --- .../launcher3/taskbar/TaskbarView.java | 63 +++++++------------ 1 file changed, 21 insertions(+), 42 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java index 8763509183..3ab88a1cc0 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java @@ -412,13 +412,33 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar if (mTaskbarDividerContainer != null && !recentTasks.isEmpty()) { addView(mTaskbarDividerContainer, nextViewIndex++); mAddedDividerForRecents = true; - if (mTaskbarOverflowView != null) { + } + + // At this point, the all apps button has not been added as a child view, but needs to be + // accounted for when comparing current icon count to max number of icons. + int nonTaskIconsToBeAdded = 1; + + boolean supportsOverflow = Flags.taskbarOverflow(); + if (supportsOverflow) { + int numberOfSupportedRecents = 0; + for (GroupTask task : recentTasks) { + // TODO(b/343289567 and b/316004172): support app pairs and desktop mode. + if (!task.hasMultipleTasks()) { + ++numberOfSupportedRecents; + } + } + if (nextViewIndex + numberOfSupportedRecents + nonTaskIconsToBeAdded > mMaxNumIcons + && mTaskbarOverflowView != null) { addView(mTaskbarOverflowView, nextViewIndex++); } } // Add Recent/Running icons. for (GroupTask task : recentTasks) { + if (supportsOverflow && nextViewIndex + nonTaskIconsToBeAdded >= mMaxNumIcons) { + break; + } + // Replace any Recent views with the appropriate type if it's not already that type. final int expectedLayoutResId; boolean isCollection = false; @@ -488,8 +508,6 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar } } - updateRecentAppsToFit(); - if (mActivityContext.getDeviceProfile().isQsbInline) { addView(mQsb, mIsRtl ? getChildCount() : 0); // Always set QSB to invisible after re-adding. @@ -497,45 +515,6 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar } } - /** - * Updates the recent apps portion of the taskbar by: - * - Removing overflow affordance if overflow is not needed. - * - Removing any recent apps that do not fit. - */ - private void updateRecentAppsToFit() { - if (!Flags.taskbarOverflow()) { - return; - } - int indexOfFirstRecentApp = -1; - int size = getChildCount(); - boolean removeOverflowView = true; - - for (int i = 0; i < size; ++i) { - if (getChildAt(i).getTag() instanceof GroupTask) { - indexOfFirstRecentApp = i; - removeOverflowView = false; - break; - } - } - - if (indexOfFirstRecentApp != -1) { - // We pre-maturely added the overflow icon, so we can take it out of the count. - int numRecentAppsToRemove = Math.max(0, getChildCount() - mMaxNumIcons + 1); - if (numRecentAppsToRemove <= 1) { - // We can fit all of the recent apps if we remove the overflow icon. - removeOverflowView = true; - } else { - for (int i = 0; i < numRecentAppsToRemove; ++i) { - removeAndRecycle(getChildAt(indexOfFirstRecentApp)); - } - } - } - - if (removeOverflowView) { - removeView(mTaskbarOverflowView); - } - } - /** Binds the GroupTask to the BubbleTextView to be ready to present to the user. */ public void applyGroupTaskToBubbleTextView(BubbleTextView btv, GroupTask groupTask) { // TODO(b/343289567): support app pairs.