@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
hideRechargeBar();
Intent intent = getIntent();
String state = intent.getStringExtra("state");
if (state.equals("forget")) {
timeCount2 = new TimeCount2(60000, 1000);
setTopTitle(R.string.textView_forget);
setContentView(R.layout.activity_forget);
initForget();
} else if (state.equals("register")) {
timeCount = new TimeCount(60000, 1000);
setTopTitle(R.string.textView_regist);
setContentView(R.layout.activity_regist);
initRegister();
}
mHttpService = new HttpService(RegistActivity.this);
}
private final static int REGISTER_USER_PHONE = 1;
private final static int FORGET_USER_NUMBER = 2;
private String getFinalPhoneNumber;
/**
* HF add
* 账号注册 - 识别手机号码,格式化手机号码,自动空格
* 忘记密码 - 识别手机号码,格式化手机号码,自动空格
*/
private TextWatcher chooseTextWatcher(final int type) {
return new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (count == 1) {
if (s.length() == 4) {
String text = s.subSequence(0, s.length() - 1) + " " + s.subSequence(s.length() - 1, s.length());
switch (type) {
case REGISTER_USER_PHONE:
registerUserPhone.setText(text);
registerUserPhone.setSelection(5);
break;
case FORGET_USER_NUMBER:
forgetUserNumber.setText(text);
forgetUserNumber.setSelection(5);
break;
}
}
if (s.length() == 9) {
String text = s.subSequence(0, s.length() - 1) + " " + s.subSequence(s.length() - 1, s.length());
switch (type) {
case REGISTER_USER_PHONE:
registerUserPhone.setText(text);
registerUserPhone.setSelection(10);
break;
case FORGET_USER_NUMBER:
forgetUserNumber.setText(text);
forgetUserNumber.setSelection(10);
break;
}
}
} else if (count == 0) {
if (s.length() == 4) {
switch (type) {
case REGISTER_USER_PHONE:
registerUserPhone.setText(s.subSequence(0, s.length() - 1));
registerUserPhone.setSelection(3);
break;
case FORGET_USER_NUMBER:
forgetUserNumber.setText(s.subSequence(0, s.length() - 1));
forgetUserNumber.setSelection(3);
break;
}
}
if (s.length() == 9) {
switch (type) {
case REGISTER_USER_PHONE:
registerUserPhone.setText(s.subSequence(0, s.length() - 1));
registerUserPhone.setSelection(8);
break;
case FORGET_USER_NUMBER:
forgetUserNumber.setText(s.subSequence(0, s.length() - 1));
forgetUserNumber.setSelection(8);
break;
}
}
}
}
@Override
public void afterTextChanged(Editable s) {
switch (type) {
case REGISTER_USER_PHONE:
getFinalPhoneNumber = registerUserPhone.getText().toString().replaceAll("\\s+", "");
break;
case FORGET_USER_NUMBER:
getFinalPhoneNumber = forgetUserNumber.getText().toString().replaceAll("\\s+", "");
break;
}
int numLength = getFinalPhoneNumber.length();
if (numLength > 11) {
Toast showToast = Toast.makeText(RegistActivity.this, "号码长度有误,请输入11位正确号码", Toast.LENGTH_LONG);
showToast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
showToast.show();
}
}
};
}
/**
* HF add,对 EditText 的焦点进行处理,转移焦点后确定将手机号码格式化成 xxx-xxxx-xxxx 的形式
*
* @param type 判断处理的页面类型,账号注册 或 忘记密码
* @return
*/
private View.OnFocusChangeListener chooseFocusChangeListener(final int type) {
return new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus) {
} else {
int phoneLength = getFinalPhoneNumber.replaceAll("\\s+", "").length();
if (phoneLength == 11) {
String formatPhoneNumber = getFinalPhoneNumber.substring(0, 3) + " " + getFinalPhoneNumber.substring(3, 7) + " " + getFinalPhoneNumber.substring(7);
switch (type) {
case REGISTER_USER_PHONE:
registerUserPhone.setText(formatPhoneNumber);
break;
case FORGET_USER_NUMBER:
forgetUserNumber.setText(formatPhoneNumber);
break;
}
} else {
Toast showToast = Toast.makeText(RegistActivity.this, "号码长度有误,请输入11位正确号码", Toast.LENGTH_LONG);
showToast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
showToast.show();
}
}
}
};
}
private void initRegister() {
registerUserPhone = (EditText) findViewById(R.id.register_user_phone);
registerUserPhone.setInputType(InputType.TYPE_CLASS_PHONE);
registerUserPhone.addTextChangedListener(chooseTextWatcher(REGISTER_USER_PHONE));
registerUserPhone.setOnFocusChangeListener(chooseFocusChangeListener(REGISTER_USER_PHONE));
verificationCodeBtn = (Button) findViewById(R.id.register_gain_verificationCode);
verificationCodeBtn.setOnClickListener(this);
registerVerificationCode = (EditText) findViewById(R.id.register_verification_code);
registerUserPassWord = (EditText) findViewById(R.id.register_user_password);
registerAffirmUserPassWord = (EditText) findViewById(R.id.register_user_affirm_password);
personalAccount = (Button) findViewById(R.id.personal_account);
personalAccount.setOnClickListener(this);
groupAccount = (Button) findViewById(R.id.group_account);
groupAccount.setOnClickListener(this);
userCheckbox = (CheckBox) findViewById(R.id.user_checkbox);
registerCommit = (Button) findViewById(R.id.register_commit);
registerCommit.setOnClickListener(this);
doermiProtocol = (TextView) findViewById(R.id.doermi_protocol);
doermiProtocol.setOnClickListener(this);
}