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

Commit cccdd3c8 authored by Ibrahim Yilmaz's avatar Ibrahim Yilmaz Committed by Android (Google) Code Review
Browse files

Merge "[API Abuse - Text Consistency] Clean up spans and new lines" into main

parents 2eab65a7 59f62746
Loading
Loading
Loading
Loading
+104 −26
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICO
import static android.app.admin.DevicePolicyResources.UNDEFINED;
import static android.graphics.drawable.Icon.TYPE_URI;
import static android.graphics.drawable.Icon.TYPE_URI_ADAPTIVE_BITMAP;
import static android.app.Flags.cleanUpSpansAndNewLines;
import static android.app.Flags.evenlyDividedCallStyleActionLayout;
import static android.app.Flags.updateRankingTime;
@@ -3124,9 +3125,29 @@ public class Notification implements Parcelable
                    + " instance is a custom Parcelable and not allowed in Notification");
            return cs.toString();
        }
        if (Flags.cleanUpSpansAndNewLines()) {
            return stripStyling(cs);
        }
        return removeTextSizeSpans(cs);
    }
    private static CharSequence stripStyling(@Nullable CharSequence cs) {
        if (cs == null) {
            return cs;
        }
        return cs.toString();
    }
    private static CharSequence cleanUpNewLines(@Nullable CharSequence charSequence) {
        if (charSequence == null) {
            return charSequence;
        }
        return charSequence.toString().replaceAll("[\r\n]+", "\n");
    }
    private static CharSequence removeTextSizeSpans(CharSequence charSequence) {
        if (charSequence instanceof Spanned) {
            Spanned ss = (Spanned) charSequence;
@@ -5505,7 +5526,8 @@ public class Notification implements Parcelable
            boolean hasSecondLine = showProgress;
            if (p.hasTitle()) {
                contentView.setViewVisibility(p.mTitleViewId, View.VISIBLE);
                contentView.setTextViewText(p.mTitleViewId, ensureColorSpanContrast(p.mTitle, p));
                contentView.setTextViewText(p.mTitleViewId,
                        ensureColorSpanContrastOrStripStyling(p.mTitle, p));
                setTextViewColorPrimary(contentView, p.mTitleViewId, p);
            } else if (p.mTitleViewId != R.id.title) {
                // This alternate title view ID is not cleared by resetStandardTemplate
@@ -5515,7 +5537,8 @@ public class Notification implements Parcelable
            if (p.mText != null && p.mText.length() != 0
                    && (!showProgress || p.mAllowTextWithProgress)) {
                contentView.setViewVisibility(p.mTextViewId, View.VISIBLE);
                contentView.setTextViewText(p.mTextViewId, ensureColorSpanContrast(p.mText, p));
                contentView.setTextViewText(p.mTextViewId,
                        ensureColorSpanContrastOrStripStyling(p.mText, p));
                setTextViewColorSecondary(contentView, p.mTextViewId, p);
                hasSecondLine = true;
            } else if (p.mTextViewId != R.id.text) {
@@ -5804,7 +5827,7 @@ public class Notification implements Parcelable
                headerText = mN.extras.getCharSequence(EXTRA_INFO_TEXT);
            }
            if (!TextUtils.isEmpty(headerText)) {
                contentView.setTextViewText(R.id.header_text, ensureColorSpanContrast(
                contentView.setTextViewText(R.id.header_text, ensureColorSpanContrastOrStripStyling(
                        processLegacyText(headerText), p));
                setTextViewColorSecondary(contentView, R.id.header_text, p);
                contentView.setViewVisibility(R.id.header_text, View.VISIBLE);
@@ -5826,7 +5849,8 @@ public class Notification implements Parcelable
                return false;
            }
            if (!TextUtils.isEmpty(p.mHeaderTextSecondary)) {
                contentView.setTextViewText(R.id.header_text_secondary, ensureColorSpanContrast(
                contentView.setTextViewText(R.id.header_text_secondary,
                        ensureColorSpanContrastOrStripStyling(
                                processLegacyText(p.mHeaderTextSecondary), p));
                setTextViewColorSecondary(contentView, R.id.header_text_secondary, p);
                contentView.setViewVisibility(R.id.header_text_secondary, View.VISIBLE);
@@ -6048,7 +6072,7 @@ public class Notification implements Parcelable
                big.setViewVisibility(R.id.notification_material_reply_text_1_container,
                        View.VISIBLE);
                big.setTextViewText(R.id.notification_material_reply_text_1,
                        ensureColorSpanContrast(replyText[0].getText(), p));
                        ensureColorSpanContrastOrStripStyling(replyText[0].getText(), p));
                setTextViewColorSecondary(big, R.id.notification_material_reply_text_1, p);
                big.setViewVisibility(R.id.notification_material_reply_progress,
                        showSpinner ? View.VISIBLE : View.GONE);
@@ -6060,7 +6084,7 @@ public class Notification implements Parcelable
                        && p.maxRemoteInputHistory > 1) {
                    big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE);
                    big.setTextViewText(R.id.notification_material_reply_text_2,
                            ensureColorSpanContrast(replyText[1].getText(), p));
                            ensureColorSpanContrastOrStripStyling(replyText[1].getText(), p));
                    setTextViewColorSecondary(big, R.id.notification_material_reply_text_2, p);
                    if (replyText.length > 2 && !TextUtils.isEmpty(replyText[2].getText())
@@ -6068,7 +6092,7 @@ public class Notification implements Parcelable
                        big.setViewVisibility(
                                R.id.notification_material_reply_text_3, View.VISIBLE);
                        big.setTextViewText(R.id.notification_material_reply_text_3,
                                ensureColorSpanContrast(replyText[2].getText(), p));
                                ensureColorSpanContrastOrStripStyling(replyText[2].getText(), p));
                        setTextViewColorSecondary(big, R.id.notification_material_reply_text_3, p);
                    }
                }
@@ -6500,6 +6524,18 @@ public class Notification implements Parcelable
                                    mContext, getColors(p).getBackgroundColor(), mInNightMode),
                            R.dimen.notification_action_disabled_container_alpha);
                }
                if (Flags.cleanUpSpansAndNewLines()) {
                    if (!isLegacy()) {
                        // Check for a full-length span color to use as the button fill color.
                        Integer fullLengthColor = getFullLengthSpanColor(title);
                        if (fullLengthColor != null) {
                            // Ensure the custom button fill has 1.3:1 contrast w/ notification bg.
                            int notifBackgroundColor = getColors(p).getBackgroundColor();
                            buttonFillColor = ensureButtonFillContrast(
                                    fullLengthColor, notifBackgroundColor);
                        }
                    }
                } else {
                    if (isLegacy()) {
                        title = ContrastColorUtil.clearColorSpans(title);
                    } else {
@@ -6511,10 +6547,14 @@ public class Notification implements Parcelable
                            buttonFillColor = ensureButtonFillContrast(
                                    fullLengthColor, notifBackgroundColor);
                        }
                    // Remove full-length color spans and ensure text contrast with the button fill.
                        // Remove full-length color spans
                        // and ensure text contrast with the button fill.
                        title = ContrastColorUtil.ensureColorSpanContrast(title, buttonFillColor);
                    }
                final CharSequence label = ensureColorSpanContrast(title, p);
                }
                final CharSequence label = ensureColorSpanContrastOrStripStyling(title, p);
                if (p.mCallStyleActions && evenlyDividedCallStyleActionLayout()) {
                    if (CallStyle.DEBUG_NEW_ACTION_LAYOUT) {
                        Log.d(TAG, "new action layout enabled, gluing instead of setting text");
@@ -6554,7 +6594,7 @@ public class Notification implements Parcelable
                    button.setIntDimen(R.id.action0, "setMinimumWidth", minWidthDimen);
                }
            } else {
                button.setTextViewText(R.id.action0, ensureColorSpanContrast(
                button.setTextViewText(R.id.action0, ensureColorSpanContrastOrStripStyling(
                        action.title, p));
                button.setTextColor(R.id.action0, getStandardActionColor(p));
            }
@@ -6628,6 +6668,26 @@ public class Notification implements Parcelable
            return result;
        }
        /**
         * @hide
         */
        public CharSequence ensureColorSpanContrastOrStripStyling(CharSequence cs,
                StandardTemplateParams p) {
            return ensureColorSpanContrastOrStripStyling(cs, getBackgroundColor(p));
        }
        /**
         * @hide
         */
        public CharSequence ensureColorSpanContrastOrStripStyling(CharSequence cs,
                int buttonFillColor) {
            if (Flags.cleanUpSpansAndNewLines()) {
                return stripStyling(cs);
            }
            return ContrastColorUtil.ensureColorSpanContrast(cs, buttonFillColor);
        }
        /**
         * Ensures contrast on color spans against a background color.
         * Note that any full-length color spans will be removed instead of being contrasted.
@@ -7853,7 +7913,8 @@ public class Notification implements Parcelable
            RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource(),
                    p, null /* result */);
            if (mSummaryTextSet) {
                contentView.setTextViewText(R.id.text, mBuilder.ensureColorSpanContrast(
                contentView.setTextViewText(R.id.text,
                        mBuilder.ensureColorSpanContrastOrStripStyling(
                                mBuilder.processLegacyText(mSummaryText), p));
                mBuilder.setTextViewColorSecondary(contentView, R.id.text, p);
                contentView.setViewVisibility(R.id.text, View.VISIBLE);
@@ -8017,6 +8078,9 @@ public class Notification implements Parcelable
         */
        public BigTextStyle bigText(CharSequence cs) {
            mBigText = safeCharSequence(cs);
            if (Flags.cleanUpSpansAndNewLines()) {
                mBigText = cleanUpNewLines(mBigText);
            }
            return this;
        }
@@ -8517,7 +8581,7 @@ public class Notification implements Parcelable
            for (int i = 0; i < N; i++) {
                final Message m = messages.get(i);
                if (ensureContrast) {
                    m.ensureColorContrast(backgroundColor);
                    m.ensureColorContrastOrStripStyling(backgroundColor);
                }
                bundles[i] = m.toBundle();
            }
@@ -8543,7 +8607,9 @@ public class Notification implements Parcelable
            } else {
                title = sender;
            }
            if (Flags.cleanUpSpansAndNewLines()) {
                title = stripStyling(title);
            }
            if (title != null) {
                extras.putCharSequence(EXTRA_TITLE, title);
            }
@@ -8994,6 +9060,17 @@ public class Notification implements Parcelable
                return this;
            }
            /**
             * Strip styling or updates TextAppearance spans in message text.
             * @hide
             */
            public void ensureColorContrastOrStripStyling(int backgroundColor) {
                if (Flags.cleanUpSpansAndNewLines()) {
                    mText = stripStyling(mText);
                } else {
                    ensureColorContrast(backgroundColor);
                }
            }
            /**
             * Updates TextAppearance spans in the message text so it has sufficient contrast
             * against its background.
@@ -9324,7 +9401,8 @@ public class Notification implements Parcelable
                if (!TextUtils.isEmpty(str)) {
                    contentView.setViewVisibility(rowIds[i], View.VISIBLE);
                    contentView.setTextViewText(rowIds[i],
                            mBuilder.ensureColorSpanContrast(mBuilder.processLegacyText(str), p));
                            mBuilder.ensureColorSpanContrastOrStripStyling(
                                    mBuilder.processLegacyText(str), p));
                    mBuilder.setTextViewColorSecondary(contentView, rowIds[i], p);
                    contentView.setViewPadding(rowIds[i], 0, topPadding, 0, 0);
                    if (first) {
+7 −0
Original line number Diff line number Diff line
@@ -110,3 +110,10 @@ flag {
  description: "No notifs can use USAGE_UNKNOWN or USAGE_MEDIA"
  bug: "331793339"
}

flag {
  name: "clean_up_spans_and_new_lines"
  namespace: "systemui"
  description: "Cleans up spans and unnecessary new lines from standard notification templates"
  bug: "313439845"
}
 No newline at end of file
+4 −0
Original line number Diff line number Diff line
@@ -1212,6 +1212,10 @@ public class ConversationLayout extends FrameLayout
                }
            }
        }
        if (android.app.Flags.cleanUpSpansAndNewLines() && conversationText != null) {
            // remove formatting from title.
            conversationText = conversationText.toString();
        }

        if (conversationIcon == null) {
            conversationIcon = largeIcon;
+5 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StyleRes;
import android.app.Flags;
import android.app.Person;
import android.content.Context;
import android.content.res.ColorStateList;
@@ -200,6 +201,10 @@ public class MessagingGroup extends NotificationOptimizedLinearLayout implements
        if (nameOverride == null) {
            nameOverride = sender.getName();
        }
        if (Flags.cleanUpSpansAndNewLines() && nameOverride != null) {
            // remove formatting from sender name
            nameOverride = nameOverride.toString();
        }
        mSenderName = nameOverride;
        if (mSingleLine && !TextUtils.isEmpty(nameOverride)) {
            nameOverride = mContext.getResources().getString(
+2 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.statusbar.notification.row

import android.app.Flags
import android.app.Notification
import android.app.Notification.MessagingStyle
import android.app.Person
@@ -131,7 +132,7 @@ internal object SingleLineViewInflater {
        val senderName =
            systemUiContext.resources.getString(
                R.string.conversation_single_line_name_display,
                name
                if (Flags.cleanUpSpansAndNewLines()) name?.toString() else name
            )

        // We need to find back-up values for those texts if they are needed and empty