Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fabe8a0e authored by James O'Leary's avatar James O'Leary
Browse files

Add key color roles, rename surfaces, adjust spec.

Done per chat and commentary on ag/21127519.

- Key colors are a new concept. A key color for a palette is found by
taking the palette's hue and chroma, and searching for the first tone
from T50 that reaches that chroma. Colors made using relativeLstar in
XML will now reach spec.
- Surface names changed after the code landed in the internal source
repo. This CL updates their names.
- Monet Gallery matches Android 2021's output. libmonet Java did not
match. Double-checked that Monet Gallery matched Android,
updated variant specs to match.

Bug: 266731167
Test: atest com.android.systemui.monet, all 389 pass.
Change-Id: I09a8ec9bd8883d124804db31369c595a6aca6a1b
parent 83c4c5da
Loading
Loading
Loading
Loading
+25 −4
Original line number Diff line number Diff line
@@ -57,19 +57,19 @@ public final class MaterialDynamicColors {
    public static final DynamicColor surfaceDim =
            DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 6.0 : 87.0);

    public static final DynamicColor surfaceSub2 =
    public static final DynamicColor surfaceContainerLowest =
            DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 4.0 : 100.0);

    public static final DynamicColor surfaceSub1 =
    public static final DynamicColor surfaceContainerLow =
            DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 10.0 : 96.0);

    public static final DynamicColor surfaceContainer =
            DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 12.0 : 94.0);

    public static final DynamicColor surfaceAdd1 =
    public static final DynamicColor surfaceContainerHigh =
            DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 17.0 : 92.0);

    public static final DynamicColor surfaceAdd2 =
    public static final DynamicColor surfaceContainerHighest =
            DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 22.0 : 90.0);

    public static final DynamicColor onSurface =
@@ -366,6 +366,27 @@ public final class MaterialDynamicColors {
    public static final DynamicColor textHintInverse =
            DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 10.0 : 90.0);

    public static final DynamicColor primaryPaletteKeyColor =
            DynamicColor.fromPalette(
                    (s) -> s.primaryPalette, (s) -> s.primaryPalette.getKeyColor().getTone());

    public static final DynamicColor secondaryPaletteKeyColor =
            DynamicColor.fromPalette(
                    (s) -> s.secondaryPalette, (s) -> s.secondaryPalette.getKeyColor().getTone());

    public static final DynamicColor tertiaryPaletteKeyColor =
            DynamicColor.fromPalette(
                    (s) -> s.tertiaryPalette, (s) -> s.tertiaryPalette.getKeyColor().getTone());

    public static final DynamicColor neutralPaletteKeyColor =
            DynamicColor.fromPalette(
                    (s) -> s.neutralPalette, (s) -> s.neutralPalette.getKeyColor().getTone());

    public static final DynamicColor neutralVariantPaletteKeyColor =
            DynamicColor.fromPalette(
                    (s) -> s.neutralVariantPalette,
                    (s) -> s.neutralVariantPalette.getKeyColor().getTone());

    private static ViewingConditions viewingConditionsForAlbers(DynamicScheme scheme) {
        return ViewingConditions.defaultWithBackgroundLstar(scheme.isDark ? 30.0 : 80.0);
    }
+48 −3
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import java.util.Map;
 */
public final class TonalPalette {
    Map<Integer, Integer> cache;
    Hct keyColor;
    double hue;
    double chroma;

@@ -46,7 +47,7 @@ public final class TonalPalette {
     * @return Tones matching that color's hue and chroma.
     */
    public static TonalPalette fromHct(Hct hct) {
        return TonalPalette.fromHueAndChroma(hct.getHue(), hct.getChroma());
        return new TonalPalette(hct.getHue(), hct.getChroma(), hct);
    }

    /**
@@ -57,13 +58,52 @@ public final class TonalPalette {
     * @return Tones matching hue and chroma.
     */
    public static TonalPalette fromHueAndChroma(double hue, double chroma) {
        return new TonalPalette(hue, chroma);
        return new TonalPalette(hue, chroma, createKeyColor(hue, chroma));
    }

    private TonalPalette(double hue, double chroma) {
    private TonalPalette(double hue, double chroma, Hct keyColor) {
        cache = new HashMap<>();
        this.hue = hue;
        this.chroma = chroma;
        this.keyColor = keyColor;
    }

    /** The key color is the first tone, starting from T50, matching the given hue and chroma. */
    private static Hct createKeyColor(double hue, double chroma) {
        double startTone = 50.0;
        Hct smallestDeltaHct = Hct.from(hue, chroma, startTone);
        double smallestDelta = Math.abs(smallestDeltaHct.getChroma() - chroma);
        // Starting from T50, check T+/-delta to see if they match the requested
        // chroma.
        //
        // Starts from T50 because T50 has the most chroma available, on
        // average. Thus it is most likely to have a direct answer and minimize
        // iteration.
        for (double delta = 1.0; delta < 50.0; delta += 1.0) {
            // Termination condition rounding instead of minimizing delta to avoid
            // case where requested chroma is 16.51, and the closest chroma is 16.49.
            // Error is minimized, but when rounded and displayed, requested chroma
            // is 17, key color's chroma is 16.
            if (Math.round(chroma) == Math.round(smallestDeltaHct.getChroma())) {
                return smallestDeltaHct;
            }

            final Hct hctAdd = Hct.from(hue, chroma, startTone + delta);
            final double hctAddDelta = Math.abs(hctAdd.getChroma() - chroma);
            if (hctAddDelta < smallestDelta) {
                smallestDelta = hctAddDelta;
                smallestDeltaHct = hctAdd;
            }

            final Hct hctSubtract = Hct.from(hue, chroma, startTone - delta);
            final double hctSubtractDelta = Math.abs(hctSubtract.getChroma() - chroma);
            if (hctSubtractDelta < smallestDelta) {
                smallestDelta = hctSubtractDelta;
                smallestDeltaHct = hctSubtract;
            }
        }

        return smallestDeltaHct;
    }

    /**
@@ -98,4 +138,9 @@ public final class TonalPalette {
    public double getHue() {
        return this.hue;
    }

    /** The key color is the first tone, starting from T50, that matches the palette's chroma. */
    public Hct getKeyColor() {
        return this.keyColor;
    }
}
+5 −3
Original line number Diff line number Diff line
@@ -34,14 +34,16 @@ public class SchemeExpressive extends DynamicScheme {
                isDark,
                contrastLevel,
                TonalPalette.fromHueAndChroma(
                        MathUtils.sanitizeDegreesDouble(sourceColorHct.getHue() + 120.0), 40.0),
                        MathUtils.sanitizeDegreesDouble(sourceColorHct.getHue() + 240.0), 40.0),
                TonalPalette.fromHueAndChroma(
                        DynamicScheme.getRotatedHue(sourceColorHct, HUES, SECONDARY_ROTATIONS),
                        24.0),
                TonalPalette.fromHueAndChroma(
                        DynamicScheme.getRotatedHue(sourceColorHct, HUES, TERTIARY_ROTATIONS),
                        32.0),
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 8.0),
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 12.0));
                TonalPalette.fromHueAndChroma(
                        MathUtils.sanitizeDegreesDouble(sourceColorHct.getHue() + 15.0), 8.0),
                TonalPalette.fromHueAndChroma(
                        MathUtils.sanitizeDegreesDouble(sourceColorHct.getHue() + 15.0), 12.0));
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -28,11 +28,11 @@ public class SchemeTonalSpot extends DynamicScheme {
                Variant.TONAL_SPOT,
                isDark,
                contrastLevel,
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 40.0),
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 36.0),
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 16.0),
                TonalPalette.fromHueAndChroma(
                        MathUtils.sanitizeDegreesDouble(sourceColorHct.getHue() + 60.0), 24.0),
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 6.0),
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 4.0),
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 8.0));
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ public class SchemeVibrant extends DynamicScheme {
                TonalPalette.fromHueAndChroma(
                        DynamicScheme.getRotatedHue(sourceColorHct, HUES, TERTIARY_ROTATIONS),
                        32.0),
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 8.0),
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 10.0),
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 12.0));
    }
}
Loading