diff options
author | 2024-09-13 12:11:28 +0000 | |
---|---|---|
committer | 2024-09-28 08:07:17 +0000 | |
commit | 5ef9ea4951f31f7f29b3f2004c0bc9ee7d8a40e9 (patch) | |
tree | b5e98cb420a4cac3676e9d2d241f377686e33b33 /packages/SettingsLib/ButtonPreference | |
parent | 3b5125b3fec4df1166c6acaf94f166f41a204131 (diff) |
[Expressive design] update ButtonPreference
- update to material button
- add filled, tonal, outline style
- support more size
Bug: 366403617
Test: manual
Flag: EXEMPT resource only update
Change-Id: Ied90fda2c9967e655721293c141ee0936f17303c
Diffstat (limited to 'packages/SettingsLib/ButtonPreference')
11 files changed, 348 insertions, 9 deletions
diff --git a/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_filled.xml b/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_filled.xml new file mode 100644 index 000000000000..f55b320269a8 --- /dev/null +++ b/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_filled.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2024 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. +--> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:paddingStart="?android:attr/listPreferredItemPaddingStart" + android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"> + + <com.google.android.material.button.MaterialButton + android:id="@+id/settingslib_button" + style="@style/SettingsLibButtonStyle.Expressive.Filled" /> + +</LinearLayout> diff --git a/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_filled_extra.xml b/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_filled_extra.xml new file mode 100644 index 000000000000..b663b6ccc5bf --- /dev/null +++ b/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_filled_extra.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2024 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. +--> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:paddingStart="?android:attr/listPreferredItemPaddingStart" + android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"> + + <com.google.android.material.button.MaterialButton + android:id="@+id/settingslib_button" + style="@style/SettingsLibButtonStyle.Expressive.Filled.Extra" /> + +</LinearLayout> diff --git a/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_filled_large.xml b/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_filled_large.xml new file mode 100644 index 000000000000..784e6ad6a9f8 --- /dev/null +++ b/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_filled_large.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2024 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. +--> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:paddingStart="?android:attr/listPreferredItemPaddingStart" + android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"> + + <com.google.android.material.button.MaterialButton + android:id="@+id/settingslib_button" + style="@style/SettingsLibButtonStyle.Expressive.Filled.Large" /> + +</LinearLayout> diff --git a/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_outline.xml b/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_outline.xml new file mode 100644 index 000000000000..8b44a6539801 --- /dev/null +++ b/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_outline.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2024 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. +--> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:paddingStart="?android:attr/listPreferredItemPaddingStart" + android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"> + + <com.google.android.material.button.MaterialButton + android:id="@+id/settingslib_button" + style="@style/SettingsLibButtonStyle.Expressive.Outline" /> + +</LinearLayout> diff --git a/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_outline_extra.xml b/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_outline_extra.xml new file mode 100644 index 000000000000..f8a2d8fbd975 --- /dev/null +++ b/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_outline_extra.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2024 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. +--> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:paddingStart="?android:attr/listPreferredItemPaddingStart" + android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"> + + <com.google.android.material.button.MaterialButton + android:id="@+id/settingslib_button" + style="@style/SettingsLibButtonStyle.Expressive.Outline.Extra" /> + +</LinearLayout> diff --git a/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_outline_large.xml b/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_outline_large.xml new file mode 100644 index 000000000000..781a5a136164 --- /dev/null +++ b/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_outline_large.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2024 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. +--> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:paddingStart="?android:attr/listPreferredItemPaddingStart" + android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"> + + <com.google.android.material.button.MaterialButton + android:id="@+id/settingslib_button" + style="@style/SettingsLibButtonStyle.Expressive.Outline.Large" /> + +</LinearLayout> diff --git a/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_tonal.xml b/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_tonal.xml new file mode 100644 index 000000000000..5b568f870ea4 --- /dev/null +++ b/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_tonal.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2024 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. +--> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:paddingStart="?android:attr/listPreferredItemPaddingStart" + android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"> + + <com.google.android.material.button.MaterialButton + android:id="@+id/settingslib_button" + style="@style/SettingsLibButtonStyle.Expressive.Tonal" /> + +</LinearLayout> diff --git a/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_tonal_extra.xml b/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_tonal_extra.xml new file mode 100644 index 000000000000..1e7a08b714f1 --- /dev/null +++ b/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_tonal_extra.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2024 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. +--> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:paddingStart="?android:attr/listPreferredItemPaddingStart" + android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"> + + <com.google.android.material.button.MaterialButton + android:id="@+id/settingslib_button" + style="@style/SettingsLibButtonStyle.Expressive.Tonal.Extra" /> + +</LinearLayout> diff --git a/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_tonal_large.xml b/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_tonal_large.xml new file mode 100644 index 000000000000..42116be07041 --- /dev/null +++ b/packages/SettingsLib/ButtonPreference/res/layout-v35/settingslib_expressive_button_tonal_large.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2024 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. +--> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:paddingStart="?android:attr/listPreferredItemPaddingStart" + android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"> + + <com.google.android.material.button.MaterialButton + android:id="@+id/settingslib_button" + style="@style/SettingsLibButtonStyle.Expressive.Tonal.Large" /> + +</LinearLayout> diff --git a/packages/SettingsLib/ButtonPreference/res/values-v35/attrs_expressive.xml b/packages/SettingsLib/ButtonPreference/res/values-v35/attrs_expressive.xml new file mode 100644 index 000000000000..a1761e55f1e0 --- /dev/null +++ b/packages/SettingsLib/ButtonPreference/res/values-v35/attrs_expressive.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2024 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> + <declare-styleable name="ButtonPreference"> + <attr name="buttonType" format="enum"> + <enum name="filled" value="0"/> + <enum name="tonal" value="1"/> + <enum name="outline" value="2"/> + </attr> + <attr name="buttonSize" format="enum"> + <enum name="normal" value="0"/> + <enum name="large" value="1"/> + <enum name="extra" value="2"/> + </attr> + </declare-styleable> +</resources>
\ No newline at end of file diff --git a/packages/SettingsLib/ButtonPreference/src/com/android/settingslib/widget/ButtonPreference.java b/packages/SettingsLib/ButtonPreference/src/com/android/settingslib/widget/ButtonPreference.java index 16ba96265751..0041eb2c7072 100644 --- a/packages/SettingsLib/ButtonPreference/src/com/android/settingslib/widget/ButtonPreference.java +++ b/packages/SettingsLib/ButtonPreference/src/com/android/settingslib/widget/ButtonPreference.java @@ -32,11 +32,44 @@ import androidx.preference.PreferenceViewHolder; import com.android.settingslib.widget.preference.button.R; +import com.google.android.material.button.MaterialButton; + /** * A preference handled a button */ public class ButtonPreference extends Preference { + enum ButtonStyle { + FILLED_NORMAL(0, 0, R.layout.settingslib_expressive_button_filled), + FILLED_LARGE(0, 1, R.layout.settingslib_expressive_button_filled_large), + FILLED_EXTRA(0, 2, R.layout.settingslib_expressive_button_filled_extra), + TONAL_NORMAL(1, 0, R.layout.settingslib_expressive_button_tonal), + TONAL_LARGE(1, 1, R.layout.settingslib_expressive_button_tonal_large), + TONAL_EXTRA(1, 2, R.layout.settingslib_expressive_button_tonal_extra), + OUTLINE_NORMAL(2, 0, R.layout.settingslib_expressive_button_outline), + OUTLINE_LARGE(2, 1, R.layout.settingslib_expressive_button_outline_large), + OUTLINE_EXTRA(2, 2, R.layout.settingslib_expressive_button_outline_extra); + + private final int mType; + private final int mSize; + private final int mLayoutId; + + ButtonStyle(int type, int size, int layoutId) { + this.mType = type; + this.mSize = size; + this.mLayoutId = layoutId; + } + + static int getLayoutId(int type, int size) { + for (ButtonStyle style : values()) { + if (style.mType == type && style.mSize == size) { + return style.mLayoutId; + } + } + throw new IllegalArgumentException(); + } + } + private static final int ICON_SIZE = 24; private View.OnClickListener mClickListener; @@ -86,7 +119,7 @@ public class ButtonPreference extends Preference { } private void init(Context context, AttributeSet attrs, int defStyleAttr) { - setLayoutResource(R.layout.settingslib_button_layout); + int resId = R.layout.settingslib_button_layout; if (attrs != null) { TypedArray a = context.obtainStyledAttributes(attrs, @@ -102,8 +135,16 @@ public class ButtonPreference extends Preference { R.styleable.ButtonPreference, defStyleAttr, 0 /*defStyleRes*/); mGravity = a.getInt(R.styleable.ButtonPreference_android_gravity, Gravity.START); + + if (SettingsThemeHelper.isExpressiveTheme(context)) { + int type = a.getInt(R.styleable.ButtonPreference_buttonType, 0); + int size = a.getInt(R.styleable.ButtonPreference_buttonSize, 0); + resId = ButtonStyle.getLayoutId(type, size); + } a.recycle(); } + + setLayoutResource(resId); } @Override @@ -144,14 +185,20 @@ public class ButtonPreference extends Preference { if (mButton == null || icon == null) { return; } - //get pixel from dp - int size = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, ICON_SIZE, - getContext().getResources().getDisplayMetrics()); - icon.setBounds(0, 0, size, size); - - //set drawableStart - mButton.setCompoundDrawablesRelativeWithIntrinsicBounds(icon, null/* top */, null/* end */, - null/* bottom */); + + if (mButton instanceof MaterialButton) { + ((MaterialButton) mButton).setIcon(icon); + } else { + //get pixel from dp + int size = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, ICON_SIZE, + getContext().getResources().getDisplayMetrics()); + icon.setBounds(0, 0, size, size); + + //set drawableStart + mButton.setCompoundDrawablesRelativeWithIntrinsicBounds(icon, null/* top */, + null/* end */, + null/* bottom */); + } } @Override |