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

Commit 4da4efc9 authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

[Notif redesign] Center top line vertically when needed

The top line text and expand button are usually aligned near the top of
the app icon, but in some cases where we're only showing this line of
text in the notification with nothing below it, it should be vertically
centered instead.

More specifically:
- in group headers when expanded
- in automatic public views
- in minimized views, including low priority groups

Also added some explicit nullability annotations in
NotificationChildrenContainer because I originally hadn't realised that
the group header can be null and got an NPR. This should help the IDE
warn against that in the future.

Bug: 378660052
Test: manually tested all the cases specified above, screenshot tests to come later
Flag: android.app.notifications_redesign_templates
Change-Id: Ic08ec354a435123dd8e58bf25fc58e78d246d47c
parent a45cfd8f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -6819,6 +6819,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) {
+4 −0
Original line number Diff line number Diff line
@@ -1158,10 +1158,12 @@ public class NotificationChildrenContainer extends ViewGroup
        return mContainingNotification;
    }

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

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

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

    @Nullable
    public NotificationHeaderView getMinimizedNotificationHeader() {
        return mMinimizedGroupHeader;
    }
+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;
@@ -6856,15 +6858,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() {