diff options
author | 2024-09-25 15:39:04 +0000 | |
---|---|---|
committer | 2024-09-25 15:39:04 +0000 | |
commit | 8ae19c7249ff1bcedd6c0006d95fc2cc92c91c6e (patch) | |
tree | 97db7b85422d9e8e121f58d36812439357b1f46b | |
parent | 40cd639f39d5a7925ce5e2be47d7f66b91b05135 (diff) | |
parent | 1b729656c64f3aab293e950af43180b5fc8f056e (diff) |
Merge "[Expressive design] update ActionButtonPreference" into main
6 files changed, 245 insertions, 42 deletions
diff --git a/packages/SettingsLib/ActionButtonsPreference/Android.bp b/packages/SettingsLib/ActionButtonsPreference/Android.bp index 71ecb4c30543..37a0e7915a0a 100644 --- a/packages/SettingsLib/ActionButtonsPreference/Android.bp +++ b/packages/SettingsLib/ActionButtonsPreference/Android.bp @@ -19,6 +19,7 @@ android_library { static_libs: [ "androidx.preference_preference", + "SettingsLibSettingsTheme", ], sdk_version: "system_current", diff --git a/packages/SettingsLib/ActionButtonsPreference/res/layout-v35/settingslib_expressive_action_buttons.xml b/packages/SettingsLib/ActionButtonsPreference/res/layout-v35/settingslib_expressive_action_buttons.xml new file mode 100644 index 000000000000..fc63c0f9ab93 --- /dev/null +++ b/packages/SettingsLib/ActionButtonsPreference/res/layout-v35/settingslib_expressive_action_buttons.xml @@ -0,0 +1,104 @@ +<?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:layout_margin="@dimen/settingslib_expressive_space_extrasmall4" + android:paddingHorizontal="@dimen/settingslib_expressive_space_extrasmall4" + android:orientation="horizontal"> + + <LinearLayout + android:id="@+id/action1" + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="1" + android:orientation="vertical"> + + <com.google.android.material.button.MaterialButton + android:id="@+id/button1" + style="@style/SettingsLibActionButton.Expressive" + android:layout_width="@dimen/settingslib_expressive_space_large3" + android:layout_height="@dimen/settingslib_expressive_space_medium5" + android:layout_gravity="center_horizontal" /> + <TextView + android:id="@+id/text1" + style="@style/SettingsLibActionButton.Expressive.Label" + android:layout_marginTop="@dimen/settingslib_expressive_space_extrasmall3"/> + + </LinearLayout> + + <LinearLayout + android:id="@+id/action2" + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="1" + android:orientation="vertical"> + + <com.google.android.material.button.MaterialButton + android:id="@+id/button2" + style="@style/SettingsLibActionButton.Expressive" + android:layout_width="@dimen/settingslib_expressive_space_large3" + android:layout_height="@dimen/settingslib_expressive_space_medium5" + android:layout_gravity="center_horizontal" /> + <TextView + android:id="@+id/text2" + style="@style/SettingsLibActionButton.Expressive.Label" + android:layout_marginTop="@dimen/settingslib_expressive_space_extrasmall3"/> + + </LinearLayout> + + <LinearLayout + android:id="@+id/action3" + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="1" + android:orientation="vertical"> + + <com.google.android.material.button.MaterialButton + android:id="@+id/button3" + style="@style/SettingsLibActionButton.Expressive" + android:layout_width="@dimen/settingslib_expressive_space_large3" + android:layout_height="@dimen/settingslib_expressive_space_medium5" + android:layout_gravity="center_horizontal" /> + <TextView + android:id="@+id/text3" + style="@style/SettingsLibActionButton.Expressive.Label" + android:layout_marginTop="@dimen/settingslib_expressive_space_extrasmall3"/> + + </LinearLayout> + + <LinearLayout + android:id="@+id/action4" + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="1" + android:orientation="vertical"> + + <com.google.android.material.button.MaterialButton + android:id="@+id/button4" + style="@style/SettingsLibActionButton.Expressive" + android:layout_width="@dimen/settingslib_expressive_space_large3" + android:layout_height="@dimen/settingslib_expressive_space_medium5" + android:layout_gravity="center_horizontal" /> + <TextView + android:id="@+id/text4" + style="@style/SettingsLibActionButton.Expressive.Label" + android:layout_marginTop="@dimen/settingslib_expressive_space_extrasmall3"/> + </LinearLayout> +</LinearLayout> diff --git a/packages/SettingsLib/ActionButtonsPreference/res/values-v35/styles_expressive.xml b/packages/SettingsLib/ActionButtonsPreference/res/values-v35/styles_expressive.xml new file mode 100644 index 000000000000..cc948a670382 --- /dev/null +++ b/packages/SettingsLib/ActionButtonsPreference/res/values-v35/styles_expressive.xml @@ -0,0 +1,34 @@ +<?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> + <style name="SettingsLibActionButton.Expressive" parent="SettingsLibButtonStyle.Expressive.Tonal"> + <item name="android:backgroundTint">@color/settingslib_materialColorPrimaryContainer</item> + <item name="iconTint">@color/settingslib_materialColorOnPrimaryContainer</item> + <item name="iconGravity">textTop</item> + </style> + + <style name="SettingsLibActionButton.Expressive.Label" parent="SettingsLibTextAppearance.Emphasized.Title.Small"> + <item name="android:layout_width">wrap_content</item> + <item name="android:layout_height">wrap_content</item> + <item name="android:minWidth">@dimen/settingslib_expressive_space_small3</item> + <item name="android:minHeight">@dimen/settingslib_expressive_space_small3</item> + <item name="android:textColor">@color/settingslib_materialColorOnSurface</item> + <item name="android:layout_gravity">center</item> + </style> + +</resources> diff --git a/packages/SettingsLib/ActionButtonsPreference/src/com/android/settingslib/widget/ActionButtonsPreference.java b/packages/SettingsLib/ActionButtonsPreference/src/com/android/settingslib/widget/ActionButtonsPreference.java index 5dc11cfc0392..f011039517ce 100644 --- a/packages/SettingsLib/ActionButtonsPreference/src/com/android/settingslib/widget/ActionButtonsPreference.java +++ b/packages/SettingsLib/ActionButtonsPreference/src/com/android/settingslib/widget/ActionButtonsPreference.java @@ -26,6 +26,8 @@ import android.util.AttributeSet; import android.util.Log; import android.view.View; import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.TextView; import androidx.annotation.DrawableRes; import androidx.annotation.StringRes; @@ -34,6 +36,8 @@ import androidx.preference.PreferenceViewHolder; import com.android.settingslib.widget.preference.actionbuttons.R; +import com.google.android.material.button.MaterialButton; + import java.util.ArrayList; import java.util.List; @@ -98,7 +102,10 @@ public class ActionButtonsPreference extends Preference { } private void init() { - setLayoutResource(R.layout.settingslib_action_buttons); + int resId = SettingsThemeHelper.isExpressiveTheme(getContext()) + ? R.layout.settingslib_expressive_action_buttons + : R.layout.settingslib_action_buttons; + setLayoutResource(resId); setSelectable(false); final Resources res = getContext().getResources(); @@ -127,6 +134,21 @@ public class ActionButtonsPreference extends Preference { mButton3Info.mButton = (Button) holder.findViewById(R.id.button3); mButton4Info.mButton = (Button) holder.findViewById(R.id.button4); + if (SettingsThemeHelper.isExpressiveTheme(getContext())) { + mButton1Info.mIsExpressive = true; + mButton1Info.mTextView = (TextView) holder.findViewById(R.id.text1); + mButton1Info.mActionLayout = (LinearLayout) holder.findViewById(R.id.action1); + mButton2Info.mIsExpressive = true; + mButton2Info.mTextView = (TextView) holder.findViewById(R.id.text2); + mButton2Info.mActionLayout = (LinearLayout) holder.findViewById(R.id.action2); + mButton3Info.mIsExpressive = true; + mButton3Info.mTextView = (TextView) holder.findViewById(R.id.text3); + mButton3Info.mActionLayout = (LinearLayout) holder.findViewById(R.id.action3); + mButton4Info.mIsExpressive = true; + mButton4Info.mTextView = (TextView) holder.findViewById(R.id.text4); + mButton4Info.mActionLayout = (LinearLayout) holder.findViewById(R.id.action4); + } + mDivider1 = holder.findViewById(R.id.divider1); mDivider2 = holder.findViewById(R.id.divider2); mDivider3 = holder.findViewById(R.id.divider3); @@ -169,45 +191,47 @@ public class ActionButtonsPreference extends Preference { mVisibleButtonInfos.add(mButton4Info); } - final boolean isRtl = getContext().getResources().getConfiguration() - .getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; - switch (mVisibleButtonInfos.size()) { - case SINGLE_BUTTON_STYLE : - if (isRtl) { - setupRtlBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle1); - } else { - setupBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle1); - } - break; - case TWO_BUTTONS_STYLE : - if (isRtl) { - setupRtlBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle2); - } else { - setupBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle2); - } - break; - case THREE_BUTTONS_STYLE : - if (isRtl) { - setupRtlBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle3); - } else { - setupBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle3); - } - break; - case FOUR_BUTTONS_STYLE : - if (isRtl) { - setupRtlBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle4); - } else { - setupBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle4); - } - break; - default: - Log.e(TAG, "No visible buttons info, skip background settings."); - break; - } + if (!SettingsThemeHelper.isExpressiveTheme(getContext())) { + final boolean isRtl = getContext().getResources().getConfiguration() + .getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; + switch (mVisibleButtonInfos.size()) { + case SINGLE_BUTTON_STYLE : + if (isRtl) { + setupRtlBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle1); + } else { + setupBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle1); + } + break; + case TWO_BUTTONS_STYLE : + if (isRtl) { + setupRtlBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle2); + } else { + setupBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle2); + } + break; + case THREE_BUTTONS_STYLE : + if (isRtl) { + setupRtlBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle3); + } else { + setupBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle3); + } + break; + case FOUR_BUTTONS_STYLE : + if (isRtl) { + setupRtlBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle4); + } else { + setupBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle4); + } + break; + default: + Log.e(TAG, "No visible buttons info, skip background settings."); + break; + } - setupDivider1(); - setupDivider2(); - setupDivider3(); + setupDivider1(); + setupDivider2(); + setupDivider3(); + } } private void setupBackgrounds( @@ -509,23 +533,43 @@ public class ActionButtonsPreference extends Preference { static class ButtonInfo { private Button mButton; + private TextView mTextView; + private LinearLayout mActionLayout; private CharSequence mText; private Drawable mIcon; private View.OnClickListener mListener; private boolean mIsEnabled = true; private boolean mIsVisible = true; + private boolean mIsExpressive = false; void setUpButton() { - mButton.setText(mText); + if (mIsExpressive) { + mTextView.setText(mText); + if (mButton instanceof MaterialButton) { + ((MaterialButton) mButton).setIcon(mIcon); + } + } else { + mButton.setText(mText); + mButton.setCompoundDrawablesWithIntrinsicBounds( + null /* left */, mIcon /* top */, null /* right */, null /* bottom */); + } + mButton.setOnClickListener(mListener); mButton.setEnabled(mIsEnabled); - mButton.setCompoundDrawablesWithIntrinsicBounds( - null /* left */, mIcon /* top */, null /* right */, null /* bottom */); + if (shouldBeVisible()) { mButton.setVisibility(View.VISIBLE); + if (mIsExpressive) { + mTextView.setVisibility(View.VISIBLE); + mActionLayout.setVisibility(View.VISIBLE); + } } else { mButton.setVisibility(View.GONE); + if (mIsExpressive) { + mTextView.setVisibility(View.GONE); + mActionLayout.setVisibility(View.GONE); + } } } diff --git a/packages/SettingsLib/SettingsTheme/res/values-v35/dimens_expressive.xml b/packages/SettingsLib/SettingsTheme/res/values-v35/dimens_expressive.xml index 2320aab8f459..0542c510fa63 100644 --- a/packages/SettingsLib/SettingsTheme/res/values-v35/dimens_expressive.xml +++ b/packages/SettingsLib/SettingsTheme/res/values-v35/dimens_expressive.xml @@ -48,6 +48,7 @@ <dimen name="settingslib_expressive_space_medium2">36dp</dimen> <dimen name="settingslib_expressive_space_medium3">40dp</dimen> <dimen name="settingslib_expressive_space_medium4">48dp</dimen> + <dimen name="settingslib_expressive_space_medium5">56dp</dimen> <dimen name="settingslib_expressive_space_large1">60dp</dimen> <dimen name="settingslib_expressive_space_large2">64dp</dimen> <dimen name="settingslib_expressive_space_large3">72dp</dimen> diff --git a/packages/SettingsLib/SettingsTheme/res/values-v35/styles_expressive.xml b/packages/SettingsLib/SettingsTheme/res/values-v35/styles_expressive.xml index 04ae80e72401..442def9ea540 100644 --- a/packages/SettingsLib/SettingsTheme/res/values-v35/styles_expressive.xml +++ b/packages/SettingsLib/SettingsTheme/res/values-v35/styles_expressive.xml @@ -169,4 +169,23 @@ <item name="android:focusable">false</item> <item name="thumbIcon">@drawable/settingslib_expressive_switch_thumb_icon</item> </style> + + <style name="SettingsLibButtonStyle.Expressive.Tonal" + parent="@style/Widget.Material3.Button.TonalButton"> + <item name="android:theme">@style/Theme.Material3.DynamicColors.DayNight</item> + <item name="android:layout_width">wrap_content</item> + <item name="android:layout_height">wrap_content</item> + <item name="android:gravity">center</item> + <item name="android:minWidth">@dimen/settingslib_expressive_space_medium4</item> + <item name="android:minHeight">@dimen/settingslib_expressive_space_medium4</item> + <item name="android:paddingVertical">@dimen/settingslib_expressive_space_extrasmall5</item> + <item name="android:paddingHorizontal">@dimen/settingslib_expressive_space_small1</item> + <item name="android:backgroundTint">@color/settingslib_materialColorSecondaryContainer</item> + <item name="android:textAppearance">@android:style/TextAppearance.DeviceDefault.Medium</item> + <item name="android:textColor">@color/settingslib_materialColorOnSecondaryContainer</item> + <item name="android:textSize">14sp</item> + <item name="iconGravity">textStart</item> + <item name="iconTint">@color/settingslib_materialColorOnSecondaryContainer</item> + <item name="iconSize">@dimen/settingslib_expressive_space_small4</item> + </style> </resources>
\ No newline at end of file |