PageRenderTime 3826ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 1ms

/app/src/main/java/com/uprint/android_pack/cloudprint4androidmanager/activity/CPRegisteActivity.java

https://gitlab.com/zhangxiaang/CloudPrint4AndroidManager
Java | 134 lines | 115 code | 15 blank | 4 comment | 13 complexity | ad2c0fd321190cb4729f8ab0e7c31114 MD5 | raw file
  1. package com.uprint.android_pack.cloudprint4androidmanager.activity;
  2. import android.content.Intent;
  3. import android.os.Bundle;
  4. import android.support.v7.widget.Toolbar;
  5. import android.text.TextUtils;
  6. import android.view.View;
  7. import android.widget.TextView;
  8. import android.widget.Toast;
  9. import com.alibaba.fastjson.JSONObject;
  10. import com.dd.processbutton.FlatButton;
  11. import com.rengwuxian.materialedittext.MaterialEditText;
  12. import com.uprint.android_pack.cloudprint4androidmanager.CPBaseActivity;
  13. import com.uprint.android_pack.cloudprint4androidmanager.R;
  14. import com.uprint.android_pack.cloudprint4androidmanager.network.ICallBack;
  15. import com.uprint.android_pack.cloudprint4androidmanager.network.NetValue;
  16. import com.uprint.android_pack.cloudprint4androidmanager.network.biz.CommonPostBiz;
  17. import com.uprint.android_pack.cloudprint4androidmanager.utils.ActivityUtils;
  18. import com.uprint.android_pack.cloudprint4androidmanager.utils.CountDownButtonHelper;
  19. import com.uprint.android_pack.cloudprint4androidmanager.utils.RegexUtils;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. /**
  23. * Created by zhangxiaang on 15/10/8.
  24. */
  25. public class CPRegisteActivity extends CPBaseActivity {
  26. public static final String TAG = "CPRegisteActivity";
  27. MaterialEditText phoneAccount;
  28. MaterialEditText oauthCode;
  29. FlatButton oauthBtn;
  30. FlatButton secondBtn;
  31. public String phString;
  32. private TextView title;
  33. private Map<String, String> params_map;
  34. private CountDownButtonHelper helper;
  35. private String oauth_code;
  36. private boolean flag;
  37. @Override
  38. public void onCreate(Bundle savedInstanceState) {
  39. super.onCreate(savedInstanceState);
  40. setContentView(R.layout.cp_registe);
  41. flag = getIntent().getBooleanExtra("flag", false);
  42. init();
  43. }
  44. public void init() {
  45. mToolbar = (Toolbar) findViewById(R.id.toolbar);
  46. mToolbar.setNavigationIcon(R.drawable.goback);
  47. title = (TextView) mToolbar.findViewById(R.id.toolbar_title);
  48. if (flag) {
  49. title.setText("忘记密码");
  50. } else title.setText("获取验证码");
  51. setSupportActionBar(mToolbar);
  52. if (getSupportActionBar() != null) {
  53. getSupportActionBar().setHomeButtonEnabled(false);
  54. getSupportActionBar().setDisplayShowHomeEnabled(true);
  55. getSupportActionBar().setDisplayShowTitleEnabled(false);
  56. }
  57. phoneAccount = (MaterialEditText) findViewById(R.id.newAccounts);
  58. oauthCode = (MaterialEditText) findViewById(R.id.oauthCode);
  59. oauthBtn = (FlatButton) findViewById(R.id.oauthBtn);
  60. secondBtn = (FlatButton) findViewById(R.id.regisBtn);
  61. if (flag) {
  62. secondBtn.setText("修改密码");
  63. }
  64. helper = new CountDownButtonHelper(oauthBtn, "发送验证码", 60, 1);
  65. params_map = new HashMap<>();
  66. }
  67. public void route(View view) {
  68. int resId = view.getId();
  69. switch (resId) {
  70. case R.id.oauthBtn:
  71. phoneAccount.validateWith(RegexUtils.phone());
  72. if (!TextUtils.isEmpty(phString = phoneAccount.getText().toString())) {
  73. params_map.put("username", phString);
  74. CommonPostBiz biz = new CommonPostBiz(this);
  75. biz.isOauth(true);
  76. biz.request(new ICallBack() {
  77. @Override
  78. public void displayResult(int status, Object... params) {
  79. if (params[0] instanceof JSONObject) {
  80. JSONObject jsonObject = (JSONObject) params[0];
  81. if (jsonObject.getInteger("error") == -1) {
  82. Toast.makeText(CPRegisteActivity.this, "该手机号已经注册过", Toast.LENGTH_SHORT).show();
  83. }
  84. }
  85. }
  86. }, NetValue.GET_SMS_CODE(), params_map);
  87. helper.setOnFinishListener(new CountDownButtonHelper.OnFinishListener() {
  88. @Override
  89. public void finish() {
  90. //do nothing
  91. }
  92. });
  93. helper.start();
  94. } else {
  95. Toast.makeText(this, "手机不能为空", Toast.LENGTH_SHORT).show();
  96. }
  97. break;
  98. case R.id.regisBtn:
  99. phString = phoneAccount.getText().toString().replace(" ", "").replace("-", "");
  100. if (!TextUtils.isEmpty(oauth_code = oauthCode.getText().toString())) {
  101. mIntent = new Intent(this, CPSecondRegisteActivity.class);
  102. mIntent.putExtra("cellphone", phString);
  103. mIntent.putExtra("oauthCode", oauth_code);
  104. mIntent.putExtra("flag", flag);
  105. ActivityUtils.startActivity(this, mIntent);
  106. } else {
  107. Toast.makeText(this, "验证码不能为空", Toast.LENGTH_SHORT).show();
  108. }
  109. break;
  110. default:
  111. break;
  112. }
  113. }
  114. @Override
  115. protected void onDestroy() {
  116. helper.stop();
  117. super.onDestroy();
  118. }
  119. }