List of usage examples for android.graphics.drawable Animatable stop
void stop();
From source file:Main.java
public static void startVDAnimation(ImageView imageView, @DrawableRes int inactiveResId, @DrawableRes int activeResId, int duration) { int drawableResId = imageView.isSelected() ? activeResId : inactiveResId; Drawable drawable = ContextCompat.getDrawable(imageView.getContext(), drawableResId); imageView.setImageDrawable(drawable); if (drawable instanceof Animatable) { Animatable animatable = (Animatable) drawable; if (animatable.isRunning()) { animatable.stop(); }//from w w w. java2s.c o m animatable.start(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { imageView.setSelected(!imageView.isSelected()); } else { imageView.postDelayed(() -> { imageView.setSelected(!imageView.isSelected()); int nextDrawableResId = imageView.isSelected() ? activeResId : inactiveResId; Drawable nextDrawable = ContextCompat.getDrawable(imageView.getContext(), nextDrawableResId); imageView.setImageDrawable(nextDrawable); }, duration); } } }
From source file:io.github.importre.animatedicons.AnimatedButton.java
/** * Change the checked state of the view to the inverse of its current state */// w w w . j ava 2 s. co m public void toggle() { checked = !checked; setImageDrawable(checked ? onDrawable : offDrawable); if (isLollipop()) { Drawable drawable = getDrawable(); if (drawable instanceof Animatable) { Animatable animatable = (Animatable) drawable; if (animatable.isRunning()) { animatable.stop(); } animatable.start(); } } }
From source file:cn.qingchengfit.widgets.AnimatedButton.java
/** * Change the checked state of the view to the inverse of its current state *///from w w w .j a v a 2 s .c o m public void toggle() { checked = !checked; setImageDrawable(checked ? onDrawable : offDrawable); Drawable drawable = getDrawable(); if (drawable instanceof Animatable) { Animatable animatable = (Animatable) drawable; if (animatable.isRunning()) { animatable.stop(); } animatable.start(); } }