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

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

Merge changes I11400a55,I49461363,Ia18b2dc3,I8c554755 into sc-dev

* changes:
  Simplify SmartReplyView padding layout logic
  Smart action buttons now have 8dp corner radius
  Fix measure logic so that priority children can have more than 1/N space.
  Update the style of emphasized notification actions.
parents f192dbf7 df7223b8
Loading
Loading
Loading
Loading
+21 −16
Original line number Diff line number Diff line
@@ -5662,11 +5662,6 @@ public class Notification implements Parcelable
                        R.dimen.call_notification_collapsible_indent);
            }
            big.setBoolean(R.id.actions, "setEmphasizedMode", emphazisedMode);
            if (p.mCallStyleActions) {
                // Use "wrap_content" (unlike normal emphasized mode) and allow prioritizing the
                // required actions (Answer, Decline, and Hang Up).
                big.setBoolean(R.id.actions, "setPrioritizedWrapMode", true);
            }
            if (numActions > 0 && !p.mHideActions) {
                big.setViewVisibility(R.id.actions_container, View.VISIBLE);
                big.setViewVisibility(R.id.actions, View.VISIBLE);
@@ -5683,7 +5678,7 @@ public class Notification implements Parcelable
                        // Clear the drawable
                        button.setInt(R.id.action0, "setBackgroundResource", 0);
                    }
                    if (p.mCallStyleActions && i > 0) {
                    if (emphazisedMode && i > 0) {
                        // Clear start margin from non-first buttons to reduce the gap between them.
                        //  (8dp remaining gap is from all buttons' standard 4dp inset).
                        button.setViewLayoutMarginDimen(R.id.action0, RemoteViews.MARGIN_START, 0);
@@ -6103,26 +6098,21 @@ public class Notification implements Parcelable
                // change the background bgColor
                CharSequence title = action.title;
                ColorStateList[] outResultColor = new ColorStateList[1];
                int background = getBackgroundColor(p);
                int background = getSecondaryAccentColor(p);
                if (isLegacy()) {
                    title = ContrastColorUtil.clearColorSpans(title);
                } else {
                    title = ensureColorSpanContrast(title, background, outResultColor);
                }
                button.setTextViewText(R.id.action0, processTextSpans(title));
                final int textColor;
                boolean hasColorOverride = outResultColor[0] != null;
                if (hasColorOverride) {
                    // There's a span spanning the full text, let's take it and use it as the
                    // background color
                    background = outResultColor[0].getDefaultColor();
                    textColor = ContrastColorUtil.resolvePrimaryColor(mContext,
                            background, mInNightMode);
                } else if (mTintActionButtons && !mInNightMode && !isBackgroundColorized(p)) {
                    textColor = getAccentColor(p);
                } else {
                    textColor = getPrimaryTextColor(p);
                }
                final int textColor = ContrastColorUtil.resolvePrimaryColor(mContext,
                        background, mInNightMode);
                button.setTextColor(R.id.action0, textColor);
                // We only want about 20% alpha for the ripple
                final int rippleColor = (textColor & 0x00ffffff) | 0x33000000;
@@ -6130,11 +6120,10 @@ public class Notification implements Parcelable
                        ColorStateList.valueOf(rippleColor));
                button.setColorStateList(R.id.action0, "setButtonBackground",
                        ColorStateList.valueOf(background));
                button.setBoolean(R.id.action0, "setHasStroke", !hasColorOverride);
                if (p.mCallStyleActions) {
                    button.setImageViewIcon(R.id.action0, action.getIcon());
                    boolean priority = action.getExtras().getBoolean(CallStyle.KEY_ACTION_PRIORITY);
                    button.setBoolean(R.id.action0, "setWrapModePriority", priority);
                    button.setBoolean(R.id.action0, "setIsPriority", priority);
                    int minWidthDimen =
                            priority ? R.dimen.call_notification_system_action_min_width : 0;
                    button.setIntDimen(R.id.action0, "setMinimumWidth", minWidthDimen);
@@ -6319,6 +6308,22 @@ public class Notification implements Parcelable
            return getContrastColor(p);
        }

        /**
         * Gets the secondary accent color for colored UI elements.  If we're tinting with the theme
         * accent, this is the theme accent color, otherwise this would be identical to
         * {@link #getSmallIconColor(StandardTemplateParams)}.
         */
        private @ColorInt int getSecondaryAccentColor(StandardTemplateParams p) {
            if (isBackgroundColorized(p)) {
                return getSecondaryTextColor(p);
            }
            int color = obtainThemeColor(R.attr.colorAccentSecondary, COLOR_INVALID);
            if (color != COLOR_INVALID) {
                return color;
            }
            return getContrastColor(p);
        }

        /**
         * Gets the "surface protection" color from the theme, or a variant of the normal background
         * color when colorized, or when not using theme color tints.
+4 −23
Original line number Diff line number Diff line
@@ -27,9 +27,7 @@ import android.graphics.drawable.Icon;
import android.graphics.drawable.RippleDrawable;
import android.util.AttributeSet;
import android.view.RemotableViewMethod;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RemoteViews;

import com.android.internal.R;
@@ -42,8 +40,6 @@ import com.android.internal.R;
@RemoteViews.RemoteView
public class EmphasizedNotificationButton extends Button {
    private final RippleDrawable mRipple;
    private final int mStrokeWidth;
    private final int mStrokeColor;
    private boolean mPriority;

    public EmphasizedNotificationButton(Context context) {
@@ -63,9 +59,6 @@ public class EmphasizedNotificationButton extends Button {
        super(context, attrs, defStyleAttr, defStyleRes);
        DrawableWrapper background = (DrawableWrapper) getBackground().mutate();
        mRipple = (RippleDrawable) background.getDrawable();
        mStrokeWidth = getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.emphasized_button_stroke_width);
        mStrokeColor = getContext().getColor(com.android.internal.R.color.material_grey_300);
        mRipple.mutate();
    }

@@ -82,13 +75,6 @@ public class EmphasizedNotificationButton extends Button {
        invalidate();
    }

    @RemotableViewMethod
    public void setHasStroke(boolean hasStroke) {
        GradientDrawable inner = (GradientDrawable) mRipple.getDrawable(0);
        inner.setStroke(hasStroke ? mStrokeWidth : 0, mStrokeColor);
        invalidate();
    }

    /**
     * Sets an image icon which will have its size constrained and will be set to the same color as
     * the text. Must be called after {@link #setTextColor(int)} for the latter to work.
@@ -121,18 +107,13 @@ public class EmphasizedNotificationButton extends Button {
    }

    /**
     * Changes the LayoutParams.width to WRAP_CONTENT, with the argument representing if this view
     * is a priority over its peers (which affects weight).
     * Sets whether this view is a priority over its peers (which affects width).
     * Specifically, this is used by {@link NotificationActionListLayout} to give this view width
     * priority ahead of user-defined buttons when allocating horizontal space.
     */
    @RemotableViewMethod
    public void setWrapModePriority(boolean priority) {
    public void setIsPriority(boolean priority) {
        mPriority = priority;
        ViewGroup.LayoutParams layoutParams = getLayoutParams();
        layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
        if (layoutParams instanceof LinearLayout.LayoutParams) {
            ((LinearLayout.LayoutParams) layoutParams).weight = 0;
        }
        setLayoutParams(layoutParams);
    }

    /**
+61 −35
Original line number Diff line number Diff line
@@ -17,11 +17,11 @@
package com.android.internal.widget;

import android.annotation.DimenRes;
import android.app.Notification;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.RippleDrawable;
import android.util.AttributeSet;
import android.util.Pair;
import android.view.Gravity;
import android.view.RemotableViewMethod;
import android.view.View;
@@ -43,10 +43,9 @@ public class NotificationActionListLayout extends LinearLayout {
    private final int mGravity;
    private int mTotalWidth = 0;
    private int mExtraStartPadding = 0;
    private ArrayList<Pair<Integer, TextView>> mMeasureOrderTextViews = new ArrayList<>();
    private ArrayList<TextViewInfo> mMeasureOrderTextViews = new ArrayList<>();
    private ArrayList<View> mMeasureOrderOther = new ArrayList<>();
    private boolean mEmphasizedMode;
    private boolean mPrioritizedWrapMode;
    private int mDefaultPaddingBottom;
    private int mDefaultPaddingTop;
    private int mEmphasizedHeight;
@@ -70,16 +69,18 @@ public class NotificationActionListLayout extends LinearLayout {
        ta.recycle();
    }

    private static boolean isPriority(View actionView) {
        return actionView instanceof EmphasizedNotificationButton
                && ((EmphasizedNotificationButton) actionView).isPriority();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        if (mEmphasizedMode && !mPrioritizedWrapMode) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            return;
        }
        final int N = getChildCount();
        int textViews = 0;
        int otherViews = 0;
        int notGoneChildren = 0;
        int priorityChildren = 0;

        for (int i = 0; i < N; i++) {
            View c = getChildAt(i);
@@ -90,6 +91,9 @@ public class NotificationActionListLayout extends LinearLayout {
            }
            if (c.getVisibility() != GONE) {
                notGoneChildren++;
                if (isPriority(c)) {
                    priorityChildren++;
                }
            }
        }

@@ -103,9 +107,9 @@ public class NotificationActionListLayout extends LinearLayout {
        if (!needRebuild) {
            final int size = mMeasureOrderTextViews.size();
            for (int i = 0; i < size; i++) {
                Pair<Integer, TextView> pair = mMeasureOrderTextViews.get(i);
                if (pair.first != pair.second.getText().length()) {
                if (mMeasureOrderTextViews.get(i).needsRebuild()) {
                    needRebuild = true;
                    break;
                }
            }
        }
@@ -122,14 +126,19 @@ public class NotificationActionListLayout extends LinearLayout {
        int usedWidth = 0;

        int measuredChildren = 0;
        int measuredPriorityChildren = 0;
        for (int i = 0; i < N; i++) {
            // Measure shortest children first. To avoid measuring twice, we approximate by looking
            // at the text length.
            View c;
            final boolean isPriority;
            final View c;
            if (i < otherSize) {
                c = mMeasureOrderOther.get(i);
                isPriority = false;
            } else {
                c = mMeasureOrderTextViews.get(i - otherSize).second;
                TextViewInfo info = mMeasureOrderTextViews.get(i - otherSize);
                c = info.mTextView;
                isPriority = info.mIsPriority;
            }
            if (c.getVisibility() == GONE) {
                continue;
@@ -143,7 +152,18 @@ public class NotificationActionListLayout extends LinearLayout {
                // measure in the order of (approx.) size, a large view can still take more than its
                // share if the others are small.
                int availableWidth = innerWidth - usedWidth;
                int maxWidthForChild = availableWidth / (notGoneChildren - measuredChildren);
                int unmeasuredChildren = notGoneChildren - measuredChildren;
                int maxWidthForChild = availableWidth / unmeasuredChildren;
                if (isPriority) {
                    // Priority children get a larger maximum share of the total space:
                    //  maximum priority share = (nPriority + 1) / (MAX + 1)
                    int unmeasuredPriorityChildren = priorityChildren - measuredPriorityChildren;
                    int unmeasuredOtherChildren = unmeasuredChildren - unmeasuredPriorityChildren;
                    int widthReservedForOtherChildren = innerWidth * unmeasuredOtherChildren
                            / (Notification.MAX_ACTION_BUTTONS + 1);
                    int widthAvailableForPriority = availableWidth - widthReservedForOtherChildren;
                    maxWidthForChild = widthAvailableForPriority / unmeasuredPriorityChildren;
                }

                usedWidthForChild = innerWidth - maxWidthForChild;
            }
@@ -153,6 +173,9 @@ public class NotificationActionListLayout extends LinearLayout {

            usedWidth += c.getMeasuredWidth() + lp.rightMargin + lp.leftMargin;
            measuredChildren++;
            if (isPriority) {
                measuredPriorityChildren++;
            }
        }

        int collapsibleIndent = mCollapsibleIndentDimen == 0 ? 0
@@ -175,13 +198,8 @@ public class NotificationActionListLayout extends LinearLayout {
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            View c = getChildAt(i);
            if (c instanceof EmphasizedNotificationButton
                    && ((EmphasizedNotificationButton) c).isPriority()) {
                // add with 0 length to ensure that this view is measured before others.
                mMeasureOrderTextViews.add(Pair.create(0, (TextView) c));
            } else if (c instanceof TextView && ((TextView) c).getText().length() > 0) {
                mMeasureOrderTextViews.add(Pair.create(((TextView) c).getText().length(),
                        (TextView)c));
            if (c instanceof TextView && ((TextView) c).getText().length() > 0) {
                mMeasureOrderTextViews.add(new TextViewInfo((TextView) c));
            } else {
                mMeasureOrderOther.add(c);
            }
@@ -213,10 +231,6 @@ public class NotificationActionListLayout extends LinearLayout {

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        if (mEmphasizedMode && !mPrioritizedWrapMode) {
            super.onLayout(changed, left, top, right, bottom);
            return;
        }
        final boolean isLayoutRtl = isLayoutRtl();
        final int paddingTop = mPaddingTop;
        final boolean centerAligned = (mGravity & Gravity.CENTER_HORIZONTAL) != 0;
@@ -292,16 +306,6 @@ public class NotificationActionListLayout extends LinearLayout {
                com.android.internal.R.dimen.notification_action_list_height);
    }

    /**
     * When used with emphasizedMode, changes the button sizing behavior to prioritize certain
     * buttons (which are system generated) to not scrunch, and leave the remaining space for
     * custom actions.
     */
    @RemotableViewMethod
    public void setPrioritizedWrapMode(boolean prioritizedWrapMode) {
        mPrioritizedWrapMode = prioritizedWrapMode;
    }

    /**
     * When buttons are in wrap mode, this is a padding that will be applied at the start of the
     * layout of the actions, but only when those actions would fit with the entire padding
@@ -353,6 +357,28 @@ public class NotificationActionListLayout extends LinearLayout {
        return 0;
    }

    public static final Comparator<Pair<Integer, TextView>> MEASURE_ORDER_COMPARATOR
            = (a, b) -> a.first.compareTo(b.first);
    public static final Comparator<TextViewInfo> MEASURE_ORDER_COMPARATOR = (a, b) -> {
        int priorityComparison = -Boolean.compare(a.mIsPriority, b.mIsPriority);
        return priorityComparison != 0
                ? priorityComparison
                : Integer.compare(a.mTextLength, b.mTextLength);
    };

    private static final class TextViewInfo {
        final boolean mIsPriority;
        final int mTextLength;
        final TextView mTextView;

        TextViewInfo(TextView textView) {
            this.mIsPriority = isPriority(textView);
            this.mTextLength = textView.getText().length();
            this.mTextView = textView;
        }

        boolean needsRebuild() {
            return mTextView.getText().length() != mTextLength
                    || isPriority(mTextView) != mIsPriority;
        }
    }

}
+2 −4
Original line number Diff line number Diff line
@@ -24,13 +24,11 @@
        <item>
            <shape android:shape="rectangle">
                <corners android:radius="@dimen/notification_action_button_radius" />
                <padding android:left="@dimen/button_padding_horizontal_material"
                <padding android:left="12dp"
                         android:top="@dimen/button_padding_vertical_material"
                         android:right="@dimen/button_padding_horizontal_material"
                         android:right="12dp"
                         android:bottom="@dimen/button_padding_vertical_material" />
                <solid android:color="@color/white" />
                <stroke android:width="@dimen/emphasized_button_stroke_width"
                        android:color="@color/material_grey_300"/>
            </shape>
        </item>
    </ripple>
+1 −2
Original line number Diff line number Diff line
@@ -18,10 +18,9 @@
    xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/NotificationEmphasizedAction"
    android:id="@+id/action0"
    android:layout_width="match_parent"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_marginStart="12dp"
    android:layout_weight="1"
    android:drawablePadding="6dp"
    android:gravity="center"
    android:textColor="@color/notification_default_color"
Loading