Merge "Add a listener for when the illustration animation view is bound" into tm-qpr-dev am: a09626e7fc
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20600206 Change-Id: I41e80a79d83beeaed17fa7eed6da65e186f5e173 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -59,6 +59,18 @@ public class IllustrationPreference extends Preference {
|
|||||||
private Uri mImageUri;
|
private Uri mImageUri;
|
||||||
private Drawable mImageDrawable;
|
private Drawable mImageDrawable;
|
||||||
private View mMiddleGroundView;
|
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 =
|
private final Animatable2.AnimationCallback mAnimationCallback =
|
||||||
new Animatable2.AnimationCallback() {
|
new Animatable2.AnimationCallback() {
|
||||||
@@ -133,6 +145,17 @@ public class IllustrationPreference extends Preference {
|
|||||||
if (IS_ENABLED_LOTTIE_ADAPTIVE_COLOR) {
|
if (IS_ENABLED_LOTTIE_ADAPTIVE_COLOR) {
|
||||||
ColorUtils.applyDynamicColors(getContext(), illustrationView);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ public class IllustrationPreferenceTest {
|
|||||||
private PreferenceViewHolder mViewHolder;
|
private PreferenceViewHolder mViewHolder;
|
||||||
private FrameLayout mMiddleGroundLayout;
|
private FrameLayout mMiddleGroundLayout;
|
||||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||||
|
private IllustrationPreference.OnBindListener mOnBindListener;
|
||||||
|
private LottieAnimationView mOnBindListenerAnimationView;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -82,6 +84,12 @@ public class IllustrationPreferenceTest {
|
|||||||
|
|
||||||
final AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
|
final AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
|
||||||
mPreference = new IllustrationPreference(mContext, attributeSet);
|
mPreference = new IllustrationPreference(mContext, attributeSet);
|
||||||
|
mOnBindListener = new IllustrationPreference.OnBindListener() {
|
||||||
|
@Override
|
||||||
|
public void onBind(LottieAnimationView animationView) {
|
||||||
|
mOnBindListenerAnimationView = animationView;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -186,4 +194,25 @@ public class IllustrationPreferenceTest {
|
|||||||
assertThat(mBackgroundView.getMaxHeight()).isEqualTo(restrictedHeight);
|
assertThat(mBackgroundView.getMaxHeight()).isEqualTo(restrictedHeight);
|
||||||
assertThat(mAnimationView.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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user