/** 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 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();
  }
 /** 抛物线 */
 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();
 }
Example #6
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();
         }
       });
 }
  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();
      }
    }
  }
  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);
  }
Example #9
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();
 }
Example #10
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();
  }
  @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 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);
          }
        });
  }
Example #13
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 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();
         }
       });
 }
 public void perform() {
   ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1);
   valueAnimator.setInterpolator(ANIMATION_INTERP);
   valueAnimator.addUpdateListener(this);
   valueAnimator.addListener(this);
   valueAnimator.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);
          }
        });
  }
Example #17
0
 public void animateViewAlpha(float alpha, long durationOut, Interpolator interpolator) {
   Log.d(TAG, "animateViewAlpha: ");
   if (mAlphaAnimator != null) {
     mAlphaAnimator.cancel();
   }
   mAlphaAnimator = ValueAnimator.ofFloat(mViewAlpha, alpha);
   mAlphaAnimator.addUpdateListener(mAlphaUpdateListener);
   mAlphaAnimator.addListener(mClearAnimatorListener);
   mAlphaAnimator.setInterpolator(interpolator);
   mAlphaAnimator.setDuration(durationOut);
   mAlphaAnimator.start();
 }
  public MultiLineMarqueeTextView(Context context, AttributeSet attrs) {
    super(context, attrs);

    // get display size and density.
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point point = new Point();
    display.getSize(point);
    displayWidth = point.x;
    displayHeight = point.y;
    final float density = getResources().getDisplayMetrics().density;

    // load XML settings
    parseXmlSettings(context, attrs, density);

    paint.setAntiAlias(true);

    adjustTextBaseline = paint.descent() + paint.ascent();
    textHeight = Math.abs(paint.getFontMetrics().top) + paint.getFontMetrics().bottom;
    intervalSecondText = (int) (INTERVAL_SECOND_TEXT_DIPS * density);

    LinearInterpolator linearInterpolator = new LinearInterpolator();
    translateAnimator = ValueAnimator.ofFloat(0.0f, -1.0f);
    translateAnimator.setInterpolator(linearInterpolator);
    translateAnimator.removeAllUpdateListeners();
    translateAnimator.addUpdateListener(animatorUpdateListener);
    translateAnimator.removeAllListeners();
    translateAnimator.addListener(animatorListener);
    translateAnimator.setDuration(DURATION_TRANSLATE);

    suspendAnimator = ValueAnimator.ofFloat(0.0f, 0.0f);
    suspendAnimator.setInterpolator(linearInterpolator);
    suspendAnimator.removeAllUpdateListeners();
    suspendAnimator.addUpdateListener(animatorUpdateListener);
    suspendAnimator.removeAllListeners();
    suspendAnimator.addListener(animatorListener);
    suspendAnimator.setDuration(DURATION_SUSPEND);

    changeTapReset();
  }
Example #19
0
  /** Fluid animation for map centering. */
  public void runCenterMapAnim(double lat, double lng) {
    final float latInit = (float) mv.getCenter().getLatitude();
    float lngInit = (float) mv.getCenter().getLongitude();

    ValueAnimator animationLat;
    ValueAnimator animationLng;

    animationLat = ValueAnimator.ofFloat(latInit, (float) lat);
    animationLng = ValueAnimator.ofFloat(lngInit, (float) lng);

    animationLat.setInterpolator(new DecelerateInterpolator());
    animationLat.setDuration(500);
    animationLng.setInterpolator(new DecelerateInterpolator());
    animationLng.setDuration(500);

    animationLat.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            if (animation.getAnimatedValue() instanceof Float) {
              float latValue = ((Float) animation.getAnimatedValue());
              mv.setCenter(new LatLng(latValue, mv.getCenter().getLongitude()));
            }
          }
        });
    animationLng.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            if (animation.getAnimatedValue() instanceof Float) {
              float lngValue = ((Float) animation.getAnimatedValue());
              mv.setCenter(new LatLng(mv.getCenter().getLatitude(), lngValue));
            }
          }
        });
    AnimatorSet a = new AnimatorSet();
    a.playTogether(animationLat, animationLng);
    mv.setZoom(17f);
    a.start();
  }
Example #20
0
 public void crossFade(int duration) {
   ValueAnimator va = LauncherAnimUtils.ofFloat(this, 0f, 1f);
   va.setDuration(duration);
   va.setInterpolator(new DecelerateInterpolator(1.5f));
   va.addUpdateListener(
       new AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           mCrossFadeProgress = animation.getAnimatedFraction();
         }
       });
   va.start();
 }
 public void animateToFullSize() {
   final ValueAnimator animator = ValueAnimator.ofInt(getLevel(), DRAWABLE_MAX_LEVEL);
   animator.setDuration(CIRCLE_ANIM_DURATION_MS);
   animator.setInterpolator(Gusterpolator.INSTANCE);
   animator.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           setLevel((Integer) animation.getAnimatedValue());
         }
       });
   animator.start();
 }
 private void setupAnimation(ValueAnimator anim, final View v) {
   anim.setInterpolator(sAccelerateInterpolator);
   anim.setDuration(TRANSITION_DURATION);
   anim.addListener(
       new AnimatorListenerAdapter() {
         @Override
         public void onAnimationEnd(Animator animation) {
           if (v != null) {
             v.setLayerType(View.LAYER_TYPE_NONE, null);
           }
         }
       });
 }
Example #23
0
  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) {}
          });
    }
  }
  private void init() {
    animator = ValueAnimator.ofFloat(0, 0);
    animator.setDuration(DEFAULT_ANIM_DURATION);
    animator.setInterpolator(new DecelerateInterpolator());
    animator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            float value = (Float) animation.getAnimatedValue();
            if (scaleDirection == VERTICAL) {
              bottom = (int) (value * (parentHeight - drawableOriginHeight) + drawableOriginHeight);
              right = bottom * drawableOriginWidth / drawableOriginHeight;
            } else {
              right = drawableOriginWidth + (int) ((parentWidth - drawableOriginWidth) * value);
              bottom = right * drawableOriginHeight / drawableOriginWidth;
            }
            top = beginTop + (int) (value * (finalTop - beginTop));
            left = beginLeft + (int) (value * (finalLeft - beginLeft));
            parentView.setBackgroundColor((int) (200 * value) << 24);
            ScaleImageView.super.setFrame(left, top, right + left, bottom + top);
          }
        });
    animator.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animation) {}

          @Override
          public void onAnimationEnd(Animator animation) {
            if (mIsOpen) {

            } else {
              parentView.setVisibility(INVISIBLE);
            }
          }

          @Override
          public void onAnimationCancel(Animator animation) {}

          @Override
          public void onAnimationRepeat(Animator animation) {}
        });
    setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            close();
          }
        });
  }
Example #25
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();
  }
Example #26
0
  public void animateView(
      final DragView view,
      AnimatorUpdateListener updateCb,
      int duration,
      TimeInterpolator interpolator,
      final Runnable onCompleteRunnable,
      final int animationEndStyle,
      View anchorView) {
    // Clean up the previous animations
    if (mDropAnim != null) mDropAnim.cancel();
    if (mFadeOutAnim != null) mFadeOutAnim.cancel();

    // Show the drop view if it was previously hidden
    mDropView = view;
    mDropView.cancelAnimation();
    mDropView.resetLayoutParams();

    // Set the anchor view if the page is scrolling
    if (anchorView != null) {
      mAnchorViewInitialScrollX = anchorView.getScrollX();
    }
    mAnchorView = anchorView;

    // Create and start the animation
    mDropAnim = new ValueAnimator();
    mDropAnim.setInterpolator(interpolator);
    mDropAnim.setDuration(duration);
    mDropAnim.setFloatValues(0f, 1f);
    mDropAnim.addUpdateListener(updateCb);
    mDropAnim.addListener(
        new AnimatorListenerAdapter() {
          public void onAnimationEnd(Animator animation) {
            if (onCompleteRunnable != null) {
              onCompleteRunnable.run();
            }
            switch (animationEndStyle) {
              case ANIMATION_END_DISAPPEAR:
                clearAnimatedView();
                break;
              case ANIMATION_END_FADE_OUT:
                fadeOutDragView();
                break;
              case ANIMATION_END_REMAIN_VISIBLE:
                break;
            }
          }
        });
    mDropAnim.start();
  }
  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();
  }
Example #28
0
 /** 第一次展现 饼图的动画 */
 public void aniShowPie() {
   Log.i("显示控件前设置变量代码执行顺序", "饼图展现动画--aniShowPie()");
   if (fillOut) {
     // --setPiedata---到aniShowPie 此时just还没拿到数据(just在onsizechange里面获取值得)
     ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, pieRadius).setDuration(PIEANITIME);
     valueAnimator.setInterpolator(pieInterpolator);
     valueAnimator.start();
     valueAnimator.addUpdateListener(
         new AnimatorUpdateListener() {
           @Override
           public void onAnimationUpdate(ValueAnimator animation) {
             fillouting = (float) animation.getAnimatedValue();
             postInvalidate();
           }
         });
     return;
   }
   //  ---够函--setPiedata---到aniShowPie ---onsizechange----ondraw
   ValueAnimator animator = ValueAnimator.ofFloat(360, 0).setDuration(PIEANITIME);
   animator.setInterpolator(pieInterpolator);
   animator.start();
   animator.addUpdateListener(
       new AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           sweep4 = (float) animation.getAnimatedValue();
           //				if (sweep4<0.3) {
           //					//设置 提示线可见  非背景色非 扫描扇形的颜色
           //					TsColor = backColor;
           //				}else{
           //					TsColor = Color.BLACK;
           //				}
           postInvalidate();
         }
       });
 }
Example #29
0
 public void onBackAltCleared() {
   // When dismissing ime during unlock, force the back button to run the same appearance
   // animation as home (if we catch this condition early enough).
   if (!mBackTransitioning
       && getBackButton().getVisibility() == VISIBLE
       && mHomeAppearing
       && getHomeButton().getAlpha() == 0) {
     getBackButton().setAlpha(0);
     ValueAnimator a = ObjectAnimator.ofFloat(getBackButton(), "alpha", 0, 1);
     a.setStartDelay(mStartDelay);
     a.setDuration(mDuration);
     a.setInterpolator(mInterpolator);
     a.start();
   }
 }
 private ValueAnimator createAnimator(float... values) {
   ValueAnimator animator = new ValueAnimator();
   animator.setDuration(1250);
   animator.setInterpolator(INTERPOLATOR);
   animator.setFloatValues(values);
   animator.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator valueAnimator) {
           mCurrentValue = (Float) valueAnimator.getAnimatedValue();
           invalidateSelf();
         }
       });
   return animator;
 }