/** Change the checked state of the view to the inverse of its current state */
  public void toggle() {
    checked = !checked;
    setImageDrawable(checked ? onDrawable : offDrawable);

    if (isLollipop()) {
      Drawable drawable = getDrawable();
      if (drawable instanceof Animatable) {
        Animatable animatable = (Animatable) drawable;
        if (animatable.isRunning()) {
          animatable.stop();
        }
        animatable.start();
      }
    }
  }
  @Override
  protected synchronized void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    Drawable d = mCurrentDrawable;
    if (d != null) {
      // Translate canvas so a indeterminate circular progress bar with padding
      // rotates properly in its animation
      canvas.save();
      canvas.translate(mPaddingLeft, mPaddingTop);
      long time = getDrawingTime();
      if (mAnimation != null) {
        mAnimation.getTransformation(time, mTransformation);
        float scale = mTransformation.getAlpha();
        try {
          mInDrawing = true;
          d.setLevel((int) (scale * MAX_LEVEL));
        } finally {
          mInDrawing = false;
        }
        if (SystemClock.uptimeMillis() - mLastDrawTime >= ANIMATION_RESOLUTION) {
          mLastDrawTime = SystemClock.uptimeMillis();
          postInvalidateDelayed(ANIMATION_RESOLUTION);
        }
      }
      d.draw(canvas);
      canvas.restore();
      if (mShouldStartAnimationDrawable && d instanceof Animatable) {
        ((Animatable) d).start();
        mShouldStartAnimationDrawable = false;
      }
    }
  }
 /** Stop the indeterminate progress animation. */
 void stopAnimation() {
   mAnimation = null;
   mTransformation = null;
   if (mIndeterminateDrawable instanceof Animatable) {
     ((Animatable) mIndeterminateDrawable).stop();
     mShouldStartAnimationDrawable = false;
   }
   postInvalidate();
 }
Exemple #4
0
 /**
  * Create or update the drawable on the target {@link ImageView} to display the supplied bitmap
  * image.
  */
 static void setBitmap(
     ImageView target,
     Context context,
     Bitmap bitmap,
     Picasso.LoadedFrom loadedFrom,
     boolean noFade,
     boolean debugging) {
   Drawable placeholder = target.getDrawable();
   if (placeholder instanceof Animatable) {
     ((Animatable) placeholder).stop();
   }
   PicassoDrawable drawable =
       new PicassoDrawable(context, bitmap, placeholder, loadedFrom, noFade, debugging);
   target.setImageDrawable(drawable);
 }
  @OnClick(R.id.imageView)
  public void onClick(View view) {
    imageView = (ImageView) view;
    if (isChoose) {
      // 已选择
      imageView.setImageResource(R.drawable.animator_star_un_svg);
    } else {
      // 未选择
      imageView.setImageResource(R.drawable.animator_star_svg);
    }
    Drawable drawable = imageView.getDrawable();
    if (drawable instanceof Animatable) {
      ((Animatable) drawable).start();
    }

    isChoose = !isChoose;
  }
    public boolean apply(boolean isSecondaryIcon) {
      if (mMobileVisible && !mIsAirplaneMode) {
        mMobile.setImageResource(mMobileStrengthId);
        Drawable mobileDrawable = mMobile.getDrawable();
        if (mobileDrawable instanceof Animatable) {
          Animatable ad = (Animatable) mobileDrawable;
          if (!ad.isRunning()) {
            ad.start();
          }
        }

        mMobileDark.setImageResource(mMobileStrengthId);
        Drawable mobileDarkDrawable = mMobileDark.getDrawable();
        if (mobileDarkDrawable instanceof Animatable) {
          Animatable ad = (Animatable) mobileDarkDrawable;
          if (!ad.isRunning()) {
            ad.start();
          }
        }

        mMobileType.setImageResource(mMobileTypeId);
        mMobileGroup.setContentDescription(mMobileTypeDescription + " " + mMobileDescription);
        mMobileGroup.setVisibility(View.VISIBLE);
      } else {
        mMobileGroup.setVisibility(View.GONE);
      }

      // When this isn't next to wifi, give it some extra padding between the signals.
      mMobileGroup.setPaddingRelative(isSecondaryIcon ? mSecondaryTelephonyPadding : 0, 0, 0, 0);
      mMobile.setPaddingRelative(mIsMobileTypeIconWide ? mWideTypeIconStartPadding : 0, 0, 0, 0);
      mMobileDark.setPaddingRelative(
          mIsMobileTypeIconWide ? mWideTypeIconStartPadding : 0, 0, 0, 0);

      if (DEBUG)
        Log.d(
            TAG,
            String.format(
                "mobile: %s sig=%d dark=%d typ=%d",
                (mMobileVisible ? "VISIBLE" : "GONE"),
                mMobileStrengthId,
                mMobileDarkStrengthId,
                mMobileTypeId));

      mMobileType.setVisibility(mMobileTypeId != 0 ? View.VISIBLE : View.GONE);

      return mMobileVisible;
    }
 private void stopIfAnimatable(Drawable drawable) {
   if (drawable instanceof Animatable) {
     ((Animatable) drawable).stop();
   }
 }
 @Override
 public void onFinalImageSet(String id, @Nullable Object info, @Nullable Animatable anim) {
   if (anim != null) {
     anim.start();
   }
 }