获得验证码
class="brush:java;gutter:true;">case R.id.register_btn_getCode: mPhoneNumber = mEtPhoneNumber.getText().toString(); if (LoginHelperUtil.isPhoneNumber(mPhoneNumber)) { BmobManager.getInstance(new BmobMsgSendCallback() { @Override public void onMsgSendSuccess() { ToastUtil.show(RegisterActivity.this,R.string.sms_code_send_success); //验证码发送成功,倒计时 setCodeTimeDown(); } @Override public void onMsgSendFailure() { ToastUtil.show(RegisterActivity.this,R.string.sms_code_send_failure); } }).sendMsgCode(mPhoneNumber); } else { ToastUtil.show(this,R.string.phone_number_incorrect); } break;
private void setCodeTimeDown() { mBtnGetCode.setEnabled(false); final Timer timer = new Timer(); mSecCount = 60; TimerTask timerTask = new TimerTask() { @Override public void run() { runOnUiThread(new Runnable() { @Override public void run() { mSecCount--; mBtnGetCode.setText(mSecCount+" s"); if (mSecCount<=0) { timer.cancel(); mBtnGetCode.setText(R.string.reSend); mBtnGetCode.setEnabled(true); } } }); } }; timer.schedule(timerTask,1000,1000); }
注册
case R.id.register_btn_register: mPhoneNumber = mEtPhoneNumber.getText().toString(); mMsgCode = mEtCode.getText().toString(); mPassword = mEtPassword.getText().toString(); mRepassword = mEtRepassword.getText().toString(); if (LoginHelperUtil.isPhoneNumber(mPhoneNumber) && LoginHelperUtil.isCodeCorrect(mMsgCode) && TextUtils.equals(mPassword,mRepassword)) { BmobManager.getInstance(new BmobSignUpCallback() { @Override public void onSignUpSuccess(User user) { Intent intent = new Intent(RegisterActivity.this,MainActivity.class); intent.putExtra(INTENT_USER,user); startActivity(intent); ToastUtil.show(RegisterActivity.this,R.string.register_success); finish(); } @Override public void onSignUpFailure(BmobException e) { ToastUtil.show(RegisterActivity.this,R.string.register_failure); } }).signUp(mPhoneNumber,mMsgCode,mPassword); } else { ToastUtil.show(this,R.string.register_input_incorrect); } break;