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

Commit c4e19963 authored by Selim Cinek's avatar Selim Cinek Committed by Android (Google) Code Review
Browse files

Merge "Fixed the behavior of group conversations when targeting P" into pi-dev

parents 3d70d20c ce8794fb
Loading
Loading
Loading
Loading
+38 −16
Original line number Original line Diff line number Diff line
@@ -6601,22 +6601,33 @@ public class Notification implements Parcelable
     * Helper class for generating large-format notifications that include multiple back-and-forth
     * Helper class for generating large-format notifications that include multiple back-and-forth
     * messages of varying types between any number of people.
     * messages of varying types between any number of people.
     *
     *
     * <br>
     * <p>
     * If the platform does not provide large-format notifications, this method has no effect. The
     * If the platform does not provide large-format notifications, this method has no effect. The
     * user will always see the normal notification view.
     * user will always see the normal notification view.
     * <br>
     *
     * This class is a "rebuilder": It attaches to a Builder object and modifies its behavior, like
     * <p>
     * so:
     * If the app is targeting Android P and above, it is required to use the {@link Person}
     * class in order to get an optimal rendering of the notification and its avatars. For
     * conversations involving multiple people, the app should also make sure that it marks the
     * conversation as a group with {@link #setGroupConversation(boolean)}.
     *
     * <p>
     * This class is a "rebuilder": It attaches to a Builder object and modifies its behavior.
     * Here's an example of how this may be used:
     * <pre class="prettyprint">
     * <pre class="prettyprint">
     *
     *
     * Person user = new Person.Builder().setIcon(userIcon).setName(userName).build();
     * MessagingStyle style = new MessagingStyle(user)
     *      .addMessage(messages[1].getText(), messages[1].getTime(), messages[1].getPerson())
     *      .addMessage(messages[2].getText(), messages[2].getTime(), messages[2].getPerson())
     *      .setGroupConversation(hasMultiplePeople());
     *
     * Notification noti = new Notification.Builder()
     * Notification noti = new Notification.Builder()
     *     .setContentTitle(&quot;2 new messages wtih &quot; + sender.toString())
     *     .setContentTitle(&quot;2 new messages with &quot; + sender.toString())
     *     .setContentText(subject)
     *     .setContentText(subject)
     *     .setSmallIcon(R.drawable.new_message)
     *     .setSmallIcon(R.drawable.new_message)
     *     .setLargeIcon(aBitmap)
     *     .setLargeIcon(aBitmap)
     *     .setStyle(new Notification.MessagingStyle(resources.getString(R.string.reply_name))
     *     .setStyle(style)
     *         .addMessage(messages[0].getText(), messages[0].getTime(), messages[0].getSender())
     *         .addMessage(messages[1].getText(), messages[1].getTime(), messages[1].getSender()))
     *     .build();
     *     .build();
     * </pre>
     * </pre>
     */
     */
@@ -6826,7 +6837,9 @@ public class Notification implements Parcelable
        }
        }


        /**
        /**
         * Sets whether this conversation notification represents a group.
         * Sets whether this conversation notification represents a group. If the app is targeting
         * Android P, this is required if the app wants to display the largeIcon set with
         * {@link Notification.Builder#setLargeIcon(Bitmap)}, otherwise it will be hidden.
         *
         *
         * @param isGroupConversation {@code true} if the conversation represents a group,
         * @param isGroupConversation {@code true} if the conversation represents a group,
         * {@code false} otherwise.
         * {@code false} otherwise.
@@ -7048,13 +7061,22 @@ public class Notification implements Parcelable
            CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle)
            CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle)
                    ? super.mBigContentTitle
                    ? super.mBigContentTitle
                    : mConversationTitle;
                    : mConversationTitle;
            boolean isOneToOne = TextUtils.isEmpty(conversationTitle);
            boolean atLeastP = mBuilder.mContext.getApplicationInfo().targetSdkVersion
                    >= Build.VERSION_CODES.P;
            boolean isOneToOne;
            CharSequence nameReplacement = null;
            CharSequence nameReplacement = null;
            Icon avatarReplacement = null;
            if (!atLeastP) {
                isOneToOne = TextUtils.isEmpty(conversationTitle);
                avatarReplacement = mBuilder.mN.mLargeIcon;
                if (hasOnlyWhiteSpaceSenders()) {
                if (hasOnlyWhiteSpaceSenders()) {
                    isOneToOne = true;
                    isOneToOne = true;
                    nameReplacement = conversationTitle;
                    nameReplacement = conversationTitle;
                    conversationTitle = null;
                    conversationTitle = null;
                }
                }
            } else {
                isOneToOne = !isGroupConversation();
            }
            TemplateBindResult bindResult = new TemplateBindResult();
            TemplateBindResult bindResult = new TemplateBindResult();
            RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(
            RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(
                    mBuilder.getMessagingLayoutResource(),
                    mBuilder.getMessagingLayoutResource(),
@@ -7076,8 +7098,8 @@ public class Notification implements Parcelable
                    mBuilder.getSecondaryTextColor());
                    mBuilder.getSecondaryTextColor());
            contentView.setBoolean(R.id.status_bar_latest_event_content, "setDisplayImagesAtEnd",
            contentView.setBoolean(R.id.status_bar_latest_event_content, "setDisplayImagesAtEnd",
                    displayImagesAtEnd);
                    displayImagesAtEnd);
            contentView.setIcon(R.id.status_bar_latest_event_content, "setLargeIcon",
            contentView.setIcon(R.id.status_bar_latest_event_content, "setAvatarReplacement",
                    mBuilder.mN.mLargeIcon);
                    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",
+6 −6
Original line number Original line Diff line number Diff line
@@ -82,7 +82,7 @@ public class MessagingLayout extends FrameLayout {
    private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    private Paint mTextPaint = new Paint();
    private Paint mTextPaint = new Paint();
    private CharSequence mConversationTitle;
    private CharSequence mConversationTitle;
    private Icon mLargeIcon;
    private Icon mAvatarReplacement;
    private boolean mIsOneToOne;
    private boolean mIsOneToOne;
    private ArrayList<MessagingGroup> mAddedGroups = new ArrayList<>();
    private ArrayList<MessagingGroup> mAddedGroups = new ArrayList<>();
    private Person mUser;
    private Person mUser;
@@ -125,8 +125,8 @@ public class MessagingLayout extends FrameLayout {
    }
    }


    @RemotableViewMethod
    @RemotableViewMethod
    public void setLargeIcon(Icon icon) {
    public void setAvatarReplacement(Icon icon) {
        mLargeIcon = icon;
        mAvatarReplacement = icon;
    }
    }


    @RemotableViewMethod
    @RemotableViewMethod
@@ -228,7 +228,7 @@ public class MessagingLayout extends FrameLayout {
            boolean isOwnMessage = group.getSender() == mUser;
            boolean isOwnMessage = group.getSender() == mUser;
            CharSequence senderName = group.getSenderName();
            CharSequence senderName = group.getSenderName();
            if (!group.needsGeneratedAvatar() || TextUtils.isEmpty(senderName)
            if (!group.needsGeneratedAvatar() || TextUtils.isEmpty(senderName)
                    || (mIsOneToOne && mLargeIcon != null && !isOwnMessage)) {
                    || (mIsOneToOne && mAvatarReplacement != null && !isOwnMessage)) {
                continue;
                continue;
            }
            }
            String symbol = uniqueNames.get(senderName);
            String symbol = uniqueNames.get(senderName);
@@ -246,8 +246,8 @@ public class MessagingLayout extends FrameLayout {
            if (!group.needsGeneratedAvatar() || TextUtils.isEmpty(senderName)) {
            if (!group.needsGeneratedAvatar() || TextUtils.isEmpty(senderName)) {
                continue;
                continue;
            }
            }
            if (mIsOneToOne && mLargeIcon != null && group.getSender() != mUser) {
            if (mIsOneToOne && mAvatarReplacement != null && group.getSender() != mUser) {
                group.setAvatar(mLargeIcon);
                group.setAvatar(mAvatarReplacement);
            } else {
            } else {
                Icon cachedIcon = cachedAvatars.get(senderName);
                Icon cachedIcon = cachedAvatars.get(senderName);
                if (cachedIcon == null) {
                if (cachedIcon == null) {