Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8e7341df authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Fix the (still disabled) logic for re-theming custom view notifications

Test: manual
Bug: 181048615
Change-Id: I237e0f0464eb9c7ad5cba69d7c04f4489553370e
parent a6d0d293
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ public class NotificationCustomViewWrapper extends NotificationViewWrapper {

        // 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.
+1 −1
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ public class NotificationDecoratedCustomViewWrapper extends NotificationTemplate

        // 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);
+25 −14
Original line number Diff line number Diff line
@@ -58,9 +58,10 @@ public abstract class NotificationViewWrapper implements TransformableView {
    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 @@ public abstract class NotificationViewWrapper implements TransformableView {
            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 @@ public abstract class NotificationViewWrapper implements TransformableView {
        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;