/**
  * make animation to start or end when target view was be Visible or Gone or Invisible. make
  * animation to cancel when target view be onDetachedFromWindow.
  *
  * @param animStatus
  */
 public void setAnimationStatus(AnimStatus animStatus) {
   if (mAnimators == null) {
     return;
   }
   int count = mAnimators.size();
   for (int i = 0; i < count; i++) {
     Animator animator = mAnimators.get(i);
     boolean isRunning = animator.isRunning();
     switch (animStatus) {
       case START:
         if (!isRunning) {
           animator.start();
         }
         break;
       case END:
         if (isRunning) {
           animator.end();
         }
         break;
       case CANCEL:
         if (isRunning) {
           animator.cancel();
         }
         break;
     }
   }
 }
 @Override
 public void setVisibility(int visibility) {
   if (visibility != getVisibility()) {
     if (mVisibilityAnim != null) {
       mVisibilityAnim.end();
     }
     super.setVisibility(visibility);
   }
 }
Exemple #3
0
  public void compatSetOrAnimatePlusCheckIcon(
      final ImageView imageView, boolean isCheck, boolean allowAnimate) {

    final int imageResId =
        isCheck
            ? R.drawable.add_schedule_button_icon_checked
            : R.drawable.add_schedule_button_icon_unchecked;

    if (imageView.getTag() != null) {
      if (imageView.getTag() instanceof Animator) {
        Animator anim = (Animator) imageView.getTag();
        anim.end();
        imageView.setAlpha(1f);
      }
    }

    if (allowAnimate && isCheck) {
      int duration = mActivity.getResources().getInteger(android.R.integer.config_shortAnimTime);

      Animator outAnimator = ObjectAnimator.ofFloat(imageView, View.ALPHA, 0f);
      outAnimator.setDuration(duration / 2);
      outAnimator.addListener(
          new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
              imageView.setImageResource(imageResId);
            }
          });

      AnimatorSet inAnimator = new AnimatorSet();
      outAnimator.setDuration(duration);
      inAnimator.playTogether(
          ObjectAnimator.ofFloat(imageView, View.ALPHA, 1f),
          ObjectAnimator.ofFloat(imageView, View.SCALE_X, 0f, 1f),
          ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 0f, 1f));

      AnimatorSet set = new AnimatorSet();
      set.playSequentially(outAnimator, inAnimator);
      set.addListener(
          new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
              imageView.setTag(null);
            }
          });
      imageView.setTag(set);
      set.start();
    } else {
      mHandler.post(
          new Runnable() {
            @Override
            public void run() {
              imageView.setImageResource(imageResId);
            }
          });
    }
  }
 @Override
 public void stop() {
   final ArrayList<Animator> animators = mAnimatedVectorState.mAnimators;
   final int size = animators.size();
   for (int i = 0; i < size; i++) {
     final Animator animator = animators.get(i);
     animator.end();
   }
 }