summaryrefslogtreecommitdiff
path: root/packages/SettingsLib/ButtonPreference
diff options
context:
space:
mode:
author Edgar Wang <edgarwang@google.com> 2025-01-06 17:12:32 +0000
committer Edgar Wang <edgarwang@google.com> 2025-01-16 05:36:44 +0000
commitc3e0d8109ed0d2c21b4811ea1424e6f850f144b9 (patch)
tree89dba056426b57ab6373153e642544e8ebe6c9c4 /packages/SettingsLib/ButtonPreference
parenta4e6cc06acba11f1a150b276aed28048a279075c (diff)
[Expressive design] Add BannerMessagePreferenceGroup
Bug: 367533951 Test: manual Flag: EXEMPT library update Change-Id: I616678711d7b0c2b9c0f2ed6bc30a4b752cff479
Diffstat (limited to 'packages/SettingsLib/ButtonPreference')
-rw-r--r--packages/SettingsLib/ButtonPreference/Android.bp7
-rw-r--r--packages/SettingsLib/ButtonPreference/res/color/settingslib_section_button_background.xml22
-rw-r--r--packages/SettingsLib/ButtonPreference/res/drawable/settingslib_number_button_background.xml21
-rw-r--r--packages/SettingsLib/ButtonPreference/res/drawable/settingslib_number_count_background.xml21
-rw-r--r--packages/SettingsLib/ButtonPreference/res/layout/settingslib_number_button.xml45
-rw-r--r--packages/SettingsLib/ButtonPreference/res/layout/settingslib_section_button.xml30
-rw-r--r--packages/SettingsLib/ButtonPreference/res/values/styles.xml29
-rw-r--r--packages/SettingsLib/ButtonPreference/src/com/android/settingslib/widget/NumberButtonPreference.kt70
-rw-r--r--packages/SettingsLib/ButtonPreference/src/com/android/settingslib/widget/SectionButtonPreference.kt71
9 files changed, 314 insertions, 2 deletions
diff --git a/packages/SettingsLib/ButtonPreference/Android.bp b/packages/SettingsLib/ButtonPreference/Android.bp
index 08dd27fd25ce..a377f312ffbf 100644
--- a/packages/SettingsLib/ButtonPreference/Android.bp
+++ b/packages/SettingsLib/ButtonPreference/Android.bp
@@ -14,12 +14,15 @@ android_library {
"SettingsLintDefaults",
],
- srcs: ["src/**/*.java"],
+ srcs: [
+ "src/**/*.java",
+ "src/**/*.kt",
+ ],
resource_dirs: ["res"],
static_libs: [
- "androidx.preference_preference",
"SettingsLibSettingsTheme",
+ "androidx.preference_preference",
],
sdk_version: "system_current",
diff --git a/packages/SettingsLib/ButtonPreference/res/color/settingslib_section_button_background.xml b/packages/SettingsLib/ButtonPreference/res/color/settingslib_section_button_background.xml
new file mode 100644
index 000000000000..0972b625d4fd
--- /dev/null
+++ b/packages/SettingsLib/ButtonPreference/res/color/settingslib_section_button_background.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2025 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.
+ -->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_enabled="false"
+ android:alpha="@dimen/material_emphasis_disabled_background" android:color="@color/settingslib_materialColorSurfaceBright"/>
+ <item android:color="@color/settingslib_materialColorSurfaceBright" />
+</selector> \ No newline at end of file
diff --git a/packages/SettingsLib/ButtonPreference/res/drawable/settingslib_number_button_background.xml b/packages/SettingsLib/ButtonPreference/res/drawable/settingslib_number_button_background.xml
new file mode 100644
index 000000000000..9bf5c430e8e7
--- /dev/null
+++ b/packages/SettingsLib/ButtonPreference/res/drawable/settingslib_number_button_background.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2025 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.
+ -->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+ <solid android:color="@color/settingslib_materialColorSurfaceBright" />
+ <corners android:radius="@dimen/settingslib_expressive_radius_extralarge2"/>
+</shape> \ No newline at end of file
diff --git a/packages/SettingsLib/ButtonPreference/res/drawable/settingslib_number_count_background.xml b/packages/SettingsLib/ButtonPreference/res/drawable/settingslib_number_count_background.xml
new file mode 100644
index 000000000000..b993811b34f5
--- /dev/null
+++ b/packages/SettingsLib/ButtonPreference/res/drawable/settingslib_number_count_background.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2025 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.
+ -->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+ <solid android:color="@color/settingslib_materialColorSecondaryContainer" />
+ <corners android:radius="100dp"/>
+</shape> \ No newline at end of file
diff --git a/packages/SettingsLib/ButtonPreference/res/layout/settingslib_number_button.xml b/packages/SettingsLib/ButtonPreference/res/layout/settingslib_number_button.xml
new file mode 100644
index 000000000000..fa13b4125065
--- /dev/null
+++ b/packages/SettingsLib/ButtonPreference/res/layout/settingslib_number_button.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2025 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"
+ android:paddingVertical="@dimen/settingslib_expressive_space_extrasmall4">
+
+ <LinearLayout
+ android:id="@+id/settingslib_number_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingVertical="@dimen/settingslib_expressive_space_small1"
+ android:paddingHorizontal="@dimen/settingslib_expressive_space_small4"
+ android:background="@drawable/settingslib_number_button_background">
+ <TextView
+ android:id="@+id/settingslib_number_count"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ style="@style/SettingsLibNumberButtonStyle.Number"/>
+ <TextView
+ android:id="@+id/settingslib_number_title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ style="@style/SettingsLibNumberButtonStyle.Title"/>
+ </LinearLayout>
+
+</LinearLayout> \ No newline at end of file
diff --git a/packages/SettingsLib/ButtonPreference/res/layout/settingslib_section_button.xml b/packages/SettingsLib/ButtonPreference/res/layout/settingslib_section_button.xml
new file mode 100644
index 000000000000..e7fb572d06dc
--- /dev/null
+++ b/packages/SettingsLib/ButtonPreference/res/layout/settingslib_section_button.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2025 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"
+ android:paddingVertical="@dimen/settingslib_expressive_space_extrasmall4">
+
+ <com.google.android.material.button.MaterialButton
+ android:id="@+id/settingslib_section_button"
+ style="@style/SettingsLibSectionButtonStyle.Expressive" />
+
+</LinearLayout> \ No newline at end of file
diff --git a/packages/SettingsLib/ButtonPreference/res/values/styles.xml b/packages/SettingsLib/ButtonPreference/res/values/styles.xml
index 3963732f7ae4..5208e2004a5f 100644
--- a/packages/SettingsLib/ButtonPreference/res/values/styles.xml
+++ b/packages/SettingsLib/ButtonPreference/res/values/styles.xml
@@ -30,4 +30,33 @@
<item name="android:textColor">@color/settingslib_btn_colored_text_material</item>
<item name="android:background">@drawable/settingslib_btn_colored_material</item>
</style>
+
+ <style name="SettingsLibSectionButtonStyle.Expressive"
+ parent="@style/SettingsLibButtonStyle.Expressive.Filled.Large">
+ <item name="android:textColor">?android:attr/textColorPrimary</item>
+ <item name="backgroundTint">@color/settingslib_section_button_background</item>
+ <item name="iconTint">?android:attr/textColorPrimary</item>
+ </style>
+
+ <style name="SettingsLibNumberButtonStyle.Number"
+ parent="">
+ <item name="android:minWidth">@dimen/settingslib_expressive_space_small4</item>
+ <item name="android:minHeight">@dimen/settingslib_expressive_space_small4</item>
+ <item name="android:gravity">center</item>
+ <item name="android:background">@drawable/settingslib_number_count_background</item>
+ <item name="android:paddingStart">@dimen/settingslib_expressive_radius_extrasmall2</item>
+ <item name="android:paddingEnd">@dimen/settingslib_expressive_radius_extrasmall2</item>
+ <item name="android:layout_marginEnd">@dimen/settingslib_expressive_space_extrasmall4</item>
+ <item name="android:textAppearance">@style/TextAppearance.SettingsLib.TitleMedium</item>
+ <item name="android:textColor">@color/settingslib_materialColorOnSecondaryContainer</item>
+ <item name="android:importantForAccessibility">no</item>
+ </style>
+
+ <style name="SettingsLibNumberButtonStyle.Title"
+ parent="">
+ <item name="android:gravity">center</item>
+ <item name="android:textAppearance">@style/TextAppearance.SettingsLib.LabelLarge</item>
+ <item name="android:textColor">@color/settingslib_materialColorOnSurface</item>
+ <item name="android:importantForAccessibility">no</item>
+ </style>
</resources>
diff --git a/packages/SettingsLib/ButtonPreference/src/com/android/settingslib/widget/NumberButtonPreference.kt b/packages/SettingsLib/ButtonPreference/src/com/android/settingslib/widget/NumberButtonPreference.kt
new file mode 100644
index 000000000000..a1772d5acdf9
--- /dev/null
+++ b/packages/SettingsLib/ButtonPreference/src/com/android/settingslib/widget/NumberButtonPreference.kt
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2025 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.
+ */
+
+package com.android.settingslib.widget
+
+import android.content.Context
+import android.util.AttributeSet
+import android.view.View
+import android.widget.TextView
+import androidx.preference.Preference
+import androidx.preference.PreferenceViewHolder
+
+import com.android.settingslib.widget.preference.button.R
+
+class NumberButtonPreference @JvmOverloads constructor(
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0,
+ defStyleRes: Int = 0
+) : Preference(context, attrs, defStyleAttr, defStyleRes), GroupSectionDividerMixin {
+
+ var clickListener: View.OnClickListener? = null
+
+ var count: Int = 0
+ set(value) {
+ field = value
+ notifyChanged()
+ }
+
+ var btnContentDescription: Int = 0
+ set(value) {
+ field = value
+ notifyChanged()
+ }
+
+ init {
+ isPersistent = false // This preference doesn't store data
+ order = Int.MAX_VALUE
+ layoutResource = R.layout.settingslib_number_button
+ }
+
+ override fun onBindViewHolder(holder: PreferenceViewHolder) {
+ super.onBindViewHolder(holder)
+ holder.isDividerAllowedAbove = false
+ holder.isDividerAllowedBelow = false
+
+ holder.findViewById(R.id.settingslib_number_button)?.apply {
+ setOnClickListener(clickListener)
+ if (btnContentDescription != 0) {
+ setContentDescription(context.getString(btnContentDescription, count))
+ }
+ }
+ (holder.findViewById(R.id.settingslib_number_title) as? TextView)?.text = title
+
+ (holder.findViewById(R.id.settingslib_number_count) as? TextView)?.text = "$count"
+ }
+} \ No newline at end of file
diff --git a/packages/SettingsLib/ButtonPreference/src/com/android/settingslib/widget/SectionButtonPreference.kt b/packages/SettingsLib/ButtonPreference/src/com/android/settingslib/widget/SectionButtonPreference.kt
new file mode 100644
index 000000000000..b374dea48d21
--- /dev/null
+++ b/packages/SettingsLib/ButtonPreference/src/com/android/settingslib/widget/SectionButtonPreference.kt
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2025 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.
+ */
+
+package com.android.settingslib.widget
+
+import android.content.Context
+import android.util.AttributeSet
+import android.view.View
+import androidx.preference.Preference
+import androidx.preference.PreferenceViewHolder
+import com.android.settingslib.widget.preference.button.R
+import com.google.android.material.button.MaterialButton
+
+/**
+ * A Preference that displays a button with an optional icon.
+ */
+class SectionButtonPreference @JvmOverloads constructor(
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0,
+ defStyleRes: Int = 0
+) : Preference(context, attrs, defStyleAttr, defStyleRes), GroupSectionDividerMixin {
+
+ private var clickListener: ((View) -> Unit)? = null
+ set(value) {
+ field = value
+ notifyChanged()
+ }
+ private var button: MaterialButton? = null
+ init {
+ isPersistent = false // This preference doesn't store data
+ order = Int.MAX_VALUE
+ layoutResource = R.layout.settingslib_section_button
+ }
+
+ override fun onBindViewHolder(holder: PreferenceViewHolder) {
+ super.onBindViewHolder(holder)
+ holder.isDividerAllowedAbove = false
+ holder.isDividerAllowedBelow = false
+
+ button = holder.findViewById(R.id.settingslib_section_button) as? MaterialButton
+ button?.apply{
+ text = title
+ isFocusable = isSelectable
+ isClickable = isSelectable
+ setOnClickListener { view -> clickListener?.let { it(view) } }
+ }
+ button?.isEnabled = isEnabled
+ button?.icon = icon
+ }
+
+ /**
+ * Set a listener for button click
+ */
+ fun setOnClickListener(listener: (View) -> Unit) {
+ clickListener = listener
+ }
+} \ No newline at end of file