diff options
| author | 2017-08-18 16:17:51 -0700 | |
|---|---|---|
| committer | 2017-08-22 23:24:38 +0000 | |
| commit | 48f66b7b777c13ebd942ef592888e772ab35547c (patch) | |
| tree | 798d01b1881fc251c440881570a4d6379facd9b4 | |
| parent | 0e261a68d26953d0721d9a5ecd096bb1c62f82b7 (diff) | |
Fixed a bug with app provided media spans
Since notifications are colorized now,
We need to clear color spans from media
notifications, otherwise the contrast won't
be ensured.
Test: use media notification with color span, observe no span
Fixes: 64445955
Change-Id: Ib4f5b14196c604468c8c00ba48f294b1b2d102e3
| -rw-r--r-- | core/java/android/app/Notification.java | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 35b2012b95fd..ff3603de9725 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -3898,7 +3898,7 @@ public class Notification implements Parcelable boolean showProgress = handleProgressBar(p.hasProgress, contentView, ex); if (p.title != null) { contentView.setViewVisibility(R.id.title, View.VISIBLE); - contentView.setTextViewText(R.id.title, p.title); + contentView.setTextViewText(R.id.title, processTextSpans(p.title)); if (!p.ambient) { setTextViewColorPrimary(contentView, R.id.title); } @@ -3909,7 +3909,7 @@ public class Notification implements Parcelable if (p.text != null) { int textId = showProgress ? com.android.internal.R.id.text_line_1 : com.android.internal.R.id.text; - contentView.setTextViewText(textId, p.text); + contentView.setTextViewText(textId, processTextSpans(p.text)); if (!p.ambient) { setTextViewColorSecondary(contentView, textId); } @@ -3921,11 +3921,22 @@ public class Notification implements Parcelable return contentView; } + private CharSequence processTextSpans(CharSequence text) { + if (hasForegroundColor()) { + return clearColorSpans(text); + } + return text; + } + private void setTextViewColorPrimary(RemoteViews contentView, int id) { ensureColors(); contentView.setTextColor(id, mPrimaryTextColor); } + private boolean hasForegroundColor() { + return mForegroundColor != COLOR_INVALID; + } + /** * @return the primary text color * @hide @@ -3968,7 +3979,7 @@ public class Notification implements Parcelable || mActionBarColor == COLOR_INVALID || mTextColorsAreForBackground != backgroundColor) { mTextColorsAreForBackground = backgroundColor; - if (mForegroundColor == COLOR_INVALID || !isColorized()) { + if (!hasForegroundColor() || !isColorized()) { mPrimaryTextColor = NotificationColorUtil.resolvePrimaryColor(mContext, backgroundColor); mSecondaryTextColor = NotificationColorUtil.resolveSecondaryColor(mContext, @@ -4219,7 +4230,8 @@ public class Notification implements Parcelable } if (headerText != null) { // TODO: Remove the span entirely to only have the string with propper formating. - contentView.setTextViewText(R.id.header_text, processLegacyText(headerText)); + contentView.setTextViewText(R.id.header_text, processTextSpans( + processLegacyText(headerText))); setTextViewColorSecondary(contentView, R.id.header_text); contentView.setViewVisibility(R.id.header_text, View.VISIBLE); contentView.setViewVisibility(R.id.header_text_divider, View.VISIBLE); @@ -4350,18 +4362,21 @@ public class Notification implements Parcelable if (!p.ambient && validRemoteInput && replyText != null && replyText.length > 0 && !TextUtils.isEmpty(replyText[0])) { big.setViewVisibility(R.id.notification_material_reply_container, View.VISIBLE); - big.setTextViewText(R.id.notification_material_reply_text_1, replyText[0]); + big.setTextViewText(R.id.notification_material_reply_text_1, + processTextSpans(replyText[0])); setTextViewColorSecondary(big, R.id.notification_material_reply_text_1); if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1])) { big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE); - big.setTextViewText(R.id.notification_material_reply_text_2, replyText[1]); + big.setTextViewText(R.id.notification_material_reply_text_2, + processTextSpans(replyText[1])); setTextViewColorSecondary(big, R.id.notification_material_reply_text_2); if (replyText.length > 2 && !TextUtils.isEmpty(replyText[2])) { big.setViewVisibility( R.id.notification_material_reply_text_3, View.VISIBLE); - big.setTextViewText(R.id.notification_material_reply_text_3, replyText[2]); + big.setTextViewText(R.id.notification_material_reply_text_3, + processTextSpans(replyText[2])); setTextViewColorSecondary(big, R.id.notification_material_reply_text_3); } } @@ -4673,7 +4688,7 @@ public class Notification implements Parcelable outResultColor = new ColorStateList[1]; title = ensureColorSpanContrast(title, bgColor, outResultColor); } - button.setTextViewText(R.id.action0, title); + button.setTextViewText(R.id.action0, processTextSpans(title)); setTextViewColorPrimary(button, R.id.action0); if (outResultColor != null && outResultColor[0] != null) { // We need to set the text color as well since changing a text to uppercase @@ -4683,7 +4698,8 @@ public class Notification implements Parcelable button.setTextColor(R.id.action0,resolveContrastColor()); } } else { - button.setTextViewText(R.id.action0, processLegacyText(action.title)); + button.setTextViewText(R.id.action0, processTextSpans( + processLegacyText(action.title))); if (isColorized() && !ambient) { setTextViewColorPrimary(button, R.id.action0); } else if (mN.color != COLOR_DEFAULT && mTintActionButtons) { @@ -5682,7 +5698,8 @@ public class Notification implements Parcelable RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource()); if (mSummaryTextSet) { - contentView.setTextViewText(R.id.text, mBuilder.processLegacyText(mSummaryText)); + contentView.setTextViewText(R.id.text, mBuilder.processTextSpans( + mBuilder.processLegacyText(mSummaryText))); mBuilder.setTextViewColorSecondary(contentView, R.id.text); contentView.setViewVisibility(R.id.text, View.VISIBLE); } @@ -5864,7 +5881,7 @@ public class Notification implements Parcelable static void applyBigTextContentView(Builder builder, RemoteViews contentView, CharSequence bigTextText) { - contentView.setTextViewText(R.id.big_text, bigTextText); + contentView.setTextViewText(R.id.big_text, builder.processTextSpans(bigTextText)); builder.setTextViewColorSecondary(contentView, R.id.big_text); contentView.setViewVisibility(R.id.big_text, TextUtils.isEmpty(bigTextText) ? View.GONE : View.VISIBLE); @@ -6199,7 +6216,8 @@ public class Notification implements Parcelable int rowId = rowIds[i]; contentView.setViewVisibility(rowId, View.VISIBLE); - contentView.setTextViewText(rowId, makeMessageLine(m, mBuilder)); + contentView.setTextViewText(rowId, mBuilder.processTextSpans( + makeMessageLine(m, mBuilder))); mBuilder.setTextViewColorSecondary(contentView, rowId); if (contractedMessage == m) { @@ -6565,7 +6583,8 @@ public class Notification implements Parcelable CharSequence str = mTexts.get(i); if (!TextUtils.isEmpty(str)) { contentView.setViewVisibility(rowIds[i], View.VISIBLE); - contentView.setTextViewText(rowIds[i], mBuilder.processLegacyText(str)); + contentView.setTextViewText(rowIds[i], + mBuilder.processTextSpans(mBuilder.processLegacyText(str))); mBuilder.setTextViewColorSecondary(contentView, rowIds[i]); contentView.setViewPadding(rowIds[i], 0, topPadding, 0, 0); handleInboxImageMargin(contentView, rowIds[i], first); |