Example usage for android.view.animation Animation setAnimationListener

List of usage examples for android.view.animation Animation setAnimationListener

Introduction

In this page you can find the example usage for android.view.animation Animation setAnimationListener.

Prototype

public void setAnimationListener(AnimationListener listener) 

Source Link

Document

Binds an animation listener to this animation.

Usage

From source file:Main.java

public static void executeAnimation(Animation anim, View view, AnimationListener listener) {
    if (listener != null)
        anim.setAnimationListener(listener);
    view.startAnimation(anim);//  w ww.j  a v  a2s  .  co m
}

From source file:Main.java

public static Animation makeInvisibleAnimated(final View view) {
    final Animation a = new AlphaAnimation(1.00f, 0.00f);
    a.setDuration(500);// w  w w  .  j  av a 2 s.  c o  m
    a.setAnimationListener(getFadeOutListener(view));

    view.startAnimation(a);

    return a;
}

From source file:Main.java

@SuppressLint("NewApi")
public static Animation makeVisibleAnimated(final View view) {
    final Animation a = new AlphaAnimation(0.00f, 1.00f);
    a.setDuration(500);//from  w  ww.j  av a  2  s. co m
    a.setAnimationListener(getFadeInListener(view));

    view.startAnimation(a);

    return a;
}

From source file:Main.java

public static void startFadeInAnimationOn(final View container, boolean forceFade) {
    if (forceFade || container.getVisibility() != View.VISIBLE) {
        Animation animation = getFadeInAnimation(FADE_DURATION);
        animation.setAnimationListener(new AnimationListener() {
            @Override/*  w  w  w .  j  a  v  a2 s.  c  om*/
            public void onAnimationStart(Animation animation) {
                container.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
            }
        });

        container.startAnimation(animation);
    }
}

From source file:Main.java

public static void startFadeOutAnimationOn(final View container, boolean forceFade) {
    if (forceFade || container.getVisibility() == View.VISIBLE) {
        Animation animation = getFadeOutAnimation(FADE_DURATION);
        animation.setAnimationListener(new AnimationListener() {
            @Override/*w w  w.j  a v a 2  s  . c o  m*/
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                container.setVisibility(View.GONE);
            }
        });

        container.startAnimation(animation);
    }
}

From source file:Main.java

public static void addAnimationToView(final View view, final int animation) {
    if (view == null) {
        return;/*ww w  .j  av  a2s .c  o  m*/
    }
    Animation anim = AnimationUtils.loadAnimation(view.getContext(), animation);
    anim.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            view.setVisibility(View.VISIBLE);
        }
    });
    view.startAnimation(anim);
}

From source file:Main.java

/**
 * Apply the specified animation to the view.
 *
 * @param context           the context//from   w ww .j  av a2 s . co  m
 * @param v                 the view to apply the animation to
 * @param animationResource the animation resource to apply
 * @param listener          the animation listener to attach to the animation
 */
public static void applyViewAnimation(Context context, View v, int animationResource,
        Animation.AnimationListener listener) {
    Animation animation = android.view.animation.AnimationUtils.loadAnimation(context, animationResource);
    animation.setAnimationListener(listener);
    v.startAnimation(animation);
}

From source file:Main.java

/**
 * This method will cause a view to fade out after which it fires a callback where operations can be performed then it will fade back in
 * @param view the view to fade/*from w w w  . jav  a2 s . c  om*/
 * @param callback the callback to execute after the view has faded out
 */
public static void fadeOutIn(final View view, final Handler.Callback callback) {
    final Animation in = new AlphaAnimation(0.0f, 1.0f);
    in.setDuration(ANIMATION_SPEED);
    final Animation out = new AlphaAnimation(1.0f, 0.0f);
    out.setDuration(ANIMATION_SPEED);
    out.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            callback.handleMessage(null);
            view.startAnimation(in);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });
    view.startAnimation(out);
}

From source file:Main.java

public static void fadeAnimation(final View view, final float fromAlpha, final float toAlpha, long duration,
        final Runnable callback) {
    Animation anim = new AlphaAnimation(fromAlpha, toAlpha);
    anim.setDuration(duration);/*  w  w  w  .ja  v a 2 s.co m*/
    anim.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            view.setAlpha(toAlpha);
            if (toAlpha > 0)
                view.setVisibility(View.VISIBLE);
            else
                view.setVisibility(View.GONE);

            if (callback != null)
                callback.run();
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });

    view.setVisibility(View.VISIBLE);
    view.startAnimation(anim);
}

From source file:Main.java

public static void switchViewsVisibilityByFade(final View oldView, final View newView) {

    final Animation fadeIn = new AlphaAnimation(0, 1);
    fadeIn.setDuration(700);//from  www . j a v  a2 s . com

    Animation fadeOut = new AlphaAnimation(1, 0);
    fadeOut.setDuration(700);

    fadeOut.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {

            oldView.setVisibility(View.GONE);
            newView.setVisibility(View.VISIBLE);
            newView.startAnimation(fadeIn);
        }
    });
    oldView.startAnimation(fadeOut);

}