From 0bc3f6aae294846caa971d15037bac49fdda3661 Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Mon, 6 Mar 2017 11:54:05 -0800 Subject: [PATCH] AOD: Invert color spans for ambient display view Fixes a bug where notifications with color spans would not show the text properly because we inverted the background. Now we invert the color spans the app put on the text for the ambient view. Fixes: 35705172 Bug: 30876804 Test: receive gmail notification, observe that subject is visible on ambient display Change-Id: I602335562346759d62d2a69a55f3ac9d1be735a9 --- core/java/android/app/Notification.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 34a45dd626e24..9094ddd70b7ed 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -72,6 +72,7 @@ import android.widget.RemoteViews; import com.android.internal.R; import com.android.internal.util.ArrayUtils; import com.android.internal.util.NotificationColorUtil; +import com.android.internal.util.Preconditions; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -4068,7 +4069,7 @@ public class Notification implements Parcelable public RemoteViews makeAmbientNotification() { RemoteViews ambient = applyStandardTemplateWithActions( R.layout.notification_template_material_ambient, - mParams.reset().fillTextsFrom(this).hasProgress(false).ambient(true)); + mParams.reset().ambient(true).fillTextsFrom(this).hasProgress(false)); return ambient; } @@ -4381,7 +4382,13 @@ public class Notification implements Parcelable } private CharSequence processLegacyText(CharSequence charSequence) { - if (isLegacy() || textColorsNeedInversion()) { + return processLegacyText(charSequence, false /* ambient */); + } + + private CharSequence processLegacyText(CharSequence charSequence, boolean ambient) { + boolean isAlreadyLightText = isLegacy() || textColorsNeedInversion(); + boolean wantLightText = ambient; + if (isAlreadyLightText != wantLightText) { return getColorUtil().invertCharSequenceColors(charSequence); } else { return charSequence; @@ -7853,14 +7860,15 @@ public class Notification implements Parcelable } final StandardTemplateParams ambient(boolean ambient) { + Preconditions.checkState(title == null && text == null, "must set ambient before text"); this.ambient = ambient; return this; } final StandardTemplateParams fillTextsFrom(Builder b) { Bundle extras = b.mN.extras; - title = b.processLegacyText(extras.getCharSequence(EXTRA_TITLE)); - text = b.processLegacyText(extras.getCharSequence(EXTRA_TEXT)); + title = b.processLegacyText(extras.getCharSequence(EXTRA_TITLE), ambient); + text = b.processLegacyText(extras.getCharSequence(EXTRA_TEXT), ambient); return this; } }