Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1295ffec authored by Toni Barzic's avatar Toni Barzic
Browse files

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
parent 9b093db2
Loading
Loading
Loading
Loading
+36 −5
Original line number Diff line number Diff line
@@ -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