/** * 获取验证码 * * @param v */ @OnClick(R.id.register_captcha_tv_get_captcha) public void onGetCaptcha(View v) { if (StringUtil.isEmpty(etPhone.getText().toString())) { ToastUtil.getInstance().showShortToast(this, "请输入手机号码"); return; } if (!StringUtil.isMobileNumber(etPhone.getText().toString())) { ToastUtil.getInstance().showShortToast(this, "请输入正确的号码"); return; } phone = etPhone.getText().toString(); RequestParams params = new RequestParams(); params.put("phone", phone); params.put("identity", HMApi.IDENTITY); HMApiUser.getInstance().postCaptcha(this, params); tvGetCaptcha.setClickable(false); timer = new Timer(); timer.schedule( new TimerTask() { @Override public void run() { timeHandler.post( new Runnable() { @Override public void run() { if (count > 0) { tvGetCaptcha.setText("" + count); count--; } else { setCaptchaAble(); } } }); } }, 0, 1000); }
/** * 提交验证码 * * @param v */ @OnClick(R.id.register_captcha_tv_submit) public void onRegister(View v) { String captcha = etCaptcha.getText().toString().trim(); password = etPassword.getText().toString().trim(); String psComfirm = etPasswordComfirm.getText().toString().trim(); phone = etPhone.getText().toString().trim(); if (StringUtil.isEmpty(etPhone.getText().toString())) { ToastUtil.getInstance().showShortToast(this, "请输入手机号码"); return; } if (!StringUtil.isMobileNumber(etPhone.getText().toString())) { ToastUtil.getInstance().showShortToast(this, "请输入正确的号码"); return; } if (StringUtil.isEmpty(captcha)) { ToastUtil.getInstance().showShortToast(this, "请输入验证码"); return; } if (StringUtil.isEmpty(password)) { ToastUtil.getInstance().showShortToast(this, "请输入密码"); return; } if (StringUtil.isEmpty(psComfirm)) { ToastUtil.getInstance().showShortToast(this, "请输入确认密码"); return; } if (!password.matches(BaseConfig.PATTERN_PASSWORD)) { ToastUtil.toastAlways(this, "请输入正确的密码格式"); return; } if (!password.equals(psComfirm)) { ToastUtil.getInstance().showShortToast(this, "密码不一致"); return; } showLoading(); RequestParams params = new RequestParams(); params.put("phone", phone); params.put("password", password); params.put("code", captcha); params.put("identity", HMApi.IDENTITY); HMApiUser.getInstance().postRegister(this, params); }