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

Commit 9547fb5f authored by Lucas Dupin's avatar Lucas Dupin Committed by Android (Google) Code Review
Browse files

Merge "Fix issue with white and black themes"

parents b1e041d5 860f61b4
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -254,6 +254,12 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
        ColorUtils.RGBToHSL(Color.red(color), Color.green(color), Color.blue(color), hslMain);
        hslMain[0] /= 360f;

        // To close to white or black, let's use the default system theme instead of
        // applying a colorized one.
        if (hslMain[2] < 0.05 || hslMain[2] > 0.95) {
            return Color.TRANSPARENT;
        }

        float minDistance = Float.MAX_VALUE;
        int closestColor = Color.TRANSPARENT;
        for (int candidate: candidates) {
@@ -281,7 +287,7 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
        final String overlayPackageJson = mSecureSettings.getStringForUser(
                Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES,
                currentUser);
        if (DEBUG) Log.d(TAG, "updateThemeOverlays: " + overlayPackageJson);
        if (DEBUG) Log.d(TAG, "updateThemeOverlays. Setting: " + overlayPackageJson);
        boolean hasSystemPalette = false;
        boolean hasAccentColor = false;
        final Map<String, String> categoryToPackage = new ArrayMap<>();
+28 −2
Original line number Diff line number Diff line
@@ -147,11 +147,37 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
        verifyNoMoreInteractions(mThemeOverlayApplier);
    }

    @Test
    public void onWallpaperColorsChanged_whiteTheme() {
        WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.WHITE),
                Color.valueOf(Color.BLUE), null);
        mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM);
        ArgumentCaptor<Map<String, String>> themeOverlays = ArgumentCaptor.forClass(Map.class);

        verify(mThemeOverlayApplier).applyCurrentUserOverlays(themeOverlays.capture(), any());

        // Assert that we received the colors that we were expecting
        assertThat(!themeOverlays.getValue().containsKey(OVERLAY_CATEGORY_SYSTEM_PALETTE));
    }

    @Test
    public void onWallpaperColorsChanged_blackTheme() {
        WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.BLACK),
                Color.valueOf(Color.BLUE), null);
        mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM);
        ArgumentCaptor<Map<String, String>> themeOverlays = ArgumentCaptor.forClass(Map.class);

        verify(mThemeOverlayApplier).applyCurrentUserOverlays(themeOverlays.capture(), any());

        // Assert that we received the colors that we were expecting
        assertThat(!themeOverlays.getValue().containsKey(OVERLAY_CATEGORY_SYSTEM_PALETTE));
    }

    @Test
    public void onWallpaperColorsChanged_addsLeadingZerosToColors() {
        // Should ask for a new theme when wallpaper colors change
        WallpaperColors mainColors = new WallpaperColors(Color.valueOf(0x0CCCCC),
                Color.valueOf(0x000111), null);
                Color.valueOf(0x000CCC), null);
        mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM);
        ArgumentCaptor<Map<String, String>> themeOverlays = ArgumentCaptor.forClass(Map.class);

@@ -161,7 +187,7 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
        assertThat(themeOverlays.getValue().get(OVERLAY_CATEGORY_SYSTEM_PALETTE))
                .isEqualTo(MONET_SYSTEM_PALETTE_PACKAGE + "0CCCCC");
        assertThat(themeOverlays.getValue().get(OVERLAY_CATEGORY_ACCENT_COLOR))
                .isEqualTo(MONET_ACCENT_COLOR_PACKAGE + "000111");
                .isEqualTo(MONET_ACCENT_COLOR_PACKAGE + "000CCC");
    }

    @Test