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

import android.view.View;

public class Main {
    public static final String COLOR_PROPERTY = "color";

    public static void animateColorChange(View view, int fromColor, int toColor, int duration,
            Animator.AnimatorListener listener) {
        if (view.getWindowToken() == null) {
            return;
        }
        AnimatorSet animation = new AnimatorSet();
        ObjectAnimator colorAnimator = ObjectAnimator.ofInt(view, COLOR_PROPERTY, fromColor, toColor);
        colorAnimator.setEvaluator(new ArgbEvaluator());
        colorAnimator.setDuration(duration);
        if (listener != null)
            animation.addListener(listener);
        animation.play(colorAnimator);
        animation.start();
    }
}