diff options
2 files changed, 52 insertions, 0 deletions
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 468a97630e19..15920940140c 100644 --- a/packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/IllustrationPreference.java +++ b/packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/IllustrationPreference.java @@ -59,6 +59,18 @@ public class IllustrationPreference extends Preference { private Uri mImageUri; private Drawable mImageDrawable; private View mMiddleGroundView; + private OnBindListener mOnBindListener; + + /** + * Interface to listen in on when {@link #onBindViewHolder(PreferenceViewHolder)} occurs. + */ + public interface OnBindListener { + /** + * Called when when {@link #onBindViewHolder(PreferenceViewHolder)} occurs. + * @param animationView the animation view for this preference. + */ + void onBind(LottieAnimationView animationView); + } private final Animatable2.AnimationCallback mAnimationCallback = new Animatable2.AnimationCallback() { @@ -133,6 +145,17 @@ public class IllustrationPreference extends Preference { if (IS_ENABLED_LOTTIE_ADAPTIVE_COLOR) { ColorUtils.applyDynamicColors(getContext(), illustrationView); } + + if (mOnBindListener != null) { + mOnBindListener.onBind(illustrationView); + } + } + + /** + * Sets a listener to be notified when the views are binded. + */ + public void setOnBindListener(OnBindListener listener) { + mOnBindListener = listener; } /** 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 29549d9a7fa7..103512d4a28a 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 @@ -61,6 +61,8 @@ public class IllustrationPreferenceTest { private PreferenceViewHolder mViewHolder; private FrameLayout mMiddleGroundLayout; private final Context mContext = ApplicationProvider.getApplicationContext(); + private IllustrationPreference.OnBindListener mOnBindListener; + private LottieAnimationView mOnBindListenerAnimationView; @Before public void setUp() { @@ -82,6 +84,12 @@ public class IllustrationPreferenceTest { final AttributeSet attributeSet = Robolectric.buildAttributeSet().build(); mPreference = new IllustrationPreference(mContext, attributeSet); + mOnBindListener = new IllustrationPreference.OnBindListener() { + @Override + public void onBind(LottieAnimationView animationView) { + mOnBindListenerAnimationView = animationView; + } + }; } @Test @@ -186,4 +194,25 @@ public class IllustrationPreferenceTest { assertThat(mBackgroundView.getMaxHeight()).isEqualTo(restrictedHeight); assertThat(mAnimationView.getMaxHeight()).isEqualTo(restrictedHeight); } + + @Test + public void setOnBindListener_isNotified() { + mOnBindListenerAnimationView = null; + mPreference.setOnBindListener(mOnBindListener); + + mPreference.onBindViewHolder(mViewHolder); + + assertThat(mOnBindListenerAnimationView).isNotNull(); + assertThat(mOnBindListenerAnimationView).isEqualTo(mAnimationView); + } + + @Test + public void setOnBindListener_notNotified() { + mOnBindListenerAnimationView = null; + mPreference.setOnBindListener(null); + + mPreference.onBindViewHolder(mViewHolder); + + assertThat(mOnBindListenerAnimationView).isNull(); + } } |