From ad63d3ff7e2e0fa6a6c23a9c4f50a2f40fc723f1 Mon Sep 17 00:00:00 2001 From: Material Design Team Date: Thu, 19 Oct 2023 09:23:34 -0700 Subject: [PATCH] [M3][Color] Introduce U color tokens PiperOrigin-RevId: 574897222 --- .../android/material/color/DynamicColors.java | 51 +------ .../material/color/res/values-v31/colors.xml | 10 ++ .../material/color/res/values-v34/colors.xml | 28 ++++ .../material/color/res/values-v34/tokens.xml | 120 ++++++++++++++++ .../material/color/res/values/attrs.xml | 4 - .../dialog/res/values/themes_base.xml | 2 - .../theme/res/values-v31/themes_overlay.xml | 16 +-- .../material/theme/res/values/themes_base.xml | 2 - .../theme/res/values/themes_overlay.xml | 134 ------------------ 9 files changed, 167 insertions(+), 200 deletions(-) create mode 100644 lib/java/com/google/android/material/color/res/values-v34/colors.xml create mode 100644 lib/java/com/google/android/material/color/res/values-v34/tokens.xml diff --git a/lib/java/com/google/android/material/color/DynamicColors.java b/lib/java/com/google/android/material/color/DynamicColors.java index ff0164628f1..a0986254258 100644 --- a/lib/java/com/google/android/material/color/DynamicColors.java +++ b/lib/java/com/google/android/material/color/DynamicColors.java @@ -23,13 +23,11 @@ import android.app.Application.ActivityLifecycleCallbacks; import android.app.UiModeManager; import android.content.Context; -import android.content.res.Resources.NotFoundException; import android.content.res.TypedArray; import android.os.Build; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.os.Bundle; -import android.util.Log; import android.view.ContextThemeWrapper; import androidx.annotation.ChecksSdkIntAtLeast; import androidx.annotation.NonNull; @@ -43,16 +41,12 @@ import java.util.HashMap; import java.util.Locale; import java.util.Map; -import java.util.Objects; /** Utility for applying dynamic colors to application/activities. */ 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}; - private static final DeviceSupportCondition DEFAULT_DEVICE_SUPPORT_CONDITION = new DeviceSupportCondition() { @Override @@ -126,11 +120,6 @@ public boolean isSupported() { private static final int USE_DEFAULT_THEME_OVERLAY = 0; private static final String TAG = DynamicColors.class.getSimpleName(); - private static final String SYSTEM_OUTLINE_VARIANT_DARK_RESOURCE_ENTRY_NAME = - "system_outline_variant_dark"; - - private static final int SYSTEM_OUTLINE_VARIANT_DARK_RESOURCE_ID = 0x010600c1; - private DynamicColors() {} /** @@ -326,13 +315,6 @@ public static void applyToActivityIfAvailable( } } else { ThemeUtils.applyThemeOverlay(activity, theme); - // TODO(b/289112889): Remove workaround and roll forward cl/528599594 as soon as U public - // release. Contrast ThemeOverlay is applied on top of Dynamic ThemeOverlay to keep client's - // custom Dynamic theme attributes. - if (isDynamicContrastAvailable(activity)) { - ThemeUtils.applyThemeOverlay( - activity, getDefaultThemeOverlay(activity, CONTRAST_COLOR_THEME_OVERLAY_ATTRIBUTE)); - } } // Applies client's callback after content-based dynamic colors or just dynamic colors has // been applied. @@ -409,16 +391,7 @@ public static Context wrapContextIfAvailable( MaterialColorUtilitiesHelper.createColorResourcesIdsToColorValues(scheme)); } } - Context dynamicContext = new ContextThemeWrapper(originalContext, theme); - // TODO(b/289112889): Remove workaround and roll forward cl/528599594 as soon as U public - // release. Contrast ThemeOverlay is applied on top of Dynamic ThemeOverlay to keep client's - // custom Dynamic theme attributes. - if (isDynamicContrastAvailable(originalContext)) { - return new ContextThemeWrapper( - dynamicContext, - getDefaultThemeOverlay(dynamicContext, CONTRAST_COLOR_THEME_OVERLAY_ATTRIBUTE)); - } - return dynamicContext; + return new ContextThemeWrapper(originalContext, theme); } /** Returns {@code true} if dynamic colors are available on the current SDK level. */ @@ -511,26 +484,4 @@ private static float getSystemContrast(Context context) { ? 0 : uiModeManager.getContrast(); } - - private static boolean isDynamicContrastAvailable(Context context) { - if (VERSION.SDK_INT >= VERSION_CODES.UPSIDE_DOWN_CAKE && areSystemColorRolesDefined(context)) { - return true; - } - return false; - } - - // TODO(b/289112889): Remove workaround and roll forward cl/528599594 as soon as U public release. - // - // This is to check and make sure the last material resource defined in the android block of - // resources matches the resource name from app's context. - private static boolean areSystemColorRolesDefined(Context context) { - try { - return Objects.equals( - context.getResources().getResourceEntryName(SYSTEM_OUTLINE_VARIANT_DARK_RESOURCE_ID), - SYSTEM_OUTLINE_VARIANT_DARK_RESOURCE_ENTRY_NAME); - } catch (NotFoundException e) { - Log.i(TAG, SYSTEM_OUTLINE_VARIANT_DARK_RESOURCE_ENTRY_NAME + " resource not found.", e); - } - return false; - } } diff --git a/lib/java/com/google/android/material/color/res/values-v31/colors.xml b/lib/java/com/google/android/material/color/res/values-v31/colors.xml index 4abd701238e..10c8c3532fa 100644 --- a/lib/java/com/google/android/material/color/res/values-v31/colors.xml +++ b/lib/java/com/google/android/material/color/res/values-v31/colors.xml @@ -90,4 +90,14 @@ @color/m3_ref_palette_dynamic_neutral_variant95 @color/m3_ref_palette_dynamic_neutral_variant99 @color/m3_ref_palette_dynamic_neutral_variant100 + + + @color/m3_sys_color_light_error + @color/m3_sys_color_light_on_error + @color/m3_sys_color_light_error_container + @color/m3_sys_color_light_on_error_container + @color/m3_sys_color_dark_error + @color/m3_sys_color_dark_on_error + @color/m3_sys_color_dark_error_container + @color/m3_sys_color_dark_on_error_container diff --git a/lib/java/com/google/android/material/color/res/values-v34/colors.xml b/lib/java/com/google/android/material/color/res/values-v34/colors.xml new file mode 100644 index 00000000000..8f6b2dcedd4 --- /dev/null +++ b/lib/java/com/google/android/material/color/res/values-v34/colors.xml @@ -0,0 +1,28 @@ + + + + + + @color/m3_sys_color_dynamic_light_error + @color/m3_sys_color_dynamic_light_on_error + @color/m3_sys_color_dynamic_light_error_container + @color/m3_sys_color_dynamic_light_on_error_container + @color/m3_sys_color_dynamic_dark_error + @color/m3_sys_color_dynamic_dark_on_error + @color/m3_sys_color_dynamic_dark_error_container + @color/m3_sys_color_dynamic_dark_on_error_container + diff --git a/lib/java/com/google/android/material/color/res/values-v34/tokens.xml b/lib/java/com/google/android/material/color/res/values-v34/tokens.xml new file mode 100644 index 00000000000..8904f2e1916 --- /dev/null +++ b/lib/java/com/google/android/material/color/res/values-v34/tokens.xml @@ -0,0 +1,120 @@ + + + + + + + + + + @android:color/system_primary_dark + @android:color/system_primary_container_dark + @android:color/system_on_primary_dark + @android:color/system_on_primary_container_dark + @android:color/system_primary_light + + @android:color/system_secondary_dark + @android:color/system_secondary_container_dark + @android:color/system_on_secondary_dark + @android:color/system_on_secondary_container_dark + + @android:color/system_tertiary_dark + @android:color/system_tertiary_container_dark + @android:color/system_on_tertiary_dark + @android:color/system_on_tertiary_container_dark + + @android:color/system_surface_dim_dark + @android:color/system_surface_bright_dark + @android:color/system_surface_container_dark + @android:color/system_surface_container_low_dark + @android:color/system_surface_container_high_dark + @android:color/system_surface_container_lowest_dark + @android:color/system_surface_container_highest_dark + @android:color/system_surface_dark + @android:color/system_surface_variant_dark + @android:color/system_on_surface_dark + @android:color/system_on_surface_variant_dark + @android:color/system_surface_light + @android:color/system_on_surface_light + + @android:color/system_background_dark + @android:color/system_on_background_dark + + @android:color/system_outline_dark + @android:color/system_outline_variant_dark + + @android:color/system_error_dark + @android:color/system_error_container_dark + @android:color/system_on_error_dark + @android:color/system_on_error_container_dark + + + + @android:color/system_primary_fixed + @android:color/system_on_primary_fixed + @android:color/system_primary_fixed_dim + @android:color/system_on_primary_fixed_variant + @android:color/system_primary_light + @android:color/system_primary_container_light + @android:color/system_on_primary_light + @android:color/system_on_primary_container_light + @android:color/system_primary_dark + + @android:color/system_secondary_fixed + @android:color/system_on_secondary_fixed + @android:color/system_secondary_fixed_dim + @android:color/system_on_secondary_fixed_variant + @android:color/system_secondary_light + @android:color/system_secondary_container_light + @android:color/system_on_secondary_light + @android:color/system_on_secondary_container_light + + @android:color/system_tertiary_fixed + @android:color/system_on_tertiary_fixed + @android:color/system_tertiary_fixed_dim + @android:color/system_on_tertiary_fixed_variant + @android:color/system_tertiary_light + @android:color/system_tertiary_container_light + @android:color/system_on_tertiary_light + @android:color/system_on_tertiary_container_light + + @android:color/system_surface_dim_light + @android:color/system_surface_bright_light + @android:color/system_surface_container_light + @android:color/system_surface_container_low_light + @android:color/system_surface_container_high_light + @android:color/system_surface_container_lowest_light + @android:color/system_surface_container_highest_light + @android:color/system_surface_light + @android:color/system_surface_variant_light + @android:color/system_on_surface_light + @android:color/system_on_surface_variant_light + @android:color/system_surface_dark + @android:color/system_on_surface_dark + + @android:color/system_background_light + @android:color/system_on_background_light + + @android:color/system_outline_light + @android:color/system_outline_variant_light + + @android:color/system_error_light + @android:color/system_error_container_light + @android:color/system_on_error_light + @android:color/system_on_error_container_light + + diff --git a/lib/java/com/google/android/material/color/res/values/attrs.xml b/lib/java/com/google/android/material/color/res/values/attrs.xml index b2694ef713c..327d3e92b8d 100644 --- a/lib/java/com/google/android/material/color/res/values/attrs.xml +++ b/lib/java/com/google/android/material/color/res/values/attrs.xml @@ -168,10 +168,6 @@ - - - - diff --git a/lib/java/com/google/android/material/dialog/res/values/themes_base.xml b/lib/java/com/google/android/material/dialog/res/values/themes_base.xml index 75d6debf7d1..f7bdc73ea0c 100644 --- a/lib/java/com/google/android/material/dialog/res/values/themes_base.xml +++ b/lib/java/com/google/android/material/dialog/res/values/themes_base.xml @@ -278,7 +278,6 @@ @style/ThemeOverlay.Material3.DynamicColors.Light - @style/ThemeOverlay.Material3.DynamicColors.Contrast.Light - - -