/**
   * @param anim The animator, must not be null
   * @param arrayAnimator Incoming typed array for Animator's attributes.
   * @param arrayObjectAnimator Incoming typed array for Object Animator's attributes.
   */
  private static void parseAnimatorFromTypeArray(
      ValueAnimator anim, TypedArray arrayAnimator, TypedArray arrayObjectAnimator) {
    long duration = arrayAnimator.getInt(R.styleable.Animator_android_duration, 300);

    long startDelay = arrayAnimator.getInt(R.styleable.Animator_android_startOffset, 0);

    int valueType = arrayAnimator.getInt(R.styleable.Animator_vc_valueType, 0);

    TypeEvaluator evaluator = null;

    // Must be a path animator by the time I reach here
    if (valueType == VALUE_TYPE_PATH) {
      evaluator = setupAnimatorForPath(anim, arrayAnimator);
    } else {
      throw new IllegalArgumentException("target is not a pathType target");
    }

    anim.setDuration(duration);
    anim.setStartDelay(startDelay);

    if (arrayAnimator.hasValue(R.styleable.Animator_android_repeatCount)) {
      anim.setRepeatCount(arrayAnimator.getInt(R.styleable.Animator_android_repeatCount, 0));
    }
    if (arrayAnimator.hasValue(R.styleable.Animator_android_repeatMode)) {
      anim.setRepeatMode(
          arrayAnimator.getInt(R.styleable.Animator_android_repeatMode, ValueAnimator.RESTART));
    }
    if (evaluator != null) {
      anim.setEvaluator(evaluator);
    }

    if (arrayObjectAnimator != null) {
      setupObjectAnimator(anim, arrayObjectAnimator);
    }
  }
示例#2
0
 private void startSendingAnimation(final RevealView.RevealAnimationListener listener) {
   final int width = mFab.getLeft();
   final int height = mFab.getTop();
   ValueAnimator valueAnimator = new ValueAnimator();
   valueAnimator.setDuration(Const.DURATION / 2);
   valueAnimator.setObjectValues(new PointF(0, 0));
   valueAnimator.setInterpolator(new DecelerateInterpolator());
   valueAnimator.setEvaluator(
       new TypeEvaluator<PointF>() {
         @Override
         public PointF evaluate(float fraction, PointF startValue, PointF endValue) {
           PointF point = new PointF();
           point.x = (width) * (1 - fraction / 2);
           point.y = (height) - 0.85f * (height) * (fraction / 2) * (fraction / 2);
           return point;
         }
       });
   valueAnimator.start();
   valueAnimator.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           PointF point = (PointF) animation.getAnimatedValue();
           mFab.setX(point.x);
           mFab.setY(point.y);
         }
       });
   valueAnimator.addListener(
       new AnimatorListenerAdapter() {
         @Override
         public void onAnimationEnd(Animator animation) {
           super.onAnimationEnd(animation);
           mRevealView.reveal(
               (int) mFab.getX() + mFab.getWidth() / 2,
               (int) mFab.getY() + mFab.getHeight() / 2,
               getThemeColor(),
               Const.RADIUS,
               Const.DURATION,
               listener);
         }
       });
 }
  /**
   * Change the color of the statusbackground, toolbar, toolbarlayout and pagertitlestrip With a
   * color transition animation
   *
   * @param color the final color
   * @param duration the transition color animation duration
   */
  public void setColor(int color, int duration) {
    ValueAnimator colorAnim =
        ObjectAnimator.ofInt(mHeader.headerBackground, "backgroundColor", settings.color, color);
    colorAnim.setEvaluator(new ArgbEvaluator());
    colorAnim.setDuration(duration);
    colorAnim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            final int animatedValue = (Integer) animation.getAnimatedValue();
            int colorAlpha = colorWithAlpha(animatedValue, lastPercent);
            mHeader.headerBackground.setBackgroundColor(colorAlpha);
            mHeader.statusBackground.setBackgroundColor(colorAlpha);
            mHeader.toolbar.setBackgroundColor(colorAlpha);
            mHeader.toolbarLayoutBackground.setBackgroundColor(colorAlpha);
            mHeader.mPagerSlidingTabStrip.setBackgroundColor(colorAlpha);

            // set the new color as MaterialViewPager's color
            settings.color = animatedValue;
          }
        });
    colorAnim.start();
  }