From 2e7170bb21ada34a7ea11bec1f4a462bba5fe9ee Mon Sep 17 00:00:00 2001 From: Lucas Dupin Date: Sat, 21 Mar 2020 17:07:17 -0700 Subject: Set dark theme flag when initializing with Color Users want to be able to use this flag and have been relying on WallpaperColors#fromBitmap given that flags were not parsed by the main constructor. Fixes: 151717291 Test: atest WallpaperColorsTest Change-Id: I0470a867c54756df9a758b24835a50bc67191050 --- core/java/android/app/WallpaperColors.java | 8 ++++++++ tests/Internal/src/android/app/WallpaperColorsTest.java | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/core/java/android/app/WallpaperColors.java b/core/java/android/app/WallpaperColors.java index 6765d0b67c31..e4818b274342 100644 --- a/core/java/android/app/WallpaperColors.java +++ b/core/java/android/app/WallpaperColors.java @@ -222,6 +222,14 @@ public final class WallpaperColors implements Parcelable { public WallpaperColors(@NonNull Color primaryColor, @Nullable Color secondaryColor, @Nullable Color tertiaryColor) { this(primaryColor, secondaryColor, tertiaryColor, 0); + + // Calculate dark theme support based on primary color. + final float[] tmpHsl = new float[3]; + ColorUtils.colorToHSL(primaryColor.toArgb(), tmpHsl); + final float luminance = tmpHsl[2]; + if (luminance < DARK_THEME_MEAN_LUMINANCE) { + mColorHints |= HINT_SUPPORTS_DARK_THEME; + } } /** diff --git a/tests/Internal/src/android/app/WallpaperColorsTest.java b/tests/Internal/src/android/app/WallpaperColorsTest.java index 65ff6eb1ba04..e9bac717daa1 100644 --- a/tests/Internal/src/android/app/WallpaperColorsTest.java +++ b/tests/Internal/src/android/app/WallpaperColorsTest.java @@ -87,6 +87,14 @@ public class WallpaperColorsTest { + "HINT_FROM_BITMAP.", fromBitmap); } + @Test + public void darkMainColorSupportsDarkTheme() { + final Color color = Color.valueOf(Color.BLACK); + WallpaperColors colors = new WallpaperColors(color, null, null); + Assert.assertTrue("Dark theme should be supported by dark main colors.", + (colors.getColorHints() & WallpaperColors.HINT_SUPPORTS_DARK_THEME) != 0); + } + /** * WallpaperColors should not recycle bitmaps that it didn't create. */ -- cgit v1.2.3-59-g8ed1b