Fix the (still disabled) logic for re-theming custom view notifications
Test: manual
Bug: 181048615
Change-Id: I237e0f0464eb9c7ad5cba69d7c04f4489553370e
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationCustomViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationCustomViewWrapper.java
index 414d620..222735a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationCustomViewWrapper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationCustomViewWrapper.java
@@ -49,7 +49,7 @@
// Custom views will most likely use just white or black as their text color.
// We need to scan through and replace these colors by Material NEXT colors.
- ensureThemeOnChildren();
+ ensureThemeOnChildren(mView);
// Let's invert the notification colors when we're in night mode and
// the notification background isn't colorized.
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationDecoratedCustomViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationDecoratedCustomViewWrapper.java
index 301c372..d21ae13 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationDecoratedCustomViewWrapper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationDecoratedCustomViewWrapper.java
@@ -64,7 +64,7 @@
// Custom views will most likely use just white or black as their text color.
// We need to scan through and replace these colors by Material NEXT colors.
- ensureThemeOnChildren();
+ ensureThemeOnChildren(mWrappedView);
if (needsInversion(resolveBackgroundColor(), mWrappedView)) {
invertViewLuminosity(mWrappedView);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationViewWrapper.java
index 0ef4c4d..89babf0 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationViewWrapper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationViewWrapper.java
@@ -58,9 +58,10 @@
private final Rect mTmpRect = new Rect();
protected int mBackgroundColor = 0;
- private int mLightTextColor;
- private int mDarkTextColor;
- private int mDefaultTextColor;
+ private int mMaterialTextColorPrimary;
+ private int mMaterialTextColorSecondary;
+ private int mThemedTextColorPrimary;
+ private int mThemedTextColorSecondary;
private boolean mAdjustTheme;
public static NotificationViewWrapper wrap(Context ctx, View v, ExpandableNotificationRow row) {
@@ -124,15 +125,22 @@
mBackgroundColor = backgroundColor;
mView.setBackground(new ColorDrawable(Color.TRANSPARENT));
}
- mLightTextColor = mView.getContext().getColor(
- com.android.internal.R.color.notification_primary_text_color_light);
- mDarkTextColor = mView.getContext().getColor(
- com.android.internal.R.color.notification_primary_text_color_dark);
+
+ Context materialTitleContext = new ContextThemeWrapper(mView.getContext(),
+ com.android.internal.R.style.TextAppearance_Material_Notification_Title);
+ mMaterialTextColorPrimary = Utils.getColorAttr(materialTitleContext,
+ com.android.internal.R.attr.textColor).getDefaultColor();
+ Context materialContext = new ContextThemeWrapper(mView.getContext(),
+ com.android.internal.R.style.TextAppearance_Material_Notification);
+ mMaterialTextColorSecondary = Utils.getColorAttr(materialContext,
+ com.android.internal.R.attr.textColor).getDefaultColor();
Context themedContext = new ContextThemeWrapper(mView.getContext(),
com.android.internal.R.style.Theme_DeviceDefault_DayNight);
- mDefaultTextColor = Utils.getColorAttr(themedContext,
+ mThemedTextColorPrimary = Utils.getColorAttr(themedContext,
com.android.internal.R.attr.textColorPrimary).getDefaultColor();
+ mThemedTextColorSecondary = Utils.getColorAttr(themedContext,
+ com.android.internal.R.attr.textColorSecondary).getDefaultColor();
}
protected boolean needsInversion(int defaultBackgroundColor, View view) {
@@ -210,27 +218,30 @@
return false;
}
- protected void ensureThemeOnChildren() {
- if (!mAdjustTheme || mView == null) {
+ protected void ensureThemeOnChildren(View rootView) {
+ if (!mAdjustTheme || mView == null || rootView == null) {
return;
}
// Notifications with custom backgrounds should not be adjusted
if (mBackgroundColor != Color.TRANSPARENT
- || getBackgroundColor(mView) != Color.TRANSPARENT) {
+ || getBackgroundColor(mView) != Color.TRANSPARENT
+ || getBackgroundColor(rootView) != Color.TRANSPARENT) {
return;
}
// Now let's check if there's unprotected text somewhere, and apply the theme if we find it.
- processTextColorRecursive(mView);
+ processTextColorRecursive(rootView);
}
private void processTextColorRecursive(View view) {
if (view instanceof TextView) {
TextView textView = (TextView) view;
int foreground = textView.getCurrentTextColor();
- if (foreground == mLightTextColor || foreground == mDarkTextColor) {
- textView.setTextColor(mDefaultTextColor);
+ if (foreground == mMaterialTextColorPrimary) {
+ textView.setTextColor(mThemedTextColorPrimary);
+ } else if (foreground == mMaterialTextColorSecondary) {
+ textView.setTextColor(mThemedTextColorSecondary);
}
} else if (view instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) view;