Skip to content

Commit 9c2c419

Browse files
ikim24dsn5ft
authored andcommitted
[Color] Update theme switcher to have customizable text for the description above the radio buttons for choosing color
PiperOrigin-RevId: 355223824
1 parent 0d0c90b commit 9c2c419

File tree

4 files changed

+55
-5
lines changed

4 files changed

+55
-5
lines changed

catalog/java/io/material/catalog/themeswitcher/ThemeSwitcherDialogFragment.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@
3333
import android.view.ViewGroup;
3434
import android.widget.LinearLayout;
3535
import android.widget.RadioGroup;
36+
import android.widget.TextView;
3637
import androidx.annotation.ArrayRes;
3738
import androidx.annotation.ColorInt;
3839
import androidx.annotation.IdRes;
3940
import androidx.annotation.NonNull;
4041
import androidx.annotation.Nullable;
42+
import androidx.annotation.StringRes;
4143
import androidx.annotation.StyleRes;
4244
import androidx.annotation.StyleableRes;
4345
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
@@ -112,6 +114,8 @@ public View onCreateView(
112114
resourceProvider.getPrimaryColorsContentDescription(),
113115
resourceProvider.getPrimaryThemeOverlayAttrs(),
114116
R.id.theme_feature_primary_color,
117+
view.findViewById(R.id.primary_colors_label),
118+
resourceProvider.getPrimaryColorsGroupDescription(),
115119
ThemingType.COLOR);
116120

117121
secondaryColorGroup = view.findViewById(R.id.secondary_colors);
@@ -121,6 +125,8 @@ public View onCreateView(
121125
resourceProvider.getSecondaryColorsContentDescription(),
122126
resourceProvider.getSecondaryThemeOverlayAttrs(),
123127
R.id.theme_feature_secondary_color,
128+
view.findViewById(R.id.secondary_colors_label),
129+
resourceProvider.getSecondaryColorsGroupDescription(),
124130
ThemingType.COLOR);
125131

126132
shapeCornerFamilyGroup = view.findViewById(R.id.shape_families);
@@ -129,6 +135,8 @@ public View onCreateView(
129135
resourceProvider.getShapes(),
130136
resourceProvider.getShapesContentDescription(),
131137
R.id.theme_feature_corner_family,
138+
view.findViewById(R.id.shape_families_label),
139+
resourceProvider.getShapesGroupDescription(),
132140
ThemingType.SHAPE_CORNER_FAMILY);
133141

134142
shapeCornerSizeGroup = view.findViewById(R.id.shape_corner_sizes);
@@ -137,6 +145,8 @@ public View onCreateView(
137145
resourceProvider.getShapeSizes(),
138146
resourceProvider.getShapeSizesContentDescription(),
139147
R.id.theme_feature_corner_size,
148+
view.findViewById(R.id.shape_corner_sizes_label),
149+
resourceProvider.getShapeSizesGroupDescription(),
140150
ThemingType.SHAPE_CORNER_SIZE);
141151

142152
View applyButton = view.findViewById(R.id.apply_button);
@@ -203,9 +213,18 @@ private void initializeThemingValues(
203213
@ArrayRes int overlays,
204214
@ArrayRes int contentDescriptions,
205215
@IdRes int overlayId,
216+
TextView groupLabel,
217+
@StringRes int groupDescriptionResId,
206218
ThemingType themingType) {
207219
initializeThemingValues(
208-
group, overlays, contentDescriptions, new int[] {}, overlayId, themingType);
220+
group,
221+
overlays,
222+
contentDescriptions,
223+
new int[] {},
224+
overlayId,
225+
groupLabel,
226+
groupDescriptionResId,
227+
themingType);
209228
}
210229

211230
private void initializeThemingValues(
@@ -214,7 +233,11 @@ private void initializeThemingValues(
214233
@ArrayRes int contentDescriptions,
215234
@StyleableRes int[] themeOverlayAttrs,
216235
@IdRes int overlayId,
236+
TextView groupLabel,
237+
@StringRes int groupDescriptionResId,
217238
ThemingType themingType) {
239+
groupLabel.setText(groupDescriptionResId);
240+
218241
TypedArray themingValues = getResources().obtainTypedArray(overlays);
219242
TypedArray contentDescriptionArray = getResources().obtainTypedArray(contentDescriptions);
220243
if (themingValues.length() != contentDescriptionArray.length()) {

catalog/java/io/material/catalog/themeswitcher/ThemeSwitcherResourceProvider.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import androidx.annotation.ArrayRes;
2222
import androidx.annotation.AttrRes;
23+
import androidx.annotation.StringRes;
2324
import androidx.annotation.StyleableRes;
2425

2526
/** A helper class that facilitates overriding of theme switcher resources in the Catalog app. */
@@ -67,6 +68,16 @@ public int getSecondaryColorsContentDescription() {
6768
return R.array.mtrl_palettes_content_description;
6869
}
6970

71+
@StringRes
72+
public int getPrimaryColorsGroupDescription() {
73+
return R.string.mtrl_primary_color_description;
74+
}
75+
76+
@StringRes
77+
public int getSecondaryColorsGroupDescription() {
78+
return R.string.mtrl_secondary_color_description;
79+
}
80+
7081
public int getShapes() {
7182
return R.array.mtrl_shape_overlays;
7283
}
@@ -75,11 +86,21 @@ public int getShapesContentDescription() {
7586
return R.array.mtrl_shapes_content_description;
7687
}
7788

89+
@StringRes
90+
public int getShapesGroupDescription() {
91+
return R.string.mtrl_shape_corner_family;
92+
}
93+
7894
public int getShapeSizes() {
7995
return R.array.mtrl_shape_size_overlays;
8096
}
8197

8298
public int getShapeSizesContentDescription() {
8399
return R.array.mtrl_shape_size_content_description;
84100
}
101+
102+
@StringRes
103+
public int getShapeSizesGroupDescription() {
104+
return R.string.mtrl_shape_corner_size;
105+
}
85106
}

catalog/java/io/material/catalog/themeswitcher/res/layout/mtrl_theme_switcher_dialog.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
<TextView
8585
android:layout_width="wrap_content"
8686
android:layout_height="wrap_content"
87-
android:text="\?attr/colorPrimary"/>
87+
android:id="@+id/primary_colors_label"/>
8888
<HorizontalScrollView
8989
android:layout_width="wrap_content"
9090
android:layout_height="wrap_content"
@@ -100,7 +100,7 @@
100100
<TextView
101101
android:layout_width="wrap_content"
102102
android:layout_height="wrap_content"
103-
android:text="\?attr/colorSecondary"/>
103+
android:id="@+id/secondary_colors_label"/>
104104
<HorizontalScrollView
105105
android:layout_width="wrap_content"
106106
android:layout_height="wrap_content"
@@ -123,7 +123,7 @@
123123
<TextView
124124
android:layout_width="wrap_content"
125125
android:layout_height="wrap_content"
126-
android:text="@string/mtrl_shape_corner_family"/>
126+
android:id="@+id/shape_families_label"/>
127127

128128
<RadioGroup
129129
android:id="@+id/shape_families"
@@ -159,7 +159,7 @@
159159
<TextView
160160
android:layout_width="wrap_content"
161161
android:layout_height="wrap_content"
162-
android:text="@string/mtrl_shape_corner_size"/>
162+
android:id="@+id/shape_corner_sizes_label"/>
163163

164164
<RadioGroup
165165
android:id="@+id/shape_corner_sizes"

catalog/java/io/material/catalog/themeswitcher/res/values/strings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
<string name="mtrl_theme_switcher_cancel">Cancel</string>
2222
<string name="mtrl_theme_switcher_reset">Reset</string>
2323

24+
<string name="mtrl_primary_color_description" translatable="false">
25+
\?attr/colorPrimary
26+
</string>
27+
<string name="mtrl_secondary_color_description" translatable="false">
28+
\?attr/colorSecondary
29+
</string>
2430
<string name="mtrl_red">Red</string>
2531
<string name="mtrl_purple">Purple</string>
2632
<string name="mtrl_indigo">Indigo</string>

0 commit comments

Comments
 (0)