diff options
| author | 2023-09-27 23:48:34 +0000 | |
|---|---|---|
| committer | 2023-09-27 23:48:34 +0000 | |
| commit | cd6e9a59a0e777c957a0a4eab1a4881ab66bd3cb (patch) | |
| tree | 0d225cdc514c9fe6e90c3a968219d40356900eb6 | |
| parent | 5dabd1718a0ba7f56e9096e17aa3a9cf4f0cfe94 (diff) | |
| parent | 0161f478611585bf9b83da7991e3b2872523601b (diff) | |
Merge "fix(statusbar): notification icons become too small when smaller font size" into udc-qpr-dev am: 0161f47861
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24862434
Change-Id: I9a33c6b34f16d4e393ac344f97cc7ae4a5ac3aa5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java | 8 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java | 36 |
2 files changed, 39 insertions, 5 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java index fbbee53468c5..895c25cd8178 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java @@ -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; diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java index 8d016e30c0c1..302b113892cc 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java @@ -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 |