summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ibrahim Yilmaz <iyz@google.com> 2023-02-09 18:25:13 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-02-09 18:25:13 +0000
commitbc68ad7c5d399909537746289f048c257e33a4fd (patch)
tree14496ed1b84b3b3cc066c0b443a178e8103e4d55
parent016a6b97e459f3b214e87934b1aa818f1b0d5b00 (diff)
parent1eda1ef91395e5b8529f6f9444d2897abd99d4dd (diff)
Merge "Fix disabled state of CallStyle buttons to make them look/act disabled" into tm-qpr-dev
-rw-r--r--core/java/android/app/Notification.java44
-rw-r--r--core/res/res/layout/notification_material_action_emphasized_tombstone.xml30
-rw-r--r--core/res/res/values/colors.xml2
-rw-r--r--core/res/res/values/symbols.xml4
4 files changed, 75 insertions, 5 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index 46d8481646c9..0fd80c5698a9 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 000000000000..60f10dbcdebc
--- /dev/null
+++ b/core/res/res/layout/notification_material_action_emphasized_tombstone.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2023 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<com.android.internal.widget.EmphasizedNotificationButton
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ style="@style/NotificationEmphasizedAction"
+ android:id="@+id/action0"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:layout_marginStart="12dp"
+ android:drawablePadding="6dp"
+ android:enabled="false"
+ android:gravity="center"
+ android:singleLine="true"
+ android:ellipsize="end"
+/>
diff --git a/core/res/res/values/colors.xml b/core/res/res/values/colors.xml
index d5875f547e91..b83d3b4ea298 100644
--- a/core/res/res/values/colors.xml
+++ b/core/res/res/values/colors.xml
@@ -150,6 +150,8 @@
<color name="notification_default_color">#757575</color> <!-- Gray 600 -->
<color name="notification_action_button_text_color">@color/notification_default_color</color>
+ <item name="notification_action_disabled_content_alpha" format="float" type="dimen">0.38</item>
+ <item name="notification_action_disabled_container_alpha" format="float" type="dimen">0.12</item>
<color name="notification_progress_background_color">@color/notification_secondary_text_color_current</color>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 200ea44e9845..ad5b9c0e0f54 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -3304,7 +3304,10 @@
<java-symbol type="id" name="notification_action_list_margin_target" />
<java-symbol type="dimen" name="notification_actions_padding_start"/>
<java-symbol type="dimen" name="notification_actions_collapsed_priority_width"/>
+ <!--prefer to use disabled content and surface alpha values for disabled actions-->
<java-symbol type="dimen" name="notification_action_disabled_alpha" />
+ <java-symbol type="dimen" name="notification_action_disabled_content_alpha" />
+ <java-symbol type="dimen" name="notification_action_disabled_container_alpha" />
<java-symbol type="id" name="tag_margin_end_when_icon_visible" />
<java-symbol type="id" name="tag_margin_end_when_icon_gone" />
<java-symbol type="id" name="tag_uses_right_icon_drawable" />
@@ -3356,6 +3359,7 @@
<java-symbol type="string" name="unsupported_display_size_message" />
<java-symbol type="layout" name="notification_material_action_emphasized" />
+ <java-symbol type="layout" name="notification_material_action_emphasized_tombstone" />
<!-- Package name for the device provisioning package -->
<java-symbol type="string" name="config_deviceProvisioningPackage" />