PageRenderTime 1617ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://gitlab.com/zhangxiaang/CloudPrint4AndroidManager
Java | 116 lines | 100 code | 13 blank | 3 comment | 14 complexity | a38d5202ae845f1aa2d7a819433c41b5 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.util.Log;
  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.uprint.android_pack.cloudprint4androidmanager.CPBaseActivity;
  12. import com.uprint.android_pack.cloudprint4androidmanager.R;
  13. import com.uprint.android_pack.cloudprint4androidmanager.network.ICallBack;
  14. import com.uprint.android_pack.cloudprint4androidmanager.network.NetValue;
  15. import com.uprint.android_pack.cloudprint4androidmanager.network.biz.CommonPostBiz;
  16. import com.uprint.android_pack.cloudprint4androidmanager.utils.ActivityUtils;
  17. import com.uprint.android_pack.cloudprint4androidmanager.utils.MD5;
  18. import com.uprint.android_pack.cloudprint4androidmanager.utils.SharedPreferenceUtil;
  19. import com.rengwuxian.materialedittext.MaterialEditText;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. /**
  23. * Created by zhangxiaang on 15/10/10.
  24. */
  25. public class CPSecondRegisteActivity extends CPBaseActivity {
  26. public static final String TAG = "CPSecondRegisteActivity";
  27. private TextView title;
  28. MaterialEditText password_1;
  29. MaterialEditText password_2;
  30. FlatButton registeBtn;
  31. private String phNumber;
  32. private String oauthCode;
  33. private boolean flag;
  34. private Map<String, String> params_map;
  35. @Override
  36. public void onCreate(Bundle savedInstanceState) {
  37. super.onCreate(savedInstanceState);
  38. setContentView(R.layout.cp_registe_2);
  39. phNumber = getIntent().getStringExtra("cellphone");
  40. oauthCode = getIntent().getStringExtra("oauthCode");
  41. flag = getIntent().getBooleanExtra("flag", false);
  42. init();
  43. }
  44. public void init() {
  45. params_map = new HashMap<>();
  46. mToolbar = (Toolbar) findViewById(R.id.toolbar);
  47. mToolbar.setNavigationIcon(R.drawable.goback);
  48. title = (TextView) mToolbar.findViewById(R.id.toolbar_title);
  49. title.setText("确认密码");
  50. setSupportActionBar(mToolbar);
  51. if (getSupportActionBar() != null) {
  52. getSupportActionBar().setHomeButtonEnabled(false);
  53. getSupportActionBar().setDisplayShowHomeEnabled(false);
  54. getSupportActionBar().setDisplayShowTitleEnabled(false);
  55. }
  56. password_1 = (MaterialEditText) findViewById(R.id.newpaswd);
  57. password_2 = (MaterialEditText) findViewById(R.id.comfirm_paswd);
  58. registeBtn = (FlatButton) findViewById(R.id.registe);
  59. if (flag) {
  60. registeBtn.setText("提交新密码");
  61. } else registeBtn.setText("注册");
  62. }
  63. public void routes(View view) {
  64. int resId = view.getId();
  65. switch (resId) {
  66. case R.id.registe:
  67. if (!password_1.getText().toString().equals(password_2.getText().toString())) {
  68. Toast.makeText(CPSecondRegisteActivity.this, "密码不一致", Toast.LENGTH_SHORT).show();
  69. break;
  70. }
  71. if (phNumber.trim().length() != 0 && oauthCode.trim().length() != 0) {
  72. params_map.put("username", phNumber);
  73. params_map.put("password", MD5.getMD5(password_1.getText().toString()));
  74. params_map.put("smsCode", oauthCode);
  75. CommonPostBiz biz = new CommonPostBiz(this);
  76. biz.request(new ICallBack() {
  77. @Override
  78. public void displayResult(int status, Object... params) {
  79. JSONObject result = (JSONObject) params[0];
  80. Log.e(TAG, result.toString());
  81. Log.e(TAG, params_map.toString());
  82. if (result.getInteger("error") == 0) {
  83. Toast.makeText(CPSecondRegisteActivity.this, flag ? "修改成功" : "注册成功", Toast.LENGTH_SHORT).show();
  84. SharedPreferenceUtil.storage_Token(getApplicationContext(), result.getJSONArray("results").getJSONObject(0).getString("token"));
  85. mIntent = new Intent(CPSecondRegisteActivity.this, CPLoginActivity.class);
  86. ActivityUtils.startActivity(CPSecondRegisteActivity.this, mIntent);
  87. }
  88. if (result.getInteger("error") == -1) {
  89. Toast.makeText(CPSecondRegisteActivity.this, result.getString("msg"), Toast.LENGTH_SHORT).show();
  90. }
  91. }
  92. }, flag ? NetValue.POST_PASSWORD() : NetValue.GET_SIGN_UP(), params_map);
  93. }
  94. break;
  95. default:
  96. break;
  97. }
  98. }
  99. @Override
  100. protected void onDestroy() {
  101. super.onDestroy();
  102. }
  103. }