/** Get的StringRequest(通过接口回调处理成功和失败的结果) */
  public static void RequestGet(Context context, String url, String tag, VolleyInterface vif) {

    ApplicationController.cancelPendingRequests(tag);
    stringRequest =
        new StringRequest(Request.Method.GET, url, vif.loadingListener(), vif.errorListener());
    stringRequest.setTag(tag);
    ApplicationController.getRequestQueue().add(stringRequest);
  }
Beispiel #2
0
 private void requestNewFeedRefresh() {
   StringRequest req =
       new StringRequest(
           Urls.SERVER_PATH + "/feed/unread_num?offset=" + offset,
           new Response.Listener<String>() {
             @Override
             public void onResponse(String response) {
               if (!TextUtils.isEmpty(response)) {
                 try {
                   JSONObject json = new JSONObject(response);
                   int count = json.getInt("unread_num");
                   String msg = json.getString("message");
                   if (count > 0 && !TextUtils.isEmpty(msg)) {
                     showRefreshNewsCount(msg, true);
                     stopRefreshNews();
                     return;
                   }
                 } catch (Exception e) {
                   e.printStackTrace();
                 }
                 startRefreshNews();
               }
             }
           },
           new Response.ErrorListener() {
             @Override
             public void onErrorResponse(VolleyError error) {
               Trace.d(TAG, error.getMessage());
               startRefreshNews();
             }
           });
   if (TextUtils.isEmpty(REFRESH_TAG)) REFRESH_TAG = getUniqueRequestTag();
   req.setHeaders(AppUtils.getOAuthMap(getActivity()));
   req.addHeader("lang", getString(R.string.lang));
   req.setShouldCache(false);
   ApplicationController.getInstance().addToRequestQueue(req, REFRESH_TAG);
 }
 /** Post的StringRequest(通过接口回调处理成功和失败的结果) */
 public static void RequestPost(
     Context context,
     String url,
     String tag,
     final Map<String, String> params,
     VolleyInterface vif) {
   ApplicationController.cancelPendingRequests(tag);
   stringRequest =
       new StringRequest(Request.Method.POST, url, vif.loadingListener(), vif.errorListener()) {
         @Override
         protected Map<String, String> getParams() throws AuthFailureError {
           return params;
         }
       };
   stringRequest.setTag(tag);
   ApplicationController.getRequestQueue().add(stringRequest);
 }
 /** Post的StringRequest(直接解析结果) */
 public static NetworkResponse RequestPostTickle(
     Context context,
     String url,
     String tag,
     final Map<String, String> params,
     VolleyInterface vif) {
   RequestTickle mRequestTickle = VolleyTickle.newRequestTickle(context);
   stringRequest =
       new StringRequest(Request.Method.POST, url, null, null) {
         @Override
         protected Map<String, String> getParams() throws AuthFailureError {
           return params;
         }
       };
   stringRequest.setTag(tag);
   mRequestTickle.add(stringRequest);
   NetworkResponse response = mRequestTickle.start();
   return response;
 }