Loading packages/SettingsLib/IllustrationPreference/res/values/attrs.xml 0 → 100644 +22 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2023 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> <declare-styleable name="IllustrationPreference"> <attr name="dynamicColor" format="boolean" /> </declare-styleable> </resources> No newline at end of file packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/IllustrationPreference.java +28 −1 Original line number Diff line number Diff line Loading @@ -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. */ Loading Loading @@ -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); } Loading Loading @@ -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; Loading Loading @@ -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(); } } Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/IllustrationPreferenceTest.java +16 −0 Original line number Diff line number Diff line Loading @@ -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(); } } Loading
packages/SettingsLib/IllustrationPreference/res/values/attrs.xml 0 → 100644 +22 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2023 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> <declare-styleable name="IllustrationPreference"> <attr name="dynamicColor" format="boolean" /> </declare-styleable> </resources> No newline at end of file
packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/IllustrationPreference.java +28 −1 Original line number Diff line number Diff line Loading @@ -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. */ Loading Loading @@ -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); } Loading Loading @@ -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; Loading Loading @@ -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(); } } Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/IllustrationPreferenceTest.java +16 −0 Original line number Diff line number Diff line Loading @@ -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(); } }