@Override public void onStart() { if (animatable != null) { animatable.start(); } }
/** * Create or update the drawable on the target {@link ImageView} to display the supplied bitmap * image. */ static void setResult(ImageView target, Context context, RequestHandler.Result result, boolean noFade, boolean debugging) { Drawable placeholder = target.getDrawable(); if (placeholder instanceof Animatable) { ((Animatable) placeholder).stop(); } Bitmap bitmap = result.getBitmap(); if (bitmap != null) { Picasso.LoadedFrom loadedFrom = result.getLoadedFrom(); PicassoDrawable drawable = new PicassoDrawable(context, bitmap, placeholder, loadedFrom, noFade, debugging); target.setImageDrawable(drawable); return; } Drawable drawable = result.getDrawable(); if (drawable != null) { target.setImageDrawable(drawable); if (drawable instanceof Animatable) { ((Animatable) drawable).start(); } } }
@Override public int onFinish(@NonNull RefreshLayout refreshLayout, boolean success) { final View progressView = mProgressView; Drawable drawable = mProgressView.getDrawable(); if (drawable instanceof Animatable) { if (((Animatable) drawable).isRunning()) { ((Animatable) drawable).stop(); } } else { progressView.animate().rotation(0).setDuration(0); } progressView.setVisibility(GONE); return mFinishDuration;//延迟500毫秒之后再弹回 }
/** * gif播放与暂停 */ private void gifPlayController(DraweeController draweeController) { if (draweeController == null) { return; } Animatable animatable = draweeController.getAnimatable(); if (animatable == null) { return; } //判断是否正在运行 if (animatable.isRunning()) { //运行中,停止 animatable.stop(); } else { //停止了,运行 animatable.start(); } }
@Override protected void drawableStateChanged() { super.drawableStateChanged(); // autostart if(getDrawable().getCurrent() instanceof Animatable) { Animatable animatable = (Animatable) getDrawable().getCurrent(); if(!animatable.isRunning()) animatable.start(); } if (tint != null && tint.isStateful()) { setColorFilter(tint.getColorForState(getDrawableState(), 0)); } }
@Override public void onStop() { if (animatable != null) { animatable.stop(); } }
@Override public boolean isRunning() { boolean result = false; Drawable dr = getCurrent(); if (dr != null && dr instanceof Animatable) { result = ((Animatable) dr).isRunning(); } return result; }
/** * Toggle the current button style, changing the icon * and animating the change if the device supports it. */ public void toggle() { // Toggle the button style mButtonStyle = (mButtonStyle == STYLE_NEXT) ? STYLE_DONE : STYLE_NEXT; // Set image drawable depending on the button style setImageDrawable(mButtonStyle == STYLE_NEXT ? mNextDrawable : mDoneDrawable); // Attempt to animate the button if we're on Lollipop or above if (Utils.hasLollipop()) { Drawable drawable = getDrawable(); if (drawable instanceof Animatable) { Animatable animatable = (Animatable) drawable; if (animatable.isRunning()) { animatable.stop(); } animatable.start(); } } }
/** * Stop showing progress. */ public void stop(){ if(mProgressDrawable != null) ((Animatable)mProgressDrawable).stop(); }
mProgressId = mCircular ? R.style.Material_Drawable_CircularProgress : R.style.Material_Drawable_LinearProgress; needStart = mProgressDrawable != null && ((Animatable)mProgressDrawable).isRunning(); mProgressDrawable = mCircular ? new CircularProgressDrawable.Builder(context, mProgressId).build() : new LinearProgressDrawable.Builder(context, mProgressId).build(); ViewUtil.setBackground(this, mProgressDrawable);
@Override public void onAnimationStart(Animator animation) { animatable.start(); } });
/** * 设置开启图片 * * @param drawable 开启图片 */ public void setOpenDrawable(Drawable drawable) { if (mOpenDrawable == drawable) return; if (mOpenDrawable != null) { if (mOpenDrawable instanceof Animatable) ((Animatable) mOpenDrawable).stop(); mOpenDrawable.setCallback(null); } mOpenDrawable = drawable; if (mOpenDrawable != null) { mOpenDrawable.setCallback(this); if (mOpenDrawable instanceof Animatable) { Animatable animatable = (Animatable) mOpenDrawable; if (!animatable.isRunning()) animatable.start(); } } invalidate(); }
private void changeAnimation(Operation operation) { Drawable[] drawables = textView.getCompoundDrawables(); for (Drawable drawable : drawables) { if (drawable != null && drawable instanceof Animatable) { Animatable animatable = ((Animatable) drawable); switch (operation) { case START: animatable.start(); break; case STOP: animatable.stop(); break; } } } } }
@Override public void error(Exception e) { Drawable placeholder = target.getDrawable(); if (placeholder instanceof Animatable) { ((Animatable) placeholder).stop(); } if (errorResId != 0) { target.setImageResource(errorResId); } else if (errorDrawable != null) { target.setImageDrawable(errorDrawable); } if (callback != null) { callback.onError(e); } }
@Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { final View arrowView = mArrowView; final View progressView = mProgressView; arrowView.animate().cancel(); progressView.animate().cancel(); } final Drawable drawable = mProgressView.getDrawable(); if (drawable instanceof Animatable) { if (((Animatable) drawable).isRunning()) { ((Animatable) drawable).stop(); } } }
/** * Start showing progress. */ public void start(){ if(mProgressDrawable != null) ((Animatable)mProgressDrawable).start(); }
/** * 设置错误图片 * * @param drawable 错误图片 */ public void setErrorDrawable(Drawable drawable) { if (mErrorDrawable == drawable) return; if (mErrorDrawable != null) { if (mErrorDrawable instanceof Animatable) ((Animatable) mErrorDrawable).stop(); mErrorDrawable.setCallback(null); } mErrorDrawable = drawable; if (mErrorDrawable != null) { mErrorDrawable.setCallback(this); if (mErrorDrawable instanceof Animatable) { Animatable animatable = (Animatable) mErrorDrawable; if (!animatable.isRunning()) animatable.start(); } } invalidate(); }