Ejemplo n.º 1
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 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));
          }
        });
  }
Ejemplo n.º 3
0
  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();
  }
  @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 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();
  }
Ejemplo n.º 6
0
  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;
  }
  private void performDismiss() {
    // Animate the dismissed view to zero-height and then fire the dismiss callback.
    // This triggers layout on each animation frame; in the future we may want to do something
    // smarter and more performant.

    final ViewGroup.LayoutParams lp = mView.getLayoutParams();
    final int originalHeight = mView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            mCallbacks.onDismiss(mView, mToken);
            // Reset view presentation
            mView.setAlpha(1f);
            mView.setTranslationX(0);
            lp.height = originalHeight;
            mView.setLayoutParams(lp);
          }
        });

    animator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            mView.setLayoutParams(lp);
          }
        });

    animator.start();
  }
Ejemplo n.º 8
0
 /** 抛物线 */
 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();
 }
Ejemplo n.º 9
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();
  }
Ejemplo n.º 10
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();
  }
  private void performDismiss(
      final View dismissView, final int dismissPosition, final int direction) {
    // Animate the dismissed list item to zero-height and fire the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.

    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalHeight = dismissView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(createAnimatorListener(originalHeight));

    animator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
          }
        });

    mPendingDismisses.add(new PendingDismissData(dismissPosition, direction, dismissView));
    animator.start();
  }
  /** 圆周运动 */
  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);
          }
        });
  }
Ejemplo n.º 13
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();
  }
  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);
  }
Ejemplo n.º 15
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();
 }
Ejemplo n.º 16
0
 public void start(int a) {
   v = ValueAnimator.ofInt(0, 1000);
   v.setDuration(a);
   v.addUpdateListener(this);
   playing = true;
   v.start();
 }
Ejemplo n.º 17
0
 public void perform() {
   ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1);
   valueAnimator.setInterpolator(ANIMATION_INTERP);
   valueAnimator.addUpdateListener(this);
   valueAnimator.addListener(this);
   valueAnimator.start();
 }
Ejemplo n.º 18
0
 private void showCheck() {
   if (isAnim) {
     return;
   }
   isAnim = true;
   ValueAnimator va = ValueAnimator.ofFloat(0, 1).setDuration(animDurtion);
   va.setInterpolator(new LinearInterpolator());
   va.start();
   va.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           float value = (float) animation.getAnimatedValue(); // 0f ~ 1f
           radius = (int) (value * height * 0.37f + height * 0.125f);
           if (value >= 1) {
             isChecked = true;
             isAnim = false;
             if (listener != null) {
               listener.onCheckedChanged(AnimatedCheckBox.this, true);
             }
             showCorrect();
           }
           invalidate();
         }
       });
 }
Ejemplo n.º 19
0
  @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;
  }
Ejemplo n.º 20
0
 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();
         }
       });
 }
Ejemplo n.º 21
0
  @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;
  }
Ejemplo n.º 22
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();
 }
Ejemplo n.º 23
0
  /**
   * Set the thumb to be in the normal/un-pressed state and calls invalidate() to redraw the canvas
   * to reflect the updated state.
   *
   * @param thumb the thumb to release
   */
  private void releasePin(final PinView thumb) {

    final float nearestTickX = mBar.getNearestTickCoordinate(thumb);
    thumb.setX(nearestTickX);
    int tickIndex = mBar.getNearestTickIndex(thumb);
    thumb.setXValue(getPinValue(tickIndex));

    if (mArePinsTemporary) {
      ValueAnimator animator = ValueAnimator.ofFloat(mExpandedPinRadius, 0);
      animator.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
              mThumbRadiusDP = (Float) (animation.getAnimatedValue());
              thumb.setSize(
                  mThumbRadiusDP, mPinPadding - (mPinPadding * animation.getAnimatedFraction()));
              invalidate();
            }
          });
      animator.start();
    } else {
      invalidate();
    }

    thumb.release();
  }
Ejemplo n.º 24
0
  private void scrollToTarget(int target, final Runnable after) {
    int scrollX = getScrollX();
    if (scrollX == target) {
      if (after != null) after.run();
    } else {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        ValueAnimator realSmoothScrollAnimation =
            ValueAnimator.ofInt(scrollX, target).setDuration(500);
        realSmoothScrollAnimation.setInterpolator(new DecelerateInterpolator());
        realSmoothScrollAnimation.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
              @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
              @Override
              public void onAnimationUpdate(ValueAnimator animation) {
                scrollTo((Integer) animation.getAnimatedValue(), 0);
              }
            });

        realSmoothScrollAnimation.addListener(
            new AnimatorListenerAdapter() {
              @Override
              public void onAnimationEnd(Animator animation) {
                if (after != null) after.run();
              }
            });
        realSmoothScrollAnimation.start();
      } else {
        smoothScrollTo(target, 0);
        if (after != null) after.run();
      }
    }
  }
 @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;
 }
Ejemplo n.º 26
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();
  }
  /**
   * 抛物线
   *
   * @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;
  }
  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();
  }
Ejemplo n.º 30
0
 public void stop() {
   playing = false;
   v.cancel();
   ValueAnimator v2 = ValueAnimator.ofInt(0, 100);
   v2.setDuration(200);
   v2.addUpdateListener(this);
   v2.start();
 }