List of usage examples for android.graphics.drawable AnimationDrawable setVisible
@Override public boolean setVisible(boolean visible, boolean restart)
From source file:ca.rmen.android.scrumchatter.meeting.detail.MeetingCursorAdapter.java
/** * Stop the animation drawable on this imageView and hide the imageView. *///from w w w . j a v a2 s. co m private void stopAnimation(final ImageView imageView) { if (imageView.getVisibility() == View.VISIBLE) { Log.v(TAG, "stopAnimation"); imageView.setVisibility(View.INVISIBLE); final AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getDrawable(); animationDrawable.setVisible(false, false); } }
From source file:ca.rmen.android.scrumchatter.meeting.detail.MeetingCursorAdapter.java
/** * Show the imageView and start its animation drawable. *///ww w . j a va 2 s.co m private void startAnimation(final ImageView imageView) { if (imageView.getVisibility() != View.VISIBLE) { Log.v(TAG, "startAnimation"); imageView.setVisibility(View.VISIBLE); final AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getDrawable(); // On some devices, directly calling start() on the animation does not work. // We have to wait until the ImageView is visible before starting the animation. imageView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { if (!animationDrawable.isRunning()) { imageView.post(() -> { animationDrawable.setVisible(true, false); animationDrawable.start(); }); } imageView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } }); } }