package com.liulishuo.magicprogress.demo.widget;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * Created by Jacksgong on 12/11/15.
 */
public class AnimTextView extends TextView {
    public AnimTextView(Context context) {
        super(context);
    }

    public AnimTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public AnimTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public AnimTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    private int progress;
    private int max;

    public void setProgress(final int progress) {
        this.progress = progress;
        setText(String.valueOf(progress));
    }

    public int getProgress() {
        return this.progress;
    }

    public int getMax() {
        return max;
    }

    public void setMax(int max) {
        this.max = max;
    }
}

@@ -204,16 +204,166 @@
 tView;%0A%0A
+import java.lang.ref.WeakReference;%0A%0Aimport cn.dreamtobe.percentsmoothhandler.ISmoothTarget;%0Aimport cn.dreamtobe.percentsmoothhandler.SmoothHandler;%0A%0A
 /**%0A * C
@@ -442,17 +442,84 @@
 extView 
-%7B
+implements ISmoothTarget %7B%0A    private SmoothHandler smoothHandler;%0A
 %0A    pub
@@ -1072,16 +1072,22 @@
  int max
+ = 100
 ;%0A%0A    p
@@ -1127,24 +1127,142 @@
 progress) %7B%0A
+        if (smoothHandler != null) %7B%0A            smoothHandler.commitPercent(progress / (float) getMax());%0A        %7D%0A%0A
         this
@@ -1517,11 +1517,485 @@
 x;%0A    %7D
+%0A%0A    @Override%0A    public float getPercent() %7B%0A        return getProgress() / (float) getMax();%0A    %7D%0A%0A    @Override%0A    public void setPercent(float percent) %7B%0A        setProgress((int) Math.ceil(percent * getMax()));%0A    %7D%0A%0A    @Override%0A    public void setSmoothPercent(float percent) %7B%0A        if (smoothHandler == null) %7B%0A            smoothHandler = new SmoothHandler(new WeakReference%3CISmoothTarget%3E(this));%0A        %7D%0A%0A        smoothHandler.loopSmooth(percent);%0A    %7D
 %0A%7D%0A

add smooth-progress integration to AnimTextView