From 1eda1ef91395e5b8529f6f9444d2897abd99d4dd Mon Sep 17 00:00:00 2001 From: Ibrahim Yilmaz Date: Fri, 27 Jan 2023 16:00:58 +0000 Subject: [PATCH] Fix disabled state of CallStyle buttons to make them look/act disabled TLDR; Call Style Buttons does not seem disabled when they dont have intent. In Android Notifications, Button's enabled state is coupled with the action intent. It means when there is an intent, the button is enabled. Otherwise, it is disabled. We are handling this for normal action button by creating specific layout for disabled view but not for emphasized buttons. We follow the similar approach here to mitigate this visual issue. Bug: 265021861 Test: We can verify the change by observing visual effect on the Call Style Notification. Change-Id: I2427f613e6051bf887dfe99c6caead1521b1e661 --- core/java/android/app/Notification.java | 44 ++++++++++++++++--- ...n_material_action_emphasized_tombstone.xml | 30 +++++++++++++ core/res/res/values/colors.xml | 2 + core/res/res/values/symbols.xml | 4 ++ 4 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 core/res/res/layout/notification_material_action_emphasized_tombstone.xml diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 46d8481646c99..0fd80c5698a9c 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -6185,10 +6185,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); } @@ -6200,6 +6198,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 { @@ -6215,8 +6219,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; @@ -6246,6 +6256,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. * @@ -6725,6 +6755,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 200ea44e9845e..ad5b9c0e0f548 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -3304,7 +3304,10 @@ + + + @@ -3356,6 +3359,7 @@ +