class TimeCount extends CountDownTimer {
public TimeCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {// 计时完毕
finish();
}
public void finish() {
ui_login_code.setText("获取");
ui_login_code.setClickable(true);
}
@Override
public void onTick(long millisUntilFinished) {// 计时过程
ui_login_code.setClickable(false);// 防止重复点击
ui_login_code.setText(millisUntilFinished / 1000 + "s");
}
}
public class LoginActivity extends BaseActivity implements OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
setContentView(R.layout.ui_login);
time = new TimeCount(60000, 1000);
initView();
}
private void initView(){
ui_login_code = (Button) findViewById(R.id.ui_login_code);
ui_login_code.setOnClickListener(this);
}
public void onClick(View v){
switch(v.getId)
case R.id.ui_login_code:
// 发送请求获取短信验证码
if (NetWorkUtil.isNetworkConnected(context)) {
LoginNameNull();
} else {
Utils.showToast(Constants.ToastText.NETWORK_BAD, context);
}
break;
case R.id.ui_login_btn_1:// 登录按钮
{
judge();// 用户名密码空判断
}
break;
}
/**
* 用户名为空判断
*/
public void LoginNameNull() {
name = ui_login_user.getText().toString().trim();// 用户名
if (StringUtil.isEmpty(name)) {
Utils.showToast("用户名不能为空", context);
return;
}
time.start();// 开始计时
}
private void reSet() {
time.cancel();
time.finish();
}
}