diff options
author | 2021-12-07 15:10:13 +0800 | |
---|---|---|
committer | 2021-12-07 16:11:05 +0800 | |
commit | 41a3197e7436c9c93949f7b296f75916fb7d2f9c (patch) | |
tree | ad86b76e0d027470fa9f321ad5aed86ae7ba8ccd | |
parent | 22d2a97dd821bc281eda7ba2c37d68e6862d7db4 (diff) |
Allow customize icon of BannerMessagePreference before Android S
Synced with UX, we decided to allow user to customize the icon of
BannerMessage which could provide more ability to make UX consistency.
Bug: 205244609
Test: robotest
Change-Id: Iea29c48730c943c5436e42a1effd11fe3601356a
-rw-r--r-- | packages/SettingsLib/BannerMessagePreference/src/com/android/settingslib/widget/BannerMessagePreference.java | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/packages/SettingsLib/BannerMessagePreference/src/com/android/settingslib/widget/BannerMessagePreference.java b/packages/SettingsLib/BannerMessagePreference/src/com/android/settingslib/widget/BannerMessagePreference.java index 3a70d657f62f..afeb24ad3b61 100644 --- a/packages/SettingsLib/BannerMessagePreference/src/com/android/settingslib/widget/BannerMessagePreference.java +++ b/packages/SettingsLib/BannerMessagePreference/src/com/android/settingslib/widget/BannerMessagePreference.java @@ -152,10 +152,22 @@ public class BannerMessagePreference extends Preference { mPositiveButtonInfo.mButton = (Button) holder.findViewById(R.id.banner_positive_btn); mNegativeButtonInfo.mButton = (Button) holder.findViewById(R.id.banner_negative_btn); + final Resources.Theme theme = context.getTheme(); + @ColorInt final int accentColor = + context.getResources().getColor(mAttentionLevel.getAccentColorResId(), theme); + + final ImageView iconView = (ImageView) holder.findViewById(R.id.banner_icon); + if (iconView != null) { + Drawable icon = getIcon(); + iconView.setImageDrawable( + icon == null + ? getContext().getDrawable(R.drawable.ic_warning) + : icon); + iconView.setColorFilter( + new PorterDuffColorFilter(accentColor, PorterDuff.Mode.SRC_IN)); + } + if (IS_AT_LEAST_S) { - final Resources.Theme theme = context.getTheme(); - @ColorInt final int accentColor = - context.getResources().getColor(mAttentionLevel.getAccentColorResId(), theme); @ColorInt final int backgroundColor = context.getResources().getColor( mAttentionLevel.getBackgroundColorResId(), theme); @@ -174,16 +186,6 @@ public class BannerMessagePreference extends Preference { subtitleView.setText(mSubtitle); subtitleView.setVisibility(mSubtitle == null ? View.GONE : View.VISIBLE); - final ImageView iconView = (ImageView) holder.findViewById(R.id.banner_icon); - if (iconView != null) { - Drawable icon = getIcon(); - iconView.setImageDrawable( - icon == null - ? getContext().getDrawable(R.drawable.ic_warning) - : icon); - iconView.setColorFilter( - new PorterDuffColorFilter(accentColor, PorterDuff.Mode.SRC_IN)); - } } else { holder.setDividerAllowedAbove(true); holder.setDividerAllowedBelow(true); @@ -323,7 +325,6 @@ public class BannerMessagePreference extends Preference { /** * Sets the attention level. This will update the color theme of the preference. */ - @RequiresApi(Build.VERSION_CODES.S) public BannerMessagePreference setAttentionLevel(AttentionLevel attentionLevel) { if (attentionLevel == mAttentionLevel) { return this; |