diff options
author | 2025-03-20 12:46:44 -0700 | |
---|---|---|
committer | 2025-03-20 12:49:52 -0700 | |
commit | cd18c5140c3bc9c15d3516acc3993ad04a5b5076 (patch) | |
tree | 168cc44a16c0b354280d877b33ecefa9dd857bac | |
parent | 014ffc854c30c28bdbe17b61a1258d890f4b9419 (diff) |
[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
-rw-r--r-- | packages/SettingsLib/StatusBannerPreference/src/com/android/settingslib/widget/StatusBannerPreference.kt | 13 |
1 files changed, 11 insertions, 2 deletions
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))) + } +} |