diff options
author | 2024-09-10 10:20:47 +0000 | |
---|---|---|
committer | 2024-09-26 01:57:10 +0000 | |
commit | 7ac8dc69d9b9dbf57cf90d347508c9cac37caa1f (patch) | |
tree | 47a94e2fece0cfe65546148e0e69aec025c4ad1e | |
parent | 8ae19c7249ff1bcedd6c0006d95fc2cc92c91c6e (diff) |
[Expressive design] Add ZeroStatePreference
Bug: 367666403
Test: manual
Flag: EXEMPT resource only update
Change-Id: I90d5822758b2733e8c408f244304e4fa16093dcb
7 files changed, 222 insertions, 0 deletions
diff --git a/packages/SettingsLib/Android.bp b/packages/SettingsLib/Android.bp index 0cb85d8638b0..0a5eb9bb9fce 100644 --- a/packages/SettingsLib/Android.bp +++ b/packages/SettingsLib/Android.bp @@ -53,6 +53,7 @@ android_library { "SettingsLibTwoTargetPreference", "SettingsLibUsageProgressBarPreference", "SettingsLibUtils", + "SettingsLibZeroStatePreference", "settingslib_media_flags_lib", "settingslib_flags_lib", ], diff --git a/packages/SettingsLib/ZeroStatePreference/Android.bp b/packages/SettingsLib/ZeroStatePreference/Android.bp new file mode 100644 index 000000000000..4fc00bdbfee0 --- /dev/null +++ b/packages/SettingsLib/ZeroStatePreference/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: "SettingsLibZeroStatePreference", + 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: "28", + apex_available: [ + "//apex_available:platform", + ], +} diff --git a/packages/SettingsLib/ZeroStatePreference/AndroidManifest.xml b/packages/SettingsLib/ZeroStatePreference/AndroidManifest.xml new file mode 100644 index 000000000000..51b0ab86c835 --- /dev/null +++ b/packages/SettingsLib/ZeroStatePreference/AndroidManifest.xml @@ -0,0 +1,23 @@ +<?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. + --> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.settingslib.widget.preference.zerostate"> + + <uses-sdk android:minSdkVersion="28" /> + +</manifest> diff --git a/packages/SettingsLib/ZeroStatePreference/res/drawable/settingslib_expressive_zerostate_background.xml b/packages/SettingsLib/ZeroStatePreference/res/drawable/settingslib_expressive_zerostate_background.xml new file mode 100644 index 000000000000..f42b4415c39e --- /dev/null +++ b/packages/SettingsLib/ZeroStatePreference/res/drawable/settingslib_expressive_zerostate_background.xml @@ -0,0 +1,26 @@ +<?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="160dp" + android:height="160dp" + android:viewportWidth="161" + android:viewportHeight="161"> + <path + android:pathData="M67.2,4.43C74.79,-1.41 85.35,-1.41 92.94,4.43L112.01,19.1C113.48,20.23 115.09,21.16 116.8,21.87L139.02,31.08C147.86,34.74 153.14,43.9 151.89,53.4L148.74,77.28C148.5,79.12 148.5,80.98 148.74,82.82L151.89,106.71C153.14,116.2 147.86,125.36 139.02,129.03L116.8,138.23C115.09,138.95 113.48,139.87 112.01,141L92.94,155.67C85.35,161.51 74.79,161.51 67.2,155.67L48.13,141C46.66,139.87 45.05,138.95 43.34,138.23L21.12,129.03C12.28,125.36 7,116.2 8.25,106.71L11.4,82.82C11.64,80.98 11.64,79.12 11.4,77.28L8.25,53.4C7,43.9 12.28,34.74 21.12,31.08L43.34,21.87C45.05,21.16 46.66,20.23 48.13,19.1L67.2,4.43Z" + android:fillColor="@color/settingslib_materialColorSurfaceContainerHigh"/> +</vector> diff --git a/packages/SettingsLib/ZeroStatePreference/res/layout/settingslib_expressive_preference_zerostate.xml b/packages/SettingsLib/ZeroStatePreference/res/layout/settingslib_expressive_preference_zerostate.xml new file mode 100644 index 000000000000..c0b195cc1f74 --- /dev/null +++ b/packages/SettingsLib/ZeroStatePreference/res/layout/settingslib_expressive_preference_zerostate.xml @@ -0,0 +1,57 @@ +<?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" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_gravity="center" + android:gravity="center" + android:orientation="vertical"> + + <FrameLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + tools:ignore="ContentDescription"> + + <ImageView + android:layout_width="@dimen/settingslib_expressive_zero_state_background_size" + android:layout_height="@dimen/settingslib_expressive_zero_state_background_size" + android:src="@drawable/settingslib_expressive_zerostate_background"/> + + <ImageView + android:id="@android:id/icon" + android:layout_width="@dimen/settingslib_expressive_space_large3" + android:layout_height="@dimen/settingslib_expressive_space_large3" + android:layout_gravity="center"/> + + </FrameLayout> + <TextView + android:id="@android:id/title" + android:layout_width="@dimen/settingslib_expressive_zero_state_title_width" + android:layout_height="wrap_content" + android:gravity="center" + android:textAppearance="?android:attr/textAppearanceMedium" + android:layout_marginTop="@dimen/settingslib_expressive_space_small4"/> + <TextView + android:id="@android:id/summary" + android:layout_width="@dimen/settingslib_expressive_zero_state_title_width" + android:layout_height="wrap_content" + android:gravity="center" + android:layout_marginTop="@dimen/settingslib_expressive_space_small4" + android:textAppearance="?android:attr/textAppearanceSmall" + android:textColor="?android:attr/textColorSecondary"/> +</LinearLayout>
\ No newline at end of file diff --git a/packages/SettingsLib/ZeroStatePreference/res/values/dimens.xml b/packages/SettingsLib/ZeroStatePreference/res/values/dimens.xml new file mode 100644 index 000000000000..e981eccf2be2 --- /dev/null +++ b/packages/SettingsLib/ZeroStatePreference/res/values/dimens.xml @@ -0,0 +1,20 @@ +<?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_expressive_zero_state_background_size">160dp</dimen> + <dimen name="settingslib_expressive_zero_state_title_width">316dp</dimen> +</resources>
\ No newline at end of file diff --git a/packages/SettingsLib/ZeroStatePreference/src/com/android/settingslib/widget/ZeroStatePreference.kt b/packages/SettingsLib/ZeroStatePreference/src/com/android/settingslib/widget/ZeroStatePreference.kt new file mode 100644 index 000000000000..9b1ccef9dadf --- /dev/null +++ b/packages/SettingsLib/ZeroStatePreference/src/com/android/settingslib/widget/ZeroStatePreference.kt @@ -0,0 +1,62 @@ +/* + * 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.graphics.PorterDuff +import android.graphics.PorterDuffColorFilter +import android.graphics.drawable.Drawable +import android.util.AttributeSet +import android.widget.ImageView +import androidx.preference.Preference +import androidx.preference.PreferenceViewHolder + +import com.android.settingslib.widget.preference.zerostate.R + +class ZeroStatePreference @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0, + defStyleRes: Int = 0 +) : Preference(context, attrs, defStyleAttr, defStyleRes) { + + private val iconTint: Int = context.getColor( + com.android.settingslib.widget.theme.R.color.settingslib_materialColorOnSecondaryContainer + ) + private var tintedIcon: Drawable? = null + + init { + isSelectable = false + layoutResource = R.layout.settingslib_expressive_preference_zerostate + icon?.let { originalIcon -> + tintedIcon = originalIcon.mutate().apply { + colorFilter = PorterDuffColorFilter(iconTint, PorterDuff.Mode.SRC_IN) + } + } + } + + override fun onBindViewHolder(holder: PreferenceViewHolder) { + super.onBindViewHolder(holder) + + holder.itemView.isFocusable = false + holder.itemView.isClickable = false + + (holder.findViewById(android.R.id.icon) as? ImageView)?.apply { + setImageDrawable(tintedIcon ?: icon) + } + } +}
\ No newline at end of file |