List of usage examples for android.view.animation Animation setAnimationListener
public void setAnimationListener(AnimationListener listener)
Binds an animation listener to this animation.
From source file:Main.java
public static void linearAnimation(final View view, final int startX, final int startY, final int endX, final int endY, long duration, final Runnable callback) { Animation anim = new TranslateAnimation(startX, endX, startY, endY); anim.setDuration(duration);/* w w w.j av a 2 s . co m*/ anim.setInterpolator(new DecelerateInterpolator()); view.startAnimation(anim); anim.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { view.clearAnimation(); view.setX(view.getX() + endX); view.setY(view.getY() + endY); if (callback != null) callback.run(); } @Override public void onAnimationRepeat(Animation animation) { } }); }
From source file:Main.java
/** * Applies a fade in animation and set the visibility in * {@link View#VISIBLE}.//from w w w. jav a 2s.c o m * @param view view to animate. */ public static void fadeInView(final View view) { if (view.getVisibility() != View.VISIBLE) { cancelAnimation(view); view.setVisibility(View.VISIBLE); Animation animation = android.view.animation.AnimationUtils.loadAnimation(view.getContext(), android.R.anim.fade_in); animation.setFillEnabled(true); animation.setFillBefore(true); animation.setFillAfter(true); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { view.clearAnimation(); } @Override public void onAnimationRepeat(Animation animation) { } }); view.setAnimation(animation); animation.start(); } }
From source file:Main.java
/** * Applies a fade out animation and set the visibility in * {@link View#GONE}./*from w w w . j a v a2s . c o m*/ * @param view view to animate. */ public static void fadeOutView(final View view) { if (view.getVisibility() == View.VISIBLE) { cancelAnimation(view); Animation animation = android.view.animation.AnimationUtils.loadAnimation(view.getContext(), android.R.anim.fade_out); animation.setFillEnabled(true); animation.setFillBefore(true); animation.setFillAfter(true); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { view.setVisibility(View.GONE); view.clearAnimation(); } @Override public void onAnimationRepeat(Animation animation) { } }); view.setAnimation(animation); animation.start(); } }
From source file:com.bluros.music.utils.FabAnimationUtils.java
public static void scaleOut(final View fab, long duration, final ScaleCallback callback) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { ViewCompat.animate(fab).scaleX(0.0F).scaleY(0.0F).alpha(0.0F) .setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR).setDuration(duration).withLayer() .setListener(new ViewPropertyAnimatorListener() { public void onAnimationStart(View view) { if (callback != null) callback.onAnimationStart(); }/*from w w w.ja va 2 s. com*/ public void onAnimationCancel(View view) { } public void onAnimationEnd(View view) { view.setVisibility(View.INVISIBLE); if (callback != null) callback.onAnimationEnd(); } }).start(); } else { Animation anim = AnimationUtils.loadAnimation(fab.getContext(), R.anim.design_fab_out); anim.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR); anim.setDuration(duration); anim.setAnimationListener(new Animation.AnimationListener() { public void onAnimationStart(Animation animation) { if (callback != null) callback.onAnimationStart(); } public void onAnimationEnd(Animation animation) { fab.setVisibility(View.INVISIBLE); if (callback != null) callback.onAnimationEnd(); } @Override public void onAnimationRepeat(Animation animation) { // } }); fab.startAnimation(anim); } }
From source file:com.bluros.music.utils.FabAnimationUtils.java
public static void scaleIn(final View fab, long duration, final ScaleCallback callback) { fab.setVisibility(View.VISIBLE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { ViewCompat.animate(fab).scaleX(1.0F).scaleY(1.0F).alpha(1.0F).setDuration(duration) .setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR).withLayer() .setListener(new ViewPropertyAnimatorListener() { public void onAnimationStart(View view) { if (callback != null) callback.onAnimationStart(); }//w w w. j av a 2 s . c o m public void onAnimationCancel(View view) { } public void onAnimationEnd(View view) { view.setVisibility(View.VISIBLE); if (callback != null) callback.onAnimationEnd(); } }).start(); } else { Animation anim = AnimationUtils.loadAnimation(fab.getContext(), R.anim.design_fab_out); anim.setDuration(duration); anim.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR); anim.setAnimationListener(new Animation.AnimationListener() { public void onAnimationStart(Animation animation) { if (callback != null) callback.onAnimationStart(); } public void onAnimationEnd(Animation animation) { fab.setVisibility(View.VISIBLE); if (callback != null) callback.onAnimationEnd(); } @Override public void onAnimationRepeat(Animation animation) { // } }); fab.startAnimation(anim); } }
From source file:Main.java
public static void slideToUp(View view) { Animation slide = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f); slide.setDuration(400);// w w w.j a va 2 s . c o m slide.setFillAfter(true); slide.setFillEnabled(true); view.startAnimation(slide); slide.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } }); }
From source file:org.smssecure.smssecure.util.ViewUtil.java
public static ListenableFuture<Boolean> animateOut(final @NonNull View view, final @NonNull Animation animation, final int visibility) { final SettableFuture future = new SettableFuture(); if (view.getVisibility() == visibility) { future.set(true);/*from w w w. j av a2s .c o m*/ } else { view.clearAnimation(); animation.reset(); animation.setStartTime(0); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { view.setVisibility(visibility); future.set(true); } }); view.startAnimation(animation); } return future; }
From source file:Main.java
public static void collapse(final View v, final int initialHeight, final int targetHeight, int duration, Animation.AnimationListener listener) { final int diffHeight = initialHeight - targetHeight; Animation a = new Animation() { @Override// ww w . jav a 2 s . c om protected void applyTransformation(float interpolatedTime, Transformation t) { v.getLayoutParams().height = initialHeight - (int) (diffHeight * interpolatedTime); v.requestLayout(); } @Override public boolean willChangeBounds() { return true; } }; a.setDuration(duration); a.setInterpolator(new DecelerateInterpolator(2)); if (listener != null) { a.setAnimationListener(listener); } v.startAnimation(a); }
From source file:Main.java
public static void animateHeight(final View animated, final int from, final int to, final long duration, final Interpolator interpolator, final AnimationListener animationListener) { final Animation animation = new Animation() { @Override//from w w w . j a v a 2 s . c o m protected void applyTransformation(float interpolatedTime, Transformation t) { final int newHeight = (int) (from + (to - from) * interpolatedTime); setHeight(animated, newHeight); } @Override public boolean willChangeBounds() { return true; } }; animation.setDuration(duration); animation.setInterpolator(interpolator); if (animationListener != null) { animation.setAnimationListener(animationListener); } animated.startAnimation(animation); }
From source file:Main.java
public static void expand(final View v, final int targetHeight, int duration, Interpolator interpolator, final Animation.AnimationListener listener) { final int initialHeight = v.getMeasuredHeight(); Animation a = new Animation() { @Override// w ww . java2 s.c o m protected void applyTransformation(float interpolatedTime, Transformation t) { v.getLayoutParams().height = initialHeight + (int) (targetHeight * interpolatedTime); v.requestLayout(); } @Override public boolean willChangeBounds() { return true; } }; a.setDuration(duration); if (interpolator != null) { a.setInterpolator(interpolator); } a.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { v.setLayerType(View.LAYER_TYPE_HARDWARE, null); if (listener != null) listener.onAnimationStart(animation); } @Override public void onAnimationEnd(Animation animation) { v.setLayerType(View.LAYER_TYPE_NONE, null); if (listener != null) listener.onAnimationEnd(animation); } @Override public void onAnimationRepeat(Animation animation) { if (listener != null) onAnimationRepeat(animation); } }); v.startAnimation(a); }