Pick the primary color as the best color to use.
Previously, the best color was picked by checking the colors
against the blacklist. The logic was for picking the best color
was broken When the blacklist was removed for
b/124180048.
Fixes: b129762944
Test: New test points added to TonalTest.java
Change-Id: Ie51806735910bb40e5e66d7baf545ea213e4a01e
diff --git a/tests/Internal/Android.bp b/tests/Internal/Android.bp
index 4cb9f8d5..e233fed 100644
--- a/tests/Internal/Android.bp
+++ b/tests/Internal/Android.bp
@@ -10,6 +10,7 @@
"junit",
"androidx.test.rules",
"mockito-target-minus-junit4",
+ "truth-prebuilt",
],
java_resource_dirs: ["res"],
certificate: "platform",
diff --git a/tests/Internal/src/com/android/internal/colorextraction/types/TonalTest.java b/tests/Internal/src/com/android/internal/colorextraction/types/TonalTest.java
index 300182d..768e47c 100644
--- a/tests/Internal/src/com/android/internal/colorextraction/types/TonalTest.java
+++ b/tests/Internal/src/com/android/internal/colorextraction/types/TonalTest.java
@@ -15,6 +15,8 @@
*/
package com.android.internal.colorextraction.types;
+import static com.google.common.truth.Truth.assertThat;
+
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -67,6 +69,36 @@
}
@Test
+ public void extractInto_fromBitmap() {
+ Tonal tonal = new Tonal(InstrumentationRegistry.getContext());
+ GradientColors normal = new GradientColors();
+ GradientColors dark = new GradientColors();
+ GradientColors extraDark = new GradientColors();
+ WallpaperColors wallColors = new WallpaperColors(Color.valueOf(Color.RED), null, null,
+ WallpaperColors.HINT_FROM_BITMAP);
+
+ // WHEN colors are extracted from a wallpaper with only a red primary color.
+ tonal.extractInto(wallColors, normal, dark, extraDark);
+ // THEN the main extracted color is red
+ assertThat(normal.getMainColor()).isEqualTo(Color.RED);
+ }
+
+ @Test
+ public void extractInto_supportsDarkText() {
+ Tonal tonal = new Tonal(InstrumentationRegistry.getContext());
+ GradientColors normal = new GradientColors();
+ GradientColors dark = new GradientColors();
+ GradientColors extraDark = new GradientColors();
+ WallpaperColors wallColors = new WallpaperColors(Color.valueOf(Color.RED), null, null,
+ WallpaperColors.HINT_SUPPORTS_DARK_TEXT);
+
+ // WHEN colors are extracted from a wallpaper with only a red primary color.
+ tonal.extractInto(wallColors, normal, dark, extraDark);
+ // THEN the main extracted color is red
+ assertThat(normal.getMainColor()).isEqualTo(Color.RED);
+ }
+
+ @Test
public void colorRange_containsColor() {
Tonal.ColorRange colorRange = new Tonal.ColorRange(new Range<>(0f, 50f),
new Range<>(0f, 1f), new Range<>(0f, 1f));