private ObjectAnimator createAnimation(View view, AnimationParams params) {
   ObjectAnimator animator = null;
   if (params.attr != null) {
     if (params.paramsFloat != null) {
       animator = ObjectAnimator.ofFloat(view, params.attr, params.paramsFloat);
     } else if (params.paramsInt != null) {
       animator = ObjectAnimator.ofInt(view, params.attr, params.paramsInt);
     }
   } else {
     if (params.paramsFloat != null && params.propertyFloat != null) {
       animator = ObjectAnimator.ofFloat(view, params.propertyFloat, params.paramsFloat);
     } else if (params.paramsInt != null && params.propertyInt != null) {
       animator = ObjectAnimator.ofInt(view, params.propertyInt, params.paramsInt);
     }
   }
   if (animator == null) {
     throw new RuntimeException("Can't support this animation params");
   }
   if (params.evaluator != null) {
     animator.setEvaluator(params.evaluator);
   }
   if (params.interpolator != null) {
     animator.setInterpolator(params.interpolator);
   }
   return animator;
 }
Beispiel #2
0
  public void selectOffButton(Button button) {
    TransitionDrawable drawable = (TransitionDrawable) button.getBackground();
    drawable.reverseTransition(100);

    ObjectAnimator colorAnim = ObjectAnimator.ofInt(button, "textColor", Color.BLACK, Color.WHITE);
    colorAnim.setDuration(100);
    colorAnim.setEvaluator(new ArgbEvaluator());
    colorAnim.start();
  }
  private void startAnimation() {
    final float sunYStart = sunView.getTop();
    final float sunYEnd = skyView.getHeight();

    final ObjectAnimator heightAnimator =
        ObjectAnimator.ofFloat(sunView, "y", sunYStart, sunYEnd).setDuration(3000);
    heightAnimator.setInterpolator(new AccelerateInterpolator());

    final ObjectAnimator sunsetSkyAnimator =
        ObjectAnimator.ofInt(skyView, "backgroundColor", blueSkyColor, sunsetSkyColor)
            .setDuration(3000);
    sunsetSkyAnimator.setEvaluator(new ArgbEvaluator());

    final ObjectAnimator nightSkyAnimator =
        ObjectAnimator.ofInt(skyView, "backgroundColor", sunsetSkyColor, nightSkyColor)
            .setDuration(1500);
    nightSkyAnimator.setEvaluator(new ArgbEvaluator());

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(heightAnimator).with(sunsetSkyAnimator).before(nightSkyAnimator);
    animatorSet.start();
  }
  public void testOfInt() throws Throwable {
    Object object = mActivity.view.newBall;
    String property = "backgroundColor";
    int startColor = mActivity.view.RED;
    int endColor = mActivity.view.BLUE;

    ObjectAnimator colorAnimator = ObjectAnimator.ofInt(object, property, startColor, endColor);
    colorAnimator.setDuration(1000);
    colorAnimator.setEvaluator(new ArgbEvaluator());
    colorAnimator.setRepeatCount(1);
    colorAnimator.setRepeatMode(ValueAnimator.REVERSE);
    colorAnimator.start();
    startAnimation(mObjectAnimator, colorAnimator);
    Thread.sleep(100);
    Integer i = (Integer) colorAnimator.getAnimatedValue();
    // We are going from less negative value to a more negative value
    assertTrue(i.intValue() <= startColor);
    assertTrue(endColor <= i.intValue());
  }
Beispiel #5
0
  Animator getCancelAnimator() {
    ObjectAnimator backToTransparent1 =
        (ObjectAnimator)
            AnimatorInflater.loadAnimator(view.getContext(), R.animator.pin_background_end);
    ObjectAnimator goDark =
        (ObjectAnimator)
            AnimatorInflater.loadAnimator(view.getContext(), R.animator.pin_background_go_dark);
    ObjectAnimator backToTransparent2 =
        (ObjectAnimator)
            AnimatorInflater.loadAnimator(view.getContext(), R.animator.pin_background_end);

    ViewGroup parent = (ViewGroup) view.getParent();
    ArgbEvaluator evaluator = new ArgbEvaluator();
    for (ObjectAnimator animator : list(backToTransparent1, goDark, backToTransparent2)) {
      animator.setTarget(parent);
      animator.setEvaluator(evaluator);
    }

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.setTarget(parent);
    animatorSet.playSequentially(backToTransparent1, goDark, backToTransparent2);
    return animatorSet;
  }
Beispiel #6
0
  public void animateYourself() {
    final ViewGroup parent = (ViewGroup) view.getParent();

    if (pinBackgroundAnim != null) {
      pinBackgroundAnim.end();
      pinBackgroundAnim = null;
    }

    pinBackgroundAnim =
        (ObjectAnimator)
            AnimatorInflater.loadAnimator(view.getContext(), R.animator.pin_background_start);

    pinBackgroundAnim.setTarget(parent);
    pinBackgroundAnim.setEvaluator(new ArgbEvaluator());
    pinBackgroundAnim.addListener(
        new AnimatorListener() {

          @Override
          public void onAnimationStart(Animator animation) {
            // NO OP
          }

          @Override
          public void onAnimationRepeat(Animator animation) {}

          @Override
          public void onAnimationEnd(Animator animation) {}

          @Override
          public void onAnimationCancel(Animator animation) {
            endAnimation = getCancelAnimator();
            endAnimation.start();
          }
        });
    pinBackgroundAnim.start();
  }
  public void start() {
    ValueAnimator widthAnimation = ValueAnimator.ofInt(mFromWidth, mToWidth);
    final GradientDrawable gradientDrawable = mDrawable.getGradientDrawable();
    widthAnimation.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            Integer value = (Integer) animation.getAnimatedValue();
            int leftOffset;
            int rightOffset;
            int padding;

            if (mFromWidth > mToWidth) {
              leftOffset = (mFromWidth - value) / 2;
              rightOffset = mFromWidth - leftOffset;
              padding = (int) (mPadding * animation.getAnimatedFraction());
            } else {
              leftOffset = (mToWidth - value) / 2;
              rightOffset = mToWidth - leftOffset;
              padding = (int) (mPadding - mPadding * animation.getAnimatedFraction());
            }

            gradientDrawable.setBounds(
                leftOffset + padding, padding, rightOffset - padding, mView.getHeight() - padding);
          }
        });

    ObjectAnimator bgColorAnimation =
        ObjectAnimator.ofInt(gradientDrawable, "color", mFromColor, mToColor);
    bgColorAnimation.setEvaluator(new ArgbEvaluator());

    ObjectAnimator strokeColorAnimation =
        ObjectAnimator.ofInt(mDrawable, "strokeColor", mFromStrokeColor, mToStrokeColor);
    strokeColorAnimation.setEvaluator(new ArgbEvaluator());

    ObjectAnimator cornerAnimation =
        ObjectAnimator.ofFloat(
            gradientDrawable, "cornerRadius", mFromCornerRadius, mToCornerRadius);

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.setDuration(mDuration);
    animatorSet.playTogether(
        widthAnimation, bgColorAnimation, strokeColorAnimation, cornerAnimation);
    animatorSet.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animation) {}

          @Override
          public void onAnimationEnd(Animator animation) {
            if (mListener != null) {
              mListener.onAnimationEnd();
            }
          }

          @Override
          public void onAnimationCancel(Animator animation) {}

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