Merge changes Ie8bf816b,I8045cb47

* changes:
  Allow tapping notification icon to expand/contract.
  Prioritize ContentTitle over the SubText
This commit is contained in:
TreeHugger Robot
2020-11-21 01:00:51 +00:00
committed by Android (Google) Code Review
7 changed files with 61 additions and 31 deletions

View File

@@ -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<Rect> 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);

View File

@@ -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;
}

View File

@@ -54,6 +54,14 @@
</NotificationTopLineView>
<FrameLayout
android:id="@+id/alternate_expand_target"
android:layout_width="@dimen/notification_content_margin_start"
android:layout_height="match_parent"
android:layout_gravity="start"
android:importantForAccessibility="no"
/>
<com.android.internal.widget.NotificationExpandButton
android:id="@+id/expand_button"
android:layout_width="@dimen/notification_header_expand_icon_size"

View File

@@ -143,6 +143,14 @@
android:scaleType="centerCrop"
/>
<FrameLayout
android:id="@+id/alternate_expand_target"
android:layout_width="@dimen/notification_content_margin_start"
android:layout_height="match_parent"
android:layout_gravity="start"
android:importantForAccessibility="no"
/>
<FrameLayout
android:id="@+id/expand_button_touch_container"
android:layout_width="wrap_content"

View File

@@ -259,6 +259,9 @@
<!-- The height of the background for a notification header on a group -->
<dimen name="notification_header_background_height">49.5dp</dimen>
<!-- The height of the full-width touch rectangle for the notification header -->
<dimen name="notification_header_touchable_height">36dp</dimen>
<!-- The top padding for the notification header -->
<dimen name="notification_header_padding_top">16dp</dimen>

View File

@@ -2861,6 +2861,7 @@
<java-symbol type="id" name="header_text" />
<java-symbol type="id" name="header_text_secondary" />
<java-symbol type="id" name="expand_button" />
<java-symbol type="id" name="alternate_expand_target" />
<java-symbol type="id" name="notification_header" />
<java-symbol type="id" name="notification_top_line" />
<java-symbol type="id" name="time_divider" />
@@ -2878,6 +2879,7 @@
<java-symbol type="dimen" name="notification_content_margin_top" />
<java-symbol type="dimen" name="notification_content_margin" />
<java-symbol type="dimen" name="notification_header_background_height" />
<java-symbol type="dimen" name="notification_header_touchable_height" />
<java-symbol type="dimen" name="notification_header_expand_icon_size" />
<java-symbol type="dimen" name="notification_expand_button_padding_top" />
<java-symbol type="dimen" name="notification_header_icon_size" />

View File

@@ -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);
}