Update the style of emphasized notification actions.
* This removed many of the differences between CallStyle and emphasized actions. * These actions are now pill shaped with a solid bg color, no stroke, less height, less spacing between, and wrapping content instead of splitting space equally. Fixes: 187533622 Test: manual testing with Notify, Notify2, and Clock (using timers and alarms) Change-Id: I8c554755755c59f2756870f7cd2e0c533d22d823
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,7 +46,6 @@ public class NotificationActionListLayout extends LinearLayout {
|
||||
private ArrayList<Pair<Integer, TextView>> mMeasureOrderTextViews = new ArrayList<>();
|
||||
private ArrayList<View> 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
|
||||
|
||||
@@ -24,13 +24,11 @@
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="@dimen/notification_action_button_radius" />
|
||||
<padding android:left="@dimen/button_padding_horizontal_material"
|
||||
<padding android:left="12dp"
|
||||
android:top="@dimen/button_padding_vertical_material"
|
||||
android:right="@dimen/button_padding_horizontal_material"
|
||||
android:right="12dp"
|
||||
android:bottom="@dimen/button_padding_vertical_material" />
|
||||
<solid android:color="@color/white" />
|
||||
<stroke android:width="@dimen/emphasized_button_stroke_width"
|
||||
android:color="@color/material_grey_300"/>
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -224,14 +224,14 @@
|
||||
<!-- The margin on the end of the top-line content views (accommodates the expander) -->
|
||||
<dimen name="notification_heading_margin_end">56dp</dimen>
|
||||
|
||||
<!-- The height of the notification action list -->
|
||||
<!-- The total height of the notification action list -->
|
||||
<dimen name="notification_action_list_height">60dp</dimen>
|
||||
|
||||
<!-- The margin of the notification action list at the top -->
|
||||
<dimen name="notification_action_list_margin_top">0dp</dimen>
|
||||
|
||||
<!-- The height of the notification action list -->
|
||||
<dimen name="notification_action_emphasized_height">48dp</dimen>
|
||||
<!-- The visual height of the emphasized notification action -->
|
||||
<dimen name="notification_action_emphasized_height">36dp</dimen>
|
||||
|
||||
<!-- The padding of the actions in non-conversation layout. For conversations, the analogous
|
||||
value is calculated in ConversationLayout#updateActionListPadding() -->
|
||||
@@ -252,7 +252,7 @@
|
||||
<dimen name="notification_actions_icon_drawable_size">20dp</dimen>
|
||||
|
||||
<!-- The corner radius if the emphasized action buttons in a notification -->
|
||||
<dimen name="notification_action_button_radius">8dp</dimen>
|
||||
<dimen name="notification_action_button_radius">18dp</dimen>
|
||||
|
||||
<!-- Size of the stroke with for the emphasized notification button style -->
|
||||
<dimen name="emphasized_button_stroke_width">1dp</dimen>
|
||||
|
||||
Reference in New Issue
Block a user