コード例 #1
0
ファイル: FlipView.java プロジェクト: Y-bao/Android
  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();
  }
コード例 #2
0
    public MyAnimationView(Context context) {
      super(context);

      ValueAnimator colorAnim = ObjectAnimator.ofInt(this, "backgroundColor", RED, BLUE);
      colorAnim.setDuration(3000);
      colorAnim.setEvaluator(new ArgbEvaluator());
      colorAnim.setRepeatCount(ValueAnimator.INFINITE);
      colorAnim.setRepeatMode(ValueAnimator.REVERSE);
      ObjectAnimator.setFrameDelay(0);
      colorAnim.start();
    }
コード例 #3
0
    public MyAnimationView(Context context) {
      super(context);

      // Animate background color
      // Note that setting the background color will automatically invalidate the
      // view, so that the animated color, and the bouncing balls, get redisplayed on
      // every frame of the animation.
      ValueAnimator colorAnim = ObjectAnimator.ofInt(this, "backgroundColor", RED, BLUE);
      colorAnim.setDuration(3000);
      colorAnim.setEvaluator(new ArgbEvaluator());
      colorAnim.setRepeatCount(ValueAnimator.INFINITE);
      colorAnim.setRepeatMode(ValueAnimator.REVERSE);
      colorAnim.start();
    }
コード例 #4
0
  private void initIfNecessary(TextPaint tp) {
    if (jumpAnimator != null) {
      return;
    }

    shift = (int) tp.ascent() / 2;
    jumpAnimator = ValueAnimator.ofInt(0, shift, 0);
    jumpAnimator.setDuration(loopDuration).setStartDelay(delay);
    jumpAnimator.setInterpolator(new JumpInterpolator(animatedRange));
    jumpAnimator.setRepeatCount(ValueAnimator.INFINITE);
    jumpAnimator.setRepeatMode(ValueAnimator.RESTART);
    jumpAnimator.addUpdateListener(this);
    jumpAnimator.start();
  }
コード例 #5
0
ファイル: ParabolicTextView.java プロジェクト: libobobo/App
  private void PlayAnimator() {
    if (i < text.length()) {
      mPath.moveTo(0, 0); // 起点
      mPath.quadTo(
          (mTextSize * i) / 2, 0, mTextSize * i, mTextSize + DensityUtil.px2dip(mContext, 300));
      mPathMeasure = new PathMeasure(mPath, false);
      animator = ValueAnimator.ofFloat(0, mPathMeasure.getLength());
      animator.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
              float value = (Float) animation.getAnimatedValue();
              mPathMeasure.getPosTan(value, mCurrentPosition, null);
              postInvalidate();
            }
          });
      mPath.close();
      animator.setDuration(1500);
      animator.setRepeatMode(ValueAnimator.RESTART);
      animator.setInterpolator(new LinearInterpolator());
      animator.start();
      animator.addListener(
          new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animator) {}

            @Override
            public void onAnimationEnd(Animator animator) {
              // 每一个动画执行完成后记录最后一个坐标点
              Point point = new Point();
              point.x = (int) mCurrentPosition[0];
              point.y = (int) mCurrentPosition[1];
              endloc.put(i, point);
              i++;
              if (i >= text.length()) { // 当i大于7的时候置为零方便下次循环
                i = 0;
                endloc.clear(); // 清空集合,从新来过
              }
              mPath.reset();
              PlayAnimator();
            }

            @Override
            public void onAnimationCancel(Animator animator) {}

            @Override
            public void onAnimationRepeat(Animator animator) {}
          });
    }
  }
コード例 #6
0
  private void initIfNecessary(float ascent) {
    if (jumpAnimator != null) {
      return;
    }

    this.shift = 0;
    int maxShift = (int) ascent / 2;
    jumpAnimator = ValueAnimator.ofInt(0, maxShift);
    jumpAnimator.setDuration(loopDuration).setStartDelay(delay);
    jumpAnimator.setInterpolator(new JumpInterpolator(animatedRange));
    jumpAnimator.setRepeatCount(ValueAnimator.INFINITE);
    jumpAnimator.setRepeatMode(ValueAnimator.RESTART);
    jumpAnimator.addUpdateListener(this);
    jumpAnimator.start();
  }
コード例 #7
0
  private static void animateFlashText(
      final TextView[] textViews, int color1, int color2, boolean staySecondColor) {

    ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(), color1, color2);
    anim.addUpdateListener(
        new AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animator) {
            for (TextView textView : textViews) {
              textView.setTextColor((Integer) animator.getAnimatedValue());
            }
          }
        });
    anim.setRepeatMode(ValueAnimator.REVERSE);
    anim.setRepeatCount(staySecondColor ? 4 : 5);
    anim.setDuration(180);
    anim.setInterpolator(new AccelerateInterpolator());
    anim.start();
  }
コード例 #8
0
ファイル: LVWifi.java プロジェクト: yangqiuyi/LoadingView
  private ValueAnimator startViewAnim(float startF, final float endF, long time) {
    valueAnimator = ValueAnimator.ofFloat(startF, endF);
    valueAnimator.setDuration(time);
    valueAnimator.setInterpolator(new LinearInterpolator());
    valueAnimator.setRepeatCount(ValueAnimator.INFINITE); // 无限循环
    valueAnimator.setRepeatMode(ValueAnimator.RESTART);
    valueAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {

            mAnimatedValue = (float) valueAnimator.getAnimatedValue();
            invalidate();
          }
        });
    valueAnimator.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
          }

          @Override
          public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
          }

          @Override
          public void onAnimationRepeat(Animator animation) {
            super.onAnimationRepeat(animation);
          }
        });
    if (!valueAnimator.isRunning()) {
      valueAnimator.start();
    }

    return valueAnimator;
  }
コード例 #9
0
    @Override
    public boolean onTouchEvent(MotionEvent event) {
      if (event.getAction() != MotionEvent.ACTION_DOWN
          && event.getAction() != MotionEvent.ACTION_MOVE) {
        return false;
      }
      ShapeHolder newBall = addBall(event.getX(), event.getY());

      // Bouncing animation with squash and stretch
      float startY = newBall.getY();
      float endY = getHeight() - 50f;
      float h = (float) getHeight();
      float eventY = event.getY();
      int duration = (int) (500 * ((h - eventY) / h));
      ValueAnimator bounceAnim = ObjectAnimator.ofFloat(newBall, "y", startY, endY);
      bounceAnim.setDuration(duration);
      bounceAnim.setInterpolator(new AccelerateInterpolator());
      ValueAnimator squashAnim1 =
          ObjectAnimator.ofFloat(newBall, "x", newBall.getX(), newBall.getX() - 25f);
      squashAnim1.setDuration(duration / 4);
      squashAnim1.setRepeatCount(1);
      squashAnim1.setRepeatMode(ValueAnimator.REVERSE);
      squashAnim1.setInterpolator(new DecelerateInterpolator());
      ValueAnimator squashAnim2 =
          ObjectAnimator.ofFloat(newBall, "width", newBall.getWidth(), newBall.getWidth() + 50);
      squashAnim2.setDuration(duration / 4);
      squashAnim2.setRepeatCount(1);
      squashAnim2.setRepeatMode(ValueAnimator.REVERSE);
      squashAnim2.setInterpolator(new DecelerateInterpolator());
      ValueAnimator stretchAnim1 = ObjectAnimator.ofFloat(newBall, "y", endY, endY + 25f);
      stretchAnim1.setDuration(duration / 4);
      stretchAnim1.setRepeatCount(1);
      stretchAnim1.setInterpolator(new DecelerateInterpolator());
      stretchAnim1.setRepeatMode(ValueAnimator.REVERSE);
      ValueAnimator stretchAnim2 =
          ObjectAnimator.ofFloat(newBall, "height", newBall.getHeight(), newBall.getHeight() - 25);
      stretchAnim2.setDuration(duration / 4);
      stretchAnim2.setRepeatCount(1);
      stretchAnim2.setInterpolator(new DecelerateInterpolator());
      stretchAnim2.setRepeatMode(ValueAnimator.REVERSE);
      ValueAnimator bounceBackAnim = ObjectAnimator.ofFloat(newBall, "y", endY, startY);
      bounceBackAnim.setDuration(duration);
      bounceBackAnim.setInterpolator(new DecelerateInterpolator());
      // Sequence the down/squash&stretch/up animations
      AnimatorSet bouncer = new AnimatorSet();
      bouncer.play(bounceAnim).before(squashAnim1);
      bouncer.play(squashAnim1).with(squashAnim2);
      bouncer.play(squashAnim1).with(stretchAnim1);
      bouncer.play(squashAnim1).with(stretchAnim2);
      bouncer.play(bounceBackAnim).after(stretchAnim2);

      // Fading animation - remove the ball when the animation is done
      ValueAnimator fadeAnim = ObjectAnimator.ofFloat(newBall, "alpha", 1f, 0f);
      fadeAnim.setDuration(250);
      fadeAnim.addListener(
          new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
              balls.remove(((ObjectAnimator) animation).getTarget());
            }
          });

      // Sequence the two animations to play one after the other
      AnimatorSet animatorSet = new AnimatorSet();
      animatorSet.play(bouncer).before(fadeAnim);

      // Start the animation
      animatorSet.start();

      return true;
    }
コード例 #10
0
    @Override
    public boolean onTouchEvent(MotionEvent event) {
      if (event.getAction() != MotionEvent.ACTION_DOWN
          && event.getAction() != MotionEvent.ACTION_MOVE) {
        return false;
      }
      ShapeHolder newBall = ShapeHolder.createBall(event.getX(), event.getY());
      balls.add(newBall);

      // 수정 시작해야 하는 부분
      // 공이 늘어났다 찌그러드는 애니메이션 효과
      float startY = newBall.getY();
      float endY = getHeight() - 50f;
      float h = (float) getHeight();
      float eventY = event.getY();
      int duration = (int) (500 * ((h - eventY) / h));

      ValueAnimator bounceAnim = ObjectAnimator.ofFloat(newBall, "y", startY, endY);
      bounceAnim.setDuration(duration);
      bounceAnim.setInterpolator(new AccelerateInterpolator());

      ValueAnimator squashAnim1 =
          ObjectAnimator.ofFloat(newBall, "x", newBall.getX(), newBall.getX() - 25f);
      squashAnim1.setDuration(duration / 4);
      squashAnim1.setRepeatCount(1);
      squashAnim1.setRepeatMode(ValueAnimator.REVERSE);
      squashAnim1.setInterpolator(new DecelerateInterpolator());

      ValueAnimator squashAnim2 =
          ObjectAnimator.ofFloat(newBall, "width", newBall.getWidth(), newBall.getWidth() + 50);
      squashAnim2.setDuration(duration / 4);
      squashAnim2.setRepeatCount(1);
      squashAnim2.setRepeatMode(ValueAnimator.REVERSE);
      squashAnim2.setInterpolator(new DecelerateInterpolator());

      ValueAnimator stretchAnim1 = ObjectAnimator.ofFloat(newBall, "y", endY, endY + 25f);
      stretchAnim1.setDuration(duration / 4);
      stretchAnim1.setRepeatCount(1);
      stretchAnim1.setInterpolator(new DecelerateInterpolator());
      stretchAnim1.setRepeatMode(ValueAnimator.REVERSE);

      ValueAnimator stretchAnim2 =
          ObjectAnimator.ofFloat(newBall, "height", newBall.getHeight(), newBall.getHeight() - 25);
      stretchAnim2.setDuration(duration / 4);
      stretchAnim2.setRepeatCount(1);
      stretchAnim2.setInterpolator(new DecelerateInterpolator());
      stretchAnim2.setRepeatMode(ValueAnimator.REVERSE);

      startY = endY - (endY - startY) / 2;

      ValueAnimator bounceBackAnim = ObjectAnimator.ofFloat(newBall, "y", endY, startY);
      bounceBackAnim.setDuration(duration);
      bounceBackAnim.setInterpolator(new DecelerateInterpolator());

      ValueAnimator bounceAnim2 = ObjectAnimator.ofFloat(newBall, "y", startY, endY);
      bounceAnim2.setDuration(duration);
      bounceAnim2.setInterpolator(new AccelerateInterpolator());

      ValueAnimator squashAnim21 =
          ObjectAnimator.ofFloat(newBall, "x", newBall.getX(), newBall.getX() - 25f);
      squashAnim21.setDuration(duration / 4);
      squashAnim21.setRepeatCount(1);
      squashAnim21.setRepeatMode(ValueAnimator.REVERSE);
      squashAnim21.setInterpolator(new DecelerateInterpolator());

      ValueAnimator squashAnim22 =
          ObjectAnimator.ofFloat(newBall, "width", newBall.getWidth(), newBall.getWidth() + 50);
      squashAnim22.setDuration(duration / 4);
      squashAnim22.setRepeatCount(1);
      squashAnim22.setRepeatMode(ValueAnimator.REVERSE);
      squashAnim22.setInterpolator(new DecelerateInterpolator());

      ValueAnimator stretchAnim21 = ObjectAnimator.ofFloat(newBall, "y", endY, endY + 25f);
      stretchAnim21.setDuration(duration / 4);
      stretchAnim21.setRepeatCount(1);
      stretchAnim21.setInterpolator(new DecelerateInterpolator());
      stretchAnim21.setRepeatMode(ValueAnimator.REVERSE);

      ValueAnimator stretchAnim22 =
          ObjectAnimator.ofFloat(newBall, "height", newBall.getHeight(), newBall.getHeight() - 25);
      stretchAnim22.setDuration(duration / 4);
      stretchAnim22.setRepeatCount(1);
      stretchAnim22.setInterpolator(new DecelerateInterpolator());
      stretchAnim22.setRepeatMode(ValueAnimator.REVERSE);

      startY = endY - (endY - startY) / 2;

      ValueAnimator bounceBackAnim2 = ObjectAnimator.ofFloat(newBall, "y", endY, startY);
      bounceBackAnim2.setDuration(duration);
      bounceBackAnim2.setInterpolator(new DecelerateInterpolator());

      AnimatorSet bouncer = new AnimatorSet();
      bouncer.play(bounceAnim).before(squashAnim1);
      bouncer.play(squashAnim1).with(squashAnim2);
      bouncer.play(squashAnim1).with(stretchAnim1);
      bouncer.play(squashAnim1).with(stretchAnim2);
      bouncer.play(bounceBackAnim).after(stretchAnim2);
      bouncer.play(bounceAnim2).after(bounceBackAnim);
      bouncer.play(bounceAnim2).before(squashAnim21);
      bouncer.play(squashAnim21).with(squashAnim22);
      bouncer.play(squashAnim21).with(stretchAnim21);
      bouncer.play(squashAnim21).with(stretchAnim22);
      bouncer.play(bounceBackAnim2).after(stretchAnim22);

      // 수정 끝나는 부분

      // 페이딩 애니메이션
      ValueAnimator fadeAnim = ObjectAnimator.ofFloat(newBall, "alpha", 1f, 0f);
      fadeAnim.setDuration(250);
      fadeAnim.addListener(
          new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
              balls.remove(((ObjectAnimator) animation).getTarget());
            }
          });

      // 애니메이션 셋의 애니메이션 셋
      AnimatorSet animatorSet = new AnimatorSet();
      animatorSet.play(bouncer).before(fadeAnim);

      animatorSet.start();

      return true;
    }