diff options
author | 2020-11-20 11:21:25 -0500 | |
---|---|---|
committer | 2020-11-20 14:39:44 -0500 | |
commit | fbc843081f86cf6194b49d1d6f3b4e68b51dc320 (patch) | |
tree | 88845eae9045b4d02c20ee1adc44a5109dbb0e14 | |
parent | fa5c76c245ad37dbaf12ec7f1ef3880ed5ae75c4 (diff) |
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
-rw-r--r-- | core/java/android/view/NotificationTopLineView.java | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/core/java/android/view/NotificationTopLineView.java b/core/java/android/view/NotificationTopLineView.java index a8eabe5a7967..05636de8e8e4 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); + + // 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, we shrink the header text - overFlow = shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mHeaderText, 0); + // Next, shrink the secondary header text (this rarely has conversationTitle) + overFlow = shrinkViewForOverflow(heightSpec, overFlow, mSecondaryHeaderText, 0); - // still overflowing, finally we shrink the secondary header text - shrinkViewForOverflow(wrapContentHeightSpec, 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; } |