Skip to content

Commit

Permalink
[Catalog] Updated catalog preferences for shape corner sizes.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 463151256
  • Loading branch information
pekingme authored and drchen committed Jul 28, 2022
1 parent a65a262 commit 3daa028
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,28 @@
* Shape corner size preference to change the corner size among small, medium, and large.
*/
public class ShapeCornerSizePreference extends CatalogPreference {
private static final int OPTION_ID_SMALL = 1;
private static final int OPTION_ID_MEDIUM = 2;
private static final int OPTION_ID_LARGE = 3;
private static final int OPTION_ID_DEFAULT = 4;
private static final int OPTION_ID_NONE = 1;
private static final int OPTION_ID_EXTRA_SMALL = 2;
private static final int OPTION_ID_SMALL = 3;
private static final int OPTION_ID_MEDIUM = 4;
private static final int OPTION_ID_LARGE = 5;
private static final int OPTION_ID_EXTRA_LARGE = 6;
private static final int OPTION_ID_FULL = 7;
private static final int OPTION_ID_DEFAULT = 8;

private static final SparseIntArray OPTION_ID_TO_THEME_OVERLAY = new SparseIntArray();

static {
OPTION_ID_TO_THEME_OVERLAY.append(OPTION_ID_SMALL, R.style.ThemeOverlay_ShapeSize_Small);
OPTION_ID_TO_THEME_OVERLAY.append(OPTION_ID_MEDIUM, R.style.ThemeOverlay_ShapeSize_Medium);
OPTION_ID_TO_THEME_OVERLAY.append(OPTION_ID_LARGE, R.style.ThemeOverlay_ShapeSize_Large);
OPTION_ID_TO_THEME_OVERLAY.append(OPTION_ID_NONE, R.style.ThemeOverlay_ShapeCornerSize_None);
OPTION_ID_TO_THEME_OVERLAY.append(
OPTION_ID_EXTRA_SMALL, R.style.ThemeOverlay_ShapeCornerSize_ExtraSmall);
OPTION_ID_TO_THEME_OVERLAY.append(OPTION_ID_SMALL, R.style.ThemeOverlay_ShapeCornerSize_Small);
OPTION_ID_TO_THEME_OVERLAY.append(
OPTION_ID_MEDIUM, R.style.ThemeOverlay_ShapeCornerSize_Medium);
OPTION_ID_TO_THEME_OVERLAY.append(OPTION_ID_LARGE, R.style.ThemeOverlay_ShapeCornerSize_Large);
OPTION_ID_TO_THEME_OVERLAY.append(
OPTION_ID_EXTRA_LARGE, R.style.ThemeOverlay_ShapeCornerSize_ExtraLarge);
OPTION_ID_TO_THEME_OVERLAY.append(OPTION_ID_FULL, R.style.ThemeOverlay_ShapeCornerSize_Full);
OPTION_ID_TO_THEME_OVERLAY.append(OPTION_ID_DEFAULT, ThemeOverlayUtils.NO_THEME_OVERLAY);
}

Expand All @@ -48,18 +60,16 @@ public class ShapeCornerSizePreference extends CatalogPreference {

private static final ImmutableList<Option> OPTIONS =
ImmutableList.of(
new Option(OPTION_ID_NONE, 0, R.string.shape_corner_size_preference_option_none),
new Option(
OPTION_ID_SMALL,
0,
R.string.shape_corner_size_preference_option_small),
OPTION_ID_EXTRA_SMALL, 0, R.string.shape_corner_size_preference_option_extra_small),
new Option(OPTION_ID_SMALL, 0, R.string.shape_corner_size_preference_option_small),
new Option(OPTION_ID_MEDIUM, 0, R.string.shape_corner_size_preference_option_medium),
new Option(OPTION_ID_LARGE, 0, R.string.shape_corner_size_preference_option_large),
new Option(
OPTION_ID_MEDIUM,
0,
R.string.shape_corner_size_preference_option_medium),
OPTION_ID_EXTRA_LARGE, 0, R.string.shape_corner_size_preference_option_extra_large),
new Option(
OPTION_ID_LARGE,
0,
R.string.shape_corner_size_preference_option_large),
OPTION_ID_FULL, 0, R.string.shape_corner_size_preference_option_full),
DEFAULT_OPTION);

public ShapeCornerSizePreference() {
Expand All @@ -81,8 +91,7 @@ protected Option getDefaultOption() {
@Override
protected void apply(@NonNull Context context, @NonNull Option selectedOption) {
ThemeOverlayUtils.setThemeOverlay(
R.id.theme_feature_corner_size,
OPTION_ID_TO_THEME_OVERLAY.get(selectedOption.id));
R.id.theme_feature_corner_size, OPTION_ID_TO_THEME_OVERLAY.get(selectedOption.id));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@
<string name="shape_corner_family_preference_option_cut" translatable="false">Cut</string>
<string name="shape_corner_family_preference_option_default" translatable="false">Default</string>
<string name="shape_corner_size_preference_description" translatable="false">Shape Corner Size</string>
<string name="shape_corner_size_preference_option_small" translatable="false">Small</string>
<string name="shape_corner_size_preference_option_medium" translatable="false">Medium</string>
<string name="shape_corner_size_preference_option_large" translatable="false">Large</string>
<string name="shape_corner_size_preference_option_none" translatable="false">None</string>
<string name="shape_corner_size_preference_option_extra_small" translatable="false">XS</string>
<string name="shape_corner_size_preference_option_small" translatable="false">S</string>
<string name="shape_corner_size_preference_option_medium" translatable="false">M</string>
<string name="shape_corner_size_preference_option_large" translatable="false">L</string>
<string name="shape_corner_size_preference_option_extra_large" translatable="false">XL</string>
<string name="shape_corner_size_preference_option_full" translatable="false">Full</string>
<string name="shape_corner_size_preference_option_default" translatable="false">Default</string>
<string name="dynamic_color_preference_description" translatable="false">Dynamic Colors</string>
<string name="dynamic_color_preference_option_on" translatable="false">On</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,60 @@

<resources>

<style name="ThemeOverlay.ShapeSize.Small" parent="">
<item name="shapeAppearanceSmallComponent">@style/ShapeAppearanceComponent.SmallCornerSize</item>
<item name="shapeAppearanceMediumComponent">@style/ShapeAppearanceComponent.SmallCornerSize</item>
<item name="shapeAppearanceLargeComponent">@style/ShapeAppearanceComponent.ExtraSmall</item>
<style name="ThemeOverlay.ShapeCornerSize.None" parent="">
<item name="shapeAppearanceCornerExtraSmall">@style/ShapeAppearance.Material3.Corner.None</item>
<item name="shapeAppearanceCornerSmall">@style/ShapeAppearance.Material3.Corner.None</item>
<item name="shapeAppearanceCornerMedium">@style/ShapeAppearance.Material3.Corner.None</item>
<item name="shapeAppearanceCornerLarge">@style/ShapeAppearance.Material3.Corner.None</item>
<item name="shapeAppearanceCornerExtraLarge">@style/ShapeAppearance.Material3.Corner.None</item>
</style>

<style name="ThemeOverlay.ShapeSize.Medium" parent="">
<item name="shapeAppearanceSmallComponent">@style/ShapeAppearanceComponent.MediumCornerSize</item>
<item name="shapeAppearanceMediumComponent">@style/ShapeAppearanceComponent.MediumCornerSize</item>
<item name="shapeAppearanceLargeComponent">@style/ShapeAppearanceComponent.SmallCornerSize</item>
<style name="ThemeOverlay.ShapeCornerSize.ExtraSmall" parent="">
<item name="shapeAppearanceCornerExtraSmall">@style/ShapeAppearance.Material3.Corner.ExtraSmall</item>
<item name="shapeAppearanceCornerSmall">@style/ShapeAppearance.Material3.Corner.ExtraSmall</item>
<item name="shapeAppearanceCornerMedium">@style/ShapeAppearance.Material3.Corner.ExtraSmall</item>
<item name="shapeAppearanceCornerLarge">@style/ShapeAppearance.Material3.Corner.ExtraSmall</item>
<item name="shapeAppearanceCornerExtraLarge">@style/ShapeAppearance.Material3.Corner.ExtraSmall</item>
</style>

<style name="ThemeOverlay.ShapeSize.Large" parent="">
<item name="shapeAppearanceSmallComponent">@style/ShapeAppearanceComponent.LargeCornerSize</item>
<item name="shapeAppearanceMediumComponent">@style/ShapeAppearanceComponent.LargeCornerSize</item>
<item name="shapeAppearanceLargeComponent">@style/ShapeAppearanceComponent.MediumCornerSize</item>
<style name="ThemeOverlay.ShapeCornerSize.Small" parent="">
<item name="shapeAppearanceCornerExtraSmall">@style/ShapeAppearance.Material3.Corner.Small</item>
<item name="shapeAppearanceCornerSmall">@style/ShapeAppearance.Material3.Corner.Small</item>
<item name="shapeAppearanceCornerMedium">@style/ShapeAppearance.Material3.Corner.Small</item>
<item name="shapeAppearanceCornerLarge">@style/ShapeAppearance.Material3.Corner.Small</item>
<item name="shapeAppearanceCornerExtraLarge">@style/ShapeAppearance.Material3.Corner.Small</item>
</style>

<style name="ShapeAppearanceComponent.ExtraSmall" parent="">
<item name="cornerSize">0dp</item>
<style name="ThemeOverlay.ShapeCornerSize.Medium" parent="">
<item name="shapeAppearanceCornerExtraSmall">@style/ShapeAppearance.Material3.Corner.Medium</item>
<item name="shapeAppearanceCornerSmall">@style/ShapeAppearance.Material3.Corner.Medium</item>
<item name="shapeAppearanceCornerMedium">@style/ShapeAppearance.Material3.Corner.Medium</item>
<item name="shapeAppearanceCornerLarge">@style/ShapeAppearance.Material3.Corner.Medium</item>
<item name="shapeAppearanceCornerExtraLarge">@style/ShapeAppearance.Material3.Corner.Medium</item>
</style>

<style name="ShapeAppearanceComponent.SmallCornerSize" parent="">
<item name="cornerSize">4dp</item>
<style name="ThemeOverlay.ShapeCornerSize.Large" parent="">
<item name="shapeAppearanceCornerExtraSmall">@style/ShapeAppearance.Material3.Corner.Large</item>
<item name="shapeAppearanceCornerSmall">@style/ShapeAppearance.Material3.Corner.Large</item>
<item name="shapeAppearanceCornerMedium">@style/ShapeAppearance.Material3.Corner.Large</item>
<item name="shapeAppearanceCornerLarge">@style/ShapeAppearance.Material3.Corner.Large</item>
<item name="shapeAppearanceCornerExtraLarge">@style/ShapeAppearance.Material3.Corner.Large</item>
</style>

<style name="ShapeAppearanceComponent.MediumCornerSize" parent="">
<item name="cornerSize">8dp</item>
<style name="ThemeOverlay.ShapeCornerSize.ExtraLarge" parent="">
<item name="shapeAppearanceCornerExtraSmall">@style/ShapeAppearance.Material3.Corner.ExtraLarge</item>
<item name="shapeAppearanceCornerSmall">@style/ShapeAppearance.Material3.Corner.ExtraLarge</item>
<item name="shapeAppearanceCornerMedium">@style/ShapeAppearance.Material3.Corner.ExtraLarge</item>
<item name="shapeAppearanceCornerLarge">@style/ShapeAppearance.Material3.Corner.ExtraLarge</item>
<item name="shapeAppearanceCornerExtraLarge">@style/ShapeAppearance.Material3.Corner.ExtraLarge</item>
</style>

<style name="ShapeAppearanceComponent.LargeCornerSize" parent="">
<item name="cornerSize">16dp</item>

<style name="ThemeOverlay.ShapeCornerSize.Full" parent="">
<item name="shapeAppearanceCornerExtraSmall">@style/ShapeAppearance.Material3.Corner.Full</item>
<item name="shapeAppearanceCornerSmall">@style/ShapeAppearance.Material3.Corner.Full</item>
<item name="shapeAppearanceCornerMedium">@style/ShapeAppearance.Material3.Corner.Full</item>
<item name="shapeAppearanceCornerLarge">@style/ShapeAppearance.Material3.Corner.Full</item>
<item name="shapeAppearanceCornerExtraLarge">@style/ShapeAppearance.Material3.Corner.Full</item>
</style>

</resources>

0 comments on commit 3daa028

Please sign in to comment.