Skip to content

Commit fe8b022

Browse files
committed
[Color] Added Material custom palettes to catalog.
PiperOrigin-RevId: 642730653
1 parent 6862b6f commit fe8b022

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

catalog/java/io/material/catalog/color/ColorHeaderItem.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
public class ColorHeaderItem implements ColorAdapterItem {
2727

2828
public static final String SYSTEM_PREFIX = "system_";
29+
public static final String MATERIAL_CUSTOM_PALETTE_NAME_SEARCH_WORD = "_ref_palette_dynamic_";
30+
public static final String MATERIAL_CUSTOM_PALETTE_TITLE_PREFIX = "Material custom ";
2931
private static final String COLOR_600 = "600";
3032

3133
@ColorRes private final int backgroundColorRes;
@@ -54,13 +56,21 @@ public String getDisplayName() {
5456
String name;
5557
int splitIndex = description.lastIndexOf("_");
5658
if (description.startsWith(SYSTEM_PREFIX)) {
57-
// Split the resource name into the color name and value, ie. system_accent1_500 to
59+
// Split the resource name into the color name and value, i.e., system_accent1_500 to
5860
// system_accent1 and 500.
5961
name = description.substring(0, splitIndex);
62+
} else if (description.contains(MATERIAL_CUSTOM_PALETTE_NAME_SEARCH_WORD)) {
63+
// Get the name of the color and value without the search word.
64+
splitIndex = description.lastIndexOf(MATERIAL_CUSTOM_PALETTE_NAME_SEARCH_WORD);
65+
String trimmedResName =
66+
description.substring(splitIndex + MATERIAL_CUSTOM_PALETTE_NAME_SEARCH_WORD.length());
67+
// Split the resource name into the color name and value, i.e., neutral92 to neutral and 92.
68+
List<String> parts = Arrays.asList(trimmedResName.split("(?<=\\D)(?=\\d)", -1));
69+
name = MATERIAL_CUSTOM_PALETTE_TITLE_PREFIX + parts.get(0);
6070
} else {
61-
// Get the name of the color an value without prefixes
71+
// Get the name of the color and value without prefixes
6272
String trimmedResName = description.substring(splitIndex + 1);
63-
// Split the resource name into the color name and value, ie. blue500 to blue and 500.
73+
// Split the resource name into the color name and value, i.e., blue500 to blue and 500.
6474
List<String> parts = Arrays.asList(trimmedResName.split("(?<=\\D)(?=\\d)", -1));
6575
name = parts.get(0);
6676
}

catalog/java/io/material/catalog/color/res/values-v31/arrays.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
<item>@array/m3_colors_accent3_array</item>
2424
<item>@array/m3_colors_neutral1_array</item>
2525
<item>@array/m3_colors_neutral2_array</item>
26+
<item>@array/m3_colors_material_neutral_array</item>
27+
<item>@array/m3_colors_material_neutral_variant_array</item>
2628
</array>
2729

2830
<array name="m3_colors_accent1_array">
@@ -104,4 +106,33 @@
104106
<item>@android:color/system_neutral2_10</item>
105107
<item>@android:color/system_neutral2_0</item>
106108
</array>
109+
110+
<array name="m3_colors_material_neutral_array">
111+
<item>@color/m3_ref_palette_dynamic_neutral4</item>
112+
<item>@color/m3_ref_palette_dynamic_neutral6</item>
113+
<item>@color/m3_ref_palette_dynamic_neutral12</item>
114+
<item>@color/m3_ref_palette_dynamic_neutral17</item>
115+
<item>@color/m3_ref_palette_dynamic_neutral22</item>
116+
<item>@color/m3_ref_palette_dynamic_neutral24</item>
117+
<item>@color/m3_ref_palette_dynamic_neutral87</item>
118+
<item>@color/m3_ref_palette_dynamic_neutral92</item>
119+
<item>@color/m3_ref_palette_dynamic_neutral94</item>
120+
<item>@color/m3_ref_palette_dynamic_neutral96</item>
121+
<item>@color/m3_ref_palette_dynamic_neutral98</item>
122+
</array>
123+
124+
<array name="m3_colors_material_neutral_variant_array">
125+
<item>@color/m3_ref_palette_dynamic_neutral_variant4</item>
126+
<item>@color/m3_ref_palette_dynamic_neutral_variant6</item>
127+
<item>@color/m3_ref_palette_dynamic_neutral_variant12</item>
128+
<item>@color/m3_ref_palette_dynamic_neutral_variant17</item>
129+
<item>@color/m3_ref_palette_dynamic_neutral_variant22</item>
130+
<item>@color/m3_ref_palette_dynamic_neutral_variant24</item>
131+
<item>@color/m3_ref_palette_dynamic_neutral_variant87</item>
132+
<item>@color/m3_ref_palette_dynamic_neutral_variant92</item>
133+
<item>@color/m3_ref_palette_dynamic_neutral_variant94</item>
134+
<item>@color/m3_ref_palette_dynamic_neutral_variant96</item>
135+
<item>@color/m3_ref_palette_dynamic_neutral_variant98</item>
136+
</array>
137+
107138
</resources>

0 commit comments

Comments
 (0)