Merge "Merge "Set dark theme flag when initializing with Color" into rvc-dev am: 59dc371fed am: 4c69e80709" into rvc-d1-dev-plus-aosp am: 7f371d3ada am: 9d0e8ec62c

Change-Id: I12aa8f8607e9fe2090a89cb21472026636c3d674
This commit is contained in:
Automerger Merge Worker 2020-03-24 02:52:41 +00:00
commit 37b4e02c38
2 changed files with 16 additions and 0 deletions

View File

@ -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;
}
}
/**

View File

@ -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.
*/