第二次冲刺(一)
今天我完成了短信的验证码功能。
代码:
eventHandler = new EventHandler() { public void afterEvent(int event, int result, Object data) { Message msg=new Message(); msg.arg1=event; msg.arg2=result; msg.obj=data; handler.sendMessage(msg); } }; SMSSDK.registerEventHandler(eventHandler); protected void onDestroy() { super.onDestroy(); SMSSDK.unregisterEventHandler(eventHandler); } Handler handler=new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); int event=msg.arg1; int result=msg.arg2; Object data=msg.obj; if (event == SMSSDK.EVENT_GET_VERIFICATION_CODE) { if(result == SMSSDK.RESULT_COMPLETE) { boolean smart = (Boolean)data; if(smart) { Toast.makeText(getApplicationContext(),"该手机号已经注册过,请重新输入", Toast.LENGTH_LONG).show(); EditTextPhone.requestFocus(); return; } } } if(result==SMSSDK.RESULT_COMPLETE) { if (event == SMSSDK.EVENT_SUBMIT_VERIFICATION_CODE) { Toast.makeText(getApplicationContext(), "验证码输入正确", Toast.LENGTH_LONG).show(); } } else { if(flag) { ButtonGetcode.setVisibility(View.VISIBLE); Toast.makeText(getApplicationContext(),"验证码获取失败请重新获取", Toast.LENGTH_LONG).show(); EditTextPhone.requestFocus(); } else { Toast.makeText(getApplicationContext(),"验证码输入错误", Toast.LENGTH_LONG).show(); } } } }; private boolean judPhone() { if(TextUtils.isEmpty(EditTextPhone.getText().toString().trim())) { Toast.makeText(RegisterActivity.this,"请输入您的电话号码",Toast.LENGTH_LONG).show(); EditTextPhone.requestFocus(); return false; } else if(EditTextPhone.getText().toString().trim().length()!=11) { Toast.makeText(RegisterActivity.this,"您的电话号码位数不正确",Toast.LENGTH_LONG).show(); EditTextPhone.requestFocus(); return false; } else { phone_number=EditTextPhone.getText().toString().trim(); String num="[1][358]\\d{9}"; if(phone_number.matches(num)) return true; else { Toast.makeText(RegisterActivity.this,"请输入正确的手机号码",Toast.LENGTH_LONG).show(); return false; } } } private boolean judCord() { judPhone(); if(TextUtils.isEmpty(EditTextCode.getText().toString().trim())) { Toast.makeText(RegisterActivity.this,"请输入您的验证码",Toast.LENGTH_LONG).show(); EditTextCode.requestFocus(); return false; } else if(EditTextCode.getText().toString().trim().length()!=4) { Toast.makeText(RegisterActivity.this,"您的验证码位数不正确",Toast.LENGTH_LONG).show(); EditTextCode.requestFocus(); return false; } else { cord_number=EditTextCode.getText().toString().trim(); return true; }