Example usage for android.view.animation AlphaAnimation setDuration

List of usage examples for android.view.animation AlphaAnimation setDuration

Introduction

In this page you can find the example usage for android.view.animation AlphaAnimation setDuration.

Prototype

public void setDuration(long durationMillis) 

Source Link

Document

How long this animation should last.

Usage

From source file:Main.java

@SuppressLint("NewApi")
public static void setAlpha(View view, float alpha) {
    if (Build.VERSION.SDK_INT < 11) {
        final AlphaAnimation animation = new AlphaAnimation(alpha, alpha);
        animation.setDuration(0);
        animation.setFillAfter(true);/*from w  w w. ja  v a 2 s . co  m*/
        view.startAnimation(animation);
    } else {
        view.setAlpha(alpha);
    }
}

From source file:Main.java

/**
 * Change opacity of a given view, with the alpha level given as parameter.
 * This method considers the environment version.
 *
 * @param view       View that will change its opacity
 * @param alphaLevel Alpha level representing the opacity, where 0.0 is completely transparent, and 1.0 is completely opaque
 *///ww w  . j  a  va 2 s  .c o m
public static void setAlphaForAllVersions(View view, float alphaLevel) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        view.setAlpha(alphaLevel);
    } else {
        AlphaAnimation alpha = new AlphaAnimation(alphaLevel, alphaLevel);
        alpha.setDuration(0); // Make animation instant
        alpha.setFillAfter(true); // Tell it to persist after the animation ends
        view.startAnimation(alpha);
    }
}

From source file:Main.java

private static void setAlpha(View view, float alphaValue) {

    if (alphaValue == 1) {
        view.clearAnimation();/*from   w  w w . j  a v a 2 s  .  co  m*/
    } else {
        AlphaAnimation alpha = new AlphaAnimation(alphaValue, alphaValue);
        alpha.setDuration(0); // Make animation instant
        alpha.setFillAfter(true); // Tell it to persist after the animation ends       
        view.startAnimation(alpha);
    }

}

From source file:Main.java

public static AnimationSet RotateAndFadeInAnimation() {

    AlphaAnimation fade_in = new AlphaAnimation(0.2f, 1f);
    fade_in.setDuration(400);
    fade_in.setStartOffset(0);//from w  w w.java 2  s  . co  m
    fade_in.setFillAfter(true);

    ScaleAnimation expand = new ScaleAnimation(0.2f, 1, 0.2f, 1, Animation.RELATIVE_TO_SELF, .5f,
            Animation.RELATIVE_TO_SELF, .5f);
    expand.setDuration(500);
    expand.setStartOffset(0);
    expand.setFillAfter(true);

    RotateAnimation rotate = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, .5f,
            Animation.RELATIVE_TO_SELF, .5f);
    rotate.setDuration(500);
    rotate.setStartOffset(0);
    // rotate.setInterpolator(new LinearInterpolator());
    rotate.setFillAfter(true);

    AnimationSet Reload = new AnimationSet(true);
    Reload.addAnimation(fade_in);
    Reload.addAnimation(expand);
    Reload.addAnimation(rotate);
    Reload.setInterpolator(new DecelerateInterpolator(1.3f));
    return Reload;
}

From source file:Main.java

public static Animation getAlpha(float fromAlpha, float toAlpha, long duration) {
    AlphaAnimation animation = new AlphaAnimation(fromAlpha, toAlpha);
    animation.setFillAfter(true);//w  w w .  j  a v  a 2 s  .  co m
    animation.setDuration(duration);
    return animation;
}

From source file:Main.java

public static AnimationSet RotateAndFadeOutAnimation() {
    AlphaAnimation fade_out = new AlphaAnimation(1f, 0.2f);
    fade_out.setDuration(500);
    fade_out.setStartOffset(0);/*from w  w w  .  ja  v a2 s. c om*/
    fade_out.setFillAfter(true);

    ScaleAnimation shrink = new ScaleAnimation(1f, 0.2f, 1f, 0.2f, Animation.RELATIVE_TO_SELF, .5f,
            Animation.RELATIVE_TO_SELF, .5f);
    shrink.setDuration(400);
    shrink.setStartOffset(0);
    shrink.setFillAfter(true);

    RotateAnimation rotate = new RotateAnimation(0.0f, 360f, Animation.RELATIVE_TO_SELF, .5f,
            Animation.RELATIVE_TO_SELF, .5f);
    rotate.setDuration(500);
    rotate.setStartOffset(0);
    rotate.setInterpolator(new LinearInterpolator());
    rotate.setFillAfter(true);

    AnimationSet Reload = new AnimationSet(true);
    Reload.addAnimation(fade_out);
    Reload.addAnimation(shrink);
    Reload.addAnimation(rotate);
    Reload.setInterpolator(new AccelerateInterpolator(1.1f));

    return Reload;
}

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);
        view.setVisibility(View.INVISIBLE);
        view.startAnimation(anim);/*  w ww .j  a v  a 2  s .com*/
    }
}

From source file:Main.java

/**
 * Animate a view to fade in./*from   www. ja v a 2 s  . c o  m*/
 *
 * @param view         The view to be animated.
 * @param duration     Duration that the animation should run, in milliseconds; specify -1 to use the default.
 * @param interpolator The interpolator which defines the acceleration curve; can be null to use default.
 */
public static void startFadeIn(View view, long duration, Interpolator interpolator) {
    AlphaAnimation alphaAnimation = new AlphaAnimation(0f, 1f);
    if (duration > 0) {
        alphaAnimation.setDuration(duration);
    }
    if (interpolator != null) {
        alphaAnimation.setInterpolator(interpolator);
    }
    view.startAnimation(alphaAnimation);
}

From source file:Main.java

public static void SetFlickerAnimation(final TextView v, final String info, final String temp) {
    v.setText(info);/*from  w  w  w.jav a2s.c  om*/
    AlphaAnimation anim = new AlphaAnimation(0, 1);
    anim.setDuration(4000);
    anim.setRepeatCount(Animation.INFINITE);
    // anim1.setRepeatMode(Animation.REVERSE);
    anim.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationStart(Animation arg0) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onAnimationRepeat(Animation arg0) {
            // TODO Auto-generated method stub
            num++;
            if (num == 10) {
                num = 0;
            }
            if (num % 2 == 0) {
                v.setText(info);
            } else {
                v.setText(temp);
            }
        }

        @Override
        public void onAnimationEnd(Animation arg0) {
            // TODO Auto-generated method stub

        }
    });
    v.startAnimation(anim);

}

From source file:Main.java

public static Animation getAplhaAnimation(float fromAlpha, float toAlpha) {
    AlphaAnimation alphaAnimation = new AlphaAnimation(fromAlpha, toAlpha);
    alphaAnimation.setFillAfter(true);//from  ww  w.  j av  a 2s .c o  m
    alphaAnimation.setDuration(0);
    return (alphaAnimation);
}