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

Commit 9641493d authored by Roy Chou's avatar Roy Chou
Browse files

fix(statusbar): notification icons become too small when smaller font size

In StatusBarIconView, when calculating the icon scale for notification icons, we should first compute the scale to make the raw drawable same size when icon view size is mOriginalStatusBarIconSize. Therefore, when smaller font size already makes the drawable constrained further than mOriginalStatusBarIconSize does, we should compute the scale to enlarge the constrained image to the size it would be when mOriginalStatusBarIconSize. Then, we could do the next steps to scale the scaled image to fit mNewStatusBarIconSize.

Bug: 296026932
Test: manually - attach screenshots in bug
      atest systemui/statusbar/phone/
Change-Id: Id8aa77ebac631377cc2ed623d8c4dedad59c27de
parent b650f99c
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -244,12 +244,16 @@ public class StatusBarIconView extends AnimatedImageView implements StatusIconDi
            }
            final float scaledImageWidth = drawableWidth * scaleToFitIconView;
            final float scaledImageHeight = drawableHeight * scaleToFitIconView;
            // if the scaled image size <= mOriginalStatusBarIconSize, we don't need to enlarge it
            scaleToOriginalDrawingSize = Math.min(
                    (float) mOriginalStatusBarIconSize / scaledImageWidth,
                    (float) mOriginalStatusBarIconSize / scaledImageHeight);
            if (scaleToOriginalDrawingSize > 1.0f) {
                scaleToOriginalDrawingSize = 1.0f;
                // per b/296026932, if the scaled image size <= mOriginalStatusBarIconSize, we need
                // to scale up the scaled image to fit in mOriginalStatusBarIconSize. But if both
                // the raw drawable intrinsic width/height are less than mOriginalStatusBarIconSize,
                // then we just scale up the scaled image back to the raw drawable size.
                scaleToOriginalDrawingSize = Math.min(
                        scaleToOriginalDrawingSize, 1f / scaleToFitIconView);
            }
        }
        iconScale = scaleToOriginalDrawingSize;
+33 −3
Original line number Diff line number Diff line
@@ -248,7 +248,7 @@ public class StatusBarIconViewTest extends SysuiTestCase {
    }

    @Test
    public void testUpdateIconScale_smallerFontAndConstrainedDrawableSizeLessThanDpIconSize() {
    public void testUpdateIconScale_smallerFontAndRawDrawableSizeLessThanDpIconSize() {
        int dpIconSize = 60;
        int dpDrawingSize = 30;
        // smaller font scaling causes the spIconSize < dpIconSize
@@ -262,12 +262,42 @@ public class StatusBarIconViewTest extends SysuiTestCase {
        setIconDrawableWithSize(/* width= */ 50, /* height= */ 50);
        mIconView.maybeUpdateIconScaleDimens();

        // WHEN both the constrained drawable width/height are less than dpIconSize,
        // WHEN both the raw/constrained drawable width/height are less than dpIconSize,
        // THEN the icon is scaled up from constrained drawable size to the raw drawable size
        float scaleToBackRawDrawableSize = (float) 50 / 40;
        // THEN the icon is scaled down from dpIconSize to fit the dpDrawingSize
        float scaleToFitDrawingSize = (float) dpDrawingSize / dpIconSize;
        // THEN the scaled icon should be scaled down further to fit spIconSize
        float scaleToFitSpIconSize = (float) spIconSize / dpIconSize;
        assertEquals(scaleToFitDrawingSize * scaleToFitSpIconSize, mIconView.getIconScale(), 0.01f);
        assertEquals(scaleToBackRawDrawableSize * scaleToFitDrawingSize * scaleToFitSpIconSize,
                mIconView.getIconScale(), 0.01f);
    }

    @Test
    public void testUpdateIconScale_smallerFontAndConstrainedDrawableSizeLessThanDpIconSize() {
        int dpIconSize = 60;
        int dpDrawingSize = 30;
        // smaller font scaling causes the spIconSize < dpIconSize
        int spIconSize = 40;
        // the icon view layout size would be 40x150
        //   (the height is always 150 due to TEST_STATUS_BAR_HEIGHT)
        setUpIconView(dpIconSize, dpDrawingSize, spIconSize);
        mIconView.setNotification(mock(StatusBarNotification.class));
        // the raw drawable size is 70x70. When put the drawable into iconView whose
        // layout size is 40x150, the drawable size would be constrained to 40x40
        setIconDrawableWithSize(/* width= */ 70, /* height= */ 70);
        mIconView.maybeUpdateIconScaleDimens();

        // WHEN the raw drawable width/height are larger than dpIconSize,
        //      but the constrained drawable width/height are less than dpIconSize,
        // THEN the icon is scaled up from constrained drawable size to fit dpIconSize
        float scaleToFitDpIconSize = (float) dpIconSize / 40;
        // THEN the icon is scaled down from dpIconSize to fit the dpDrawingSize
        float scaleToFitDrawingSize = (float) dpDrawingSize / dpIconSize;
        // THEN the scaled icon should be scaled down further to fit spIconSize
        float scaleToFitSpIconSize = (float) spIconSize / dpIconSize;
        assertEquals(scaleToFitDpIconSize * scaleToFitDrawingSize * scaleToFitSpIconSize,
                mIconView.getIconScale(), 0.01f);
    }

    @Test