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

Commit 6063e254 authored by Julia Tuttle's avatar Julia Tuttle
Browse files

Update framework to new notification color spec

Bug: 277285099
Test: manual
Flag: NONE
Change-Id: I194d2d2275d8647bcc61514520b9088f2382a1ee
parent e9fc0fb0
Loading
Loading
Loading
Loading
+39 −11
Original line number Diff line number Diff line
@@ -5606,7 +5606,8 @@ public class Notification implements Parcelable
            contentView.setInt(R.id.expand_button, "setDefaultPillColor", pillColor);
            // Use different highlighted colors for conversations' unread count
            if (p.mHighlightExpander) {
                pillColor = Colors.flattenAlpha(getColors(p).getTertiaryAccentColor(), bgColor);
                pillColor = Colors.flattenAlpha(
                        getColors(p).getTertiaryFixedDimAccentColor(), bgColor);
                textColor = Colors.flattenAlpha(
                        getColors(p).getOnTertiaryAccentTextColor(), pillColor);
            }
@@ -12835,6 +12836,9 @@ public class Notification implements Parcelable
        private int mSecondaryAccentColor = COLOR_INVALID;
        private int mTertiaryAccentColor = COLOR_INVALID;
        private int mOnTertiaryAccentTextColor = COLOR_INVALID;
        private int mTertiaryFixedDimAccentColor = COLOR_INVALID;
        private int mOnTertiaryFixedAccentTextColor = COLOR_INVALID;
        private int mErrorColor = COLOR_INVALID;
        private int mContrastColor = COLOR_INVALID;
        private int mRippleAlpha = 0x33;
@@ -12892,7 +12896,7 @@ public class Notification implements Parcelable
            if (isColorized) {
                if (rawColor == COLOR_DEFAULT) {
                    int[] attrs = {R.attr.colorAccentSecondary};
                    int[] attrs = {R.attr.materialColorSecondary};
                    try (TypedArray ta = obtainDayNightAttributes(ctx, attrs)) {
                        mBackgroundColor = getColor(ta, 0, Color.WHITE);
                    }
@@ -12910,17 +12914,21 @@ public class Notification implements Parcelable
                mSecondaryAccentColor = mSecondaryTextColor;
                mTertiaryAccentColor = flattenAlpha(mPrimaryTextColor, mBackgroundColor);
                mOnTertiaryAccentTextColor = mBackgroundColor;
                mTertiaryFixedDimAccentColor = mTertiaryAccentColor;
                mOnTertiaryFixedAccentTextColor = mOnTertiaryAccentTextColor;
                mErrorColor = mPrimaryTextColor;
                mRippleAlpha = 0x33;
            } else {
                int[] attrs = {
                        R.attr.colorSurface,
                        R.attr.textColorPrimary,
                        R.attr.textColorSecondary,
                        R.attr.colorAccent,
                        R.attr.colorAccentSecondary,
                        R.attr.colorAccentTertiary,
                        R.attr.textColorOnAccent,
                        R.attr.materialColorSurfaceContainerHigh,
                        R.attr.materialColorOnSurface,
                        R.attr.materialColorOnSurfaceVariant,
                        R.attr.materialColorPrimary,
                        R.attr.materialColorSecondary,
                        R.attr.materialColorTertiary,
                        R.attr.materialColorOnTertiary,
                        R.attr.materialColorTertiaryFixedDim,
                        R.attr.materialColorOnTertiaryFixed,
                        R.attr.colorError,
                        R.attr.colorControlHighlight
                };
@@ -12932,8 +12940,10 @@ public class Notification implements Parcelable
                    mSecondaryAccentColor = getColor(ta, 4, COLOR_INVALID);
                    mTertiaryAccentColor = getColor(ta, 5, COLOR_INVALID);
                    mOnTertiaryAccentTextColor = getColor(ta, 6, COLOR_INVALID);
                    mErrorColor = getColor(ta, 7, COLOR_INVALID);
                    mRippleAlpha = Color.alpha(getColor(ta, 8, 0x33ffffff));
                    mTertiaryFixedDimAccentColor = getColor(ta, 7, COLOR_INVALID);
                    mOnTertiaryFixedAccentTextColor = getColor(ta, 8, COLOR_INVALID);
                    mErrorColor = getColor(ta, 9, COLOR_INVALID);
                    mRippleAlpha = Color.alpha(getColor(ta, 10, 0x33ffffff));
                }
                mContrastColor = calculateContrastColor(ctx, rawColor, mPrimaryAccentColor,
                        mBackgroundColor, nightMode);
@@ -12961,6 +12971,14 @@ public class Notification implements Parcelable
                            ContrastColorUtil.resolvePrimaryColor(
                                    ctx, mTertiaryAccentColor, nightMode), 0xFF);
                }
                if (mTertiaryFixedDimAccentColor == COLOR_INVALID) {
                    mTertiaryFixedDimAccentColor = mContrastColor;
                }
                if (mOnTertiaryFixedAccentTextColor == COLOR_INVALID) {
                    mOnTertiaryFixedAccentTextColor = ColorUtils.setAlphaComponent(
                            ContrastColorUtil.resolvePrimaryColor(
                                    ctx, mTertiaryFixedDimAccentColor, nightMode), 0xFF);
                }
                if (mErrorColor == COLOR_INVALID) {
                    mErrorColor = mPrimaryTextColor;
                }
@@ -13034,6 +13052,16 @@ public class Notification implements Parcelable
            return mOnTertiaryAccentTextColor;
        }
        /** @return the theme's tertiary fixed dim accent color for colored UI elements. */
        public @ColorInt int getTertiaryFixedDimAccentColor() {
            return mTertiaryFixedDimAccentColor;
        }
        /** @return the theme's text color to be used on the tertiary fixed accent color. */
        public @ColorInt int getOnTertiaryFixedAccentTextColor() {
            return mOnTertiaryFixedAccentTextColor;
        }
        /**
         * @return the contrast-adjusted version of the color provided by the app, or the
         * primary text color when colorized.
+5 −4
Original line number Diff line number Diff line
@@ -135,11 +135,12 @@
    <drawable name="notification_template_icon_low_bg">#0cffffff</drawable>
    <drawable name="notification_template_divider">#29000000</drawable>
    <drawable name="notification_template_divider_media">#29ffffff</drawable>
    <color name="notification_primary_text_color_light">@color/primary_text_default_material_light</color>
    <color name="notification_primary_text_color_dark">@color/primary_text_default_material_dark</color>
    <color name="notification_secondary_text_color_light">@color/primary_text_default_material_light</color>
    <color name="notification_primary_text_color_light">@color/system_on_surface_light</color>
    <color name="notification_primary_text_color_dark">@color/system_on_surface_dark</color>
    <!-- Note that the primary and secondary notification text colors are, in fact, the same. -->
    <color name="notification_secondary_text_color_light">@color/system_on_surface_light</color>
    <color name="notification_secondary_text_color_dark">@color/system_on_surface_dark</color>
    <item name="notification_secondary_text_disabled_alpha" format="float" type="dimen">0.38</item>
    <color name="notification_secondary_text_color_dark">@color/primary_text_default_material_dark</color>
    <color name="notification_default_color_dark">#ddffffff</color>
    <color name="notification_default_color_light">#a3202124</color>

+9 −0
Original line number Diff line number Diff line
@@ -859,6 +859,10 @@ public class NotificationTest {
            assertEquals(cDay.getTertiaryAccentColor(), cNight.getTertiaryAccentColor());
            assertEquals(cDay.getOnTertiaryAccentTextColor(),
                    cNight.getOnTertiaryAccentTextColor());
            assertEquals(cDay.getTertiaryFixedDimAccentColor(),
                    cNight.getTertiaryFixedDimAccentColor());
            assertEquals(cDay.getOnTertiaryFixedAccentTextColor(),
                    cNight.getOnTertiaryFixedAccentTextColor());
            assertEquals(cDay.getProtectionColor(), cNight.getProtectionColor());
            assertEquals(cDay.getContrastColor(), cNight.getContrastColor());
            assertEquals(cDay.getRippleAlpha(), cNight.getRippleAlpha());
@@ -1832,6 +1836,8 @@ public class NotificationTest {
        assertThat(c.getSecondaryAccentColor()).isNotEqualTo(Notification.COLOR_INVALID);
        assertThat(c.getTertiaryAccentColor()).isNotEqualTo(Notification.COLOR_INVALID);
        assertThat(c.getOnTertiaryAccentTextColor()).isNotEqualTo(Notification.COLOR_INVALID);
        assertThat(c.getTertiaryFixedDimAccentColor()).isNotEqualTo(Notification.COLOR_INVALID);
        assertThat(c.getOnTertiaryFixedAccentTextColor()).isNotEqualTo(Notification.COLOR_INVALID);
        assertThat(c.getErrorColor()).isNotEqualTo(Notification.COLOR_INVALID);
        assertThat(c.getContrastColor()).isNotEqualTo(Notification.COLOR_INVALID);
        assertThat(c.getRippleAlpha()).isAtLeast(0x00);
@@ -1847,9 +1853,12 @@ public class NotificationTest {
        // These colors are only used for emphasized buttons; they do not need contrast
        assertContrastIsAtLeast(c.getSecondaryAccentColor(), c.getBackgroundColor(), 1);
        assertContrastIsAtLeast(c.getTertiaryAccentColor(), c.getBackgroundColor(), 1);
        assertContrastIsAtLeast(c.getTertiaryFixedDimAccentColor(), c.getBackgroundColor(), 1);

        // The text that is used within the accent color DOES need to have contrast
        assertContrastIsAtLeast(c.getOnTertiaryAccentTextColor(), c.getTertiaryAccentColor(), 4.5);
        assertContrastIsAtLeast(c.getOnTertiaryFixedAccentTextColor(),
                c.getTertiaryFixedDimAccentColor(), 4.5);
    }

    private void resolveColorsInNightMode(boolean nightMode, Notification.Colors c, int rawColor,