Merge "Fix position of expand/collapse button"

This commit is contained in:
Beth Thibodeau
2019-03-07 15:06:11 +00:00
committed by Android (Google) Code Review
3 changed files with 50 additions and 22 deletions

View File

@@ -67,6 +67,7 @@ public class NotificationHeaderView extends ViewGroup {
private boolean mExpanded;
private boolean mShowExpandButtonAtEnd;
private boolean mShowWorkBadgeAtEnd;
private int mHeaderTextMarginEnd;
private Drawable mBackground;
private boolean mEntireHeaderClickable;
private boolean mExpandOnlyOnButton;
@@ -133,7 +134,8 @@ public class NotificationHeaderView extends ViewGroup {
MeasureSpec.AT_MOST);
int wrapContentHeightSpec = MeasureSpec.makeMeasureSpec(givenHeight,
MeasureSpec.AT_MOST);
int totalWidth = getPaddingStart() + getPaddingEnd();
int totalWidth = getPaddingStart();
int iconWidth = getPaddingEnd();
for (int i = 0; i < getChildCount(); i++) {
final View child = getChildAt(i);
if (child.getVisibility() == GONE) {
@@ -146,10 +148,19 @@ public class NotificationHeaderView extends ViewGroup {
int childHeightSpec = getChildMeasureSpec(wrapContentHeightSpec,
lp.topMargin + lp.bottomMargin, lp.height);
child.measure(childWidthSpec, childHeightSpec);
totalWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth();
if ((child == mExpandButton && mShowExpandButtonAtEnd)
|| child == mProfileBadge
|| child == mAppOps) {
iconWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth();
} else {
totalWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth();
}
}
if (totalWidth > givenWidth) {
int overFlow = totalWidth - givenWidth;
// 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, lets shrink the app name first
overFlow = shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mAppName,
mChildMinWidth);
@@ -161,6 +172,7 @@ public class NotificationHeaderView extends ViewGroup {
shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mSecondaryHeaderText,
0);
}
totalWidth += getPaddingEnd();
mTotalWidth = Math.min(totalWidth, givenWidth);
setMeasuredDimension(givenWidth, givenHeight);
}
@@ -383,6 +395,26 @@ public class NotificationHeaderView extends ViewGroup {
return mIcon;
}
/**
* Sets the margin end for the text portion of the header, excluding right-aligned elements
* @param headerTextMarginEnd margin size
*/
@RemotableViewMethod
public void setHeaderTextMarginEnd(int headerTextMarginEnd) {
if (mHeaderTextMarginEnd != headerTextMarginEnd) {
mHeaderTextMarginEnd = headerTextMarginEnd;
requestLayout();
}
}
/**
* Get the current margin end value for the header text
* @return margin size
*/
public int getHeaderTextMarginEnd() {
return mHeaderTextMarginEnd;
}
public class HeaderTouchListener implements View.OnTouchListener {
private final ArrayList<Rect> mTouchRects = new ArrayList<>();

View File

@@ -19,6 +19,7 @@ package com.android.internal.widget;
import android.annotation.Nullable;
import android.content.Context;
import android.util.AttributeSet;
import android.view.NotificationHeaderView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
@@ -37,7 +38,7 @@ public class MediaNotificationView extends FrameLayout {
private final int mNotificationContentImageMarginEnd;
private ImageView mRightIcon;
private View mActions;
private View mHeader;
private NotificationHeaderView mHeader;
private View mMainColumn;
private View mMediaContent;
private int mImagePushIn;
@@ -94,7 +95,14 @@ public class MediaNotificationView extends FrameLayout {
mMainColumn.setLayoutParams(params);
reMeasure = true;
}
int headerMarginEnd = size + imageEndMargin;
// margin for the entire header line
int headerMarginEnd = imageEndMargin;
// margin for the header text (not including the expand button and other icons)
int headerTextMarginEnd = size + imageEndMargin;
if (headerTextMarginEnd != mHeader.getHeaderTextMarginEnd()) {
mHeader.setHeaderTextMarginEnd(headerTextMarginEnd);
reMeasure = true;
}
params = (MarginLayoutParams) mHeader.getLayoutParams();
if (params.getMarginEnd() != headerMarginEnd) {
params.setMarginEnd(headerMarginEnd);

View File

@@ -328,22 +328,10 @@ public class NotificationContentView extends FrameLayout {
if (mExpandedChild != null
&& mExpandedWrapper.getNotificationHeader() != null) {
NotificationHeaderView expandedHeader = mExpandedWrapper.getNotificationHeader();
int expandedSize = expandedHeader.getMeasuredWidth()
- expandedHeader.getPaddingEnd();
int collapsedSize = contractedHeader.getMeasuredWidth()
- expandedHeader.getPaddingEnd();
if (expandedSize != collapsedSize) {
int paddingEnd = contractedHeader.getMeasuredWidth() - expandedSize;
contractedHeader.setPadding(
contractedHeader.isLayoutRtl()
? paddingEnd
: contractedHeader.getPaddingLeft(),
contractedHeader.getPaddingTop(),
contractedHeader.isLayoutRtl()
? contractedHeader.getPaddingLeft()
: paddingEnd,
contractedHeader.getPaddingBottom());
contractedHeader.setShowWorkBadgeAtEnd(true);
int headerTextMargin = expandedHeader.getHeaderTextMarginEnd();
if (headerTextMargin != contractedHeader.getHeaderTextMarginEnd()) {
contractedHeader.setHeaderTextMarginEnd(headerTextMargin);
return true;
}
} else {