Skip to content

Commit

Permalink
Tonal password strength checker widget
Browse files Browse the repository at this point in the history
Also update APIs:

* Move active container type enum into RadianceThemingSlices
* Add active container type parameter to RadianceSkin.getSystemContainerTokens

For #400
  • Loading branch information
kirill-grouchnikov committed Jan 23, 2025
1 parent 7abbe88 commit c2b38a8
Show file tree
Hide file tree
Showing 19 changed files with 221 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public SampleSkin(RadianceColorScheme accentScheme) {

RadianceColorScheme2 lightColorScheme = ColorSchemeUtils.getColorScheme(
/* palettesSource */ new ColorSchemeUtils.BalancedPaletteSource(Hct.fromInt(0xFF9020F4), 8.0, 6.0),
/* activeStatesContainerType */ ColorSchemeUtils.ActiveStatesContainerType.TONAL,
/* activeStatesContainerType */ RadianceThemingSlices.ActiveContainerType.TONAL,
/* isDark */ false,
/* schemeColorResolver */ SchemeResolverUtils.getSchemeColorResolver());

Expand All @@ -110,7 +110,7 @@ public SampleSkin(RadianceColorScheme accentScheme) {
bundle2.registerActiveContainerTokens(
ColorSchemeUtils.getContainerTokens(
/* seed */ Hct.fromInt(0xFF20F490),
/* activeStatesContainerType */ ColorSchemeUtils.ActiveStatesContainerType.TONAL,
/* activeStatesContainerType */ RadianceThemingSlices.ActiveContainerType.TONAL,
/* isFidelity */ true,
/* isDark */ false),
RadianceThemingSlices.ContainerColorTokensAssociationKind.MARK,
Expand All @@ -119,7 +119,7 @@ public SampleSkin(RadianceColorScheme accentScheme) {
bundle2.registerActiveContainerTokens(
ColorSchemeUtils.getContainerTokens(
/* seed */ Hct.fromInt(0xFF20F490),
/* activeStatesContainerType */ ColorSchemeUtils.ActiveStatesContainerType.TONAL,
/* activeStatesContainerType */ RadianceThemingSlices.ActiveContainerType.TONAL,
/* isFidelity */ true,
/* isDark */ false),
RadianceThemingSlices.ContainerColorTokensAssociationKind.HIGHLIGHT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public PaletteBalancedDemo() {

RadianceColorScheme2 lightColorScheme = ColorSchemeUtils.getColorScheme(
/* palettesSource */ new ColorSchemeUtils.BalancedPaletteSource(Hct.fromInt(0xFF76A8C8), 16.0, 10.0),
/* activeStatesContainerType */ ColorSchemeUtils.ActiveStatesContainerType.TONAL,
/* activeStatesContainerType */ RadianceThemingSlices.ActiveContainerType.TONAL,
/* isDark */ false,
/* schemeColorResolver */ SchemeResolverUtils.getSchemeColorResolver());
RadianceColorScheme2 darkColorScheme = ColorSchemeUtils.getColorScheme(
/* palettesSource */ new ColorSchemeUtils.BalancedPaletteSource(Hct.fromInt(0xFF76A8C8), 16.0, 10.0),
/* activeStatesContainerType */ ColorSchemeUtils.ActiveStatesContainerType.TONAL,
/* activeStatesContainerType */ RadianceThemingSlices.ActiveContainerType.TONAL,
/* isDark */ true,
/* schemeColorResolver */ SchemeResolverUtils.getSchemeColorResolver());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ public PaletteFidelityDemo() {
RadianceColorScheme2 lightColorScheme = ColorSchemeUtils.getColorScheme(
/* palettesSource */ new ColorSchemeUtils.FidelityPaletteSource(
Hct.fromInt(0xFFFDBD72), Hct.fromInt(0xFFFEDCB6), Hct.fromInt(0xFFFFE3C4)),
/* activeStatesContainerType */ ColorSchemeUtils.ActiveStatesContainerType.TONAL,
/* activeStatesContainerType */ RadianceThemingSlices.ActiveContainerType.TONAL,
/* isDark */ false,
/* schemeColorResolver */ SchemeResolverUtils.getSchemeColorResolver());
RadianceColorScheme2 darkColorScheme = ColorSchemeUtils.getColorScheme(
/* palettesSource */ new ColorSchemeUtils.FidelityPaletteSource(
Hct.fromInt(0xFF663E00), Hct.fromInt(0xFF402200), Hct.fromInt(0xFF201200)),
/* activeStatesContainerType */ ColorSchemeUtils.ActiveStatesContainerType.TONAL,
/* activeStatesContainerType */ RadianceThemingSlices.ActiveContainerType.TONAL,
/* isDark */ true,
/* schemeColorResolver */ SchemeResolverUtils.getSchemeColorResolver());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,35 +278,35 @@ public OfficeSilver2007TonalSkin() {
RadianceColorScheme2 officeSilverColorScheme = ColorSchemeUtils.getColorScheme(
/* palettesSource */ new ColorSchemeUtils.FidelityPaletteSource(
Hct.fromInt(0xFFC6CACF), Hct.fromInt(0xFFE6EAEE), Hct.fromInt(0xFFF2F5F5)),
/* activeStatesContainerType */ ColorSchemeUtils.ActiveStatesContainerType.TONAL,
/* activeStatesContainerType */ RadianceThemingSlices.ActiveContainerType.TONAL,
/* isDark */ false,
/* schemeColorResolver */ SchemeResolverUtils.getSchemeColorResolver());
RadianceColorSchemeBundle2 officeSilverDefaultBundle =
new RadianceColorSchemeBundle2(officeSilverColorScheme);

ContainerColorTokens rolloverContainerTokens = ColorSchemeUtils.getContainerTokens(
/* seed */ Hct.fromInt(0xFFFFD111),
/* activeStatesContainerType */ ColorSchemeUtils.ActiveStatesContainerType.TONAL,
/* activeStatesContainerType */ RadianceThemingSlices.ActiveContainerType.TONAL,
/* isFidelity */ true,
/* isDark */ false);
ContainerColorTokens selectedContainerTokens = ColorSchemeUtils.getContainerTokens(
/* seed */ Hct.fromInt(0xFFFFBD51),
/* activeStatesContainerType */ ColorSchemeUtils.ActiveStatesContainerType.TONAL,
/* activeStatesContainerType */ RadianceThemingSlices.ActiveContainerType.TONAL,
/* isFidelity */ true,
/* isDark */ false);
ContainerColorTokens rolloverSelectedContainerTokens = ColorSchemeUtils.getContainerTokens(
/* seed */ Hct.fromInt(0xFFFFA400),
/* activeStatesContainerType */ ColorSchemeUtils.ActiveStatesContainerType.TONAL,
/* activeStatesContainerType */ RadianceThemingSlices.ActiveContainerType.TONAL,
/* isFidelity */ true,
/* isDark */ false);
ContainerColorTokens pressedContainerTokens = ColorSchemeUtils.getContainerTokens(
/* seed */ Hct.fromInt(0xFFFF8C18),
/* activeStatesContainerType */ ColorSchemeUtils.ActiveStatesContainerType.TONAL,
/* activeStatesContainerType */ RadianceThemingSlices.ActiveContainerType.TONAL,
/* isFidelity */ true,
/* isDark */ false);
ContainerColorTokens pressedSelectedContainerTokens = ColorSchemeUtils.getContainerTokens(
/* seed */ Hct.fromInt(0xFFFF991C),
/* activeStatesContainerType */ ColorSchemeUtils.ActiveStatesContainerType.TONAL,
/* activeStatesContainerType */ RadianceThemingSlices.ActiveContainerType.TONAL,
/* isFidelity */ true,
/* isDark */ false);

Expand Down Expand Up @@ -394,7 +394,7 @@ public OfficeSilver2007TonalSkin() {
RadianceColorScheme2 officeSilverHeaderColorScheme = ColorSchemeUtils.getColorScheme(
/* palettesSource */ new ColorSchemeUtils.FidelityPaletteSource(
Hct.fromInt(0xFFCFD4DE), Hct.fromInt(0xFFE6EAEE), Hct.fromInt(0xFFDDDEE1)),
/* activeStatesContainerType */ ColorSchemeUtils.ActiveStatesContainerType.TONAL,
/* activeStatesContainerType */ RadianceThemingSlices.ActiveContainerType.TONAL,
/* isDark */ false,
/* schemeColorResolver */ SchemeResolverUtils.getSchemeColorResolver());
this.registerAsDecorationArea(
Expand All @@ -404,7 +404,7 @@ public OfficeSilver2007TonalSkin() {
RadianceColorScheme2 officeSilverTitleColorScheme = ColorSchemeUtils.getColorScheme(
/* palettesSource */ new ColorSchemeUtils.FidelityPaletteSource(
Hct.fromInt(0xFFC6CACF), Hct.fromInt(0xFFE6EAEE), Hct.fromInt(0xFFCFCFD0)),
/* activeStatesContainerType */ ColorSchemeUtils.ActiveStatesContainerType.TONAL,
/* activeStatesContainerType */ RadianceThemingSlices.ActiveContainerType.TONAL,
/* isDark */ false,
/* schemeColorResolver */ SchemeResolverUtils.getSchemeColorResolver());
this.registerAsDecorationArea(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,31 @@ public ContainerColorTokens getContainerTokens(ComponentState componentState,
}

public ContainerColorTokens getSystemContainerTokens(
RadianceThemingSlices.SystemContainerType systemContainerType) {
RadianceThemingSlices.SystemContainerType systemContainerType,
RadianceThemingSlices.ActiveContainerType activeContainerType) {

switch (systemContainerType) {
case INFO: return this.mainColorScheme.getSystemInfoTonalContainerTokens();
case WARNING: return this.mainColorScheme.getSystemWarningTonalContainerTokens();
case ERROR: return this.mainColorScheme.getSystemErrorTonalContainerTokens();
case SUCCESS: return this.mainColorScheme.getSystemSuccessTonalContainerTokens();
case EMERGENCY:
switch (activeContainerType) {
case TONAL:
switch (systemContainerType) {
case INFO: return this.mainColorScheme.getSystemInfoTonalContainerTokens();
case WARNING: return this.mainColorScheme.getSystemWarningTonalContainerTokens();
case ERROR: return this.mainColorScheme.getSystemErrorTonalContainerTokens();
case SUCCESS: return this.mainColorScheme.getSystemSuccessTonalContainerTokens();
case EMERGENCY:
default:
return this.mainColorScheme.getSystemEmergencyTonalContainerTokens();
}
case PRIMARY:
default:
return this.mainColorScheme.getSystemEmergencyTonalContainerTokens();
switch (systemContainerType) {
case INFO: return this.mainColorScheme.getSystemInfoPrimaryContainerTokens();
case WARNING: return this.mainColorScheme.getSystemWarningPrimaryContainerTokens();
case ERROR: return this.mainColorScheme.getSystemErrorPrimaryContainerTokens();
case SUCCESS: return this.mainColorScheme.getSystemSuccessPrimaryContainerTokens();
case EMERGENCY:
default:
return this.mainColorScheme.getSystemEmergencyPrimaryContainerTokens();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,8 @@ public final ContainerColorTokens getContainerTokens(Component comp,
}

public final ContainerColorTokens getSystemContainerTokens(Component comp,
RadianceThemingSlices.SystemContainerType systemContainerType) {
RadianceThemingSlices.SystemContainerType systemContainerType,
RadianceThemingSlices.ActiveContainerType activeContainerType) {
// small optimization - lookup the decoration area only if there
// are decoration-specific scheme bundles.
if (this.tonalColorSchemeMap.size() > 1) {
Expand All @@ -540,12 +541,12 @@ public final ContainerColorTokens getSystemContainerTokens(Component comp,
RadianceThemingCortex.ComponentOrParentChainScope.getDecorationType(comp);
if (this.tonalColorSchemeMap.containsKey(decorationAreaType)) {
return this.tonalColorSchemeMap.get(decorationAreaType)
.getSystemContainerTokens(systemContainerType);
.getSystemContainerTokens(systemContainerType, activeContainerType);
}
}

return this.tonalColorSchemeMap.get(RadianceThemingSlices.DecorationAreaType.NONE)
.getSystemContainerTokens(systemContainerType);
.getSystemContainerTokens(systemContainerType, activeContainerType);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,10 @@ public enum ContainerType {
PRIMARY
}

public enum ActiveContainerType {
TONAL, PRIMARY
}

public enum SystemContainerType {
INFO,
WARNING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@
import org.pushingpixels.ephemeral.chroma.hct.Hct;
import org.pushingpixels.ephemeral.chroma.palettes.TonalPalette;
import org.pushingpixels.radiance.theming.api.ComponentState;
import org.pushingpixels.radiance.theming.api.RadianceThemingSlices;
import org.pushingpixels.radiance.theming.internal.utils.RadianceColorUtilities;

import java.awt.*;
import java.util.HashMap;

public class ColorSchemeUtils {
public enum ActiveStatesContainerType {
TONAL, PRIMARY
}

private static ContainerColorTokens getContainerTokens(
DynamicScheme dynamicScheme, SchemeContainerColorsResolver tonalContainerColorResolver) {
Expand Down Expand Up @@ -362,7 +360,7 @@ public Palettes getPalettes() {

public static RadianceColorScheme2 getColorScheme(
PalettesSource palettesSource,
ActiveStatesContainerType activeStatesContainerType,
RadianceThemingSlices.ActiveContainerType activeContainerType,
boolean isDark,
SchemeColorResolver schemeColorResolver) {

Expand All @@ -389,35 +387,35 @@ public static RadianceColorScheme2 getColorScheme(
scheme, schemeColorResolver.getPrimaryContainerResolver());

ContainerColorTokens systemInfoTonalContainerTokens = getContainerTokens(
palettes.getSystemInfoSourceHct(), ActiveStatesContainerType.TONAL,
palettes.isFidelity(), isDark);
palettes.getSystemInfoSourceHct(), RadianceThemingSlices.ActiveContainerType.TONAL,
false, isDark);
ContainerColorTokens systemInfoPrimaryContainerTokens = getContainerTokens(
palettes.getSystemInfoSourceHct(), ActiveStatesContainerType.PRIMARY,
palettes.isFidelity(), isDark);
palettes.getSystemInfoSourceHct(), RadianceThemingSlices.ActiveContainerType.PRIMARY,
false, isDark);
ContainerColorTokens systemWarningTonalContainerTokens = getContainerTokens(
palettes.getSystemWarningSourceHct(), ActiveStatesContainerType.TONAL,
palettes.isFidelity(), isDark);
palettes.getSystemWarningSourceHct(), RadianceThemingSlices.ActiveContainerType.TONAL,
false, isDark);
ContainerColorTokens systemWarningPrimaryContainerTokens = getContainerTokens(
palettes.getSystemWarningSourceHct(), ActiveStatesContainerType.PRIMARY,
palettes.isFidelity(), isDark);
palettes.getSystemWarningSourceHct(), RadianceThemingSlices.ActiveContainerType.PRIMARY,
false, isDark);
ContainerColorTokens systemErrorTonalContainerTokens = getContainerTokens(
palettes.getSystemErrorSourceHct(), ActiveStatesContainerType.TONAL,
palettes.isFidelity(), isDark);
palettes.getSystemErrorSourceHct(), RadianceThemingSlices.ActiveContainerType.TONAL,
false, isDark);
ContainerColorTokens systemErrorPrimaryContainerTokens = getContainerTokens(
palettes.getSystemErrorSourceHct(), ActiveStatesContainerType.PRIMARY,
palettes.isFidelity(), isDark);
palettes.getSystemErrorSourceHct(), RadianceThemingSlices.ActiveContainerType.PRIMARY,
false, isDark);
ContainerColorTokens systemSuccessTonalContainerTokens = getContainerTokens(
palettes.getSystemSuccessSourceHct(), ActiveStatesContainerType.TONAL,
palettes.isFidelity(), isDark);
palettes.getSystemSuccessSourceHct(), RadianceThemingSlices.ActiveContainerType.TONAL,
false, isDark);
ContainerColorTokens systemSuccessPrimaryContainerTokens = getContainerTokens(
palettes.getSystemSuccessSourceHct(), ActiveStatesContainerType.PRIMARY,
palettes.isFidelity(), isDark);
palettes.getSystemSuccessSourceHct(), RadianceThemingSlices.ActiveContainerType.PRIMARY,
false, isDark);
ContainerColorTokens systemEmergencyTonalContainerTokens = getContainerTokens(
palettes.getSystemEmergencySourceHct(), ActiveStatesContainerType.TONAL,
palettes.isFidelity(), isDark);
palettes.getSystemEmergencySourceHct(), RadianceThemingSlices.ActiveContainerType.TONAL,
false, isDark);
ContainerColorTokens systemEmergencyPrimaryContainerTokens = getContainerTokens(
palettes.getSystemEmergencySourceHct(), ActiveStatesContainerType.PRIMARY,
palettes.isFidelity(), isDark);
palettes.getSystemEmergencySourceHct(), RadianceThemingSlices.ActiveContainerType.PRIMARY,
false, isDark);

return new RadianceColorScheme2() {
private HashMap<ComponentState, ContainerColorTokens> stateTokens = new HashMap<>();
Expand Down Expand Up @@ -464,7 +462,7 @@ public ContainerColorTokens getPrimaryContainerTokens() {

@Override
public ContainerColorTokens getActiveContainerTokens() {
return (activeStatesContainerType == ActiveStatesContainerType.PRIMARY)
return (activeContainerType == RadianceThemingSlices.ActiveContainerType.PRIMARY)
? this.getPrimaryContainerTokens()
: this.getTonalContainerTokens();
}
Expand Down Expand Up @@ -582,11 +580,11 @@ public ContainerColorTokens getSystemEmergencyPrimaryContainerTokens() {

public static ContainerColorTokens getContainerTokens(
Hct seed,
ActiveStatesContainerType activeStatesContainerType,
RadianceThemingSlices.ActiveContainerType activeContainerType,
boolean isFidelity,
boolean isDark) {
return getContainerTokens(seed, isFidelity, isDark, 0.0,
(activeStatesContainerType == ActiveStatesContainerType.TONAL)
(activeContainerType == RadianceThemingSlices.ActiveContainerType.TONAL)
? PaletteResolverUtils.getPaletteTonalColorResolver()
: PaletteResolverUtils.getPalettePrimaryColorResolver());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public AutumnTonalSkin() {
RadianceColorScheme2 autumnColorScheme = ColorSchemeUtils.getColorScheme(
/* palettesSource */ new ColorSchemeUtils.FidelityPaletteSource(
Hct.fromInt(0xFFFFCB90), Hct.fromInt(0xFFFEDCB6), Hct.fromInt(0xFFFFE2C1)),
/* activeStatesContainerType */ ColorSchemeUtils.ActiveStatesContainerType.TONAL,
/* activeStatesContainerType */ RadianceThemingSlices.ActiveContainerType.TONAL,
/* isDark */ false,
/* schemeColorResolver */ autumnColorResolver);

Expand Down Expand Up @@ -239,7 +239,7 @@ public AutumnTonalSkin() {
RadianceColorScheme2 autumnControlPaneColorScheme = ColorSchemeUtils.getColorScheme(
/* palettesSource */ new ColorSchemeUtils.FidelityPaletteSource(
Hct.fromInt(0xFFFDBD72), Hct.fromInt(0xFFFEDCB6), Hct.fromInt(0xFFFFDDB9)),
/* activeStatesContainerType */ ColorSchemeUtils.ActiveStatesContainerType.TONAL,
/* activeStatesContainerType */ RadianceThemingSlices.ActiveContainerType.TONAL,
/* isDark */ false,
/* schemeColorResolver */ autumnColorResolver);
RadianceColorSchemeBundle2 autumnControlPaneBundle =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected BusinessAccentedTonalSkin(AccentBuilder accentBuilder) {

RadianceColorScheme2 controlPaneColorScheme = ColorSchemeUtils.getColorScheme(
/* palettesSource */ new ColorSchemeUtils.BalancedPaletteSource(Hct.fromInt(0xFFDBDFE4), 3.0, 1.0),
/* activeStatesContainerType */ ColorSchemeUtils.ActiveStatesContainerType.TONAL,
/* activeStatesContainerType */ RadianceThemingSlices.ActiveContainerType.TONAL,
/* isDark */ false,
/* schemeColorResolver */ SchemeResolverUtils.getSchemeColorResolver());
this.registerAsDecorationArea(controlPaneColorScheme.getExtendedTonalContainerTokens(),
Expand Down
Loading

0 comments on commit c2b38a8

Please sign in to comment.