@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { getActivity().registerReceiver(receiver, receiverFilter); View root = inflater.inflate(R.layout.activity_index, container, false); FrameLayout layerLayout = (FrameLayout) root.findViewById(R.id.layer); layerLayout.setOnTouchListener(controller); barTitle = (TitleBar) root.findViewById(R.id.titlebar); barTitle.getTitle().setText(R.string.activity_title); barTitle.getLeftButton().setOnClickListener(controller); barTitle.getLeftButton().setBackgroundResource(R.drawable.nav_btnselector); barTitle.getRightButton().setText(R.string.search); barTitle.getRightButton().setVisibility(View.VISIBLE); barTitle.getRightButton().setOnClickListener(controller); circleMsgTip(); pager = (IndexViewPager) root.findViewById(R.id.pager); pager.setPagerViewLayoutParams(); pager.setVisibility(View.GONE); btnHuWai = root.findViewById(R.id.huwai); btnHuWai.setOnClickListener(controller); btnShiNei = root.findViewById(R.id.shinei); btnShiNei.setOnClickListener(controller); // btnLvYou = root.findViewById(R.id.lvyou); // btnLvYou.setOnClickListener(controller); btnXianShang = root.findViewById(R.id.xianshang); btnXianShang.setOnClickListener(controller); fujin = (ImageView) root.findViewById(R.id.fujin); fujin.setOnClickListener(controller); controllerFloat = new FloatWindowController(layerLayout); String res = App.CACHE.read(CACHE_KEY); if (!TextUtils.isEmpty(res)) { String today = res.substring(0, 8); res = res.substring(8); if (today.equals(controller.today.toString())) { try { pager.onSuccess(res); pager.notifyDataSetChanged(); } catch (Exception e) { ELog.e("Exception:" + e.getMessage()); e.printStackTrace(); } } } return root; }
void obtainList() { String cache = App.CACHE.read(CACHE_KEY); if (!TextUtils.isEmpty(cache)) { try { processData(cache, true); } catch (JSONException e) { ELog.e("Exception:" + e.getMessage()); e.printStackTrace(); } } DefaultHttpCallback callback = new DefaultHttpCallback( new DefaultHttpCallback.EventListener() { @Override public void onSuccess(HttpResult result) { try { String res = result.getResult(); ELog.i(res); processData(res, false); App.CACHE.save(CACHE_KEY, res); } catch (Exception e) { ELog.e("Exception:" + e.getMessage()); e.printStackTrace(); } } @Override public void onForceClose(ExceptionHttpResult result) {} @Override public void onException(ExceptionHttpResult result) {} }); HttpRequest req = new HttpRequest(Constants.GET_MV_PREFIX, null, HttpRequest.Method.GET, callback); App.THREAD.execute(req); }