Example usage for android.graphics.drawable AnimationDrawable selectDrawable

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

Introduction

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

Prototype

public boolean selectDrawable(int index) 

Source Link

Document

Sets the currently displayed drawable by index.

Usage

From source file:androidx.mediarouter.app.MediaRouteButton.java

/**
 * Sets a drawable to use as the remote route indicator.
 *//*from ww  w  . j  a  va 2 s.c om*/
public void setRemoteIndicatorDrawable(Drawable d) {
    if (mRemoteIndicatorLoader != null) {
        mRemoteIndicatorLoader.cancel(false);
    }

    if (mRemoteIndicator != null) {
        mRemoteIndicator.setCallback(null);
        unscheduleDrawable(mRemoteIndicator);
    }
    if (d != null) {
        if (mButtonTint != null) {
            d = DrawableCompat.wrap(d.mutate());
            DrawableCompat.setTintList(d, mButtonTint);
        }
        d.setCallback(this);
        d.setState(getDrawableState());
        d.setVisible(getVisibility() == VISIBLE, false);
    }
    mRemoteIndicator = d;

    refreshDrawableState();
    if (mAttachedToWindow && mRemoteIndicator != null
            && mRemoteIndicator.getCurrent() instanceof AnimationDrawable) {
        AnimationDrawable curDrawable = (AnimationDrawable) mRemoteIndicator.getCurrent();
        if (mIsConnecting) {
            if (!curDrawable.isRunning()) {
                curDrawable.start();
            }
        } else if (mRemoteActive) {
            if (curDrawable.isRunning()) {
                curDrawable.stop();
            }
            curDrawable.selectDrawable(curDrawable.getNumberOfFrames() - 1);
        }
    }
}

From source file:androidx.mediarouter.app.MediaRouteButton.java

void refreshRoute() {
    final MediaRouter.RouteInfo route = mRouter.getSelectedRoute();
    final boolean isRemote = !route.isDefaultOrBluetooth() && route.matchesSelector(mSelector);
    final boolean isConnecting = isRemote && route.isConnecting();
    boolean needsRefresh = false;
    if (mRemoteActive != isRemote) {
        mRemoteActive = isRemote;/*w ww  .ja  v  a2  s .  c  o m*/
        needsRefresh = true;
    }
    if (mIsConnecting != isConnecting) {
        mIsConnecting = isConnecting;
        needsRefresh = true;
    }

    if (needsRefresh) {
        updateContentDescription();
        refreshDrawableState();
    }
    if (mAttachedToWindow) {
        setEnabled(mRouter.isRouteAvailable(mSelector, MediaRouter.AVAILABILITY_FLAG_IGNORE_DEFAULT_ROUTE));
    }
    if (mRemoteIndicator != null && mRemoteIndicator.getCurrent() instanceof AnimationDrawable) {
        AnimationDrawable curDrawable = (AnimationDrawable) mRemoteIndicator.getCurrent();
        if (mAttachedToWindow) {
            if ((needsRefresh || isConnecting) && !curDrawable.isRunning()) {
                curDrawable.start();
            }
        } else if (isRemote && !isConnecting) {
            // When the route is already connected before the view is attached, show the last
            // frame of the connected animation immediately.
            if (curDrawable.isRunning()) {
                curDrawable.stop();
            }
            curDrawable.selectDrawable(curDrawable.getNumberOfFrames() - 1);
        }
    }
}