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

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

Merge changes from topic "notif_text_flows_below_expander" into main

* changes:
  [Notif redesign] Remove large icon bottom margin
  [Notif redesign] Make text flow below expander in collapsed notifs
  Adjust right icon spacing based on font size
  Refactor right icon space calculation for promoted notifs
  Update mHeadingFullMarginSet
parents c90fc292 b68c6dc0
Loading
Loading
Loading
Loading
+72 −41
Original line number Diff line number Diff line
@@ -6266,13 +6266,25 @@ public class Notification implements Parcelable
                result = new TemplateBindResult();
            }
            bindLargeIcon(contentView, p, result);
            if (!p.mHeaderless) {
                // views in states with a header (big states)
                result.mHeadingExtraMarginSet.applyToView(contentView, R.id.notification_header);
            if (!p.mHeaderless) { // views in states with a header (expanded states)
                if (mN.isPromotedOngoing()) {
                    // When promoted, the expander is hidden but we need to include the notif margin
                    result.mHeadingFullMarginSet.applyToView(contentView, R.id.notification_header);
                } else {
                    result.mHeadingExtraMarginSet.applyToView(contentView,
                            R.id.notification_header);
                }
                result.mTitleMarginSet.applyToView(contentView, R.id.title);
                // If there is no title, the text (or big_text) needs to wrap around the image
                result.mTitleMarginSet.applyToView(contentView, p.mTextViewId);
                contentView.setInt(p.mTextViewId, "setNumIndentLines", p.hasTitle() ? 0 : 1);
            } else if (notificationsRedesignTemplates()) {
                // In the collapsed view, the top line needs to accommodate both the expander and
                // large icon (when present)
                result.mHeadingFullMarginSet.applyToView(contentView, R.id.notification_top_line);
                // The text underneath can flow below the expander, but only if there's no large
                // icon to leave space for (similar to the title in the expanded version).
                result.mTitleMarginSet.applyToView(contentView, R.id.notification_main_column);
            }
            // The expand button uses paddings rather than margins, so we'll adjust it
            // separately.
@@ -6299,6 +6311,10 @@ public class Notification implements Parcelable
                @NonNull TemplateBindResult result) {
            final Resources resources = mContext.getResources();
            final float density = resources.getDisplayMetrics().density;
            int notifMarginId = notificationsRedesignTemplates()
                    ? R.dimen.notification_2025_margin
                    : R.dimen.notification_content_margin;
            final float notificationMarginDp = resources.getDimension(notifMarginId) / density;
            int iconMarginId = notificationsRedesignTemplates()
                    ? R.dimen.notification_2025_right_icon_content_margin
                    : R.dimen.notification_right_icon_content_margin;
@@ -6306,17 +6322,18 @@ public class Notification implements Parcelable
            final float contentMarginDp = resources.getDimension(
                    R.dimen.notification_content_margin_end) / density;
            float spaceForExpanderDp;
            if (mN.isPromotedOngoing()) {
            if (Flags.uiRichOngoing() && mN.isPromotedOngoing() && !mParams.mHeaderless) {
                // No expander is shown in promoted notifications
                spaceForExpanderDp = 0;
            } else {
                final int expanderSizeRes;
                if (notificationsRedesignTemplates()) {
                    expanderSizeRes = R.dimen.notification_2025_right_icon_expanded_margin_end;
                    spaceForExpanderDp = getLargeIconMarginEnd(mParams) / density
                            - notificationMarginDp;
                } else {
                    expanderSizeRes =  R.dimen.notification_header_expand_icon_size;
                }
                    spaceForExpanderDp = resources.getDimension(
                        expanderSizeRes) / density - contentMarginDp;
                            R.dimen.notification_header_expand_icon_size) / density
                            - contentMarginDp;
                }
            }
            final float viewHeightDp = resources.getDimension(
@@ -6335,16 +6352,11 @@ public class Notification implements Parcelable
                    }
                }
            }
            result.setRightIconState(rightIcon != null /* visible */, viewWidthDp, viewHeightDp);
            // Margin needed for the header to accommodate the icon when shown
            final float extraMarginEndDpIfVisible = viewWidthDp + iconMarginDp;
            result.setRightIconState(rightIcon != null /* visible */, viewWidthDp,
                    viewHeightDp, extraMarginEndDpIfVisible, spaceForExpanderDp);
            if (mN.isPromotedOngoing() && !mParams.mHeaderless) {
                result.mHeadingExtraMarginSet.setValues(
                        /* valueIfGone = */ contentMarginDp,
                        /* valueIfVisible = */ extraMarginEndDpIfVisible + contentMarginDp);
            }
            result.calculateMargins(extraMarginEndDpIfVisible, spaceForExpanderDp,
                    notificationMarginDp);
        }
        /**
@@ -6387,20 +6399,9 @@ public class Notification implements Parcelable
                contentView.setImageViewIcon(R.id.right_icon, rightIcon);
                contentView.setIntTag(R.id.right_icon, R.id.tag_keep_when_showing_left_icon,
                        isPromotedPicture ? 1 : 0);
                if (Flags.uiRichOngoing() && !p.mHeaderless) {
                    final int largeIconMarginEnd;
                    if (mN.isPromotedOngoing()) {
                        largeIconMarginEnd = R.dimen.notification_content_margin;
                    } else {
                        if (notificationsRedesignTemplates()) {
                            largeIconMarginEnd =
                                    R.dimen.notification_2025_right_icon_expanded_margin_end;
                        } else {
                            largeIconMarginEnd = R.dimen.notification_header_expand_icon_size;
                        }
                    }
                    contentView.setViewLayoutMarginDimen(
                            R.id.right_icon, RemoteViews.MARGIN_END, largeIconMarginEnd);
                if (notificationsRedesignTemplates() || Flags.uiRichOngoing()) {
                    contentView.setViewLayoutMargin(R.id.right_icon,
                            RemoteViews.MARGIN_END, getLargeIconMarginEnd(p), COMPLEX_UNIT_PX);
                }
                processLargeLegacyIcon(rightIcon, contentView, p);
@@ -6413,6 +6414,29 @@ public class Notification implements Parcelable
            }
        }
        int getLargeIconMarginEnd(@NonNull StandardTemplateParams p) {
            Resources res = mContext.getResources();
            if (Flags.uiRichOngoing() && mN.isPromotedOngoing() && !p.mHeaderless) {
                // Promoted notifications don't need space for the expand button
                if (notificationsRedesignTemplates()) {
                    return res.getDimensionPixelSize(R.dimen.notification_2025_margin);
                } else {
                    return res.getDimensionPixelSize(R.dimen.notification_content_margin);
                }
            }
            if (notificationsRedesignTemplates()) {
                int rightIconMarginPx = res.getDimensionPixelSize(
                        R.dimen.notification_2025_right_icon_margin_end);
                int extraSpaceForExpanderPx = res.getDimensionPixelSize(
                        R.dimen.notification_2025_extra_space_for_expander);
                return rightIconMarginPx + extraSpaceForExpanderPx;
            } else {
                return res.getDimensionPixelSize(R.dimen.notification_header_expand_icon_size);
            }
        }
        private void bindNotificationHeader(RemoteViews contentView, StandardTemplateParams p) {
            bindSmallIcon(contentView, p);
            // Populate text left-to-right so that separators are only shown between strings
@@ -8375,8 +8399,12 @@ public class Notification implements Parcelable
                // ensures that we don't under-pad the content, which could lead to abuse, at the
                // cost of making single-line custom content over-padded.
                Builder.setHeaderlessVerticalMargins(template, p, true /* hasSecondLine */);
            } else {
                if (notificationsRedesignTemplates()) {
                    // also update the end margin to account for the large icon or expander
                    result.mHeadingFullMarginSet.applyToView(template,
                            R.id.notification_main_column);
                }
            } else {
                Resources resources = context.getResources();
                result.mTitleMarginSet.applyToView(template, R.id.notification_main_column,
                        resources.getDimension(R.dimen.notification_content_margin_end)
@@ -14941,8 +14969,7 @@ public class Notification implements Parcelable
        /**
         * The margin end that needs to be added to the heading so that it won't overlap
         * with the large icon. This value includes the space required to accommodate the large
         * icon as well as the expander.  This does not include the 16dp content margin that all
         * notification views must have.
         * icon as well as the expander (when present). This DOES include the 16dp content margin.
         */
        public final MarginSet mHeadingFullMarginSet = new MarginSet();
@@ -14953,17 +14980,21 @@ public class Notification implements Parcelable
         */
        public final MarginSet mTitleMarginSet = new MarginSet();
        public void setRightIconState(boolean visible, float widthDp, float heightDp,
                float marginEndDpIfVisible, float spaceForExpanderDp) {
        public void setRightIconState(boolean visible, float widthDp, float heightDp) {
            mRightIconVisible = visible;
            mRightIconWidthDp = widthDp;
            mRightIconHeightDp = heightDp;
        }
        public void calculateMargins(float marginEndDpIfVisible, float spaceForExpanderDp,
                float notificationMarginDp) {
            mHeadingExtraMarginSet.setValues(
                    /* valueIfGone = */ 0,
                    /* valueIfVisible = */ marginEndDpIfVisible);
            mHeadingFullMarginSet.setValues(
                    /* valueIfGone = */ spaceForExpanderDp,
                    /* valueIfVisible = */ marginEndDpIfVisible + spaceForExpanderDp);
                    /* valueIfGone = */ spaceForExpanderDp + notificationMarginDp,
                    /* valueIfVisible = */ marginEndDpIfVisible + spaceForExpanderDp
                            + notificationMarginDp);
            mTitleMarginSet.setValues(
                    /* valueIfGone = */ 0,
                    /* valueIfVisible = */ marginEndDpIfVisible + spaceForExpanderDp);
+3 −3
Original line number Diff line number Diff line
@@ -13,15 +13,15 @@
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License
  -->
<!-- Large icon to be used in expanded notification layouts. -->
<!-- Large icon to be used in notification layouts. -->
<com.android.internal.widget.CachingIconView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/right_icon"
    android:layout_width="@dimen/notification_right_icon_size"
    android:layout_height="@dimen/notification_right_icon_size"
    android:layout_gravity="top|end"
    android:layout_marginEnd="@dimen/notification_2025_right_icon_expanded_margin_end"
    android:layout_marginVertical="@dimen/notification_2025_right_icon_vertical_margin"
    android:layout_marginEnd="@dimen/notification_2025_right_icon_margin_end"
    android:layout_marginTop="@dimen/notification_2025_right_icon_vertical_margin"
    android:background="@drawable/notification_large_icon_outline"
    android:clipToOutline="true"
    android:importantForAccessibility="no"
+9 −20
Original line number Diff line number Diff line
@@ -58,12 +58,11 @@
        android:focusable="false"
        />

    <LinearLayout
    <FrameLayout
        android:id="@+id/notification_headerless_view_row"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginStart="@dimen/notification_2025_content_margin_start"
        android:orientation="horizontal"
        >

        <!--
@@ -72,19 +71,19 @@
        -->
        <LinearLayout
            android:id="@+id/notification_headerless_view_column"
            android:layout_width="0px"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:layout_marginVertical="@dimen/notification_2025_reduced_margin"
            android:orientation="vertical"
            >

            <NotificationTopLineView
                android:id="@+id/notification_top_line"
                android:layout_width="wrap_content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/notification_2025_additional_margin"
                android:layout_marginEnd="@dimen/notification_2025_content_margin_end"
                android:minHeight="@dimen/notification_2025_content_min_height"
                android:clipChildren="false"
                android:theme="@style/Theme.DeviceDefault.Notification"
@@ -123,6 +122,7 @@
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="@dimen/notification_2025_additional_margin"
                    android:layout_marginEnd="@dimen/notification_2025_margin"
                    android:minHeight="@dimen/notification_headerless_line_height"
                    >
                    <include layout="@layout/notification_2025_text" />
@@ -132,32 +132,21 @@
                    layout="@layout/notification_template_progress"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/notification_headerless_line_height"
                    android:layout_marginEnd="@dimen/notification_2025_margin"
                    />

            </LinearLayout>

        </LinearLayout>

        <com.android.internal.widget.CachingIconView
            android:id="@+id/right_icon"
            android:layout_width="@dimen/notification_right_icon_size"
            android:layout_height="@dimen/notification_right_icon_size"
            android:layout_gravity="center_vertical|end"
            android:layout_marginVertical="@dimen/notification_2025_right_icon_vertical_margin"
            android:layout_marginStart="@dimen/notification_2025_right_icon_content_margin"
            android:background="@drawable/notification_large_icon_outline"
            android:clipToOutline="true"
            android:importantForAccessibility="no"
            android:scaleType="centerCrop"
            android:maxDrawableWidth="@dimen/notification_right_icon_size"
            android:maxDrawableHeight="@dimen/notification_right_icon_size"
            />
        <include layout="@layout/notification_2025_right_icon" />

        <FrameLayout
            android:id="@+id/expand_button_touch_container"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:minWidth="@dimen/notification_2025_margin"
            android:layout_gravity="top|end"
            >

            <include layout="@layout/notification_2025_expand_button"
@@ -168,7 +157,7 @@

        </FrameLayout>

    </LinearLayout>
    </FrameLayout>

    <include layout="@layout/notification_close_button"
        android:id="@+id/close_button"
+8 −18
Original line number Diff line number Diff line
@@ -64,20 +64,18 @@
                android:focusable="false"
                />

            <LinearLayout
            <FrameLayout
                android:id="@+id/notification_headerless_view_row"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginStart="@dimen/notification_2025_content_margin_start"
                android:orientation="horizontal"
                android:clipChildren="false"
                >

                <LinearLayout
                    android:id="@+id/notification_headerless_view_column"
                    android:layout_width="0px"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:layout_marginTop="@dimen/notification_2025_margin"
                    android:clipChildren="false"
                    android:orientation="vertical"
@@ -85,9 +83,10 @@

                    <NotificationTopLineView
                        android:id="@+id/notification_top_line"
                        android:layout_width="wrap_content"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:minHeight="@dimen/notification_headerless_line_height"
                        android:layout_marginEnd="@dimen/notification_2025_content_margin_end"
                        android:clipChildren="false"
                        android:theme="@style/Theme.DeviceDefault.Notification"
                        >
@@ -124,6 +123,7 @@
                        <com.android.internal.widget.NotificationVanishingFrameLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginEnd="@dimen/notification_2025_margin"
                            android:minHeight="@dimen/notification_headerless_line_height"
                            >
                            <include layout="@layout/notification_2025_text" />
@@ -132,24 +132,14 @@

                </LinearLayout>

                <ImageView
                    android:id="@+id/right_icon"
                    android:layout_width="@dimen/notification_right_icon_size"
                    android:layout_height="@dimen/notification_right_icon_size"
                    android:layout_gravity="center_vertical|end"
                    android:layout_marginVertical="@dimen/notification_2025_right_icon_vertical_margin"
                    android:layout_marginStart="@dimen/notification_2025_right_icon_content_margin"
                    android:background="@drawable/notification_large_icon_outline"
                    android:clipToOutline="true"
                    android:importantForAccessibility="no"
                    android:scaleType="centerCrop"
                    />
                <include layout="@layout/notification_2025_right_icon" />

                <FrameLayout
                    android:id="@+id/expand_button_touch_container"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:minWidth="@dimen/notification_2025_margin"
                    android:layout_gravity="top|end"
                    >

                    <include layout="@layout/notification_2025_expand_button"
@@ -160,7 +150,7 @@

                </FrameLayout>

            </LinearLayout>
            </FrameLayout>

            <include layout="@layout/notification_close_button"
                android:id="@+id/close_button"
+8 −18
Original line number Diff line number Diff line
@@ -68,19 +68,17 @@
              layout_marginStart on the id/notification_headerless_view_row, we put it on
              id/notification_top_line, making the layout here just a bit different from the base.
              -->
            <LinearLayout
            <FrameLayout
                android:id="@+id/notification_headerless_view_row"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal"
                android:clipChildren="false"
                >

                <LinearLayout
                    android:id="@+id/notification_headerless_view_column"
                    android:layout_width="0px"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:layout_marginTop="@dimen/notification_2025_margin"
                    android:layout_marginStart="@dimen/notification_2025_content_margin_start"
                    android:clipChildren="false"
@@ -89,9 +87,10 @@

                    <NotificationTopLineView
                        android:id="@+id/notification_top_line"
                        android:layout_width="wrap_content"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:minHeight="@dimen/notification_headerless_line_height"
                        android:layout_marginEnd="@dimen/notification_2025_content_margin_end"
                        android:clipChildren="false"
                        android:theme="@style/Theme.DeviceDefault.Notification"
                        >
@@ -129,6 +128,7 @@
                            android:id="@+id/notification_messaging"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginEnd="@dimen/notification_2025_margin"
                            android:clipChildren="false"
                            android:spacing="@dimen/notification_messaging_spacing" />
                    </LinearLayout>
@@ -149,24 +149,14 @@
                    android:visibility="gone"
                    />

                <ImageView
                    android:id="@+id/right_icon"
                    android:layout_width="@dimen/notification_right_icon_size"
                    android:layout_height="@dimen/notification_right_icon_size"
                    android:layout_gravity="center_vertical|end"
                    android:layout_marginVertical="@dimen/notification_2025_right_icon_vertical_margin"
                    android:layout_marginStart="@dimen/notification_2025_right_icon_content_margin"
                    android:background="@drawable/notification_large_icon_outline"
                    android:clipToOutline="true"
                    android:importantForAccessibility="no"
                    android:scaleType="centerCrop"
                    />
                <include layout="@layout/notification_2025_right_icon" />

                <FrameLayout
                    android:id="@+id/expand_button_touch_container"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:minWidth="@dimen/notification_2025_margin"
                    android:layout_gravity="top|end"
                    >

                    <include layout="@layout/notification_2025_expand_button"
@@ -177,7 +167,7 @@

                </FrameLayout>

            </LinearLayout>
            </FrameLayout>

            <include layout="@layout/notification_close_button"
                android:id="@+id/close_button"
Loading