From cd18c5140c3bc9c15d3516acc3993ad04a5b5076 Mon Sep 17 00:00:00 2001 From: Wes Okuhara Date: Thu, 20 Mar 2025 12:46:44 -0700 Subject: [SettingsLib] Dynamically update StatusBannerPreference icon tint Prior to this change, the icon tint was only set during initialization based on the icon or icon level. This allows the icon tint to be dynamically updated based on a respective icon level change. Setting the icon level whenthere is no icon defined is a no-op. Bug: 400999418 Test: Manual Flag: EXEMPT bugfix Change-Id: I37d4cf890ecf9152013ac5c53cb60bc55fb26643 --- .../android/settingslib/widget/StatusBannerPreference.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'packages/SettingsLib') diff --git a/packages/SettingsLib/StatusBannerPreference/src/com/android/settingslib/widget/StatusBannerPreference.kt b/packages/SettingsLib/StatusBannerPreference/src/com/android/settingslib/widget/StatusBannerPreference.kt index e6c6638f7de4..c62aed1da352 100644 --- a/packages/SettingsLib/StatusBannerPreference/src/com/android/settingslib/widget/StatusBannerPreference.kt +++ b/packages/SettingsLib/StatusBannerPreference/src/com/android/settingslib/widget/StatusBannerPreference.kt @@ -49,6 +49,7 @@ class StatusBannerPreference @JvmOverloads constructor( var iconLevel: BannerStatus = BannerStatus.GENERIC set(value) { field = value + updateIconTint(value) notifyChanged() } var buttonLevel: BannerStatus = BannerStatus.GENERIC @@ -81,7 +82,7 @@ class StatusBannerPreference @JvmOverloads constructor( if (icon == null) { icon = getIconDrawable(iconLevel) } else { - icon!!.setTintList(ColorStateList.valueOf(getBackgroundColor(iconLevel))) + updateIconTint(iconLevel) } buttonLevel = getInteger(R.styleable.StatusBanner_buttonLevel, 0).toBannerStatus() buttonText = getString(R.styleable.StatusBanner_buttonText) ?: "" @@ -252,4 +253,12 @@ class StatusBannerPreference @JvmOverloads constructor( ) } } -} \ No newline at end of file + + /** + * Sets the icon's tint color based on the icon level. If an icon is not defined, this is a + * no-op. + */ + private fun updateIconTint(iconLevel: BannerStatus) { + icon?.setTintList(ColorStateList.valueOf(getBackgroundColor(iconLevel))) + } +} -- cgit v1.2.3-59-g8ed1b