Skip to content

Commit 32e4a40

Browse files
Merge pull request #831 from nextcloud/chore/noid/materialColorRepoSyncNov
Automated Code Change sync 19/11/2025
2 parents 3b9bc01 + 0e40da7 commit 32e4a40

File tree

7 files changed

+36
-42
lines changed

7 files changed

+36
-42
lines changed

material-color-utilities/src/main/java/blend/Blend.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,9 @@ public static int hctHue(int from, int to, double amount) {
7676
public static int cam16Ucs(int from, int to, double amount) {
7777
Cam16 fromCam = Cam16.fromInt(from);
7878
Cam16 toCam = Cam16.fromInt(to);
79-
double fromJ = fromCam.getJstar();
80-
double fromA = fromCam.getAstar();
81-
double fromB = fromCam.getBstar();
82-
double toJ = toCam.getJstar();
83-
double toA = toCam.getAstar();
84-
double toB = toCam.getBstar();
85-
double jstar = fromJ + (toJ - fromJ) * amount;
86-
double astar = fromA + (toA - fromA) * amount;
87-
double bstar = fromB + (toB - fromB) * amount;
79+
double jstar = MathUtils.lerp(fromCam.getJstar(), toCam.getJstar(), amount);
80+
double astar = MathUtils.lerp(fromCam.getAstar(), toCam.getAstar(), amount);
81+
double bstar = MathUtils.lerp(fromCam.getBstar(), toCam.getBstar(), amount);
8882
return Cam16.fromUcs(jstar, astar, bstar).toInt();
8983
}
9084
}

material-color-utilities/src/main/java/dynamiccolor/ColorSpec2025.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,8 @@ public DynamicColor onSurface() {
428428
return surfaceContainerHigh();
429429
}
430430
})
431-
.setContrastCurve((s) -> s.isDark ? getContrastCurve(11) : getContrastCurve(9))
431+
.setContrastCurve(
432+
(s) -> s.isDark && s.platform == PHONE ? getContrastCurve(11) : getContrastCurve(9))
432433
.build();
433434
return super.onSurface().toBuilder()
434435
.extendSpecVersion(SpecVersion.SPEC_2025, color2025)
@@ -625,15 +626,23 @@ public DynamicColor primary() {
625626
return tMaxC(s.primaryPalette, 0, 90);
626627
}
627628
} else if (s.variant == EXPRESSIVE) {
628-
return tMaxC(
629-
s.primaryPalette,
630-
0,
631-
Hct.isYellow(s.primaryPalette.getHue())
632-
? 25
633-
: Hct.isCyan(s.primaryPalette.getHue()) ? 88 : 98);
629+
if (s.platform == PHONE) {
630+
return tMaxC(
631+
s.primaryPalette,
632+
0,
633+
Hct.isYellow(s.primaryPalette.getHue())
634+
? 25
635+
: Hct.isCyan(s.primaryPalette.getHue()) ? 88 : 98);
636+
} else { // WATCH
637+
return tMaxC(s.primaryPalette);
638+
}
634639
} else { // VIBRANT
635-
return tMaxC(
636-
s.primaryPalette, 0, Hct.isCyan(s.primaryPalette.getHue()) ? 88 : 98);
640+
if (s.platform == PHONE) {
641+
return tMaxC(
642+
s.primaryPalette, 0, Hct.isCyan(s.primaryPalette.getHue()) ? 88 : 98);
643+
} else { // WATCH
644+
return tMaxC(s.primaryPalette);
645+
}
637646
}
638647
})
639648
.setIsBackground(true)
@@ -1529,7 +1538,7 @@ private static double tMinC(TonalPalette palette, double lowerBound, double uppe
15291538

15301539
private static ContrastCurve getContrastCurve(double defaultContrast) {
15311540
if (defaultContrast == 1.5) {
1532-
return new ContrastCurve(1.5, 1.5, 3, 4.5);
1541+
return new ContrastCurve(1.5, 1.5, 3, 5.5);
15331542
} else if (defaultContrast == 3) {
15341543
return new ContrastCurve(3, 3, 4.5, 7);
15351544
} else if (defaultContrast == 4.5) {

material-color-utilities/src/main/java/dynamiccolor/DynamicColor.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@
4646
* flexibility, any desired behavior of a color for any design system, but it usually unnecessary.
4747
* See the default constructor for more information.
4848
*/
49-
// Prevent lint for Function.apply not being available on Android before API level 14 (4.0.1).
50-
// "AndroidJdkLibsChecker" for Function, "NewApi" for Function.apply().
51-
// A java_library Bazel rule with an Android constraint cannot skip these warnings without this
52-
// annotation; another solution would be to create an android_library rule and supply
53-
// AndroidManifest with an SDK set higher than 14.
54-
@SuppressWarnings("NewApi")
5549
public final class DynamicColor {
5650
public final String name;
5751
public final Function<DynamicScheme, TonalPalette> palette;

material-color-utilities/src/main/java/dynamiccolor/DynamicScheme.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public DynamicScheme(
141141
this.isDark = isDark;
142142
this.contrastLevel = contrastLevel;
143143
this.platform = platform;
144-
this.specVersion = specVersion;
144+
this.specVersion = maybeFallbackSpecVersion(specVersion, variant);
145145

146146
this.primaryPalette = primaryPalette;
147147
this.secondaryPalette = secondaryPalette;
@@ -171,6 +171,17 @@ public static DynamicScheme from(DynamicScheme other, boolean isDark, double con
171171
Optional.of(other.errorPalette));
172172
}
173173

174+
/**
175+
* Returns the spec version to use for the given variant. If the variant is not supported by the
176+
* given spec version, the fallback spec version is returned.
177+
*/
178+
private static SpecVersion maybeFallbackSpecVersion(SpecVersion specVersion, Variant variant) {
179+
return switch (variant) {
180+
case EXPRESSIVE, VIBRANT, TONAL_SPOT, NEUTRAL -> specVersion;
181+
default -> SpecVersion.SPEC_2021;
182+
};
183+
}
184+
174185
/**
175186
* Returns a new hue based on a piecewise function and input color hue.
176187
*

material-color-utilities/src/main/java/dynamiccolor/MaterialDynamicColors.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@
2323
import java.util.function.Supplier;
2424

2525
/** Named colors, otherwise known as tokens, or roles, in the Material Design system. */
26-
// Prevent lint for Function.apply not being available on Android before API level 14 (4.0.1).
27-
// "AndroidJdkLibsChecker" for Function, "NewApi" for Function.apply().
28-
// A java_library Bazel rule with an Android constraint cannot skip these warnings without this
29-
// annotation; another solution would be to create an android_library rule and supply
30-
// AndroidManifest with an SDK set higher than 14.
31-
@SuppressWarnings("NewApi")
3226
public final class MaterialDynamicColors {
3327

3428
private static final ColorSpec colorSpec = new ColorSpec2025();

material-color-utilities/src/main/java/hct/Cam16.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static java.lang.Math.max;
2020

2121
import utils.ColorUtils;
22+
import utils.MathUtils;
2223

2324
/**
2425
* CAM16, a color appearance model. Colors are not just defined by their hex code, but rather, a hex
@@ -246,10 +247,7 @@ static Cam16 fromXyzInViewingConditions(
246247
// hue
247248
double atan2 = Math.atan2(b, a);
248249
double atanDegrees = Math.toDegrees(atan2);
249-
double hue =
250-
atanDegrees < 0
251-
? atanDegrees + 360.0
252-
: atanDegrees >= 360 ? atanDegrees - 360.0 : atanDegrees;
250+
double hue = MathUtils.sanitizeDegreesDouble(atanDegrees);
253251
double hueRadians = Math.toRadians(hue);
254252

255253
// achromatic response to color

material-color-utilities/src/main/java/temperature/TemperatureCache.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,6 @@ private List<Hct> getHctsByHue() {
276276
*
277277
* <p>Sorted from coldest first to warmest last.
278278
*/
279-
// Prevent lint for Comparator not being available on Android before API level 24, 7.0, 2016.
280-
// "AndroidJdkLibsChecker" for one linter, "NewApi" for another.
281-
// A java_library Bazel rule with an Android constraint cannot skip these warnings without this
282-
// annotation; another solution would be to create an android_library rule and supply
283-
// AndroidManifest with an SDK set higher than 23.
284-
@SuppressWarnings("NewApi")
285279
private List<Hct> getHctsByTemp() {
286280
if (precomputedHctsByTemp != null) {
287281
return precomputedHctsByTemp;

0 commit comments

Comments
 (0)