Example usage for android.animation ValueAnimator addUpdateListener

List of usage examples for android.animation ValueAnimator addUpdateListener

Introduction

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

Prototype

public void addUpdateListener(AnimatorUpdateListener listener) 

Source Link

Document

Adds a listener to the set of listeners that are sent update events through the life of an animation.

Usage

From source file:Main.java

public static ValueAnimator slideAnimator(int start, int end, final View v) {
    ValueAnimator animator = ValueAnimator.ofInt(start, end);

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/* w w  w  .  ja  va2 s  .  c  o m*/
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int value = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = v.getLayoutParams();
            layoutParams.height = value;
            v.setLayoutParams(layoutParams);
        }
    });
    return animator;
}

From source file:Main.java

public static void animateHeight(final View view, int from, int to, int duration) {
    boolean expanding = to > from;

    ValueAnimator anim = ValueAnimator.ofInt(from, to);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from  w w w .  j  av  a2s.  c o  m*/
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
            layoutParams.height = val;
            view.setLayoutParams(layoutParams);
        }
    });
    anim.setDuration(duration);
    anim.start();

    view.animate().alpha(expanding ? 1 : 0).setDuration(duration / 2).start();
}

From source file:Main.java

private static ValueAnimator slideAnimator(int start, int end, final View summary) {
    ValueAnimator animator = ValueAnimator.ofInt(start, end);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//from   ww  w.  j av a  2  s  .c o m
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            //Update Height
            int value = (Integer) valueAnimator.getAnimatedValue();

            ViewGroup.LayoutParams layoutParams = summary.getLayoutParams();
            layoutParams.height = value;
            summary.setLayoutParams(layoutParams);
        }
    });
    return animator;
}

From source file:Main.java

public static ValueAnimator getRiseElevationValue(final View targetView, int duration, final int mimElevation,
        final int maxElevation) {
    ValueAnimator addElevationValueAnim = ValueAnimator.ofInt(1);
    addElevationValueAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
        @Override/*w w w . jav a 2s  .  c o  m*/
        public void onAnimationUpdate(ValueAnimator animation) {
            float fraction = animation.getAnimatedFraction();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                targetView.setElevation((1 - fraction) * maxElevation + mimElevation);
            }
        }
    });
    addElevationValueAnim.setDuration(duration);
    return addElevationValueAnim;
}

From source file:Main.java

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

From source file:Main.java

public static void startScaleAnime(final View view, float newScale, Animator.AnimatorListener listener) {
    ValueAnimator anime = ValueAnimator.ofFloat(view.getScaleX(), newScale);
    anime.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from   w  ww .ja  va 2s  .  c  o  m*/
        public void onAnimationUpdate(ValueAnimator animation) {
            float s = Float.parseFloat(animation.getAnimatedValue().toString());
            view.setScaleX(s);
            view.setScaleY(s);
        }
    });
    if (listener != null) {
        anime.addListener(listener);
    }
    anime.setDuration(mAnimeDuration);
    anime.start();
}

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);//from   w  ww . jav a  2 s  .  c  om
    va.addUpdateListener(animation -> mView.setBackgroundColor((Integer) animation.getAnimatedValue()));
    va.start();
}

From source file:Main.java

public static void backgroundColorChange(final View view, int fromColor, int toColor) {
    ValueAnimator imageColorChangeAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), fromColor, toColor);
    imageColorChangeAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from  ww  w . j  a  va2s.  com*/
        public void onAnimationUpdate(ValueAnimator animator) {
            view.setBackgroundColor((Integer) animator.getAnimatedValue());
        }
    });
    imageColorChangeAnimation.setDuration(150);
    imageColorChangeAnimation.start();
}

From source file:Main.java

/**
 * Update alpha//  w ww  .ja v a  2 s.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 changeImageColorFilter(final ImageView image, int fromColor, int toColor) {
    ValueAnimator imageColorChangeAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), fromColor, toColor);
    imageColorChangeAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*w w  w . j a  va2 s . c om*/
        public void onAnimationUpdate(ValueAnimator animator) {
            image.setColorFilter((Integer) animator.getAnimatedValue());
        }
    });
    imageColorChangeAnimation.setDuration(150);
    imageColorChangeAnimation.start();
}