Loading packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java +2 −1 Original line number Diff line number Diff line Loading @@ -454,7 +454,8 @@ public class NotificationShelf extends ActivatableNotificationView implements || row.getTranslationZ() > mAmbientState.getBaseZHeight()))) { iconState.hidden = true; } int shelfColor = icon.getStaticDrawableColor(); int backgroundColor = getBackgroundColorWithoutTint(); int shelfColor = icon.getContrastedStaticDrawableColor(backgroundColor); if (!noIcon && shelfColor != StatusBarIconView.NO_COLOR) { int iconColor = row.getVisibleNotificationHeader().getOriginalIconColor(); shelfColor = NotificationUtils.interpolateColors(iconColor, shelfColor, Loading packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java +41 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.graphics.drawable.Icon; import android.os.Parcelable; import android.os.UserHandle; import android.service.notification.StatusBarNotification; import android.support.v4.graphics.ColorUtils; import android.text.TextUtils; import android.util.AttributeSet; import android.util.FloatProperty; Loading @@ -46,6 +47,7 @@ import android.view.accessibility.AccessibilityEvent; import android.view.animation.Interpolator; import com.android.internal.statusbar.StatusBarIcon; import com.android.internal.util.NotificationColorUtil; import com.android.systemui.Interpolators; import com.android.systemui.R; import com.android.systemui.statusbar.notification.NotificationIconDozeHelper; Loading Loading @@ -127,6 +129,8 @@ public class StatusBarIconView extends AnimatedImageView { setColorInternal(newColor); }; private final NotificationIconDozeHelper mDozer; private int mContrastedDrawableColor; private int mCachedContrastBackgroundColor = NO_COLOR; public StatusBarIconView(Context context, String slot, StatusBarNotification sbn) { this(context, slot, sbn, false); Loading Loading @@ -528,6 +532,7 @@ public class StatusBarIconView extends AnimatedImageView { public void setStaticDrawableColor(int color) { mDrawableColor = color; setColorInternal(color); updateContrastedStaticColor(); mIconColor = color; mDozer.setColor(color); } Loading Loading @@ -580,6 +585,42 @@ public class StatusBarIconView extends AnimatedImageView { return mDrawableColor; } /** * A drawable color that passes GAR on a specific background. * This value is cached. * * @param backgroundColor Background to test against. * @return GAR safe version of {@link StatusBarIconView#getStaticDrawableColor()}. */ int getContrastedStaticDrawableColor(int backgroundColor) { if (mCachedContrastBackgroundColor != backgroundColor) { mCachedContrastBackgroundColor = backgroundColor; updateContrastedStaticColor(); } return mContrastedDrawableColor; } private void updateContrastedStaticColor() { if (mCachedContrastBackgroundColor == NO_COLOR) { return; } // We'll modify the color if it doesn't pass GAR int contrastedColor = mDrawableColor; if (!NotificationColorUtil.satisfiesTextContrast(mCachedContrastBackgroundColor, contrastedColor)) { float[] hsl = new float[3]; ColorUtils.colorToHSL(mDrawableColor, hsl); // This is basically a light grey, pushing the color will only distort it. // Best thing to do in here is to fallback to the default color. if (hsl[1] < 0.2f) { contrastedColor = Notification.COLOR_DEFAULT; } contrastedColor = NotificationColorUtil.resolveContrastColor(mContext, contrastedColor, mCachedContrastBackgroundColor); } mContrastedDrawableColor = contrastedColor; } public void setVisibleState(int state) { setVisibleState(state, true /* animate */, null /* endRunnable */); } Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java +17 −0 Original line number Diff line number Diff line Loading @@ -16,8 +16,10 @@ package com.android.systemui.statusbar; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; Loading @@ -33,12 +35,14 @@ import android.content.ContextWrapper; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.Resources; import android.graphics.Color; import android.graphics.drawable.Icon; import android.os.UserHandle; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; import com.android.internal.statusbar.StatusBarIcon; import com.android.internal.util.NotificationColorUtil; import com.android.systemui.R; import com.android.systemui.SysuiTestCase; Loading Loading @@ -100,4 +104,17 @@ public class StatusBarIconViewTest extends SysuiTestCase { assertFalse(mIconView.set(mStatusBarIcon)); } @Test public void testGetContrastedStaticDrawableColor() { mIconView.setStaticDrawableColor(Color.DKGRAY); int color = mIconView.getContrastedStaticDrawableColor(Color.WHITE); assertEquals("Color should not change when we have enough contrast", Color.DKGRAY, color); mIconView.setStaticDrawableColor(Color.WHITE); color = mIconView.getContrastedStaticDrawableColor(Color.WHITE); assertTrue("Similar colors should be shifted to satisfy contrast", NotificationColorUtil.satisfiesTextContrast(Color.WHITE, color)); } } No newline at end of file Loading
packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java +2 −1 Original line number Diff line number Diff line Loading @@ -454,7 +454,8 @@ public class NotificationShelf extends ActivatableNotificationView implements || row.getTranslationZ() > mAmbientState.getBaseZHeight()))) { iconState.hidden = true; } int shelfColor = icon.getStaticDrawableColor(); int backgroundColor = getBackgroundColorWithoutTint(); int shelfColor = icon.getContrastedStaticDrawableColor(backgroundColor); if (!noIcon && shelfColor != StatusBarIconView.NO_COLOR) { int iconColor = row.getVisibleNotificationHeader().getOriginalIconColor(); shelfColor = NotificationUtils.interpolateColors(iconColor, shelfColor, Loading
packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java +41 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.graphics.drawable.Icon; import android.os.Parcelable; import android.os.UserHandle; import android.service.notification.StatusBarNotification; import android.support.v4.graphics.ColorUtils; import android.text.TextUtils; import android.util.AttributeSet; import android.util.FloatProperty; Loading @@ -46,6 +47,7 @@ import android.view.accessibility.AccessibilityEvent; import android.view.animation.Interpolator; import com.android.internal.statusbar.StatusBarIcon; import com.android.internal.util.NotificationColorUtil; import com.android.systemui.Interpolators; import com.android.systemui.R; import com.android.systemui.statusbar.notification.NotificationIconDozeHelper; Loading Loading @@ -127,6 +129,8 @@ public class StatusBarIconView extends AnimatedImageView { setColorInternal(newColor); }; private final NotificationIconDozeHelper mDozer; private int mContrastedDrawableColor; private int mCachedContrastBackgroundColor = NO_COLOR; public StatusBarIconView(Context context, String slot, StatusBarNotification sbn) { this(context, slot, sbn, false); Loading Loading @@ -528,6 +532,7 @@ public class StatusBarIconView extends AnimatedImageView { public void setStaticDrawableColor(int color) { mDrawableColor = color; setColorInternal(color); updateContrastedStaticColor(); mIconColor = color; mDozer.setColor(color); } Loading Loading @@ -580,6 +585,42 @@ public class StatusBarIconView extends AnimatedImageView { return mDrawableColor; } /** * A drawable color that passes GAR on a specific background. * This value is cached. * * @param backgroundColor Background to test against. * @return GAR safe version of {@link StatusBarIconView#getStaticDrawableColor()}. */ int getContrastedStaticDrawableColor(int backgroundColor) { if (mCachedContrastBackgroundColor != backgroundColor) { mCachedContrastBackgroundColor = backgroundColor; updateContrastedStaticColor(); } return mContrastedDrawableColor; } private void updateContrastedStaticColor() { if (mCachedContrastBackgroundColor == NO_COLOR) { return; } // We'll modify the color if it doesn't pass GAR int contrastedColor = mDrawableColor; if (!NotificationColorUtil.satisfiesTextContrast(mCachedContrastBackgroundColor, contrastedColor)) { float[] hsl = new float[3]; ColorUtils.colorToHSL(mDrawableColor, hsl); // This is basically a light grey, pushing the color will only distort it. // Best thing to do in here is to fallback to the default color. if (hsl[1] < 0.2f) { contrastedColor = Notification.COLOR_DEFAULT; } contrastedColor = NotificationColorUtil.resolveContrastColor(mContext, contrastedColor, mCachedContrastBackgroundColor); } mContrastedDrawableColor = contrastedColor; } public void setVisibleState(int state) { setVisibleState(state, true /* animate */, null /* endRunnable */); } Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java +17 −0 Original line number Diff line number Diff line Loading @@ -16,8 +16,10 @@ package com.android.systemui.statusbar; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; Loading @@ -33,12 +35,14 @@ import android.content.ContextWrapper; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.Resources; import android.graphics.Color; import android.graphics.drawable.Icon; import android.os.UserHandle; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; import com.android.internal.statusbar.StatusBarIcon; import com.android.internal.util.NotificationColorUtil; import com.android.systemui.R; import com.android.systemui.SysuiTestCase; Loading Loading @@ -100,4 +104,17 @@ public class StatusBarIconViewTest extends SysuiTestCase { assertFalse(mIconView.set(mStatusBarIcon)); } @Test public void testGetContrastedStaticDrawableColor() { mIconView.setStaticDrawableColor(Color.DKGRAY); int color = mIconView.getContrastedStaticDrawableColor(Color.WHITE); assertEquals("Color should not change when we have enough contrast", Color.DKGRAY, color); mIconView.setStaticDrawableColor(Color.WHITE); color = mIconView.getContrastedStaticDrawableColor(Color.WHITE); assertTrue("Similar colors should be shifted to satisfy contrast", NotificationColorUtil.satisfiesTextContrast(Color.WHITE, color)); } } No newline at end of file