Merge "Fix bug removing semantic colors of CallStyle notification actions." into sc-dev am: 4203db854f
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15405173 Change-Id: If6c4a857e6cc322f8071256bc2645bae74f1274a
This commit is contained in:
@@ -6122,28 +6122,29 @@ public class Notification implements Parcelable
|
|||||||
// change the background bgColor
|
// change the background bgColor
|
||||||
CharSequence title = action.title;
|
CharSequence title = action.title;
|
||||||
ColorStateList[] outResultColor = new ColorStateList[1];
|
ColorStateList[] outResultColor = new ColorStateList[1];
|
||||||
int background = getColors(p).getSecondaryAccentColor();
|
int buttonFillColor = getColors(p).getSecondaryAccentColor();
|
||||||
if (isLegacy()) {
|
if (isLegacy()) {
|
||||||
title = ContrastColorUtil.clearColorSpans(title);
|
title = ContrastColorUtil.clearColorSpans(title);
|
||||||
} else {
|
} else {
|
||||||
title = ensureColorSpanContrast(title, background, outResultColor);
|
int notifBackgroundColor = getColors(p).getBackgroundColor();
|
||||||
|
title = ensureColorSpanContrast(title, notifBackgroundColor, outResultColor);
|
||||||
}
|
}
|
||||||
button.setTextViewText(R.id.action0, processTextSpans(title));
|
button.setTextViewText(R.id.action0, processTextSpans(title));
|
||||||
boolean hasColorOverride = outResultColor[0] != null;
|
boolean hasColorOverride = outResultColor[0] != null;
|
||||||
if (hasColorOverride) {
|
if (hasColorOverride) {
|
||||||
// There's a span spanning the full text, let's take it and use it as the
|
// There's a span spanning the full text, let's take it and use it as the
|
||||||
// background color
|
// background color
|
||||||
background = outResultColor[0].getDefaultColor();
|
buttonFillColor = outResultColor[0].getDefaultColor();
|
||||||
}
|
}
|
||||||
final int textColor = ContrastColorUtil.resolvePrimaryColor(mContext,
|
final int textColor = ContrastColorUtil.resolvePrimaryColor(mContext,
|
||||||
background, mInNightMode);
|
buttonFillColor, mInNightMode);
|
||||||
button.setTextColor(R.id.action0, textColor);
|
button.setTextColor(R.id.action0, textColor);
|
||||||
// We only want about 20% alpha for the ripple
|
// We only want about 20% alpha for the ripple
|
||||||
final int rippleColor = (textColor & 0x00ffffff) | 0x33000000;
|
final int rippleColor = (textColor & 0x00ffffff) | 0x33000000;
|
||||||
button.setColorStateList(R.id.action0, "setRippleColor",
|
button.setColorStateList(R.id.action0, "setRippleColor",
|
||||||
ColorStateList.valueOf(rippleColor));
|
ColorStateList.valueOf(rippleColor));
|
||||||
button.setColorStateList(R.id.action0, "setButtonBackground",
|
button.setColorStateList(R.id.action0, "setButtonBackground",
|
||||||
ColorStateList.valueOf(background));
|
ColorStateList.valueOf(buttonFillColor));
|
||||||
if (p.mCallStyleActions) {
|
if (p.mCallStyleActions) {
|
||||||
button.setImageViewIcon(R.id.action0, action.getIcon());
|
button.setImageViewIcon(R.id.action0, action.getIcon());
|
||||||
boolean priority = action.getExtras().getBoolean(CallStyle.KEY_ACTION_PRIORITY);
|
boolean priority = action.getExtras().getBoolean(CallStyle.KEY_ACTION_PRIORITY);
|
||||||
@@ -6176,8 +6177,8 @@ public class Notification implements Parcelable
|
|||||||
* there exists a full length color span.
|
* there exists a full length color span.
|
||||||
* @return the contrasted charSequence
|
* @return the contrasted charSequence
|
||||||
*/
|
*/
|
||||||
private CharSequence ensureColorSpanContrast(CharSequence charSequence, int background,
|
private static CharSequence ensureColorSpanContrast(CharSequence charSequence,
|
||||||
ColorStateList[] outResultColor) {
|
int background, ColorStateList[] outResultColor) {
|
||||||
if (charSequence instanceof Spanned) {
|
if (charSequence instanceof Spanned) {
|
||||||
Spanned ss = (Spanned) charSequence;
|
Spanned ss = (Spanned) charSequence;
|
||||||
Object[] spans = ss.getSpans(0, ss.length(), Object.class);
|
Object[] spans = ss.getSpans(0, ss.length(), Object.class);
|
||||||
@@ -6197,8 +6198,9 @@ public class Notification implements Parcelable
|
|||||||
int[] colors = textColor.getColors();
|
int[] colors = textColor.getColors();
|
||||||
int[] newColors = new int[colors.length];
|
int[] newColors = new int[colors.length];
|
||||||
for (int i = 0; i < newColors.length; i++) {
|
for (int i = 0; i < newColors.length; i++) {
|
||||||
|
boolean isBgDark = isColorDark(background);
|
||||||
newColors[i] = ContrastColorUtil.ensureLargeTextContrast(
|
newColors[i] = ContrastColorUtil.ensureLargeTextContrast(
|
||||||
colors[i], background, mInNightMode);
|
colors[i], background, isBgDark);
|
||||||
}
|
}
|
||||||
textColor = new ColorStateList(textColor.getStates().clone(),
|
textColor = new ColorStateList(textColor.getStates().clone(),
|
||||||
newColors);
|
newColors);
|
||||||
@@ -6217,8 +6219,9 @@ public class Notification implements Parcelable
|
|||||||
} else if (resultSpan instanceof ForegroundColorSpan) {
|
} else if (resultSpan instanceof ForegroundColorSpan) {
|
||||||
ForegroundColorSpan originalSpan = (ForegroundColorSpan) resultSpan;
|
ForegroundColorSpan originalSpan = (ForegroundColorSpan) resultSpan;
|
||||||
int foregroundColor = originalSpan.getForegroundColor();
|
int foregroundColor = originalSpan.getForegroundColor();
|
||||||
|
boolean isBgDark = isColorDark(background);
|
||||||
foregroundColor = ContrastColorUtil.ensureLargeTextContrast(
|
foregroundColor = ContrastColorUtil.ensureLargeTextContrast(
|
||||||
foregroundColor, background, mInNightMode);
|
foregroundColor, background, isBgDark);
|
||||||
if (fullLength) {
|
if (fullLength) {
|
||||||
outResultColor[0] = ColorStateList.valueOf(foregroundColor);
|
outResultColor[0] = ColorStateList.valueOf(foregroundColor);
|
||||||
resultSpan = null;
|
resultSpan = null;
|
||||||
@@ -6237,6 +6240,19 @@ public class Notification implements Parcelable
|
|||||||
return charSequence;
|
return charSequence;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if the color is light or dark. Specifically, this is using the same metric as
|
||||||
|
* {@link ContrastColorUtil#resolvePrimaryColor(Context, int, boolean)} and peers so that
|
||||||
|
* the direction of color shift is consistent.
|
||||||
|
*
|
||||||
|
* @param color the color to check
|
||||||
|
* @return true if the color has higher contrast with white than black
|
||||||
|
*/
|
||||||
|
private static boolean isColorDark(int color) {
|
||||||
|
// as per ContrastColorUtil.shouldUseDark, this uses the color contrast midpoint.
|
||||||
|
return ContrastColorUtil.calculateLuminance(color) <= 0.17912878474;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Whether we are currently building a notification from a legacy (an app that
|
* @return Whether we are currently building a notification from a legacy (an app that
|
||||||
* doesn't create material notifications by itself) app.
|
* doesn't create material notifications by itself) app.
|
||||||
|
|||||||
@@ -29,5 +29,8 @@
|
|||||||
<color name="resolver_empty_state_text">#FFFFFF</color>
|
<color name="resolver_empty_state_text">#FFFFFF</color>
|
||||||
<color name="resolver_empty_state_icon">#FFFFFF</color>
|
<color name="resolver_empty_state_icon">#FFFFFF</color>
|
||||||
|
|
||||||
|
<color name="call_notification_decline_color">#E66A5E</color>
|
||||||
|
<color name="call_notification_answer_color">#5DBA80</color>
|
||||||
|
|
||||||
<color name="personal_apps_suspension_notification_color">#8AB4F8</color>
|
<color name="personal_apps_suspension_notification_color">#8AB4F8</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user