下面列出了android.graphics.drawable.Animatable#isRunning() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Toggle the current button style, changing the icon
* and animating the change if the device supports it.
*/
public void toggle() {
// Toggle the button style
mButtonStyle = (mButtonStyle == STYLE_NEXT) ? STYLE_DONE : STYLE_NEXT;
// Set image drawable depending on the button style
setImageDrawable(mButtonStyle == STYLE_NEXT ? mNextDrawable : mDoneDrawable);
// Attempt to animate the button if we're on Lollipop or above
if (Utils.hasLollipop()) {
Drawable drawable = getDrawable();
if (drawable instanceof Animatable) {
Animatable animatable = (Animatable) drawable;
if (animatable.isRunning()) {
animatable.stop();
}
animatable.start();
}
}
}
@Override
public void onClick(View v) {
DraweeController controller = mDraweeView.getController();
if (controller == null) {
return;
}
Animatable animatable = controller.getAnimatable();
if (animatable == null) {
return;
}
if (animatable.isRunning()) {
animatable.stop();
} else {
animatable.start();
}
}
/**
* 设置开启图片
*
* @param drawable 开启图片
*/
public void setOpenDrawable(Drawable drawable) {
if (mOpenDrawable == drawable)
return;
if (mOpenDrawable != null) {
if (mOpenDrawable instanceof Animatable)
((Animatable) mOpenDrawable).stop();
mOpenDrawable.setCallback(null);
}
mOpenDrawable = drawable;
if (mOpenDrawable != null) {
mOpenDrawable.setCallback(this);
if (mOpenDrawable instanceof Animatable) {
Animatable animatable = (Animatable) mOpenDrawable;
if (!animatable.isRunning())
animatable.start();
}
}
invalidate();
}
/**
* 设置错误图片
*
* @param drawable 错误图片
*/
public void setErrorDrawable(Drawable drawable) {
if (mErrorDrawable == drawable)
return;
if (mErrorDrawable != null) {
if (mErrorDrawable instanceof Animatable)
((Animatable) mErrorDrawable).stop();
mErrorDrawable.setCallback(null);
}
mErrorDrawable = drawable;
if (mErrorDrawable != null) {
mErrorDrawable.setCallback(this);
if (mErrorDrawable instanceof Animatable) {
Animatable animatable = (Animatable) mErrorDrawable;
if (!animatable.isRunning())
animatable.start();
}
}
invalidate();
}