Skip to content

Commit

Permalink
[M3][Color] Expose attr contrastColorThemeOverlay
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 546792664
  • Loading branch information
Material Design Team authored and paulfthomas committed Jul 11, 2023
1 parent e3b255b commit 839b14c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
17 changes: 10 additions & 7 deletions lib/java/com/google/android/material/color/DynamicColors.java
Expand Up @@ -53,6 +53,9 @@ public class DynamicColors {
private static final int[] DYNAMIC_COLOR_THEME_OVERLAY_ATTRIBUTE =
new int[] {R.attr.dynamicColorThemeOverlay};

private static final int[] CONTRAST_COLOR_THEME_OVERLAY_ATTRIBUTE =
new int[] {R.attr.contrastColorThemeOverlay};

@RequiresApi(api = VERSION_CODES.S)
private static final int[] SYSTEM_NEUTRAL_PALETTE_RES_IDS =
new int[] {
Expand Down Expand Up @@ -457,13 +460,13 @@ public static boolean isDynamicColorAvailable() {
private static int getDefaultThemeOverlay(@NonNull Context context) {
// TODO(b/289112889): Remove workaround and roll forward cl/528599594 as soon as U public
// release.
if (isDynamicContrastAvailable(context)) {
return R.style.ThemeOverlay_Material3_DynamicColors_Contrast_DayNight;
}
TypedArray dynamicColorAttributes =
context.obtainStyledAttributes(DYNAMIC_COLOR_THEME_OVERLAY_ATTRIBUTE);
final int theme = dynamicColorAttributes.getResourceId(0, 0);
dynamicColorAttributes.recycle();
int[] themeOverlayAttribute =
isDynamicContrastAvailable(context)
? CONTRAST_COLOR_THEME_OVERLAY_ATTRIBUTE
: DYNAMIC_COLOR_THEME_OVERLAY_ATTRIBUTE;
TypedArray colorAttributes = context.obtainStyledAttributes(themeOverlayAttribute);
final int theme = colorAttributes.getResourceId(0, 0);
colorAttributes.recycle();
return theme;
}

Expand Down
Expand Up @@ -172,6 +172,10 @@
<!-- TODO(b/272585197) Remove after tonal surface migration is complete. -->
<attr name="preUDynamicNeutralChromaUpdateEnabled" format="boolean"/>

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

<!-- Deprecated. -->

<!-- A tonal variation of the primary color. -->
Expand Down
Expand Up @@ -278,6 +278,7 @@

<!-- Theme overlays. -->
<item name="dynamicColorThemeOverlay">@style/ThemeOverlay.Material3.DynamicColors.Light</item>
<item name="contrastColorThemeOverlay">@style/ThemeOverlay.Material3.DynamicColors.Contrast.Light</item>
</style>

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

<!-- Theme overlays. -->
<item name="dynamicColorThemeOverlay">@style/ThemeOverlay.Material3.DynamicColors.Dark</item>
<item name="contrastColorThemeOverlay">@style/ThemeOverlay.Material3.DynamicColors.Contrast.Dark</item>
</style>

<style name="Base.Theme.Material3.Light.Dialog" parent="Base.V14.Theme.Material3.Light.Dialog"/>
Expand Down
Expand Up @@ -17,5 +17,4 @@
<resources>
<style name="ThemeOverlay.Material3.DynamicColors.DayNight" parent="ThemeOverlay.Material3.DynamicColors.Dark" />

<style name="ThemeOverlay.Material3.DynamicColors.Contrast.DayNight" parent="ThemeOverlay.Material3.DynamicColors.Contrast.Dark" />
</resources>
Expand Up @@ -281,6 +281,7 @@

<!-- Theme overlays. -->
<item name="dynamicColorThemeOverlay">@style/ThemeOverlay.Material3.DynamicColors.Light</item>
<item name="contrastColorThemeOverlay">@style/ThemeOverlay.Material3.DynamicColors.Contrast.Light</item>
</style>

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

<!-- Theme overlays. -->
<item name="dynamicColorThemeOverlay">@style/ThemeOverlay.Material3.DynamicColors.Dark</item>
<item name="contrastColorThemeOverlay">@style/ThemeOverlay.Material3.DynamicColors.Contrast.Dark</item>
</style>

<style name="Base.Theme.Material3.Light" parent="Base.V14.Theme.Material3.Light"/>
Expand Down
Expand Up @@ -286,6 +286,4 @@
<item name="android:textColorHighlightInverse">@color/m3_dynamic_contrast_highlighted_text</item>
</style>

<style name="ThemeOverlay.Material3.DynamicColors.Contrast.DayNight" parent="ThemeOverlay.Material3.DynamicColors.Contrast.Light" />

</resources>

0 comments on commit 839b14c

Please sign in to comment.