Example usage for android.animation ValueAnimator start

List of usage examples for android.animation ValueAnimator start

Introduction

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

Prototype

@Override
    public void start() 

Source Link

Usage

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// w ww  .  ja  v a 2  s . 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

static void changeViewLeftPadding(final View view, int fromMargin, int toMargin) {
    ValueAnimator animator = ValueAnimator.ofFloat(fromMargin, toMargin);
    animator.setDuration(3000);//from   w  w w .java 2s. c  o  m
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        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:com.musenkishi.wally.util.PaletteLoader.java

private static void applyColorToView(final PaletteTarget target, int color, boolean fromCache) {
    if (target.getView() instanceof TextView) {
        applyColorToView((TextView) target.getView(), color, fromCache);
        return;//from  www . java2  s.co  m
    }
    if (fromCache) {
        if (target.getView() instanceof ImageView && target.shouldMaskDrawable()) {
            ((ImageView) target.getView()).getDrawable().mutate().setColorFilter(color,
                    PorterDuff.Mode.MULTIPLY);
        } else {
            target.getView().setBackgroundColor(color);
        }
    } else {
        if (target.getView() instanceof ImageView && target.shouldMaskDrawable()) {
            Integer colorFrom;
            ValueAnimator.AnimatorUpdateListener imageAnimatorUpdateListener = new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    ((ImageView) target.getView()).getDrawable().mutate().setColorFilter(
                            (Integer) valueAnimator.getAnimatedValue(), PorterDuff.Mode.MULTIPLY);
                }
            };
            ValueAnimator.AnimatorUpdateListener animatorUpdateListener;

            PaletteTag paletteTag = (PaletteTag) target.getView().getTag();
            animatorUpdateListener = imageAnimatorUpdateListener;
            colorFrom = paletteTag.getColor();
            target.getView().setTag(new PaletteTag(paletteTag.getId(), color));

            Integer colorTo = color;
            ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
            colorAnimation.addUpdateListener(animatorUpdateListener);
            colorAnimation.setDuration(300);
            colorAnimation.start();
        } else {

            Drawable preDrawable;

            if (target.getView().getBackground() == null) {
                preDrawable = new ColorDrawable(Color.TRANSPARENT);
            } else {
                preDrawable = target.getView().getBackground();
            }

            TransitionDrawable transitionDrawable = new TransitionDrawable(
                    new Drawable[] { preDrawable, new ColorDrawable(color) });
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                target.getView().setBackground(transitionDrawable);
            } else {
                target.getView().setBackgroundDrawable(transitionDrawable);
            }
            transitionDrawable.startTransition(300);
        }
    }
}

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/*from w  w w.java 2s. 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.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 w w .j a  va2s.  co m
        public void onAnimationUpdate(ValueAnimator animator) {
            view.setBackgroundColor((Integer) animator.getAnimatedValue());
        }
    });
    valueAnimator.start();
}

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/*from  www. j  a v  a2s .  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:com.harlan.jxust.ui.view.bottombar.MiscUtils.java

/**
 * A method for animating width for the tabs.
 * @param tab tab to animate.//ww w.  ja  v  a  2s  .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.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 .  ja  v  a  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.
 *//*from  ww  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.musenkishi.atelier.Atelier.java

private static void applyColorToView(final ImageView imageView, int color, boolean fromCache,
        boolean shouldMask) {
    if (fromCache) {
        if (shouldMask) {
            if (imageView.getDrawable() != null) {
                imageView.getDrawable().mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
            } else if (imageView.getBackground() != null) {
                imageView.getBackground().mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
            }// ww  w  . j  a v a  2 s. com
        } else {
            imageView.setBackgroundColor(color);
        }
    } else {
        if (shouldMask) {
            Integer colorFrom;
            ValueAnimator.AnimatorUpdateListener imageAnimatorUpdateListener = new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    if (imageView.getDrawable() != null) {
                        imageView.getDrawable().mutate().setColorFilter(
                                (Integer) valueAnimator.getAnimatedValue(), PorterDuff.Mode.MULTIPLY);
                    } else if (imageView.getBackground() != null) {
                        imageView.getBackground().mutate().setColorFilter(
                                (Integer) valueAnimator.getAnimatedValue(), PorterDuff.Mode.MULTIPLY);
                    }
                }
            };
            ValueAnimator.AnimatorUpdateListener animatorUpdateListener;

            PaletteTag paletteTag = (PaletteTag) imageView.getTag(viewTagKey);
            animatorUpdateListener = imageAnimatorUpdateListener;
            colorFrom = paletteTag.getColor();
            imageView.setTag(viewTagKey, new PaletteTag(paletteTag.getId(), color));

            Integer colorTo = color;
            ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
            colorAnimation.addUpdateListener(animatorUpdateListener);
            colorAnimation.setDuration(300);
            colorAnimation.start();
        } else {
            Drawable preDrawable;

            if (imageView.getBackground() == null) {
                preDrawable = new ColorDrawable(Color.TRANSPARENT);
            } else {
                preDrawable = imageView.getBackground();
            }

            TransitionDrawable transitionDrawable = new TransitionDrawable(
                    new Drawable[] { preDrawable, new ColorDrawable(color) });
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                imageView.setBackground(transitionDrawable);
            } else {
                imageView.setBackgroundDrawable(transitionDrawable);
            }
            transitionDrawable.startTransition(300);
        }
    }
}