Merge changes from topic "variants_landing" into tm-dev
* changes: Add color scheme constructor that takes WallpaperColors & Style objects Adjust variants specs to match latest UX spec.
This commit is contained in:
committed by
Android (Google) Code Review
commit
ee74679e85
@@ -23,6 +23,7 @@ import com.android.internal.graphics.ColorUtils
|
|||||||
import com.android.internal.graphics.cam.Cam
|
import com.android.internal.graphics.cam.Cam
|
||||||
import com.android.internal.graphics.cam.CamUtils.lstarFromInt
|
import com.android.internal.graphics.cam.CamUtils.lstarFromInt
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
|
import kotlin.math.max
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
const val TAG = "ColorScheme"
|
const val TAG = "ColorScheme"
|
||||||
@@ -78,36 +79,32 @@ internal class HueSubtract(val amountDegrees: Double) : Hue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal class HueVibrantSecondary() : Hue {
|
internal class HueVibrantSecondary() : Hue {
|
||||||
val hueToRotations = listOf(Pair(24, 15), Pair(53, 15), Pair(91, 15), Pair(123, 15),
|
val hueToRotations = listOf(Pair(0, 18), Pair(41, 15), Pair(61, 10), Pair(101, 12),
|
||||||
Pair(141, 15), Pair(172, 15), Pair(198, 15), Pair(234, 18), Pair(272, 18),
|
Pair(131, 15), Pair(181, 18), Pair(251, 15), Pair(301, 12))
|
||||||
Pair(302, 18), Pair(329, 30), Pair(354, 15))
|
|
||||||
override fun get(sourceColor: Cam): Double {
|
override fun get(sourceColor: Cam): Double {
|
||||||
return getHueRotation(sourceColor.hue, hueToRotations)
|
return getHueRotation(sourceColor.hue, hueToRotations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class HueVibrantTertiary() : Hue {
|
internal class HueVibrantTertiary() : Hue {
|
||||||
val hueToRotations = listOf(Pair(24, 30), Pair(53, 30), Pair(91, 15), Pair(123, 30),
|
val hueToRotations = listOf(Pair(0, 35), Pair(41, 30), Pair(61, 20), Pair(101, 25),
|
||||||
Pair(141, 27), Pair(172, 27), Pair(198, 30), Pair(234, 35), Pair(272, 30),
|
Pair(131, 30), Pair(181, 35), Pair(251, 30), Pair(301, 25))
|
||||||
Pair(302, 30), Pair(329, 60), Pair(354, 30))
|
|
||||||
override fun get(sourceColor: Cam): Double {
|
override fun get(sourceColor: Cam): Double {
|
||||||
return getHueRotation(sourceColor.hue, hueToRotations)
|
return getHueRotation(sourceColor.hue, hueToRotations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class HueExpressiveSecondary() : Hue {
|
internal class HueExpressiveSecondary() : Hue {
|
||||||
val hueToRotations = listOf(Pair(24, 95), Pair(53, 45), Pair(91, 45), Pair(123, 20),
|
val hueToRotations = listOf(Pair(0, 45), Pair(21, 95), Pair(51, 45), Pair(121, 20),
|
||||||
Pair(141, 45), Pair(172, 45), Pair(198, 15), Pair(234, 15),
|
Pair(141, 45), Pair(191, 90), Pair(271, 45), Pair(321, 45))
|
||||||
Pair(272, 45), Pair(302, 45), Pair(329, 45), Pair(354, 45))
|
|
||||||
override fun get(sourceColor: Cam): Double {
|
override fun get(sourceColor: Cam): Double {
|
||||||
return getHueRotation(sourceColor.hue, hueToRotations)
|
return getHueRotation(sourceColor.hue, hueToRotations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class HueExpressiveTertiary() : Hue {
|
internal class HueExpressiveTertiary() : Hue {
|
||||||
val hueToRotations = listOf(Pair(24, 20), Pair(53, 20), Pair(91, 20), Pair(123, 45),
|
val hueToRotations = listOf(Pair(0, 120), Pair(21, 120), Pair(51, 20), Pair(121, 45),
|
||||||
Pair(141, 20), Pair(172, 20), Pair(198, 90), Pair(234, 90), Pair(272, 20),
|
Pair(141, 20), Pair(191, 15), Pair(271, 20), Pair(321, 120))
|
||||||
Pair(302, 20), Pair(329, 120), Pair(354, 120))
|
|
||||||
override fun get(sourceColor: Cam): Double {
|
override fun get(sourceColor: Cam): Double {
|
||||||
return getHueRotation(sourceColor.hue, hueToRotations)
|
return getHueRotation(sourceColor.hue, hueToRotations)
|
||||||
}
|
}
|
||||||
@@ -140,18 +137,15 @@ internal interface Chroma {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class ChromaConstant(val chroma: Double) : Chroma {
|
internal class ChromaMinimum(val chroma: Double) : Chroma {
|
||||||
override fun get(sourceColor: Cam): Double {
|
override fun get(sourceColor: Cam): Double {
|
||||||
return chroma
|
return max(sourceColor.chroma.toDouble(), chroma)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class ChromaExpressiveNeutral() : Chroma {
|
internal class ChromaConstant(val chroma: Double) : Chroma {
|
||||||
val hueToChromas = listOf(Pair(24, 8), Pair(53, 8), Pair(91, 8), Pair(123, 8),
|
|
||||||
Pair(141, 6), Pair(172, 6), Pair(198, 8), Pair(234, 8), Pair(272, 8),
|
|
||||||
Pair(302, 8), Pair(329, 8), Pair(354, 8))
|
|
||||||
override fun get(sourceColor: Cam): Double {
|
override fun get(sourceColor: Cam): Double {
|
||||||
return getSpecifiedChroma(sourceColor.hue, hueToChromas)
|
return chroma
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,17 +181,17 @@ enum class Style(internal val coreSpec: CoreSpec) {
|
|||||||
n2 = TonalSpec(HueSource(), ChromaConstant(8.0))
|
n2 = TonalSpec(HueSource(), ChromaConstant(8.0))
|
||||||
)),
|
)),
|
||||||
VIBRANT(CoreSpec(
|
VIBRANT(CoreSpec(
|
||||||
a1 = TonalSpec(HueSource(), ChromaConstant(48.0)),
|
a1 = TonalSpec(HueSource(), ChromaMinimum(48.0)),
|
||||||
a2 = TonalSpec(HueVibrantSecondary(), ChromaConstant(24.0)),
|
a2 = TonalSpec(HueVibrantSecondary(), ChromaConstant(24.0)),
|
||||||
a3 = TonalSpec(HueVibrantTertiary(), ChromaConstant(32.0)),
|
a3 = TonalSpec(HueVibrantTertiary(), ChromaConstant(32.0)),
|
||||||
n1 = TonalSpec(HueSource(), ChromaConstant(6.0)),
|
n1 = TonalSpec(HueSource(), ChromaConstant(10.0)),
|
||||||
n2 = TonalSpec(HueSource(), ChromaConstant(12.0))
|
n2 = TonalSpec(HueSource(), ChromaConstant(12.0))
|
||||||
)),
|
)),
|
||||||
EXPRESSIVE(CoreSpec(
|
EXPRESSIVE(CoreSpec(
|
||||||
a1 = TonalSpec(HueAdd(240.0), ChromaConstant(40.0)),
|
a1 = TonalSpec(HueAdd(240.0), ChromaConstant(40.0)),
|
||||||
a2 = TonalSpec(HueExpressiveSecondary(), ChromaConstant(24.0)),
|
a2 = TonalSpec(HueExpressiveSecondary(), ChromaConstant(24.0)),
|
||||||
a3 = TonalSpec(HueExpressiveTertiary(), ChromaConstant(40.0)),
|
a3 = TonalSpec(HueExpressiveTertiary(), ChromaConstant(32.0)),
|
||||||
n1 = TonalSpec(HueAdd(15.0), ChromaExpressiveNeutral()),
|
n1 = TonalSpec(HueAdd(15.0), ChromaConstant(8.0)),
|
||||||
n2 = TonalSpec(HueAdd(15.0), ChromaConstant(12.0))
|
n2 = TonalSpec(HueAdd(15.0), ChromaConstant(12.0))
|
||||||
)),
|
)),
|
||||||
RAINBOW(CoreSpec(
|
RAINBOW(CoreSpec(
|
||||||
@@ -231,8 +225,13 @@ class ColorScheme(
|
|||||||
constructor(@ColorInt seed: Int, darkTheme: Boolean):
|
constructor(@ColorInt seed: Int, darkTheme: Boolean):
|
||||||
this(seed, darkTheme, Style.TONAL_SPOT)
|
this(seed, darkTheme, Style.TONAL_SPOT)
|
||||||
|
|
||||||
constructor(wallpaperColors: WallpaperColors, darkTheme: Boolean):
|
@JvmOverloads
|
||||||
this(getSeedColor(wallpaperColors), darkTheme)
|
constructor(
|
||||||
|
wallpaperColors: WallpaperColors,
|
||||||
|
darkTheme: Boolean,
|
||||||
|
style: Style = Style.TONAL_SPOT
|
||||||
|
):
|
||||||
|
this(getSeedColor(wallpaperColors), darkTheme, style)
|
||||||
|
|
||||||
val allAccentColors: List<Int>
|
val allAccentColors: List<Int>
|
||||||
get() {
|
get() {
|
||||||
|
|||||||
@@ -62,6 +62,16 @@ public class ColorSchemeTest extends SysuiTestCase {
|
|||||||
Assert.assertEquals(rankedSeedColors, List.of(0xffaec00a));
|
Assert.assertEquals(rankedSeedColors, List.of(0xffaec00a));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStyleApplied() {
|
||||||
|
WallpaperColors wallpaperColors = new WallpaperColors(Color.valueOf(0xffaec00a),
|
||||||
|
null, null);
|
||||||
|
// Expressive applies hue rotations to the theme color. The input theme color has hue
|
||||||
|
// 117, ensuring the hue changed significantly is a strong signal styles are being applied.
|
||||||
|
ColorScheme colorScheme = new ColorScheme(wallpaperColors, false, Style.EXPRESSIVE);
|
||||||
|
Assert.assertEquals(Cam.fromInt(colorScheme.getAccent1().get(6)).getHue(), 357.46, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFiltersInvalidColors() {
|
public void testFiltersInvalidColors() {
|
||||||
@@ -123,7 +133,7 @@ public class ColorSchemeTest extends SysuiTestCase {
|
|||||||
Style.VIBRANT /* style */);
|
Style.VIBRANT /* style */);
|
||||||
int neutralMid = colorScheme.getNeutral1().get(colorScheme.getNeutral1().size() / 2);
|
int neutralMid = colorScheme.getNeutral1().get(colorScheme.getNeutral1().size() / 2);
|
||||||
Cam cam = Cam.fromInt(neutralMid);
|
Cam cam = Cam.fromInt(neutralMid);
|
||||||
Assert.assertTrue(cam.getChroma() <= 8.0);
|
Assert.assertTrue("chroma was " + cam.getChroma(), Math.floor(cam.getChroma()) <= 10.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user