예제 #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 initView() {
   myLoadingDialog = new MyLoadingDialog(getActivity(), R.style.custom_dialog);
   activity = (MainActivity) getActivity();
   news_tital = (TextView) view.findViewById(R.id.news_tital);
   news_list = (ListView) view.findViewById(R.id.news_list);
   gold_button = (Button) view.findViewById(R.id.gold_button);
   world_button = (Button) view.findViewById(R.id.world_button);
   news_list = (ListView) view.findViewById(R.id.news_list);
   webView = (WebView) view.findViewById(R.id.web_view);
   webView.setBackgroundColor(getActivity().getResources().getColor(R.color.forgettextcolor));
   webView.getSettings().setJavaScriptEnabled(true);
   webView.getSettings().setBuiltInZoomControls(true);
   webView.getSettings().setUseWideViewPort(true);
   webView.getSettings().setLoadWithOverviewMode(true);
   webView.getSettings().setDomStorageEnabled(true);
   webView.getSettings().setDefaultFontSize(Util.dip2px(getActivity(), 24));
   webView.getSettings().setSupportZoom(true);
   webView.setWebViewClient(new WebViewClient());
   settab(1);
 }
예제 #3
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) {}
            });
  }