예제 #1
0
  protected void result(String headCode, RequestParams params, final DaoResult daoResult) {
    if (MyApplication.getInstence().isNetworkConnected()) {
      httpUtils.send(
          HttpMethod.POST,
          Tools.SERVER_URL,
          params,
          new RequestCallBack<String>() {

            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
              try {
                System.out.println("-------------body-------------" + responseInfo.result);
                JSONObject jsonObject = new JSONObject(responseInfo.result);
                JSONObject head = jsonObject.getJSONObject("head");
                JSONObject body = jsonObject.getJSONObject("body");

                String resultStr = body.getString("field");
                if (Constant.HEAD_SUCCESS.equals(head.getString("res_code")) && resultStr != null) {
                  daoResult.onSuccess(resultStr);
                } else {
                  daoResult.onFailure(head.getString("res_msg"));
                }
              } catch (Exception e) {
                e.printStackTrace();
                daoResult.onFailure(
                    MyApplication.getInstence()
                            .getApplicationContext()
                            .getString(R.string.unknown_error)
                        + e.toString());
              }
            }

            @Override
            public void onFailure(HttpException error, String msg) {
              if (msg.contains("SocketTimeoutException")
                  || msg.contains("ConnectTimeoutException")) {
                daoResult.onFailure("网络连接超时,请稍后重试");
              } else {
                daoResult.onFailure(msg);
              }
              System.out.println("是不是这啊" + msg);
            }
          });
    } else {
      daoResult.onFailure(
          MyApplication.getInstence()
              .getApplicationContext()
              .getString(R.string.network_isnot_available));
    }
  }
예제 #2
0
 public BaseDao() {
   if (httpUtils == null) {
     httpUtils = MyApplication.getInstence().getHttpUtils();
   }
   if (gson == null) {
     gson = new Gson();
   }
 }
예제 #3
0
  protected void result(
      String headCode, Map<String, Object> paramsMap, String filePath, final DaoResult daoResult) {
    File file = new File(filePath);
    if (!file.exists()) {
      daoResult.onFailure(
          MyApplication.getInstence().getApplicationContext().getString(R.string.file_not_found));
      return;
    }
    try {
      RequestParams params = generateRequestParams(headCode, paramsMap);
      byte[] bytes = FileUtils.toByteArray(filePath);
      // Bitmap bitmap = BitmapFactory.decodeFile(imgPath);
      // byte[] imageBytes = BitmapUtil.getByteArray(bitmap);
      String hashName =
          SHA1.getDigestOfString(bytes) + filePath.substring(filePath.lastIndexOf("."));
      params.addBodyParameter(hashName, new FileInputStream(file), file.length(), hashName);

      result(headCode, params, daoResult);
    } catch (Exception e) {
      e.printStackTrace();
      daoResult.onFailure(
          MyApplication.getInstence().getApplicationContext().getString(R.string.upload_error));
    }
  }