예제 #1
0
  // 解析Timeline接口返回的数据
  private void handlePostExecute(String result, int type) {
    if (!isNetworkConnected(getActivity())) {
      Util.showToast(getActivity(), "没有可用网络,请检查网络设置~");
      listView.onRefreshComplete();
    } else if (result == "") {
      Util.showToast(getActivity(), "网络开小差了,不如再试试吧~");
      listView.onRefreshComplete();
    } else {
      LinkedList<PostBean> postBeans = PostBean.parseBabietaTimeline(result, getActivity());
      if (type == 0) {
        listPostAdapter.clearPost(); // 上拉刷新,清空原来的数据
        listPostAdapter.appendPost(postBeans);
        listPostAdapter.sortPost();

        saveTimeline();
      } else { // 下拉刷新,直接添加数据
        listPostAdapter.appendPost(postBeans);
        listPostAdapter.sortPost();
      }
      listPostAdapter.notifyDataSetInvalidated();
      TextView textView = (TextView) pageView.findViewById(R.id.vp_main_text);
      if (listPostAdapter.getCount() == 0) {
        textView.setText("还没有内容,下拉刷新看看~");
      } else {
        textView.setText("新闻列表");
        textView.setVisibility(View.GONE);
      }
      listView.onRefreshComplete();
    }
  }
예제 #2
0
  // 网络读取Focus内容
  private boolean requestForFocus() {
    if (!isNetworkConnected(getActivity())) {
      Util.showToast(getActivity(), "没有可用网络,请检查网络设置~");
      return false;
    } else {
      JSONObject jsonRequest = null;
      String url = ApiUrl.BABIETA_BASE_URL + ApiUrl.BABIETA_CONTENT_LIST + "?on_focus=true&limit=5";
      JsonObjectRequest request =
          new JsonObjectRequest(
              url,
              jsonRequest,
              new Listener<JSONObject>() {
                @Override
                public void onSuccess(JSONObject response) {
                  try {
                    if (response.has("status") && response.getInt("status") == 0) {
                      // 先清空
                      LinkedList<PostBean> temp = new LinkedList<PostBean>();
                      pageCarouselAdapter.setPostBeans(temp);
                      pageCarouselAdapter.notifyDataSetChanged();
                      // 再读取内容
                      String result = response.toString();
                      focusData = PostBean.parseSection(result, getActivity());
                      pageCarouselAdapter.setPostBeans(focusData);
                      pageCarouselAdapter.notifyDataSetChanged();
                      indicatorLayout.setViewPage(viewPager); // 设置focus右下角的指示器
                      focusLoadedFlag = true;
                    } else {
                      // 接口出错
                    }
                  } catch (JSONException e) {
                    e.printStackTrace();
                  }
                }

                @Override
                public void onError(NetroidError error) {
                  Util.showToast(getActivity(), "网络开小差了,不如再试试吧~");
                }
              });
      // 设置请求标识,这个标识可用于终止该请求时传入的Key
      request.setTag("LOAD_FOCUS");
      Netroid.addRequest(request);
    }
    return true;
  }
예제 #3
0
 @Override
 public void onResume() {
   super.onResume();
   Util.setStatusBarColor(getActivity());
   // 设置标题
   TextView titleTextView = (TextView) getActivity().findViewById(R.id.header_textview);
   titleTextView.setText("今日新闻");
   // 改变ViewPager高度按16:9
   viewPager.post(
       new Runnable() {
         @Override
         public void run() {
           int width = viewPager.getWidth();
           if (width == 0) return;
           int height = width * 9 / 16;
           viewPager.setLayoutParams(new RelativeLayout.LayoutParams(width, height));
         }
       });
   // 每隔5秒钟切换一张图片
   startViewPagerTask();
 }
예제 #4
0
 public void handleFocusClick(int index) {
   PostBean postBean = focusData.get(index);
   Activity activity = getActivity();
   Util.handleItemClick(activity, postBean);
 }