Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.os.Build;
import android.view.View;
import android.view.ViewAnimationUtils;

import android.view.animation.LinearInterpolator;

public class Main {
    public static final int START_LEFT_TOP = 1;
    public static final int START_LEFT_BOTTOM = 2;
    public static final int START_RIGHT_TOP = 3;
    public static final int START_RIGHT_BOTTOM = 4;
    public static final int START_CENTER = 5;

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public static void show(final View view, final int cornerType, int normalAnimRes,
            final AnimatorListenerAdapter listener) {
        try {
            int[] amaya = calulateCorner(view, cornerType);
            Animator anim = ViewAnimationUtils.createCircularReveal(view, amaya[0], amaya[1], 0, amaya[2]);
            anim.setInterpolator(new LinearInterpolator());
            anim.setDuration(300);
            anim.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationStart(Animator animation) {
                    super.onAnimationStart(animation);
                    view.setVisibility(View.VISIBLE);
                    if (listener != null) {
                        listener.onAnimationStart(animation);
                    }
                }

            });
            anim.start();
        } catch (Exception e) {
            e.printStackTrace();
            view.setVisibility(View.VISIBLE);
        }
    }

    private static int[] calulateCorner(View view, int cornerType) {
        int x = (int) view.getX();
        int y = (int) view.getY();
        int w = view.getWidth();
        int h = view.getHeight();
        int[] amaya = new int[3];
        switch (cornerType) {
        default:
        case START_LEFT_TOP:
            amaya[0] = x;
            amaya[1] = y;
            break;
        case START_LEFT_BOTTOM:
            amaya[0] = x;
            amaya[1] = y + h;
            break;
        case START_RIGHT_TOP:
            amaya[0] = x + w;
            amaya[1] = y;
            break;
        case START_RIGHT_BOTTOM:
            amaya[0] = x + w;
            amaya[1] = y + h;
            break;
        case START_CENTER:
            amaya[0] = x + w / 2;
            amaya[1] = y + h / 2;
            break;
        }
        amaya[2] = (int) Math.sqrt(w * w + h * h);
        return amaya;
    }
}