diff options
3 files changed, 239 insertions, 185 deletions
diff --git a/packages/SystemUI/monet/src/com/android/systemui/monet/dynamiccolor/MaterialDynamicColors.java b/packages/SystemUI/monet/src/com/android/systemui/monet/dynamiccolor/MaterialDynamicColors.java index 21218a2dc8e2..9f075e521126 100644 --- a/packages/SystemUI/monet/src/com/android/systemui/monet/dynamiccolor/MaterialDynamicColors.java +++ b/packages/SystemUI/monet/src/com/android/systemui/monet/dynamiccolor/MaterialDynamicColors.java @@ -16,13 +16,15 @@ package com.android.systemui.monet.dynamiccolor; +import android.annotation.NonNull; + import com.android.systemui.monet.dislike.DislikeAnalyzer; import com.android.systemui.monet.hct.Hct; import com.android.systemui.monet.hct.ViewingConditions; import com.android.systemui.monet.scheme.DynamicScheme; import com.android.systemui.monet.scheme.Variant; -/** Named colors, otherwise known as tokens, or roles, in the Material Design system.*/ +/** Named colors, otherwise known as tokens, or roles, in the Material Design system. */ // Prevent lint for Function.apply not being available on Android before API level 14 (4.0.1). // "AndroidJdkLibsChecker" for Function, "NewApi" for Function.apply(). // A java_library Bazel rule with an Android constraint cannot skip these warnings without this @@ -32,190 +34,148 @@ import com.android.systemui.monet.scheme.Variant; public final class MaterialDynamicColors { private static final double CONTAINER_ACCENT_TONE_DELTA = 15.0; - - public MaterialDynamicColors() { - } - - /** - * These colors were present in Android framework before Android U, and used by MDC controls. - * They - * should be avoided, if possible. It's unclear if they're used on multiple backgrounds, and if - * they are, they can't be adjusted for contrast.* For now, they will be set with no background, - * and those won't adjust for contrast, avoiding issues. - * - * <p>* For example, if the same color is on a white background _and_ black background, - * there's no - * way to increase contrast with either without losing contrast with the other. - */ - // colorControlActivated documented as colorAccent in M3 & GM3. - // colorAccent documented as colorSecondary in M3 and colorPrimary in GM3. - // Android used Material's Container as Primary/Secondary/Tertiary at launch. - // Therefore, this is a duplicated version of Primary Container. - public static DynamicColor controlActivated() { - return DynamicColor.fromPalette((s) -> s.primaryPalette, (s) -> s.isDark ? 30.0 : 90.0, null); - } + public MaterialDynamicColors() {} // Compatibility Keys Colors for Android - public static DynamicColor primaryPaletteKeyColor() { + public DynamicColor primaryPaletteKeyColor() { return DynamicColor.fromPalette( (s) -> s.primaryPalette, (s) -> s.primaryPalette.getKeyColor().getTone()); } - public static DynamicColor secondaryPaletteKeyColor() { + public DynamicColor secondaryPaletteKeyColor() { return DynamicColor.fromPalette( (s) -> s.secondaryPalette, (s) -> s.secondaryPalette.getKeyColor().getTone()); } - public static DynamicColor tertiaryPaletteKeyColor() { + public DynamicColor tertiaryPaletteKeyColor() { return DynamicColor.fromPalette( (s) -> s.tertiaryPalette, (s) -> s.tertiaryPalette.getKeyColor().getTone()); } - public static DynamicColor neutralPaletteKeyColor() { + public DynamicColor neutralPaletteKeyColor() { return DynamicColor.fromPalette( (s) -> s.neutralPalette, (s) -> s.neutralPalette.getKeyColor().getTone()); } - public static DynamicColor neutralVariantPaletteKeyColor() { + public DynamicColor neutralVariantPaletteKeyColor() { return 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); - } - - private static boolean isFidelity(DynamicScheme scheme) { - return scheme.variant == Variant.FIDELITY || scheme.variant == Variant.CONTENT; - } - - private static boolean isMonochrome(DynamicScheme scheme) { - return scheme.variant == Variant.MONOCHROME; - } - - static double findDesiredChromaByTone( - double hue, double chroma, double tone, boolean byDecreasingTone) { - double answer = tone; - - Hct closestToChroma = Hct.from(hue, chroma, tone); - if (closestToChroma.getChroma() < chroma) { - double chromaPeak = closestToChroma.getChroma(); - while (closestToChroma.getChroma() < chroma) { - answer += byDecreasingTone ? -1.0 : 1.0; - Hct potentialSolution = Hct.from(hue, chroma, answer); - if (chromaPeak > potentialSolution.getChroma()) { - break; - } - if (Math.abs(potentialSolution.getChroma() - chroma) < 0.4) { - break; - } - - double potentialDelta = Math.abs(potentialSolution.getChroma() - chroma); - double currentDelta = Math.abs(closestToChroma.getChroma() - chroma); - if (potentialDelta < currentDelta) { - closestToChroma = potentialSolution; - } - chromaPeak = Math.max(chromaPeak, potentialSolution.getChroma()); - } - } - - return answer; - } - - static double performAlbers(Hct prealbers, DynamicScheme scheme) { - final Hct albersd = prealbers.inViewingConditions(viewingConditionsForAlbers(scheme)); - if (DynamicColor.tonePrefersLightForeground(prealbers.getTone()) - && !DynamicColor.toneAllowsLightForeground(albersd.getTone())) { - return DynamicColor.enableLightForeground(prealbers.getTone()); - } else { - return DynamicColor.enableLightForeground(albersd.getTone()); - } - } - - public static DynamicColor highestSurface(DynamicScheme s) { + @NonNull + public DynamicColor highestSurface(@NonNull DynamicScheme s) { return s.isDark ? surfaceBright() : surfaceDim(); } - public static DynamicColor background() { + @NonNull + public DynamicColor background() { return DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 6.0 : 98.0); } - public static DynamicColor onBackground() { + @NonNull + public DynamicColor onBackground() { return DynamicColor.fromPalette( (s) -> s.neutralPalette, (s) -> s.isDark ? 90.0 : 10.0, (s) -> background()); } - public static DynamicColor surface() { + @NonNull + public DynamicColor surface() { return DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 6.0 : 98.0); } - public static DynamicColor inverseSurface() { + @NonNull + public DynamicColor inverseSurface() { return DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 90.0 : 20.0); } - public static DynamicColor surfaceBright() { + @NonNull + public DynamicColor surfaceBright() { return DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 24.0 : 98.0); } - public static DynamicColor surfaceDim() { + @NonNull + public DynamicColor surfaceDim() { return DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 6.0 : 87.0); } - public static DynamicColor surfaceContainerLowest() { + @NonNull + public DynamicColor surfaceContainerLowest() { return DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 4.0 : 100.0); } - public static DynamicColor surfaceContainerLow() { + @NonNull + public DynamicColor surfaceContainerLow() { return DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 10.0 : 96.0); } - public static DynamicColor surfaceContainer() { + @NonNull + public DynamicColor surfaceContainer() { return DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 12.0 : 94.0); } - public static DynamicColor surfaceContainerHigh() { + @NonNull + public DynamicColor surfaceContainerHigh() { return DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 17.0 : 92.0); } - public static DynamicColor surfaceContainerHighest() { + @NonNull + public DynamicColor surfaceContainerHighest() { return DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 22.0 : 90.0); } - public static DynamicColor onSurface() { + @NonNull + public DynamicColor onSurface() { return DynamicColor.fromPalette( - (s) -> s.neutralPalette, (s) -> s.isDark ? 90.0 : 10.0, - MaterialDynamicColors::highestSurface); + (s) -> s.neutralPalette, (s) -> s.isDark ? 90.0 : 10.0, this::highestSurface); } - public static DynamicColor inverseOnSurface() { + @NonNull + public DynamicColor inverseOnSurface() { return DynamicColor.fromPalette( (s) -> s.neutralPalette, (s) -> s.isDark ? 20.0 : 95.0, (s) -> inverseSurface()); } - public static DynamicColor surfaceVariant() { - return DynamicColor.fromPalette((s) -> s.neutralVariantPalette, - (s) -> s.isDark ? 30.0 : 90.0); + @NonNull + public DynamicColor surfaceVariant() { + return DynamicColor.fromPalette((s) -> s.neutralVariantPalette, (s) -> s.isDark ? 30.0 : 90.0); } - public static DynamicColor onSurfaceVariant() { + @NonNull + public DynamicColor onSurfaceVariant() { return DynamicColor.fromPalette( - (s) -> s.neutralVariantPalette, (s) -> s.isDark ? 80.0 : 30.0, - (s) -> surfaceVariant()); + (s) -> s.neutralVariantPalette, (s) -> s.isDark ? 80.0 : 30.0, (s) -> surfaceVariant()); } - public static DynamicColor outline() { + @NonNull + public DynamicColor outline() { return DynamicColor.fromPalette( - (s) -> s.neutralVariantPalette, (s) -> 50.0, MaterialDynamicColors::highestSurface); + (s) -> s.neutralVariantPalette, (s) -> s.isDark ? 60.0 : 50.0, this::highestSurface); } - public static DynamicColor outlineVariant() { + @NonNull + public DynamicColor outlineVariant() { return DynamicColor.fromPalette( - (s) -> s.neutralVariantPalette, (s) -> s.isDark ? 30.0 : 80.0, - MaterialDynamicColors::highestSurface); + (s) -> s.neutralVariantPalette, (s) -> s.isDark ? 30.0 : 80.0, this::highestSurface); + } + + @NonNull + public DynamicColor shadow() { + return DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> 0.0); } - public static DynamicColor primaryContainer() { + @NonNull + public DynamicColor scrim() { + return DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> 0.0); + } + + @NonNull + public DynamicColor surfaceTint() { + return DynamicColor.fromPalette((s) -> s.primaryPalette, (s) -> s.isDark ? 80.0 : 40.0); + } + + @NonNull + public DynamicColor primaryContainer() { return DynamicColor.fromPalette( (s) -> s.primaryPalette, (s) -> { @@ -227,10 +187,11 @@ public final class MaterialDynamicColors { } return s.isDark ? 30.0 : 90.0; }, - MaterialDynamicColors::highestSurface); + this::highestSurface); } - public static DynamicColor onPrimaryContainer() { + @NonNull + public DynamicColor onPrimaryContainer() { return DynamicColor.fromPalette( (s) -> s.primaryPalette, (s) -> { @@ -246,7 +207,8 @@ public final class MaterialDynamicColors { null); } - public static DynamicColor primary() { + @NonNull + public DynamicColor primary() { return DynamicColor.fromPalette( (s) -> s.primaryPalette, (s) -> { @@ -255,7 +217,7 @@ public final class MaterialDynamicColors { } return s.isDark ? 80.0 : 40.0; }, - MaterialDynamicColors::highestSurface, + this::highestSurface, (s) -> new ToneDeltaConstraint( CONTAINER_ACCENT_TONE_DELTA, @@ -263,12 +225,14 @@ public final class MaterialDynamicColors { s.isDark ? TonePolarity.DARKER : TonePolarity.LIGHTER)); } - public static DynamicColor inversePrimary() { + @NonNull + public DynamicColor inversePrimary() { return DynamicColor.fromPalette( (s) -> s.primaryPalette, (s) -> s.isDark ? 40.0 : 80.0, (s) -> inverseSurface()); } - public static DynamicColor onPrimary() { + @NonNull + public DynamicColor onPrimary() { return DynamicColor.fromPalette( (s) -> s.primaryPalette, (s) -> { @@ -280,7 +244,8 @@ public final class MaterialDynamicColors { (s) -> primary()); } - public static DynamicColor secondaryContainer() { + @NonNull + public DynamicColor secondaryContainer() { return DynamicColor.fromPalette( (s) -> s.secondaryPalette, (s) -> { @@ -300,10 +265,11 @@ public final class MaterialDynamicColors { answer = performAlbers(s.secondaryPalette.getHct(answer), s); return answer; }, - MaterialDynamicColors::highestSurface); + this::highestSurface); } - public static DynamicColor onSecondaryContainer() { + @NonNull + public DynamicColor onSecondaryContainer() { return DynamicColor.fromPalette( (s) -> s.secondaryPalette, (s) -> { @@ -315,11 +281,12 @@ public final class MaterialDynamicColors { (s) -> secondaryContainer()); } - public static DynamicColor secondary() { + @NonNull + public DynamicColor secondary() { return DynamicColor.fromPalette( (s) -> s.secondaryPalette, (s) -> s.isDark ? 80.0 : 40.0, - MaterialDynamicColors::highestSurface, + this::highestSurface, (s) -> new ToneDeltaConstraint( CONTAINER_ACCENT_TONE_DELTA, @@ -327,7 +294,8 @@ public final class MaterialDynamicColors { s.isDark ? TonePolarity.DARKER : TonePolarity.LIGHTER)); } - public static DynamicColor onSecondary() { + @NonNull + public DynamicColor onSecondary() { return DynamicColor.fromPalette( (s) -> s.secondaryPalette, (s) -> { @@ -339,7 +307,8 @@ public final class MaterialDynamicColors { (s) -> secondary()); } - public static DynamicColor tertiaryContainer() { + @NonNull + public DynamicColor tertiaryContainer() { return DynamicColor.fromPalette( (s) -> s.tertiaryPalette, (s) -> { @@ -354,10 +323,11 @@ public final class MaterialDynamicColors { final Hct proposedHct = s.tertiaryPalette.getHct(albersTone); return DislikeAnalyzer.fixIfDisliked(proposedHct).getTone(); }, - MaterialDynamicColors::highestSurface); + this::highestSurface); } - public static DynamicColor onTertiaryContainer() { + @NonNull + public DynamicColor onTertiaryContainer() { return DynamicColor.fromPalette( (s) -> s.tertiaryPalette, (s) -> { @@ -372,7 +342,8 @@ public final class MaterialDynamicColors { (s) -> tertiaryContainer()); } - public static DynamicColor tertiary() { + @NonNull + public DynamicColor tertiary() { return DynamicColor.fromPalette( (s) -> s.tertiaryPalette, (s) -> { @@ -381,7 +352,7 @@ public final class MaterialDynamicColors { } return s.isDark ? 80.0 : 40.0; }, - MaterialDynamicColors::highestSurface, + this::highestSurface, (s) -> new ToneDeltaConstraint( CONTAINER_ACCENT_TONE_DELTA, @@ -389,7 +360,8 @@ public final class MaterialDynamicColors { s.isDark ? TonePolarity.DARKER : TonePolarity.LIGHTER)); } - public static DynamicColor onTertiary() { + @NonNull + public DynamicColor onTertiary() { return DynamicColor.fromPalette( (s) -> s.tertiaryPalette, (s) -> { @@ -401,22 +373,24 @@ public final class MaterialDynamicColors { (s) -> tertiary()); } - public static DynamicColor errorContainer() { + @NonNull + public DynamicColor errorContainer() { return DynamicColor.fromPalette( - (s) -> s.errorPalette, (s) -> s.isDark ? 30.0 : 90.0, - MaterialDynamicColors::highestSurface); + (s) -> s.errorPalette, (s) -> s.isDark ? 30.0 : 90.0, this::highestSurface); } - public static DynamicColor onErrorContainer() { + @NonNull + public DynamicColor onErrorContainer() { return DynamicColor.fromPalette( (s) -> s.errorPalette, (s) -> s.isDark ? 90.0 : 10.0, (s) -> errorContainer()); } - public static DynamicColor error() { + @NonNull + public DynamicColor error() { return DynamicColor.fromPalette( (s) -> s.errorPalette, (s) -> s.isDark ? 80.0 : 40.0, - MaterialDynamicColors::highestSurface, + this::highestSurface, (s) -> new ToneDeltaConstraint( CONTAINER_ACCENT_TONE_DELTA, @@ -424,113 +398,138 @@ public final class MaterialDynamicColors { s.isDark ? TonePolarity.DARKER : TonePolarity.LIGHTER)); } - public static DynamicColor onError() { + @NonNull + public DynamicColor onError() { return DynamicColor.fromPalette( (s) -> s.errorPalette, (s) -> s.isDark ? 20.0 : 100.0, (s) -> error()); } - public static DynamicColor primaryFixed() { + @NonNull + public DynamicColor primaryFixed() { return DynamicColor.fromPalette( (s) -> s.primaryPalette, (s) -> { if (isMonochrome(s)) { - return s.isDark ? 100.0 : 10.0; + return 40.0; } return 90.0; }, - MaterialDynamicColors::highestSurface); + this::highestSurface); } - public static DynamicColor primaryFixedDim() { + @NonNull + public DynamicColor primaryFixedDim() { return DynamicColor.fromPalette( (s) -> s.primaryPalette, (s) -> { if (isMonochrome(s)) { - return s.isDark ? 90.0 : 20.0; + return 30.0; } return 80.0; }, - MaterialDynamicColors::highestSurface); + this::highestSurface); } - public static DynamicColor onPrimaryFixed() { + @NonNull + public DynamicColor onPrimaryFixed() { return DynamicColor.fromPalette( (s) -> s.primaryPalette, (s) -> { if (isMonochrome(s)) { - return s.isDark ? 10.0 : 90.0; + return 100.0; } return 10.0; }, (s) -> primaryFixedDim()); } - public static DynamicColor onPrimaryFixedVariant() { + @NonNull + public DynamicColor onPrimaryFixedVariant() { return DynamicColor.fromPalette( (s) -> s.primaryPalette, (s) -> { if (isMonochrome(s)) { - return s.isDark ? 30.0 : 70.0; + return 90.0; } return 30.0; }, (s) -> primaryFixedDim()); } - public static DynamicColor secondaryFixed() { + @NonNull + public DynamicColor secondaryFixed() { return DynamicColor.fromPalette( - (s) -> s.secondaryPalette, (s) -> isMonochrome(s) ? 80.0 : 90.0, - MaterialDynamicColors::highestSurface); + (s) -> s.secondaryPalette, (s) -> isMonochrome(s) ? 80.0 : 90.0, this::highestSurface); } - public static DynamicColor secondaryFixedDim() { + @NonNull + public DynamicColor secondaryFixedDim() { return DynamicColor.fromPalette( - (s) -> s.secondaryPalette, (s) -> isMonochrome(s) ? 70.0 : 80.0, - MaterialDynamicColors::highestSurface); + (s) -> s.secondaryPalette, (s) -> isMonochrome(s) ? 70.0 : 80.0, this::highestSurface); } - public static DynamicColor onSecondaryFixed() { + @NonNull + public DynamicColor onSecondaryFixed() { return DynamicColor.fromPalette( (s) -> s.secondaryPalette, (s) -> 10.0, (s) -> secondaryFixedDim()); } - public static DynamicColor onSecondaryFixedVariant() { + @NonNull + public DynamicColor onSecondaryFixedVariant() { return DynamicColor.fromPalette( (s) -> s.secondaryPalette, (s) -> isMonochrome(s) ? 25.0 : 30.0, (s) -> secondaryFixedDim()); } - public static DynamicColor tertiaryFixed() { + @NonNull + public DynamicColor tertiaryFixed() { return DynamicColor.fromPalette( - (s) -> s.tertiaryPalette, (s) -> isMonochrome(s) ? 40.0 : 90.0, - MaterialDynamicColors::highestSurface); + (s) -> s.tertiaryPalette, (s) -> isMonochrome(s) ? 40.0 : 90.0, this::highestSurface); } - public static DynamicColor tertiaryFixedDim() { + @NonNull + public DynamicColor tertiaryFixedDim() { return DynamicColor.fromPalette( - (s) -> s.tertiaryPalette, (s) -> isMonochrome(s) ? 30.0 : 80.0, - MaterialDynamicColors::highestSurface); + (s) -> s.tertiaryPalette, (s) -> isMonochrome(s) ? 30.0 : 80.0, this::highestSurface); } - public static DynamicColor onTertiaryFixed() { + @NonNull + public DynamicColor onTertiaryFixed() { return DynamicColor.fromPalette( - (s) -> s.tertiaryPalette, (s) -> isMonochrome(s) ? 90.0 : 10.0, - (s) -> tertiaryFixedDim()); + (s) -> s.tertiaryPalette, (s) -> isMonochrome(s) ? 100.0 : 10.0, (s) -> tertiaryFixedDim()); } - public static DynamicColor onTertiaryFixedVariant() { + @NonNull + public DynamicColor onTertiaryFixedVariant() { return DynamicColor.fromPalette( - (s) -> s.tertiaryPalette, (s) -> isMonochrome(s) ? 70.0 : 30.0, - (s) -> tertiaryFixedDim()); + (s) -> s.tertiaryPalette, (s) -> isMonochrome(s) ? 90.0 : 30.0, (s) -> tertiaryFixedDim()); + } + + /** + * These colors were present in Android framework before Android U, and used by MDC controls. They + * should be avoided, if possible. It's unclear if they're used on multiple backgrounds, and if + * they are, they can't be adjusted for contrast.* For now, they will be set with no background, + * and those won't adjust for contrast, avoiding issues. + * + * <p>* For example, if the same color is on a white background _and_ black background, there's no + * way to increase contrast with either without losing contrast with the other. + */ + // colorControlActivated documented as colorAccent in M3 & GM3. + // colorAccent documented as colorSecondary in M3 and colorPrimary in GM3. + // Android used Material's Container as Primary/Secondary/Tertiary at launch. + // Therefore, this is a duplicated version of Primary Container. + @NonNull + public DynamicColor controlActivated() { + return DynamicColor.fromPalette((s) -> s.primaryPalette, (s) -> s.isDark ? 30.0 : 90.0, null); } // colorControlNormal documented as textColorSecondary in M3 & GM3. // In Material, textColorSecondary points to onSurfaceVariant in the non-disabled state, // which is Neutral Variant T30/80 in light/dark. - public static DynamicColor controlNormal() { - return DynamicColor.fromPalette((s) -> s.neutralVariantPalette, - (s) -> s.isDark ? 80.0 : 30.0); + @NonNull + public DynamicColor controlNormal() { + return DynamicColor.fromPalette((s) -> s.neutralVariantPalette, (s) -> s.isDark ? 80.0 : 30.0); } // colorControlHighlight documented, in both M3 & GM3: @@ -541,7 +540,8 @@ public final class MaterialDynamicColors { // DynamicColors do not support alpha currently, and _may_ not need it for this use case, // depending on how MDC resolved alpha for the other cases. // Returning black in dark mode, white in light mode. - public static DynamicColor controlHighlight() { + @NonNull + public DynamicColor controlHighlight() { return new DynamicColor( s -> 0.0, s -> 0.0, @@ -549,40 +549,92 @@ public final class MaterialDynamicColors { s -> s.isDark ? 0.20 : 0.12, null, scheme -> - - DynamicColor.toneMinContrastDefault((s) -> s.isDark ? 100.0 : 0.0, null, - scheme, null), + DynamicColor.toneMinContrastDefault((s) -> s.isDark ? 100.0 : 0.0, null, scheme, null), scheme -> - DynamicColor.toneMaxContrastDefault((s) -> s.isDark ? 100.0 : 0.0, null, - scheme, null), + DynamicColor.toneMaxContrastDefault((s) -> s.isDark ? 100.0 : 0.0, null, scheme, null), null); } // textColorPrimaryInverse documented, in both M3 & GM3, documented as N10/N90. - public static DynamicColor textPrimaryInverse() { + @NonNull + public DynamicColor textPrimaryInverse() { return DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 10.0 : 90.0); } // textColorSecondaryInverse and textColorTertiaryInverse both documented, in both M3 & GM3, as // NV30/NV80 - public static DynamicColor textSecondaryAndTertiaryInverse() { - return DynamicColor.fromPalette((s) -> s.neutralVariantPalette, - (s) -> s.isDark ? 30.0 : 80.0); + @NonNull + public DynamicColor textSecondaryAndTertiaryInverse() { + return DynamicColor.fromPalette((s) -> s.neutralVariantPalette, (s) -> s.isDark ? 30.0 : 80.0); } // textColorPrimaryInverseDisableOnly documented, in both M3 & GM3, as N10/N90 - public static DynamicColor textPrimaryInverseDisableOnly() { + @NonNull + public DynamicColor textPrimaryInverseDisableOnly() { return DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 10.0 : 90.0); } // textColorSecondaryInverse and textColorTertiaryInverse in disabled state both documented, // in both M3 & GM3, as N10/N90 - public static DynamicColor textSecondaryAndTertiaryInverseDisabled() { + @NonNull + public DynamicColor textSecondaryAndTertiaryInverseDisabled() { return DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 10.0 : 90.0); } // textColorHintInverse documented, in both M3 & GM3, as N10/N90 - public static DynamicColor textHintInverse() { + @NonNull + public DynamicColor textHintInverse() { return DynamicColor.fromPalette((s) -> s.neutralPalette, (s) -> s.isDark ? 10.0 : 90.0); } -} + + private static ViewingConditions viewingConditionsForAlbers(DynamicScheme scheme) { + return ViewingConditions.defaultWithBackgroundLstar(scheme.isDark ? 30.0 : 80.0); + } + + private static boolean isFidelity(DynamicScheme scheme) { + return scheme.variant == Variant.FIDELITY || scheme.variant == Variant.CONTENT; + } + + private static boolean isMonochrome(DynamicScheme scheme) { + return scheme.variant == Variant.MONOCHROME; + } + + static double findDesiredChromaByTone( + double hue, double chroma, double tone, boolean byDecreasingTone) { + double answer = tone; + + Hct closestToChroma = Hct.from(hue, chroma, tone); + if (closestToChroma.getChroma() < chroma) { + double chromaPeak = closestToChroma.getChroma(); + while (closestToChroma.getChroma() < chroma) { + answer += byDecreasingTone ? -1.0 : 1.0; + Hct potentialSolution = Hct.from(hue, chroma, answer); + if (chromaPeak > potentialSolution.getChroma()) { + break; + } + if (Math.abs(potentialSolution.getChroma() - chroma) < 0.4) { + break; + } + + double potentialDelta = Math.abs(potentialSolution.getChroma() - chroma); + double currentDelta = Math.abs(closestToChroma.getChroma() - chroma); + if (potentialDelta < currentDelta) { + closestToChroma = potentialSolution; + } + chromaPeak = Math.max(chromaPeak, potentialSolution.getChroma()); + } + } + + return answer; + } + + static double performAlbers(Hct prealbers, DynamicScheme scheme) { + final Hct albersd = prealbers.inViewingConditions(viewingConditionsForAlbers(scheme)); + if (DynamicColor.tonePrefersLightForeground(prealbers.getTone()) + && !DynamicColor.toneAllowsLightForeground(albersd.getTone())) { + return DynamicColor.enableLightForeground(prealbers.getTone()); + } else { + return DynamicColor.enableLightForeground(albersd.getTone()); + } + } +}
\ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/theme/DynamicColors.kt b/packages/SystemUI/src/com/android/systemui/theme/DynamicColors.kt index 57b9f914d4d6..ae4820837ce5 100644 --- a/packages/SystemUI/src/com/android/systemui/theme/DynamicColors.kt +++ b/packages/SystemUI/src/com/android/systemui/theme/DynamicColors.kt @@ -18,10 +18,11 @@ package com.android.systemui.theme import android.util.Pair import com.android.systemui.monet.dynamiccolor.DynamicColor -import com.android.systemui.monet.dynamiccolor.MaterialDynamicColors as MDC +import com.android.systemui.monet.dynamiccolor.MaterialDynamicColors class DynamicColors { companion object { + private val MDC = MaterialDynamicColors() @JvmField val ALL_DYNAMIC_COLORS_MAPPED: List<Pair<String, DynamicColor>> = arrayListOf( diff --git a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java index c1999b284553..b78329cfa5aa 100644 --- a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java +++ b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java @@ -659,6 +659,7 @@ public class ThemeOverlayController implements CoreStartable, Dumpable { Resources res = userHandle.isSystem() ? mResources : mContext.createContextAsUser(userHandle, 0).getResources(); Resources.Theme theme = mContext.getTheme(); + MaterialDynamicColors dynamicColors = new MaterialDynamicColors(); if (!(res.getColor(android.R.color.system_accent1_500, theme) == mColorScheme.getAccent1().getS500() && res.getColor(android.R.color.system_accent2_500, theme) @@ -670,15 +671,15 @@ public class ThemeOverlayController implements CoreStartable, Dumpable { && res.getColor(android.R.color.system_neutral2_500, theme) == mColorScheme.getNeutral2().getS500() && res.getColor(android.R.color.system_outline_variant_dark, theme) - == MaterialDynamicColors.outlineVariant().getArgb(mDynamicSchemeDark) + == dynamicColors.outlineVariant().getArgb(mDynamicSchemeDark) && res.getColor(android.R.color.system_outline_variant_light, theme) - == MaterialDynamicColors.outlineVariant().getArgb(mDynamicSchemeLight) + == dynamicColors.outlineVariant().getArgb(mDynamicSchemeLight) && res.getColor(android.R.color.system_primary_container_dark, theme) - == MaterialDynamicColors.primaryContainer().getArgb(mDynamicSchemeDark) + == dynamicColors.primaryContainer().getArgb(mDynamicSchemeDark) && res.getColor(android.R.color.system_primary_container_light, theme) - == MaterialDynamicColors.primaryContainer().getArgb(mDynamicSchemeLight) + == dynamicColors.primaryContainer().getArgb(mDynamicSchemeLight) && res.getColor(android.R.color.system_primary_fixed, theme) - == MaterialDynamicColors.primaryFixed().getArgb(mDynamicSchemeLight))) { + == dynamicColors.primaryFixed().getArgb(mDynamicSchemeLight))) { return false; } } |