diff options
| author | Selim Cinek <cinek@google.com> | 2017-12-12 17:32:44 -0800 |
|---|---|---|
| committer | Selim Cinek <cinek@google.com> | 2018-01-10 20:14:03 +0000 |
| commit | afeed29bdc80bd4c7542e1177e418a3bfb6682d8 (patch) | |
| tree | f53f53a6b283339d3d5916518d44e21c3f624688 /core/java/android | |
| parent | cb8b985e5b14013ef903c8cd77c272e305b68633 (diff) | |
Changing messaging style and overall visual adoption
The messaging style is changed to a bubble-less design.
In addition are we also updating a few spacings in
order for it to look nicer / more balanced.
Test: manual
Change-Id: I43326bd8a23cd1f1d5964d2d6740fde99d29c7e4
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/Notification.java | 55 | ||||
| -rw-r--r-- | core/java/android/view/NotificationHeaderView.java | 46 |
2 files changed, 69 insertions, 32 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 76aa5f46ead6..6004a83b9dcf 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -3981,7 +3981,10 @@ public class Notification implements Parcelable contentView.setViewVisibility(R.id.chronometer, View.GONE); contentView.setViewVisibility(R.id.header_text, View.GONE); contentView.setTextViewText(R.id.header_text, null); + contentView.setViewVisibility(R.id.header_text_secondary, View.GONE); + contentView.setTextViewText(R.id.header_text_secondary, null); contentView.setViewVisibility(R.id.header_text_divider, View.GONE); + contentView.setViewVisibility(R.id.header_text_secondary_divider, View.GONE); contentView.setViewVisibility(R.id.time_divider, View.GONE); contentView.setViewVisibility(R.id.time, View.GONE); contentView.setImageViewIcon(R.id.profile_badge, null); @@ -4012,7 +4015,7 @@ public class Notification implements Parcelable final Bundle ex = mN.extras; updateBackgroundColor(contentView); - bindNotificationHeader(contentView, p.ambient); + bindNotificationHeader(contentView, p.ambient, p.headerTextSecondary); bindLargeIcon(contentView, p.hideLargeIcon, p.alwaysShowReply); boolean showProgress = handleProgressBar(p.hasProgress, contentView, ex); if (p.title != null) { @@ -4295,12 +4298,14 @@ public class Notification implements Parcelable return null; } - private void bindNotificationHeader(RemoteViews contentView, boolean ambient) { + private void bindNotificationHeader(RemoteViews contentView, boolean ambient, + CharSequence secondaryHeaderText) { bindSmallIcon(contentView, ambient); bindHeaderAppName(contentView, ambient); if (!ambient) { // Ambient view does not have these bindHeaderText(contentView); + bindHeaderTextSecondary(contentView, secondaryHeaderText); bindHeaderChronometerAndTime(contentView); bindProfileBadge(contentView); } @@ -4369,6 +4374,17 @@ public class Notification implements Parcelable } } + private void bindHeaderTextSecondary(RemoteViews contentView, CharSequence secondaryText) { + if (!TextUtils.isEmpty(secondaryText)) { + contentView.setTextViewText(R.id.header_text_secondary, processTextSpans( + processLegacyText(secondaryText))); + setTextViewColorSecondary(contentView, R.id.header_text_secondary); + contentView.setViewVisibility(R.id.header_text_secondary, View.VISIBLE); + contentView.setViewVisibility(R.id.header_text_secondary_divider, View.VISIBLE); + setTextViewColorSecondary(contentView, R.id.header_text_secondary_divider); + } + } + /** * @hide */ @@ -4602,7 +4618,7 @@ public class Notification implements Parcelable ambient ? R.layout.notification_template_ambient_header : R.layout.notification_template_header); resetNotificationHeader(header); - bindNotificationHeader(header, ambient); + bindNotificationHeader(header, ambient, null); if (colorized != null) { mN.extras.putBoolean(EXTRA_COLORIZED, colorized); } else { @@ -6269,7 +6285,7 @@ public class Notification implements Parcelable public RemoteViews makeContentView(boolean increasedHeight) { mBuilder.mOriginalActions = mBuilder.mActions; mBuilder.mActions = new ArrayList<>(); - RemoteViews remoteViews = makeBigContentView(); + RemoteViews remoteViews = makeBigContentView(true /* showRightIcon */); mBuilder.mActions = mBuilder.mOriginalActions; mBuilder.mOriginalActions = null; return remoteViews; @@ -6304,23 +6320,31 @@ public class Notification implements Parcelable */ @Override public RemoteViews makeBigContentView() { + return makeBigContentView(false /* showRightIcon */); + } + + @NonNull + private RemoteViews makeBigContentView(boolean showRightIcon) { CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle) ? super.mBigContentTitle : mConversationTitle; boolean isOneToOne = TextUtils.isEmpty(conversationTitle); - if (isOneToOne) { - // Let's add the conversationTitle in case we didn't have one before and all - // messages are from the same sender - conversationTitle = createConversationTitleFromMessages(); - } else if (hasOnlyWhiteSpaceSenders()) { + if (hasOnlyWhiteSpaceSenders()) { isOneToOne = true; } - boolean hasTitle = !TextUtils.isEmpty(conversationTitle); RemoteViews contentView = mBuilder.applyStandardTemplateWithActions( mBuilder.getMessagingLayoutResource(), mBuilder.mParams.reset().hasProgress(false).title(conversationTitle).text(null) - .hideLargeIcon(isOneToOne).alwaysShowReply(true)); + .hideLargeIcon(!showRightIcon || isOneToOne) + .headerTextSecondary(conversationTitle) + .alwaysShowReply(showRightIcon)); addExtras(mBuilder.mN.extras); + // also update the end margin if there is an image + int endMargin = R.dimen.notification_content_margin_end; + if (mBuilder.mN.hasLargeIcon() && showRightIcon) { + endMargin = R.dimen.notification_content_plus_picture_margin_end; + } + contentView.setViewLayoutMarginEndDimen(R.id.notification_main_column, endMargin); contentView.setInt(R.id.status_bar_latest_event_content, "setLayoutColor", mBuilder.resolveContrastColor()); contentView.setIcon(R.id.status_bar_latest_event_content, "setLargeIcon", @@ -6387,7 +6411,7 @@ public class Notification implements Parcelable */ @Override public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { - RemoteViews remoteViews = makeBigContentView(); + RemoteViews remoteViews = makeBigContentView(true /* showRightIcon */); remoteViews.setInt(R.id.notification_messaging, "setMaxDisplayedLines", 1); return remoteViews; } @@ -8854,6 +8878,7 @@ public class Notification implements Parcelable boolean ambient = false; CharSequence title; CharSequence text; + CharSequence headerTextSecondary; boolean hideLargeIcon; public boolean alwaysShowReply; @@ -8862,6 +8887,7 @@ public class Notification implements Parcelable ambient = false; title = null; text = null; + headerTextSecondary = null; return this; } @@ -8880,6 +8906,11 @@ public class Notification implements Parcelable return this; } + final StandardTemplateParams headerTextSecondary(CharSequence text) { + this.headerTextSecondary = text; + return this; + } + final StandardTemplateParams alwaysShowReply(boolean alwaysShowReply) { this.alwaysShowReply = alwaysShowReply; return this; diff --git a/core/java/android/view/NotificationHeaderView.java b/core/java/android/view/NotificationHeaderView.java index ab0b3eec8753..fbba8abff304 100644 --- a/core/java/android/view/NotificationHeaderView.java +++ b/core/java/android/view/NotificationHeaderView.java @@ -47,6 +47,7 @@ public class NotificationHeaderView extends ViewGroup { private final int mGravity; private View mAppName; private View mHeaderText; + private View mSecondaryHeaderText; private OnClickListener mExpandClickListener; private HeaderTouchListener mTouchListener = new HeaderTouchListener(); private ImageView mExpandButton; @@ -58,7 +59,6 @@ public class NotificationHeaderView extends ViewGroup { private boolean mShowExpandButtonAtEnd; private boolean mShowWorkBadgeAtEnd; private Drawable mBackground; - private int mHeaderBackgroundHeight; private boolean mEntireHeaderClickable; private boolean mExpandOnlyOnButton; private boolean mAcceptAllTouches; @@ -68,7 +68,7 @@ public class NotificationHeaderView extends ViewGroup { @Override public void getOutline(View view, Outline outline) { if (mBackground != null) { - outline.setRect(0, 0, getWidth(), mHeaderBackgroundHeight); + outline.setRect(0, 0, getWidth(), getHeight()); outline.setAlpha(1f); } } @@ -91,8 +91,6 @@ public class NotificationHeaderView extends ViewGroup { Resources res = getResources(); mChildMinWidth = res.getDimensionPixelSize(R.dimen.notification_header_shrink_min_width); mContentEndMargin = res.getDimensionPixelSize(R.dimen.notification_content_margin_end); - mHeaderBackgroundHeight = res.getDimensionPixelSize( - R.dimen.notification_header_background_height); mEntireHeaderClickable = res.getBoolean(R.bool.config_notificationHeaderClickableForExpand); int[] attrIds = { android.R.attr.gravity }; @@ -106,6 +104,7 @@ public class NotificationHeaderView extends ViewGroup { super.onFinishInflate(); mAppName = findViewById(com.android.internal.R.id.app_name_text); mHeaderText = findViewById(com.android.internal.R.id.header_text); + mSecondaryHeaderText = findViewById(com.android.internal.R.id.header_text_secondary); mExpandButton = findViewById(com.android.internal.R.id.expand_button); mIcon = findViewById(com.android.internal.R.id.icon); mProfileBadge = findViewById(com.android.internal.R.id.profile_badge); @@ -137,26 +136,33 @@ public class NotificationHeaderView extends ViewGroup { if (totalWidth > givenWidth) { int overFlow = totalWidth - givenWidth; // We are overflowing, lets shrink the app name first - final int appWidth = mAppName.getMeasuredWidth(); - if (overFlow > 0 && mAppName.getVisibility() != GONE && appWidth > mChildMinWidth) { - int newSize = appWidth - Math.min(appWidth - mChildMinWidth, overFlow); - int childWidthSpec = MeasureSpec.makeMeasureSpec(newSize, MeasureSpec.AT_MOST); - mAppName.measure(childWidthSpec, wrapContentHeightSpec); - overFlow -= appWidth - newSize; - } - // still overflowing, finaly we shrink the header text - if (overFlow > 0 && mHeaderText.getVisibility() != GONE) { - // we're still too big - final int textWidth = mHeaderText.getMeasuredWidth(); - int newSize = Math.max(0, textWidth - overFlow); - int childWidthSpec = MeasureSpec.makeMeasureSpec(newSize, MeasureSpec.AT_MOST); - mHeaderText.measure(childWidthSpec, wrapContentHeightSpec); - } + overFlow = shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mAppName, + mChildMinWidth); + + // still overflowing, we shrink the header text + overFlow = shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mHeaderText, 0); + + // still overflowing, finally we shrink the secondary header text + shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mSecondaryHeaderText, + 0); } mTotalWidth = Math.min(totalWidth, givenWidth); 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(); @@ -228,7 +234,7 @@ public class NotificationHeaderView extends ViewGroup { @Override protected void onDraw(Canvas canvas) { if (mBackground != null) { - mBackground.setBounds(0, 0, getWidth(), mHeaderBackgroundHeight); + mBackground.setBounds(0, 0, getWidth(), getHeight()); mBackground.draw(canvas); } } |
