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 Animator animFlow(android.animation.ValueAnimator.AnimatorUpdateListener animatorupdatelistener) {
    ValueAnimator valueanimator = ValueAnimator.ofFloat(new float[] { 0.0F, 1.0F });
    valueanimator.setInterpolator(new AccelerateInterpolator());
    valueanimator.addUpdateListener(animatorupdatelistener);
    return valueanimator;
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static void clipDrawable(final View image, Drawable drawable, boolean isActivated) {
    if (drawable == null) {
        return;//from  w  w w .  j a v  a2s  .  c  om
    }
    if (isActivated) {
        final ClipDrawable scaleDrawable = new ClipDrawable(drawable, Gravity.CENTER,
                ClipDrawable.HORIZONTAL | ClipDrawable.VERTICAL);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            image.setBackground(scaleDrawable);
        } else {
            image.setBackgroundDrawable(scaleDrawable);
        }
        image.setBackgroundDrawable(scaleDrawable);
        ValueAnimator animator = ValueAnimator.ofInt(0, 10000);
        animator.setDuration(200);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                scaleDrawable.setLevel((Integer) animation.getAnimatedValue());
            }
        });
        animator.start();
    } else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            image.setBackground(null);
        } else {
            image.setBackgroundDrawable(null);
        }
    }
}

From source file:com.xujun.contralayout.utils.AnimatorUtil.java

public static void show(final View view, int start, int end) {
    final int height = view.getHeight();
    final ValueAnimator animator = ValueAnimator.ofInt(start, end);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//ww  w.j  a  v a 2 s .  co  m
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int value = (Integer) animator.getAnimatedValue();
            Log.i(TAG, "onAnimationUpdate: value=" + value);
            view.setTop(value);
            view.setBottom(value + height);
        }
    });
    view.setVisibility(View.VISIBLE);
    animator.setDuration(200);
    animator.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
    animator.start();
}

From source file:Main.java

public static void changeTextColor(final TextView textView, int fromColor, int toColor) {
    ValueAnimator changeTextColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), fromColor, toColor);
    changeTextColorAnimation.setDuration(150);
    changeTextColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//  w w  w.j  a v a2s.  co m
        public void onAnimationUpdate(ValueAnimator animator) {
            textView.setTextColor((Integer) animator.getAnimatedValue());
        }
    });
    changeTextColorAnimation.start();
}

From source file:Main.java

static void changeTextColor(final TextView textView, int fromColor, int toColor) {
    ValueAnimator changeTextColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), fromColor, toColor);
    changeTextColorAnimation.setDuration(150);
    changeTextColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from   ww w .  j a  v a 2 s. c om*/
        public void onAnimationUpdate(ValueAnimator animator) {
            textView.setTextColor((Integer) animator.getAnimatedValue());
        }
    });
    changeTextColorAnimation.start();
}

From source file:com.xujun.contralayout.utils.AnimatorUtil.java

public static void tanslation(final View view, float start, float end) {
    final ValueAnimator animator = ValueAnimator.ofFloat(start, end);
    view.setVisibility(View.VISIBLE);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//w ww . jav  a2  s  . c  o m
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            Float value = (Float) animator.getAnimatedValue();
            Log.i(TAG, "tanslation: value=" + value);
            view.setTranslationY(value);
        }
    });
    animator.setDuration(200);
    animator.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
    animator.start();
}

From source file:com.xujun.contralayout.utils.AnimatorUtil.java

public static void showHeight(final View view, float start, float end) {
    final ValueAnimator animator = ValueAnimator.ofFloat(start, end);
    final ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//from w  w w .j ava 2  s.c o  m
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float value = (Float) animator.getAnimatedValue();
            layoutParams.height = (int) value;
            view.setLayoutParams(layoutParams);
            Log.i(TAG, "onAnimationUpdate: value=" + value);

        }
    });
    animator.setDuration(500);
    animator.setInterpolator(new AccelerateInterpolator());
    animator.start();
}

From source file:Main.java

/**
 * Animates a view to the new specified dimensions.
 * @param view The view to change the dimensions of.
 * @param newWidth The new width of the view.
 * @param newHeight The new height of the view.
 *//*  w  w w  . j  av a2 s . c o m*/
public static void changeDimensions(final View view, final int newWidth, final int newHeight) {
    ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);

    final int oldWidth = view.getWidth();
    final int oldHeight = view.getHeight();
    final int deltaWidth = newWidth - oldWidth;
    final int deltaHeight = newHeight - oldHeight;

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animator) {
            Float value = (Float) animator.getAnimatedValue();

            view.getLayoutParams().width = (int) (value * deltaWidth + oldWidth);
            view.getLayoutParams().height = (int) (value * deltaHeight + oldHeight);
            view.requestLayout();
        }
    });
    animator.start();
}

From source file:com.harlan.jxust.ui.view.bottombar.MiscUtils.java

/**
 * A method for animating width for the tabs.
 * @param tab tab to animate.//  w w  w .j  a va  2 s  . c o m
 * @param start starting width.
 * @param end final width after animation.
 */
protected static void resizeTab(final View tab, float start, float end) {
    ValueAnimator animator = ValueAnimator.ofFloat(start, end);
    animator.setDuration(150);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animator) {
            ViewGroup.LayoutParams params = tab.getLayoutParams();
            if (params == null)
                return;

            params.width = Math.round((float) animator.getAnimatedValue());
            tab.setLayoutParams(params);
        }
    });
    animator.start();
}

From source file:com.jerrellmardis.amphitheatre.util.Utils.java

public static void animateColorChange(final View view, int colorFrom, int colorTo) {
    ValueAnimator valueAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//from  w  ww . ja  va2 s . c o m
        public void onAnimationUpdate(ValueAnimator animator) {
            view.setBackgroundColor((Integer) animator.getAnimatedValue());
        }
    });
    valueAnimator.start();
}