package com.taikor.investment.utils;

import android.graphics.Color;
import android.os.CountDownTimer;
import android.widget.TextView;

import com.taikor.investment.R;

/**
 * 验证码倒计时
 * Created by Any on 2017/4/13.
 */

public class CountDownTimerUtils extends CountDownTimer {

    private TextView mTextView;

    public CountDownTimerUtils(TextView textView, long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
        this.mTextView = textView;
    }

    @Override
    public void onTick(long millisUntilFinished) {
        mTextView.setClickable(false); //设置不可点击  
        mTextView.setText("重新发送" + millisUntilFinished / 1000 + "s");  //设置倒计时时间 
        mTextView.setTextColor(Color.parseColor("#999999"));//不可点击时字体颜色
        mTextView.setBackgroundResource(R.drawable.bg_code_clicked); //设置按钮为灰色，这时是不能点击的  

    }

    @Override
    public void onFinish() {
        mTextView.setText("重新获取");
        mTextView.setClickable(true);//重新获得点击
        mTextView.setTextColor(Color.parseColor("#ED5351")); //恢复字体颜色
        mTextView.setBackgroundResource(R.drawable.bg_code_normal);  //还原背景色  
    }
}  
