コード例 #1
0
 /**
  * 获取验证码
  *
  * @throws JSONException
  */
 private void getRegistCode() throws JSONException {
   final ProgressHUD mProgressHUD;
   mProgressHUD =
       ProgressHUD.show(
           this, getResources().getString(R.string.prompt_progress_get_code), true, false, null);
   String url = NetInterface.HOST + NetInterface.METHON_VERIFY_CODE_REGIST_GEN;
   PostUser postEntity = new PostUser();
   postEntity.setToken(Constants.TOKEN_VALUE);
   postEntity.setMobile(etNum.getText().toString());
   String postString = new Gson().toJson(postEntity, new TypeToken<PostUser>() {}.getType());
   JSONObject postJson = new JSONObject(postString);
   JsonObjectRequest getCategoryReq =
       new JsonObjectRequest(
           Request.Method.POST,
           url,
           postJson,
           new Response.Listener<JSONObject>() {
             @Override
             public void onResponse(JSONObject jsonObject) {
               DebugFlags.logD(TAG, jsonObject.toString());
               Gson gson = new Gson();
               codeBindNum = etNum.getText().toString();
               etNum.setEnabled(true);
               try {
                 if (jsonObject
                     .getString(Constants.RESULT_STATUS_FIELD)
                     .equals(Constants.RESULT_SUCCEED_STATUS)) {
                   JSONObject jsonCode = jsonObject.getJSONObject(Constants.RESULT_CONTENT_FIELD);
                   verifyCode = jsonCode.getString("code");
                   btnGetCode.setClickable(false); // 关闭按钮点击
                   refreshSecond();
                 } else {
                   Toast.makeText(
                           LoginFastActivity.this,
                           getResources().getString(R.string.prompt_verify_code_get_faild),
                           Toast.LENGTH_SHORT)
                       .show();
                 }
               } catch (JSONException e) {
                 e.printStackTrace();
               }
               mProgressHUD.dismiss();
             }
           },
           new Response.ErrorListener() {
             @Override
             public void onErrorResponse(VolleyError volleyError) {
               etNum.setEnabled(true);
               mProgressHUD.dismiss();
             }
           });
   NetController.getInstance(this).addToRequestQueue(getCategoryReq, TAG);
 }
コード例 #2
0
  /** 登录 */
  private void loginFast() throws Exception {

    final ProgressHUD mProgressHUD;
    mProgressHUD =
        ProgressHUD.show(
            this, getResources().getString(R.string.prompt_progress_login), true, false, null);
    String url = NetInterface.HOST + NetInterface.METHON_LOGIN_FAST;
    PostUser postEntity = new PostUser();
    postEntity.setToken(Constants.TOKEN_VALUE);
    postEntity.setMobile(etNum.getText().toString());
    String postString = new Gson().toJson(postEntity, new TypeToken<PostUser>() {}.getType());
    JSONObject postJson = new JSONObject(postString);
    JsonObjectRequest getCategoryReq =
        new JsonObjectRequest(
            Request.Method.POST,
            url,
            postJson,
            new Response.Listener<JSONObject>() {
              @Override
              public void onResponse(JSONObject jsonObject) {
                DebugFlags.logD(TAG, jsonObject.toString());

                Gson gson = new Gson();
                try {
                  if (jsonObject
                      .getString(Constants.RESULT_STATUS_FIELD)
                      .equals(Constants.RESULT_SUCCEED_STATUS)) {
                    JSONObject jsonResult =
                        jsonObject.getJSONObject(Constants.RESULT_CONTENT_FIELD);
                    UserInfoModel userInfoModel = new UserInfoModel();
                    userInfoModel =
                        gson.fromJson(
                            jsonResult.getString("user"),
                            new TypeToken<UserInfoModel>() {}.getType());
                    DBHelper.getInstance(getApplicationContext()).saveUserInfo(userInfoModel);
                    TempDataManager.getInstance(getApplicationContext())
                        .setCurrentUid(userInfoModel.getUid());
                    DebugFlags.logD(TAG, userInfoModel.getTel());
                    startActivity(new Intent(LoginFastActivity.this, MainActivity.class));
                    finish();
                  } else {
                    if (TextUtils.isEmpty(jsonObject.getString(Constants.RESULT_ERROR_FIELD))) {
                      Toast.makeText(
                              LoginFastActivity.this,
                              jsonObject.getString(Constants.RESULT_ERROR_FIELD),
                              Toast.LENGTH_SHORT)
                          .show();
                    }
                  }
                } catch (JSONException e) {
                  e.printStackTrace();
                }

                mProgressHUD.dismiss();
              }
            },
            new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError volleyError) {
                mProgressHUD.dismiss();
              }
            });
    NetController.getInstance(getApplicationContext()).addToRequestQueue(getCategoryReq, TAG);
  }