Esempio n. 1
0
  private void requestDoctor(String studyId) {
    // TODO Auto-generated method stub
    JSONObject jsonObject = new JSONObject();
    try {
      jsonObject.put("SubjectType", "1");
      jsonObject.put("UserID", userModel.getID());
      jsonObject.put("UserName", userModel.getUserName());
      jsonObject.put("UserSex", userModel.getUserSex());
      jsonObject.put("Age", userModel.getAge());
      jsonObject.put("HeadPicture", userModel.getHeadPicture());
      jsonObject.put("RelationShip", "1");
      jsonObject.put("StudyID", studyId);
      jsonObject.put("AttachPics", null);
      jsonObject.put("BodyContent", null);
      HttpClient.post(
          Constants.STARTCHAT_URl,
          jsonObject.toString(),
          new RequestCallBack<String>() {
            @Override
            public void onStart() {
              // TODO Auto-generated method stub
              super.onStart();
              myProgressDialog = new MyProgressDialog(context);
              myProgressDialog.setMessage("正在请求...");
              myProgressDialog.show();
            }

            @Override
            public void onSuccess(ResponseInfo<String> arg0) {
              // TODO Auto-generated method stub
              LogUtil.i(TAG, arg0.result);
              myProgressDialog.dismiss();
              analyzeJson(arg0.result);
            }

            @Override
            public void onFailure(HttpException arg0, String arg1) {
              // TODO Auto-generated method stub
              myProgressDialog.dismiss();
            }
          });

    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Esempio n. 2
0
  /** 将修改后的信息上传服务器 */
  public void requestModifyInfo() {

    try {

      // 向服务器发送请求
      // RequestParams params = new RequestParams();
      // params.addHeader(Constants.TOKEN,
      // SharedPrefsUtil.getValue(Constants.TOKEN, ""));

      JSONObject jsonParam = new JSONObject();
      jsonParam.put("photo", "");
      jsonParam.put("fileName", "");
      String userJson = SharedPrefsUtil.getValue(Constants.USERMODEL, "");
      UserModel userModel = new Gson().fromJson(userJson, UserModel.class);
      // String userSex = "";
      // if(userModel.getUserSex().equals("男")){
      // userSex = "Man";
      // }else if(userModel.getUserSex().equals("女")){
      // userSex ="Woman";
      // }
      jsonParam.put("sex", userModel.getUserSex());

      if (title.equals("姓名")) {

        jsonParam.put("Name", et.getText().toString().trim());

        jsonParam.put("IDcard", userModel.getIDcard());

        jsonParam.put("UserAccount", userModel.getUserAccount());

      } else if (title.equals("身份证号")) {
        jsonParam.put("Name", userModel.getUserName());

        jsonParam.put("IDcard", et.getText().toString().trim());

        jsonParam.put("UserAccount", userModel.getUserAccount());

      } else {
        jsonParam.put("Name", userModel.getUserName());

        jsonParam.put("IDcard", userModel.getIDcard());

        jsonParam.put("UserAccount", et.getText().toString().trim());
      }

      // params.addBodyParameter("param", jsonParam.toString());

      LogUtil.i("=====", "===" + userModel.getUserSex() + "===");
      LogUtil.i("=====", jsonParam.toString());

      // params.setBodyEntity(new StringEntity(jsonParam.toString()));
      // HttpUtils httpUtils = new HttpUtils();
      HttpClient.post(
          Constants.MODIFYINFO_URl,
          jsonParam.toString(),
          new RequestCallBack<String>() {

            @Override
            public void onStart() {
              Log.i("HttpUtil", "onStart");
            }

            @Override
            public void onLoading(long total, long current, boolean isUploading) {
              Log.i("HttpUtil", "onLoading");
            }

            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
              Log.i("HttpUtil", "onSuccess");

              Log.i("HttpUtil", "onSuccess===" + responseInfo.result.toString());
              ToastUtil.showMessage("修改成功");

              // 存本地
              UserModel userModel =
                  new Gson()
                      .fromJson(SharedPrefsUtil.getValue(Constants.USERMODEL, ""), UserModel.class);
              if (title.equals("姓名")) {
                // 存入修改后的姓名
                userModel.setUserName(et.getText().toString().trim());

              } else if (title.equals("身份证号")) {
                // 存入修改后的身份证号
                userModel.setIDcard(et.getText().toString().trim());

                // 存入年龄
                userModel.setAge(MathUtils.calculateAge(et.getText().toString().trim()));

                // SharedPrefsUtil.putValue(Constants.USERMODEL,
                // userModel.toString());
              } else {
                // 存入修改后的手机号
                // userModel.setMobilephone(et.getText().toString()
                // .trim());

              }

              SharedPrefsUtil.putValue(Constants.USERMODEL, userModel.toString());

              Log.i("HttpUtil", "存入手机");

              finish();
            }

            @Override
            public void onFailure(HttpException error, String msg) {
              Log.i("HttpUtil", "onFailure===" + msg);
              LogUtil.i("===============", error.toString());
              ToastUtil.showMessage("网络获取失败");
              LogUtil.i("=================", Constants.MODIFYINFO_URl);
              // testTextView.setText(error.getExceptionCode() +
              // ":" +
              // msg);
            }
          });

    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }