From fbc843081f86cf6194b49d1d6f3b4e68b51dc320 Mon Sep 17 00:00:00 2001 From: Jeff DeCew Date: Fri, 20 Nov 2020 11:21:25 -0500 Subject: [PATCH 1/2] Prioritize ContentTitle over the SubText Previously, we shrunk the title to a minimum width, then showed the subtext with the remaining space. This felt like a poor balance, where we'd rather get as much of the title as possible. Bug: 163626038 Test: manual - using Notify's drag resizing was really helpful Change-Id: I8045cb473cbb42f04e3054fb40bda2ac427e693e --- .../android/view/NotificationTopLineView.java | 52 +++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/core/java/android/view/NotificationTopLineView.java b/core/java/android/view/NotificationTopLineView.java index a8eabe5a7967b..05636de8e8e4b 100644 --- a/core/java/android/view/NotificationTopLineView.java +++ b/core/java/android/view/NotificationTopLineView.java @@ -97,10 +97,8 @@ public class NotificationTopLineView extends ViewGroup { final int givenWidth = MeasureSpec.getSize(widthMeasureSpec); final int givenHeight = MeasureSpec.getSize(heightMeasureSpec); final boolean wrapHeight = MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST; - int wrapContentWidthSpec = MeasureSpec.makeMeasureSpec(givenWidth, - MeasureSpec.AT_MOST); - int wrapContentHeightSpec = MeasureSpec.makeMeasureSpec(givenHeight, - MeasureSpec.AT_MOST); + int wrapContentWidthSpec = MeasureSpec.makeMeasureSpec(givenWidth, MeasureSpec.AT_MOST); + int heightSpec = MeasureSpec.makeMeasureSpec(givenHeight, MeasureSpec.AT_MOST); int totalWidth = getPaddingStart(); int maxChildHeight = -1; mMaxAscent = -1; @@ -114,7 +112,7 @@ public class NotificationTopLineView extends ViewGroup { final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); int childWidthSpec = getChildMeasureSpec(wrapContentWidthSpec, lp.leftMargin + lp.rightMargin, lp.width); - int childHeightSpec = getChildMeasureSpec(wrapContentHeightSpec, + int childHeightSpec = getChildMeasureSpec(heightSpec, lp.topMargin + lp.bottomMargin, lp.height); child.measure(childWidthSpec, childHeightSpec); totalWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth(); @@ -131,37 +129,37 @@ public class NotificationTopLineView extends ViewGroup { int endMargin = Math.max(mHeaderTextMarginEnd, getPaddingEnd()); if (totalWidth > givenWidth - endMargin) { int overFlow = totalWidth - givenWidth + endMargin; - 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); - } + // First shrink the app name, down to a minimum size + overFlow = shrinkViewForOverflow(heightSpec, overFlow, mAppName, mChildMinWidth); - // still overflowing, we shrink the header text - overFlow = shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mHeaderText, 0); + // Next, shrink the header text (this usually has subText) + // This shrinks the subtext first, but not all the way (yet!) + overFlow = shrinkViewForOverflow(heightSpec, overFlow, mHeaderText, mChildMinWidth); - // still overflowing, finally we shrink the secondary header text - shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mSecondaryHeaderText, - 0); + // Next, shrink the secondary header text (this rarely has conversationTitle) + overFlow = shrinkViewForOverflow(heightSpec, overFlow, mSecondaryHeaderText, 0); + + // Next, shrink the title text (this has contentTitle; only in headerless views) + overFlow = shrinkViewForOverflow(heightSpec, overFlow, mTitle, mChildMinWidth); + + // Finally, if there is still overflow, shrink the header down to 0 if still necessary. + shrinkViewForOverflow(heightSpec, overFlow, mHeaderText, 0); } setMeasuredDimension(givenWidth, wrapHeight ? maxChildHeight : 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; + if (targetView != null) { + 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; } From ee451e5882b9b8bbbd4110c2ad02216f4f9ae230 Mon Sep 17 00:00:00 2001 From: Jeff DeCew Date: Fri, 20 Nov 2020 14:30:39 -0500 Subject: [PATCH 2/2] Allow tapping notification icon to expand/contract. Bug: 163626038 Test: manual Change-Id: Ie8bf816b0acfc3f078dd1d0583d325de4b625764 --- core/java/android/view/NotificationHeaderView.java | 14 ++++++++++---- .../res/layout/notification_template_header.xml | 8 ++++++++ .../layout/notification_template_material_base.xml | 8 ++++++++ core/res/res/values/dimens.xml | 3 +++ core/res/res/values/symbols.xml | 2 ++ .../row/wrapper/NotificationHeaderViewWrapper.java | 5 +++++ 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/core/java/android/view/NotificationHeaderView.java b/core/java/android/view/NotificationHeaderView.java index f7fbb1ce0ab98..673ed0d8b95db 100644 --- a/core/java/android/view/NotificationHeaderView.java +++ b/core/java/android/view/NotificationHeaderView.java @@ -43,12 +43,13 @@ import java.util.ArrayList; */ @RemoteViews.RemoteView public class NotificationHeaderView extends FrameLayout { - private final int mContentEndMargin; private final int mHeadingEndMargin; + private final int mTouchableHeight; private OnClickListener mExpandClickListener; private HeaderTouchListener mTouchListener = new HeaderTouchListener(); private NotificationTopLineView mTopLineView; private NotificationExpandButton mExpandButton; + private View mAltExpandTarget; private CachingIconView mIcon; private Drawable mBackground; private boolean mEntireHeaderClickable; @@ -82,8 +83,8 @@ public class NotificationHeaderView extends FrameLayout { int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); Resources res = getResources(); - mContentEndMargin = res.getDimensionPixelSize(R.dimen.notification_content_margin_end); mHeadingEndMargin = res.getDimensionPixelSize(R.dimen.notification_heading_margin_end); + mTouchableHeight = res.getDimensionPixelSize(R.dimen.notification_header_touchable_height); mEntireHeaderClickable = res.getBoolean(R.bool.config_notificationHeaderClickableForExpand); } @@ -93,6 +94,7 @@ public class NotificationHeaderView extends FrameLayout { mIcon = findViewById(R.id.icon); mTopLineView = findViewById(R.id.notification_top_line); mExpandButton = findViewById(R.id.expand_button); + mAltExpandTarget = findViewById(R.id.alternate_expand_target); setClipToPadding(false); } @@ -146,6 +148,7 @@ public class NotificationHeaderView extends FrameLayout { public void setOnClickListener(@Nullable OnClickListener l) { mExpandClickListener = l; mExpandButton.setOnClickListener(mExpandClickListener); + mAltExpandTarget.setOnClickListener(mExpandClickListener); updateTouchListener(); } @@ -187,6 +190,7 @@ public class NotificationHeaderView extends FrameLayout { private final ArrayList mTouchRects = new ArrayList<>(); private Rect mExpandButtonRect; + private Rect mAltExpandTargetRect; private int mTouchSlop; private boolean mTrackGesture; private float mDownX; @@ -199,6 +203,7 @@ public class NotificationHeaderView extends FrameLayout { mTouchRects.clear(); addRectAroundView(mIcon); mExpandButtonRect = addRectAroundView(mExpandButton); + mAltExpandTargetRect = addRectAroundView(mAltExpandTarget); addWidthRect(); mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); } @@ -206,7 +211,7 @@ public class NotificationHeaderView extends FrameLayout { private void addWidthRect() { Rect r = new Rect(); r.top = 0; - r.bottom = (int) (32 * getResources().getDisplayMetrics().density); + r.bottom = mTouchableHeight; r.left = 0; r.right = getWidth(); mTouchRects.add(r); @@ -277,7 +282,8 @@ public class NotificationHeaderView extends FrameLayout { return true; } if (mExpandOnlyOnButton) { - return mExpandButtonRect.contains((int) x, (int) y); + return mExpandButtonRect.contains((int) x, (int) y) + || mAltExpandTargetRect.contains((int) x, (int) y); } for (int i = 0; i < mTouchRects.size(); i++) { Rect r = mTouchRects.get(i); diff --git a/core/res/res/layout/notification_template_header.xml b/core/res/res/layout/notification_template_header.xml index 4b67509db457e..b0ee12a520d9d 100644 --- a/core/res/res/layout/notification_template_header.xml +++ b/core/res/res/layout/notification_template_header.xml @@ -54,6 +54,14 @@ + + + + 49.5dp + + 36dp + 16dp diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 6e19290d97603..40aae9e4e0857 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -2861,6 +2861,7 @@ + @@ -2878,6 +2879,7 @@ + diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationHeaderViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationHeaderViewWrapper.java index d228ce159d489..05db67d706cf5 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationHeaderViewWrapper.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationHeaderViewWrapper.java @@ -56,6 +56,7 @@ public class NotificationHeaderViewWrapper extends NotificationViewWrapper { private CachingIconView mIcon; private NotificationExpandButton mExpandButton; + private View mAltExpandTarget; protected NotificationHeaderView mNotificationHeader; protected NotificationTopLineView mNotificationTopLine; private TextView mHeaderText; @@ -106,6 +107,7 @@ public class NotificationHeaderViewWrapper extends NotificationViewWrapper { mHeaderText = mView.findViewById(com.android.internal.R.id.header_text); mAppNameText = mView.findViewById(com.android.internal.R.id.app_name_text); mExpandButton = mView.findViewById(com.android.internal.R.id.expand_button); + mAltExpandTarget = mView.findViewById(com.android.internal.R.id.alternate_expand_target); mRightIcon = mView.findViewById(com.android.internal.R.id.right_icon); mWorkProfileImage = mView.findViewById(com.android.internal.R.id.profile_badge); mNotificationHeader = mView.findViewById(com.android.internal.R.id.notification_header); @@ -260,6 +262,9 @@ public class NotificationHeaderViewWrapper extends NotificationViewWrapper { public void updateExpandability(boolean expandable, View.OnClickListener onClickListener) { mExpandButton.setVisibility(expandable ? View.VISIBLE : View.GONE); mExpandButton.setOnClickListener(expandable ? onClickListener : null); + if (mAltExpandTarget != null) { + mAltExpandTarget.setOnClickListener(expandable ? onClickListener : null); + } if (mNotificationHeader != null) { mNotificationHeader.setOnClickListener(expandable ? onClickListener : null); }