Example usage for android.graphics.drawable AnimationDrawable setVisible

List of usage examples for android.graphics.drawable AnimationDrawable setVisible

Introduction

In this page you can find the example usage for android.graphics.drawable AnimationDrawable setVisible.

Prototype

@Override
public boolean setVisible(boolean visible, boolean restart) 

Source Link

Document

Sets whether this AnimationDrawable is visible.

Usage

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);
            }
        });
    }
}