验证码

Posted 蹭饭熊

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了验证码相关的知识,希望对你有一定的参考价值。

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

/**
* Description:验证码
* User: lxs
*/
public class VerificationCode {

private Context context;
private TextView code;
private TimeHandler timeHandler;
private long startTime;
private final String second = " S";

public VerificationCode(Context context, TextView code) {
this.context = context;
this.code = code;
timeHandler = new TimeHandler();
}

public void start() {
code.setEnabled(false);
startTime = System.currentTimeMillis();
timeHandler.sendEmptyMessage(1);
}

public void stop() {
startTime = 0;
timeHandler.sendEmptyMessage(0);
}

public void clear() {
code = null;
timeHandler = null;
}

private class TimeHandler extends Handler {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what > 0) {
int time = 59 - (int) ((System.currentTimeMillis() - startTime) / 1000);
String show = time + second;
code.setText(show);
sendEmptyMessageDelayed(time, 100);
} else {
code.setText(context.getResources().getString(R.string.get_verification_code));
code.setEnabled(true);
timeHandler.removeCallbacksAndMessages(null);
}
}
}
}

<string name="get_verification_code">获取验证码</string>

以上是关于验证码的主要内容,如果未能解决你的问题,请参考以下文章

js实现输入手机验证码后点击提交按钮验证手机输入的验证码和发送的验证码是不是一致

验证码的识别

几米互联验证码有什用

PHP算式验证码和汉字验证码的实现方法

Spring Security---验证码详解

thinkphp3.2验证码怎么写