List of usage examples for android.graphics.drawable AnimationDrawable isRunning
@Override public boolean isRunning()
From source file:Main.java
public static void stopAnimation(ImageView pImageView) { AnimationDrawable pAnimation = null; if (pImageView != null) { pAnimation = (AnimationDrawable) pImageView.getBackground(); }/*from w w w. j a v a 2s .com*/ if (pAnimation != null && pAnimation.isRunning()) { pAnimation.stop(); } }
From source file:android.support.v7.app.MediaRouteButton.java
private void refreshRoute() { if (mAttachedToWindow) { 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;/*from www . ja v a2s . c o m*/ needsRefresh = true; } if (mIsConnecting != isConnecting) { mIsConnecting = isConnecting; needsRefresh = true; } if (needsRefresh) { refreshDrawableState(); if (mRemoteIndicator.getCurrent() instanceof AnimationDrawable) { AnimationDrawable curDrawable = (AnimationDrawable) mRemoteIndicator.getCurrent(); if (!curDrawable.isRunning()) { curDrawable.start(); } } } } }
From source file:ca.rmen.android.scrumchatter.meeting.detail.MeetingCursorAdapter.java
/** * Show the imageView and start its animation drawable. *///from w w w . ja va2 s. c om 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); } }); } }
From source file:androidx.mediarouter.app.MediaRouteButton.java
/** * Sets a drawable to use as the remote route indicator. *//*from w w w . j a va2s . c o m*/ 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;/*from w ww . j a 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); } } }
From source file:lu.fisch.canze.activities.MainActivity.java
private void setBluetoothState(int btState) { if (bluetoothMenutItem != null) { final ImageView imageView = (ImageView) bluetoothMenutItem.getActionView() .findViewById(R.id.animated_menu_item_action); // stop the animation if there is one running AnimationDrawable frameAnimation; if (imageView.getBackground() instanceof AnimationDrawable) { frameAnimation = (AnimationDrawable) imageView.getBackground(); if (frameAnimation.isRunning()) frameAnimation.stop();/* www.j ava2s . com*/ } switch (btState) { case BLUETOOTH_DISCONNECTED: imageView.setBackgroundResource(R.mipmap.bluetooth_none); break; case BLUETOOTH_CONNECTED: imageView.setBackgroundResource(R.mipmap.bluetooth_3); break; case BLUETOOTH_SEARCH: runOnUiThread(new Runnable() { @SuppressLint("NewApi") @Override public void run() { AnimationDrawable drawable = (AnimationDrawable) ContextCompat .getDrawable(getApplicationContext(), R.anim.animation_bluetooth); // Use setBackgroundDrawable() for API 14 and 15 and setBackground() for API 16+: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { imageView.setBackground(drawable); } else { //noinspection deprecation imageView.setBackgroundDrawable(drawable); } AnimationDrawable frameAnimation = (AnimationDrawable) imageView.getBackground(); frameAnimation.start(); } }); break; default: break; } } }