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
This commit is contained in:
Jeff DeCew
2021-09-09 13:38:48 -04:00
parent 5cb7307ebb
commit 050a0d0d64
2 changed files with 15 additions and 7 deletions

View File

@@ -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.
*
* <p>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.
*
* <p>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);
}

View File

@@ -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));
}