Merge "Fix decorated notification text colors in dark mode" into sc-dev

This commit is contained in:
Jeff DeCew
2021-02-24 23:17:29 +00:00
committed by Android (Google) Code Review
3 changed files with 25 additions and 25 deletions

View File

@@ -30,7 +30,7 @@
<style name="Theme.DeviceDefault.QuickSettings.Dialog" parent="Theme.DeviceDefault.Dialog" /> <style name="Theme.DeviceDefault.QuickSettings.Dialog" parent="Theme.DeviceDefault.Dialog" />
<style name="TextAppearance.Material.Notification"> <style name="TextAppearance.Material.Notification">
<item name="textColor">?attr/textColorPrimary</item> <item name="textColor">@color/notification_secondary_text_color_dark</item>
<item name="textSize">@dimen/notification_text_size</item> <item name="textSize">@dimen/notification_text_size</item>
</style> </style>
</resources> </resources>

View File

@@ -421,6 +421,9 @@
vibrator is capable of subtle vibrations --> vibrator is capable of subtle vibrations -->
<bool name="config_vibrateOnIconAnimation">false</bool> <bool name="config_vibrateOnIconAnimation">false</bool>
<!-- Adjust the theme on fully custom and decorated custom view notifications -->
<bool name="config_adjustThemeOnNotificationCustomViews">false</bool>
<!-- If true, enable the advance anti-falsing classifier on the lockscreen. On some devices it <!-- If true, enable the advance anti-falsing classifier on the lockscreen. On some devices it
does not work well, particularly with noisy touchscreens. Note that disabling it may does not work well, particularly with noisy touchscreens. Note that disabling it may
increase the rate of unintentional unlocks. --> increase the rate of unintentional unlocks. -->

View File

@@ -36,12 +36,12 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.graphics.ColorUtils; import com.android.internal.graphics.ColorUtils;
import com.android.internal.util.ContrastColorUtil; import com.android.internal.util.ContrastColorUtil;
import com.android.internal.widget.CachingIconView; import com.android.internal.widget.CachingIconView;
import com.android.settingslib.Utils; import com.android.settingslib.Utils;
import com.android.systemui.R;
import com.android.systemui.statusbar.CrossFadeHelper; import com.android.systemui.statusbar.CrossFadeHelper;
import com.android.systemui.statusbar.TransformableView; import com.android.systemui.statusbar.TransformableView;
import com.android.systemui.statusbar.notification.TransformState; import com.android.systemui.statusbar.notification.TransformState;
@@ -61,6 +61,7 @@ public abstract class NotificationViewWrapper implements TransformableView {
private int mLightTextColor; private int mLightTextColor;
private int mDarkTextColor; private int mDarkTextColor;
private int mDefaultTextColor; private int mDefaultTextColor;
private boolean mAdjustTheme;
public static NotificationViewWrapper wrap(Context ctx, View v, ExpandableNotificationRow row) { public static NotificationViewWrapper wrap(Context ctx, View v, ExpandableNotificationRow row) {
if (v.getId() == com.android.internal.R.id.status_bar_latest_event_content) { if (v.getId() == com.android.internal.R.id.status_bar_latest_event_content) {
@@ -97,6 +98,8 @@ public abstract class NotificationViewWrapper implements TransformableView {
mView = view; mView = view;
mRow = row; mRow = row;
onReinflated(); onReinflated();
mAdjustTheme = ctx.getResources().getBoolean(
R.bool.config_adjustThemeOnNotificationCustomViews);
} }
/** /**
@@ -124,12 +127,12 @@ public abstract class NotificationViewWrapper implements TransformableView {
mLightTextColor = mView.getContext().getColor( mLightTextColor = mView.getContext().getColor(
com.android.internal.R.color.notification_primary_text_color_light); com.android.internal.R.color.notification_primary_text_color_light);
mDarkTextColor = mView.getContext().getColor( mDarkTextColor = mView.getContext().getColor(
R.color.notification_primary_text_color_dark); com.android.internal.R.color.notification_primary_text_color_dark);
Context themedContext = new ContextThemeWrapper(mView.getContext(), Context themedContext = new ContextThemeWrapper(mView.getContext(),
R.style.Theme_DeviceDefault_DayNight); com.android.internal.R.style.Theme_DeviceDefault_DayNight);
mDefaultTextColor = Utils.getColorAttr(themedContext, R.attr.textColorPrimary) mDefaultTextColor = Utils.getColorAttr(themedContext,
.getDefaultColor(); com.android.internal.R.attr.textColorPrimary).getDefaultColor();
} }
protected boolean needsInversion(int defaultBackgroundColor, View view) { protected boolean needsInversion(int defaultBackgroundColor, View view) {
@@ -208,7 +211,7 @@ public abstract class NotificationViewWrapper implements TransformableView {
} }
protected void ensureThemeOnChildren() { protected void ensureThemeOnChildren() {
if (mView == null) { if (!mAdjustTheme || mView == null) {
return; return;
} }
@@ -219,26 +222,20 @@ public abstract class NotificationViewWrapper implements TransformableView {
} }
// Now let's check if there's unprotected text somewhere, and apply the theme if we find it. // Now let's check if there's unprotected text somewhere, and apply the theme if we find it.
if (!(mView instanceof ViewGroup)) { processTextColorRecursive(mView);
return;
}
processChildrenTextColor((ViewGroup) mView);
} }
private void processChildrenTextColor(ViewGroup viewGroup) { private void processTextColorRecursive(View view) {
if (viewGroup == null) { if (view instanceof TextView) {
return; TextView textView = (TextView) view;
} int foreground = textView.getCurrentTextColor();
if (foreground == mLightTextColor || foreground == mDarkTextColor) {
for (int i = 0; i < viewGroup.getChildCount(); i++) { textView.setTextColor(mDefaultTextColor);
View child = viewGroup.getChildAt(i); }
if (child instanceof TextView) { } else if (view instanceof ViewGroup) {
int foreground = ((TextView) child).getCurrentTextColor(); ViewGroup viewGroup = (ViewGroup) view;
if (foreground == mLightTextColor || foreground == mDarkTextColor) { for (int i = 0; i < viewGroup.getChildCount(); i++) {
((TextView) child).setTextColor(mDefaultTextColor); processTextColorRecursive(viewGroup.getChildAt(i));
}
} else if (child instanceof ViewGroup) {
processChildrenTextColor((ViewGroup) child);
} }
} }
} }