Skip to content

Commit 839b14c

Browse files
Material Design Teampaulfthomas
authored andcommitted
[M3][Color] Expose attr contrastColorThemeOverlay
PiperOrigin-RevId: 546792664
1 parent e3b255b commit 839b14c

File tree

6 files changed

+18
-10
lines changed

6 files changed

+18
-10
lines changed

lib/java/com/google/android/material/color/DynamicColors.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public class DynamicColors {
5353
private static final int[] DYNAMIC_COLOR_THEME_OVERLAY_ATTRIBUTE =
5454
new int[] {R.attr.dynamicColorThemeOverlay};
5555

56+
private static final int[] CONTRAST_COLOR_THEME_OVERLAY_ATTRIBUTE =
57+
new int[] {R.attr.contrastColorThemeOverlay};
58+
5659
@RequiresApi(api = VERSION_CODES.S)
5760
private static final int[] SYSTEM_NEUTRAL_PALETTE_RES_IDS =
5861
new int[] {
@@ -457,13 +460,13 @@ public static boolean isDynamicColorAvailable() {
457460
private static int getDefaultThemeOverlay(@NonNull Context context) {
458461
// TODO(b/289112889): Remove workaround and roll forward cl/528599594 as soon as U public
459462
// release.
460-
if (isDynamicContrastAvailable(context)) {
461-
return R.style.ThemeOverlay_Material3_DynamicColors_Contrast_DayNight;
462-
}
463-
TypedArray dynamicColorAttributes =
464-
context.obtainStyledAttributes(DYNAMIC_COLOR_THEME_OVERLAY_ATTRIBUTE);
465-
final int theme = dynamicColorAttributes.getResourceId(0, 0);
466-
dynamicColorAttributes.recycle();
463+
int[] themeOverlayAttribute =
464+
isDynamicContrastAvailable(context)
465+
? CONTRAST_COLOR_THEME_OVERLAY_ATTRIBUTE
466+
: DYNAMIC_COLOR_THEME_OVERLAY_ATTRIBUTE;
467+
TypedArray colorAttributes = context.obtainStyledAttributes(themeOverlayAttribute);
468+
final int theme = colorAttributes.getResourceId(0, 0);
469+
colorAttributes.recycle();
467470
return theme;
468471
}
469472

lib/java/com/google/android/material/color/res/values/attrs.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@
172172
<!-- TODO(b/272585197) Remove after tonal surface migration is complete. -->
173173
<attr name="preUDynamicNeutralChromaUpdateEnabled" format="boolean"/>
174174

175+
<!-- The temporary contrast color theme overlay to use when applying contrast colors. -->
176+
<!-- TODO(b/289112889): Remove workaround and roll forward cl/528599594 as soon as U public release. -->
177+
<attr name="contrastColorThemeOverlay" format="reference"/>
178+
175179
<!-- Deprecated. -->
176180

177181
<!-- A tonal variation of the primary color. -->

lib/java/com/google/android/material/dialog/res/values/themes_base.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@
278278

279279
<!-- Theme overlays. -->
280280
<item name="dynamicColorThemeOverlay">@style/ThemeOverlay.Material3.DynamicColors.Light</item>
281+
<item name="contrastColorThemeOverlay">@style/ThemeOverlay.Material3.DynamicColors.Contrast.Light</item>
281282
</style>
282283

283284
<style name="Base.V14.Theme.Material3.Dark.Dialog" parent="Theme.MaterialComponents.Dialog">
@@ -539,6 +540,7 @@
539540

540541
<!-- Theme overlays. -->
541542
<item name="dynamicColorThemeOverlay">@style/ThemeOverlay.Material3.DynamicColors.Dark</item>
543+
<item name="contrastColorThemeOverlay">@style/ThemeOverlay.Material3.DynamicColors.Contrast.Dark</item>
542544
</style>
543545

544546
<style name="Base.Theme.Material3.Light.Dialog" parent="Base.V14.Theme.Material3.Light.Dialog"/>

lib/java/com/google/android/material/theme/res/values-night/themes_overlay.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@
1717
<resources>
1818
<style name="ThemeOverlay.Material3.DynamicColors.DayNight" parent="ThemeOverlay.Material3.DynamicColors.Dark" />
1919

20-
<style name="ThemeOverlay.Material3.DynamicColors.Contrast.DayNight" parent="ThemeOverlay.Material3.DynamicColors.Contrast.Dark" />
2120
</resources>

lib/java/com/google/android/material/theme/res/values/themes_base.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@
281281

282282
<!-- Theme overlays. -->
283283
<item name="dynamicColorThemeOverlay">@style/ThemeOverlay.Material3.DynamicColors.Light</item>
284+
<item name="contrastColorThemeOverlay">@style/ThemeOverlay.Material3.DynamicColors.Contrast.Light</item>
284285
</style>
285286

286287
<style name="Base.V14.Theme.Material3.Dark" parent="Theme.MaterialComponents">
@@ -545,6 +546,7 @@
545546

546547
<!-- Theme overlays. -->
547548
<item name="dynamicColorThemeOverlay">@style/ThemeOverlay.Material3.DynamicColors.Dark</item>
549+
<item name="contrastColorThemeOverlay">@style/ThemeOverlay.Material3.DynamicColors.Contrast.Dark</item>
548550
</style>
549551

550552
<style name="Base.Theme.Material3.Light" parent="Base.V14.Theme.Material3.Light"/>

lib/java/com/google/android/material/theme/res/values/themes_overlay.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,4 @@
286286
<item name="android:textColorHighlightInverse">@color/m3_dynamic_contrast_highlighted_text</item>
287287
</style>
288288

289-
<style name="ThemeOverlay.Material3.DynamicColors.Contrast.DayNight" parent="ThemeOverlay.Material3.DynamicColors.Contrast.Light" />
290-
291289
</resources>

0 commit comments

Comments
 (0)