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

Commit 28ebd1ba authored by Toni Barzic's avatar Toni Barzic
Browse files

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
parent 0cceb242
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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) {
+30 −7
Original line number Diff line number Diff line
@@ -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) {
+11 −0
Original line number Diff line number Diff line
@@ -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()
+9 −2
Original line number Diff line number Diff line
@@ -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();
        }
    }

    /**
+5 −1
Original line number Diff line number Diff line
@@ -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();
Loading