List of usage examples for android.animation ValueAnimator setDuration
@Override public ValueAnimator setDuration(long duration)
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/*w w w.ja v a 2 s. c om*/ 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
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// www . ja v a 2 s . co 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: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 www . j ava 2 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: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 ww. jav a 2 s .co 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: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;/*w w w. java2s . 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: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 av a2 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: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//www.j av a 2 s .com 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: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); }// w w w . j a v a 2 s . c o m } 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); }/*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: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 w w w . j a v a 2 s. c o m*/ public void onAnimationUpdate(ValueAnimator valueAnimator) { backgroundLayout.setBackgroundColor((Integer) valueAnimator.getAnimatedValue()); } }); anim.setDuration(SLIDE_ANIMATION_DURATION); anim.start(); }