summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author James O'Leary <jamesoleary@google.com> 2021-11-09 11:08:48 -0500
committer James O'Leary <jamesoleary@google.com> 2021-11-09 11:08:48 -0500
commit62918fe10be750bf05bd26f865321692c2ee9ef0 (patch)
tree249730d72fdcf09d7a4fedf51c1d9da5ef0985a9
parent62924f1213ddf532b4837fd5a425c9a5b10b4d29 (diff)
Fix error computing tertiary hue
After adding 60 degrees to the hue, the result needs to be normalized to 0 to 360. Code downstream of Shades.of does not perform the normalization, so the resulting color will be the result of undefined behavior. Test: `atest ColorSchemeTest`, newly added testTertiaryHueWrapsProperly passes. Bug: 204463343 Change-Id: I93168c98ba64fb865888469220571dc6d437105d
-rw-r--r--packages/SystemUI/monet/src/com/android/systemui/monet/ColorScheme.kt3
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/monet/ColorSchemeTest.java10
2 files changed, 12 insertions, 1 deletions
diff --git a/packages/SystemUI/monet/src/com/android/systemui/monet/ColorScheme.kt b/packages/SystemUI/monet/src/com/android/systemui/monet/ColorScheme.kt
index 1844288796cc..0b3eccfd3a91 100644
--- a/packages/SystemUI/monet/src/com/android/systemui/monet/ColorScheme.kt
+++ b/packages/SystemUI/monet/src/com/android/systemui/monet/ColorScheme.kt
@@ -85,9 +85,10 @@ public class ColorScheme(@ColorInt seed: Int, val darkTheme: Boolean) {
val camSeed = Cam.fromInt(seedArgb)
val hue = camSeed.hue
val chroma = camSeed.chroma.coerceAtLeast(ACCENT1_CHROMA)
+ val tertiaryHue = wrapDegrees((hue + ACCENT3_HUE_SHIFT).toInt())
accent1 = Shades.of(hue, chroma).toList()
accent2 = Shades.of(hue, ACCENT2_CHROMA).toList()
- accent3 = Shades.of(hue + ACCENT3_HUE_SHIFT, ACCENT3_CHROMA).toList()
+ accent3 = Shades.of(tertiaryHue.toFloat(), ACCENT3_CHROMA).toList()
neutral1 = Shades.of(hue, NEUTRAL1_CHROMA).toList()
neutral2 = Shades.of(hue, NEUTRAL2_CHROMA).toList()
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/monet/ColorSchemeTest.java b/packages/SystemUI/tests/src/com/android/systemui/monet/ColorSchemeTest.java
index bc86ef98c6fe..8cd7d94d8952 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/monet/ColorSchemeTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/monet/ColorSchemeTest.java
@@ -22,6 +22,7 @@ import android.testing.AndroidTestingRunner;
import androidx.test.filters.SmallTest;
+import com.android.internal.graphics.cam.Cam;
import com.android.systemui.SysuiTestCase;
import org.junit.Assert;
@@ -90,4 +91,13 @@ public class ColorSchemeTest extends SysuiTestCase {
List<Integer> rankedSeedColors = ColorScheme.getSeedColors(wallpaperColors);
Assert.assertEquals(rankedSeedColors, List.of(0xffaec00a, 0xffbe0000, 0xffcc040f));
}
+
+ @Test
+ public void testTertiaryHueWrapsProperly() {
+ int colorInt = 0xffB3588A; // H350 C50 T50
+ ColorScheme colorScheme = new ColorScheme(colorInt, false /* darkTheme */);
+ int tertiaryMid = colorScheme.getAccent3().get(colorScheme.getAccent3().size() / 2);
+ Cam cam = Cam.fromInt(tertiaryMid);
+ Assert.assertEquals(cam.getHue(), 50.0, 10.0);
+ }
}