コード例 #1
0
 @Override
 public View onCreateView(
     LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   View root = inflater.inflate(R.layout.fg_news, null);
   initView(root);
   dispatcher = new NetworkDispatcher(new Handler());
   JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET, MURL.getReadURL());
   request.params.add(new BasicNameValuePair("arttype", "0"));
   requestIds.put("type", request.getId());
   String cache = Cache.from(getActivity()).getData(MD5Util.MD5(request.getWholeURL()));
   if (cache != null && !cache.equals("")) {
     try {
       handleType(new JSONArray(cache));
     } catch (JSONException e) {
       e.printStackTrace();
     }
   } else {
     if (NetUtils.isNetworkAvailable(getActivity())) {
       request.setListener(this);
       dispatcher.dispatch(request);
     } else {
       ToastManager.getManager().showToast(R.string.network_is_not_available);
     }
   }
   return root;
 }
コード例 #2
0
 @Override
 public void onResponse(Request<JSONArray> request, Response<JSONArray> response) {
   if (response.result == null) return;
   Cache.from(getActivity()).save(MD5Util.MD5(request.getWholeURL()), response.result.toString());
   if (request.getId() == requestIds.get("type")) {
     handleType(response.result);
   }
 }