diff options
author | John Pan <johnpan@google.com> | 2021-12-29 13:27:36 +0800 |
---|---|---|
committer | John Pan <johnpan@google.com> | 2022-01-06 11:33:54 +0800 |
commit | beb3e53b5b93ff4935680ea524ba30d8141238e0 (patch) | |
tree | 82098887bf46f068a7f0ff3e11d5a4e2b1ca8fc2 | |
parent | 93ac02f6355e066d1820f022111f6318f8e7a1e7 (diff) | |
download | ThemePicker-beb3e53b5b93ff4935680ea524ba30d8141238e0.tar.gz |
Change color option and grid option layout
- Add color option horizontal padding
- Change color option layout
- Make grid option LINEAR_LAYOUT_HORIZONTAL_DISPLAY_OPTIONS_MAX comes from resource file
Before: https://screenshot.googleplex.com/opwP97p7X8Qi6nL
https://screenshot.googleplex.com/3igtadNkX5SUJzy
After: https://screenshot.googleplex.com/AJZ43pWwCnGh6fr
https://screenshot.googleplex.com/9SBxam4MTRM2gwN
Bug: 193374285
Test: Manual
Change-Id: I3dcc4a97caa0919053b7d1db9844d6d341d70209
-rw-r--r-- | res/values-w600dp-port/dimens.xml | 21 | ||||
-rw-r--r-- | res/values-w840dp/attrs.xml | 21 | ||||
-rw-r--r-- | res/values-w840dp/dimens.xml | 21 | ||||
-rw-r--r-- | res/values/attrs.xml | 21 | ||||
-rw-r--r-- | res/values/dimens.xml | 1 | ||||
-rw-r--r-- | src/com/android/customization/widget/OptionSelectorController.java | 19 |
6 files changed, 100 insertions, 4 deletions
diff --git a/res/values-w600dp-port/dimens.xml b/res/values-w600dp-port/dimens.xml new file mode 100644 index 00000000..1be52bb4 --- /dev/null +++ b/res/values-w600dp-port/dimens.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2022 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License + --> +<resources> + <!-- Dimensions for the customization option tiles --> + <dimen name="option_tile_width">79dp</dimen> + <dimen name="option_tile_grid_padding_horizontal">8dp</dimen> +</resources>
\ No newline at end of file diff --git a/res/values-w840dp/attrs.xml b/res/values-w840dp/attrs.xml new file mode 100644 index 00000000..f63f574b --- /dev/null +++ b/res/values-w840dp/attrs.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + + Copyright (C) 2022 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<resources> + <item name="linear_layout_horizontal_display_options_max" format="float" type="dimen">6.35 + </item> +</resources>
\ No newline at end of file diff --git a/res/values-w840dp/dimens.xml b/res/values-w840dp/dimens.xml new file mode 100644 index 00000000..4cd6242d --- /dev/null +++ b/res/values-w840dp/dimens.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2022 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License + --> +<resources> + <!-- Dimensions for the customization option tiles --> + <dimen name="option_tile_width">87dp</dimen> + <dimen name="option_tile_grid_padding_horizontal">8dp</dimen> +</resources>
\ No newline at end of file diff --git a/res/values/attrs.xml b/res/values/attrs.xml new file mode 100644 index 00000000..288dd190 --- /dev/null +++ b/res/values/attrs.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + + Copyright (C) 2022 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<resources> + <item name="linear_layout_horizontal_display_options_max" format="float" type="dimen">4.35 + </item> +</resources>
\ No newline at end of file diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 2086480e..4aa43b4c 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -38,6 +38,7 @@ <dimen name="option_tile_margin_horizontal">6dp</dimen> <dimen name="option_tile_padding_vertical">12dp</dimen> <dimen name="option_tile_padding_horizontal">12dp</dimen> + <dimen name="option_tile_grid_padding_horizontal">4dp</dimen> <dimen name="option_icon_size">16dp</dimen> <dimen name="theme_option_icon_sample_height">22dp</dimen> <dimen name="theme_option_icon_sample_width">22dp</dimen> diff --git a/src/com/android/customization/widget/OptionSelectorController.java b/src/com/android/customization/widget/OptionSelectorController.java index 952bc555..a66dd441 100644 --- a/src/com/android/customization/widget/OptionSelectorController.java +++ b/src/com/android/customization/widget/OptionSelectorController.java @@ -24,6 +24,7 @@ import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.text.TextUtils; import android.util.DisplayMetrics; +import android.util.TypedValue; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; @@ -43,6 +44,7 @@ import androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate; import com.android.customization.model.CustomizationManager; import com.android.customization.model.CustomizationOption; import com.android.wallpaper.R; +import com.android.wallpaper.widget.GridPaddingDecoration; import java.util.HashSet; import java.util.List; @@ -77,7 +79,7 @@ public class OptionSelectorController<T extends CustomizationOption<T>> { int CENTER_CHANGE_COLOR_WHEN_NOT_SELECTED = 3; } - private static final float LINEAR_LAYOUT_HORIZONTAL_DISPLAY_OPTIONS_MAX = 4.35f; + private float mLinearLayoutHorizontalDisplayOptionsMax; private final RecyclerView mContainer; private final List<T> mOptions; @@ -99,6 +101,10 @@ public class OptionSelectorController<T extends CustomizationOption<T>> { mOptions = options; mUseGrid = useGrid; mCheckmarkStyle = checkmarkStyle; + TypedValue typedValue = new TypedValue(); + mContainer.getResources().getValue(R.dimen.linear_layout_horizontal_display_options_max, + typedValue, true); + mLinearLayoutHorizontalDisplayOptionsMax = typedValue.getFloat(); } public void addListener(OptionSelectedListener listener) { @@ -312,6 +318,11 @@ public class OptionSelectorController<T extends CustomizationOption<T>> { if (mContainer.getLayoutManager() != null) { ((GridLayoutManager) mContainer.getLayoutManager()).setSpanCount(numColumns); } + if (mContainer.getItemDecorationCount() == 0) { + mContainer.addItemDecoration(new GridPaddingDecoration( + mContainer.getContext().getResources().getDimensionPixelSize( + R.dimen.option_tile_grid_padding_horizontal), 0)); + } return; } @@ -320,12 +331,12 @@ public class OptionSelectorController<T extends CustomizationOption<T>> { mContainer.setOverScrollMode(View.OVER_SCROLL_NEVER); } - if (mAdapter.getItemCount() >= LINEAR_LAYOUT_HORIZONTAL_DISPLAY_OPTIONS_MAX) { + if (mAdapter.getItemCount() >= mLinearLayoutHorizontalDisplayOptionsMax) { int spaceBetweenItems = availableWidth - - Math.round(widthPerItem * LINEAR_LAYOUT_HORIZONTAL_DISPLAY_OPTIONS_MAX) + - Math.round(widthPerItem * mLinearLayoutHorizontalDisplayOptionsMax) - mContainer.getPaddingLeft(); int itemEndMargin = - spaceBetweenItems / (int) LINEAR_LAYOUT_HORIZONTAL_DISPLAY_OPTIONS_MAX; + spaceBetweenItems / (int) mLinearLayoutHorizontalDisplayOptionsMax; if (itemEndMargin <= 0) { itemEndMargin = res.getDimensionPixelOffset(R.dimen.option_tile_margin_horizontal); } |