package com.kdanmobile.kdan_others_library_for_android.model;

import android.animation.ValueAnimator;
import android.view.animation.AccelerateDecelerateInterpolator;

/**
 * Created by Shan on 2017/4/12.
 */

public class AnimatorHelper {

    public interface AnimatorUpdateListener {
        void onAnimatorUpdate(Float updatePercent);
    }

    private ValueAnimator valueAnimator;

    public void startCirclePercentAnimator(float from, float to, final AnimatorUpdateListener l) {
        if (valueAnimator != null && !valueAnimator.isRunning()) return;
        valueAnimator = ValueAnimator.ofFloat(from, to);
        valueAnimator.setDuration(400);
        valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                float value = (Float) valueAnimator.getAnimatedValue();
                if (value >= 100) value = 100;
                l.onAnimatorUpdate(value);
            }
        });
        valueAnimator.setStartDelay(400);
        valueAnimator.start();
    }
}
