private void doBackAnim(final View view) {
   ValueAnimator tmpAnimator =
       ObjectAnimator.ofFloat(view, "translationX", view.getTranslationX(), 0);
   tmpAnimator.setDuration(mBackAnimTime);
   tmpAnimator.setRepeatCount(0);
   tmpAnimator.start();
 }
  /** Pop alphabet */
  protected void popAlphabet() {
    if (mAlphabetList.size() < POP_LIMIT_NUM) {
      return;
    }
    backAlphabet(false); // first, back alphabet, and pop alphabet

    isPoped = true;
    changeTextColor(mCurrentSelection, false);
    isShowSelected = false;
    invalidate();

    int position;
    int halfMoveCount = (mMoveCount + 1) / 2;
    for (int i = 0; i < mMoveCount; i++) {
      position = mCurrentSelection - halfMoveCount + 1 + i;
      if (position >= 0 && position < getChildCount()) {
        View view = getChildAt(position);
        ValueAnimator tmpAnimator =
            ObjectAnimator.ofFloat(
                view,
                "translationX",
                view.getTranslationX(),
                -mMaxOffset * (float) Math.sin((i + 1) * Math.PI / (mMoveCount + 1)));
        // Math.sin((i + 1) * Math.PI / (mMoveCount + 2))区间是[0,1],如移动的字母数(mMoveCount=3),
        // 那么取sin曲线上5个点,1和5点无动画,只创建中间3点动画,值是0.7071、1.0、0.7071。
        tmpAnimator.setDuration(mPopAnimTime);
        tmpAnimator.setRepeatCount(0);
        tmpAnimator.setInterpolator(mInterpolator);
        tmpAnimator.start();
        mAnimMap.put(position, tmpAnimator);
      }
    }
  }
  private void startAnimation(final boolean isLeft, final boolean isOpen, boolean staticDuration) {
    mToOpen = isOpen;
    int total;
    if (isLeft) {
      mTargetView = mLeftDrawer;
      mStartLeft = mLeftDrawer.getLeft();
      total = mLeftDrawer.getWidth();
      mEndLeft = mToOpen ? 0 : -total;
    } else {
      mTargetView = mRightDrawer;
      mStartLeft = mRightDrawer.getLeft();
      total = mRightDrawer.getWidth();
      mEndLeft = mToOpen ? getWidth() - total : getWidth();
    }

    if (mStartLeft == mEndLeft) {
      // No need to animate
      updateDrawerSlide(mTargetView, mToOpen ? 1.0f : 0.0f);
      updateDrawerState(mTargetView, mToOpen ? STATE_OPEN : STATE_CLOSED);
      if (mToOpen) dispatchOnDrawerOpened(mTargetView);
      else dispatchOnDrawerClosed(mTargetView);
      return;
    }

    mAnimator.setDuration(
        staticDuration ? ANIMATE_TIME : ANIMATE_TIME * Math.abs(mStartLeft - mEndLeft) / total);

    mAnimator.start();
  }
Beispiel #4
0
  private void animateOut() {
    ValueAnimator animWidth = ValueAnimator.ofInt(zoomableImageView.getMeasuredWidth(), rect.right);
    animWidth.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = zoomableImageView.getLayoutParams();
            layoutParams.width = val;
            zoomableImageView.setLayoutParams(layoutParams);
          }
        });
    animWidth.setDuration(500);
    animWidth.start();

    ValueAnimator animHeight =
        ValueAnimator.ofInt(zoomableImageView.getMeasuredHeight(), rect.bottom);
    animHeight.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = zoomableImageView.getLayoutParams();
            layoutParams.height = val;
            zoomableImageView.setLayoutParams(layoutParams);
          }
        });
    animHeight.setDuration(500);
    animHeight.start();
    if (statusBarHeightCorrection > 0) {
      zoomableImageView.animate().y(-statusBarHeightCorrection).setDuration(300).start();
    }
    zoomableImageView.animate().alpha(0.0f).setDuration(500).start();
  }
  private void startUnCheckedAnimation() {
    ValueAnimator animator = ValueAnimator.ofFloat(0f, 1.0f);
    animator.setDuration(mAnimDuration);
    animator.setInterpolator(new LinearInterpolator());
    animator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            mScaleVal = (float) animation.getAnimatedValue();
            mFloorColor = getGradientColor(mCheckedColor, COLOR_FLOOR_UNCHECKED, mScaleVal);
            postInvalidate();
          }
        });
    animator.start();

    ValueAnimator floorAnimator = ValueAnimator.ofFloat(1.0f, 0.8f, 1.0f);
    floorAnimator.setDuration(mAnimDuration);
    floorAnimator.setInterpolator(new LinearInterpolator());
    floorAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            mFloorScale = (float) animation.getAnimatedValue();
            postInvalidate();
          }
        });
    floorAnimator.start();
  }
  private void initBackgroundDimAnimation() {
    final int maxAlpha = Color.alpha(mBackgroundColor);
    final int red = Color.red(mBackgroundColor);
    final int green = Color.green(mBackgroundColor);
    final int blue = Color.blue(mBackgroundColor);

    mShowBackgroundAnimator = ValueAnimator.ofInt(0, maxAlpha);
    mShowBackgroundAnimator.setDuration(ANIMATION_DURATION);
    mShowBackgroundAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            Integer alpha = (Integer) animation.getAnimatedValue();
            setBackgroundColor(Color.argb(alpha, red, green, blue));
          }
        });

    mHideBackgroundAnimator = ValueAnimator.ofInt(maxAlpha, 0);
    mHideBackgroundAnimator.setDuration(ANIMATION_DURATION);
    mHideBackgroundAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            Integer alpha = (Integer) animation.getAnimatedValue();
            setBackgroundColor(Color.argb(alpha, red, green, blue));
          }
        });
  }
  @Override
  public List<Animator> createAnimation() {
    List<Animator> animators = new ArrayList<>();
    float startX = getWidth() / 5;
    float startY = getWidth() / 5;
    for (int i = 0; i < 3; i++) {
      final int index = i;
      ValueAnimator translateXAnim =
          ValueAnimator.ofFloat(getWidth() / 2, getWidth() - startX, startX, getWidth() / 2);
      if (i == 1) {
        translateXAnim =
            ValueAnimator.ofFloat(getWidth() - startX, startX, getWidth() / 2, getWidth() - startX);
      } else if (i == 2) {
        translateXAnim = ValueAnimator.ofFloat(startX, getWidth() / 2, getWidth() - startX, startX);
      }
      ValueAnimator translateYAnim =
          ValueAnimator.ofFloat(startY, getHeight() - startY, getHeight() - startY, startY);
      if (i == 1) {
        translateYAnim =
            ValueAnimator.ofFloat(
                getHeight() - startY, getHeight() - startY, startY, getHeight() - startY);
      } else if (i == 2) {
        translateYAnim =
            ValueAnimator.ofFloat(
                getHeight() - startY, startY, getHeight() - startY, getHeight() - startY);
      }

      translateXAnim.setDuration(2000);
      translateXAnim.setInterpolator(new LinearInterpolator());
      translateXAnim.setRepeatCount(-1);
      translateXAnim.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
              translateX[index] = (float) animation.getAnimatedValue();
              postInvalidate();
            }
          });
      translateXAnim.start();

      translateYAnim.setDuration(2000);
      translateYAnim.setInterpolator(new LinearInterpolator());
      translateYAnim.setRepeatCount(-1);
      translateYAnim.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
              translateY[index] = (float) animation.getAnimatedValue();
              postInvalidate();
            }
          });
      translateYAnim.start();

      animators.add(translateXAnim);
      animators.add(translateYAnim);
    }
    return animators;
  }
  private void animateBothText() {
    ValueAnimator rotateAnimX = ObjectAnimator.ofFloat(bothText, "scaleX", 0f, 0.9f);
    rotateAnimX.setDuration(700);
    rotateAnimX.start();

    ValueAnimator rotateAnimY = ObjectAnimator.ofFloat(bothText, "scaleY", 0f, 0.9f);
    rotateAnimY.setDuration(700);
    rotateAnimY.start();
  }
  private void startLineAnim() {
    mStatus = LINE_MOVE;
    int duration = 1;
    // (cxRight - cxLeft) != mRecWidth. 极小的数字也会画出一个点
    linePosXAnim = ValueAnimator.ofFloat(0, cxRight - cxLeft);
    linePosXAnim.setDuration(duration * mRippleDuration);
    linePosXAnim.setInterpolator(new LinearInterpolator());
    linePosXAnim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            mLinePosX = (float) animation.getAnimatedValue();
            postInvalidate();
          }
        });

    sweepAngAnim = ValueAnimator.ofFloat(180f, mSweepAngMin);
    sweepAngAnim.setDuration(duration * mRippleDuration);
    sweepAngAnim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            mSweepAng = (float) animation.getAnimatedValue();
            postInvalidate();
          }
        });
    sweepAngAnim.setInterpolator(new LinearInterpolator());
    sweepAngAnim.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animation) {}

          @Override
          public void onAnimationEnd(Animator animation) {
            mLinePosX = 0;
            mSweepAng = 180f;
            startTickAnim();
          }

          @Override
          public void onAnimationCancel(Animator animation) {}

          @Override
          public void onAnimationRepeat(Animator animation) {}
        });

    AnimatorSet animSet = new AnimatorSet();
    animSet.playSequentially(linePosXAnim, sweepAngAnim);
    animSet.start();
  }
 @Override
 public List<Animator> createAnimation() {
   List<Animator> animators = new ArrayList<>();
   float circleSpacing = 4;
   float radius = (getWidth() - circleSpacing * 2) / 6;
   int[] delays = new int[] {70, 140, 210};
   for (int i = 0; i < 3; i++) {
     final int index = i;
     ValueAnimator scaleAnim =
         ValueAnimator.ofFloat(getHeight() / 2, getHeight() / 2 - radius * 2, getHeight() / 2);
     scaleAnim.setDuration(600);
     scaleAnim.setRepeatCount(-1);
     scaleAnim.setStartDelay(delays[i]);
     scaleAnim.addUpdateListener(
         new ValueAnimator.AnimatorUpdateListener() {
           @Override
           public void onAnimationUpdate(ValueAnimator animation) {
             translateYFloats[index] = (float) animation.getAnimatedValue();
             postInvalidate();
           }
         });
     scaleAnim.start();
     animators.add(scaleAnim);
   }
   return animators;
 }
Beispiel #11
0
  private void fadeOutDragView() {
    mFadeOutAnim = new ValueAnimator();
    mFadeOutAnim.setDuration(150);
    mFadeOutAnim.setFloatValues(0f, 1f);
    mFadeOutAnim.removeAllUpdateListeners();
    mFadeOutAnim.addUpdateListener(
        new AnimatorUpdateListener() {
          public void onAnimationUpdate(ValueAnimator animation) {
            final float percent = (Float) animation.getAnimatedValue();

            float alpha = 1 - percent;
            mDropView.setAlpha(alpha);
          }
        });
    mFadeOutAnim.addListener(
        new AnimatorListenerAdapter() {
          public void onAnimationEnd(Animator animation) {
            if (mDropView != null) {
              mDragController.onDeferredEndDrag(mDropView);
            }
            mDropView = null;
            invalidate();
          }
        });
    mFadeOutAnim.start();
  }
Beispiel #12
0
 public void start(int a) {
   v = ValueAnimator.ofInt(0, 1000);
   v.setDuration(a);
   v.addUpdateListener(this);
   playing = true;
   v.start();
 }
  private AnimatorSet startAniMoveRightToCenter(View rightDot) {
    int dotDiameter = (int) getResources().getDimension(R.dimen.loading_dot_size);
    int dotPadding = (int) getResources().getDimension(R.dimen.loading_dot_padding);
    AnimatorSet moveRightToCentral = new AnimatorSet();
    ObjectAnimator rightDotToCentral =
        ObjectAnimator.ofFloat(rightDot, "translationX", 0, -dotPadding - dotDiameter);

    rightDotColorChange =
        ValueAnimator.ofObject(
            new ArgbEvaluator(),
            getResources().getColor(R.color.dot_normal),
            getResources().getColor(R.color.dot_active));
    final GradientDrawable rightDotBg = (GradientDrawable) rightDot.getBackground();
    rightDotColorChange.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(final ValueAnimator animator) {
            rightDotBg.setColor((Integer) animator.getAnimatedValue());
          }
        });
    rightDotColorChange.setDuration(aniDuration);
    rightDotColorChange.addListener(this);
    moveRightToCentral.play(rightDotColorChange).with(rightDotToCentral);
    return moveRightToCentral;
  }
  @Override
  protected void runAnimators() {
    reflectSetupStartEndListeners();
    animMap.clear();
    for (int i = 0, count = getTransitionCount(); i < count; i++) {
      Transition transition = getTransitionAt(i);
      ArrayList<ValueAnimator> valueAnimators = new ArrayList<>();
      for (Animator animator : AnimatorUtils.collectAnimators(transition)) {
        valueAnimators.addAll(AnimatorUtils.collectValueAnimators(animator));
      }

      // insure animator's duration, startDelay, Interpolator same as this transition
      long duration = (long) (getDuration() / AnimatorUtils.getAnimatorDurationScale());
      long startDelay = getStartDelay();
      TimeInterpolator interpolator = getInterpolator();
      for (ValueAnimator animator : valueAnimators) {
        if (duration >= 0) animator.setDuration(duration);
        if (startDelay >= 0) animator.setStartDelay(startDelay + animator.getStartDelay());
        if (interpolator != null) animator.setInterpolator(interpolator);
      }

      animMap.put(transition, valueAnimators);
      // you can change transition's duration, startDelay and Interpolator at here
      if (playControl != null) playControl.onPreRunAnimator(transition, valueAnimators);
    }
  }
 /** 抛物线 */
 public void parabolaRun(View view) {
   ValueAnimator ani = new ValueAnimator();
   ani.setDuration(1000);
   ani.setObjectValues(new PointF(0, 0));
   ani.setInterpolator(new LinearInterpolator());
   ani.setEvaluator(
       new TypeEvaluator<PointF>() {
         @Override
         public PointF evaluate(float fraction, PointF startValue, PointF endValue) {
           Log.e("TAG", fraction + "");
           // x方向的速度v=200px/s;y方向的加速度为0.5f,速度也是v
           PointF point = new PointF();
           point.x = mX * fraction;
           point.y = mY * fraction * fraction;
           return point;
         }
       });
   ani.addUpdateListener(
       new AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           PointF point = (PointF) animation.getAnimatedValue();
           ivBall.setX(point.x);
           ivBall.setY(point.y);
         }
       });
   ani.start();
 }
Beispiel #16
0
  /**
   * call when you want to animate the highlight in or out - this is NOT dependant on {@link
   * #setChecked(boolean)} above because on scroll, among other layout calls, would trigger
   * setChecked many, many times
   *
   * @param checked
   */
  public void animateHighlight(boolean checked) {
    if (mHighlightAnimator != null && mHighlightAnimator.isRunning()) {
      mHighlightAnimator.cancel();
      mHighlightAnimator.removeAllUpdateListeners();
      mHighlightAnimator.removeAllListeners();
    }

    if (checked) {
      mHighlightAnimator = ValueAnimator.ofFloat(0, mMaxWidth);
    } else {
      mHighlightAnimator = ValueAnimator.ofFloat(mMaxWidth, 0);
    }

    mHighlightAnimator.setDuration(250);
    mHighlightAnimator.addListener(mHighlightAnimatorListener);
    mHighlightAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            mPinkPaint.setStrokeWidth((float) animation.getAnimatedValue());
            postInvalidate();
          }
        });
    mHighlightAnimator.start();
  }
Beispiel #17
0
  private void peak(boolean next, boolean once) {
    final float baseFlipDistance = mCurrentPageIndex * FLIP_DISTANCE_PER_PAGE;
    if (next) {
      mPeakAnim =
          ValueAnimator.ofFloat(baseFlipDistance, baseFlipDistance + FLIP_DISTANCE_PER_PAGE / 4);
    } else {
      mPeakAnim =
          ValueAnimator.ofFloat(baseFlipDistance, baseFlipDistance - FLIP_DISTANCE_PER_PAGE / 4);
    }
    mPeakAnim.setInterpolator(mPeakInterpolator);
    mPeakAnim.addUpdateListener(
        new AnimatorUpdateListener() {

          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            setFlipDistance((Float) animation.getAnimatedValue());
          }
        });
    mPeakAnim.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            endPeak();
          }
        });
    mPeakAnim.setDuration(PEAK_ANIM_DURATION);
    mPeakAnim.setRepeatMode(ValueAnimator.REVERSE);
    mPeakAnim.setRepeatCount(once ? 1 : ValueAnimator.INFINITE);
    mPeakAnim.start();
  }
  public void startRippleAnimation(
      final int centerX, final int centerY, int min, int max, boolean expand) {

    isAnimation = true;

    ValueAnimator valueAnimator;

    if (expand) valueAnimator = ValueAnimator.ofInt(min, max);
    else valueAnimator = ValueAnimator.ofInt(max, 0);

    valueAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            path.reset();
            path.addCircle(centerX, centerY, (int) animation.getAnimatedValue(), Path.Direction.CW);
            path.close();
            invalidate();
          }
        });

    valueAnimator.setInterpolator(interpolator);
    valueAnimator.setDuration(duration).start();
    postDelayed(
        new Runnable() {
          @Override
          public void run() {
            isAnimation = false;
          }
        },
        duration);
  }
  /** 圆周运动 */
  public void circleRun(View view) {
    ValueAnimator animator = new ValueAnimator();
    animator.setDuration(10000);
    animator.setTarget(mCircleBall);
    animator.setObjectValues(new PointF(mCircleBall.getX(), mCircleBall.getY()));
    animator.setInterpolator(new LinearInterpolator());

    animator.setEvaluator(
        new TypeEvaluator<PointF>() {
          @Override
          public PointF evaluate(float fraction, PointF startValue, PointF endValue) {
            /** 设置圆的半径r为200px 圆点坐标为(x1,y1) 圆周上的点坐标的公式为 x = x1 + r * cos(wt) y = y1 + r * sin(wt) */
            PointF point = new PointF();
            point.x =
                (float) (mScreenWidth / 2 + 200 * Math.cos(Math.toRadians(360 * fraction - 90)));
            point.y = (float) (200 + 200 * Math.sin(Math.toRadians(360 * fraction - 90)));
            return point;
          }
        });
    //        //设置重复模式,RESTART为结束后重新开始,REVERSE为按原来的轨迹逆向返回
    // animator.setRepeatMode(Animation.RESTART);
    // 设置重复次数,INFINITE为无限
    animator.setRepeatCount(0);
    animator.start();
    animator.addUpdateListener(
        new AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            PointF point = (PointF) animation.getAnimatedValue();
            mCircleBall.setX(point.x);
            mCircleBall.setY(point.y);
          }
        });
  }
Beispiel #20
0
  private void smoothTo(int fromY, int toY) {
    ValueAnimator valueAnimator =
        ValueAnimator.ofObject(
            new TypeEvaluator<Integer>() {
              @Override
              public Integer evaluate(float fraction, Integer startValue, Integer endValue) {
                return startValue + (int) (fraction * (endValue - startValue));
              }
            },
            fromY,
            toY);

    valueAnimator.setInterpolator(null);
    valueAnimator.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));
    valueAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            offsetTop = (int) animation.getAnimatedValue();
            requestLayout();
          }
        });

    valueAnimator.start();
  }
Beispiel #21
0
 private void startAnimation(int temp_moveX, int temp_moveY) {
   Point startPoint = new Point(temp_moveX, temp_moveY);
   Point endPoint = new Point((int) centerX, (int) centerY);
   ValueAnimator anim = ValueAnimator.ofObject(new PointEvaluator(), startPoint, endPoint);
   anim.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           Point point = (Point) animation.getAnimatedValue();
           moveX = point.getX();
           moveY = point.getY();
           Log.i("CJT", moveX + "   ====   " + moveY);
           invalidate();
         }
       });
   anim.addListener(
       new AnimatorListenerAdapter() {
         @Override
         public void onAnimationEnd(Animator animation) {
           isAnim = false;
           VIEW_STATUS = VIEW_ACTION_STATUS;
           invalidate();
         }
       });
   anim.setInterpolator(new SpringInterpolator());
   anim.setDuration(1000);
   anim.start();
 }
 private void startAnim() {
   ValueAnimator valueAnimator =
       ValueAnimator.ofFloat(mActiveCircle.angle, mActiveCircle.angle + 360);
   valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
   valueAnimator.setDuration(2500);
   valueAnimator.setRepeatCount(Animation.INFINITE);
   valueAnimator.start();
   valueAnimator.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           float angle = (Float) animation.getAnimatedValue();
           mActiveCircle.x =
               (float)
                   (mCenterCircle.x
                       + (mCenterCircleRadius + mWallCircleRadius)
                           * Math.cos(Math.toRadians(angle)));
           mActiveCircle.y =
               (float)
                   (mCenterCircle.y
                       + (mCenterCircleRadius + mWallCircleRadius)
                           * Math.sin(Math.toRadians(angle)));
           invalidate();
         }
       });
 }
  @TargetApi(11)
  public ValueAnimator setSpeed(double progress, long duration, long startDelay) {
    if (progress <= 0)
      throw new IllegalArgumentException("Non-positive value specified as a speed.");

    if (progress > maxSpeed) progress = maxSpeed;

    ValueAnimator va =
        ValueAnimator.ofObject(
            new TypeEvaluator<Double>() {
              @Override
              public Double evaluate(float fraction, Double startValue, Double endValue) {
                return startValue + fraction * (endValue - startValue);
              }
            },
            Double.valueOf(getSpeed()),
            Double.valueOf(progress));

    va.setDuration(duration);
    va.setStartDelay(startDelay);
    va.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            Double value = (Double) animation.getAnimatedValue();
            if (value != null) setSpeed(value);
          }
        });
    va.start();
    return va;
  }
Beispiel #24
0
 public void animateToNaturalState() {
   if (mAcceptAnimator != null) {
     mAcceptAnimator.cancel();
   }
   mNeutralAnimator = ValueAnimator.ofFloat(0f, 1f);
   mNeutralAnimator.setDuration(CONSUMPTION_ANIMATION_DURATION);
   mNeutralAnimator.addUpdateListener(
       new AnimatorUpdateListener() {
         public void onAnimationUpdate(ValueAnimator animation) {
           final float percent = (Float) animation.getAnimatedValue();
           mOuterRingSize = (1 + (1 - percent) * OUTER_RING_GROWTH_FACTOR) * sPreviewSize;
           mInnerRingSize = (1 + (1 - percent) * INNER_RING_GROWTH_FACTOR) * sPreviewSize;
           if (mCellLayout != null) {
             mCellLayout.invalidate();
           }
         }
       });
   mNeutralAnimator.addListener(
       new AnimatorListenerAdapter() {
         @Override
         public void onAnimationEnd(Animator animation) {
           if (mCellLayout != null) {
             mCellLayout.hideFolderAccept(FolderRingAnimator.this);
           }
           if (mFolderIcon != null) {
             mFolderIcon.mPreviewBackground.setVisibility(VISIBLE);
           }
         }
       });
   mNeutralAnimator.start();
 }
  @Override
  public List<Animator> createAnimation() {
    List<Animator> animators = new ArrayList<>();

    int[] durations = {960, 930, 1190, 1130, 1340, 940, 1200, 820, 1190};
    int[] delays = {360, 400, 680, 410, 710, -150, -120, 10, 320};

    for (int i = 0; i < 9; i++) {
      final int index = i;
      ValueAnimator alphaAnim = ValueAnimator.ofInt(255, 168, 255);
      alphaAnim.setDuration(durations[i]);
      alphaAnim.setRepeatCount(-1);
      alphaAnim.setStartDelay(delays[i]);
      alphaAnim.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
              alphas[index] = (int) animation.getAnimatedValue();
              postInvalidate();
            }
          });
      alphaAnim.start();
      animators.add(alphaAnim);
    }
    return animators;
  }
  /**
   * 抛物线
   *
   * @param view
   */
  public void paowuxian(View view) {

    final ValueAnimator valueAnimator = new ValueAnimator();
    valueAnimator.setDuration(3000);
    valueAnimator.setTarget(mBlueBall);
    valueAnimator.setObjectValues(new PointF(0, 0));
    valueAnimator.setInterpolator(new LinearInterpolator()); // 匀速

    /**
     * evaluator全部继承至TypeEvaluator接口,它只有一个evaluate()方法。它用来返回你要进行动画的那个属性在当前时间点所需要的属性值
     * 根据属性的开始、结束值与TimeInterpolation计算出的因子计算出当前时间的属性值
     */
    valueAnimator.setEvaluator(
        new TypeEvaluator<PointF>() {
          @Override
          public PointF evaluate(float fraction, PointF startValue, PointF endValue) {
            /**
             * fraction 表示时间分值 画面绘制一帧所需要的时间 平抛运动可正交分解为两个运动:水平方向上的速度为V的匀速直线运动和竖直方向上的自由落体运动. 水平方向上位移是x
             * = Vt; 竖直方向上的速度V = gt,位移y = gt²/2 这里设x的速度为200px/s g为260px/s 时间为3秒
             */
            Log.e("sssssssss", fraction + "");
            PointF point = new PointF();
            point.x = 200 * 3 * fraction;
            point.y = 260 * (fraction * 3) * (fraction * 3) / 2;
            return point;
          }
        });
    valueAnimator.start();
    valueAnimator.addUpdateListener(
        new AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            PointF point = (PointF) animation.getAnimatedValue();
            mBlueBall.setX(point.x);
            mBlueBall.setY(point.y);
          }
        });
    /**
     * 动画监听事件 AnimatorListenerAdapter继承了AnimatorListener接口,可以空实现所有的方法 你可以根据你的需要重写你需要的方法 主要的方法有
     * onAnimationStart 开始 onAnimationRepeat 重复 onAnimationCancel 停止 onAnimationEnd 结束
     */
    valueAnimator.addListener(
        new AnimatorListenerAdapter() {

          @Override
          public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            ViewGroup parent = (ViewGroup) mBlueBall.getParent();
            if (mBlueBall != null) {
              parent.removeView(mBlueBall);
            }
          }

          @Override
          public void onAnimationCancel(Animator animation) {
            super.onAnimationCancel(animation);
          }
        });
  }
  @Override
  public List<Animator> createAnimation() {
    ValueAnimator scaleAnim = ValueAnimator.ofFloat(1, 0.3f, 1);
    scaleAnim.setDuration(1000);
    scaleAnim.setRepeatCount(-1);
    scaleAnim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            scaleFloat1 = (float) animation.getAnimatedValue();
            postInvalidate();
          }
        });
    scaleAnim.start();

    ValueAnimator scaleAnim2 = ValueAnimator.ofFloat(1, 0.6f, 1);
    scaleAnim2.setDuration(1000);
    scaleAnim2.setRepeatCount(-1);
    scaleAnim2.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            scaleFloat2 = (float) animation.getAnimatedValue();
            postInvalidate();
          }
        });
    scaleAnim2.start();

    ValueAnimator rotateAnim = ValueAnimator.ofFloat(0, 180, 360);
    rotateAnim.setDuration(1000);
    rotateAnim.setRepeatCount(-1);
    rotateAnim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            degrees = (float) animation.getAnimatedValue();
            postInvalidate();
          }
        });
    rotateAnim.start();
    List<Animator> animators = new ArrayList<>();
    animators.add(scaleAnim);
    animators.add(scaleAnim2);
    animators.add(rotateAnim);
    return animators;
  }
 @Override
 public void start() {
   setupAnimators();
   mAnimation.cancel();
   mRing.storeOriginals();
   // Already showing some part of the ring
   if (mRing.getEndTrim() != mRing.getStartTrim()) {
     mFinishing = true;
     mAnimation.setDuration(ANIMATION_DURATION / 2);
     mAnimation.start();
   } else {
     mRing.setColorIndex(0);
     mRing.resetOriginals();
     mAnimation.setDuration(ANIMATION_DURATION);
     mAnimation.start();
   }
 }
Beispiel #29
0
 public void stop() {
   playing = false;
   v.cancel();
   ValueAnimator v2 = ValueAnimator.ofInt(0, 100);
   v2.setDuration(200);
   v2.addUpdateListener(this);
   v2.start();
 }
  private void startRippleAnim() {
    mStatus = RIPPLE;
    rippleAnimator = ValueAnimator.ofFloat(mRippleWidth, mMaxRippleWidth);
    rippleAlphaAnimator = ValueAnimator.ofInt(255, 0);
    rippleAnimator.setDuration(mRippleDuration);
    rippleAlphaAnimator.setDuration(mRippleDuration);
    rippleAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            mRippleWidth = (Float) animation.getAnimatedValue();
          }
        });
    rippleAlphaAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            mRippleAlpha = (int) animation.getAnimatedValue();
            postInvalidate();
          }
        });
    rippleAnimator.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animation) {}

          @Override
          public void onAnimationEnd(Animator animation) {
            mRippleWidth = mInitRippleWidth;
            mRippleAlpha = 255;
            startLineAnim();
          }

          @Override
          public void onAnimationCancel(Animator animation) {
            mRippleWidth = mInitRippleWidth;
            mRippleAlpha = 255;
          }

          @Override
          public void onAnimationRepeat(Animator animation) {}
        });
    AnimatorSet animSet = new AnimatorSet();
    animSet.playTogether(rippleAnimator, rippleAlphaAnimator);
    animSet.start();
  }