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

Commit 20d1ee24 authored by Selim Cinek's avatar Selim Cinek
Browse files

Baseline for the new ConversationLayout

Introduced a new Layout for Conversation Notifications.
There are still various open issues that will be
fixed in follow up Cls

Bug: 150905003
Test: Add conversations, obverve visuals
Change-Id: I8ab2e2988d3205a4491006df68ec14235109466f
parent dd2bd910
Loading
Loading
Loading
Loading
+18 −11
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.graphics.drawable.Icon.TYPE_URI;
import static android.graphics.drawable.Icon.TYPE_URI_ADAPTIVE_BITMAP;
import static android.graphics.drawable.Icon.TYPE_URI_ADAPTIVE_BITMAP;


import static com.android.internal.util.ContrastColorUtil.satisfiesTextContrast;
import static com.android.internal.util.ContrastColorUtil.satisfiesTextContrast;
import static com.android.internal.widget.ConversationLayout.CONVERSATION_LAYOUT_ENABLED;


import android.annotation.ColorInt;
import android.annotation.ColorInt;
import android.annotation.DimenRes;
import android.annotation.DimenRes;
@@ -389,6 +390,7 @@ public class Notification implements Parcelable
        STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_text);
        STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_text);
        STANDARD_LAYOUTS.add(R.layout.notification_template_material_inbox);
        STANDARD_LAYOUTS.add(R.layout.notification_template_material_inbox);
        STANDARD_LAYOUTS.add(R.layout.notification_template_material_messaging);
        STANDARD_LAYOUTS.add(R.layout.notification_template_material_messaging);
        STANDARD_LAYOUTS.add(R.layout.notification_template_material_conversation);
        STANDARD_LAYOUTS.add(R.layout.notification_template_material_media);
        STANDARD_LAYOUTS.add(R.layout.notification_template_material_media);
        STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_media);
        STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_media);
        STANDARD_LAYOUTS.add(R.layout.notification_template_header);
        STANDARD_LAYOUTS.add(R.layout.notification_template_header);
@@ -5138,7 +5140,7 @@ public class Notification implements Parcelable
            int color = isColorized(p) ? getPrimaryTextColor(p) : getSecondaryTextColor(p);
            int color = isColorized(p) ? getPrimaryTextColor(p) : getSecondaryTextColor(p);
            contentView.setDrawableTint(R.id.expand_button, false, color,
            contentView.setDrawableTint(R.id.expand_button, false, color,
                    PorterDuff.Mode.SRC_ATOP);
                    PorterDuff.Mode.SRC_ATOP);
            contentView.setInt(R.id.notification_header, "setOriginalNotificationColor",
            contentView.setInt(R.id.expand_button, "setOriginalNotificationColor",
                    color);
                    color);
        }
        }


@@ -6116,7 +6118,9 @@ public class Notification implements Parcelable
        }
        }


        private int getMessagingLayoutResource() {
        private int getMessagingLayoutResource() {
            return R.layout.notification_template_material_messaging;
            return CONVERSATION_LAYOUT_ENABLED
                    ? R.layout.notification_template_material_conversation
                    : R.layout.notification_template_material_messaging;
        }
        }


        private int getActionLayoutResource() {
        private int getActionLayoutResource() {
@@ -7379,7 +7383,7 @@ public class Notification implements Parcelable
        public RemoteViews makeContentView(boolean increasedHeight) {
        public RemoteViews makeContentView(boolean increasedHeight) {
            mBuilder.mOriginalActions = mBuilder.mActions;
            mBuilder.mOriginalActions = mBuilder.mActions;
            mBuilder.mActions = new ArrayList<>();
            mBuilder.mActions = new ArrayList<>();
            RemoteViews remoteViews = makeMessagingView(true /* displayImagesAtEnd */,
            RemoteViews remoteViews = makeMessagingView(true /* isCollapsed */,
                    false /* hideLargeIcon */);
                    false /* hideLargeIcon */);
            mBuilder.mActions = mBuilder.mOriginalActions;
            mBuilder.mActions = mBuilder.mOriginalActions;
            mBuilder.mOriginalActions = null;
            mBuilder.mOriginalActions = null;
@@ -7469,19 +7473,18 @@ public class Notification implements Parcelable
         */
         */
        @Override
        @Override
        public RemoteViews makeBigContentView() {
        public RemoteViews makeBigContentView() {
            return makeMessagingView(false /* displayImagesAtEnd */, true /* hideLargeIcon */);
            return makeMessagingView(false /* isCollapsed */, true /* hideLargeIcon */);
        }
        }


        /**
        /**
         * Create a messaging layout.
         * Create a messaging layout.
         *
         *
         * @param displayImagesAtEnd should images be displayed at the end of the content instead
         * @param isCollapsed Should this use the collapsed layout
         *                           of inline.
         * @param hideRightIcons Should the reply affordance be shown at the end of the notification
         * @param hideRightIcons Should the reply affordance be shown at the end of the notification
         * @return the created remoteView.
         * @return the created remoteView.
         */
         */
        @NonNull
        @NonNull
        private RemoteViews makeMessagingView(boolean displayImagesAtEnd, boolean hideRightIcons) {
        private RemoteViews makeMessagingView(boolean isCollapsed, boolean hideRightIcons) {
            CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle)
            CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle)
                    ? super.mBigContentTitle
                    ? super.mBigContentTitle
                    : mConversationTitle;
                    : mConversationTitle;
@@ -7522,14 +7525,16 @@ public class Notification implements Parcelable
                    mBuilder.getPrimaryTextColor(p));
                    mBuilder.getPrimaryTextColor(p));
            contentView.setInt(R.id.status_bar_latest_event_content, "setMessageTextColor",
            contentView.setInt(R.id.status_bar_latest_event_content, "setMessageTextColor",
                    mBuilder.getSecondaryTextColor(p));
                    mBuilder.getSecondaryTextColor(p));
            contentView.setBoolean(R.id.status_bar_latest_event_content, "setDisplayImagesAtEnd",
            contentView.setBoolean(R.id.status_bar_latest_event_content, "setIsCollapsed",
                    displayImagesAtEnd);
                    isCollapsed);
            contentView.setIcon(R.id.status_bar_latest_event_content, "setAvatarReplacement",
            contentView.setIcon(R.id.status_bar_latest_event_content, "setAvatarReplacement",
                    avatarReplacement);
                    avatarReplacement);
            contentView.setCharSequence(R.id.status_bar_latest_event_content, "setNameReplacement",
            contentView.setCharSequence(R.id.status_bar_latest_event_content, "setNameReplacement",
                    nameReplacement);
                    nameReplacement);
            contentView.setBoolean(R.id.status_bar_latest_event_content, "setIsOneToOne",
            contentView.setBoolean(R.id.status_bar_latest_event_content, "setIsOneToOne",
                    isOneToOne);
                    isOneToOne);
            contentView.setIcon(R.id.status_bar_latest_event_content, "setLargeIcon",
                    mBuilder.mN.mLargeIcon);
            contentView.setBundle(R.id.status_bar_latest_event_content, "setData",
            contentView.setBundle(R.id.status_bar_latest_event_content, "setData",
                    mBuilder.mN.extras);
                    mBuilder.mN.extras);
            return contentView;
            return contentView;
@@ -7590,9 +7595,11 @@ public class Notification implements Parcelable
         */
         */
        @Override
        @Override
        public RemoteViews makeHeadsUpContentView(boolean increasedHeight) {
        public RemoteViews makeHeadsUpContentView(boolean increasedHeight) {
            RemoteViews remoteViews = makeMessagingView(true /* displayImagesAtEnd */,
            RemoteViews remoteViews = makeMessagingView(true /* isCollapsed */,
                    true /* hideLargeIcon */);
                    true /* hideLargeIcon */);
            if (!CONVERSATION_LAYOUT_ENABLED) {
                remoteViews.setInt(R.id.notification_messaging, "setMaxDisplayedLines", 1);
                remoteViews.setInt(R.id.notification_messaging, "setMaxDisplayedLines", 1);
            }
            return remoteViews;
            return remoteViews;
        }
        }


+4 −9
Original line number Original line Diff line number Diff line
@@ -35,6 +35,7 @@ import android.widget.RemoteViews;


import com.android.internal.R;
import com.android.internal.R;
import com.android.internal.widget.CachingIconView;
import com.android.internal.widget.CachingIconView;
import com.android.internal.widget.NotificationExpandButton;


import java.util.ArrayList;
import java.util.ArrayList;


@@ -56,7 +57,7 @@ public class NotificationHeaderView extends ViewGroup {
    private OnClickListener mAppOpsListener;
    private OnClickListener mAppOpsListener;
    private HeaderTouchListener mTouchListener = new HeaderTouchListener();
    private HeaderTouchListener mTouchListener = new HeaderTouchListener();
    private LinearLayout mTransferChip;
    private LinearLayout mTransferChip;
    private ImageView mExpandButton;
    private NotificationExpandButton mExpandButton;
    private CachingIconView mIcon;
    private CachingIconView mIcon;
    private View mProfileBadge;
    private View mProfileBadge;
    private View mOverlayIcon;
    private View mOverlayIcon;
@@ -65,7 +66,6 @@ public class NotificationHeaderView extends ViewGroup {
    private View mAppOps;
    private View mAppOps;
    private View mAudiblyAlertedIcon;
    private View mAudiblyAlertedIcon;
    private int mIconColor;
    private int mIconColor;
    private int mOriginalNotificationColor;
    private boolean mExpanded;
    private boolean mExpanded;
    private boolean mShowExpandButtonAtEnd;
    private boolean mShowExpandButtonAtEnd;
    private boolean mShowWorkBadgeAtEnd;
    private boolean mShowWorkBadgeAtEnd;
@@ -324,13 +324,8 @@ public class NotificationHeaderView extends ViewGroup {
        return mIconColor;
        return mIconColor;
    }
    }


    @RemotableViewMethod
    public void setOriginalNotificationColor(int color) {
        mOriginalNotificationColor = color;
    }

    public int getOriginalNotificationColor() {
    public int getOriginalNotificationColor() {
        return mOriginalNotificationColor;
        return mExpandButton.getOriginalNotificationColor();
    }
    }


    @RemotableViewMethod
    @RemotableViewMethod
@@ -371,7 +366,7 @@ public class NotificationHeaderView extends ViewGroup {
            contentDescriptionId = R.string.expand_button_content_description_collapsed;
            contentDescriptionId = R.string.expand_button_content_description_collapsed;
        }
        }
        mExpandButton.setImageDrawable(getContext().getDrawable(drawableId));
        mExpandButton.setImageDrawable(getContext().getDrawable(drawableId));
        mExpandButton.setColorFilter(mOriginalNotificationColor);
        mExpandButton.setColorFilter(getOriginalNotificationColor());
        mExpandButton.setContentDescription(mContext.getText(contentDescriptionId));
        mExpandButton.setContentDescription(mContext.getText(contentDescriptionId));
    }
    }


+728 −0

File added.

Preview size limit exceeded, changes collapsed.

+42 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.internal.widget;

import android.content.Context;

import java.util.ArrayList;

/**
 * An interface for a MessagingLayout
 */
public interface IMessagingLayout {

    /**
     * @return the layout containing the messages
     */
    MessagingLinearLayout getMessagingLinearLayout();

    /**
     * @return the context of this view
     */
    Context getContext();

    /**
     * @return the list of messaging groups
     */
    ArrayList<MessagingGroup> getMessagingGroups();
}
+76 −18
Original line number Original line Diff line number Diff line
@@ -55,8 +55,9 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
    private static Pools.SimplePool<MessagingGroup> sInstancePool
    private static Pools.SimplePool<MessagingGroup> sInstancePool
            = new Pools.SynchronizedPool<>(10);
            = new Pools.SynchronizedPool<>(10);
    private MessagingLinearLayout mMessageContainer;
    private MessagingLinearLayout mMessageContainer;
    private ImageFloatingTextView mSenderName;
    ImageFloatingTextView mSenderView;
    private ImageView mAvatarView;
    private ImageView mAvatarView;
    private View mAvatarContainer;
    private String mAvatarSymbol = "";
    private String mAvatarSymbol = "";
    private int mLayoutColor;
    private int mLayoutColor;
    private CharSequence mAvatarName = "";
    private CharSequence mAvatarName = "";
@@ -76,6 +77,12 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
    private Point mDisplaySize = new Point();
    private Point mDisplaySize = new Point();
    private ProgressBar mSendingSpinner;
    private ProgressBar mSendingSpinner;
    private View mSendingSpinnerContainer;
    private View mSendingSpinnerContainer;
    private boolean mShowingAvatar = true;
    private CharSequence mSenderName;
    private boolean mSingleLine = false;
    private LinearLayout mContentContainer;
    private int mRequestedMaxDisplayedLines = Integer.MAX_VALUE;
    private int mSenderTextPaddingSingleLine;


    public MessagingGroup(@NonNull Context context) {
    public MessagingGroup(@NonNull Context context) {
        super(context);
        super(context);
@@ -99,26 +106,34 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
    protected void onFinishInflate() {
    protected void onFinishInflate() {
        super.onFinishInflate();
        super.onFinishInflate();
        mMessageContainer = findViewById(R.id.group_message_container);
        mMessageContainer = findViewById(R.id.group_message_container);
        mSenderName = findViewById(R.id.message_name);
        mSenderView = findViewById(R.id.message_name);
        mAvatarView = findViewById(R.id.message_icon);
        mAvatarView = findViewById(R.id.message_icon);
        mImageContainer = findViewById(R.id.messaging_group_icon_container);
        mImageContainer = findViewById(R.id.messaging_group_icon_container);
        mSendingSpinner = findViewById(R.id.messaging_group_sending_progress);
        mSendingSpinner = findViewById(R.id.messaging_group_sending_progress);
        mContentContainer = findViewById(R.id.messaging_group_content_container);
        mSendingSpinnerContainer = findViewById(R.id.messaging_group_sending_progress_container);
        mSendingSpinnerContainer = findViewById(R.id.messaging_group_sending_progress_container);
        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
        mDisplaySize.x = displayMetrics.widthPixels;
        mDisplaySize.x = displayMetrics.widthPixels;
        mDisplaySize.y = displayMetrics.heightPixels;
        mDisplaySize.y = displayMetrics.heightPixels;
        mSenderTextPaddingSingleLine = getResources().getDimensionPixelSize(
                R.dimen.messaging_group_singleline_sender_padding_end);
    }
    }


    public void updateClipRect() {
    public void updateClipRect() {
        // We want to clip to the senderName if it's available, otherwise our images will come
        // We want to clip to the senderName if it's available, otherwise our images will come
        // from a weird position
        // from a weird position
        Rect clipRect;
        Rect clipRect;
        if (mSenderName.getVisibility() != View.GONE && !mTransformingImages) {
        if (mSenderView.getVisibility() != View.GONE && !mTransformingImages) {
            ViewGroup parent = (ViewGroup) mSenderName.getParent();
            int top;
            int top = getDistanceFromParent(mSenderName, parent) - getDistanceFromParent(
            if (mSingleLine) {
                    mMessageContainer, parent) + mSenderName.getHeight();
                top = 0;
            } else {
                top = getDistanceFromParent(mSenderView, mContentContainer)
                        - getDistanceFromParent(mMessageContainer, mContentContainer)
                        + mSenderView.getHeight();
            }
            int size = Math.max(mDisplaySize.x, mDisplaySize.y);
            int size = Math.max(mDisplaySize.x, mDisplaySize.y);
            clipRect = new Rect(0, top, size, size);
            clipRect = new Rect(-size, top, size, size);
        } else {
        } else {
            clipRect = null;
            clipRect = null;
        }
        }
@@ -140,17 +155,27 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
        if (nameOverride == null) {
        if (nameOverride == null) {
            nameOverride = sender.getName();
            nameOverride = sender.getName();
        }
        }
        mSenderName.setText(nameOverride);
        mSenderName = nameOverride;
        mSenderView.setText(nameOverride);
        mNeedsGeneratedAvatar = sender.getIcon() == null;
        mNeedsGeneratedAvatar = sender.getIcon() == null;
        if (!mNeedsGeneratedAvatar) {
        if (!mNeedsGeneratedAvatar) {
            setAvatar(sender.getIcon());
            setAvatar(sender.getIcon());
        }
        }
        mAvatarView.setVisibility(VISIBLE);
        mSenderView.setVisibility(TextUtils.isEmpty(nameOverride) ? GONE : VISIBLE);
        mSenderName.setVisibility(TextUtils.isEmpty(nameOverride) ? GONE : VISIBLE);
    }

    /**
     * Should the avatar be shown for this view.
     *
     * @param showingAvatar should it be shown
     */
    public void setShowingAvatar(boolean showingAvatar) {
        mAvatarView.setVisibility(showingAvatar ? VISIBLE : GONE);
        mShowingAvatar = showingAvatar;
    }
    }


    public void setSending(boolean sending) {
    public void setSending(boolean sending) {
        int visibility = sending ? View.VISIBLE : View.GONE;
        int visibility = sending ? VISIBLE : GONE;
        if (mSendingSpinnerContainer.getVisibility() != visibility) {
        if (mSendingSpinnerContainer.getVisibility() != visibility) {
            mSendingSpinnerContainer.setVisibility(visibility);
            mSendingSpinnerContainer.setVisibility(visibility);
            updateMessageColor();
            updateMessageColor();
@@ -171,7 +196,9 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou


    public void setAvatar(Icon icon) {
    public void setAvatar(Icon icon) {
        mAvatarIcon = icon;
        mAvatarIcon = icon;
        if (mShowingAvatar || icon == null) {
            mAvatarView.setImageIcon(icon);
            mAvatarView.setImageIcon(icon);
        }
        mAvatarSymbol = "";
        mAvatarSymbol = "";
        mAvatarName = "";
        mAvatarName = "";
    }
    }
@@ -220,13 +247,17 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
        setAvatar(null);
        setAvatar(null);
        mAvatarView.setAlpha(1.0f);
        mAvatarView.setAlpha(1.0f);
        mAvatarView.setTranslationY(0.0f);
        mAvatarView.setTranslationY(0.0f);
        mSenderName.setAlpha(1.0f);
        mSenderView.setAlpha(1.0f);
        mSenderName.setTranslationY(0.0f);
        mSenderView.setTranslationY(0.0f);
        setAlpha(1.0f);
        setAlpha(1.0f);
        mIsolatedMessage = null;
        mIsolatedMessage = null;
        mMessages = null;
        mMessages = null;
        mSenderName = null;
        mAddedMessages.clear();
        mAddedMessages.clear();
        mFirstLayout = true;
        mFirstLayout = true;
        setMaxDisplayedLines(Integer.MAX_VALUE);
        setSingleLine(false);
        setShowingAvatar(true);
        MessagingPropertyAnimator.recycle(this);
        MessagingPropertyAnimator.recycle(this);
        sInstancePool.release(MessagingGroup.this);
        sInstancePool.release(MessagingGroup.this);
    }
    }
@@ -252,7 +283,7 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
    }
    }


    public CharSequence getSenderName() {
    public CharSequence getSenderName() {
        return mSenderName.getText();
        return mSenderName;
    }
    }


    public static void dropCache() {
    public static void dropCache() {
@@ -310,7 +341,12 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou


    @Override
    @Override
    public void setMaxDisplayedLines(int lines) {
    public void setMaxDisplayedLines(int lines) {
        mMessageContainer.setMaxDisplayedLines(lines);
        mRequestedMaxDisplayedLines = lines;
        updateMaxDisplayedLines();
    }

    private void updateMaxDisplayedLines() {
        mMessageContainer.setMaxDisplayedLines(mSingleLine ? 1 : mRequestedMaxDisplayedLines);
    }
    }


    @Override
    @Override
@@ -362,7 +398,7 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
        mTextColor = messageTextColor;
        mTextColor = messageTextColor;
        mSendingTextColor = calculateSendingTextColor();
        mSendingTextColor = calculateSendingTextColor();
        updateMessageColor();
        updateMessageColor();
        mSenderName.setTextColor(senderTextColor);
        mSenderView.setTextColor(senderTextColor);
    }
    }


    public void setLayoutColor(int layoutColor) {
    public void setLayoutColor(int layoutColor) {
@@ -506,13 +542,17 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
    }
    }


    public View getSenderView() {
    public View getSenderView() {
        return mSenderName;
        return mSenderView;
    }
    }


    public View getAvatar() {
    public View getAvatar() {
        return mAvatarView;
        return mAvatarView;
    }
    }


    public Icon getAvatarIcon() {
        return mAvatarIcon;
    }

    public MessagingLinearLayout getMessageContainer() {
    public MessagingLinearLayout getMessageContainer() {
        return mMessageContainer;
        return mMessageContainer;
    }
    }
@@ -543,4 +583,22 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
    public List<MessagingMessage> getMessages() {
    public List<MessagingMessage> getMessages() {
        return mMessages;
        return mMessages;
    }
    }

    /**
     * Set this layout to be single line and therefore displaying both the sender and the text on
     * the same line.
     *
     * @param singleLine should be layout be single line
     */
    public void setSingleLine(boolean singleLine) {
        if (singleLine != mSingleLine) {
            mSingleLine = singleLine;
            mContentContainer.setOrientation(
                    singleLine ? LinearLayout.HORIZONTAL : LinearLayout.VERTICAL);
            MarginLayoutParams layoutParams = (MarginLayoutParams) mSenderView.getLayoutParams();
            layoutParams.setMarginEnd(singleLine ? mSenderTextPaddingSingleLine : 0);
            updateMaxDisplayedLines();
            updateClipRect();
        }
    }
}
}
Loading