From 7995e6d7b51337f5fc973be47b4edfcfc602fb20 Mon Sep 17 00:00:00 2001 From: Jeff DeCew Date: Tue, 27 Oct 2020 10:50:14 -0400 Subject: [PATCH] NotificationTopLineView supports layout_height="wrap_content" Test: atest SystemUITests Test: manually tested within my branch which does this Change-Id: I78412489be7723697d8dc3106dbb4d67fd72a3a0 --- core/java/android/view/NotificationTopLineView.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/java/android/view/NotificationTopLineView.java b/core/java/android/view/NotificationTopLineView.java index 69094b166fdb7..24748222b3af7 100644 --- a/core/java/android/view/NotificationTopLineView.java +++ b/core/java/android/view/NotificationTopLineView.java @@ -103,12 +103,14 @@ public class NotificationTopLineView extends ViewGroup { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 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 totalWidth = getPaddingStart(); int iconWidth = getPaddingEnd(); + int maxChildHeight = -1; mMaxAscent = -1; mMaxDescent = -1; for (int i = 0; i < getChildCount(); i++) { @@ -130,10 +132,12 @@ public class NotificationTopLineView extends ViewGroup { totalWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth(); } int childBaseline = child.getBaseline(); + int childHeight = child.getMeasuredHeight(); if (childBaseline != -1) { mMaxAscent = Math.max(mMaxAscent, childBaseline); - mMaxDescent = Math.max(mMaxDescent, child.getMeasuredHeight() - childBaseline); + mMaxDescent = Math.max(mMaxDescent, childHeight - childBaseline); } + maxChildHeight = Math.max(maxChildHeight, childHeight); } // Ensure that there is at least enough space for the icons @@ -151,7 +155,7 @@ public class NotificationTopLineView extends ViewGroup { shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mSecondaryHeaderText, 0); } - setMeasuredDimension(givenWidth, givenHeight); + setMeasuredDimension(givenWidth, wrapHeight ? maxChildHeight : givenHeight); } private int shrinkViewForOverflow(int heightSpec, int overFlow, View targetView,