From 5f47d30fad1bdbec72b5f8d4a5e0accebd5689b6 Mon Sep 17 00:00:00 2001 From: Edgar Wang Date: Tue, 31 Jan 2023 15:26:47 +0800 Subject: [PATCH] Add new attribute to support lottie dynamic color Bug: 243889662 Test: manual Change-Id: Iba35e69ec18d8582358e16069e86f060797ad1bf --- .../res/values/attrs.xml | 22 ++++++++++++++ .../widget/IllustrationPreference.java | 29 ++++++++++++++++++- .../widget/IllustrationPreferenceTest.java | 16 ++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 packages/SettingsLib/IllustrationPreference/res/values/attrs.xml diff --git a/packages/SettingsLib/IllustrationPreference/res/values/attrs.xml b/packages/SettingsLib/IllustrationPreference/res/values/attrs.xml new file mode 100644 index 0000000000000..141886cda8a71 --- /dev/null +++ b/packages/SettingsLib/IllustrationPreference/res/values/attrs.xml @@ -0,0 +1,22 @@ + + + + + + + + \ No newline at end of file diff --git a/packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/IllustrationPreference.java b/packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/IllustrationPreference.java index 15920940140ce..3b902757c43ea 100644 --- a/packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/IllustrationPreference.java +++ b/packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/IllustrationPreference.java @@ -61,6 +61,8 @@ public class IllustrationPreference extends Preference { private View mMiddleGroundView; private OnBindListener mOnBindListener; + private boolean mLottieDynamicColor; + /** * Interface to listen in on when {@link #onBindViewHolder(PreferenceViewHolder)} occurs. */ @@ -146,6 +148,10 @@ public class IllustrationPreference extends Preference { ColorUtils.applyDynamicColors(getContext(), illustrationView); } + if (mLottieDynamicColor) { + LottieColorUtils.applyDynamicColors(getContext(), illustrationView); + } + if (mOnBindListener != null) { mOnBindListener.onBind(illustrationView); } @@ -262,6 +268,21 @@ public class IllustrationPreference extends Preference { } } + /** + * Sets the lottie illustration apply dynamic color. + */ + public void applyDynamicColor() { + mLottieDynamicColor = true; + notifyChanged(); + } + + /** + * Return if the lottie illustration apply dynamic color or not. + */ + public boolean isApplyDynamicColor() { + return mLottieDynamicColor; + } + private void resetImageResourceCache() { mImageDrawable = null; mImageUri = null; @@ -403,9 +424,15 @@ public class IllustrationPreference extends Preference { mIsAutoScale = false; if (attrs != null) { - final TypedArray a = context.obtainStyledAttributes(attrs, + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LottieAnimationView, 0 /*defStyleAttr*/, 0 /*defStyleRes*/); mImageResId = a.getResourceId(R.styleable.LottieAnimationView_lottie_rawRes, 0); + + a = context.obtainStyledAttributes(attrs, + R.styleable.IllustrationPreference, 0 /*defStyleAttr*/, 0 /*defStyleRes*/); + mLottieDynamicColor = a.getBoolean(R.styleable.IllustrationPreference_dynamicColor, + false); + a.recycle(); } } diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/IllustrationPreferenceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/IllustrationPreferenceTest.java index 103512d4a28a9..21e119a48f7bc 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/IllustrationPreferenceTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/IllustrationPreferenceTest.java @@ -215,4 +215,20 @@ public class IllustrationPreferenceTest { assertThat(mOnBindListenerAnimationView).isNull(); } + + @Test + public void onBindViewHolder_default_shouldNotApplyDynamicColor() { + mPreference.onBindViewHolder(mViewHolder); + + assertThat(mPreference.isApplyDynamicColor()).isFalse(); + } + + @Test + public void onBindViewHolder_applyDynamicColor_shouldReturnTrue() { + mPreference.applyDynamicColor(); + + mPreference.onBindViewHolder(mViewHolder); + + assertThat(mPreference.isApplyDynamicColor()).isTrue(); + } }