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

Commit 5c83fdf7 authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

[Notif redesign] Adjust spacing for messaging image

Adjust the spacing for the image shown in collapsed messaging
notifications to match the one for the large icon. Also adjust the
expander padding in the same way we do for the large icon.

Duplicated some logic from MessagingLayout into ConversationLayout for
consistency in hiding the large icon when the messaging icon is showing,
since we additionally need to make sure we avoid messing with the
margins when they've already been adjusted for the large icon.

Fix: 404557681
Test: manual
Flag: android.app.notifications_redesign_templates
Change-Id: I7c78a712be1e5e5a5e9279061d8ca9e305e3eaa7
parent bfe2c0c9
Loading
Loading
Loading
Loading
+32 −1
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.app.Person;
import android.app.RemoteInputHistoryItem;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
@@ -124,6 +125,7 @@ public class ConversationLayout extends FrameLayout
    private ViewGroup mExpandButtonContainerA11yContainer;
    private NotificationExpandButton mExpandButton;
    private MessagingLinearLayout mImageMessageContainer;
    private ImageView mRightIconView;
    private int mBadgeProtrusion;
    private int mConversationAvatarSize;
    private int mConversationAvatarSizeExpanded;
@@ -193,6 +195,7 @@ public class ConversationLayout extends FrameLayout
        mMessagingLinearLayout = findViewById(R.id.notification_messaging);
        mActions = findViewById(R.id.actions);
        mImageMessageContainer = findViewById(R.id.conversation_image_message_container);
        mRightIconView = findViewById(R.id.right_icon);
        // We still want to clip, but only on the top, since views can temporarily out of bounds
        // during transitions.
        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
@@ -734,13 +737,41 @@ public class ConversationLayout extends FrameLayout
        View newMessage = getNewImageMessage();
        // Remove all messages that don't belong into the image layout
        View previousMessage = mImageMessageContainer.getChildAt(0);
        boolean isShowingImage = newMessage != null;
        if (previousMessage != newMessage) {
            mImageMessageContainer.removeView(previousMessage);
            if (newMessage != null) {
            if (isShowingImage) {
                mImageMessageContainer.addView(newMessage);
            }
        }
        mImageMessageContainer.setVisibility(newMessage != null ? VISIBLE : GONE);

        if (mRightIconView != null && mRightIconView.getDrawable() != null) {
            // When showing an image message, do not show the large icon.  Removing the drawable
            // prevents it from being shown in the left_icon view (by the grouping util).
            if (notificationsRedesignTemplates() && isShowingImage) {
                mRightIconView.setImageDrawable(null);
                mRightIconView.setVisibility(GONE);
            }
        } else {
            // Only alter the padding if we're not showing the large icon; otherwise it's already
            // been adjusted in Notification.java and we shouldn't override it.
            adjustExpandButtonPadding(isShowingImage);
        }
    }

    /**
     * When showing an isolated image message similar to the large icon, adjust the padding of the
     * expand button in the same way we do for large icons.
     */
    private void adjustExpandButtonPadding(boolean isShowingImage) {
        if (notificationsRedesignTemplates() && mExpandButton != null) {
            final Resources res = mContext.getResources();
            int normalPadding = res.getDimensionPixelSize(R.dimen.notification_2025_margin);
            int iconSpacing = res.getDimensionPixelSize(
                    R.dimen.notification_2025_expand_button_right_icon_spacing);
            mExpandButton.setStartPadding(isShowingImage ? iconSpacing : normalPadding);
        }
    }

    @Nullable
+33 −7
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.internal.widget;

import static android.app.Flags.notificationsRedesignTemplates;

import static com.android.internal.widget.MessagingGroup.IMAGE_DISPLAY_LOCATION_EXTERNAL;
import static com.android.internal.widget.MessagingGroup.IMAGE_DISPLAY_LOCATION_INLINE;

@@ -27,6 +29,7 @@ import android.app.Notification;
import android.app.Person;
import android.app.RemoteInputHistoryItem;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.graphics.drawable.Icon;
import android.os.Bundle;
@@ -74,6 +77,7 @@ public class MessagingLayout extends FrameLayout
    private final ArrayList<MessagingGroup> mGroups = new ArrayList<>();
    private MessagingLinearLayout mImageMessageContainer;
    private ImageView mRightIconView;
    private NotificationExpandButton mExpandButton;
    private Rect mMessagingClipRect;
    private int mLayoutColor;
    private int mSenderTextColor;
@@ -115,6 +119,7 @@ public class MessagingLayout extends FrameLayout
        mMessagingLinearLayout = findViewById(R.id.notification_messaging);
        mImageMessageContainer = findViewById(R.id.conversation_image_message_container);
        mRightIconView = findViewById(R.id.right_icon);
        mExpandButton = findViewById(R.id.expand_button);
        // We still want to clip, but only on the top, since views can temporarily out of bounds
        // during transitions.
        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
@@ -349,20 +354,41 @@ public class MessagingLayout extends FrameLayout
        View newMessage = getNewImageMessage();
        // Remove all messages that don't belong into the image layout
        View previousMessage = mImageMessageContainer.getChildAt(0);
        boolean isShowingImage = newMessage != null;
        if (previousMessage != newMessage) {
            mImageMessageContainer.removeView(previousMessage);
            if (newMessage != null) {
            if (isShowingImage) {
                mImageMessageContainer.addView(newMessage);
            }
        }
        mImageMessageContainer.setVisibility(newMessage != null ? VISIBLE : GONE);
        mImageMessageContainer.setVisibility(isShowingImage ? VISIBLE : GONE);

        if (mRightIconView != null && mRightIconView.getDrawable() != null) {
            // When showing an image message, do not show the large icon.  Removing the drawable
            // prevents it from being shown in the left_icon view (by the grouping util).
        if (newMessage != null && mRightIconView != null && mRightIconView.getDrawable() != null) {
            if (isShowingImage) {
                mRightIconView.setImageDrawable(null);
                mRightIconView.setVisibility(GONE);
            }
        } else {
            // Only alter the padding if we're not showing the large icon; otherwise it's already
            // been adjusted in Notification.java and we shouldn't override it.
            adjustExpandButtonPadding(isShowingImage);
        }
    }

    /**
     * When showing an isolated image message similar to the large icon, adjust the padding of the
     * expand button in the same way we do for large icons.
     */
    private void adjustExpandButtonPadding(boolean isShowingImage) {
        if (notificationsRedesignTemplates() && mExpandButton != null) {
            final Resources res = mContext.getResources();
            int normalPadding = res.getDimensionPixelSize(R.dimen.notification_2025_margin);
            int iconSpacing = res.getDimensionPixelSize(
                    R.dimen.notification_2025_expand_button_right_icon_spacing);
            mExpandButton.setStartPadding(isShowingImage ? iconSpacing : normalPadding);
        }
    }

    @Nullable
+1 −1
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@
                    android:layout_width="@dimen/notification_right_icon_size"
                    android:layout_height="@dimen/notification_right_icon_size"
                    android:layout_gravity="center_vertical|end"
                    android:layout_marginTop="@dimen/notification_2025_margin"
                    android:layout_marginVertical="@dimen/notification_2025_right_icon_vertical_margin"
                    android:layout_marginStart="@dimen/notification_2025_right_icon_content_margin"
                    android:forceHasOverlappingRendering="false"
                    android:spacing="0dp"
+1 −1
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@
                    android:layout_width="@dimen/notification_right_icon_size"
                    android:layout_height="@dimen/notification_right_icon_size"
                    android:layout_gravity="center_vertical|end"
                    android:layout_marginTop="@dimen/notification_2025_margin"
                    android:layout_marginVertical="@dimen/notification_2025_right_icon_vertical_margin"
                    android:layout_marginStart="@dimen/notification_2025_right_icon_content_margin"
                    android:forceHasOverlappingRendering="false"
                    android:spacing="0dp"