Example usage for android.view.animation AlphaAnimation AlphaAnimation

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

Introduction

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

Prototype

public AlphaAnimation(float fromAlpha, float toAlpha) 

Source Link

Document

Constructor to use when building an AlphaAnimation from code

Usage

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
 *///from   w  w  w. j a  v a 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

public static void animate(View v, int duration) {
    AlphaAnimation alpha = new AlphaAnimation(0f, 1f);
    alpha.setDuration(duration);//from   ww  w.j a v  a 2 s  .  c  o  m
    v.startAnimation(alpha);
}

From source file:Main.java

public static void animation(View paramView) {
    TranslateAnimation localTranslateAnimation = new TranslateAnimation(2, 1.0F, 2, 0.0F, 2, 0.0F, 2, 0.0F);
    AlphaAnimation localAlphaAnimation = new AlphaAnimation(0.0F, 1.0F);
    AnimationSet localAnimationSet = new AnimationSet(false);
    localAnimationSet.addAnimation(localTranslateAnimation);
    localAnimationSet.addAnimation(localAlphaAnimation);
    animation(paramView, localAnimationSet, 1000L, 0L);
}

From source file:Main.java

/**
 *
 * @param view//from www  . j av  a2  s.  c  o  m
 * @param duration
 */
public static void fadeOut(final View view, long duration) {
    Animation animation = new AlphaAnimation(1, 0);
    animation.setDuration(duration);

    animation.setFillAfter(true);
    animation.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            Message message = Message.obtain();
            message.obj = view;
            handler.sendMessage(message);
        }
    });

    view.startAnimation(animation);
}

From source file:Main.java

public static void fadeOut(View view) {
    if (view.getVisibility() != View.VISIBLE)
        return;/*  w  w w  .  j a va 2s  .c o  m*/

    Animation animation = new AlphaAnimation(1F, 0F);
    animation.setDuration(400);
    view.startAnimation(animation);
    view.setVisibility(View.GONE);
}

From source file:Main.java

public static AnimationSet FlipAnimation(int duration, int repeatCount) {
    AnimationSet flip = new AnimationSet(true);
    if (duration > 20) //Flip anim
    {/* ww w.  ja va 2  s.  c o  m*/
        Animation from_middle1_anim = new ScaleAnimation(1.0f, 0.0f, 1.0f, 1.0f, Animation.RELATIVE_TO_SELF,
                .5f, Animation.RELATIVE_TO_SELF, .5f);
        from_middle1_anim.setDuration(duration);
        from_middle1_anim.setStartOffset(0);
        from_middle1_anim.setRepeatMode(Animation.REVERSE);
        from_middle1_anim.setRepeatCount(repeatCount);

        flip.addAnimation(from_middle1_anim);
    } else // no anim
    {
        Animation noAnim = new AlphaAnimation(1f, 1f);
        noAnim.setDuration(duration);
        flip.addAnimation(noAnim);
    }
    return flip;
}

From source file:Main.java

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

    if (alphaValue == 1) {
        view.clearAnimation();/*from w  w  w .  ja  v a  2  s  . c  o  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 void fadeIn(View view) {
    if (view.getVisibility() == View.VISIBLE)
        return;/* w  w  w. j  a v a 2s .  c  om*/

    view.setVisibility(View.VISIBLE);
    Animation animation = new AlphaAnimation(0F, 1F);
    animation.setDuration(400);
    view.startAnimation(animation);
}

From source file:Main.java

public static void fadeIn(final View view) {
    Animation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);
    alphaAnimation.setDuration(FADE_DURATION);
    alphaAnimation.setAnimationListener(new AnimationListener() {

        @Override//  www.  j ava2s  .c o  m
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            view.setVisibility(View.INVISIBLE);

        }
    });
    view.startAnimation(alphaAnimation);
}

From source file:Main.java

private static void fadeInPreHoneyComb(final View view) {
    AlphaAnimation alphaAnimation = new AlphaAnimation(0.0F, 1.0F);
    alphaAnimation.setDuration(ANIMATION_DURATION);
    view.setVisibility(View.VISIBLE);
    view.startAnimation(alphaAnimation);
}