Loading core/java/android/app/Notification.java +39 −34 Original line number Diff line number Diff line Loading @@ -90,6 +90,7 @@ import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings; import android.text.BidiFormatter; import android.text.SpannableString; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.TextUtils; Loading Loading @@ -3427,6 +3428,39 @@ public class Notification implements Parcelable return cs.toString(); } @Nullable private static CharSequence stripNonStyleSpans(@Nullable CharSequence text) { if (text == null) return null; if (text instanceof Spanned) { Spanned ss = (Spanned) text; Object[] spans = ss.getSpans(0, ss.length(), Object.class); SpannableString outString = new SpannableString(ss.toString()); for (Object span : spans) { final Object resultSpan; if (span instanceof StyleSpan || span instanceof StrikethroughSpan || span instanceof UnderlineSpan) { resultSpan = span; } else if (span instanceof TextAppearanceSpan) { final TextAppearanceSpan originalSpan = (TextAppearanceSpan) span; resultSpan = new TextAppearanceSpan( null, originalSpan.getTextStyle(), -1, null, null); } else { continue; } outString.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), ss.getSpanFlags(span)); } return outString; } return text; } private static CharSequence normalizeBigText(@Nullable CharSequence charSequence) { if (charSequence == null) { return charSequence; Loading Loading @@ -7405,8 +7439,10 @@ public class Notification implements Parcelable */ public CharSequence ensureColorSpanContrastOrStripStyling(CharSequence cs, int buttonFillColor) { // Ongoing promoted notifications are allowed to have styling. if (Flags.cleanUpSpansAndNewLines()) { if ( mN.isPromotedOngoing()) { // RON keeps non style spans just like MessagingStyle return stripNonStyleSpans(cs); } else if (Flags.cleanUpSpansAndNewLines()) { return stripStyling(cs); } Loading Loading @@ -9018,7 +9054,7 @@ public class Notification implements Parcelable // Replace the text with the big text, but only if the big text is not empty. CharSequence bigTextText = mBuilder.processLegacyText(mBigText); // Ongoing promoted notifications are allowed to have styling. if (Flags.cleanUpSpansAndNewLines()) { if (!mBuilder.mN.isPromotedOngoing() && Flags.cleanUpSpansAndNewLines()) { bigTextText = normalizeBigText(stripStyling(bigTextText)); } if (!TextUtils.isEmpty(bigTextText)) { Loading Loading @@ -10153,37 +10189,6 @@ public class Notification implements Parcelable } } private CharSequence stripNonStyleSpans(CharSequence text) { if (text instanceof Spanned) { Spanned ss = (Spanned) text; Object[] spans = ss.getSpans(0, ss.length(), Object.class); SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); for (Object span : spans) { final Object resultSpan; if (span instanceof StyleSpan || span instanceof StrikethroughSpan || span instanceof UnderlineSpan) { resultSpan = span; } else if (span instanceof TextAppearanceSpan) { final TextAppearanceSpan originalSpan = (TextAppearanceSpan) span; resultSpan = new TextAppearanceSpan( null, originalSpan.getTextStyle(), -1, null, null); } else { continue; } builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), ss.getSpanFlags(span)); } return builder; } return text; } /** * Updates TextAppearance spans in the message text so it has sufficient contrast * against its background. Loading Loading
core/java/android/app/Notification.java +39 −34 Original line number Diff line number Diff line Loading @@ -90,6 +90,7 @@ import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings; import android.text.BidiFormatter; import android.text.SpannableString; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.TextUtils; Loading Loading @@ -3427,6 +3428,39 @@ public class Notification implements Parcelable return cs.toString(); } @Nullable private static CharSequence stripNonStyleSpans(@Nullable CharSequence text) { if (text == null) return null; if (text instanceof Spanned) { Spanned ss = (Spanned) text; Object[] spans = ss.getSpans(0, ss.length(), Object.class); SpannableString outString = new SpannableString(ss.toString()); for (Object span : spans) { final Object resultSpan; if (span instanceof StyleSpan || span instanceof StrikethroughSpan || span instanceof UnderlineSpan) { resultSpan = span; } else if (span instanceof TextAppearanceSpan) { final TextAppearanceSpan originalSpan = (TextAppearanceSpan) span; resultSpan = new TextAppearanceSpan( null, originalSpan.getTextStyle(), -1, null, null); } else { continue; } outString.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), ss.getSpanFlags(span)); } return outString; } return text; } private static CharSequence normalizeBigText(@Nullable CharSequence charSequence) { if (charSequence == null) { return charSequence; Loading Loading @@ -7405,8 +7439,10 @@ public class Notification implements Parcelable */ public CharSequence ensureColorSpanContrastOrStripStyling(CharSequence cs, int buttonFillColor) { // Ongoing promoted notifications are allowed to have styling. if (Flags.cleanUpSpansAndNewLines()) { if ( mN.isPromotedOngoing()) { // RON keeps non style spans just like MessagingStyle return stripNonStyleSpans(cs); } else if (Flags.cleanUpSpansAndNewLines()) { return stripStyling(cs); } Loading Loading @@ -9018,7 +9054,7 @@ public class Notification implements Parcelable // Replace the text with the big text, but only if the big text is not empty. CharSequence bigTextText = mBuilder.processLegacyText(mBigText); // Ongoing promoted notifications are allowed to have styling. if (Flags.cleanUpSpansAndNewLines()) { if (!mBuilder.mN.isPromotedOngoing() && Flags.cleanUpSpansAndNewLines()) { bigTextText = normalizeBigText(stripStyling(bigTextText)); } if (!TextUtils.isEmpty(bigTextText)) { Loading Loading @@ -10153,37 +10189,6 @@ public class Notification implements Parcelable } } private CharSequence stripNonStyleSpans(CharSequence text) { if (text instanceof Spanned) { Spanned ss = (Spanned) text; Object[] spans = ss.getSpans(0, ss.length(), Object.class); SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); for (Object span : spans) { final Object resultSpan; if (span instanceof StyleSpan || span instanceof StrikethroughSpan || span instanceof UnderlineSpan) { resultSpan = span; } else if (span instanceof TextAppearanceSpan) { final TextAppearanceSpan originalSpan = (TextAppearanceSpan) span; resultSpan = new TextAppearanceSpan( null, originalSpan.getTextStyle(), -1, null, null); } else { continue; } builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), ss.getSpanFlags(span)); } return builder; } return text; } /** * Updates TextAppearance spans in the message text so it has sufficient contrast * against its background. Loading