Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5185c6bf authored by Jeff DeCew's avatar Jeff DeCew Committed by Android (Google) Code Review
Browse files

Merge changes from topic "template_redesign"

* changes:
  Update variable names to reduce confusion.
  Fix/hack MessagingStyle notifications
  Reduce notification minimized height
  Fix the placement of the work profile and feedback badges.
  Fix HUNs
  Remove the unneeded icon spacing in the InboxStyle.
  Hide app name from minimized notifications
  Notification Title is 16pt in Big state
  Ensure headerless notification with large icon is big enough.
  Round corners of BigPicture
  Increase the expand button touchable area.
  Remove the reply action entirely.
  Notification template redesign; part 1.
  Remove night-mode override of notification_divider_height
parents 9a8f3712 89cc6a1f
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -91659,8 +91659,6 @@ Lcom/android/internal/R$dimen;->notification_expand_button_padding_top:I
Lcom/android/internal/R$dimen;->notification_header_app_name_margin_start:I
Lcom/android/internal/R$dimen;->notification_header_background_height:I
Lcom/android/internal/R$dimen;->notification_header_expand_icon_size:I
Lcom/android/internal/R$dimen;->notification_header_height:I
Lcom/android/internal/R$dimen;->notification_header_icon_margin_end:I
Lcom/android/internal/R$dimen;->notification_header_icon_size:I
Lcom/android/internal/R$dimen;->notification_header_separating_margin:I
Lcom/android/internal/R$dimen;->notification_header_shrink_min_width:I
@@ -92444,7 +92442,6 @@ Lcom/android/internal/R$id;->remote_input_send:I
Lcom/android/internal/R$id;->replaceText:I
Lcom/android/internal/R$id;->replace_app_icon:I
Lcom/android/internal/R$id;->replace_message:I
Lcom/android/internal/R$id;->reply_icon_action:I
Lcom/android/internal/R$id;->resolver_list:I
Lcom/android/internal/R$id;->rew:I
Lcom/android/internal/R$id;->rightSpacer:I
+190 −178

File changed.

Preview size limit exceeded, changes collapsed.

+26 −117
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.RemoteViews;

import com.android.internal.R;
@@ -41,15 +42,14 @@ import java.util.ArrayList;
 * @hide
 */
@RemoteViews.RemoteView
public class NotificationHeaderView extends ViewGroup {
    private final int mChildMinWidth;
public class NotificationHeaderView extends FrameLayout {
    private final int mContentEndMargin;
    private final int mHeadingEndMargin;
    private OnClickListener mExpandClickListener;
    private HeaderTouchListener mTouchListener = new HeaderTouchListener();
    private NotificationTopLineView mTopLineView;
    private NotificationExpandButton mExpandButton;
    private CachingIconView mIcon;
    private int mHeaderTextMarginEnd;
    private Drawable mBackground;
    private boolean mEntireHeaderClickable;
    private boolean mExpandOnlyOnButton;
@@ -82,8 +82,8 @@ public class NotificationHeaderView extends ViewGroup {
            int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        Resources res = getResources();
        mChildMinWidth = res.getDimensionPixelSize(R.dimen.notification_header_shrink_min_width);
        mContentEndMargin = res.getDimensionPixelSize(R.dimen.notification_content_margin_end);
        mHeadingEndMargin = res.getDimensionPixelSize(R.dimen.notification_heading_margin_end);
        mEntireHeaderClickable = res.getBoolean(R.bool.config_notificationHeaderClickableForExpand);
    }

@@ -96,108 +96,6 @@ public class NotificationHeaderView extends ViewGroup {
        setClipToPadding(false);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        final int givenWidth = MeasureSpec.getSize(widthMeasureSpec);
        final int givenHeight = MeasureSpec.getSize(heightMeasureSpec);
        int wrapContentWidthSpec = MeasureSpec.makeMeasureSpec(givenWidth,
                MeasureSpec.AT_MOST);
        int wrapContentHeightSpec = MeasureSpec.makeMeasureSpec(givenHeight,
                MeasureSpec.AT_MOST);
        int totalWidth = getPaddingStart();
        int iconWidth = getPaddingEnd();
        for (int i = 0; i < getChildCount(); i++) {
            final View child = getChildAt(i);
            if (child.getVisibility() == GONE) {
                // We'll give it the rest of the space in the end
                continue;
            }
            final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
            int childWidthSpec = getChildMeasureSpec(wrapContentWidthSpec,
                    lp.leftMargin + lp.rightMargin, lp.width);
            int childHeightSpec = getChildMeasureSpec(wrapContentHeightSpec,
                    lp.topMargin + lp.bottomMargin, lp.height);
            child.measure(childWidthSpec, childHeightSpec);
            // Icons that should go at the end
            if (child == mExpandButton) {
                iconWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth();
            } else {
                totalWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth();
            }
        }

        // 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; shrink the top line
            shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mTopLineView,
                    mChildMinWidth);
        }
        setMeasuredDimension(givenWidth, 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;
        }
        return overFlow;
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        int left = getPaddingStart();
        int end = getMeasuredWidth();
        int childCount = getChildCount();
        int ownHeight = getMeasuredHeight() - getPaddingTop() - getPaddingBottom();
        for (int i = 0; i < childCount; i++) {
            View child = getChildAt(i);
            if (child.getVisibility() == GONE) {
                continue;
            }
            int childHeight = child.getMeasuredHeight();
            MarginLayoutParams params = (MarginLayoutParams) child.getLayoutParams();
            int layoutLeft;
            int layoutRight;
            int top = (int) (getPaddingTop() + (ownHeight - childHeight) / 2.0f);
            int bottom = top + childHeight;
            // Icons that should go at the end
            if (child == mExpandButton) {
                if (end == getMeasuredWidth()) {
                    layoutRight = end - mContentEndMargin;
                } else {
                    layoutRight = end - params.getMarginEnd();
                }
                layoutLeft = layoutRight - child.getMeasuredWidth();
                end = layoutLeft - params.getMarginStart();
            } else {
                left += params.getMarginStart();
                int right = left + child.getMeasuredWidth();
                layoutLeft = left;
                layoutRight = right;
                left = right + params.getMarginEnd();
            }
            if (getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
                int ltrLeft = layoutLeft;
                layoutLeft = getWidth() - layoutRight;
                layoutRight = getWidth() - ltrLeft;
            }
            child.layout(layoutLeft, top, layoutRight, bottom);
        }
        updateTouchListener();
    }

    @Override
    public LayoutParams generateLayoutParams(AttributeSet attrs) {
        return new MarginLayoutParams(getContext(), attrs);
    }

    /**
     * Set a {@link Drawable} to be displayed as a background on the header.
     */
@@ -252,23 +150,34 @@ public class NotificationHeaderView extends ViewGroup {
    }

    /**
     * Sets the margin end for the text portion of the header, excluding right-aligned elements
     * @param headerTextMarginEnd margin size
     * Sets the extra margin at the end of the top line of left-aligned text + icons.
     * This value will have the margin required to accommodate the expand button added to it.
     *
     * @param extraMarginEnd extra margin
     */
    @RemotableViewMethod
    public void setHeaderTextMarginEnd(int headerTextMarginEnd) {
        if (mHeaderTextMarginEnd != headerTextMarginEnd) {
            mHeaderTextMarginEnd = headerTextMarginEnd;
            requestLayout();
    public void setTopLineExtraMarginEnd(int extraMarginEnd) {
        mTopLineView.setHeaderTextMarginEnd(extraMarginEnd + mHeadingEndMargin);
    }

    /**
     * Get the current margin end value for the header text.
     * Add this to {@link #getTopLineBaseMarginEnd()} to get the total margin of the top line.
     *
     * @return extra margin
     */
    public int getTopLineExtraMarginEnd() {
        return mTopLineView.getHeaderTextMarginEnd() - mHeadingEndMargin;
    }

    /**
     * Get the current margin end value for the header text
     * @return margin size
     * Get the base margin at the end of the top line view.
     * Add this to {@link #getTopLineExtraMarginEnd()} to get the total margin of the top line.
     *
     * @return base margin
     */
    public int getHeaderTextMarginEnd() {
        return mHeaderTextMarginEnd;
    public int getTopLineBaseMarginEnd() {
        return mHeadingEndMargin;
    }

    /**
+29 −38
Original line number Diff line number Diff line
@@ -26,9 +26,6 @@ import android.widget.RemoteViews;

import com.android.internal.R;

import java.util.Arrays;
import java.util.List;

/**
 * The top line of content in a notification view.
 * This includes the text views and badges but excludes the icon and the expander.
@@ -39,16 +36,14 @@ import java.util.List;
public class NotificationTopLineView extends ViewGroup {
    private final int mGravityY;
    private final int mChildMinWidth;
    private final int mContentEndMargin;
    private View mAppName;
    @Nullable private View mAppName;
    @Nullable private View mTitle;
    private View mHeaderText;
    private View mSecondaryHeaderText;
    private OnClickListener mFeedbackListener;
    private HeaderTouchListener mTouchListener = new HeaderTouchListener();
    private View mProfileBadge;
    private View mFeedbackIcon;
    private int mHeaderTextMarginEnd;
    private List<View> mIconsAtEnd;

    private int mMaxAscent;
    private int mMaxDescent;
@@ -71,7 +66,6 @@ public class NotificationTopLineView extends ViewGroup {
        super(context, attrs, defStyleAttr, defStyleRes);
        Resources res = getResources();
        mChildMinWidth = res.getDimensionPixelSize(R.dimen.notification_header_shrink_min_width);
        mContentEndMargin = res.getDimensionPixelSize(R.dimen.notification_content_margin_end);

        // NOTE: Implementation only supports TOP, BOTTOM, and CENTER_VERTICAL gravities,
        // with CENTER_VERTICAL being the default.
@@ -92,11 +86,10 @@ public class NotificationTopLineView extends ViewGroup {
    protected void onFinishInflate() {
        super.onFinishInflate();
        mAppName = findViewById(R.id.app_name_text);
        mTitle = findViewById(R.id.title);
        mHeaderText = findViewById(R.id.header_text);
        mSecondaryHeaderText = findViewById(R.id.header_text_secondary);
        mProfileBadge = findViewById(R.id.profile_badge);
        mFeedbackIcon = findViewById(R.id.feedback);
        mIconsAtEnd = Arrays.asList(mProfileBadge, mFeedbackIcon);
    }

    @Override
@@ -109,7 +102,6 @@ public class NotificationTopLineView extends ViewGroup {
        int wrapContentHeightSpec = MeasureSpec.makeMeasureSpec(givenHeight,
                MeasureSpec.AT_MOST);
        int totalWidth = getPaddingStart();
        int iconWidth = getPaddingEnd();
        int maxChildHeight = -1;
        mMaxAscent = -1;
        mMaxDescent = -1;
@@ -125,12 +117,7 @@ public class NotificationTopLineView extends ViewGroup {
            int childHeightSpec = getChildMeasureSpec(wrapContentHeightSpec,
                    lp.topMargin + lp.bottomMargin, lp.height);
            child.measure(childWidthSpec, childHeightSpec);
            // Icons that should go at the end
            if (mIconsAtEnd.contains(child)) {
                iconWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth();
            } else {
            totalWidth += lp.leftMargin + lp.rightMargin + child.getMeasuredWidth();
            }
            int childBaseline = child.getBaseline();
            int childHeight = child.getMeasuredHeight();
            if (childBaseline != -1) {
@@ -141,12 +128,20 @@ public class NotificationTopLineView extends ViewGroup {
        }

        // Ensure that there is at least enough space for the icons
        int endMargin = Math.max(mHeaderTextMarginEnd, iconWidth);
        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);
            }

            // still overflowing, we shrink the header text
            overFlow = shrinkViewForOverflow(wrapContentHeightSpec, overFlow, mHeaderText, 0);
@@ -174,7 +169,6 @@ public class NotificationTopLineView extends ViewGroup {
    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        int left = getPaddingStart();
        int end = getMeasuredWidth();
        int childCount = getChildCount();
        int ownHeight = b - t;
        int childSpace = ownHeight - mPaddingTop - mPaddingBottom;
@@ -228,22 +222,12 @@ public class NotificationTopLineView extends ViewGroup {
                    childTop = mPaddingTop;
            }

            // Icons that should go at the end
            if (mIconsAtEnd.contains(child)) {
                if (end == getMeasuredWidth()) {
                    layoutRight = end - mContentEndMargin;
                } else {
                    layoutRight = end - params.getMarginEnd();
                }
                layoutLeft = layoutRight - child.getMeasuredWidth();
                end = layoutLeft - params.getMarginStart();
            } else {
            left += params.getMarginStart();
            int right = left + child.getMeasuredWidth();
            layoutLeft = left;
            layoutRight = right;
            left = right + params.getMarginEnd();
            }

            if (getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
                int ltrLeft = layoutLeft;
                layoutLeft = getWidth() - layoutRight;
@@ -298,6 +282,13 @@ public class NotificationTopLineView extends ViewGroup {
        return mHeaderTextMarginEnd;
    }

    /**
     * Set padding at the start of the view.
     */
    public void setPaddingStart(int paddingStart) {
        setPaddingRelative(paddingStart, getPaddingTop(), getPaddingEnd(), getPaddingBottom());
    }

    private class HeaderTouchListener implements OnTouchListener {

        private Rect mFeedbackRect;
+2 −13
Original line number Diff line number Diff line
@@ -134,7 +134,6 @@ public class ConversationLayout extends FrameLayout
    private CachingIconView mConversationIconBadgeBg;
    private Icon mLargeIcon;
    private View mExpandButtonContainer;
    private View mExpandButtonInnerContainer;
    private ViewGroup mExpandButtonAndContentContainer;
    private NotificationExpandButton mExpandButton;
    private MessagingLinearLayout mImageMessageContainer;
@@ -266,7 +265,6 @@ public class ConversationLayout extends FrameLayout
        mConversationHeader = findViewById(R.id.conversation_header);
        mContentContainer = findViewById(R.id.notification_action_list_margin_target);
        mExpandButtonAndContentContainer = findViewById(R.id.expand_button_and_content_container);
        mExpandButtonInnerContainer = findViewById(R.id.expand_button_inner_container);
        mExpandButton = findViewById(R.id.expand_button);
        mExpandButtonExpandedTopMargin = getResources().getDimensionPixelSize(
                R.dimen.conversation_expand_button_top_margin_expanded);
@@ -1217,25 +1215,18 @@ public class ConversationLayout extends FrameLayout
    }

    private void updateExpandButton() {
        int drawableId;
        int contentDescriptionId;
        int gravity;
        int topMargin = 0;
        ViewGroup newContainer;
        if (mIsCollapsed) {
            drawableId = R.drawable.ic_expand_notification;
            contentDescriptionId = R.string.expand_button_content_description_collapsed;
            gravity = Gravity.CENTER;
            newContainer = mExpandButtonAndContentContainer;
        } else {
            drawableId = R.drawable.ic_collapse_notification;
            contentDescriptionId = R.string.expand_button_content_description_expanded;
            gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
            topMargin = mExpandButtonExpandedTopMargin;
            newContainer = this;
        }
        mExpandButton.setImageDrawable(getContext().getDrawable(drawableId));
        mExpandButton.setColorFilter(mExpandButton.getOriginalNotificationColor());
        mExpandButton.setExpanded(!mIsCollapsed);

        // We need to make sure that the expand button is in the linearlayout pushing over the
        // content when collapsed, but allows the content to flow under it when expanded.
@@ -1250,8 +1241,6 @@ public class ConversationLayout extends FrameLayout
        layoutParams.gravity = gravity;
        layoutParams.topMargin = topMargin;
        mExpandButton.setLayoutParams(layoutParams);

        mExpandButtonInnerContainer.setContentDescription(mContext.getText(contentDescriptionId));
    }

    private void updateContentEndPaddings() {
@@ -1298,7 +1287,7 @@ public class ConversationLayout extends FrameLayout
        mExpandable = expandable;
        if (expandable) {
            mExpandButtonContainer.setVisibility(VISIBLE);
            mExpandButtonInnerContainer.setOnClickListener(onClickListener);
            mExpandButton.setOnClickListener(onClickListener);
            mConversationIconContainer.setOnClickListener(onClickListener);
        } else {
            mExpandButtonContainer.setVisibility(GONE);
Loading