Example usage for android.animation ValueAnimator setDuration

List of usage examples for android.animation ValueAnimator setDuration

Introduction

In this page you can find the example usage for android.animation ValueAnimator setDuration.

Prototype

@Override
public ValueAnimator setDuration(long duration) 

Source Link

Document

Sets the length of the animation.

Usage

From source file:Main.java

public static ValueAnimator checkAnim(ValueAnimator.AnimatorUpdateListener listener) {
    ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
    anim.setDuration(ANIM_DURATION);
    anim.addUpdateListener(listener);/*from  w  w  w .  j a va  2 s.  c o m*/
    return anim;
}

From source file:Main.java

public static void animateColor(View view, int colorFrom, int colorTo) {
    final View mView = view;
    final ValueAnimator va = ObjectAnimator.ofArgb(colorFrom, colorTo);
    va.setDuration(300);
    va.addUpdateListener(animation -> mView.setBackgroundColor((Integer) animation.getAnimatedValue()));
    va.start();/*from  w  w w.j a v a2s  .co m*/
}

From source file:Main.java

public static void changeTextSize(final TextView textView, float from, float to) {
    ValueAnimator textSizeChangeAnimator = ValueAnimator.ofFloat(from, to);
    textSizeChangeAnimator.setDuration(150);
    textSizeChangeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*  w  w  w.  ja v  a 2s.co m*/
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) valueAnimator.getAnimatedValue());
        }
    });
    textSizeChangeAnimator.start();
}

From source file:Main.java

/**
 * Update alpha//from  w  w  w  .  j a v  a  2s. c  om
 */
public static void updateAlpha(final View view, float fromValue, float toValue) {
    ValueAnimator animator = ValueAnimator.ofFloat(fromValue, toValue);
    animator.setDuration(150);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float animatedValue = (float) valueAnimator.getAnimatedValue();
            view.setAlpha(animatedValue);
        }
    });
    animator.start();
}

From source file:Main.java

static void changeTextSize(final TextView textView, float from, float to) {
    ValueAnimator textSizeChangeAnimator = ValueAnimator.ofFloat(from, to);
    textSizeChangeAnimator.setDuration(150);
    textSizeChangeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from   w  ww  .  j av a  2  s  .  c  o m*/
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, (float) valueAnimator.getAnimatedValue());
        }
    });
    textSizeChangeAnimator.start();
}

From source file:Main.java

static void changeRightPadding(final View view, int fromPadding, int toPadding) {
    ValueAnimator animator = ValueAnimator.ofFloat(fromPadding, toPadding);
    animator.setDuration(150);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from  w ww  .j a va  2s . c o m*/
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float animatedValue = (float) valueAnimator.getAnimatedValue();
            view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), (int) animatedValue,
                    view.getPaddingBottom());
        }
    });
    animator.start();
}

From source file:Main.java

static void changeViewTopPadding(final View view, int fromPadding, int toPadding) {
    ValueAnimator animator = ValueAnimator.ofFloat(fromPadding, toPadding);
    animator.setDuration(150);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override// ww w  .j a va 2 s  .c  o m
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float animatedValue = (float) valueAnimator.getAnimatedValue();
            view.setPadding(view.getPaddingLeft(), (int) animatedValue, view.getPaddingRight(),
                    view.getPaddingBottom());
        }
    });
    animator.start();
}

From source file:Main.java

static void changeViewLeftPadding(final View view, int fromMargin, int toMargin) {
    ValueAnimator animator = ValueAnimator.ofFloat(fromMargin, toMargin);
    animator.setDuration(3000);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from  w  w w. j a v a 2  s  . c o  m*/
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float animatedValue = (float) valueAnimator.getAnimatedValue();
            view.setPadding((int) animatedValue, view.getPaddingTop(), view.getPaddingRight(),
                    view.getPaddingBottom());
            view.requestLayout();

        }
    });
    animator.start();
}

From source file:Main.java

public static void dimBackground(final float from, final float to, Activity context) {
    final Window window = context.getWindow();
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(from, to);
    valueAnimator.setDuration(500);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override// w  w w  . j a  va  2s. c o m
        public void onAnimationUpdate(ValueAnimator animation) {
            WindowManager.LayoutParams params = window.getAttributes();
            params.alpha = (Float) animation.getAnimatedValue();
            window.setAttributes(params);
        }
    });
    valueAnimator.start();
}

From source file:Main.java

/**
 * Update text color with animation/*from w  w  w.  j  a v a 2  s .  co m*/
 */
public static void updateTextColor(final TextView textView, int fromColor, int toColor) {
    ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), fromColor, toColor);
    colorAnimation.setDuration(150);
    colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animator) {
            textView.setTextColor((Integer) animator.getAnimatedValue());
        }
    });
    colorAnimation.start();
}