diff options
| author | Jeff DeCew <jeffdq@google.com> | 2020-11-17 13:21:53 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-11-17 13:21:53 +0000 |
| commit | 5185c6bf6630744a73dbc29b0204422368dfdc76 (patch) | |
| tree | 920fc9f76de9ef2c930a019240e31d2e9841288a /core/java/android/view | |
| parent | 9a8f3712e8f94756ab4a81133c56af30cc93865b (diff) | |
| parent | 89cc6a1fc321e709312f71f199fa3757a3ee94cb (diff) | |
Merge changes from topic "template_redesign"
* changes:
Update variable names to reduce confusion.
Fix/hack MessagingStyle notifications
Reduce notification minimized height
Fix the placement of the work profile and feedback badges.
Fix HUNs
Remove the unneeded icon spacing in the InboxStyle.
Hide app name from minimized notifications
Notification Title is 16pt in Big state
Ensure headerless notification with large icon is big enough.
Round corners of BigPicture
Increase the expand button touchable area.
Remove the reply action entirely.
Notification template redesign; part 1.
Remove night-mode override of notification_divider_height
Diffstat (limited to 'core/java/android/view')
| -rw-r--r-- | core/java/android/view/NotificationHeaderView.java | 143 | ||||
| -rw-r--r-- | core/java/android/view/NotificationTopLineView.java | 67 |
2 files changed, 55 insertions, 155 deletions
diff --git a/core/java/android/view/NotificationHeaderView.java b/core/java/android/view/NotificationHeaderView.java index 2bd3d46d389a..f7fbb1ce0ab9 100644 --- a/core/java/android/view/NotificationHeaderView.java +++ b/core/java/android/view/NotificationHeaderView.java @@ -27,6 +27,7 @@ import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.Build; import android.util.AttributeSet; +import android.widget.FrameLayout; import android.widget.RemoteViews; import com.android.internal.R; @@ -41,15 +42,14 @@ import java.util.ArrayList; * @hide */ @RemoteViews.RemoteView -public class NotificationHeaderView extends ViewGroup { - private final int mChildMinWidth; +public class NotificationHeaderView extends FrameLayout { private final int mContentEndMargin; + private final int mHeadingEndMargin; private OnClickListener mExpandClickListener; private HeaderTouchListener mTouchListener = new HeaderTouchListener(); private NotificationTopLineView mTopLineView; private NotificationExpandButton mExpandButton; private CachingIconView mIcon; - private int mHeaderTextMarginEnd; private Drawable mBackground; private boolean mEntireHeaderClickable; private boolean mExpandOnlyOnButton; @@ -82,8 +82,8 @@ public class NotificationHeaderView extends ViewGroup { int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); Resources res = getResources(); - mChildMinWidth = res.getDimensionPixelSize(R.dimen.notification_header_shrink_min_width); mContentEndMargin = res.getDimensionPixelSize(R.dimen.notification_content_margin_end); + mHeadingEndMargin = res.getDimensionPixelSize(R.dimen.notification_heading_margin_end); mEntireHeaderClickable = res.getBoolean(R.bool.config_notificationHeaderClickableForExpand); } @@ -96,108 +96,6 @@ public class NotificationHeaderView extends ViewGroup { setClipToPadding(false); } - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - final int givenWidth = MeasureSpec.getSize(widthMeasureSpec); - final int givenHeight = MeasureSpec.getSize(heightMeasureSpec); - int wrapContentWidthSpec = MeasureSpec.makeMeasureSpec(givenWidth, - MeasureSpec.AT_MOST); - int wrapContentHeightSpec = MeasureSpec.makeMeasureSpec(givenHeight, - MeasureSpec.AT_MOST); - int totalWidth = getPaddingStart(); - int iconWidth = getPaddingEnd(); - for (int i = 0; i < getChildCount(); i++) { - final View child = getChildAt(i); - if (child.getVisibility() == GONE) { - // We'll give it the rest of the space in the end - continue; - } - final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); - int childWidthSpec = getChildMeasureSpec(wrapContentWidthSpec, - lp.leftMargin + lp.rightMargin, lp.width); - int childHeightSpec = getChildMeasureSpec(wrapContentHeightSpec, - lp.topMargin + lp.bottomMargin, lp.height); - child.measure(childWidthSpec, childHeightSpec); - // Icons that should go at the end - if (child == mExpandButton) { - iconWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth(); - } else { - totalWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth(); - } - } - - // Ensure that there is at least enough space for the icons - int endMargin = Math.max(mHeaderTextMarginEnd, iconWidth); - if (totalWidth > givenWidth - endMargin) { - int overFlow = totalWidth - givenWidth + endMargin; - // We are overflowing; shrink the top line - shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mTopLineView, - mChildMinWidth); - } - setMeasuredDimension(givenWidth, givenHeight); - } - - private int shrinkViewForOverflow(int heightSpec, int overFlow, View targetView, - int minimumWidth) { - final int oldWidth = targetView.getMeasuredWidth(); - if (overFlow > 0 && targetView.getVisibility() != GONE && oldWidth > minimumWidth) { - // we're still too big - int newSize = Math.max(minimumWidth, oldWidth - overFlow); - int childWidthSpec = MeasureSpec.makeMeasureSpec(newSize, MeasureSpec.AT_MOST); - targetView.measure(childWidthSpec, heightSpec); - overFlow -= oldWidth - newSize; - } - return overFlow; - } - - @Override - protected void onLayout(boolean changed, int l, int t, int r, int b) { - int left = getPaddingStart(); - int end = getMeasuredWidth(); - int childCount = getChildCount(); - int ownHeight = getMeasuredHeight() - getPaddingTop() - getPaddingBottom(); - for (int i = 0; i < childCount; i++) { - View child = getChildAt(i); - if (child.getVisibility() == GONE) { - continue; - } - int childHeight = child.getMeasuredHeight(); - MarginLayoutParams params = (MarginLayoutParams) child.getLayoutParams(); - int layoutLeft; - int layoutRight; - int top = (int) (getPaddingTop() + (ownHeight - childHeight) / 2.0f); - int bottom = top + childHeight; - // Icons that should go at the end - if (child == mExpandButton) { - if (end == getMeasuredWidth()) { - layoutRight = end - mContentEndMargin; - } else { - layoutRight = end - params.getMarginEnd(); - } - layoutLeft = layoutRight - child.getMeasuredWidth(); - end = layoutLeft - params.getMarginStart(); - } else { - left += params.getMarginStart(); - int right = left + child.getMeasuredWidth(); - layoutLeft = left; - layoutRight = right; - left = right + params.getMarginEnd(); - } - if (getLayoutDirection() == LAYOUT_DIRECTION_RTL) { - int ltrLeft = layoutLeft; - layoutLeft = getWidth() - layoutRight; - layoutRight = getWidth() - ltrLeft; - } - child.layout(layoutLeft, top, layoutRight, bottom); - } - updateTouchListener(); - } - - @Override - public LayoutParams generateLayoutParams(AttributeSet attrs) { - return new MarginLayoutParams(getContext(), attrs); - } - /** * Set a {@link Drawable} to be displayed as a background on the header. */ @@ -252,23 +150,34 @@ public class NotificationHeaderView extends ViewGroup { } /** - * Sets the margin end for the text portion of the header, excluding right-aligned elements - * @param headerTextMarginEnd margin size + * Sets the extra margin at the end of the top line of left-aligned text + icons. + * This value will have the margin required to accommodate the expand button added to it. + * + * @param extraMarginEnd extra margin */ @RemotableViewMethod - public void setHeaderTextMarginEnd(int headerTextMarginEnd) { - if (mHeaderTextMarginEnd != headerTextMarginEnd) { - mHeaderTextMarginEnd = headerTextMarginEnd; - requestLayout(); - } + public void setTopLineExtraMarginEnd(int extraMarginEnd) { + mTopLineView.setHeaderTextMarginEnd(extraMarginEnd + mHeadingEndMargin); + } + + /** + * Get the current margin end value for the header text. + * Add this to {@link #getTopLineBaseMarginEnd()} to get the total margin of the top line. + * + * @return extra margin + */ + public int getTopLineExtraMarginEnd() { + return mTopLineView.getHeaderTextMarginEnd() - mHeadingEndMargin; } /** - * Get the current margin end value for the header text - * @return margin size + * Get the base margin at the end of the top line view. + * Add this to {@link #getTopLineExtraMarginEnd()} to get the total margin of the top line. + * + * @return base margin */ - public int getHeaderTextMarginEnd() { - return mHeaderTextMarginEnd; + public int getTopLineBaseMarginEnd() { + return mHeadingEndMargin; } /** diff --git a/core/java/android/view/NotificationTopLineView.java b/core/java/android/view/NotificationTopLineView.java index 24748222b3af..a8eabe5a7967 100644 --- a/core/java/android/view/NotificationTopLineView.java +++ b/core/java/android/view/NotificationTopLineView.java @@ -26,9 +26,6 @@ import android.widget.RemoteViews; import com.android.internal.R; -import java.util.Arrays; -import java.util.List; - /** * The top line of content in a notification view. * This includes the text views and badges but excludes the icon and the expander. @@ -39,16 +36,14 @@ import java.util.List; public class NotificationTopLineView extends ViewGroup { private final int mGravityY; private final int mChildMinWidth; - private final int mContentEndMargin; - private View mAppName; + @Nullable private View mAppName; + @Nullable private View mTitle; private View mHeaderText; private View mSecondaryHeaderText; private OnClickListener mFeedbackListener; private HeaderTouchListener mTouchListener = new HeaderTouchListener(); - private View mProfileBadge; private View mFeedbackIcon; private int mHeaderTextMarginEnd; - private List<View> mIconsAtEnd; private int mMaxAscent; private int mMaxDescent; @@ -71,7 +66,6 @@ public class NotificationTopLineView extends ViewGroup { super(context, attrs, defStyleAttr, defStyleRes); Resources res = getResources(); mChildMinWidth = res.getDimensionPixelSize(R.dimen.notification_header_shrink_min_width); - mContentEndMargin = res.getDimensionPixelSize(R.dimen.notification_content_margin_end); // NOTE: Implementation only supports TOP, BOTTOM, and CENTER_VERTICAL gravities, // with CENTER_VERTICAL being the default. @@ -92,11 +86,10 @@ public class NotificationTopLineView extends ViewGroup { protected void onFinishInflate() { super.onFinishInflate(); mAppName = findViewById(R.id.app_name_text); + mTitle = findViewById(R.id.title); mHeaderText = findViewById(R.id.header_text); mSecondaryHeaderText = findViewById(R.id.header_text_secondary); - mProfileBadge = findViewById(R.id.profile_badge); mFeedbackIcon = findViewById(R.id.feedback); - mIconsAtEnd = Arrays.asList(mProfileBadge, mFeedbackIcon); } @Override @@ -109,7 +102,6 @@ public class NotificationTopLineView extends ViewGroup { int wrapContentHeightSpec = MeasureSpec.makeMeasureSpec(givenHeight, MeasureSpec.AT_MOST); int totalWidth = getPaddingStart(); - int iconWidth = getPaddingEnd(); int maxChildHeight = -1; mMaxAscent = -1; mMaxDescent = -1; @@ -125,12 +117,7 @@ public class NotificationTopLineView extends ViewGroup { int childHeightSpec = getChildMeasureSpec(wrapContentHeightSpec, lp.topMargin + lp.bottomMargin, lp.height); child.measure(childWidthSpec, childHeightSpec); - // Icons that should go at the end - if (mIconsAtEnd.contains(child)) { - iconWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth(); - } else { - totalWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth(); - } + totalWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth(); int childBaseline = child.getBaseline(); int childHeight = child.getMeasuredHeight(); if (childBaseline != -1) { @@ -141,12 +128,20 @@ public class NotificationTopLineView extends ViewGroup { } // Ensure that there is at least enough space for the icons - int endMargin = Math.max(mHeaderTextMarginEnd, iconWidth); + int endMargin = Math.max(mHeaderTextMarginEnd, getPaddingEnd()); if (totalWidth > givenWidth - endMargin) { int overFlow = totalWidth - givenWidth + endMargin; - // We are overflowing, lets shrink the app name first - overFlow = shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mAppName, - mChildMinWidth); + if (mAppName != null) { + // We are overflowing, lets shrink the app name first + overFlow = shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mAppName, + mChildMinWidth); + } + + if (mTitle != null) { + // still overflowing, we shrink the title text + overFlow = shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mTitle, + mChildMinWidth); + } // still overflowing, we shrink the header text overFlow = shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mHeaderText, 0); @@ -174,7 +169,6 @@ public class NotificationTopLineView extends ViewGroup { @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { int left = getPaddingStart(); - int end = getMeasuredWidth(); int childCount = getChildCount(); int ownHeight = b - t; int childSpace = ownHeight - mPaddingTop - mPaddingBottom; @@ -228,22 +222,12 @@ public class NotificationTopLineView extends ViewGroup { childTop = mPaddingTop; } - // Icons that should go at the end - if (mIconsAtEnd.contains(child)) { - if (end == getMeasuredWidth()) { - layoutRight = end - mContentEndMargin; - } else { - layoutRight = end - params.getMarginEnd(); - } - layoutLeft = layoutRight - child.getMeasuredWidth(); - end = layoutLeft - params.getMarginStart(); - } else { - left += params.getMarginStart(); - int right = left + child.getMeasuredWidth(); - layoutLeft = left; - layoutRight = right; - left = right + params.getMarginEnd(); - } + left += params.getMarginStart(); + int right = left + child.getMeasuredWidth(); + layoutLeft = left; + layoutRight = right; + left = right + params.getMarginEnd(); + if (getLayoutDirection() == LAYOUT_DIRECTION_RTL) { int ltrLeft = layoutLeft; layoutLeft = getWidth() - layoutRight; @@ -298,6 +282,13 @@ public class NotificationTopLineView extends ViewGroup { return mHeaderTextMarginEnd; } + /** + * Set padding at the start of the view. + */ + public void setPaddingStart(int paddingStart) { + setPaddingRelative(paddingStart, getPaddingTop(), getPaddingEnd(), getPaddingBottom()); + } + private class HeaderTouchListener implements OnTouchListener { private Rect mFeedbackRect; |
