From 050a0d0d64a33d16584319929456552ecc151a42 Mon Sep 17 00:00:00 2001 From: Jeff DeCew Date: Thu, 9 Sep 2021 13:38:48 -0400 Subject: [PATCH] Reduce the color contrast requirements for the emphasized action button fill color. This reduces the contrast requirement between the notification background and the button fill from 3:1 to 1.3:1 Fixes: 196393060 Test: manual testing using the go/notify2-apk and the CallStyle color customizer Test: android.app.NotificationTest Change-Id: I0fc3b7ae1ede7afd28974c59fa2a58d7fea2e9de --- core/java/android/app/Notification.java | 16 ++++++++++++---- .../src/android/app/NotificationTest.java | 6 +++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 91605b78a56bb..719025f9e2159 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -1884,6 +1884,14 @@ public class Notification implements Parcelable * clicks. To launch an activity in those cases, provide a {@link PendingIntent} for the * activity itself. * + *

How an Action is displayed, including whether the {@code icon}, {@code text}, or + * both are displayed or required, depends on where and how the action is used, and the + * {@link Style} applied to the Notification. + * + *

When the {@code title} is a {@link android.text.Spanned}, any colors set by a + * {@link ForegroundColorSpan} or {@link TextAppearanceSpan} may be removed or displayed + * with an altered in luminance to ensure proper contrast within the Notification. + * * @param icon icon to show for this action * @param title the title of the action * @param intent the {@link PendingIntent} to fire when users trigger this action @@ -6128,7 +6136,7 @@ public class Notification implements Parcelable // Check for a full-length span color to use as the button fill color. Integer fullLengthColor = getFullLengthSpanColor(title); if (fullLengthColor != null) { - // Ensure the custom button fill has 3:1 contrast w/ notification bg. + // Ensure the custom button fill has 1.3:1 contrast w/ notification bg. int notifBackgroundColor = getColors(p).getBackgroundColor(); buttonFillColor = ensureButtonFillContrast( fullLengthColor, notifBackgroundColor); @@ -6296,7 +6304,7 @@ public class Notification implements Parcelable } /** - * Finds a button fill color with sufficient contrast over bg (3:1) that has the same hue + * Finds a button fill color with sufficient contrast over bg (1.3:1) that has the same hue * as the original color, but is lightened or darkened depending on whether the background * is dark or light. * @@ -6305,8 +6313,8 @@ public class Notification implements Parcelable @VisibleForTesting public static int ensureButtonFillContrast(int color, int bg) { return isColorDark(bg) - ? ContrastColorUtil.findContrastColorAgainstDark(color, bg, true, 3) - : ContrastColorUtil.findContrastColor(color, bg, true, 3); + ? ContrastColorUtil.findContrastColorAgainstDark(color, bg, true, 1.3) + : ContrastColorUtil.findContrastColor(color, bg, true, 1.3); } diff --git a/core/tests/coretests/src/android/app/NotificationTest.java b/core/tests/coretests/src/android/app/NotificationTest.java index 02d8a4b783a51..34c1763b32869 100644 --- a/core/tests/coretests/src/android/app/NotificationTest.java +++ b/core/tests/coretests/src/android/app/NotificationTest.java @@ -436,7 +436,7 @@ public class NotificationTest { Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); CharSequence result = ensureColorSpanContrast(text, background); - // ensure the span has been updated to have > 3:1 contrast ratio with fill color + // ensure the span has been updated to have > 1.3:1 contrast ratio with fill color Object[] spans = ((Spannable) result).getSpans(0, result.length(), Object.class); assertThat(spans).hasLength(1); int foregroundColor = ((ForegroundColorSpan) spans[0]).getForegroundColor(); @@ -487,7 +487,7 @@ public class NotificationTest { int background = Color.LTGRAY; int foreground = Color.LTGRAY; int result = Notification.Builder.ensureButtonFillContrast(foreground, background); - assertContrastIsWithinRange(result, background, 3, 3.2); + assertContrastIsWithinRange(result, background, 1.3, 1.5); assertThat(ContrastColorUtil.calculateLuminance(result)) .isLessThan(ContrastColorUtil.calculateLuminance(background)); } @@ -497,7 +497,7 @@ public class NotificationTest { int background = Color.DKGRAY; int foreground = Color.DKGRAY; int result = Notification.Builder.ensureButtonFillContrast(foreground, background); - assertContrastIsWithinRange(result, background, 3, 3.2); + assertContrastIsWithinRange(result, background, 1.3, 1.5); assertThat(ContrastColorUtil.calculateLuminance(result)) .isGreaterThan(ContrastColorUtil.calculateLuminance(background)); }