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

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

Merge changes Ic08ec354,If3ef7948 into main

* changes:
  [Notif redesign] Center top line vertically when needed
  [Notif redesign] Allow space for entire header in expanded groups
parents 77678aa0 4da4efc9
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -6822,6 +6822,12 @@ public class Notification implements Parcelable
                    getHeaderLayoutResource());
            resetNotificationHeader(header);
            bindNotificationHeader(header, p);
            if (Flags.notificationsRedesignTemplates()
                    && (p.mViewType == StandardTemplateParams.VIEW_TYPE_MINIMIZED
                    || p.mViewType == StandardTemplateParams.VIEW_TYPE_PUBLIC)) {
                // Center top line vertically in minimized and public header-only views
                header.setBoolean(R.id.notification_header, "centerTopLine", true);
            }
            return header;
        }
+32 −0
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@

package android.view;

import static android.app.Flags.notificationsRedesignTemplates;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
@@ -27,6 +31,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.RelativeLayout;
import android.widget.RemoteViews;
import android.widget.TextView;
@@ -173,6 +178,33 @@ public class NotificationHeaderView extends RelativeLayout {
                (int) (extraMarginEndDp * getResources().getDisplayMetrics().density));
    }

    /**
     * Center top line  and expand button vertically.
     */
    @RemotableViewMethod
    public void centerTopLine(boolean center) {
        if (notificationsRedesignTemplates()) {
            // The content of the top line view is already center-aligned, but since the height
            // matches the content by default, it looks top-aligned. If the height matches the
            // parent instead, the text ends up correctly centered in the parent.
            ViewGroup.LayoutParams lp = mTopLineView.getLayoutParams();
            lp.height = center ? MATCH_PARENT : WRAP_CONTENT;
            mTopLineView.setLayoutParams(lp);

            centerExpandButton(center);
        }
    }

    /** Center expand button vertically. */
    private void centerExpandButton(boolean center) {
        ViewGroup.LayoutParams lp = mExpandButton.getLayoutParams();
        lp.height = center ? MATCH_PARENT : WRAP_CONTENT;
        if (lp instanceof FrameLayout.LayoutParams flp) {
            flp.gravity = center ? Gravity.CENTER : (Gravity.TOP | Gravity.END);
        }
        mExpandButton.setLayoutParams(lp);
    }

    /**
     * This is used to make the low-priority header show the bolded text of a title.
     *
+3 −0
Original line number Diff line number Diff line
@@ -3685,6 +3685,9 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        if (mIsSummaryWithChildren && (!mIsMinimized || wasExpanded)) {
            nowExpanded = mGroupExpansionManager.isGroupExpanded(mEntry);
        }
        // Note: nowExpanded is going to be true here on the first expansion of minimized groups,
        // even though the group itself is not expanded. Use mGroupExpansionManager to get the real
        // group expansion if needed.
        if (nowExpanded != wasExpanded) {
            updateShelfIconColor();
            if (mLogger != null) {
+44 −35
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import android.os.Trace;
import android.service.notification.StatusBarNotification;
import android.util.AttributeSet;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.NotificationHeaderView;
import android.view.View;
@@ -93,9 +92,16 @@ public class NotificationChildrenContainer extends ViewGroup
    private int mChildPadding;
    private int mDividerHeight;
    private float mDividerAlpha;
    private int mNotificationHeaderMargin;

    private int mNotificationTopPadding;
    private int mHeaderHeight;
    /** Margin needed at the top in the collapsed group, to allow space for the header text. */
    private int mCollapsedHeaderMargin;
    /**
     * Spacing needed in addition to {@link this#mCollapsedHeaderMargin} when the group is expanded,
     * to accommodate the full header. It doesn't include the spacing needed for the first divider.
     */
    private int mAdditionalExpandedHeaderMargin;

    private float mCollapsedBottomPadding;
    private boolean mChildrenExpanded;
    private ExpandableNotificationRow mContainingNotification;
@@ -105,7 +111,6 @@ public class NotificationChildrenContainer extends ViewGroup
    private boolean mUserLocked;
    private int mActualHeight;
    private boolean mNeverAppliedGroupState;
    private int mHeaderHeight;

    /**
     * Whether or not individual notifications that are part of this container will have shadows.
@@ -168,15 +173,18 @@ public class NotificationChildrenContainer extends ViewGroup
        mDividerHeight = res.getDimensionPixelOffset(
                R.dimen.notification_children_container_divider_height);
        mDividerAlpha = res.getFloat(R.dimen.notification_divider_alpha);
        mNotificationHeaderMargin = notificationsRedesignTemplates()
                ? Notification.Builder.getContentMarginTop(getContext(),
                    R.dimen.notification_2025_children_container_margin_top)
                : res.getDimensionPixelOffset(R.dimen.notification_children_container_margin_top);
        mNotificationTopPadding = res.getDimensionPixelOffset(
        if (notificationsRedesignTemplates()) {
            mHeaderHeight = res.getDimensionPixelSize(R.dimen.notification_2025_header_height);
            mCollapsedHeaderMargin = Notification.Builder.getContentMarginTop(getContext(),
                    R.dimen.notification_2025_children_container_margin_top);
            mAdditionalExpandedHeaderMargin = mHeaderHeight - mCollapsedHeaderMargin;
        } else {
            mCollapsedHeaderMargin = res.getDimensionPixelOffset(
                    R.dimen.notification_children_container_margin_top);
            mAdditionalExpandedHeaderMargin = res.getDimensionPixelOffset(
                    R.dimen.notification_children_container_top_padding);
        mHeaderHeight = notificationsRedesignTemplates()
                ? res.getDimensionPixelSize(R.dimen.notification_2025_header_height)
                : mNotificationHeaderMargin + mNotificationTopPadding;
            mHeaderHeight = mCollapsedHeaderMargin + mAdditionalExpandedHeaderMargin;
        }
        mCollapsedBottomPadding = res.getDimensionPixelOffset(
                R.dimen.notification_children_collapsed_bottom_padding);
        mEnableShadowOnChildNotifications =
@@ -189,7 +197,7 @@ public class NotificationChildrenContainer extends ViewGroup
                res.getBoolean(R.bool.config_hideDividersDuringExpand);
        mTranslationForHeader = res.getDimensionPixelOffset(
                com.android.internal.R.dimen.notification_content_margin)
                - mNotificationHeaderMargin;
                - mCollapsedHeaderMargin;
        mHybridGroupManager.initDimens();
        mMinSingleLineHeight = getResources().getDimensionPixelSize(
                R.dimen.conversation_single_line_face_pile_size);
@@ -251,7 +259,7 @@ public class NotificationChildrenContainer extends ViewGroup
                    newHeightSpec);
        }
        int dividerHeightSpec = MeasureSpec.makeMeasureSpec(mDividerHeight, MeasureSpec.EXACTLY);
        int height = mNotificationHeaderMargin + mNotificationTopPadding;
        int height = mCollapsedHeaderMargin + mAdditionalExpandedHeaderMargin;
        int childCount =
                Math.min(mAttachedChildren.size(), NUMBER_OF_CHILDREN_WHEN_CHILDREN_EXPANDED);
        int collapsedChildren = getMaxAllowedVisibleChildren(true /* likeCollapsed */);
@@ -705,7 +713,7 @@ public class NotificationChildrenContainer extends ViewGroup
                return mMinimizedGroupHeader.getHeight();
            }
        }
        int intrinsicHeight = mNotificationHeaderMargin + mCurrentHeaderTranslation;
        int intrinsicHeight = mCollapsedHeaderMargin + mCurrentHeaderTranslation;
        int visibleChildren = 0;
        int childCount = mAttachedChildren.size();
        boolean firstChild = true;
@@ -729,11 +737,11 @@ public class NotificationChildrenContainer extends ViewGroup
                if (mUserLocked) {
                    intrinsicHeight += NotificationUtils.interpolate(
                            0,
                            mNotificationTopPadding + mDividerHeight,
                            mAdditionalExpandedHeaderMargin + mDividerHeight,
                            expandFactor);
                } else {
                    intrinsicHeight += childrenExpanded
                            ? mNotificationTopPadding + mDividerHeight
                            ? mAdditionalExpandedHeaderMargin + mDividerHeight
                            : 0;
                }
                firstChild = false;
@@ -758,7 +766,7 @@ public class NotificationChildrenContainer extends ViewGroup
     */
    public void updateState(ExpandableViewState parentState) {
        int childCount = mAttachedChildren.size();
        int yPosition = mNotificationHeaderMargin + mCurrentHeaderTranslation;
        int yPosition = mCollapsedHeaderMargin + mCurrentHeaderTranslation;
        boolean firstChild = true;
        int maxAllowedVisibleChildren = getMaxAllowedVisibleChildren();
        int lastVisibleIndex = maxAllowedVisibleChildren - 1;
@@ -786,10 +794,12 @@ public class NotificationChildrenContainer extends ViewGroup
                if (expandingToExpandedGroup) {
                    yPosition += NotificationUtils.interpolate(
                            0,
                            mNotificationTopPadding + mDividerHeight,
                            mAdditionalExpandedHeaderMargin + mDividerHeight,
                            expandFactor);
                } else {
                    yPosition += mChildrenExpanded ? mNotificationTopPadding + mDividerHeight : 0;
                    yPosition += mChildrenExpanded
                            ? mAdditionalExpandedHeaderMargin + mDividerHeight
                            : 0;
                }
                firstChild = false;
            }
@@ -852,7 +862,7 @@ public class NotificationChildrenContainer extends ViewGroup
                }
            } else {
                mGroupOverFlowState.setYTranslation(
                        mGroupOverFlowState.getYTranslation() + mNotificationHeaderMargin);
                        mGroupOverFlowState.getYTranslation() + mCollapsedHeaderMargin);
                mGroupOverFlowState.setAlpha(0.0f);
            }
        }
@@ -1148,10 +1158,12 @@ public class NotificationChildrenContainer extends ViewGroup
        return mContainingNotification;
    }

    @Nullable
    public NotificationViewWrapper getNotificationViewWrapper() {
        return mGroupHeaderWrapper;
    }

    @Nullable
    public NotificationViewWrapper getMinimizedGroupHeaderWrapper() {
        return mMinimizedGroupHeaderWrapper;
    }
@@ -1161,10 +1173,12 @@ public class NotificationChildrenContainer extends ViewGroup
        return mCurrentHeader;
    }

    @Nullable
    public NotificationHeaderView getGroupHeader() {
        return mGroupHeader;
    }

    @Nullable
    public NotificationHeaderView getMinimizedNotificationHeader() {
        return mMinimizedGroupHeader;
    }
@@ -1301,8 +1315,8 @@ public class NotificationChildrenContainer extends ViewGroup
            return getMinHeight(NUMBER_OF_CHILDREN_WHEN_SYSTEM_EXPANDED, true
                    /* likeHighPriority */);
        }
        int maxContentHeight = mNotificationHeaderMargin + mCurrentHeaderTranslation
                + mNotificationTopPadding;
        int maxContentHeight = mCollapsedHeaderMargin + mCurrentHeaderTranslation
                + mAdditionalExpandedHeaderMargin;
        int visibleChildren = 0;
        int childCount = mAttachedChildren.size();
        for (int i = 0; i < childCount; i++) {
@@ -1364,8 +1378,8 @@ public class NotificationChildrenContainer extends ViewGroup
    }

    private int getVisibleChildrenExpandHeight() {
        int intrinsicHeight = mNotificationHeaderMargin + mCurrentHeaderTranslation
                + mNotificationTopPadding + mDividerHeight;
        int intrinsicHeight = mCollapsedHeaderMargin + mCurrentHeaderTranslation
                + mAdditionalExpandedHeaderMargin + mDividerHeight;
        int visibleChildren = 0;
        int childCount = mAttachedChildren.size();
        int maxAllowedVisibleChildren = getMaxAllowedVisibleChildren(true /* forceCollapsed */);
@@ -1430,7 +1444,7 @@ public class NotificationChildrenContainer extends ViewGroup
            }
            return mMinimizedGroupHeader.getHeight();
        }
        int minExpandHeight = mNotificationHeaderMargin + headerTranslation;
        int minExpandHeight = mCollapsedHeaderMargin + headerTranslation;
        int visibleChildren = 0;
        boolean firstChild = true;
        int childCount = mAttachedChildren.size();
@@ -1518,18 +1532,13 @@ public class NotificationChildrenContainer extends ViewGroup
            // The overflow number is not used, so its color is irrelevant; skip this
            return;
        }
        int color = mContainingNotification.getNotificationColor();
        Resources.Theme theme = new ContextThemeWrapper(mContext,
                com.android.internal.R.style.Theme_DeviceDefault_DayNight).getTheme();

        color = mContext.getColor(com.android.internal.R.color.materialColorPrimary);

        int color = mContext.getColor(com.android.internal.R.color.materialColorPrimary);
        mHybridGroupManager.setOverflowNumberColor(mOverflowNumber, color);
    }

    public int getPositionInLinearLayout(View childInGroup) {
        int position = mNotificationHeaderMargin + mCurrentHeaderTranslation
                + mNotificationTopPadding;
        int position = mCollapsedHeaderMargin + mCurrentHeaderTranslation
                + mAdditionalExpandedHeaderMargin;

        for (int i = 0; i < mAttachedChildren.size(); i++) {
            ExpandableNotificationRow child = mAttachedChildren.get(i);
+22 −6
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.statusbar.notification.stack;

import static android.app.Flags.notificationsRedesignTemplates;
import static android.os.Trace.TRACE_TAG_APP;
import static android.view.MotionEvent.ACTION_CANCEL;
import static android.view.MotionEvent.ACTION_UP;
@@ -62,6 +63,7 @@ import android.view.DisplayCutout;
import android.view.InputDevice;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.NotificationHeaderView;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
@@ -6849,15 +6851,29 @@ public class NotificationStackScrollLayout
            mExpandedGroupView = changedRow;
            mNeedsAnimation = true;
        }

        changedRow.setChildrenExpanded(expanded);
        onChildHeightChanged(changedRow, false /* needsAnimation */);
        updateGroupHeaderAlignment(changedRow, expanded);

        runAfterAnimationFinished(new Runnable() {
            @Override
            public void run() {
                changedRow.onFinishedExpansionChange();
        runAfterAnimationFinished(changedRow::onFinishedExpansionChange);
    }

    private void updateGroupHeaderAlignment(ExpandableNotificationRow row, boolean expanded) {
        if (!notificationsRedesignTemplates()) {
            return;
        }

        NotificationChildrenContainer childrenContainer = row.getChildrenContainer();
        if (childrenContainer == null) {
            Log.wtf(TAG, "Tried to update group header alignment for something that's "
                    + "not a group; key = " + row.getEntry().getKey());
            return;
        }
        NotificationHeaderView header = childrenContainer.getGroupHeader();
        if (header != null) {
            header.centerTopLine(expanded);
        }
        });
    }

    private final ExpandHelper.Callback mExpandHelperCallback = new ExpandHelper.Callback() {