Loading core/java/android/app/Notification.java +10 −6 Original line number Diff line number Diff line Loading @@ -4476,9 +4476,9 @@ public class Notification implements Parcelable mTextColorsAreForBackground = backgroundColor; if (!hasForegroundColor() || !isColorized()) { mPrimaryTextColor = ContrastColorUtil.resolvePrimaryColor(mContext, backgroundColor); backgroundColor, mInNightMode); mSecondaryTextColor = ContrastColorUtil.resolveSecondaryColor(mContext, backgroundColor); backgroundColor, mInNightMode); if (backgroundColor != COLOR_DEFAULT && isColorized()) { mPrimaryTextColor = ContrastColorUtil.findAlphaToMeetContrast( mPrimaryTextColor, backgroundColor, 4.5); Loading Loading @@ -5263,7 +5263,7 @@ public class Notification implements Parcelable // background color background = outResultColor[0].getDefaultColor(); int textColor = ContrastColorUtil.resolvePrimaryColor(mContext, background); background, mInNightMode); button.setTextColor(R.id.action0, textColor); rippleColor = textColor; } else if (mN.color != COLOR_DEFAULT && !isColorized() && mTintActionButtons) { Loading Loading @@ -5443,7 +5443,7 @@ public class Notification implements Parcelable com.android.internal.R.color.notification_material_background_color); if (mN.color == COLOR_DEFAULT) { ensureColors(); color = ContrastColorUtil.resolveDefaultColor(mContext, background); color = ContrastColorUtil.resolveDefaultColor(mContext, background, mInNightMode); } else { color = ContrastColorUtil.resolveContrastColor(mContext, mN.color, background, mInNightMode); Loading @@ -5462,7 +5462,8 @@ public class Notification implements Parcelable } int background = mContext.getColor( com.android.internal.R.color.notification_material_background_color); mNeutralColor = ContrastColorUtil.resolveDefaultColor(mContext, background); mNeutralColor = ContrastColorUtil.resolveDefaultColor(mContext, background, mInNightMode); if (Color.alpha(mNeutralColor) < 255) { // alpha doesn't go well for color filters, so let's blend it manually mNeutralColor = ContrastColorUtil.compositeColors(mNeutralColor, background); Loading Loading @@ -7833,10 +7834,13 @@ public class Notification implements Parcelable // If the action buttons should not be tinted, then just use the default // notification color. Otherwise, just use the passed-in color. Configuration currentConfig = mBuilder.mContext.getResources().getConfiguration(); boolean inNightMode = (currentConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES; int tintColor = mBuilder.shouldTintActionButtons() || mBuilder.isColorized() ? color : ContrastColorUtil.resolveColor(mBuilder.mContext, Notification.COLOR_DEFAULT); Notification.COLOR_DEFAULT, inNightMode); button.setDrawableTint(R.id.action0, false, tintColor, PorterDuff.Mode.SRC_ATOP); Loading core/java/android/util/MathUtils.java +15 −0 Original line number Diff line number Diff line Loading @@ -186,6 +186,21 @@ public final class MathUtils { return maxStart + (maxStop - maxStart) * ((value - minStart) / (minStop - minStart)); } /** * Perform Hermite interpolation between two values. * Eg: * smoothStep(0, 0.5f, 0.5f) = 1f * smoothStep(0, 0.5f, 0.25f) = 0.5f * * @param start Left edge. * @param end Right edge. * @param x A value between {@code start} and {@code end}. * @return A number between 0 and 1 representing where {@code x} is in the interpolation. */ public static float smoothStep(float start, float end, float x) { return constrain((x - start) / (end - start), 0f, 1f); } /** * Returns the sum of the two parameters, or throws an exception if the resulting sum would * cause an overflow or underflow. Loading core/java/com/android/internal/util/ContrastColorUtil.java +21 −15 Original line number Diff line number Diff line Loading @@ -454,9 +454,12 @@ public class ContrastColorUtil { /** * Resolves {@param color} to an actual color if it is {@link Notification#COLOR_DEFAULT} */ public static int resolveColor(Context context, int color) { public static int resolveColor(Context context, int color, boolean defaultBackgroundIsDark) { if (color == Notification.COLOR_DEFAULT) { return context.getColor(com.android.internal.R.color.notification_default_color_light); int res = defaultBackgroundIsDark ? com.android.internal.R.color.notification_default_color_dark : com.android.internal.R.color.notification_default_color_light; return context.getColor(res); } return color; } Loading Loading @@ -486,7 +489,7 @@ public class ContrastColorUtil { */ public static int resolveContrastColor(Context context, int notificationColor, int backgroundColor, boolean isDark) { final int resolvedColor = resolveColor(context, notificationColor); final int resolvedColor = resolveColor(context, notificationColor, isDark); int color = resolvedColor; color = ContrastColorUtil.ensureTextContrast(color, backgroundColor, isDark); Loading Loading @@ -520,7 +523,8 @@ public class ContrastColorUtil { } public static int resolveAmbientColor(Context context, int notificationColor) { final int resolvedColor = resolveColor(context, notificationColor); final int resolvedColor = resolveColor(context, notificationColor, true /* defaultBackgroundIsDark */); int color = resolvedColor; color = ContrastColorUtil.ensureTextContrastOnBlack(color); Loading @@ -538,8 +542,9 @@ public class ContrastColorUtil { return color; } public static int resolvePrimaryColor(Context context, int backgroundColor) { boolean useDark = shouldUseDark(backgroundColor); public static int resolvePrimaryColor(Context context, int backgroundColor, boolean defaultBackgroundIsDark) { boolean useDark = shouldUseDark(backgroundColor, defaultBackgroundIsDark); if (useDark) { return context.getColor( com.android.internal.R.color.notification_primary_text_color_light); Loading @@ -549,8 +554,9 @@ public class ContrastColorUtil { } } public static int resolveSecondaryColor(Context context, int backgroundColor) { boolean useDark = shouldUseDark(backgroundColor); public static int resolveSecondaryColor(Context context, int backgroundColor, boolean defaultBackgroundIsDark) { boolean useDark = shouldUseDark(backgroundColor, defaultBackgroundIsDark); if (useDark) { return context.getColor( com.android.internal.R.color.notification_secondary_text_color_light); Loading @@ -560,8 +566,9 @@ public class ContrastColorUtil { } } public static int resolveDefaultColor(Context context, int backgroundColor) { boolean useDark = shouldUseDark(backgroundColor); public static int resolveDefaultColor(Context context, int backgroundColor, boolean defaultBackgroundIsDark) { boolean useDark = shouldUseDark(backgroundColor, defaultBackgroundIsDark); if (useDark) { return context.getColor( com.android.internal.R.color.notification_default_color_light); Loading Loading @@ -591,12 +598,11 @@ public class ContrastColorUtil { return ColorUtilsFromCompat.LABToColor(result[0], result[1], result[2]); } private static boolean shouldUseDark(int backgroundColor) { boolean useDark = backgroundColor == Notification.COLOR_DEFAULT; if (!useDark) { useDark = ColorUtilsFromCompat.calculateLuminance(backgroundColor) > 0.5; private static boolean shouldUseDark(int backgroundColor, boolean defaultBackgroundIsDark) { if (backgroundColor == Notification.COLOR_DEFAULT) { return !defaultBackgroundIsDark; } return useDark; return ColorUtilsFromCompat.calculateLuminance(backgroundColor) > 0.5; } public static double calculateLuminance(int backgroundColor) { Loading core/res/res/values-night/colors.xml 0 → 100644 +31 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- ~ Copyright (C) 2018 The Android Open Source Project ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. ~ You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by applicable law or agreed to in writing, software ~ distributed under the License is distributed on an "AS IS" BASIS, ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the License for the specific language governing permissions and ~ limitations under the License NOTE: You might also want to edit: packages/SystemUI/res/values-night/colors.xml --> <resources> <!-- The primary text color if the text is on top of a dark background. This is also affects colorized notifications with dark backgrounds. --> <color name="notification_primary_text_color_dark">#dadada</color> <!-- The secondary text color if the text is on top of a dark background. --> <color name="notification_secondary_text_color_dark">#dadada</color> <color name="notification_default_color_dark">#dadada</color> <!-- The background color of a notification card. --> <color name="notification_material_background_color">@*android:color/material_grey_900</color> </resources> No newline at end of file core/res/res/values-night/values.xml +5 −0 Original line number Diff line number Diff line Loading @@ -31,4 +31,9 @@ <!-- volume background --> <item name="panelColorBackground">@color/material_grey_800</item> </style> <style name="TextAppearance.Material.Notification"> <item name="textColor">@color/notification_secondary_text_color_dark</item> <item name="textSize">@dimen/notification_text_size</item> </style> </resources> No newline at end of file Loading
core/java/android/app/Notification.java +10 −6 Original line number Diff line number Diff line Loading @@ -4476,9 +4476,9 @@ public class Notification implements Parcelable mTextColorsAreForBackground = backgroundColor; if (!hasForegroundColor() || !isColorized()) { mPrimaryTextColor = ContrastColorUtil.resolvePrimaryColor(mContext, backgroundColor); backgroundColor, mInNightMode); mSecondaryTextColor = ContrastColorUtil.resolveSecondaryColor(mContext, backgroundColor); backgroundColor, mInNightMode); if (backgroundColor != COLOR_DEFAULT && isColorized()) { mPrimaryTextColor = ContrastColorUtil.findAlphaToMeetContrast( mPrimaryTextColor, backgroundColor, 4.5); Loading Loading @@ -5263,7 +5263,7 @@ public class Notification implements Parcelable // background color background = outResultColor[0].getDefaultColor(); int textColor = ContrastColorUtil.resolvePrimaryColor(mContext, background); background, mInNightMode); button.setTextColor(R.id.action0, textColor); rippleColor = textColor; } else if (mN.color != COLOR_DEFAULT && !isColorized() && mTintActionButtons) { Loading Loading @@ -5443,7 +5443,7 @@ public class Notification implements Parcelable com.android.internal.R.color.notification_material_background_color); if (mN.color == COLOR_DEFAULT) { ensureColors(); color = ContrastColorUtil.resolveDefaultColor(mContext, background); color = ContrastColorUtil.resolveDefaultColor(mContext, background, mInNightMode); } else { color = ContrastColorUtil.resolveContrastColor(mContext, mN.color, background, mInNightMode); Loading @@ -5462,7 +5462,8 @@ public class Notification implements Parcelable } int background = mContext.getColor( com.android.internal.R.color.notification_material_background_color); mNeutralColor = ContrastColorUtil.resolveDefaultColor(mContext, background); mNeutralColor = ContrastColorUtil.resolveDefaultColor(mContext, background, mInNightMode); if (Color.alpha(mNeutralColor) < 255) { // alpha doesn't go well for color filters, so let's blend it manually mNeutralColor = ContrastColorUtil.compositeColors(mNeutralColor, background); Loading Loading @@ -7833,10 +7834,13 @@ public class Notification implements Parcelable // If the action buttons should not be tinted, then just use the default // notification color. Otherwise, just use the passed-in color. Configuration currentConfig = mBuilder.mContext.getResources().getConfiguration(); boolean inNightMode = (currentConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES; int tintColor = mBuilder.shouldTintActionButtons() || mBuilder.isColorized() ? color : ContrastColorUtil.resolveColor(mBuilder.mContext, Notification.COLOR_DEFAULT); Notification.COLOR_DEFAULT, inNightMode); button.setDrawableTint(R.id.action0, false, tintColor, PorterDuff.Mode.SRC_ATOP); Loading
core/java/android/util/MathUtils.java +15 −0 Original line number Diff line number Diff line Loading @@ -186,6 +186,21 @@ public final class MathUtils { return maxStart + (maxStop - maxStart) * ((value - minStart) / (minStop - minStart)); } /** * Perform Hermite interpolation between two values. * Eg: * smoothStep(0, 0.5f, 0.5f) = 1f * smoothStep(0, 0.5f, 0.25f) = 0.5f * * @param start Left edge. * @param end Right edge. * @param x A value between {@code start} and {@code end}. * @return A number between 0 and 1 representing where {@code x} is in the interpolation. */ public static float smoothStep(float start, float end, float x) { return constrain((x - start) / (end - start), 0f, 1f); } /** * Returns the sum of the two parameters, or throws an exception if the resulting sum would * cause an overflow or underflow. Loading
core/java/com/android/internal/util/ContrastColorUtil.java +21 −15 Original line number Diff line number Diff line Loading @@ -454,9 +454,12 @@ public class ContrastColorUtil { /** * Resolves {@param color} to an actual color if it is {@link Notification#COLOR_DEFAULT} */ public static int resolveColor(Context context, int color) { public static int resolveColor(Context context, int color, boolean defaultBackgroundIsDark) { if (color == Notification.COLOR_DEFAULT) { return context.getColor(com.android.internal.R.color.notification_default_color_light); int res = defaultBackgroundIsDark ? com.android.internal.R.color.notification_default_color_dark : com.android.internal.R.color.notification_default_color_light; return context.getColor(res); } return color; } Loading Loading @@ -486,7 +489,7 @@ public class ContrastColorUtil { */ public static int resolveContrastColor(Context context, int notificationColor, int backgroundColor, boolean isDark) { final int resolvedColor = resolveColor(context, notificationColor); final int resolvedColor = resolveColor(context, notificationColor, isDark); int color = resolvedColor; color = ContrastColorUtil.ensureTextContrast(color, backgroundColor, isDark); Loading Loading @@ -520,7 +523,8 @@ public class ContrastColorUtil { } public static int resolveAmbientColor(Context context, int notificationColor) { final int resolvedColor = resolveColor(context, notificationColor); final int resolvedColor = resolveColor(context, notificationColor, true /* defaultBackgroundIsDark */); int color = resolvedColor; color = ContrastColorUtil.ensureTextContrastOnBlack(color); Loading @@ -538,8 +542,9 @@ public class ContrastColorUtil { return color; } public static int resolvePrimaryColor(Context context, int backgroundColor) { boolean useDark = shouldUseDark(backgroundColor); public static int resolvePrimaryColor(Context context, int backgroundColor, boolean defaultBackgroundIsDark) { boolean useDark = shouldUseDark(backgroundColor, defaultBackgroundIsDark); if (useDark) { return context.getColor( com.android.internal.R.color.notification_primary_text_color_light); Loading @@ -549,8 +554,9 @@ public class ContrastColorUtil { } } public static int resolveSecondaryColor(Context context, int backgroundColor) { boolean useDark = shouldUseDark(backgroundColor); public static int resolveSecondaryColor(Context context, int backgroundColor, boolean defaultBackgroundIsDark) { boolean useDark = shouldUseDark(backgroundColor, defaultBackgroundIsDark); if (useDark) { return context.getColor( com.android.internal.R.color.notification_secondary_text_color_light); Loading @@ -560,8 +566,9 @@ public class ContrastColorUtil { } } public static int resolveDefaultColor(Context context, int backgroundColor) { boolean useDark = shouldUseDark(backgroundColor); public static int resolveDefaultColor(Context context, int backgroundColor, boolean defaultBackgroundIsDark) { boolean useDark = shouldUseDark(backgroundColor, defaultBackgroundIsDark); if (useDark) { return context.getColor( com.android.internal.R.color.notification_default_color_light); Loading Loading @@ -591,12 +598,11 @@ public class ContrastColorUtil { return ColorUtilsFromCompat.LABToColor(result[0], result[1], result[2]); } private static boolean shouldUseDark(int backgroundColor) { boolean useDark = backgroundColor == Notification.COLOR_DEFAULT; if (!useDark) { useDark = ColorUtilsFromCompat.calculateLuminance(backgroundColor) > 0.5; private static boolean shouldUseDark(int backgroundColor, boolean defaultBackgroundIsDark) { if (backgroundColor == Notification.COLOR_DEFAULT) { return !defaultBackgroundIsDark; } return useDark; return ColorUtilsFromCompat.calculateLuminance(backgroundColor) > 0.5; } public static double calculateLuminance(int backgroundColor) { Loading
core/res/res/values-night/colors.xml 0 → 100644 +31 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- ~ Copyright (C) 2018 The Android Open Source Project ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. ~ You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by applicable law or agreed to in writing, software ~ distributed under the License is distributed on an "AS IS" BASIS, ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the License for the specific language governing permissions and ~ limitations under the License NOTE: You might also want to edit: packages/SystemUI/res/values-night/colors.xml --> <resources> <!-- The primary text color if the text is on top of a dark background. This is also affects colorized notifications with dark backgrounds. --> <color name="notification_primary_text_color_dark">#dadada</color> <!-- The secondary text color if the text is on top of a dark background. --> <color name="notification_secondary_text_color_dark">#dadada</color> <color name="notification_default_color_dark">#dadada</color> <!-- The background color of a notification card. --> <color name="notification_material_background_color">@*android:color/material_grey_900</color> </resources> No newline at end of file
core/res/res/values-night/values.xml +5 −0 Original line number Diff line number Diff line Loading @@ -31,4 +31,9 @@ <!-- volume background --> <item name="panelColorBackground">@color/material_grey_800</item> </style> <style name="TextAppearance.Material.Notification"> <item name="textColor">@color/notification_secondary_text_color_dark</item> <item name="textSize">@dimen/notification_text_size</item> </style> </resources> No newline at end of file