Loading packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/IllustrationPreference.java +23 −0 Original line number Diff line number Diff line Loading @@ -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() { Loading Loading @@ -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; } /** Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/IllustrationPreferenceTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -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() { Loading @@ -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 Loading Loading @@ -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(); } } Loading
packages/SettingsLib/IllustrationPreference/src/com/android/settingslib/widget/IllustrationPreference.java +23 −0 Original line number Diff line number Diff line Loading @@ -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() { Loading Loading @@ -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; } /** Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/IllustrationPreferenceTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -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() { Loading @@ -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 Loading Loading @@ -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(); } }