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

Commit fe2229e6 authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

[Notif redesign] Top-align top line in expanded notifs

In expanded notifications, the top line of text showing the app name,
timestamp etc should be aligned with the top of the icon (so 16dp under
the top of the notification, which is the margin used for most things in
the redesign).

Also align the content that comes below it accordingly.

Bug: 378660052
Test: visual test, screenshot tests to come later
Flag: android.app.notifications_redesign_templates
Change-Id: I93d624ad4cd46fd454286c8771ca6bb9d15c74ac
parent e55bbde6
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -6453,6 +6453,13 @@ public class Notification implements Parcelable
            big.setColorStateList(R.id.snooze_button, "setImageTintList", actionColor);
            big.setColorStateList(R.id.bubble_button, "setImageTintList", actionColor);
            if (Flags.notificationsRedesignTemplates()) {
                int margin = getContentMarginTop(mContext,
                        R.dimen.notification_2025_content_margin_top);
                big.setViewLayoutMargin(R.id.notification_main_column, RemoteViews.MARGIN_TOP,
                        margin, TypedValue.COMPLEX_UNIT_PX);
            }
            boolean validRemoteInput = false;
            // In the UI, contextual actions appear separately from the standard actions, so we
@@ -6549,6 +6556,30 @@ public class Notification implements Parcelable
            return big;
        }
        /**
         * Calculate the top margin for the content in px, to allow enough space for the top line
         * above, using the given resource ID for the desired spacing.
         *
         * @hide
         */
        public static int getContentMarginTop(Context context, @DimenRes int spacingRes) {
            final Resources resources = context.getResources();
            // The margin above the text, at the top of the notification (originally in dp)
            int notifMargin = resources.getDimensionPixelSize(R.dimen.notification_2025_margin);
            // Spacing between the text lines, scaling with the font size (originally in sp)
            int spacing = resources.getDimensionPixelSize(spacingRes);
            // Size of the text in the notification top line (originally in sp)
            int[] textSizeAttr = new int[] { android.R.attr.textSize };
            TypedArray typedArray = context.obtainStyledAttributes(
                    R.style.TextAppearance_DeviceDefault_Notification_Info, textSizeAttr);
            int textSize = typedArray.getDimensionPixelSize(0 /* index */, -1 /* default */);
            typedArray.recycle();
            // Adding up all the values as pixels
            return notifMargin + spacing + textSize;
        }
        private boolean hasValidRemoteInput(Action action) {
            if (TextUtils.isEmpty(action.title) || action.actionIntent == null) {
                // Weird actions
+2 −1
Original line number Diff line number Diff line
@@ -40,13 +40,14 @@

            <include layout="@layout/notification_2025_template_header" />

            <!-- Note: the top margin is being set in code based on the estimated space needed for
            the header text. -->
            <LinearLayout
                android:id="@+id/notification_main_column"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/notification_2025_content_margin_start"
                android:layout_marginEnd="@dimen/notification_content_margin_end"
                android:layout_marginTop="@dimen/notification_content_margin_top"
                android:orientation="vertical"
                >

+2 −1
Original line number Diff line number Diff line
@@ -32,11 +32,12 @@
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="top"
        android:layout_marginTop="@dimen/notification_content_margin_top"
        android:clipToPadding="false"
        android:orientation="vertical"
        >

        <!-- Note: the top margin is being set in code based on the estimated space needed for
        the header text. -->
        <LinearLayout
            android:id="@+id/notification_main_column"
            android:layout_width="match_parent"
+2 −1
Original line number Diff line number Diff line
@@ -30,12 +30,13 @@
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:layout_marginTop="@dimen/notification_content_margin_top"
        android:layout_marginBottom="@dimen/notification_content_margin"
        android:clipToPadding="false"
        android:orientation="vertical"
        >

        <!-- Note: the top margin is being set in code based on the estimated space needed for
        the header text. -->
        <com.android.internal.widget.RemeasuringLinearLayout
            android:id="@+id/notification_main_column"
            android:layout_width="match_parent"
+1 −1
Original line number Diff line number Diff line
@@ -48,8 +48,8 @@
                android:id="@+id/notification_main_column"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_marginStart="@dimen/notification_2025_content_margin_start"
                android:layout_weight="1"
                android:orientation="vertical"
                android:minHeight="68dp"
                >
Loading