Beispiel #1
0
  private void doGetAdList(final AsyncTaskPayload payload) {
    AdverRequest request = (AdverRequest) payload.getData()[0];

    String jsonStr = JSONHelper.objToJson(request);

    HttpEntity entity = new ByteArrayEntity(jsonStr.getBytes());
    final String url = NetworkHelper.executeUrl(ServiceConstants.SERVICE_AD);
    Log.i(TAG + " url: =====>", url);
    Log.i(TAG + " jsonStr: =====>", jsonStr);
    NetworkHelper.asyncHttpClient.post(
        mContext,
        url,
        entity,
        "application/json; charset=utf-8",
        new AsyncHttpResponseHandler() {
          @Override
          public void onSuccess(String content) {
            super.onSuccess(content);
            Log.i(TAG + " Response: =====>", content);
            BaseResponse response = null;
            response = NetworkHelper.doObject(url, content, AdverResponse.class);
            if (checkErrorResponse(payload, response, false)) {
              return;
            }
            if (response instanceof AdverResponse) {
              mAdList = ((AdverResponse) response).getData();
            }
            dismisDialog();
            mListener.onSuccess(payload.getTaskType());
          }

          @Override
          protected void handleFailureMessage(Throwable e, String responseBody) {
            err = responseBody;
            super.handleFailureMessage(e, responseBody);
          }

          @Override
          public void onFailure(Throwable error) {
            super.onFailure(error);
            if (StringUtils.isEmpty(err)) {
              onfailure(payload);
            } else {
              onfailures(payload, err);
            }
          }
        });
  }
Beispiel #2
0
  private void log(String message, Throwable e) {
    if (e != null) {
      Log.e(TAG, message, e);

    } else {
      Log.i(TAG, message);
    }
  }