Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.animation.Animator;

import android.animation.AnimatorSet;

import android.animation.ObjectAnimator;

import android.view.View;

public class Main {
    public static final int DURATION_SHORT = 300;

    public static void scaleHide(final View view) {
        scaleHide(view, null);
    }

    public static void scaleHide(final View view, final Runnable rWhenEnd) {
        if (view.getWindowToken() == null) {
            view.setVisibility(View.INVISIBLE);
            if (rWhenEnd != null) {
                rWhenEnd.run();
            }
            return;
        }
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0f);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0f);
        AnimatorSet set = new AnimatorSet();
        set.playTogether(scaleX, scaleY);
        set.setDuration(DURATION_SHORT);
        set.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                view.setVisibility(View.INVISIBLE);
                if (rWhenEnd != null) {
                    rWhenEnd.run();
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                view.setVisibility(View.INVISIBLE);
                if (rWhenEnd != null) {
                    rWhenEnd.run();
                }
            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        set.start();
    }
}