[Expressive design] Add StatusBannerPreference
Bug: 367537747
Test: manual
Flag: EXEMPT resource only update
Change-Id: I4d5a22fc1db09a31a10de56cf8f7c642e0807b9b
diff --git a/packages/SettingsLib/Android.bp b/packages/SettingsLib/Android.bp
index cee7d8f..e141867 100644
--- a/packages/SettingsLib/Android.bp
+++ b/packages/SettingsLib/Android.bp
@@ -54,6 +54,7 @@
"SettingsLibSettingsSpinner",
"SettingsLibSettingsTransition",
"SettingsLibSliderPreference",
+ "SettingsLibStatusBannerPreference",
"SettingsLibTopIntroPreference",
"SettingsLibTwoTargetPreference",
"SettingsLibUsageProgressBarPreference",
diff --git a/packages/SettingsLib/SettingsTheme/res/values-v35/styles_expressive.xml b/packages/SettingsLib/SettingsTheme/res/values-v35/styles_expressive.xml
index 88f7eb8..05a1cea 100644
--- a/packages/SettingsLib/SettingsTheme/res/values-v35/styles_expressive.xml
+++ b/packages/SettingsLib/SettingsTheme/res/values-v35/styles_expressive.xml
@@ -335,4 +335,15 @@
<item name="android:textSize">14sp</item>
<item name="android:textColor">?android:attr/colorAccent</item>
</style>
+
+ <style name="SettingsLibStatusBannerCardStyle">
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:layout_height">wrap_content</item>
+ <item name="android:layout_marginHorizontal">?android:attr/listPreferredItemPaddingStart</item>
+ <item name="android:layout_marginVertical">@dimen/settingslib_expressive_space_extrasmall4</item>
+ <item name="cardBackgroundColor">@color/settingslib_materialColorSurfaceBright</item>
+ <item name="cardCornerRadius">@dimen/settingslib_expressive_radius_extralarge2</item>
+ <item name="cardElevation">0dp</item>
+ <item name="rippleColor">?android:attr/colorControlHighlight</item>
+ </style>
</resources>
\ No newline at end of file
diff --git a/packages/SettingsLib/StatusBannerPreference/Android.bp b/packages/SettingsLib/StatusBannerPreference/Android.bp
new file mode 100644
index 0000000..d6af318
--- /dev/null
+++ b/packages/SettingsLib/StatusBannerPreference/Android.bp
@@ -0,0 +1,33 @@
+package {
+ // See: http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // all of the 'license_kinds' from "frameworks_base_license"
+ // to get the below license kinds:
+ // SPDX-license-identifier-Apache-2.0
+ default_applicable_licenses: ["frameworks_base_license"],
+}
+
+android_library {
+ name: "SettingsLibStatusBannerPreference",
+ use_resource_processor: true,
+ defaults: [
+ "SettingsLintDefaults",
+ ],
+
+ srcs: [
+ "src/**/*.java",
+ "src/**/*.kt",
+ ],
+ resource_dirs: ["res"],
+
+ static_libs: [
+ "androidx.annotation_annotation",
+ "androidx.preference_preference",
+ "SettingsLibSettingsTheme",
+ ],
+ sdk_version: "system_current",
+ min_sdk_version: "24",
+ apex_available: [
+ "//apex_available:platform",
+ ],
+}
diff --git a/packages/SettingsLib/StatusBannerPreference/AndroidManifest.xml b/packages/SettingsLib/StatusBannerPreference/AndroidManifest.xml
new file mode 100644
index 0000000..1dca93f
--- /dev/null
+++ b/packages/SettingsLib/StatusBannerPreference/AndroidManifest.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 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.
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.settingslib.widget.preference.statusbanner">
+
+ <uses-sdk android:minSdkVersion="24" />
+
+</manifest>
diff --git a/packages/SettingsLib/StatusBannerPreference/res/drawable-night/settingslib_expressive_background_level_high.xml b/packages/SettingsLib/StatusBannerPreference/res/drawable-night/settingslib_expressive_background_level_high.xml
new file mode 100644
index 0000000..b977893c
--- /dev/null
+++ b/packages/SettingsLib/StatusBannerPreference/res/drawable-night/settingslib_expressive_background_level_high.xml
@@ -0,0 +1,21 @@
+<?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.
+ -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="oval">
+ <size android:height="68dp" android:width="68dp" />
+ <solid android:color="@color/settingslib_materialColorSurfaceContainerHigh" />
+</shape>
diff --git a/packages/SettingsLib/StatusBannerPreference/res/drawable-night/settingslib_expressive_background_level_low.xml b/packages/SettingsLib/StatusBannerPreference/res/drawable-night/settingslib_expressive_background_level_low.xml
new file mode 100644
index 0000000..b977893c
--- /dev/null
+++ b/packages/SettingsLib/StatusBannerPreference/res/drawable-night/settingslib_expressive_background_level_low.xml
@@ -0,0 +1,21 @@
+<?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.
+ -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="oval">
+ <size android:height="68dp" android:width="68dp" />
+ <solid android:color="@color/settingslib_materialColorSurfaceContainerHigh" />
+</shape>
diff --git a/packages/SettingsLib/StatusBannerPreference/res/drawable-night/settingslib_expressive_background_level_medium.xml b/packages/SettingsLib/StatusBannerPreference/res/drawable-night/settingslib_expressive_background_level_medium.xml
new file mode 100644
index 0000000..b977893c
--- /dev/null
+++ b/packages/SettingsLib/StatusBannerPreference/res/drawable-night/settingslib_expressive_background_level_medium.xml
@@ -0,0 +1,21 @@
+<?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.
+ -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="oval">
+ <size android:height="68dp" android:width="68dp" />
+ <solid android:color="@color/settingslib_materialColorSurfaceContainerHigh" />
+</shape>
diff --git a/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_background_generic.xml b/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_background_generic.xml
new file mode 100644
index 0000000..b64c09f
--- /dev/null
+++ b/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_background_generic.xml
@@ -0,0 +1,21 @@
+<?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.
+ -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="oval">
+ <size android:height="68dp" android:width="68dp" />
+ <solid android:color="@color/settingslib_materialColorSurfaceContainerHigh" />
+</shape>
\ No newline at end of file
diff --git a/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_background_level_high.xml b/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_background_level_high.xml
new file mode 100644
index 0000000..c3caaf7
--- /dev/null
+++ b/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_background_level_high.xml
@@ -0,0 +1,21 @@
+<?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.
+ -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="oval">
+ <size android:height="68dp" android:width="68dp" />
+ <solid android:color="#FFECEE" />
+</shape>
diff --git a/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_background_level_low.xml b/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_background_level_low.xml
new file mode 100644
index 0000000..4e2254c
--- /dev/null
+++ b/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_background_level_low.xml
@@ -0,0 +1,21 @@
+<?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.
+ -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="oval">
+ <size android:height="68dp" android:width="68dp" />
+ <solid android:color="#DDF8D8" />
+</shape>
diff --git a/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_background_level_medium.xml b/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_background_level_medium.xml
new file mode 100644
index 0000000..31ac059
--- /dev/null
+++ b/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_background_level_medium.xml
@@ -0,0 +1,21 @@
+<?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.
+ -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="oval">
+ <size android:height="68dp" android:width="68dp" />
+ <solid android:color="#FFF2B4" />
+</shape>
diff --git a/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_icon_status_level_high.xml b/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_icon_status_level_high.xml
new file mode 100644
index 0000000..58d0fd0
--- /dev/null
+++ b/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_icon_status_level_high.xml
@@ -0,0 +1,28 @@
+<?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.
+ -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="34dp"
+ android:height="42dp"
+ android:viewportWidth="34"
+ android:viewportHeight="42">
+ <path
+ android:pathData="M0.856,17.569C0.887,19.083 1.004,20.593 1.206,22.094C2.166,28.584 5.804,35.937 15.774,41.089C16.171,41.293 16.61,41.4 17.056,41.4C17.503,41.4 17.942,41.293 18.339,41.089C28.309,35.936 31.947,28.583 32.907,22.093C33.109,20.593 33.226,19.083 33.256,17.569V8.605C33.257,7.919 33.046,7.25 32.652,6.688C32.259,6.127 31.703,5.7 31.059,5.467L18.191,0.8C17.458,0.534 16.655,0.534 15.922,0.8L3.054,5.467C2.41,5.7 1.854,6.127 1.461,6.688C1.067,7.25 0.856,7.919 0.856,8.605V17.569Z"
+ android:fillColor="#DB372D"/>
+ <path
+ android:pathData="M15.067,24.333V10.733H18.933V24.333H15.067ZM15.067,31.267V27.433H18.933V31.267H15.067Z"
+ android:fillColor="@color/settingslib_materialColorSurfaceContainerLowest"/>
+</vector>
diff --git a/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_icon_status_level_low.xml b/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_icon_status_level_low.xml
new file mode 100644
index 0000000..d8862e8
--- /dev/null
+++ b/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_icon_status_level_low.xml
@@ -0,0 +1,28 @@
+<?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.
+ -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="34dp"
+ android:height="42dp"
+ android:viewportWidth="34"
+ android:viewportHeight="42">
+ <path
+ android:pathData="M0.856,17.569C0.887,19.083 1.004,20.593 1.206,22.094C2.166,28.584 5.804,35.937 15.774,41.089C16.171,41.293 16.61,41.4 17.056,41.4C17.503,41.4 17.942,41.293 18.339,41.089C28.309,35.936 31.947,28.583 32.907,22.093C33.109,20.593 33.226,19.083 33.256,17.569V8.605C33.257,7.919 33.046,7.25 32.652,6.688C32.259,6.127 31.703,5.7 31.059,5.467L18.191,0.8C17.458,0.534 16.655,0.534 15.922,0.8L3.054,5.467C2.41,5.7 1.854,6.127 1.461,6.688C1.067,7.25 0.856,7.919 0.856,8.605V17.569Z"
+ android:fillColor="#1AA64A"/>
+ <path
+ android:pathData="M14.389,27.733L8.423,21.767L11.156,19.033L14.389,22.267L22.956,13.7L25.69,16.433L14.389,27.733Z"
+ android:fillColor="@color/settingslib_materialColorSurfaceContainerLowest"/>
+</vector>
diff --git a/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_icon_status_level_medium.xml b/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_icon_status_level_medium.xml
new file mode 100644
index 0000000..5e34050
--- /dev/null
+++ b/packages/SettingsLib/StatusBannerPreference/res/drawable/settingslib_expressive_icon_status_level_medium.xml
@@ -0,0 +1,28 @@
+<?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.
+ -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="34dp"
+ android:height="42dp"
+ android:viewportWidth="34"
+ android:viewportHeight="42">
+ <path
+ android:pathData="M0.856,17.569C0.887,19.083 1.004,20.593 1.206,22.094C2.166,28.584 5.804,35.937 15.774,41.089C16.171,41.293 16.61,41.4 17.056,41.4C17.503,41.4 17.942,41.293 18.339,41.089C28.309,35.936 31.947,28.583 32.907,22.093C33.109,20.593 33.226,19.083 33.256,17.569V8.605C33.257,7.919 33.046,7.25 32.652,6.688C32.259,6.127 31.703,5.7 31.059,5.467L18.191,0.8C17.458,0.534 16.655,0.534 15.922,0.8L3.054,5.467C2.41,5.7 1.854,6.127 1.461,6.688C1.067,7.25 0.856,7.919 0.856,8.605V17.569Z"
+ android:fillColor="#FCBD00"/>
+ <path
+ android:pathData="M15.067,24.333V10.733H18.933V24.333H15.067ZM15.067,31.267V27.433H18.933V31.267H15.067Z"
+ android:fillColor="@color/settingslib_materialColorSurfaceContainerLowest"/>
+</vector>
diff --git a/packages/SettingsLib/StatusBannerPreference/res/layout/settingslib_expressive_preference_statusbanner.xml b/packages/SettingsLib/StatusBannerPreference/res/layout/settingslib_expressive_preference_statusbanner.xml
new file mode 100644
index 0000000..9a3e5b9
--- /dev/null
+++ b/packages/SettingsLib/StatusBannerPreference/res/layout/settingslib_expressive_preference_statusbanner.xml
@@ -0,0 +1,94 @@
+<?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.
+ -->
+
+<com.google.android.material.card.MaterialCardView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ style="@style/SettingsLibStatusBannerCardStyle">
+
+ <LinearLayout
+ android:id="@+id/banner_container"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:baselineAligned="false"
+ android:paddingVertical="@dimen/settingslib_expressive_space_small1"
+ android:paddingHorizontal="?android:attr/listPreferredItemPaddingStart"
+ android:orientation="vertical">
+
+ <LinearLayout
+ android:id="@+id/status_container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="horizontal">
+
+ <FrameLayout
+ android:id="@android:id/icon_frame"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:minWidth="@dimen/settingslib_status_banner_icon_frame_size"
+ android:minHeight="@dimen/settingslib_status_banner_icon_frame_size"
+ android:gravity="center"
+ android:orientation="horizontal">
+
+ <ImageView
+ android:id="@+id/icon_background"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"/>
+
+ <ImageView
+ android:id="@android:id/icon"
+ android:layout_width="@dimen/settingslib_expressive_space_medium4"
+ android:layout_height="@dimen/settingslib_expressive_space_medium4"
+ android:layout_gravity="center"
+ android:scaleType="centerInside"/>
+
+ </FrameLayout>
+
+ <LinearLayout
+ android:id="@+id/text_container"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:paddingVertical="@dimen/settingslib_expressive_space_extrasmall4"
+ android:paddingHorizontal="@dimen/settingslib_expressive_space_small1"
+ android:layout_weight="1"
+ android:layout_gravity="center"
+ android:orientation="vertical">
+ <TextView
+ android:id="@android:id/title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:hyphenationFrequency="normalFast"
+ android:lineBreakWordStyle="phrase"
+ android:textAppearance="@style/SettingsLibTextAppearance.Emphasized.Title.Large"/>
+
+ <TextView
+ android:id="@android:id/summary"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:hyphenationFrequency="normalFast"
+ android:lineBreakWordStyle="phrase"
+ android:maxLines="3"
+ android:textAppearance="@style/SettingsLibTextAppearance.Primary.Body.Medium"/>
+ </LinearLayout>
+ </LinearLayout>
+
+ <com.google.android.material.button.MaterialButton
+ android:id="@+id/status_banner_button"
+ android:layout_marginTop="@dimen/settingslib_expressive_space_small3"
+ style="@style/SettingsLibButtonStyle.Expressive.Filled.Extra"/>
+
+ </LinearLayout>
+</com.google.android.material.card.MaterialCardView>
\ No newline at end of file
diff --git a/packages/SettingsLib/StatusBannerPreference/res/values/attrs.xml b/packages/SettingsLib/StatusBannerPreference/res/values/attrs.xml
new file mode 100644
index 0000000..54860d4
--- /dev/null
+++ b/packages/SettingsLib/StatusBannerPreference/res/values/attrs.xml
@@ -0,0 +1,33 @@
+<?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="StatusBanner">
+ <attr name="iconLevel" format="enum">
+ <enum name="generic" value="0"/>
+ <enum name="low" value="1"/>
+ <enum name="medium" value="2"/>
+ <enum name="high" value="3"/>
+ </attr>
+ <attr name="buttonLevel" format="enum">
+ <enum name="generic" value="0"/>
+ <enum name="low" value="1"/>
+ <enum name="medium" value="2"/>
+ <enum name="high" value="3"/>
+ </attr>
+ <attr name="buttonText" format="string"/>
+ </declare-styleable>
+</resources>
\ No newline at end of file
diff --git a/packages/SettingsLib/StatusBannerPreference/res/values/colors.xml b/packages/SettingsLib/StatusBannerPreference/res/values/colors.xml
new file mode 100644
index 0000000..19181dd
--- /dev/null
+++ b/packages/SettingsLib/StatusBannerPreference/res/values/colors.xml
@@ -0,0 +1,25 @@
+<?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>
+ <!-- static palette green60 -->
+ <color name="settingslib_expressive_color_status_level_low">#1AA64A</color>
+ <!-- static palette yellow80 -->
+ <color name="settingslib_expressive_color_status_level_medium">#FCBD00</color>
+ <!-- static palette red50 -->
+ <color name="settingslib_expressive_color_status_level_high">#DB372D</color>
+</resources>
\ No newline at end of file
diff --git a/packages/SettingsLib/StatusBannerPreference/res/values/dimens.xml b/packages/SettingsLib/StatusBannerPreference/res/values/dimens.xml
new file mode 100644
index 0000000..f18f168
--- /dev/null
+++ b/packages/SettingsLib/StatusBannerPreference/res/values/dimens.xml
@@ -0,0 +1,19 @@
+<?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>
+ <dimen name="settingslib_status_banner_icon_frame_size">68dp</dimen>
+</resources>
\ No newline at end of file
diff --git a/packages/SettingsLib/StatusBannerPreference/src/com/android/settingslib/widget/StatusBannerPreference.kt b/packages/SettingsLib/StatusBannerPreference/src/com/android/settingslib/widget/StatusBannerPreference.kt
new file mode 100644
index 0000000..c1578ef
--- /dev/null
+++ b/packages/SettingsLib/StatusBannerPreference/src/com/android/settingslib/widget/StatusBannerPreference.kt
@@ -0,0 +1,197 @@
+/*
+ * 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.
+ */
+
+package com.android.settingslib.widget
+
+import android.content.Context
+import android.content.res.ColorStateList
+import android.graphics.drawable.Drawable
+import android.util.AttributeSet
+import android.view.View
+import android.widget.ImageView
+import androidx.annotation.StringRes
+import androidx.core.content.ContextCompat
+import androidx.preference.Preference
+import androidx.preference.PreferenceViewHolder
+import com.android.settingslib.widget.preference.statusbanner.R
+import com.google.android.material.button.MaterialButton
+
+class StatusBannerPreference @JvmOverloads constructor(
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0,
+ defStyleRes: Int = 0
+) : Preference(context, attrs, defStyleAttr, defStyleRes) {
+
+ enum class BannerStatus {
+ GENERIC,
+ LOW,
+ MEDIUM,
+ HIGH
+ }
+ var iconLevel: BannerStatus = BannerStatus.GENERIC
+ set(value) {
+ field = value
+ notifyChanged()
+ }
+ var buttonLevel: BannerStatus = BannerStatus.GENERIC
+ set(value) {
+ field = value
+ notifyChanged()
+ }
+ private var buttonText: String = ""
+ set(value) {
+ field = value
+ notifyChanged()
+ }
+ private var listener: View.OnClickListener? = null
+
+ init {
+ layoutResource = R.layout.settingslib_expressive_preference_statusbanner
+ isSelectable = false
+
+ initAttributes(context, attrs, defStyleAttr)
+ }
+
+ private fun initAttributes(context: Context, attrs: AttributeSet?, defStyleAttr: Int) {
+ context.obtainStyledAttributes(
+ attrs,
+ R.styleable.StatusBanner, defStyleAttr, 0
+ ).apply {
+ iconLevel = getInteger(R.styleable.StatusBanner_iconLevel, 0).toBannerStatus()
+ if (icon == null) {
+ icon = getIconDrawable(iconLevel)
+ } else {
+ icon!!.setTintList(ColorStateList.valueOf(getBackgroundColor(iconLevel)))
+ }
+ buttonLevel = getInteger(R.styleable.StatusBanner_buttonLevel, 0).toBannerStatus()
+ buttonText = getString(R.styleable.StatusBanner_buttonText) ?: ""
+ recycle()
+ }
+ }
+
+ private fun Int.toBannerStatus(): BannerStatus = when (this) {
+ 1 -> BannerStatus.LOW
+ 2 -> BannerStatus.MEDIUM
+ 3 -> BannerStatus.HIGH
+ else -> BannerStatus.GENERIC
+ }
+
+ override fun onBindViewHolder(holder: PreferenceViewHolder) {
+ super.onBindViewHolder(holder)
+ holder.isDividerAllowedBelow = false
+ holder.isDividerAllowedAbove = false
+
+ (holder.findViewById(R.id.icon_background) as? ImageView)?.apply {
+ setImageDrawable(getBackgroundDrawable(iconLevel))
+ }
+
+ holder.findViewById(android.R.id.icon_frame)?.apply {
+ visibility = if (icon != null) View.VISIBLE else View.GONE
+ }
+
+ (holder.findViewById(R.id.status_banner_button) as? MaterialButton)?.apply {
+ setBackgroundColor(getBackgroundColor(buttonLevel))
+ text = buttonText
+ setOnClickListener(listener)
+ visibility = if (listener != null) View.VISIBLE else View.GONE
+ }
+ }
+
+ /**
+ * Sets the text to be displayed in button.
+ */
+ fun setButtonText(@StringRes textResId: Int) {
+ buttonText = context.getString(textResId)
+ }
+
+ /**
+ * Register a callback to be invoked when positive button is clicked.
+ */
+ fun setButtonOnClickListener(listener: View.OnClickListener) {
+ this.listener = listener
+ notifyChanged()
+ }
+
+ private fun getBackgroundColor(level: BannerStatus): Int {
+ return when (level) {
+ BannerStatus.LOW -> ContextCompat.getColor(
+ context,
+ R.color.settingslib_expressive_color_status_level_low
+ )
+
+ BannerStatus.MEDIUM -> ContextCompat.getColor(
+ context,
+ R.color.settingslib_expressive_color_status_level_medium
+ )
+
+ BannerStatus.HIGH -> ContextCompat.getColor(
+ context,
+ R.color.settingslib_expressive_color_status_level_high
+ )
+
+ else -> ContextCompat.getColor(
+ context,
+ com.android.settingslib.widget.theme.R.color.settingslib_materialColorPrimary
+ )
+ }
+ }
+
+ private fun getIconDrawable(level: BannerStatus): Drawable? {
+ return when (level) {
+ BannerStatus.LOW -> ContextCompat.getDrawable(
+ context,
+ R.drawable.settingslib_expressive_icon_status_level_low
+ )
+
+ BannerStatus.MEDIUM -> ContextCompat.getDrawable(
+ context,
+ R.drawable.settingslib_expressive_icon_status_level_medium
+ )
+
+ BannerStatus.HIGH -> ContextCompat.getDrawable(
+ context,
+ R.drawable.settingslib_expressive_icon_status_level_high
+ )
+
+ else -> null
+ }
+ }
+
+ private fun getBackgroundDrawable(level: BannerStatus): Drawable? {
+ return when (level) {
+ BannerStatus.LOW -> ContextCompat.getDrawable(
+ context,
+ R.drawable.settingslib_expressive_background_level_low
+ )
+
+ BannerStatus.MEDIUM -> ContextCompat.getDrawable(
+ context,
+ R.drawable.settingslib_expressive_background_level_medium
+ )
+
+ BannerStatus.HIGH -> ContextCompat.getDrawable(
+ context,
+ R.drawable.settingslib_expressive_background_level_high
+ )
+
+ else -> ContextCompat.getDrawable(
+ context,
+ R.drawable.settingslib_expressive_background_generic
+ )
+ }
+ }
+}
\ No newline at end of file