示例#1
0
  private void getHttpData() {
    RequestParams params = new RequestParams();
    String key = "msg/greet/text";
    try {
      params.addQueryStringParameter("cur_user", Conf.userID);
    } catch (Exception e) {
      // TODO: handle exception
    }

    params.addHeader("Authorization", PreferenceHelper.readString(context, "auth", "token"));
    CacheRequest.requestGET(
        context,
        key,
        params,
        key,
        0,
        new CacheRequestCallBack() {

          @Override
          public void onData(String json) {
            // TODO Auto-generated method stub
            try {
              baseJson = new Gson().fromJson(json, BaseJson.class);
              if (baseJson.getStatus().equals("200")) {
                helperAdapter = new TalkHelperAdapter(context, baseJson.getTexts());
                lv_helper.setAdapter(helperAdapter);
              }
            } catch (Exception e) {
              // TODO Auto-generated catch block
            } finally {
              if (mDialog != null) {
                mDialog.dismiss();
              }
            }
          }

          @Override
          public void onFail(HttpException e, String result, String json) {
            // TODO Auto-generated method stub
            if (mDialog != null) {
              mDialog.dismiss();
            }
            ExitManager.getScreenManager().intentLogin(context, e.getExceptionCode() + "");
          }
        });
  }
示例#2
0
  private void getHttpData(final int type) {
    int cache_time = 0;
    String key = "";
    RequestParams params = new RequestParams();
    try {
      params.addQueryStringParameter("cur_user", Conf.userID);
      params.addQueryStringParameter("gender", Conf.gender); // Conf.gender

      if (type == 1) {
        key = "show";
      } else {
        key = "show/praise";
        params.addQueryStringParameter("user_id", person.getUser_id());
        params.addQueryStringParameter("photo_id", person.getPhoto_id());
      }
    } catch (Exception e) {
      // TODO: handle exception
    }
    // Log.e("上传参数", params.toString());
    params.addHeader("Authorization", PreferenceHelper.readString(context, "auth", "token"));
    CacheRequest.requestGET(
        context,
        key,
        params,
        key,
        cache_time,
        new CacheRequestCallBack() {

          @Override
          public void onFail(HttpException e, String result, String json) {
            // TODO Auto-generated method stub
            if (mDialog != null) {
              mDialog.dismiss();
            }
            ExitManager.getScreenManager().intentLogin(context, e.getExceptionCode() + "");
            if (json.equals("")) {
              BasicUtils.toast(StringUtils.getResourse(R.string.str_net_register));
              return;
            }
          }

          @Override
          public void onData(String json) {
            // TODO Auto-generated method stub
            if (mDialog != null) {
              mDialog.dismiss();
            }
            if (json.equals("")) {
              return;
            }
            try {
              person = new Gson().fromJson(json, BaseJson.class);
              if (person.getStatus() != null && person.getStatus().equals("200")) {
                setView();
                if (type == 2) {
                  BasicUtils.toast(StringUtils.getResourse(R.string.str_intro_call));
                }
              }
            } catch (Exception e) {
              // TODO Auto-generated catch block
            }
          }
        });
    // kjh.get(url, params, new HttpCallBack() {
    //
    // @Override
    // public void onSuccess(Object obj) {
    // // TODO Auto-generated method stub
    //
    // try {
    // person = new Gson().fromJson(obj.toString(), BaseJson.class);
    // if (person.getStatus() != null
    // && person.getStatus().equals("200")) {
    // setView();
    // if (type == 2) {
    // ViewInject
    // .toast(getString(R.string.str_intro_call));
    // }
    // }
    // } catch (Exception e) {
    // // TODO Auto-generated catch block
    // } finally {
    // if (mDialog != null) {
    // mDialog.dismiss();
    // }
    // }
    //
    // }
    //
    // @Override
    // public void onLoading(long count, long current) {
    // // TODO Auto-generated method stub
    // }
    //
    // @Override
    // public void onFailure(Throwable t, int errorNo, String strMsg) {
    // // TODO Auto-generated method stub
    // if (mDialog != null) {
    // mDialog.dismiss();
    // }
    // ExitManager.getScreenManager().intentLogin(context,
    // StringUtils.httpRsponse(t.toString()));
    // }
    //
    // });
  }