Merge "Update libmonet with upstream contrast fixes" into udc-dev
This commit is contained in:
@@ -350,7 +350,7 @@ public final class DynamicColor {
|
|||||||
if (bgDynamicColor != null) {
|
if (bgDynamicColor != null) {
|
||||||
final boolean bgHasBg =
|
final boolean bgHasBg =
|
||||||
bgDynamicColor.background != null && bgDynamicColor.background.apply(scheme)
|
bgDynamicColor.background != null && bgDynamicColor.background.apply(scheme)
|
||||||
== null;
|
!= null;
|
||||||
final double standardRatio =
|
final double standardRatio =
|
||||||
Contrast.ratioOfTones(tone.apply(scheme), bgDynamicColor.tone.apply(scheme));
|
Contrast.ratioOfTones(tone.apply(scheme), bgDynamicColor.tone.apply(scheme));
|
||||||
if (decreasingContrast) {
|
if (decreasingContrast) {
|
||||||
@@ -358,15 +358,15 @@ public final class DynamicColor {
|
|||||||
Contrast.ratioOfTones(
|
Contrast.ratioOfTones(
|
||||||
toneMinContrast.apply(scheme),
|
toneMinContrast.apply(scheme),
|
||||||
bgDynamicColor.toneMinContrast.apply(scheme));
|
bgDynamicColor.toneMinContrast.apply(scheme));
|
||||||
minRatio = bgHasBg ? 1.0 : minContrastRatio;
|
minRatio = bgHasBg ? minContrastRatio : 1.0;
|
||||||
maxRatio = standardRatio;
|
maxRatio = standardRatio;
|
||||||
} else {
|
} else {
|
||||||
final double maxContrastRatio =
|
final double maxContrastRatio =
|
||||||
Contrast.ratioOfTones(
|
Contrast.ratioOfTones(
|
||||||
toneMaxContrast.apply(scheme),
|
toneMaxContrast.apply(scheme),
|
||||||
bgDynamicColor.toneMaxContrast.apply(scheme));
|
bgDynamicColor.toneMaxContrast.apply(scheme));
|
||||||
minRatio = !bgHasBg ? 1.0 : min(maxContrastRatio, standardRatio);
|
minRatio = bgHasBg ? min(maxContrastRatio, standardRatio) : 1.0;
|
||||||
maxRatio = !bgHasBg ? 21.0 : max(maxContrastRatio, standardRatio);
|
maxRatio = bgHasBg ? max(maxContrastRatio, standardRatio) : 21.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,13 +18,21 @@ package com.android.systemui.monet;
|
|||||||
|
|
||||||
import static com.android.systemui.monet.utils.ArgbSubject.assertThat;
|
import static com.android.systemui.monet.utils.ArgbSubject.assertThat;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import androidx.test.filters.SmallTest;
|
import androidx.test.filters.SmallTest;
|
||||||
|
|
||||||
import com.android.systemui.SysuiTestCase;
|
import com.android.systemui.SysuiTestCase;
|
||||||
|
import com.android.systemui.monet.contrast.Contrast;
|
||||||
import com.android.systemui.monet.dynamiccolor.DynamicColor;
|
import com.android.systemui.monet.dynamiccolor.DynamicColor;
|
||||||
|
import com.android.systemui.monet.dynamiccolor.MaterialDynamicColors;
|
||||||
import com.android.systemui.monet.dynamiccolor.ToneDeltaConstraint;
|
import com.android.systemui.monet.dynamiccolor.ToneDeltaConstraint;
|
||||||
import com.android.systemui.monet.dynamiccolor.TonePolarity;
|
import com.android.systemui.monet.dynamiccolor.TonePolarity;
|
||||||
import com.android.systemui.monet.hct.Hct;
|
import com.android.systemui.monet.hct.Hct;
|
||||||
|
import com.android.systemui.monet.scheme.DynamicScheme;
|
||||||
|
import com.android.systemui.monet.scheme.SchemeContent;
|
||||||
|
import com.android.systemui.monet.scheme.SchemeFidelity;
|
||||||
|
import com.android.systemui.monet.scheme.SchemeMonochrome;
|
||||||
import com.android.systemui.monet.scheme.SchemeTonalSpot;
|
import com.android.systemui.monet.scheme.SchemeTonalSpot;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -90,4 +98,92 @@ public final class DynamicColorTest extends SysuiTestCase {
|
|||||||
final SchemeTonalSpot darkScheme = new SchemeTonalSpot(Hct.fromInt(0xff4285f4), true, 0.0);
|
final SchemeTonalSpot darkScheme = new SchemeTonalSpot(Hct.fromInt(0xff4285f4), true, 0.0);
|
||||||
assertThat(dynamicColor.getArgb(darkScheme)).isSameColorAs(0x33ffffff);
|
assertThat(dynamicColor.getArgb(darkScheme)).isSameColorAs(0x33ffffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void respectsContrast() {
|
||||||
|
final Hct[] seedColors =
|
||||||
|
new Hct[]{
|
||||||
|
Hct.fromInt(0xFFFF0000),
|
||||||
|
Hct.fromInt(0xFFFFFF00),
|
||||||
|
Hct.fromInt(0xFF00FF00),
|
||||||
|
Hct.fromInt(0xFF0000FF)
|
||||||
|
};
|
||||||
|
|
||||||
|
final double[] contrastLevels = {-1.0, -0.5, 0.0, 0.5, 1.0};
|
||||||
|
|
||||||
|
for (Hct seedColor : seedColors) {
|
||||||
|
for (double contrastLevel : contrastLevels) {
|
||||||
|
for (boolean isDark : new boolean[]{false, true}) {
|
||||||
|
final DynamicScheme[] schemes =
|
||||||
|
new DynamicScheme[]{
|
||||||
|
new SchemeContent(seedColor, isDark, contrastLevel),
|
||||||
|
new SchemeMonochrome(seedColor, isDark, contrastLevel),
|
||||||
|
new SchemeTonalSpot(seedColor, isDark, contrastLevel),
|
||||||
|
new SchemeFidelity(seedColor, isDark, contrastLevel)
|
||||||
|
};
|
||||||
|
for (final DynamicScheme scheme : schemes) {
|
||||||
|
assertTrue(
|
||||||
|
pairSatisfiesContrast(
|
||||||
|
scheme, MaterialDynamicColors.onPrimary,
|
||||||
|
MaterialDynamicColors.primary));
|
||||||
|
assertTrue(
|
||||||
|
pairSatisfiesContrast(
|
||||||
|
scheme,
|
||||||
|
MaterialDynamicColors.onPrimaryContainer,
|
||||||
|
MaterialDynamicColors.primaryContainer));
|
||||||
|
assertTrue(
|
||||||
|
pairSatisfiesContrast(
|
||||||
|
scheme, MaterialDynamicColors.onSecondary,
|
||||||
|
MaterialDynamicColors.secondary));
|
||||||
|
assertTrue(
|
||||||
|
pairSatisfiesContrast(
|
||||||
|
scheme,
|
||||||
|
MaterialDynamicColors.onSecondaryContainer,
|
||||||
|
MaterialDynamicColors.secondaryContainer));
|
||||||
|
assertTrue(
|
||||||
|
pairSatisfiesContrast(
|
||||||
|
scheme, MaterialDynamicColors.onTertiary,
|
||||||
|
MaterialDynamicColors.tertiary));
|
||||||
|
assertTrue(
|
||||||
|
pairSatisfiesContrast(
|
||||||
|
scheme,
|
||||||
|
MaterialDynamicColors.onTertiaryContainer,
|
||||||
|
MaterialDynamicColors.tertiaryContainer));
|
||||||
|
assertTrue(
|
||||||
|
pairSatisfiesContrast(
|
||||||
|
scheme, MaterialDynamicColors.onError,
|
||||||
|
MaterialDynamicColors.error));
|
||||||
|
assertTrue(
|
||||||
|
pairSatisfiesContrast(
|
||||||
|
scheme,
|
||||||
|
MaterialDynamicColors.onErrorContainer,
|
||||||
|
MaterialDynamicColors.errorContainer));
|
||||||
|
assertTrue(
|
||||||
|
pairSatisfiesContrast(
|
||||||
|
scheme, MaterialDynamicColors.onBackground,
|
||||||
|
MaterialDynamicColors.background));
|
||||||
|
assertTrue(
|
||||||
|
pairSatisfiesContrast(
|
||||||
|
scheme,
|
||||||
|
MaterialDynamicColors.onSurfaceVariant,
|
||||||
|
MaterialDynamicColors.surfaceVariant));
|
||||||
|
assertTrue(
|
||||||
|
pairSatisfiesContrast(
|
||||||
|
scheme,
|
||||||
|
MaterialDynamicColors.onSurfaceInverse,
|
||||||
|
MaterialDynamicColors.surfaceInverse));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean pairSatisfiesContrast(DynamicScheme scheme, DynamicColor fg, DynamicColor bg) {
|
||||||
|
double fgTone = fg.getHct(scheme).getTone();
|
||||||
|
double bgTone = bg.getHct(scheme).getTone();
|
||||||
|
// TODO(b/270915664) - Fix inconsistencies.
|
||||||
|
// TODO(b/270915664) - Minimum requirement should be 4.5 when not reducing contrast.
|
||||||
|
double minimumRequirement = 3.0;
|
||||||
|
return Contrast.ratioOfTones(fgTone, bgTone) >= minimumRequirement;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user