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

Commit a745ebf3 authored by Lyn Han's avatar Lyn Han Committed by Android (Google) Code Review
Browse files

Merge "Fix dot/icon overlap in notification shelf" into tm-qpr-dev

parents 699f5e94 30649549
Loading
Loading
Loading
Loading
+25 −10
Original line number Diff line number Diff line
@@ -423,6 +423,21 @@ public class NotificationIconContainer extends ViewGroup {
                + getActualPaddingEnd();
    }

    @VisibleForTesting
    boolean shouldForceOverflow(int i, int speedBumpIndex, float iconAppearAmount,
            int maxVisibleIcons) {
        return speedBumpIndex != -1 && i >= speedBumpIndex
                && iconAppearAmount > 0.0f || i >= maxVisibleIcons;
    }

    @VisibleForTesting
    boolean isOverflowing(boolean isLastChild, float translationX, float layoutEnd,
            float iconSize) {
        // Layout end, as used here, does not include padding end.
        final float overflowX = isLastChild ? layoutEnd : layoutEnd - iconSize;
        return translationX >= overflowX;
    }

    /**
     * Calculate the horizontal translations for each notification based on how much the icons
     * are inserted into the notification container.
@@ -448,26 +463,26 @@ public class NotificationIconContainer extends ViewGroup {
            if (mFirstVisibleIconState == null) {
                mFirstVisibleIconState = iconState;
            }
            boolean forceOverflow = mSpeedBumpIndex != -1 && i >= mSpeedBumpIndex
                    && iconState.iconAppearAmount > 0.0f || i >= maxVisibleIcons;
            boolean isLastChild = i == childCount - 1;
            float drawingScale = mOnLockScreen && view instanceof StatusBarIconView
                    ? ((StatusBarIconView) view).getIconScaleIncreased()
                    : 1f;
            iconState.visibleState = iconState.hidden
                    ? StatusBarIconView.STATE_HIDDEN
                    : StatusBarIconView.STATE_ICON;

            final float overflowDotX = layoutEnd - mIconSize;
            boolean isOverflowing = translationX > overflowDotX;
            final boolean forceOverflow = shouldForceOverflow(i, mSpeedBumpIndex,
                    iconState.iconAppearAmount, maxVisibleIcons);
            final boolean isOverflowing = forceOverflow || isOverflowing(
                    /* isLastChild= */ i == childCount - 1, translationX, layoutEnd, mIconSize);

            if (firstOverflowIndex == -1 && (forceOverflow || isOverflowing)) {
                firstOverflowIndex = isLastChild && !forceOverflow ? i - 1 : i;
            // First icon to overflow.
            if (firstOverflowIndex == -1 && isOverflowing) {
                firstOverflowIndex = i;
                mVisualOverflowStart = layoutEnd - mIconSize;
                if (forceOverflow || mIsStaticLayout) {
                    mVisualOverflowStart = Math.min(translationX, mVisualOverflowStart);
                }
            }
            final float drawingScale = mOnLockScreen && view instanceof StatusBarIconView
                    ? ((StatusBarIconView) view).getIconScaleIncreased()
                    : 1f;
            translationX += iconState.iconAppearAmount * view.getWidth() * drawingScale;
        }
        mNumDots = 0;
+100 −0
Original line number Diff line number Diff line
@@ -153,6 +153,106 @@ class NotificationIconContainerTest : SysuiTestCase() {
        assertTrue(iconContainer.hasOverflow())
    }

    @Test
    fun shouldForceOverflow_appearingAboveSpeedBump_true() {
        val forceOverflow = iconContainer.shouldForceOverflow(
                /* i= */ 1,
                /* speedBumpIndex= */ 0,
                /* iconAppearAmount= */ 1f,
                /* maxVisibleIcons= */ 5
        )
        assertTrue(forceOverflow);
    }

    @Test
    fun shouldForceOverflow_moreThanMaxVisible_true() {
        val forceOverflow = iconContainer.shouldForceOverflow(
                /* i= */ 10,
                /* speedBumpIndex= */ 11,
                /* iconAppearAmount= */ 0f,
                /* maxVisibleIcons= */ 5
        )
        assertTrue(forceOverflow);
    }

    @Test
    fun shouldForceOverflow_belowSpeedBumpAndLessThanMaxVisible_false() {
        val forceOverflow = iconContainer.shouldForceOverflow(
                /* i= */ 0,
                /* speedBumpIndex= */ 11,
                /* iconAppearAmount= */ 0f,
                /* maxVisibleIcons= */ 5
        )
        assertFalse(forceOverflow);
    }

    @Test
    fun isOverflowing_lastChildXLessThanLayoutEnd_false() {
        val isOverflowing = iconContainer.isOverflowing(
                /* isLastChild= */ true,
                /* translationX= */ 0f,
                /* layoutEnd= */ 10f,
                /* iconSize= */ 2f,
        )
        assertFalse(isOverflowing)
    }


    @Test
    fun isOverflowing_lastChildXEqualToLayoutEnd_true() {
        val isOverflowing = iconContainer.isOverflowing(
                /* isLastChild= */ true,
                /* translationX= */ 10f,
                /* layoutEnd= */ 10f,
                /* iconSize= */ 2f,
        )
        assertTrue(isOverflowing)
    }

    @Test
    fun isOverflowing_lastChildXGreaterThanLayoutEnd_true() {
        val isOverflowing = iconContainer.isOverflowing(
                /* isLastChild= */ true,
                /* translationX= */ 20f,
                /* layoutEnd= */ 10f,
                /* iconSize= */ 2f,
        )
        assertTrue(isOverflowing)
    }

    @Test
    fun isOverflowing_notLastChildXLessThanDotX_false() {
        val isOverflowing = iconContainer.isOverflowing(
                /* isLastChild= */ false,
                /* translationX= */ 0f,
                /* layoutEnd= */ 10f,
                /* iconSize= */ 2f,
        )
        assertFalse(isOverflowing)
    }

    @Test
    fun isOverflowing_notLastChildXGreaterThanDotX_true() {
        val isOverflowing = iconContainer.isOverflowing(
                /* isLastChild= */ false,
                /* translationX= */ 20f,
                /* layoutEnd= */ 10f,
                /* iconSize= */ 2f,
        )
        assertTrue(isOverflowing)
    }

    @Test
    fun isOverflowing_notLastChildXEqualToDotX_true() {
        val isOverflowing = iconContainer.isOverflowing(
                /* isLastChild= */ false,
                /* translationX= */ 8f,
                /* layoutEnd= */ 10f,
                /* iconSize= */ 2f,
        )
        assertTrue(isOverflowing)
    }

    private fun mockStatusBarIcon() : StatusBarIconView {
        val iconView = mock(StatusBarIconView::class.java)
        whenever(iconView.width).thenReturn(10)