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

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

Merge changes from topics "notif_redesign_conversations",...

Merge changes from topics "notif_redesign_conversations", "notif_redesign_legacy_msg_title" into main

* changes:
  [Notif redesign] Show title in legacy messaging notifs
  [Notif redesign] Update conversation layout
parents db002868 2f6cdb0d
Loading
Loading
Loading
Loading
+71 −29
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.app;
import static android.annotation.Dimension.DP;
import static android.app.Flags.evenlyDividedCallStyleActionLayout;
import static android.app.Flags.notificationsRedesignTemplates;
import static android.app.admin.DevicePolicyResources.Drawables.Source.NOTIFICATION;
import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_COLORED;
import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON;
@@ -818,7 +819,8 @@ public class Notification implements Parcelable
                     R.layout.notification_2025_template_expanded_base,
                     R.layout.notification_2025_template_heads_up_base,
                     R.layout.notification_2025_template_header,
                     R.layout.notification_2025_template_conversation,
                     R.layout.notification_2025_template_collapsed_conversation,
                     R.layout.notification_2025_template_expanded_conversation,
                     R.layout.notification_2025_template_collapsed_call,
                     R.layout.notification_2025_template_expanded_call,
                     R.layout.notification_2025_template_collapsed_messaging,
@@ -5963,7 +5965,8 @@ public class Notification implements Parcelable
                    || resId == getCompactHeadsUpBaseLayoutResource()
                    || resId == getMessagingCompactHeadsUpLayoutResource()
                    || resId == getCollapsedMessagingLayoutResource()
                    || resId == getCollapsedMediaLayoutResource());
                    || resId == getCollapsedMediaLayoutResource()
                    || resId == getCollapsedConversationLayoutResource());
            RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId);
            resetStandardTemplate(contentView);
@@ -6001,8 +6004,7 @@ public class Notification implements Parcelable
            // Update margins to leave space for the top line (but not for headerless views like
            // HUNS, which use a different layout that already accounts for that). Templates that
            // have content that will be displayed under the small icon also use a different margin.
            if (Flags.notificationsRedesignTemplates()
                    && !p.mHeaderless && !p.mSkipTopLineAlignment) {
            if (Flags.notificationsRedesignTemplates() && !p.mHeaderless) {
                int margin = getContentMarginTop(mContext,
                        R.dimen.notification_2025_content_margin_top);
                contentView.setViewLayoutMargin(R.id.notification_main_column,
@@ -7673,12 +7675,18 @@ public class Notification implements Parcelable
            }
        }
        // Note: In the 2025 redesign, we use two separate layouts for the collapsed and expanded
        //  version of conversations. See below.
        private int getConversationLayoutResource() {
            if (Flags.notificationsRedesignTemplates()) {
                return R.layout.notification_2025_template_conversation;
            } else {
            return R.layout.notification_template_material_conversation;
        }
        private int getCollapsedConversationLayoutResource() {
            return R.layout.notification_2025_template_collapsed_conversation;
        }
        private int getExpandedConversationLayoutResource() {
            return R.layout.notification_2025_template_expanded_conversation;
        }
        private int getCollapsedCallLayoutResource() {
@@ -9462,7 +9470,7 @@ public class Notification implements Parcelable
            boolean hideRightIcons = viewType != StandardTemplateParams.VIEW_TYPE_NORMAL;
            boolean isConversationLayout = mConversationType != CONVERSATION_TYPE_LEGACY;
            boolean isImportantConversation = mConversationType == CONVERSATION_TYPE_IMPORTANT;
            boolean isHeaderless = !isConversationLayout && isCollapsed;
            boolean isLegacyHeaderless = !isConversationLayout && isCollapsed;
            //TODO (b/217799515): ensure mConversationTitle always returns the correct
            // conversationTitle, probably set mConversationTitle = conversationTitle after this
@@ -9483,7 +9491,8 @@ public class Notification implements Parcelable
            } else {
                isOneToOne = !isGroupConversation();
            }
            if (isHeaderless && isOneToOne && TextUtils.isEmpty(conversationTitle)) {
            if ((isLegacyHeaderless || notificationsRedesignTemplates())
                    && isOneToOne && TextUtils.isEmpty(conversationTitle)) {
                conversationTitle = getOtherPersonName();
            }
@@ -9493,22 +9502,24 @@ public class Notification implements Parcelable
                    .viewType(viewType)
                    .highlightExpander(isConversationLayout)
                    .hideProgress(true)
                    .title(isHeaderless ? conversationTitle : null)
                    .text(null)
                    .hideLeftIcon(isOneToOne)
                    .hideRightIcon(hideRightIcons || isOneToOne)
                    .headerTextSecondary(isHeaderless ? null : conversationTitle)
                    .skipTopLineAlignment(true);
                    .hideRightIcon(hideRightIcons || isOneToOne);
            if (notificationsRedesignTemplates()) {
                p.title(conversationTitle)
                        .hideAppName(isCollapsed);
            } else {
                p.title(isLegacyHeaderless ? conversationTitle : null)
                        .headerTextSecondary(isLegacyHeaderless ? null : conversationTitle);
            }
            RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(
                    isConversationLayout
                            ? mBuilder.getConversationLayoutResource()
                            : isCollapsed
                                    ? mBuilder.getCollapsedMessagingLayoutResource()
                                    : mBuilder.getExpandedMessagingLayoutResource(),
                    getMessagingLayoutResource(isConversationLayout, isCollapsed),
                    p,
                    bindResult);
            if (isConversationLayout) {
            if (isConversationLayout && !notificationsRedesignTemplates()) {
                // Redesign note: This view is replaced by the `title`, which is handled normally.
                mBuilder.setTextViewColorPrimary(contentView, R.id.conversation_text, p);
                // Redesign note: This special divider is no longer needed.
                mBuilder.setTextViewColorSecondary(contentView, R.id.app_name_divider, p);
            }
@@ -9538,7 +9549,18 @@ public class Notification implements Parcelable
                contentView.setBoolean(R.id.status_bar_latest_event_content,
                        "setIsImportantConversation", isImportantConversation);
            }
            if (isHeaderless) {
            if (notificationsRedesignTemplates() && !isCollapsed) {
                // Align the title to the app/small icon in the expanded form. In other layouts,
                // this margin is added directly to the notification_main_column parent, but for
                // messages we don't want the margin to be applied to the actual messaging
                // content since it can contain icons that are displayed below the app icon.
                Resources res = mBuilder.mContext.getResources();
                int marginStart = res.getDimensionPixelSize(
                        R.dimen.notification_2025_content_margin_start);
                contentView.setViewLayoutMargin(R.id.title,
                        RemoteViews.MARGIN_START, marginStart, TypedValue.COMPLEX_UNIT_PX);
            }
            if (isLegacyHeaderless) {
                // Collapsed legacy messaging style has a 1-line limit.
                contentView.setInt(R.id.notification_messaging, "setMaxDisplayedLines", 1);
            }
@@ -9549,6 +9571,33 @@ public class Notification implements Parcelable
            return contentView;
        }
        private int getMessagingLayoutResource(boolean isConversationLayout, boolean isCollapsed) {
            if (notificationsRedesignTemplates()) {
                // Note: We eventually would like to use the same layouts for both conversations and
                //  regular messaging notifications.
                if (isConversationLayout) {
                    if (isCollapsed) {
                        return mBuilder.getCollapsedConversationLayoutResource();
                    } else {
                        return mBuilder.getExpandedConversationLayoutResource();
                    }
                } else {
                    if (isCollapsed) {
                        return mBuilder.getCollapsedMessagingLayoutResource();
                    } else {
                        return mBuilder.getExpandedMessagingLayoutResource();
                    }
                }
            } else {
                return isConversationLayout
                        ? mBuilder.getConversationLayoutResource()
                        : isCollapsed
                                ? mBuilder.getCollapsedMessagingLayoutResource()
                                : mBuilder.getExpandedMessagingLayoutResource();
            }
        }
        private CharSequence getKey(Person person) {
            return person == null ? null
                    : person.getKey() == null ? person.getName() : person.getKey();
@@ -14676,7 +14725,6 @@ public class Notification implements Parcelable
        Icon mPromotedPicture;
        boolean mCallStyleActions;
        boolean mAllowTextWithProgress;
        boolean mSkipTopLineAlignment;
        int mTitleViewId;
        int mTextViewId;
        @Nullable CharSequence mTitle;
@@ -14702,7 +14750,6 @@ public class Notification implements Parcelable
            mPromotedPicture = null;
            mCallStyleActions = false;
            mAllowTextWithProgress = false;
            mSkipTopLineAlignment = false;
            mTitleViewId = R.id.title;
            mTextViewId = R.id.text;
            mTitle = null;
@@ -14769,11 +14816,6 @@ public class Notification implements Parcelable
            return this;
        }
        public StandardTemplateParams skipTopLineAlignment(boolean skipTopLineAlignment) {
            mSkipTopLineAlignment = skipTopLineAlignment;
            return this;
        }
        final StandardTemplateParams hideSnoozeButton(boolean hideSnoozeButton) {
            this.mHideSnoozeButton = hideSnoozeButton;
            return this;
+43 −11
Original line number Diff line number Diff line
@@ -250,7 +250,8 @@ public class ConversationLayout extends FrameLayout
            mPeopleHelper.animateViewForceHidden(mImportanceRingView, forceHidden);
            mPeopleHelper.animateViewForceHidden(mIcon, forceHidden);
        });
        mConversationText = findViewById(R.id.conversation_text);
        mConversationText = findViewById(notificationsRedesignTemplates()
                ? R.id.title : R.id.conversation_text);
        mExpandButtonContainer = findViewById(R.id.expand_button_container);
        mExpandButtonContainerA11yContainer =
                findViewById(R.id.expand_button_a11y_container);
@@ -716,17 +717,10 @@ public class ConversationLayout extends FrameLayout
    }

    private void updateImageMessages() {
        View newMessage = null;
        if (mIsCollapsed && !mGroups.isEmpty()) {

            // When collapsed, we're displaying the image message in a dedicated container
            // on the right of the layout instead of inline. Let's add the isolated image there
            MessagingGroup messagingGroup = mGroups.getLast();
            MessagingImageMessage isolatedMessage = messagingGroup.getIsolatedMessage();
            if (isolatedMessage != null) {
                newMessage = isolatedMessage.getView();
            }
        if (mImageMessageContainer == null) {
            return;
        }
        View newMessage = getNewImageMessage();
        // Remove all messages that don't belong into the image layout
        View previousMessage = mImageMessageContainer.getChildAt(0);
        if (previousMessage != newMessage) {
@@ -738,6 +732,20 @@ public class ConversationLayout extends FrameLayout
        mImageMessageContainer.setVisibility(newMessage != null ? VISIBLE : GONE);
    }

    @Nullable
    private View getNewImageMessage() {
        if (mIsCollapsed && !mGroups.isEmpty()) {
            // When collapsed, we're displaying the image message in a dedicated container
            // on the right of the layout instead of inline. Let's add the isolated image there
            MessagingGroup messagingGroup = mGroups.getLast();
            MessagingImageMessage isolatedMessage = messagingGroup.getIsolatedMessage();
            if (isolatedMessage != null) {
                return isolatedMessage.getView();
            }
        }
        return null;
    }

    public void bindFacePile(ImageView bottomBackground, ImageView bottomView, ImageView topView) {
        applyNotificationBackgroundColor(bottomBackground);
        // Let's find the two last conversations:
@@ -841,6 +849,10 @@ public class ConversationLayout extends FrameLayout
    }

    private void updateAppName() {
        if (notificationsRedesignTemplates()) {
            return;
        }

        mAppName.setVisibility(mIsCollapsed ? GONE : VISIBLE);
    }

@@ -1533,6 +1545,10 @@ public class ConversationLayout extends FrameLayout
    }

    private void updateExpandButton() {
        if (notificationsRedesignTemplates()) {
            return;
        }

        int buttonGravity;
        ViewGroup newContainer;
        if (mIsCollapsed) {
@@ -1565,6 +1581,10 @@ public class ConversationLayout extends FrameLayout
    }

    private void updateContentEndPaddings() {
        if (notificationsRedesignTemplates()) {
            return;
        }

        // Let's make sure the conversation header can't run into the expand button when we're
        // collapsed and update the paddings of the content
        int headerPaddingEnd;
@@ -1593,6 +1613,10 @@ public class ConversationLayout extends FrameLayout
    }

    private void onAppNameVisibilityChanged() {
        if (notificationsRedesignTemplates()) {
            return;
        }

        boolean appNameGone = mAppName.getVisibility() == GONE;
        if (appNameGone != mAppNameGone) {
            mAppNameGone = appNameGone;
@@ -1601,10 +1625,18 @@ public class ConversationLayout extends FrameLayout
    }

    private void updateAppNameDividerVisibility() {
        if (notificationsRedesignTemplates()) {
            return;
        }

        mAppNameDivider.setVisibility(mAppNameGone ? GONE : VISIBLE);
    }

    public void updateExpandability(boolean expandable, @Nullable OnClickListener onClickListener) {
        if (notificationsRedesignTemplates()) {
            return;
        }

        mExpandable = expandable;
        if (expandable) {
            mExpandButtonContainer.setVisibility(VISIBLE);
+2 −6
Original line number Diff line number Diff line
@@ -449,12 +449,8 @@ public class MessagingGroup extends NotificationOptimizedLinearLayout implements
    }

    private void updateIconVisibility() {
        if (Flags.notificationsRedesignTemplates() && !mIsInConversation) {
            // We don't show any icon (other than the app icon) in the collapsed form. For
            // conversations, keeping this container helps with aligning the message to the icon
            // when collapsed, but the old messaging style already has this alignment built into
            // the template like all other layouts. Conversations are special because we use the
            // same base layout for both the collapsed and expanded views.
        if (Flags.notificationsRedesignTemplates()) {
            // We don't show any icon (other than the app or person icon) in the collapsed form.
            mMessagingIconContainer.setVisibility(mSingleLine ? GONE : VISIBLE);
        }
    }
+15 −10
Original line number Diff line number Diff line
@@ -337,19 +337,10 @@ public class MessagingLayout extends FrameLayout
    }

    private void updateImageMessages() {
        View newMessage = null;
        if (mImageMessageContainer == null) {
            return;
        }
        if (mIsCollapsed && !mGroups.isEmpty()) {
            // When collapsed, we're displaying the image message in a dedicated container
            // on the right of the layout instead of inline. Let's add the isolated image there
            MessagingGroup messagingGroup = mGroups.getLast();
            MessagingImageMessage isolatedMessage = messagingGroup.getIsolatedMessage();
            if (isolatedMessage != null) {
                newMessage = isolatedMessage.getView();
            }
        }
        View newMessage = getNewImageMessage();
        // Remove all messages that don't belong into the image layout
        View previousMessage = mImageMessageContainer.getChildAt(0);
        if (previousMessage != newMessage) {
@@ -368,6 +359,20 @@ public class MessagingLayout extends FrameLayout
        }
    }

    @Nullable
    private View getNewImageMessage() {
        if (mIsCollapsed && !mGroups.isEmpty()) {
            // When collapsed, we're displaying the image message in a dedicated container
            // on the right of the layout instead of inline. Let's add the isolated image there
            MessagingGroup messagingGroup = mGroups.getLast();
            MessagingImageMessage isolatedMessage = messagingGroup.getIsolatedMessage();
            if (isolatedMessage != null) {
                return isolatedMessage.getView();
            }
        }
        return null;
    }

    private void removeGroups(ArrayList<MessagingGroup> oldGroups) {
        int size = oldGroups.size();
        for (int i = 0; i < size; i++) {
+53 −136

File changed.

Preview size limit exceeded, changes collapsed.

Loading