diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 2dcdd07c99462..c6847aac0ceaf 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -5662,11 +5662,6 @@ public class Notification implements Parcelable R.dimen.call_notification_collapsible_indent); } big.setBoolean(R.id.actions, "setEmphasizedMode", emphazisedMode); - if (p.mCallStyleActions) { - // Use "wrap_content" (unlike normal emphasized mode) and allow prioritizing the - // required actions (Answer, Decline, and Hang Up). - big.setBoolean(R.id.actions, "setPrioritizedWrapMode", true); - } if (numActions > 0 && !p.mHideActions) { big.setViewVisibility(R.id.actions_container, View.VISIBLE); big.setViewVisibility(R.id.actions, View.VISIBLE); @@ -5683,7 +5678,7 @@ public class Notification implements Parcelable // Clear the drawable button.setInt(R.id.action0, "setBackgroundResource", 0); } - if (p.mCallStyleActions && i > 0) { + if (emphazisedMode && i > 0) { // Clear start margin from non-first buttons to reduce the gap between them. // (8dp remaining gap is from all buttons' standard 4dp inset). button.setViewLayoutMarginDimen(R.id.action0, RemoteViews.MARGIN_START, 0); @@ -6103,26 +6098,21 @@ public class Notification implements Parcelable // change the background bgColor CharSequence title = action.title; ColorStateList[] outResultColor = new ColorStateList[1]; - int background = getBackgroundColor(p); + int background = getSecondaryAccentColor(p); if (isLegacy()) { title = ContrastColorUtil.clearColorSpans(title); } else { title = ensureColorSpanContrast(title, background, outResultColor); } button.setTextViewText(R.id.action0, processTextSpans(title)); - final int textColor; boolean hasColorOverride = outResultColor[0] != null; if (hasColorOverride) { // There's a span spanning the full text, let's take it and use it as the // background color background = outResultColor[0].getDefaultColor(); - textColor = ContrastColorUtil.resolvePrimaryColor(mContext, - background, mInNightMode); - } else if (mTintActionButtons && !mInNightMode && !isBackgroundColorized(p)) { - textColor = getAccentColor(p); - } else { - textColor = getPrimaryTextColor(p); } + final int textColor = ContrastColorUtil.resolvePrimaryColor(mContext, + background, mInNightMode); button.setTextColor(R.id.action0, textColor); // We only want about 20% alpha for the ripple final int rippleColor = (textColor & 0x00ffffff) | 0x33000000; @@ -6130,11 +6120,10 @@ public class Notification implements Parcelable ColorStateList.valueOf(rippleColor)); button.setColorStateList(R.id.action0, "setButtonBackground", ColorStateList.valueOf(background)); - button.setBoolean(R.id.action0, "setHasStroke", !hasColorOverride); if (p.mCallStyleActions) { button.setImageViewIcon(R.id.action0, action.getIcon()); boolean priority = action.getExtras().getBoolean(CallStyle.KEY_ACTION_PRIORITY); - button.setBoolean(R.id.action0, "setWrapModePriority", priority); + button.setBoolean(R.id.action0, "setIsPriority", priority); int minWidthDimen = priority ? R.dimen.call_notification_system_action_min_width : 0; button.setIntDimen(R.id.action0, "setMinimumWidth", minWidthDimen); @@ -6319,6 +6308,22 @@ public class Notification implements Parcelable return getContrastColor(p); } + /** + * Gets the secondary accent color for colored UI elements. If we're tinting with the theme + * accent, this is the theme accent color, otherwise this would be identical to + * {@link #getSmallIconColor(StandardTemplateParams)}. + */ + private @ColorInt int getSecondaryAccentColor(StandardTemplateParams p) { + if (isBackgroundColorized(p)) { + return getSecondaryTextColor(p); + } + int color = obtainThemeColor(R.attr.colorAccentSecondary, COLOR_INVALID); + if (color != COLOR_INVALID) { + return color; + } + return getContrastColor(p); + } + /** * Gets the "surface protection" color from the theme, or a variant of the normal background * color when colorized, or when not using theme color tints. diff --git a/core/java/com/android/internal/widget/EmphasizedNotificationButton.java b/core/java/com/android/internal/widget/EmphasizedNotificationButton.java index 058a9218def45..4460e4a0ea781 100644 --- a/core/java/com/android/internal/widget/EmphasizedNotificationButton.java +++ b/core/java/com/android/internal/widget/EmphasizedNotificationButton.java @@ -27,9 +27,7 @@ import android.graphics.drawable.Icon; import android.graphics.drawable.RippleDrawable; import android.util.AttributeSet; import android.view.RemotableViewMethod; -import android.view.ViewGroup; import android.widget.Button; -import android.widget.LinearLayout; import android.widget.RemoteViews; import com.android.internal.R; @@ -42,8 +40,6 @@ import com.android.internal.R; @RemoteViews.RemoteView public class EmphasizedNotificationButton extends Button { private final RippleDrawable mRipple; - private final int mStrokeWidth; - private final int mStrokeColor; private boolean mPriority; public EmphasizedNotificationButton(Context context) { @@ -63,9 +59,6 @@ public class EmphasizedNotificationButton extends Button { super(context, attrs, defStyleAttr, defStyleRes); DrawableWrapper background = (DrawableWrapper) getBackground().mutate(); mRipple = (RippleDrawable) background.getDrawable(); - mStrokeWidth = getResources().getDimensionPixelSize( - com.android.internal.R.dimen.emphasized_button_stroke_width); - mStrokeColor = getContext().getColor(com.android.internal.R.color.material_grey_300); mRipple.mutate(); } @@ -82,13 +75,6 @@ public class EmphasizedNotificationButton extends Button { invalidate(); } - @RemotableViewMethod - public void setHasStroke(boolean hasStroke) { - GradientDrawable inner = (GradientDrawable) mRipple.getDrawable(0); - inner.setStroke(hasStroke ? mStrokeWidth : 0, mStrokeColor); - invalidate(); - } - /** * Sets an image icon which will have its size constrained and will be set to the same color as * the text. Must be called after {@link #setTextColor(int)} for the latter to work. @@ -121,18 +107,13 @@ public class EmphasizedNotificationButton extends Button { } /** - * Changes the LayoutParams.width to WRAP_CONTENT, with the argument representing if this view - * is a priority over its peers (which affects weight). + * Sets whether this view is a priority over its peers (which affects width). + * Specifically, this is used by {@link NotificationActionListLayout} to give this view width + * priority ahead of user-defined buttons when allocating horizontal space. */ @RemotableViewMethod - public void setWrapModePriority(boolean priority) { + public void setIsPriority(boolean priority) { mPriority = priority; - ViewGroup.LayoutParams layoutParams = getLayoutParams(); - layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT; - if (layoutParams instanceof LinearLayout.LayoutParams) { - ((LinearLayout.LayoutParams) layoutParams).weight = 0; - } - setLayoutParams(layoutParams); } /** diff --git a/core/java/com/android/internal/widget/NotificationActionListLayout.java b/core/java/com/android/internal/widget/NotificationActionListLayout.java index 8e6497b204c78..ea7188840aa2b 100644 --- a/core/java/com/android/internal/widget/NotificationActionListLayout.java +++ b/core/java/com/android/internal/widget/NotificationActionListLayout.java @@ -46,7 +46,6 @@ public class NotificationActionListLayout extends LinearLayout { private ArrayList> mMeasureOrderTextViews = new ArrayList<>(); private ArrayList mMeasureOrderOther = new ArrayList<>(); private boolean mEmphasizedMode; - private boolean mPrioritizedWrapMode; private int mDefaultPaddingBottom; private int mDefaultPaddingTop; private int mEmphasizedHeight; @@ -72,10 +71,6 @@ public class NotificationActionListLayout extends LinearLayout { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - if (mEmphasizedMode && !mPrioritizedWrapMode) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - return; - } final int N = getChildCount(); int textViews = 0; int otherViews = 0; @@ -175,8 +170,7 @@ public class NotificationActionListLayout extends LinearLayout { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { View c = getChildAt(i); - if (c instanceof EmphasizedNotificationButton - && ((EmphasizedNotificationButton) c).isPriority()) { + if (isPriority(c)) { // add with 0 length to ensure that this view is measured before others. mMeasureOrderTextViews.add(Pair.create(0, (TextView) c)); } else if (c instanceof TextView && ((TextView) c).getText().length() > 0) { @@ -213,10 +207,6 @@ public class NotificationActionListLayout extends LinearLayout { @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { - if (mEmphasizedMode && !mPrioritizedWrapMode) { - super.onLayout(changed, left, top, right, bottom); - return; - } final boolean isLayoutRtl = isLayoutRtl(); final int paddingTop = mPaddingTop; final boolean centerAligned = (mGravity & Gravity.CENTER_HORIZONTAL) != 0; @@ -292,16 +282,6 @@ public class NotificationActionListLayout extends LinearLayout { com.android.internal.R.dimen.notification_action_list_height); } - /** - * When used with emphasizedMode, changes the button sizing behavior to prioritize certain - * buttons (which are system generated) to not scrunch, and leave the remaining space for - * custom actions. - */ - @RemotableViewMethod - public void setPrioritizedWrapMode(boolean prioritizedWrapMode) { - mPrioritizedWrapMode = prioritizedWrapMode; - } - /** * When buttons are in wrap mode, this is a padding that will be applied at the start of the * layout of the actions, but only when those actions would fit with the entire padding diff --git a/core/res/res/drawable/btn_notification_emphasized.xml b/core/res/res/drawable/btn_notification_emphasized.xml index ad680549aaa1c..63707ab7f5d69 100644 --- a/core/res/res/drawable/btn_notification_emphasized.xml +++ b/core/res/res/drawable/btn_notification_emphasized.xml @@ -24,13 +24,11 @@ - - diff --git a/core/res/res/layout/notification_material_action_emphasized.xml b/core/res/res/layout/notification_material_action_emphasized.xml index cd1f1ab88c96c..ea841851cd443 100644 --- a/core/res/res/layout/notification_material_action_emphasized.xml +++ b/core/res/res/layout/notification_material_action_emphasized.xml @@ -18,10 +18,9 @@ xmlns:android="http://schemas.android.com/apk/res/android" style="@style/NotificationEmphasizedAction" android:id="@+id/action0" - android:layout_width="match_parent" + android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginStart="12dp" - android:layout_weight="1" android:drawablePadding="6dp" android:gravity="center" android:textColor="@color/notification_default_color" diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml index 4f90a174fef76..d3343060a8197 100644 --- a/core/res/res/values/dimens.xml +++ b/core/res/res/values/dimens.xml @@ -224,14 +224,14 @@ 56dp - + 60dp 0dp - - 48dp + + 36dp @@ -252,7 +252,7 @@ 20dp - 8dp + 18dp 1dp