From 1295ffec85dc1d7e4c1a715afc6022516585bf39 Mon Sep 17 00:00:00 2001 From: Toni Barzic Date: Thu, 10 Oct 2024 19:23:31 +0000 Subject: [PATCH] Improve max taskbar icon count calculation Updates calculation for max number of icons that can be shown in the taskbar before hitting overflow to: * account for size of the three button nav, if shown * size of margins between icons * difference in all apps button and divider icon sizes (compared to baseline icon size) Bug: 368119679 Test: Keep adding app icons to taskbar in desktop session until it hits overflow with three button nav enabled, both in landscape and portrait orientation - verify the taskbar enters overflow before icons start to overlap with nav buttons. With button navigation disabled, taskbar enters overflow as it starts nearing screen edge. Transition between transient and persistent taskbar keep consistent number of icons shown. Flag: com.android.launcher3.taskbar_overflow Change-Id: I66a12b390295dd50937e66a5bdf0e3e616b4a850 --- .../launcher3/taskbar/TaskbarView.java | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java index 8763509183..ec9416017e 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java @@ -192,13 +192,44 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar } /** - // @return the maximum number of 'icons' that can fit in the taskbar. - // TODO(368119679): Assumes that they are all the same size. + * @return the maximum number of 'icons' that can fit in the taskbar. */ private int calculateMaxNumIcons() { - int availableWidth = mActivityContext.getDeviceProfile().widthPx - - (mActivityContext.getDeviceProfile().edgeMarginPx * 2); - return Math.floorDiv(availableWidth, mIconTouchSize); + DeviceProfile deviceProfile = mActivityContext.getDeviceProfile(); + int availableWidth = deviceProfile.widthPx; + + // 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(deviceProfile.edgeMarginPx, deviceProfile.hotseatBarEndOffset); + availableWidth -= Math.max(deviceProfile.edgeMarginPx, + mShouldTryStartAlign ? 0 : deviceProfile.hotseatBarEndOffset); + + // The space taken by an item icon used during layout. + int iconSize = 2 * mItemMarginLeftRight + mIconTouchSize; + + int additionalIcons = 0; + + if (mTaskbarDividerContainer != null) { + // Space for divider icon is reduced during layout compared to normal icon size, reserve + // space for the divider separately. + availableWidth -= iconSize - 4 * mItemMarginLeftRight; + ++additionalIcons; + } + + // All apps icon takes less space compared to normal icon size, reserve space for the icon + // separately. + if (mAllAppsButtonContainer != null) { + boolean forceTransientTaskbarSize = + enableTaskbarPinning() && !mActivityContext.isThreeButtonNav(); + availableWidth -= iconSize - (int) getResources().getDimension( + mAllAppsButtonContainer.getAllAppsButtonTranslationXOffset( + forceTransientTaskbarSize || ( + DisplayController.isTransientTaskbar(mActivityContext) + && !mActivityContext.isPhoneMode()))); + ++additionalIcons; + } + + return Math.floorDiv(availableWidth, iconSize) + additionalIcons; } @Override