Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.view.View;

import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;

public class Main {
    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);
        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);
    }
}