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

Commit 9a8eb11e authored by Ioana Alexandru's avatar Ioana Alexandru Committed by Android (Google) Code Review
Browse files

Merge changes Ib628f954,I3ecede3c into main

* changes:
  [Notif redesign] Expander: highlight unopened groups
  [Notif redesign] Expander: center numbered layout better
parents c6395369 b3f8bf0a
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -6204,7 +6204,7 @@ public class Notification implements Parcelable
            int textColor = Colors.flattenAlpha(getPrimaryTextColor(p), pillColor);
            contentView.setInt(R.id.expand_button, "setDefaultTextColor", textColor);
            contentView.setInt(R.id.expand_button, "setDefaultPillColor", pillColor);
            // Use different highlighted colors for conversations' unread count
            // Use different highlighted colors for e.g. unopened groups
            if (p.mHighlightExpander) {
                pillColor = Colors.flattenAlpha(
                        getColors(p).getTertiaryFixedDimAccentColor(), bgColor);
@@ -6804,6 +6804,8 @@ public class Notification implements Parcelable
        public RemoteViews makeNotificationGroupHeader() {
            return makeNotificationHeader(mParams.reset()
                    .viewType(StandardTemplateParams.VIEW_TYPE_GROUP_HEADER)
                    // Highlight group expander until the group is first opened
                    .highlightExpander(Flags.notificationsRedesignTemplates())
                    .fillTextsFrom(this));
        }
@@ -6973,12 +6975,14 @@ public class Notification implements Parcelable
         * @param useRegularSubtext uses the normal subtext set if there is one available. Otherwise
         *                          a new subtext is created consisting of the content of the
         *                          notification.
         * @param highlightExpander whether the expander should use the highlighted colors
         * @hide
         */
        public RemoteViews makeLowPriorityContentView(boolean useRegularSubtext) {
        public RemoteViews makeLowPriorityContentView(boolean useRegularSubtext,
                boolean highlightExpander) {
            StandardTemplateParams p = mParams.reset()
                    .viewType(StandardTemplateParams.VIEW_TYPE_MINIMIZED)
                    .highlightExpander(false)
                    .highlightExpander(highlightExpander)
                    .fillTextsFrom(this);
            if (!useRegularSubtext || TextUtils.isEmpty(p.mSubText)) {
                p.summaryText(createSummaryText());
+63 −15
Original line number Diff line number Diff line
@@ -27,12 +27,12 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.util.AttributeSet;
import android.view.RemotableViewMethod;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RemoteViews;
import android.widget.TextView;

@@ -49,12 +49,15 @@ public class NotificationExpandButton extends FrameLayout {
    private Drawable mPillDrawable;
    private TextView mNumberView;
    private ImageView mIconView;
    private LinearLayout mPillView;
    private boolean mExpanded;
    private int mNumber;
    private int mDefaultPillColor;
    private int mDefaultTextColor;
    private int mHighlightPillColor;
    private int mHighlightTextColor;
    // Track whether this ever had mExpanded = true, so that we don't highlight it anymore.
    private boolean mWasExpanded = false;

    public NotificationExpandButton(Context context) {
        this(context, null, 0, 0);
@@ -78,8 +81,8 @@ public class NotificationExpandButton extends FrameLayout {
    protected void onFinishInflate() {
        super.onFinishInflate();

        final View pillView = findViewById(R.id.expand_button_pill);
        final LayerDrawable layeredPill = (LayerDrawable) pillView.getBackground();
        mPillView = findViewById(R.id.expand_button_pill);
        final LayerDrawable layeredPill = (LayerDrawable) mPillView.getBackground();
        mPillDrawable = layeredPill.findDrawableByLayerId(R.id.expand_button_pill_colorized_layer);
        mNumberView = findViewById(R.id.expand_button_number);
        mIconView = findViewById(R.id.expand_button_icon);
@@ -133,6 +136,7 @@ public class NotificationExpandButton extends FrameLayout {
        int contentDescriptionId;
        if (mExpanded) {
            if (notificationsRedesignTemplates()) {
                mWasExpanded = true;
                drawableId = R.drawable.ic_notification_2025_collapse;
            } else {
                drawableId = R.drawable.ic_collapse_notification;
@@ -152,6 +156,8 @@ public class NotificationExpandButton extends FrameLayout {
        if (!notificationsRedesignTemplates()) {
            // changing the expanded state can affect the number display
            updateNumber();
        } else {
            updateColors();
        }
    }

@@ -166,11 +172,52 @@ public class NotificationExpandButton extends FrameLayout {
            mNumberView.setVisibility(GONE);
        }

        // changing number can affect the color
        // changing number can affect the color and padding
        updateColors();
        updatePadding();
    }

    private void updatePadding() {
        if (!notificationsRedesignTemplates()) {
            return;
        }

        // Reduce the padding at the end when showing the number, since the arrow icon has more
        // inherent spacing than the number does. This makes the content look more centered.
        // Vertical padding remains unchanged.
        int reducedPadding = getResources().getDimensionPixelSize(
                R.dimen.notification_2025_expand_button_reduced_end_padding);
        int normalPadding = getResources().getDimensionPixelSize(
                R.dimen.notification_2025_expand_button_horizontal_icon_padding);
        mPillView.setPaddingRelative(
                /* start = */ normalPadding,
                /* top = */ mPillView.getPaddingTop(),
                /* end = */ shouldShowNumber() ? reducedPadding : normalPadding,
                /* bottom = */ mPillView.getPaddingBottom()
        );
    }

    /**
     * Use highlight colors for the expander for groups (when the number is showing) that haven't
     * been opened before, as long as the colors are available.
     */
    private boolean shouldBeHighlighted() {
        return !mWasExpanded && shouldShowNumber()
                && mHighlightPillColor != 0 && mHighlightTextColor != 0;
    }

    private void updateColors() {
        if (notificationsRedesignTemplates()) {
            if (shouldBeHighlighted()) {
                mPillDrawable.setTintList(ColorStateList.valueOf(mHighlightPillColor));
                mIconView.setColorFilter(mHighlightTextColor);
                mNumberView.setTextColor(mHighlightTextColor);
            } else {
                mPillDrawable.setTintList(ColorStateList.valueOf(mDefaultPillColor));
                mIconView.setColorFilter(mDefaultTextColor);
                mNumberView.setTextColor(mDefaultTextColor);
            }
        } else {
            if (shouldShowNumber()) {
                if (mHighlightPillColor != 0) {
                    mPillDrawable.setTintList(ColorStateList.valueOf(mHighlightPillColor));
@@ -189,6 +236,7 @@ public class NotificationExpandButton extends FrameLayout {
                }
            }
        }
    }

    private boolean shouldShowNumber() {
        if (notificationsRedesignTemplates()) {
+3 −0
Original line number Diff line number Diff line
@@ -408,6 +408,9 @@
    <!-- the padding of the expand icon in the notification header -->
    <dimen name="notification_2025_expand_button_horizontal_icon_padding">6dp</dimen>

    <!-- a smaller padding for the end of the expand button, for use when showing the number -->
    <dimen name="notification_2025_expand_button_reduced_end_padding">4dp</dimen>

    <!-- the size of the notification close button -->
    <dimen name="notification_close_button_size">16dp</dimen>

+2 −0
Original line number Diff line number Diff line
@@ -3247,6 +3247,8 @@
  <java-symbol type="dimen" name="notification_content_margin" />
  <java-symbol type="dimen" name="notification_2025_margin" />
  <java-symbol type="dimen" name="notification_2025_content_margin_top" />
  <java-symbol type="dimen" name="notification_2025_expand_button_horizontal_icon_padding" />
  <java-symbol type="dimen" name="notification_2025_expand_button_reduced_end_padding" />
  <java-symbol type="dimen" name="notification_progress_margin_horizontal" />
  <java-symbol type="dimen" name="notification_header_background_height" />
  <java-symbol type="dimen" name="notification_header_touchable_height" />
+1 −1
Original line number Diff line number Diff line
@@ -279,7 +279,7 @@ public class NotificationChildrenContainerTest extends SysuiTestCase {
                notification);
        RemoteViews headerRemoteViews;
        if (lowPriority) {
            headerRemoteViews = builder.makeLowPriorityContentView(true);
            headerRemoteViews = builder.makeLowPriorityContentView(true, false);
        } else {
            headerRemoteViews = builder.makeNotificationGroupHeader();
        }
Loading