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.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;

import android.view.View;
import android.view.animation.AccelerateInterpolator;

public class Main {
    private static final AccelerateInterpolator ACCELERATE_INTERPOLATOR = new AccelerateInterpolator();

    public static void animateHeart(View view) {
        AnimatorSet animatorSet = new AnimatorSet();
        ObjectAnimator imgScaleUpYAnim = ObjectAnimator.ofFloat(view, "scaleY", 1.0f, 1.2f);
        imgScaleUpYAnim.setDuration(300);
        ObjectAnimator imgScaleUpXAnim = ObjectAnimator.ofFloat(view, "scaleX", 1.0f, 1.2f);
        imgScaleUpXAnim.setDuration(300);
        ObjectAnimator imgScaleDownYAnim = ObjectAnimator.ofFloat(view, "scaleY", 1.2f, 1.0f);
        imgScaleDownYAnim.setDuration(300);
        imgScaleDownYAnim.setInterpolator(ACCELERATE_INTERPOLATOR);
        ObjectAnimator imgScaleDownXAnim = ObjectAnimator.ofFloat(view, "scaleX", 1.2f, 1.0f);
        imgScaleDownXAnim.setDuration(300);
        animatorSet.playTogether(imgScaleUpXAnim, imgScaleUpYAnim);
        animatorSet.play(imgScaleDownYAnim).with(imgScaleDownXAnim).after(imgScaleUpXAnim);
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                view.clearAnimation();
                animatorSet.start();
            }
        });
        animatorSet.start();
    }
}