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

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

Merge "[Notif redesign] Remove space under header when hiding sender" into main

parents eb2e0cef 8d35ee10
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.internal.widget;

import static android.app.Flags.notificationsRedesignTemplates;

import android.annotation.AttrRes;
import android.annotation.IntDef;
import android.annotation.NonNull;
@@ -270,7 +272,7 @@ public class MessagingGroup extends NotificationOptimizedLinearLayout implements
    }

    private static int getMessagingGroupLayoutResource() {
        if (Flags.notificationsRedesignTemplates()) {
        if (notificationsRedesignTemplates()) {
            return R.layout.notification_2025_messaging_group;
        } else {
            return R.layout.notification_template_messaging_group;
@@ -433,6 +435,11 @@ public class MessagingGroup extends NotificationOptimizedLinearLayout implements
        }
    }

    /** Whether the sender name is hidden to avoid duplication with the header. */
    public boolean hasSenderNameHidden() {
        return mSenderView.getVisibility() == GONE;
    }

    /**
     * @param canHide true if the sender can be hidden if it is first
     */
@@ -450,7 +457,7 @@ public class MessagingGroup extends NotificationOptimizedLinearLayout implements
    }

    private void updateIconVisibility() {
        if (Flags.notificationsRedesignTemplates()) {
        if (notificationsRedesignTemplates()) {
            // We don't show any icon (other than the app or person icon) in the collapsed form.
            mMessagingIconContainer.setVisibility(mIsCollapsed ? GONE : VISIBLE);
        }
@@ -740,7 +747,7 @@ public class MessagingGroup extends NotificationOptimizedLinearLayout implements
        if (mIsInConversation != isInConversation) {
            mIsInConversation = isInConversation;

            if (Flags.notificationsRedesignTemplates()) {
            if (notificationsRedesignTemplates()) {
                updateIconVisibility();
                // No other alignment adjustments are necessary in the redesign, as the size of the
                // icons in both conversations and old messaging notifications are the same.
+32 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.internal.widget;

import static android.app.Flags.notificationsRedesignTemplates;
import static android.widget.flags.Flags.messagingChildRequestLayout;

import android.annotation.Nullable;
@@ -47,6 +48,14 @@ public class MessagingLinearLayout extends ViewGroup {
     */
    private int mSpacing;

    /**
     * Whether the top padding should be ignored when laying out the children. This is used when the
     * sender name of the top message is hidden due to it matching the name in the header, to avoid
     * duplication. By ignoring the padding, we bring the message up directly under the sender name
     * in the header.
     */
    private boolean mIgnorePaddingTop = false;

    private int mMaxDisplayedLines = Integer.MAX_VALUE;

    private static final boolean TRACE_ONMEASURE = Build.isDebuggable();
@@ -111,6 +120,7 @@ public class MessagingLinearLayout extends ViewGroup {
        // Starting from the bottom: we measure every view as if it were the only one. If it still
        // fits, we take it, otherwise we stop there.
        MessagingChild previousChild = null;
        MessagingChild firstVisibleChild = null;
        View previousView = null;
        int previousChildHeight = 0;
        int previousTotalHeight = 0;
@@ -125,6 +135,7 @@ public class MessagingLinearLayout extends ViewGroup {
            int spacing = mSpacing;
            int previousChildIncrease = 0;
            if (child instanceof MessagingChild) {
                firstVisibleChild = (MessagingChild) child;
                // We need to remeasure the previous child again if it's not the first anymore
                if (previousChild != null && previousChild.hasDifferentHeightWhenFirst()) {
                    previousChild.setIsFirstInLayout(false);
@@ -174,6 +185,7 @@ public class MessagingLinearLayout extends ViewGroup {
            } else {
                // We now became too short, let's make sure to reset any previous views to be first
                // and remeasure it.
                firstVisibleChild = previousChild;
                if (previousChild != null && previousChild.hasDifferentHeightWhenFirst()) {
                    previousChild.setIsFirstInLayout(true);
                    // We need to remeasure the previous child again since it became first
@@ -187,6 +199,7 @@ public class MessagingLinearLayout extends ViewGroup {
            first = false;
        }

        totalHeight = maybeRemoveTopPadding(totalHeight, firstVisibleChild);
        setMeasuredDimension(
                resolveSize(Math.max(getSuggestedMinimumWidth(), measuredWidth),
                        widthMeasureSpec),
@@ -196,6 +209,24 @@ public class MessagingLinearLayout extends ViewGroup {
        }
    }

    private int maybeRemoveTopPadding(int totalHeight, MessagingChild firstVisibleChild) {
        if (!notificationsRedesignTemplates()) {
            return totalHeight;
        }

        mIgnorePaddingTop = false;
        if (firstVisibleChild instanceof MessagingGroup messagingGroup) {
            // Note: The sender name can only be hidden if this is the first group.
            if (messagingGroup.hasSenderNameHidden()) {
                mIgnorePaddingTop = true;
            }
        }
        if (mIgnorePaddingTop) {
            totalHeight -= mPaddingTop;
        }
        return totalHeight;
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        final int paddingLeft = mPaddingLeft;
@@ -209,7 +240,7 @@ public class MessagingLinearLayout extends ViewGroup {
        final int layoutDirection = getLayoutDirection();
        final int count = getChildCount();

        childTop = mPaddingTop;
        childTop = mIgnorePaddingTop ? 0 : mPaddingTop;

        boolean first = true;
        final boolean shown = isShown();
+6 −1
Original line number Diff line number Diff line
@@ -50,12 +50,17 @@

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

            <!-- Using padding instead of margin so that we can allow the children to draw in that
            space. This is used when the sender name of the top message is hidden due to it matching
            the name in the header, to avoid duplication. By ignoring the padding, we bring the
            message up directly under the sender name in the header. -->
            <com.android.internal.widget.MessagingLinearLayout
                android:id="@+id/notification_messaging"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/notification_2025_margin"
                android:paddingTop="@dimen/notification_2025_margin"
                android:clipChildren="false"
                android:clipToPadding="false"
                android:spacing="@dimen/notification_2025_messaging_spacing" />
        </com.android.internal.widget.RemeasuringLinearLayout>