@Override public void onClick(View v) { switch (v.getId()) { case R.id.submit_btn: // 注册提交 // 获取手机账号 mobile = user_name_edit.getText().toString().replace(" ", ""); if (isMobileNO(mobile)) { // 手机号码格式正确 Toast.makeText(mActivity, "手机号码格式正确", Toast.LENGTH_SHORT).show(); } else { // 手机号码格式错误 Toast.makeText(mActivity, "手机号码格式错误", Toast.LENGTH_SHORT).show(); } Toast.makeText(mActivity, "登录成功", Toast.LENGTH_SHORT).show(); // 进入登录验证 // CommonActivity activity = (CommonActivity) mActivity; // activity.replaceFragment(new LoginVerificateFragment()); break; case R.id.right_text: // 登录 // 进入登录页面页面 CommonActivity activityRegist = (CommonActivity) mActivity; activityRegist.replaceFragment(new LoginFragment()); break; case R.id.verificate_text: // 发送验证码 // 获取手机账号 mobile = user_name_edit.getText().toString().replace(" ", ""); if (isMobileNO(mobile)) { // 手机号码格式正确 Toast.makeText(mActivity, "手机号码格式正确", Toast.LENGTH_SHORT).show(); CountDownTextView countDownTextView = new CountDownTextView(verificate_text, "重新发送", 60, 1); countDownTextView.setOnFinishListener( new OnFinishListener() { @Override public void finish() { verificate_text.setClickable(true); } }); countDownTextView.start(); } else { // 手机号码格式错误 Toast.makeText(mActivity, "手机号码格式错误", Toast.LENGTH_SHORT).show(); } break; case R.id.soft_licence_agreement: // 软件许可协议按钮 break; default: break; } }
@Override public View initView() { // 标题 center_title = (TextView) getActivity().findViewById(R.id.center_title); // 标题右边文本内容 right_text = (TextView) getActivity().findViewById(R.id.right_text); right_text.setOnClickListener(this); // 实例化注册界面布局 View registView = View.inflate(mActivity, R.layout.regist, null); // 用户名EditText获取 user_name_edit = (ClearEditText) registView.findViewById(R.id.user_name_edit); // 发送验证码文本按钮 verificate_text = (TextView) registView.findViewById(R.id.verificate_text); // 验证码EditText获取 verificate_code_edit = (ClearEditText) registView.findViewById(R.id.verificate_code_edit); // 密码EditText获取 user_password_edit = (EditText) registView.findViewById(R.id.user_password_edit); // 设置不可长按防止编辑框自带的复制粘贴 user_password_edit.setLongClickable(false); // 密码隐藏和显示toggleButton ck_find_password_is_show = (ToggleButton) registView.findViewById(R.id.ck_find_password_is_show); // 提交按钮 submit_btn = (Button) registView.findViewById(R.id.submit_btn); // 同意协议复选框 argree_soft_agreement = (CheckBox) registView.findViewById(R.id.argree_soft_agreement); // argree_soft_agreement.isSelected() // 软件许可协议 soft_licence_agreement = (TextView) registView.findViewById(R.id.soft_licence_agreement); // 事件响应 submit_btn.setOnClickListener(this); verificate_text.setOnClickListener(this); soft_licence_agreement.setOnClickListener(this); ck_find_password_is_show.setClickable(true); // ToggleButton显示或者隐藏密码 ck_find_password_is_show.setOnCheckedChangeListener( new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // 设置隐藏密码 user_password_edit.setTransformationMethod( HideReturnsTransformationMethod.getInstance()); } else { // 设置显示密码 user_password_edit.setTransformationMethod( PasswordTransformationMethod.getInstance()); } // 设置光标的位置 user_password_edit.setSelection(user_password_edit.getText().toString().length()); } }); // 手机账号改变监听 user_name_edit.addTextChangedListener( new TextWatcher() { @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { if (arg0.toString().length() > 0) { // 长度大于0将字体颜色调为输入状态色 user_name_edit.setTextColor( getResources().getColor(R.color.login_mobile_input_right_text_color)); } else { // 没有输入讲字体颜色调为未输入状态 user_name_edit.setTextColor( getResources().getColor(R.color.login_mobile_pw_edit_text_color)); } if (user_password_edit.length() >= 6 && arg0.toString().length() == 13 && verificate_code_edit.length() == 4) { // 用户手机号和密码、验证码的长度符合规则 submit_btn.setBackgroundColor( getResources().getColor(R.color.login_ensure_input_right_background)); } else { // 用户手机号和密码的长度不符合规则 submit_btn.setBackgroundColor( getResources().getColor(R.color.login_ensure_background)); } } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { beforePosition = arg0.length(); } @Override public void afterTextChanged(Editable arg0) { if (beforePosition < arg0.toString().length() // 当前为输入 && (arg0.length() == 3 || arg0.length() == 8)) { // 长度为3或者8 arg0.insert(arg0.length(), " "); } if (beforePosition > arg0.toString().length() // 当前为删除 && (arg0.toString().length() == 4 || arg0.toString() // 长度为4或者9 .length() == 9)) { arg0.delete(arg0.length() - 1, arg0.length()); } } }); // 验证码监听 verificate_code_edit.addTextChangedListener( new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (s.toString().length() > 0) { // 长度大于0将字体颜色调为输入状态色 verificate_code_edit.setTextColor( getResources().getColor(R.color.login_mobile_input_right_text_color)); } else { // 没有输入讲字体颜色调为未输入状态 verificate_code_edit.setTextColor( getResources().getColor(R.color.login_mobile_pw_edit_text_color)); } if (user_name_edit.length() == 13 && user_password_edit.length() >= 6 && s.length() == 4) { // 用户手机号和密码、验证码的长度符合规则 submit_btn.setBackgroundColor( getResources().getColor(R.color.login_ensure_input_right_background)); } else { // 用户手机号和密码的长度不符合规则 submit_btn.setBackgroundColor( getResources().getColor(R.color.login_ensure_background)); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void afterTextChanged(Editable s) {} }); // 密码监听 user_password_edit.addTextChangedListener( new TextWatcher() { @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { if (arg0.toString().length() > 0) { // 长度大于0将字体颜色调为输入状态色 user_password_edit.setTextColor( getResources().getColor(R.color.login_mobile_input_right_text_color)); } else { // 没有输入讲字体颜色调为未输入状态 user_password_edit.setTextColor( getResources().getColor(R.color.login_mobile_pw_edit_text_color)); } if (user_name_edit.length() == 13 && arg0.toString().length() >= 6 && verificate_code_edit.length() == 4) { // 用户手机号和密码、验证码的长度符合规则 submit_btn.setBackgroundColor( getResources().getColor(R.color.login_ensure_input_right_background)); } else { // 用户手机号和密码的长度不符合规则 submit_btn.setBackgroundColor( getResources().getColor(R.color.login_ensure_background)); } } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {} @Override public void afterTextChanged(Editable arg0) {} }); return registView; }