Skip to content

Commit

Permalink
Add an API that returns all dynamic color tokens in Java.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 705080669
  • Loading branch information
Ash Huynh authored and copybara-github committed Dec 11, 2024
1 parent ca894db commit dbdf4c4
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions java/dynamiccolor/MaterialDynamicColors.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
package dynamiccolor;

import androidx.annotation.NonNull;
import com.google.common.base.Function;
import dislike.DislikeAnalyzer;
import hct.Hct;
import java.util.Arrays;
import java.util.List;

/** 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).
Expand Down Expand Up @@ -933,6 +936,73 @@ public DynamicColor textHintInverse() {
"text_hint_inverse", (s) -> s.neutralPalette, (s) -> s.isDark ? 10.0 : 90.0);
}

@NonNull
public static List<Function<MaterialDynamicColors, DynamicColor>> allDynamicColors() {
return Arrays.asList(
MaterialDynamicColors::primaryPaletteKeyColor,
MaterialDynamicColors::secondaryPaletteKeyColor,
MaterialDynamicColors::tertiaryPaletteKeyColor,
MaterialDynamicColors::neutralPaletteKeyColor,
MaterialDynamicColors::neutralVariantPaletteKeyColor,
MaterialDynamicColors::background,
MaterialDynamicColors::onBackground,
MaterialDynamicColors::surface,
MaterialDynamicColors::surfaceDim,
MaterialDynamicColors::surfaceBright,
MaterialDynamicColors::surfaceContainerLowest,
MaterialDynamicColors::surfaceContainerLow,
MaterialDynamicColors::surfaceContainer,
MaterialDynamicColors::surfaceContainerHigh,
MaterialDynamicColors::surfaceContainerHighest,
MaterialDynamicColors::onSurface,
MaterialDynamicColors::surfaceVariant,
MaterialDynamicColors::onSurfaceVariant,
MaterialDynamicColors::inverseSurface,
MaterialDynamicColors::inverseOnSurface,
MaterialDynamicColors::outline,
MaterialDynamicColors::outlineVariant,
MaterialDynamicColors::shadow,
MaterialDynamicColors::scrim,
MaterialDynamicColors::surfaceTint,
MaterialDynamicColors::primary,
MaterialDynamicColors::onPrimary,
MaterialDynamicColors::primaryContainer,
MaterialDynamicColors::onPrimaryContainer,
MaterialDynamicColors::inversePrimary,
MaterialDynamicColors::secondary,
MaterialDynamicColors::onSecondary,
MaterialDynamicColors::secondaryContainer,
MaterialDynamicColors::onSecondaryContainer,
MaterialDynamicColors::tertiary,
MaterialDynamicColors::onTertiary,
MaterialDynamicColors::tertiaryContainer,
MaterialDynamicColors::onTertiaryContainer,
MaterialDynamicColors::error,
MaterialDynamicColors::onError,
MaterialDynamicColors::errorContainer,
MaterialDynamicColors::onErrorContainer,
MaterialDynamicColors::primaryFixed,
MaterialDynamicColors::primaryFixedDim,
MaterialDynamicColors::onPrimaryFixed,
MaterialDynamicColors::onPrimaryFixedVariant,
MaterialDynamicColors::secondaryFixed,
MaterialDynamicColors::secondaryFixedDim,
MaterialDynamicColors::onSecondaryFixed,
MaterialDynamicColors::onSecondaryFixedVariant,
MaterialDynamicColors::tertiaryFixed,
MaterialDynamicColors::tertiaryFixedDim,
MaterialDynamicColors::onTertiaryFixed,
MaterialDynamicColors::onTertiaryFixedVariant,
MaterialDynamicColors::controlActivated,
MaterialDynamicColors::controlNormal,
MaterialDynamicColors::controlHighlight,
MaterialDynamicColors::textPrimaryInverse,
MaterialDynamicColors::textSecondaryAndTertiaryInverse,
MaterialDynamicColors::textPrimaryInverseDisableOnly,
MaterialDynamicColors::textSecondaryAndTertiaryInverseDisabled,
MaterialDynamicColors::textHintInverse);
}

private boolean isFidelity(DynamicScheme scheme) {
if (this.isExtendedFidelity
&& scheme.variant != Variant.MONOCHROME
Expand Down

0 comments on commit dbdf4c4

Please sign in to comment.