From 62918fe10be750bf05bd26f865321692c2ee9ef0 Mon Sep 17 00:00:00 2001 From: James O'Leary Date: Tue, 9 Nov 2021 11:08:48 -0500 Subject: 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 --- .../monet/src/com/android/systemui/monet/ColorScheme.kt | 3 ++- .../tests/src/com/android/systemui/monet/ColorSchemeTest.java | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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 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); + } } -- cgit v1.2.3-59-g8ed1b