Skip to content

Commit

Permalink
[Color] Added Material custom palettes to catalog.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 642730653
  • Loading branch information
pekingme committed Jun 12, 2024
1 parent 6862b6f commit fe8b022
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
16 changes: 13 additions & 3 deletions catalog/java/io/material/catalog/color/ColorHeaderItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
public class ColorHeaderItem implements ColorAdapterItem {

public static final String SYSTEM_PREFIX = "system_";
public static final String MATERIAL_CUSTOM_PALETTE_NAME_SEARCH_WORD = "_ref_palette_dynamic_";
public static final String MATERIAL_CUSTOM_PALETTE_TITLE_PREFIX = "Material custom ";
private static final String COLOR_600 = "600";

@ColorRes private final int backgroundColorRes;
Expand Down Expand Up @@ -54,13 +56,21 @@ public String getDisplayName() {
String name;
int splitIndex = description.lastIndexOf("_");
if (description.startsWith(SYSTEM_PREFIX)) {
// Split the resource name into the color name and value, ie. system_accent1_500 to
// Split the resource name into the color name and value, i.e., system_accent1_500 to
// system_accent1 and 500.
name = description.substring(0, splitIndex);
} else if (description.contains(MATERIAL_CUSTOM_PALETTE_NAME_SEARCH_WORD)) {
// Get the name of the color and value without the search word.
splitIndex = description.lastIndexOf(MATERIAL_CUSTOM_PALETTE_NAME_SEARCH_WORD);
String trimmedResName =
description.substring(splitIndex + MATERIAL_CUSTOM_PALETTE_NAME_SEARCH_WORD.length());
// Split the resource name into the color name and value, i.e., neutral92 to neutral and 92.
List<String> parts = Arrays.asList(trimmedResName.split("(?<=\\D)(?=\\d)", -1));
name = MATERIAL_CUSTOM_PALETTE_TITLE_PREFIX + parts.get(0);
} else {
// Get the name of the color an value without prefixes
// Get the name of the color and value without prefixes
String trimmedResName = description.substring(splitIndex + 1);
// Split the resource name into the color name and value, ie. blue500 to blue and 500.
// Split the resource name into the color name and value, i.e., blue500 to blue and 500.
List<String> parts = Arrays.asList(trimmedResName.split("(?<=\\D)(?=\\d)", -1));
name = parts.get(0);
}
Expand Down
31 changes: 31 additions & 0 deletions catalog/java/io/material/catalog/color/res/values-v31/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<item>@array/m3_colors_accent3_array</item>
<item>@array/m3_colors_neutral1_array</item>
<item>@array/m3_colors_neutral2_array</item>
<item>@array/m3_colors_material_neutral_array</item>
<item>@array/m3_colors_material_neutral_variant_array</item>
</array>

<array name="m3_colors_accent1_array">
Expand Down Expand Up @@ -104,4 +106,33 @@
<item>@android:color/system_neutral2_10</item>
<item>@android:color/system_neutral2_0</item>
</array>

<array name="m3_colors_material_neutral_array">
<item>@color/m3_ref_palette_dynamic_neutral4</item>
<item>@color/m3_ref_palette_dynamic_neutral6</item>
<item>@color/m3_ref_palette_dynamic_neutral12</item>
<item>@color/m3_ref_palette_dynamic_neutral17</item>
<item>@color/m3_ref_palette_dynamic_neutral22</item>
<item>@color/m3_ref_palette_dynamic_neutral24</item>
<item>@color/m3_ref_palette_dynamic_neutral87</item>
<item>@color/m3_ref_palette_dynamic_neutral92</item>
<item>@color/m3_ref_palette_dynamic_neutral94</item>
<item>@color/m3_ref_palette_dynamic_neutral96</item>
<item>@color/m3_ref_palette_dynamic_neutral98</item>
</array>

<array name="m3_colors_material_neutral_variant_array">
<item>@color/m3_ref_palette_dynamic_neutral_variant4</item>
<item>@color/m3_ref_palette_dynamic_neutral_variant6</item>
<item>@color/m3_ref_palette_dynamic_neutral_variant12</item>
<item>@color/m3_ref_palette_dynamic_neutral_variant17</item>
<item>@color/m3_ref_palette_dynamic_neutral_variant22</item>
<item>@color/m3_ref_palette_dynamic_neutral_variant24</item>
<item>@color/m3_ref_palette_dynamic_neutral_variant87</item>
<item>@color/m3_ref_palette_dynamic_neutral_variant92</item>
<item>@color/m3_ref_palette_dynamic_neutral_variant94</item>
<item>@color/m3_ref_palette_dynamic_neutral_variant96</item>
<item>@color/m3_ref_palette_dynamic_neutral_variant98</item>
</array>

</resources>

0 comments on commit fe8b022

Please sign in to comment.