Loading packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java +6 −2 Original line number Diff line number Diff line Loading @@ -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; Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java +33 −3 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java +6 −2 Original line number Diff line number Diff line Loading @@ -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; Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java +33 −3 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading