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

Commit e62255cc authored by Selim Cinek's avatar Selim Cinek
Browse files

Improved the headsup notification for messages

Previously the heads up notifications and also the collapsed versions were not
displaying in the new style.
They are now displayed in the new style of heads up notifications.

Test: add messaging notification in heads up
Bug: 63708826
Change-Id: I041584cd6ee740fd8c59f332f727ed83c89e777f
parent 88188f2d
Loading
Loading
Loading
Loading
+9 −61
Original line number Diff line number Diff line
@@ -6084,18 +6084,6 @@ public class Notification implements Parcelable
         */
        @Override
        public RemoteViews makeContentView(boolean increasedHeight) {
            if (!increasedHeight) {
                Message m = findLatestIncomingMessage();
                CharSequence title = mConversationTitle != null
                        ? mConversationTitle
                        : (m == null) ? null : m.mSender;
                CharSequence text = (m == null)
                        ? null
                        : mConversationTitle != null ? makeMessageLine(m, mBuilder) : m.mText;

                return mBuilder.applyStandardTemplate(mBuilder.getBaseLayoutResource(),
                        mBuilder.mParams.reset().hasProgress(false).title(title).text(text));
            } else {
            mBuilder.mOriginalActions = mBuilder.mActions;
            mBuilder.mActions = new ArrayList<>();
            RemoteViews remoteViews = makeBigContentView();
@@ -6103,7 +6091,6 @@ public class Notification implements Parcelable
            mBuilder.mOriginalActions = null;
            return remoteViews;
        }
        }

        private Message findLatestIncomingMessage() {
            return findLatestIncomingMessage(mMessages);
@@ -6148,10 +6135,6 @@ public class Notification implements Parcelable
                    mBuilder.getMessagingLayoutResource(),
                    mBuilder.mParams.reset().hasProgress(false).title(conversationTitle).text(null)
                            .hideLargeIcon(isOneToOne).alwaysShowReply(true));
            contentView.setViewLayoutMarginBottomDimen(R.id.line1,
                    hasTitle ? R.dimen.notification_messaging_spacing : 0);
            contentView.setInt(R.id.notification_messaging, "setNumIndentLines",
                    !mBuilder.mN.hasLargeIcon() ? 0 : (hasTitle ? 1 : 2));
            addExtras(mBuilder.mN.extras);
            contentView.setInt(R.id.status_bar_latest_event_content, "setLayoutColor",
                    mBuilder.resolveContrastColor());
@@ -6185,49 +6168,14 @@ public class Notification implements Parcelable
            return title;
        }

        private CharSequence makeMessageLine(Message m, Builder builder) {
            BidiFormatter bidi = BidiFormatter.getInstance();
            SpannableStringBuilder sb = new SpannableStringBuilder();
            boolean colorize = builder.isColorized();
            TextAppearanceSpan colorSpan;
            CharSequence messageName;
            if (TextUtils.isEmpty(m.mSender)) {
                CharSequence replyName = mUserDisplayName == null ? "" : mUserDisplayName;
                sb.append(bidi.unicodeWrap(replyName),
                        makeFontColorSpan(colorize
                                ? builder.getPrimaryTextColor()
                                : mBuilder.resolveContrastColor()),
                        0 /* flags */);
            } else {
                sb.append(bidi.unicodeWrap(m.mSender),
                        makeFontColorSpan(colorize
                                ? builder.getPrimaryTextColor()
                                : Color.BLACK),
                        0 /* flags */);
            }
            CharSequence text = m.mText == null ? "" : m.mText;
            sb.append("  ").append(bidi.unicodeWrap(text));
            return sb;
        }

        /**
         * @hide
         */
        @Override
        public RemoteViews makeHeadsUpContentView(boolean increasedHeight) {
            if (increasedHeight) {
                return makeBigContentView();
            }
            Message m = findLatestIncomingMessage();
            CharSequence title = mConversationTitle != null
                    ? mConversationTitle
                    : (m == null) ? null : m.mSender;
            CharSequence text = (m == null)
                    ? null
                    : mConversationTitle != null ? makeMessageLine(m, mBuilder) : m.mText;

            return mBuilder.applyStandardTemplateWithActions(mBuilder.getBigBaseLayoutResource(),
                    mBuilder.mParams.reset().hasProgress(false).title(title).text(text));
            RemoteViews remoteViews = makeBigContentView();
            remoteViews.setInt(R.id.notification_messaging, "setMaxDisplayedLines", 1);
            return remoteViews;
        }

        private static TextAppearanceSpan makeFontColorSpan(int color) {
+7 −1
Original line number Diff line number Diff line
@@ -186,7 +186,13 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
                result += ((MessagingLinearLayout.MessagingChild) child).getConsumedLines();
            }
        }
        return result;
        // A group is usually taking up quite some space with the padding and the name, let's add 1
        return result + 1;
    }

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

    public Icon getAvatarSymbolIfMatching(CharSequence avatarName, String avatarSymbol,
+15 −15
Original line number Diff line number Diff line
@@ -42,12 +42,7 @@ public class MessagingLinearLayout extends ViewGroup {
     */
    private int mSpacing;

    /**
     * The maximum height allowed.
     */
    private int mMaxHeight;

    private int mIndentLines;
    private int mMaxDisplayedLines = Integer.MAX_VALUE;

    /**
     * Id of the child that's also visible in the contracted layout.
@@ -111,6 +106,7 @@ public class MessagingLinearLayout extends ViewGroup {

            totalHeight = mPaddingTop + mPaddingBottom;
            boolean first = true;
            int linesRemaining = mMaxDisplayedLines;

            // Starting from the bottom: we measure every view as if it were the only one. If it still

@@ -121,7 +117,11 @@ public class MessagingLinearLayout extends ViewGroup {
                }
                final View child = getChildAt(i);
                LayoutParams lp = (LayoutParams) getChildAt(i).getLayoutParams();

                MessagingChild messagingChild = null;
                if (child instanceof MessagingChild) {
                    messagingChild = (MessagingChild) child;
                    messagingChild.setMaxDisplayedLines(linesRemaining);
                }
                int spacing = first ? 0 : mSpacing;
                measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, totalHeight
                        - mPaddingTop - mPaddingBottom + spacing);
@@ -131,8 +131,8 @@ public class MessagingLinearLayout extends ViewGroup {
                        lp.bottomMargin + spacing);
                first = false;
                int measureType = MessagingChild.MEASURED_NORMAL;
                if (child instanceof MessagingChild) {
                    measureType = ((MessagingChild) child).getMeasuredType();
                if (messagingChild != null) {
                    measureType = messagingChild.getMeasuredType();
                    linesRemaining -= messagingChild.getConsumedLines();
                }
                boolean isShortened = measureType == MessagingChild.MEASURED_SHORTENED;
@@ -143,7 +143,7 @@ public class MessagingLinearLayout extends ViewGroup {
                            child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin
                                    + mPaddingLeft + mPaddingRight);
                    lp.hide = false;
                    if (isShortened) {
                    if (isShortened || linesRemaining <= 0) {
                        break;
                    }
                } else {
@@ -239,21 +239,21 @@ public class MessagingLinearLayout extends ViewGroup {
    }

    /**
     * Sets how many lines should be indented to avoid a floating image.
     * Sets how many lines should be displayed at most
     */
    @RemotableViewMethod
    public boolean setNumIndentLines(int numberLines) {
        boolean changed = numberLines != mIndentLines;
        mIndentLines = numberLines;
        return changed;
    public void setMaxDisplayedLines(int numberLines) {
        mMaxDisplayedLines = numberLines;
    }

    public interface MessagingChild {
        int MEASURED_NORMAL = 0;
        int MEASURED_SHORTENED = 1;
        int MEASURED_TOO_SMALL = 2;

        int getMeasuredType();
        int getConsumedLines();
        void setMaxDisplayedLines(int lines);
    }

    public static class LayoutParams extends MarginLayoutParams {
+5 −0
Original line number Diff line number Diff line
@@ -144,6 +144,11 @@ public class MessagingMessage extends ImageFloatingTextView implements
        }
    }

    @Override
    public void setMaxDisplayedLines(int lines) {
        setMaxLines(lines);
    }

    @Override
    public int getConsumedLines() {
        return getLineCount();
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@
                android:id="@+id/notification_messaging"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:layout_marginTop="8dp"
                android:spacing="@dimen/notification_messaging_spacing" />
        </LinearLayout>
    </LinearLayout>
Loading