|
18 | 18 |
|
19 | 19 | import io.material.catalog.R; |
20 | 20 |
|
21 | | -import android.annotation.SuppressLint; |
22 | 21 | import android.app.Dialog; |
23 | 22 | import android.content.Context; |
24 | | -import android.content.res.ColorStateList; |
25 | 23 | import android.content.res.TypedArray; |
26 | | -import android.graphics.Color; |
27 | 24 | import android.os.Bundle; |
28 | | -import androidx.core.view.MarginLayoutParamsCompat; |
29 | | -import androidx.core.widget.CompoundButtonCompat; |
30 | 25 | import androidx.appcompat.widget.AppCompatRadioButton; |
31 | 26 | import android.view.LayoutInflater; |
32 | 27 | import android.view.View; |
33 | 28 | import android.view.ViewGroup; |
34 | | -import android.widget.LinearLayout; |
35 | 29 | import android.widget.RadioGroup; |
36 | 30 | import android.widget.TextView; |
37 | 31 | import androidx.annotation.ArrayRes; |
38 | | -import androidx.annotation.ColorInt; |
39 | 32 | import androidx.annotation.IdRes; |
40 | 33 | import androidx.annotation.NonNull; |
41 | 34 | import androidx.annotation.Nullable; |
|
48 | 41 | import dagger.android.DispatchingAndroidInjector; |
49 | 42 | import dagger.android.HasAndroidInjector; |
50 | 43 | import dagger.android.support.AndroidSupportInjection; |
| 44 | +import io.material.catalog.themeswitcher.ThemeAttributeValuesCreator.ThemeAttributeValues; |
51 | 45 | import io.material.catalog.windowpreferences.WindowPreferencesManager; |
52 | 46 | import javax.inject.Inject; |
53 | 47 |
|
@@ -77,6 +71,7 @@ private enum ThemingType { |
77 | 71 | } |
78 | 72 |
|
79 | 73 | @Inject ThemeSwitcherResourceProvider resourceProvider; |
| 74 | + @Inject ThemeAttributeValuesCreator themeAttributeValuesCreator; |
80 | 75 | private RadioGroup primaryColorGroup; |
81 | 76 | private RadioGroup secondaryColorGroup; |
82 | 77 | private RadioGroup shapeCornerFamilyGroup; |
@@ -251,14 +246,17 @@ private void initializeThemingValues( |
251 | 246 | // Create RadioButtons for themeAttributeValues values |
252 | 247 | switch (themingType) { |
253 | 248 | case COLOR: |
254 | | - themeAttributeValues = new ColorPalette(valueThemeOverlay, themeOverlayAttrs); |
| 249 | + themeAttributeValues = |
| 250 | + themeAttributeValuesCreator.createColorPalette( |
| 251 | + getContext(), valueThemeOverlay, themeOverlayAttrs); |
255 | 252 | break; |
256 | 253 | case SHAPE_CORNER_FAMILY: |
257 | | - themeAttributeValues = new ThemeAttributeValues(valueThemeOverlay); |
| 254 | + themeAttributeValues = |
| 255 | + themeAttributeValuesCreator.createThemeAttributeValues(valueThemeOverlay); |
258 | 256 | break; |
259 | 257 | case SHAPE_CORNER_SIZE: |
260 | 258 | themeAttributeValues = |
261 | | - new ThemeAttributeValuesWithContentDescription( |
| 259 | + themeAttributeValuesCreator.createThemeAttributeValuesWithContentDescription( |
262 | 260 | valueThemeOverlay, contentDescriptionArray.getString(i)); |
263 | 261 | break; |
264 | 262 | } |
@@ -291,63 +289,6 @@ private AppCompatRadioButton createCompatRadioButton( |
291 | 289 | return button; |
292 | 290 | } |
293 | 291 |
|
294 | | - private static class ThemeAttributeValues { |
295 | | - @StyleRes private final int themeOverlay; |
296 | | - |
297 | | - @SuppressLint("ResourceType") |
298 | | - public ThemeAttributeValues(@StyleRes int themeOverlay) { |
299 | | - this.themeOverlay = themeOverlay; |
300 | | - } |
301 | | - |
302 | | - public void customizeRadioButton(AppCompatRadioButton button) {} |
303 | | - } |
304 | | - |
305 | | - private static class ThemeAttributeValuesWithContentDescription extends ThemeAttributeValues { |
306 | | - private final String contentDescription; |
307 | | - |
308 | | - @SuppressLint("ResourceType") |
309 | | - public ThemeAttributeValuesWithContentDescription( |
310 | | - @StyleRes int themeOverlay, String contentDescription) { |
311 | | - super(themeOverlay); |
312 | | - this.contentDescription = contentDescription; |
313 | | - } |
314 | | - |
315 | | - @Override |
316 | | - public void customizeRadioButton(AppCompatRadioButton button) { |
317 | | - button.setText(contentDescription); |
318 | | - LinearLayout.LayoutParams size = |
319 | | - new LinearLayout.LayoutParams( |
320 | | - LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
321 | | - MarginLayoutParamsCompat.setMarginEnd( |
322 | | - size, button.getResources().getDimensionPixelSize(R.dimen.theme_switcher_radio_spacing)); |
323 | | - button.setLayoutParams(size); |
324 | | - } |
325 | | - } |
326 | | - |
327 | | - private class ColorPalette extends ThemeAttributeValues { |
328 | | - @ColorInt private final int main; |
329 | | - |
330 | | - @SuppressLint("ResourceType") |
331 | | - public ColorPalette(@StyleRes int themeOverlay, @StyleableRes int[] themeOverlayAttrs) { |
332 | | - super(themeOverlay); |
333 | | - TypedArray a = getContext().obtainStyledAttributes(themeOverlay, themeOverlayAttrs); |
334 | | - main = a.getColor(0, Color.TRANSPARENT); |
335 | | - |
336 | | - a.recycle(); |
337 | | - } |
338 | | - |
339 | | - @Override |
340 | | - public void customizeRadioButton(AppCompatRadioButton button) { |
341 | | - CompoundButtonCompat.setButtonTintList( |
342 | | - button, ColorStateList.valueOf(convertToDisplay(main))); |
343 | | - } |
344 | | - |
345 | | - @ColorInt |
346 | | - private int convertToDisplay(@ColorInt int color) { |
347 | | - return color == Color.WHITE ? Color.BLACK : color; |
348 | | - } |
349 | | - } |
350 | | - |
351 | 292 | @Inject DispatchingAndroidInjector<Object> childFragmentInjector; |
352 | 293 |
|
353 | 294 | @Override |
|
0 commit comments