diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 834d186eebb75..0c26d4375f72e 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -6189,10 +6189,8 @@ public class Notification implements Parcelable private RemoteViews generateActionButton(Action action, boolean emphasizedMode, StandardTemplateParams p) { final boolean tombstone = (action.actionIntent == null); - RemoteViews button = new BuilderRemoteViews(mContext.getApplicationInfo(), - emphasizedMode ? getEmphasizedActionLayoutResource() - : tombstone ? getActionTombstoneLayoutResource() - : getActionLayoutResource()); + final RemoteViews button = new BuilderRemoteViews(mContext.getApplicationInfo(), + getActionButtonLayoutResource(emphasizedMode, tombstone)); if (!tombstone) { button.setOnClickPendingIntent(R.id.action0, action.actionIntent); } @@ -6204,6 +6202,12 @@ public class Notification implements Parcelable // change the background bgColor CharSequence title = action.title; int buttonFillColor = getColors(p).getSecondaryAccentColor(); + if (tombstone) { + buttonFillColor = setAlphaComponentByFloatDimen(mContext, + ContrastColorUtil.resolveSecondaryColor( + mContext, getColors(p).getBackgroundColor(), mInNightMode), + R.dimen.notification_action_disabled_container_alpha); + } if (isLegacy()) { title = ContrastColorUtil.clearColorSpans(title); } else { @@ -6219,8 +6223,14 @@ public class Notification implements Parcelable title = ensureColorSpanContrast(title, buttonFillColor); } button.setTextViewText(R.id.action0, processTextSpans(title)); - final int textColor = ContrastColorUtil.resolvePrimaryColor(mContext, + int textColor = ContrastColorUtil.resolvePrimaryColor(mContext, buttonFillColor, mInNightMode); + if (tombstone) { + textColor = setAlphaComponentByFloatDimen(mContext, + ContrastColorUtil.resolveSecondaryColor( + mContext, getColors(p).getBackgroundColor(), mInNightMode), + R.dimen.notification_action_disabled_content_alpha); + } button.setTextColor(R.id.action0, textColor); // We only want about 20% alpha for the ripple final int rippleColor = (textColor & 0x00ffffff) | 0x33000000; @@ -6250,6 +6260,26 @@ public class Notification implements Parcelable return button; } + private int getActionButtonLayoutResource(boolean emphasizedMode, boolean tombstone) { + if (emphasizedMode) { + return tombstone ? getEmphasizedTombstoneActionLayoutResource() + : getEmphasizedActionLayoutResource(); + } else { + return tombstone ? getActionTombstoneLayoutResource() + : getActionLayoutResource(); + } + } + + /** + * Set the alpha component of {@code color} to be {@code alphaDimenResId}. + */ + private static int setAlphaComponentByFloatDimen(Context context, @ColorInt int color, + @DimenRes int alphaDimenResId) { + final TypedValue alphaValue = new TypedValue(); + context.getResources().getValue(alphaDimenResId, alphaValue, true); + return ColorUtils.setAlphaComponent(color, Math.round(alphaValue.getFloat() * 255)); + } + /** * Extract the color from a full-length span from the text. * @@ -6729,6 +6759,10 @@ public class Notification implements Parcelable return R.layout.notification_material_action_emphasized; } + private int getEmphasizedTombstoneActionLayoutResource() { + return R.layout.notification_material_action_emphasized_tombstone; + } + private int getActionTombstoneLayoutResource() { return R.layout.notification_material_action_tombstone; } diff --git a/core/res/res/layout/notification_material_action_emphasized_tombstone.xml b/core/res/res/layout/notification_material_action_emphasized_tombstone.xml new file mode 100644 index 0000000000000..60f10dbcdebc6 --- /dev/null +++ b/core/res/res/layout/notification_material_action_emphasized_tombstone.xml @@ -0,0 +1,30 @@ + + + + diff --git a/core/res/res/values/colors.xml b/core/res/res/values/colors.xml index d5875f547e91c..b83d3b4ea298f 100644 --- a/core/res/res/values/colors.xml +++ b/core/res/res/values/colors.xml @@ -150,6 +150,8 @@ #757575 @color/notification_default_color + 0.38 + 0.12 @color/notification_secondary_text_color_current diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 88a398bf255da..578fd9bb69ad0 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -3295,7 +3295,10 @@ + + + @@ -3347,6 +3350,7 @@ +