Loading core/java/android/app/Notification.java +39 −5 Original line number Diff line number Diff line Loading @@ -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); } Loading @@ -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 { Loading @@ -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; Loading Loading @@ -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. * Loading Loading @@ -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; } Loading core/res/res/layout/notification_material_action_emphasized_tombstone.xml 0 → 100644 +30 −0 Original line number Diff line number Diff line <?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" /> core/res/res/values/colors.xml +2 −0 Original line number Diff line number Diff line Loading @@ -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> Loading core/res/res/values/symbols.xml +4 −0 Original line number Diff line number Diff line Loading @@ -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" /> Loading Loading @@ -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" /> Loading Loading
core/java/android/app/Notification.java +39 −5 Original line number Diff line number Diff line Loading @@ -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); } Loading @@ -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 { Loading @@ -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; Loading Loading @@ -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. * Loading Loading @@ -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; } Loading
core/res/res/layout/notification_material_action_emphasized_tombstone.xml 0 → 100644 +30 −0 Original line number Diff line number Diff line <?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" />
core/res/res/values/colors.xml +2 −0 Original line number Diff line number Diff line Loading @@ -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> Loading
core/res/res/values/symbols.xml +4 −0 Original line number Diff line number Diff line Loading @@ -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" /> Loading Loading @@ -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" /> Loading