コード例 #1
0
  private void getlist(final String id) {
    if (Util.netFailure > 2) {
      Util.netFailure = 0;
      if (myLoadingDialog.isShowing()) {
        myLoadingDialog.dismiss();
      }
      activity.showToast("连接服务器失败", 1000, false);
      return;
    }
    myLoadingDialog.show();
    ReqGetNewsList reqGetNewsList = new ReqGetNewsList();
    reqGetNewsList.setRequestType(id);
    reqGetNewsList.setToken(Util.getStoredString(getActivity(), Util.token, null));
    MyHttpManager.getInstance(getActivity())
        .getNewsList(
            reqGetNewsList,
            new AsyncHttpResponseHandler() {
              @Override
              public void onSuccess(int i, Header[] headers, byte[] bytes) {
                Util.netFailure = 0;
                String jsonResult = new String(bytes);
                Log.i("ping_tai-->", jsonResult);
                try {
                  final ResNewsList resNewsList =
                      (ResNewsList) Util.coverClassFromJson(jsonResult, ResNewsList.class);
                  if (Util.isTrue(resNewsList.getSuccess())) {
                    activity.runOnUiThread(
                        new Runnable() {
                          @Override
                          public void run() {
                            adapter = new NewsAdapter(getActivity(), resNewsList.getContent());
                            bean = (NewsBean) adapter.getItem(0);
                            news_list.setAdapter(adapter);
                            if (isNotice) {
                              getNotice();
                            } else {
                              getAnalyze();
                            }
                          }
                        });
                  }
                } catch (Exception e) {
                  activity.showToast("网络错误", 1500, false);
                } finally {
                  if (myLoadingDialog.isShowing()) {
                    myLoadingDialog.dismiss();
                  }
                }
              }

              @Override
              public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                // activity.showToast("连接服务器失败",1500,false);
                Util.netFailure = Util.netFailure + 1;
                getlist(id);
              }
            });
  }
コード例 #2
0
  private void getAnalyze() {
    ReqAnalyze reqAnalyze = new ReqAnalyze();
    reqAnalyze.setId(bean.getID());
    reqAnalyze.setToken(Util.getStoredString(getActivity(), Util.token, null));
    MyHttpManager.getInstance(getActivity())
        .getAnalyzeDetail(
            reqAnalyze,
            new AsyncHttpResponseHandler() {
              @Override
              public void onSuccess(int i, Header[] headers, byte[] bytes) {
                String jsonResult = new String(bytes);
                Log.i("contacst", jsonResult);
                try {
                  ResNotice resNotice =
                      (ResNotice) Util.coverClassFromJson(jsonResult, ResNotice.class);
                  if (Util.isTrue(resNotice.getSuccess())) {
                    news_tital.setText(bean.getTitle());
                    webView.loadDataWithBaseURL(
                        null,
                        "<center>"
                            + Util.CSS_STYLE
                            + resNotice.getContent().getMsgBody()
                            + "</center>",
                        "text/html",
                        "utf-8",
                        null);
                  }
                } catch (Exception e) {

                }
              }

              @Override
              public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {}
            });
  }