Example usage for android.view View startAnimation

List of usage examples for android.view View startAnimation

Introduction

In this page you can find the example usage for android.view View startAnimation.

Prototype

public void startAnimation(Animation animation) 

Source Link

Document

Start the specified animation now.

Usage

From source file:Main.java

public static void fadeToVisible(final View view, int startOffset, int duration) {
    int visibility = view.getVisibility();
    if (visibility != View.VISIBLE) {
        AlphaAnimation anim = new AlphaAnimation(0, 1);
        anim.setDuration(duration);//from  w w  w.  j a v  a  2 s.com
        anim.setStartOffset(startOffset);
        view.setVisibility(View.VISIBLE);
        view.startAnimation(anim);
    }
}

From source file:Main.java

/**
 * Fade in a view from startAlpha to endAlpha during duration milliseconds
 * @param view The {@link View} to use//from   w  w w  .  java 2 s  .  c  om
 * @param startAlpha
 * @param endAlpha
 * @param duration
 */
public static void fadeIn(View view, float startAlpha, float endAlpha, long duration) {
    if (view.getVisibility() == View.VISIBLE) {
        return;
    }

    view.setVisibility(View.VISIBLE);
    Animation animation = new AlphaAnimation(startAlpha, endAlpha);
    animation.setDuration(duration);
    view.startAnimation(animation);
}

From source file:Main.java

public static void blink(View view, int durationMs, int repeatCount) {
    Animation anim = new AlphaAnimation(1.0f, 0.0f);
    anim.setDuration(durationMs); //You can manage the time of the blink with this parameter
    anim.setStartOffset(0);//from  w  w w.ja v  a2 s. co m
    anim.setRepeatMode(Animation.REVERSE);
    anim.setRepeatCount(repeatCount);
    view.startAnimation(anim);

}

From source file:Main.java

/**
 *    move the background view(translate animation).
 * /*from w ww .  j  a v  a2s .  c o  m*/
 * @param view
 *          the view will be moved
 * @param durationMillis
 *          translate animation duration
 * @param fromX
 *          from X coordinate
 * @param toX
 *          to X coordinate
 * @param fromY
 *          from Y coordinate
 * @param toY
 *          to Y coordinate
 */
public static void translate(View view, long durationMillis, boolean fillAfter, float fromX, float toX,
        float fromY, float toY) {
    TranslateAnimation ta = new TranslateAnimation(fromX, toX, fromY, toY);
    ta.setDuration(durationMillis);
    ta.setFillAfter(fillAfter);//this animation performed will persist when it is finished
    view.startAnimation(ta);
}

From source file:Main.java

public static void fadeToInvisible(final View view, int startOffset, int duration) {
    int visibility = view.getVisibility();
    if (visibility != View.INVISIBLE) {
        AlphaAnimation anim = new AlphaAnimation(1, 0);
        anim.setStartOffset(startOffset);
        anim.setDuration(duration);/*from   ww  w .j a  v a  2s .  co m*/
        view.setVisibility(View.INVISIBLE);
        view.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);//from  w ww  .  j av  a2 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: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  ww . ja  v a2 s . c  o 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

public static void startBlink(View view) {
    if (null == view) {
        return;/* ww w .  j av a 2  s.c  om*/
    }
    Animation alphaAnimation = new AlphaAnimation(1, 0);
    alphaAnimation.setDuration(500);
    alphaAnimation.setInterpolator(new LinearInterpolator());
    alphaAnimation.setRepeatCount(Animation.INFINITE);
    alphaAnimation.setRepeatMode(Animation.REVERSE);
    view.startAnimation(alphaAnimation);
}

From source file:Main.java

public static void SlideOutLeft(View v, final Runnable onComplete) {
    v.clearAnimation();/*from   www.ja  va  2  s . co  m*/
    TranslateAnimation aout = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF,
            -1f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f);
    aout.setDuration(300);
    aout.setFillAfter(true);
    v.startAnimation(aout);
    if (onComplete != null)
        aout.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation arg0) {
            }

            @Override
            public void onAnimationRepeat(Animation arg0) {
            }

            @Override
            public void onAnimationEnd(Animation arg0) {
                onComplete.run();
            }
        });
}

From source file:Main.java

public static void startAnimation(View target, int aniResId, AnimationListener listener) {
    if (target == null)
        return;//ww w.jav a2s  .  co m

    Animation animation = AnimationUtils.loadAnimation(target.getContext(), aniResId);
    if (animation != null) {
        if (listener != null) {
            animation.setAnimationListener(listener);
        }
        target.startAnimation(animation);
    }
}