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: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  w ww.ja  va  2  s .  c  o  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:io.digibyte.tools.animation.BRAnimator.java

public static void animateBackgroundDim(final ViewGroup backgroundLayout, boolean reverse) {
    int transColor = reverse ? R.color.black_trans : android.R.color.transparent;
    int blackTransColor = reverse ? android.R.color.transparent : R.color.black_trans;

    ValueAnimator anim = new ValueAnimator();
    anim.setIntValues(transColor, blackTransColor);
    anim.setEvaluator(new ArgbEvaluator());
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//from ww  w  . j  a va  2s . c  o m
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            backgroundLayout.setBackgroundColor((Integer) valueAnimator.getAnimatedValue());
        }
    });

    anim.setDuration(SLIDE_ANIMATION_DURATION);
    anim.start();
}

From source file:com.musenkishi.atelier.Atelier.java

private static void applyColorToView(final TextView textView, int color, boolean fromCache) {
    if (fromCache) {
        textView.setTextColor(color);/*w  ww .  j av  a2s.c o  m*/
    } else {
        Integer colorFrom = textView.getCurrentTextColor();
        Integer colorTo = color;
        ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
        colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                textView.setTextColor((Integer) animator.getAnimatedValue());
            }
        });
        colorAnimation.start();
    }
}

From source file:com.musenkishi.atelier.Atelier.java

private static void applyColorToView(final CardView cardView, int color, boolean fromCache) {
    if (fromCache) {
        cardView.setCardBackgroundColor(color);
    } else {//w  w w . j  a  v  a 2  s.  c  om
        Integer colorFrom = Color.parseColor("#FFFAFAFA"); //Default light CardView color.
        Integer colorTo = color;
        ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
        colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                cardView.setCardBackgroundColor((Integer) animator.getAnimatedValue());
            }
        });
        colorAnimation.setDuration(300);
        colorAnimation.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  va 2 s  .c om
        } 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);
        }
    }
}

From source file:com.musenkishi.atelier.Atelier.java

private static void applyColorToView(final FloatingActionButton floatingActionButton, int color,
        boolean fromCache, boolean shouldMask) {
    if (fromCache) {
        if (shouldMask) {
            if (floatingActionButton.getDrawable() != null) {
                floatingActionButton.getDrawable().mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
            } else if (floatingActionButton.getBackground() != null) {
                floatingActionButton.getBackground().mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
            }/*from   ww  w.  j a  v a 2  s .c  om*/
        } else {
            ColorStateList colorStateList = ColorStateList.valueOf(color);
            floatingActionButton.setBackgroundTintList(colorStateList);
        }
    } else {
        if (shouldMask) {

            Integer colorFrom;
            ValueAnimator.AnimatorUpdateListener imageAnimatorUpdateListener = new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    if (floatingActionButton.getDrawable() != null) {
                        floatingActionButton.getDrawable().mutate().setColorFilter(
                                (Integer) valueAnimator.getAnimatedValue(), PorterDuff.Mode.MULTIPLY);
                    } else if (floatingActionButton.getBackground() != null) {
                        floatingActionButton.getBackground().mutate().setColorFilter(
                                (Integer) valueAnimator.getAnimatedValue(), PorterDuff.Mode.MULTIPLY);
                    }
                }
            };
            ValueAnimator.AnimatorUpdateListener animatorUpdateListener;

            PaletteTag paletteTag = (PaletteTag) floatingActionButton.getTag(viewTagKey);
            animatorUpdateListener = imageAnimatorUpdateListener;
            colorFrom = paletteTag.getColor();
            floatingActionButton.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 {

            Integer colorFrom = Color.parseColor("#FFFAFAFA");

            ColorStateList colorStateList = floatingActionButton.getBackgroundTintList();
            if (colorStateList != null) {
                colorFrom = colorStateList.getDefaultColor();
            }

            Integer colorTo = color;
            ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
            colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animator) {
                    int color = (Integer) animator.getAnimatedValue();
                    floatingActionButton.setBackgroundTintList(ColorStateList.valueOf(color));
                }
            });
            colorAnimation.setDuration(300);
            colorAnimation.start();
        }
    }
}

From source file:org.sufficientlysecure.keychain.ui.BackupCodeFragment.java

private static void animateFlashText(final TextView[] textViews, int color1, int color2,
        boolean staySecondColor) {

    ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(), color1, color2);
    anim.addUpdateListener(new AnimatorUpdateListener() {
        @Override/* w  w w.  j ava  2 s.co m*/
        public void onAnimationUpdate(ValueAnimator animator) {
            for (TextView textView : textViews) {
                textView.setTextColor((Integer) animator.getAnimatedValue());
            }
        }
    });
    anim.setRepeatMode(ValueAnimator.REVERSE);
    anim.setRepeatCount(staySecondColor ? 4 : 5);
    anim.setDuration(180);
    anim.setInterpolator(new AccelerateInterpolator());
    anim.start();

}

From source file:com.android.argb.edhlc.Utils.java

public static void collapse(Context context, final CardView card, TextView title, ImageView selector,
        int minHeight, int maxHeight) {
    title.setTextColor(ContextCompat.getColor(context, R.color.secondary_text));

    Animation rotation = AnimationUtils.loadAnimation(context, R.anim.rotate_180_clockwise);
    selector.startAnimation(rotation);/*from  w  ww. jav  a2  s. co m*/
    selector.setColorFilter(ContextCompat.getColor(context, R.color.secondary_text));

    ValueAnimator anim = ValueAnimator.ofInt(maxHeight, minHeight);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = card.getLayoutParams();
            layoutParams.height = val;
            card.setLayoutParams(layoutParams);
        }
    });
    anim.start();
}

From source file:com.android.argb.edhlc.Utils.java

public static void expand(Context context, final CardView card, TextView title, ImageView selector,
        int minHeight, int maxHeight) {
    title.setTextColor(ContextCompat.getColor(context, R.color.accent_color_dark));

    Animation rotation = AnimationUtils.loadAnimation(context, R.anim.rotate_180_anticlockwise);
    selector.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.arrow_up));
    selector.setRotation(0);//from  w  ww. ja  v a2  s  .c o  m
    selector.startAnimation(rotation);
    selector.setColorFilter(ContextCompat.getColor(context, R.color.accent_color_dark));

    ValueAnimator anim = ValueAnimator.ofInt(minHeight, maxHeight);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = card.getLayoutParams();
            layoutParams.height = val;
            card.setLayoutParams(layoutParams);
            Utils.makeViewVisible(card);
        }
    });
    anim.start();
}

From source file:com.azita.iot.ioclient.activity.MainActivity.java

private static void setProgressAnimatedJdk(final SeekBar seekBar, int from, int to) {
    ValueAnimator anim = ValueAnimator.ofInt(from, to);
    anim.setDuration(100);//from  www. j a v a2s.c om
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int animProgress = (Integer) animation.getAnimatedValue();
            seekBar.setProgress(animProgress);
        }
    });
    anim.start();
}