| | |
| | | import com.yeshi.base.utils.BaseApiUtil; |
| | | import com.yeshi.base.utils.IsEmail; |
| | | import com.yeshi.base.utils.http.BasicTextHttpResponseHandler; |
| | | import com.yeshi.ec.base.R; |
| | | import com.yeshi.base.R; |
| | | |
| | | import org.apache.http.Header; |
| | | import org.json.JSONObject; |
| | |
| | | */ |
| | | |
| | | public class RegisterActivity extends BaseActivity implements |
| | | View.OnClickListener { |
| | | View.OnClickListener { |
| | | |
| | | private LinearLayout ll_login_content; |
| | | private ImageView iv_register_top; |
| | | private EditText et_email; |
| | | private EditText et_pwd; |
| | | private EditText et_verfication_code; |
| | | private TextView tv_obtain_verfication_code; |
| | | private CheckBox cb_user_agreement; |
| | | private TextView tv_confirm; |
| | | private LinearLayout ll_login_content; |
| | | private ImageView iv_register_top; |
| | | private EditText et_email; |
| | | private EditText et_pwd; |
| | | private EditText et_verfication_code; |
| | | private TextView tv_obtain_verfication_code; |
| | | private CheckBox cb_user_agreement; |
| | | private TextView tv_confirm; |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle arg0) { |
| | | super.onCreate(arg0); |
| | | setContentView(R.layout.activity_register); |
| | | iv_register_top = (ImageView) findViewById(R.id.iv_register_top); |
| | | et_email = (EditText) findViewById(R.id.et_name); |
| | | et_pwd = (EditText) findViewById(R.id.et_pwd); |
| | | et_verfication_code = (EditText) findViewById(R.id.et_verfication_code); |
| | | tv_obtain_verfication_code = (TextView) findViewById(R.id.tv_obtain_verfication_code); |
| | | cb_user_agreement = (CheckBox) findViewById(R.id.cb_user_agreement); |
| | | tv_confirm = (TextView) findViewById(R.id.tv_confirm); |
| | | ll_login_content = (LinearLayout) findViewById(R.id.ll_login_content); |
| | | @Override |
| | | protected void onCreate(Bundle arg0) { |
| | | super.onCreate(arg0); |
| | | setContentView(R.layout.activity_register); |
| | | iv_register_top = (ImageView) findViewById(R.id.iv_register_top); |
| | | et_email = (EditText) findViewById(R.id.et_name); |
| | | et_pwd = (EditText) findViewById(R.id.et_pwd); |
| | | et_verfication_code = (EditText) findViewById(R.id.et_verfication_code); |
| | | tv_obtain_verfication_code = (TextView) findViewById(R.id.tv_obtain_verfication_code); |
| | | cb_user_agreement = (CheckBox) findViewById(R.id.cb_user_agreement); |
| | | tv_confirm = (TextView) findViewById(R.id.tv_confirm); |
| | | ll_login_content = (LinearLayout) findViewById(R.id.ll_login_content); |
| | | |
| | | int w = View.MeasureSpec.makeMeasureSpec(0, |
| | | View.MeasureSpec.UNSPECIFIED); |
| | | int h = View.MeasureSpec.makeMeasureSpec(0, |
| | | View.MeasureSpec.UNSPECIFIED); |
| | | ll_login_content.measure(w, h); |
| | | int width = ll_login_content.getMeasuredWidth(); |
| | | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, |
| | | (int) (width * 0.434)); |
| | | params.gravity = Gravity.CENTER_HORIZONTAL; |
| | | iv_register_top.setLayoutParams(params); |
| | | int w = View.MeasureSpec.makeMeasureSpec(0, |
| | | View.MeasureSpec.UNSPECIFIED); |
| | | int h = View.MeasureSpec.makeMeasureSpec(0, |
| | | View.MeasureSpec.UNSPECIFIED); |
| | | ll_login_content.measure(w, h); |
| | | int width = ll_login_content.getMeasuredWidth(); |
| | | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, |
| | | (int) (width * 0.434)); |
| | | params.gravity = Gravity.CENTER_HORIZONTAL; |
| | | iv_register_top.setLayoutParams(params); |
| | | |
| | | et_email.addTextChangedListener(new TextWatcher() { |
| | | et_email.addTextChangedListener(new TextWatcher() { |
| | | |
| | | @Override |
| | | public void onTextChanged(CharSequence arg0, int arg1, int arg2, |
| | | int arg3) { |
| | | @Override |
| | | public void onTextChanged(CharSequence arg0, int arg1, int arg2, |
| | | int arg3) { |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void beforeTextChanged(CharSequence arg0, int arg1, |
| | | int arg2, int arg3) { |
| | | @Override |
| | | public void beforeTextChanged(CharSequence arg0, int arg1, |
| | | int arg2, int arg3) { |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void afterTextChanged(Editable arg0) { |
| | | // et_email.getText().toString() |
| | | if (!StringUtils.isEmpty(et_verfication_code.getText() |
| | | .toString()) |
| | | && !StringUtils.isEmpty(et_pwd.getText().toString()) |
| | | && !StringUtils.isEmpty(arg0.toString())) { |
| | | tv_confirm.setBackground(getResources().getDrawable( |
| | | R.drawable.shape_login2)); |
| | | } else { |
| | | tv_confirm.setBackground(getResources().getDrawable( |
| | | R.drawable.shape_login1)); |
| | | } |
| | | @Override |
| | | public void afterTextChanged(Editable arg0) { |
| | | // et_email.getText().toString() |
| | | if (!StringUtils.isEmpty(et_verfication_code.getText() |
| | | .toString()) |
| | | && !StringUtils.isEmpty(et_pwd.getText().toString()) |
| | | && !StringUtils.isEmpty(arg0.toString())) { |
| | | tv_confirm.setBackground(getResources().getDrawable( |
| | | R.drawable.shape_login2)); |
| | | } else { |
| | | tv_confirm.setBackground(getResources().getDrawable( |
| | | R.drawable.shape_login1)); |
| | | } |
| | | |
| | | if (!StringUtils.isEmpty(arg0.toString())) { |
| | | tv_obtain_verfication_code.setBackground(getResources() |
| | | .getDrawable(R.drawable.shape_login2)); |
| | | } else { |
| | | tv_obtain_verfication_code.setBackground(getResources() |
| | | .getDrawable(R.drawable.shape_login1)); |
| | | } |
| | | if (!StringUtils.isEmpty(arg0.toString())) { |
| | | tv_obtain_verfication_code.setBackground(getResources() |
| | | .getDrawable(R.drawable.shape_login2)); |
| | | } else { |
| | | tv_obtain_verfication_code.setBackground(getResources() |
| | | .getDrawable(R.drawable.shape_login1)); |
| | | } |
| | | |
| | | } |
| | | }); |
| | | et_verfication_code.addTextChangedListener(new TextWatcher() { |
| | | } |
| | | }); |
| | | et_verfication_code.addTextChangedListener(new TextWatcher() { |
| | | |
| | | @Override |
| | | public void onTextChanged(CharSequence arg0, int arg1, int arg2, |
| | | int arg3) { |
| | | @Override |
| | | public void onTextChanged(CharSequence arg0, int arg1, int arg2, |
| | | int arg3) { |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void beforeTextChanged(CharSequence arg0, int arg1, |
| | | int arg2, int arg3) { |
| | | @Override |
| | | public void beforeTextChanged(CharSequence arg0, int arg1, |
| | | int arg2, int arg3) { |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void afterTextChanged(Editable arg0) { |
| | | if (!StringUtils.isEmpty(et_email.getText().toString()) |
| | | && !StringUtils.isEmpty(et_pwd.getText().toString()) |
| | | && !StringUtils.isEmpty(arg0.toString())) { |
| | | tv_confirm.setBackground(getResources().getDrawable( |
| | | R.drawable.shape_login2)); |
| | | } else { |
| | | tv_confirm.setBackground(getResources().getDrawable( |
| | | R.drawable.shape_login1)); |
| | | } |
| | | @Override |
| | | public void afterTextChanged(Editable arg0) { |
| | | if (!StringUtils.isEmpty(et_email.getText().toString()) |
| | | && !StringUtils.isEmpty(et_pwd.getText().toString()) |
| | | && !StringUtils.isEmpty(arg0.toString())) { |
| | | tv_confirm.setBackground(getResources().getDrawable( |
| | | R.drawable.shape_login2)); |
| | | } else { |
| | | tv_confirm.setBackground(getResources().getDrawable( |
| | | R.drawable.shape_login1)); |
| | | } |
| | | |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | |
| | | et_pwd.addTextChangedListener(new TextWatcher() { |
| | | et_pwd.addTextChangedListener(new TextWatcher() { |
| | | |
| | | @Override |
| | | public void onTextChanged(CharSequence arg0, int arg1, int arg2, |
| | | int arg3) { |
| | | @Override |
| | | public void onTextChanged(CharSequence arg0, int arg1, int arg2, |
| | | int arg3) { |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void beforeTextChanged(CharSequence arg0, int arg1, |
| | | int arg2, int arg3) { |
| | | @Override |
| | | public void beforeTextChanged(CharSequence arg0, int arg1, |
| | | int arg2, int arg3) { |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void afterTextChanged(Editable arg0) { |
| | | if (!StringUtils.isEmpty(et_verfication_code.getText() |
| | | .toString()) |
| | | && !StringUtils.isEmpty(et_email.getText().toString()) |
| | | && !StringUtils.isEmpty(arg0.toString())) { |
| | | tv_confirm.setBackground(getResources().getDrawable( |
| | | R.drawable.shape_login2)); |
| | | } else { |
| | | tv_confirm.setBackground(getResources().getDrawable( |
| | | R.drawable.shape_login1)); |
| | | } |
| | | } |
| | | }); |
| | | @Override |
| | | public void afterTextChanged(Editable arg0) { |
| | | if (!StringUtils.isEmpty(et_verfication_code.getText() |
| | | .toString()) |
| | | && !StringUtils.isEmpty(et_email.getText().toString()) |
| | | && !StringUtils.isEmpty(arg0.toString())) { |
| | | tv_confirm.setBackground(getResources().getDrawable( |
| | | R.drawable.shape_login2)); |
| | | } else { |
| | | tv_confirm.setBackground(getResources().getDrawable( |
| | | R.drawable.shape_login1)); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | tv_obtain_verfication_code.setOnClickListener(this); |
| | | tv_confirm.setOnClickListener(this); |
| | | findViewById(R.id.tv_back).setOnClickListener(this); |
| | | findViewById(R.id.tv_user_agreement).setOnClickListener(this); |
| | | } |
| | | tv_obtain_verfication_code.setOnClickListener(this); |
| | | tv_confirm.setOnClickListener(this); |
| | | findViewById(R.id.tv_back).setOnClickListener(this); |
| | | findViewById(R.id.tv_user_agreement).setOnClickListener(this); |
| | | findViewById(R.id.tv_privacy).setOnClickListener(this); |
| | | } |
| | | |
| | | @Override |
| | | public void onClick(View v) { |
| | | int id = v.getId(); |
| | | if (id == R.id.tv_back) { |
| | | finish(); |
| | | } else if (id == R.id.tv_user_agreement) { |
| | | Intent intent = new Intent(RegisterActivity.this, |
| | | BrowserActivity.class); |
| | | intent.putExtra("url", getString(R.string.agreement)); |
| | | startActivity(intent); |
| | | } else if (id == R.id.tv_obtain_verfication_code) { |
| | | String email = et_email.getText().toString(); |
| | | if (StringUtils.isEmpty(email)) { |
| | | SingleToast.showToast(RegisterActivity.this, "请先输入邮箱账号"); |
| | | } else { |
| | | Matcher m = IsEmail.isEmailAddress().matcher(email); |
| | | if (m.matches()) { |
| | | getVerficationCode(email); |
| | | } else { |
| | | SingleToast.showToast(RegisterActivity.this, |
| | | "输入的邮箱账号有误,请查证!"); |
| | | return; |
| | | } |
| | | } |
| | | } else if (id == R.id.tv_confirm) { |
| | | String email1 = et_email.getText().toString(); |
| | | String pwd = et_pwd.getText().toString(); |
| | | String verficationCode = et_verfication_code.getText().toString(); |
| | | if (StringUtils.isEmpty(email1)) { |
| | | SingleToast.showToast(RegisterActivity.this, "请先输入邮箱账号"); |
| | | return; |
| | | } else { |
| | | Matcher m = IsEmail.isEmailAddress().matcher(email1); |
| | | if (!m.matches()) { |
| | | SingleToast.showToast(RegisterActivity.this, |
| | | "输入的邮箱账号有误,请查证!"); |
| | | return; |
| | | } |
| | | } |
| | | if (StringUtils.isEmpty(pwd)) { |
| | | SingleToast.showToast(RegisterActivity.this, "密码不能为空"); |
| | | return; |
| | | } |
| | | if (pwd.length() < 6) { |
| | | SingleToast.showToast(RegisterActivity.this, "密码长度不能低于6位"); |
| | | return; |
| | | } |
| | | if (StringUtils.isEmpty(verficationCode)) { |
| | | SingleToast.showToast(RegisterActivity.this, "验证码不能为空"); |
| | | return; |
| | | } |
| | | userRegister(); |
| | | } |
| | | } |
| | | @Override |
| | | public void onClick(View v) { |
| | | int id = v.getId(); |
| | | if (id == R.id.tv_back) { |
| | | finish(); |
| | | } else if (id == R.id.tv_user_agreement) { |
| | | Intent intent = new Intent(RegisterActivity.this, |
| | | BrowserActivity.class); |
| | | intent.putExtra("url", getString(R.string.agreement)); |
| | | startActivity(intent); |
| | | } else if (id == R.id.tv_privacy) { |
| | | Intent intent = new Intent(RegisterActivity.this, |
| | | BrowserActivity.class); |
| | | intent.putExtra("url", getString(R.string.privacy)); |
| | | startActivity(intent); |
| | | } else if (id == R.id.tv_obtain_verfication_code) { |
| | | String email = et_email.getText().toString(); |
| | | if (StringUtils.isEmpty(email)) { |
| | | SingleToast.showToast(RegisterActivity.this, "请先输入邮箱账号"); |
| | | } else { |
| | | Matcher m = IsEmail.isEmailAddress().matcher(email); |
| | | if (m.matches()) { |
| | | getVerficationCode(email); |
| | | } else { |
| | | SingleToast.showToast(RegisterActivity.this, |
| | | "输入的邮箱账号有误,请查证!"); |
| | | return; |
| | | } |
| | | } |
| | | } else if (id == R.id.tv_confirm) { |
| | | if (!cb_user_agreement.isChecked()) { |
| | | SingleToast.showToast(this, "选择同意用户协议与隐私政策后方可注册"); |
| | | return; |
| | | } |
| | | |
| | | private void userRegister() { |
| | | SharedPreferences sp = getSharedPreferences("user", |
| | | Context.MODE_PRIVATE); |
| | | final String uid = sp.getString("uid", ""); |
| | | BaseApiUtil.emailRegister(this, uid, et_email.getText().toString(), |
| | | et_pwd.getText().toString(), et_verfication_code.getText() |
| | | .toString(), "无名氏", new BasicTextHttpResponseHandler() { |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, |
| | | Header[] headers, JSONObject jsonObject) |
| | | throws Exception { |
| | | if (jsonObject.optBoolean("IsPost")) { |
| | | SingleToast.showToast(RegisterActivity.this, |
| | | "注册成功!"); |
| | | emailLogin(et_email.getText().toString(), et_pwd |
| | | .getText().toString(), uid); |
| | | } else { |
| | | SingleToast.showToast(RegisterActivity.this, |
| | | jsonObject.optString("Error") + ",注册失败!"); |
| | | } |
| | | } |
| | | String email1 = et_email.getText().toString(); |
| | | String pwd = et_pwd.getText().toString(); |
| | | String verficationCode = et_verfication_code.getText().toString(); |
| | | if (StringUtils.isEmpty(email1)) { |
| | | SingleToast.showToast(RegisterActivity.this, "请先输入邮箱账号"); |
| | | return; |
| | | } else { |
| | | Matcher m = IsEmail.isEmailAddress().matcher(email1); |
| | | if (!m.matches()) { |
| | | SingleToast.showToast(RegisterActivity.this, |
| | | "输入的邮箱账号有误,请查证!"); |
| | | return; |
| | | } |
| | | } |
| | | if (StringUtils.isEmpty(pwd)) { |
| | | SingleToast.showToast(RegisterActivity.this, "密码不能为空"); |
| | | return; |
| | | } |
| | | if (pwd.length() < 6) { |
| | | SingleToast.showToast(RegisterActivity.this, "密码长度不能低于6位"); |
| | | return; |
| | | } |
| | | if (StringUtils.isEmpty(verficationCode)) { |
| | | SingleToast.showToast(RegisterActivity.this, "验证码不能为空"); |
| | | return; |
| | | } |
| | | userRegister(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(int statusCode, Header[] headers, |
| | | String responseString, Throwable throwable) { |
| | | super.onFailure(statusCode, headers, responseString, |
| | | throwable); |
| | | SingleToast.showToast(RegisterActivity.this, |
| | | "注册失败,请重新注册"); |
| | | } |
| | | }); |
| | | } |
| | | private void userRegister() { |
| | | SharedPreferences sp = getSharedPreferences("user", |
| | | Context.MODE_PRIVATE); |
| | | final String uid = sp.getString("uid", ""); |
| | | BaseApiUtil.emailRegister(this, uid, et_email.getText().toString(), |
| | | et_pwd.getText().toString(), et_verfication_code.getText() |
| | | .toString(), "无名氏", new BasicTextHttpResponseHandler() { |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, |
| | | Header[] headers, JSONObject jsonObject) |
| | | throws Exception { |
| | | if (jsonObject.optBoolean("IsPost")) { |
| | | SingleToast.showToast(RegisterActivity.this, |
| | | "注册成功!"); |
| | | emailLogin(et_email.getText().toString(), et_pwd |
| | | .getText().toString(), uid); |
| | | } else { |
| | | SingleToast.showToast(RegisterActivity.this, |
| | | jsonObject.optString("Error") + ",注册失败!"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 注册成功后登陆,获取登录信息 |
| | | */ |
| | | /** |
| | | * Email登陆 |
| | | */ |
| | | private void emailLogin(String email, String pwd, String uid) { |
| | | BaseApiUtil.emailLogin(RegisterActivity.this, uid, email, pwd, |
| | | new BasicTextHttpResponseHandler() { |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, |
| | | Header[] headers, JSONObject jsonObject) |
| | | throws Exception { |
| | | if (jsonObject.optBoolean("IsPost")) { |
| | | SharedPreferences sp = getSharedPreferences("user", |
| | | MODE_PRIVATE); |
| | | SharedPreferences.Editor edit = sp.edit(); |
| | | edit.putString("portrait", jsonObject |
| | | .optJSONObject("Data") |
| | | .optString("Portrait")); |
| | | edit.putString("LoginUid", jsonObject |
| | | .getJSONObject("Data").getString("Id")); |
| | | edit.putString( |
| | | "name", |
| | | jsonObject.optJSONObject("Data").optString( |
| | | "NickName")); |
| | | edit.commit(); |
| | | SingleToast |
| | | .showToast(RegisterActivity.this, "登陆成功"); |
| | | Intent intent = new Intent(RegisterActivity.this, |
| | | PersonInfoActivity.class); |
| | | startActivity(intent); |
| | | finish(); |
| | | } else { |
| | | SingleToast |
| | | .showToast(RegisterActivity.this, "登陆失败"); |
| | | } |
| | | } |
| | | @Override |
| | | public void onFailure(int statusCode, Header[] headers, |
| | | String responseString, Throwable throwable) { |
| | | super.onFailure(statusCode, headers, responseString, |
| | | throwable); |
| | | SingleToast.showToast(RegisterActivity.this, |
| | | "注册失败,请重新注册"); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(int statusCode, Header[] headers, |
| | | String responseString, Throwable throwable) { |
| | | super.onFailure(statusCode, headers, responseString, |
| | | throwable); |
| | | SingleToast.showToast(RegisterActivity.this, "登陆失败"); |
| | | } |
| | | }); |
| | | /** |
| | | * 注册成功后登陆,获取登录信息 |
| | | */ |
| | | /** |
| | | * Email登陆 |
| | | */ |
| | | private void emailLogin(String email, String pwd, String uid) { |
| | | BaseApiUtil.emailLogin(RegisterActivity.this, uid, email, pwd, |
| | | new BasicTextHttpResponseHandler() { |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, |
| | | Header[] headers, JSONObject jsonObject) |
| | | throws Exception { |
| | | if (jsonObject.optBoolean("IsPost")) { |
| | | SharedPreferences sp = getSharedPreferences("user", |
| | | MODE_PRIVATE); |
| | | SharedPreferences.Editor edit = sp.edit(); |
| | | edit.putString("portrait", jsonObject |
| | | .optJSONObject("Data") |
| | | .optString("Portrait")); |
| | | edit.putString("LoginUid", jsonObject |
| | | .getJSONObject("Data").getString("Id")); |
| | | edit.putString( |
| | | "name", |
| | | jsonObject.optJSONObject("Data").optString( |
| | | "NickName")); |
| | | edit.commit(); |
| | | SingleToast |
| | | .showToast(RegisterActivity.this, "登陆成功"); |
| | | Intent intent = new Intent(RegisterActivity.this, |
| | | PersonInfoActivity.class); |
| | | startActivity(intent); |
| | | finish(); |
| | | } else { |
| | | SingleToast |
| | | .showToast(RegisterActivity.this, "登陆失败"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | @Override |
| | | public void onFailure(int statusCode, Header[] headers, |
| | | String responseString, Throwable throwable) { |
| | | super.onFailure(statusCode, headers, responseString, |
| | | throwable); |
| | | SingleToast.showToast(RegisterActivity.this, "登陆失败"); |
| | | } |
| | | }); |
| | | |
| | | Timer timer; |
| | | int timecount = 59; |
| | | } |
| | | |
| | | private void getVerficationCode(String email) { |
| | | timer = new Timer(); |
| | | timer.schedule(new MyTask(), 1000, 1000); |
| | | SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE); |
| | | String uid = sp.getString("uid", ""); |
| | | BaseApiUtil.getVerficationCode(RegisterActivity.this, uid, email, |
| | | new BasicTextHttpResponseHandler() { |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, |
| | | Header[] headers, JSONObject jsonObject) |
| | | throws Exception { |
| | | if (jsonObject.optBoolean("IsPost")) { |
| | | SingleToast.showToast(RegisterActivity.this, |
| | | "获取验证码成功,请打开邮箱查看!"); |
| | | } else { |
| | | SingleToast.showToast(RegisterActivity.this, |
| | | "获取验证码失败,请重新获取!"); |
| | | handler.sendEmptyMessage(1); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | Timer timer; |
| | | int timecount = 59; |
| | | |
| | | class MyTask extends TimerTask { |
| | | @Override |
| | | public void run() { |
| | | if (timecount > 0) { |
| | | handler.sendEmptyMessage(0); |
| | | } else { |
| | | handler.sendEmptyMessage(1); |
| | | } |
| | | } |
| | | } |
| | | private void getVerficationCode(String email) { |
| | | timer = new Timer(); |
| | | timer.schedule(new MyTask(), 1000, 1000); |
| | | SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE); |
| | | String uid = sp.getString("uid", ""); |
| | | BaseApiUtil.getVerficationCode(RegisterActivity.this, uid, email, |
| | | new BasicTextHttpResponseHandler() { |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, |
| | | Header[] headers, JSONObject jsonObject) |
| | | throws Exception { |
| | | if (jsonObject.optBoolean("IsPost")) { |
| | | SingleToast.showToast(RegisterActivity.this, |
| | | "获取验证码成功,请打开邮箱查看!"); |
| | | } else { |
| | | SingleToast.showToast(RegisterActivity.this, |
| | | "获取验证码失败,请重新获取!"); |
| | | handler.sendEmptyMessage(1); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | Handler handler = new Handler() { |
| | | @Override |
| | | public void handleMessage(Message msg) { |
| | | super.handleMessage(msg); |
| | | switch (msg.what) { |
| | | case 0: |
| | | tv_obtain_verfication_code.setClickable(false); |
| | | tv_obtain_verfication_code.setText("重新发送(" + timecount + "s)"); |
| | | timecount--; |
| | | break; |
| | | case 1: |
| | | timer.cancel(); |
| | | tv_obtain_verfication_code.setText("获取验证码"); |
| | | tv_obtain_verfication_code.setClickable(true); |
| | | timecount = 59; |
| | | break; |
| | | } |
| | | } |
| | | }; |
| | | class MyTask extends TimerTask { |
| | | @Override |
| | | public void run() { |
| | | if (timecount > 0) { |
| | | handler.sendEmptyMessage(0); |
| | | } else { |
| | | handler.sendEmptyMessage(1); |
| | | } |
| | | } |
| | | } |
| | | |
| | | Handler handler = new Handler() { |
| | | @Override |
| | | public void handleMessage(Message msg) { |
| | | super.handleMessage(msg); |
| | | switch (msg.what) { |
| | | case 0: |
| | | tv_obtain_verfication_code.setClickable(false); |
| | | tv_obtain_verfication_code.setText("重新发送(" + timecount + "s)"); |
| | | timecount--; |
| | | break; |
| | | case 1: |
| | | timer.cancel(); |
| | | tv_obtain_verfication_code.setText("获取验证码"); |
| | | tv_obtain_verfication_code.setClickable(true); |
| | | timecount = 59; |
| | | break; |
| | | } |
| | | } |
| | | }; |
| | | } |