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

Commit 39b95310 authored by Peter Kalauskas's avatar Peter Kalauskas Committed by Android (Google) Code Review
Browse files

Merge "Add key color roles, rename surfaces, adjust spec."

parents bf242042 fabe8a0e
Loading
Loading
Loading
Loading
+25 −4
Original line number Original line Diff line number Diff line
@@ -57,19 +57,19 @@ public final class MaterialDynamicColors {
    public static final DynamicColor surfaceDim =
    public static final DynamicColor surfaceDim =
            DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 6.0 : 87.0);
            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);
            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);
            DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 10.0 : 96.0);


    public static final DynamicColor surfaceContainer =
    public static final DynamicColor surfaceContainer =
            DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 12.0 : 94.0);
            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);
            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);
            DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 22.0 : 90.0);


    public static final DynamicColor onSurface =
    public static final DynamicColor onSurface =
@@ -366,6 +366,27 @@ public final class MaterialDynamicColors {
    public static final DynamicColor textHintInverse =
    public static final DynamicColor textHintInverse =
            DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 10.0 : 90.0);
            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) {
    private static ViewingConditions viewingConditionsForAlbers(DynamicScheme scheme) {
        return ViewingConditions.defaultWithBackgroundLstar(scheme.isDark ? 30.0 : 80.0);
        return ViewingConditions.defaultWithBackgroundLstar(scheme.isDark ? 30.0 : 80.0);
    }
    }
+48 −3
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import java.util.Map;
 */
 */
public final class TonalPalette {
public final class TonalPalette {
    Map<Integer, Integer> cache;
    Map<Integer, Integer> cache;
    Hct keyColor;
    double hue;
    double hue;
    double chroma;
    double chroma;


@@ -46,7 +47,7 @@ public final class TonalPalette {
     * @return Tones matching that color's hue and chroma.
     * @return Tones matching that color's hue and chroma.
     */
     */
    public static TonalPalette fromHct(Hct hct) {
    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.
     * @return Tones matching hue and chroma.
     */
     */
    public static TonalPalette fromHueAndChroma(double hue, double 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<>();
        cache = new HashMap<>();
        this.hue = hue;
        this.hue = hue;
        this.chroma = chroma;
        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() {
    public double getHue() {
        return this.hue;
        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 Original line Diff line number Diff line
@@ -34,14 +34,16 @@ public class SchemeExpressive extends DynamicScheme {
                isDark,
                isDark,
                contrastLevel,
                contrastLevel,
                TonalPalette.fromHueAndChroma(
                TonalPalette.fromHueAndChroma(
                        MathUtils.sanitizeDegreesDouble(sourceColorHct.getHue() + 120.0), 40.0),
                        MathUtils.sanitizeDegreesDouble(sourceColorHct.getHue() + 240.0), 40.0),
                TonalPalette.fromHueAndChroma(
                TonalPalette.fromHueAndChroma(
                        DynamicScheme.getRotatedHue(sourceColorHct, HUES, SECONDARY_ROTATIONS),
                        DynamicScheme.getRotatedHue(sourceColorHct, HUES, SECONDARY_ROTATIONS),
                        24.0),
                        24.0),
                TonalPalette.fromHueAndChroma(
                TonalPalette.fromHueAndChroma(
                        DynamicScheme.getRotatedHue(sourceColorHct, HUES, TERTIARY_ROTATIONS),
                        DynamicScheme.getRotatedHue(sourceColorHct, HUES, TERTIARY_ROTATIONS),
                        32.0),
                        32.0),
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 8.0),
                TonalPalette.fromHueAndChroma(
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 12.0));
                        MathUtils.sanitizeDegreesDouble(sourceColorHct.getHue() + 15.0), 8.0),
                TonalPalette.fromHueAndChroma(
                        MathUtils.sanitizeDegreesDouble(sourceColorHct.getHue() + 15.0), 12.0));
    }
    }
}
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -28,11 +28,11 @@ public class SchemeTonalSpot extends DynamicScheme {
                Variant.TONAL_SPOT,
                Variant.TONAL_SPOT,
                isDark,
                isDark,
                contrastLevel,
                contrastLevel,
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 40.0),
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 36.0),
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 16.0),
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 16.0),
                TonalPalette.fromHueAndChroma(
                TonalPalette.fromHueAndChroma(
                        MathUtils.sanitizeDegreesDouble(sourceColorHct.getHue() + 60.0), 24.0),
                        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));
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 8.0));
    }
    }
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -38,7 +38,7 @@ public class SchemeVibrant extends DynamicScheme {
                TonalPalette.fromHueAndChroma(
                TonalPalette.fromHueAndChroma(
                        DynamicScheme.getRotatedHue(sourceColorHct, HUES, TERTIARY_ROTATIONS),
                        DynamicScheme.getRotatedHue(sourceColorHct, HUES, TERTIARY_ROTATIONS),
                        32.0),
                        32.0),
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 8.0),
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 10.0),
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 12.0));
                TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), 12.0));
    }
    }
}
}
Loading