diff options
| author | 2023-05-07 12:21:16 -0700 | |
|---|---|---|
| committer | 2023-05-08 18:04:15 +0000 | |
| commit | 866745daac9a0204481880a7fa9a7296c614cd57 (patch) | |
| tree | bceb052b38e155390bb89043269a22089d95ebeb | |
| parent | de6724e24f0c2d6e48e8717c78868cdcef969a11 (diff) | |
Do not add suffix to fixed colors
Fixed colors only exist once. They need special logic when being
assigned to overlays.
Fixes: 280128998
Test: Change colors, look at bouncer
Test: atest ThemeOverlayControllerTest
Change-Id: I001f7cf7987702de787ce29592985b990668d89d
3 files changed, 68 insertions, 14 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/theme/DynamicColors.kt b/packages/SystemUI/src/com/android/systemui/theme/DynamicColors.kt index 58f22466d44d..57b9f914d4d6 100644 --- a/packages/SystemUI/src/com/android/systemui/theme/DynamicColors.kt +++ b/packages/SystemUI/src/com/android/systemui/theme/DynamicColors.kt @@ -56,18 +56,6 @@ class DynamicColors { Pair.create("on_error", MDC.onError()), Pair.create("error_container", MDC.errorContainer()), Pair.create("on_error_container", MDC.onErrorContainer()), - Pair.create("primary_fixed", MDC.primaryFixed()), - Pair.create("primary_fixed_dim", MDC.primaryFixedDim()), - Pair.create("on_primary_fixed", MDC.onPrimaryFixed()), - Pair.create("on_primary_fixed_variant", MDC.onPrimaryFixedVariant()), - Pair.create("secondary_fixed", MDC.secondaryFixed()), - Pair.create("secondary_fixed_dim", MDC.secondaryFixedDim()), - Pair.create("on_secondary_fixed", MDC.onSecondaryFixed()), - Pair.create("on_secondary_fixed_variant", MDC.onSecondaryFixedVariant()), - Pair.create("tertiary_fixed", MDC.tertiaryFixed()), - Pair.create("tertiary_fixed_dim", MDC.tertiaryFixedDim()), - Pair.create("on_tertiary_fixed", MDC.onTertiaryFixed()), - Pair.create("on_tertiary_fixed_variant", MDC.onTertiaryFixedVariant()), Pair.create("control_activated", MDC.controlActivated()), Pair.create("control_normal", MDC.controlNormal()), Pair.create("control_highlight", MDC.controlHighlight()), @@ -92,7 +80,24 @@ class DynamicColors { Pair.create( "palette_key_color_neutral_variant", MDC.neutralVariantPaletteKeyColor() - ) + ), + ) + + @JvmField + val FIXED_COLORS_MAPPED: List<Pair<String, DynamicColor>> = + arrayListOf( + Pair.create("primary_fixed", MDC.primaryFixed()), + Pair.create("primary_fixed_dim", MDC.primaryFixedDim()), + Pair.create("on_primary_fixed", MDC.onPrimaryFixed()), + Pair.create("on_primary_fixed_variant", MDC.onPrimaryFixedVariant()), + Pair.create("secondary_fixed", MDC.secondaryFixed()), + Pair.create("secondary_fixed_dim", MDC.secondaryFixedDim()), + Pair.create("on_secondary_fixed", MDC.onSecondaryFixed()), + Pair.create("on_secondary_fixed_variant", MDC.onSecondaryFixedVariant()), + Pair.create("tertiary_fixed", MDC.tertiaryFixed()), + Pair.create("tertiary_fixed_dim", MDC.tertiaryFixedDim()), + Pair.create("on_tertiary_fixed", MDC.onTertiaryFixed()), + Pair.create("on_tertiary_fixed_variant", MDC.onTertiaryFixedVariant()), ) } } diff --git a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java index 4b73d6190d99..c1999b284553 100644 --- a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java +++ b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java @@ -624,6 +624,7 @@ public class ThemeOverlayController implements CoreStartable, Dumpable { FabricatedOverlay overlay = newFabricatedOverlay("dynamic"); assignDynamicPaletteToOverlay(overlay, true /* isDark */); assignDynamicPaletteToOverlay(overlay, false /* isDark */); + assignFixedColorsToOverlay(overlay); return overlay; } @@ -638,6 +639,15 @@ public class ThemeOverlayController implements CoreStartable, Dumpable { }); } + private void assignFixedColorsToOverlay(FabricatedOverlay overlay) { + DynamicColors.FIXED_COLORS_MAPPED.forEach(p -> { + String resourceName = "android:color/system_" + p.first; + int colorValue = p.second.getArgb(mDynamicSchemeLight); + overlay.setResourceValue(resourceName, TYPE_INT_COLOR_ARGB8, colorValue, + null /* configuration */); + }); + } + /** * Checks if the color scheme in mColorScheme matches the current system palettes. * @param managedProfiles List of managed profiles for this user. @@ -666,7 +676,9 @@ public class ThemeOverlayController implements CoreStartable, Dumpable { && res.getColor(android.R.color.system_primary_container_dark, theme) == MaterialDynamicColors.primaryContainer().getArgb(mDynamicSchemeDark) && res.getColor(android.R.color.system_primary_container_light, theme) - == MaterialDynamicColors.primaryContainer().getArgb(mDynamicSchemeLight))) { + == MaterialDynamicColors.primaryContainer().getArgb(mDynamicSchemeLight) + && res.getColor(android.R.color.system_primary_fixed, theme) + == MaterialDynamicColors.primaryFixed().getArgb(mDynamicSchemeLight))) { return false; } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java index 17b5e0546eca..09ac0e312e21 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java @@ -16,6 +16,8 @@ package com.android.systemui.theme; +import static android.util.TypedValue.TYPE_INT_COLOR_ARGB8; + import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_AWAKE; import static com.android.systemui.theme.ThemeOverlayApplier.OVERLAY_CATEGORY_ACCENT_COLOR; import static com.android.systemui.theme.ThemeOverlayApplier.OVERLAY_CATEGORY_SYSTEM_PALETTE; @@ -29,6 +31,7 @@ import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; @@ -926,4 +929,38 @@ public class ThemeOverlayControllerTest extends SysuiTestCase { verify(mThemeOverlayApplier, never()).applyCurrentUserOverlays(any(), any(), anyInt(), any()); } + + @Test + public void createDynamicOverlay_addsAllDynamicColors() { + // Trigger new wallpaper colors to generate an overlay + WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.RED), + Color.valueOf(Color.BLUE), null); + mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM, + USER_SYSTEM); + ArgumentCaptor<FabricatedOverlay[]> themeOverlays = + ArgumentCaptor.forClass(FabricatedOverlay[].class); + + verify(mThemeOverlayApplier) + .applyCurrentUserOverlays(any(), themeOverlays.capture(), anyInt(), any()); + + FabricatedOverlay[] overlays = themeOverlays.getValue(); + FabricatedOverlay accents = overlays[0]; + FabricatedOverlay neutrals = overlays[1]; + FabricatedOverlay dynamic = overlays[2]; + + final int colorsPerPalette = 12; + + // Color resources were added for all 3 accent palettes + verify(accents, times(colorsPerPalette * 3)) + .setResourceValue(any(String.class), eq(TYPE_INT_COLOR_ARGB8), anyInt(), eq(null)); + // Color resources were added for all 2 neutral palettes + verify(neutrals, times(colorsPerPalette * 2)) + .setResourceValue(any(String.class), eq(TYPE_INT_COLOR_ARGB8), anyInt(), eq(null)); + // All dynamic colors were added twice: light and dark them + // All fixed colors were added once + verify(dynamic, times( + DynamicColors.ALL_DYNAMIC_COLORS_MAPPED.size() * 2 + + DynamicColors.FIXED_COLORS_MAPPED.size()) + ).setResourceValue(any(String.class), eq(TYPE_INT_COLOR_ARGB8), anyInt(), eq(null)); + } } |