Java Code Examples for com.android.volley.Response.Listener

The following are Jave code examples for showing how to use Listener of the com.android.volley.Response class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: RestaurantApp   File: Request.java   View Source Code Vote up 6 votes
public void requestVolleyDeskList(final DeskList deskList){

        final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(requestMethod, url, null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                deskList.getDesk(response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(context, String.valueOf(error), Toast.LENGTH_SHORT).show();
            }
        });

            requestQueue.add(jsonObjectRequest);

    }
 
Example 2
Project: RestaurantApp   File: Request.java   View Source Code Vote up 6 votes
public void requestVolleyAuth(final VolleyCallback callback, final String username, final String password){

        final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(requestMethod, url, null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    callback.onSuccesAuth(response);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(context, String.valueOf(error), Toast.LENGTH_SHORT).show();
            }
        }){
            @Override
            public byte[] getBody() {
                HashMap<String, String> params = new HashMap<String, String>();
                params.put("username", username);
                params.put("password", password);
                return new JSONObject(params).toString().getBytes();
            }
        };

        requestQueue.add(jsonObjectRequest);

    }
 
Example 3
Project: RestaurantApp   File: Request.java   View Source Code Vote up 6 votes
public void requestVolley(final VolleyCallback callback){

        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(requestMethod, url, null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                callback.onSucces(response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });

        requestQueue.add(jsonObjectRequest);

    }
 
Example 4
Project: sa-android   File: SchoolSystemModels.java   View Source Code Vote up 6 votes
public static void authInit(final ModelListener<AuthInitInfo> listener) {
    JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, baseURL + "/auth/init", null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            try {
                JSONObject result = response.getJSONObject("result");

                AuthInitInfo authInitInfo = new AuthInitInfo();
                authInitInfo.session_id = result.getString("session_id");
                authInitInfo.captcha_enabled = result.getBoolean("captcha_enabled");

                listener.onData(authInitInfo, "ok");
            } catch (JSONException e) {
                listener.onData(null, "教务系统返回非法数据");
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            listener.onData(null, "教务系统太烂无法通信,请稍后再试");
        }
    });
    SAGlobal.sharedRequestQueue.add(req);
}
 
Example 5
Project: trvlr-android   File: FindConnectionActivity.java   View Source Code Vote up 6 votes
private Response.Listener<JSONArray> loadPublicChatSuccess(final String from, final String to) {
    return new Response.Listener<JSONArray>() {
        @Override
        public void onResponse(JSONArray response) {
            // Start the public chat.
            try {
                if (response.length() == 0) {
                    Toast.makeText(FindConnectionActivity.this, TAG + ": " + "invalid connection", Toast.LENGTH_LONG).show();
                } else {
                    Intent intent = new Intent(getApplicationContext(), ChatActivity.class);
                    // We always create a new BO.
                    // TODO check for duplicate connections before executing this code.
                    Chat bo = new Chat(response.getJSONObject(0).getInt("id"), from + " - " + to, Chat.CHATROOM_TYPE_PUBLIC);
                    ((AppController) getApplication()).setCurrentActivePublicChat(bo);
                    ((AppController) getApplication()).setCurrentActiveChatTypeToPublic();
                    startActivity(intent);
                }
            } catch (JSONException e) {
                Toast.makeText(FindConnectionActivity.this, TAG + ": " + e.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }
    };
}
 
Example 6
Project: VolleySimple   File: VolleySimple.java   View Source Code Vote up 5 votes
/**
 * @param apiTag         tag to uniquely distinguish Volley requests. Null is allowed
 * @param url            URL to fetch the string at
 * @param httpMethod     the request method to use (GET or POST)
 * @param params         A HashMap<String,String> to post with the request. Null is allowed and
 *                       indicates no parameters will be posted along with request.
 * @param headers        optional Http headers
 * @param serverCallback Listener to receive the String response
 */
public void placeStringRequest(@Nullable final String apiTag, String url, int httpMethod, @Nullable final HashMap<String, String> params, final HashMap<String, String> headers, final ServerCallback serverCallback) {

    Request request = new StringRequest(httpMethod, url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            serverCallback.onAPIResponse(apiTag, response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            serverCallback.onErrorResponse(apiTag, error);
        }
    }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            return params != null ? params : super.getParams();
        }

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            return headers != null ? headers : super.getHeaders();
        }
    };

    request.setRetryPolicy(retryPolicy);

    addToRequestQueue(request);
}
 
Example 7
Project: GitHub   File: ImageRequest.java   View Source Code Vote up 5 votes
/**
 * For API compatibility with the pre-ScaleType variant of the constructor. Equivalent to
 * the normal constructor with {@code ScaleType.CENTER_INSIDE}.
 */
@Deprecated
public ImageRequest(String url, Response.Listener<Bitmap> listener, int maxWidth, int maxHeight,
        Config decodeConfig, Response.ErrorListener errorListener) {
    this(url, listener, maxWidth, maxHeight,
            ScaleType.CENTER_INSIDE, decodeConfig, errorListener);
}
 
Example 8
Project: CompassDemo   File: AccountProfileActivity.java   View Source Code Vote up 5 votes
protected void SendRequest()
{
    StringRequest stringGetRequest = new StringRequest(Request.Method.POST, UserPref.getAccountprofileUrl(),
            new Response.Listener<String>(){
                @Override
                public void onResponse(String response)
                {
                    ParseJSON(response);
                }

            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error)
        {
            Toast.makeText(AccountProfileActivity.this,error.toString(),Toast.LENGTH_SHORT).show();

        }
    }){            @Override
    protected Map<String, String> getParams() throws AuthFailureError {
        Map<String, String> params = new HashMap<>();
        params.put(UserPref.getKeyUserId(), ID);
        return params;
    }};
    requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringGetRequest);

}
 
Example 9
Project: Sega   File: ProductRegistration.java   View Source Code Vote up 5 votes
private void downloadNotification() {
    StringRequest strReq = new StringRequest(Request.Method.POST,
                                             AppConfig.URL_GETNOTIFICATION, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            try {

                JSONObject jObj = new JSONObject(response);
                JSONArray feedArray = jObj.getJSONArray("rate");
                adapter = new ItemsAdapter(items);
                for (int i = 0; i < feedArray.length(); i++) {
                    final JSONObject feedObj = (JSONObject) feedArray.get(i);
                    //add product to list product
                    items.add(new Item(feedObj.getString("text")));

                }
                recyclerView.setAdapter(adapter);
            } catch (Exception ex) {
                // JSON parsing error
                ex.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            error.printStackTrace();
        }
    }) {
        @Override
        protected Map<String, String> getParams() {
            // Posting parameters to login url
            Map<String, String> params = new HashMap<>();
            params.put("userid", String.valueOf(session.getLoginId()));
            return params;
        }
    };
    strReq.setTag(this.getClass().getName());
    VolleySingleton.getInstance(getApplicationContext()).requestQueue.add(strReq);
}
 
Example 10
Project: swaggy-jenkins   File: PatchRequest.java   View Source Code Vote up 5 votes
public PatchRequest(String url, Map<String, String> apiHeaders, String contentType, HttpEntity entity, Response.Listener<String> listener, Response.ErrorListener errorListener) {
  super(Method.PATCH, url, errorListener);
  mListener = listener;
  this.entity = entity;
  this.contentType = contentType;
  this.apiHeaders = apiHeaders;
}
 
Example 11
Project: LianXiZhihu   File: CacheService.java   View Source Code Vote up 5 votes
/**
 * 网络请求果壳的消息内容主体并存储
 *
 * @param id 对应的id
 */
private void startGuokrCache(final int id) {
    Cursor cursor = db.query("Guokr", null, null, null, null, null, null);
    if (cursor.moveToFirst()) {
        do {
            if ((cursor.getInt(cursor.getColumnIndex("guokr_id")) == id)
                    && (cursor.getString(cursor.getColumnIndex("guokr_content")).equals(""))) {
                StringRequest request = new StringRequest(Api.GUOKR_ARTICLE_LINK_V1 + id, new Response
                        .Listener<String>() {
                    @Override
                    public void onResponse(String s) {
                        ContentValues values = new ContentValues();
                        values.put("guokr_content", s);
                        db.update("Guokr", values, "guokr_id = ?", new String[]{String.valueOf(id)});
                        values.clear();
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {

                    }
                });
                request.setTag(TAG);
                VolleySingleton.getVolleySingleton(CacheService.this).getRequestQueue().add(request);
            }
        } while (cursor.moveToNext());
    }
    cursor.close();
}
 
Example 12
Project: CompassDemo   File: ApplyActivity.java   View Source Code Vote up 5 votes
protected void CheckAdmin()
{
    SharedPreferences sharedPreferences = getSharedPreferences(UserPref.getSharedPrefName(), Context.MODE_PRIVATE);
    final String  ID = sharedPreferences.getString(UserPref.getKeyUserId(),"Null");
    StringRequest stringGetRequest = new StringRequest(Request.Method.POST, "https://greatnorthcap.000webhostapp.com/PHP/usercheck.php",
            new Response.Listener<String>(){
                @Override
                public void onResponse(String response)
                {
                    LenderType = response;

                    String Unscreened = "0";
                    if (LenderType.equalsIgnoreCase(Unscreened))
                    {
                        Toast.makeText(ApplyActivity.this,"You have an unscreened account. You cannot do this.",Toast.LENGTH_SHORT).show();
                    }
                    else
                    {
                        insertLoan();
                    }
                }

            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error)
        {
            Toast.makeText(ApplyActivity.this,error.toString(),Toast.LENGTH_SHORT).show();

        }
    }){            @Override
    protected Map<String, String> getParams() throws AuthFailureError {
        Map<String, String> params = new HashMap<>();
        params.put(UserPref.getKeyUserId(), ID);
        return params;
    }} ;

    requestQueue.add(stringGetRequest);
}
 
Example 13
Project: Blockly   File: RegisterActivity.java   View Source Code Vote up 5 votes
/**
 * 用于最终确认注册
 */
public void confirmRegister(){
    final RequestQueue requestQueue = MyApplication.getRequestQueue();
    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject.put("userPassword",password1);
        jsonObject.put("verifyCode",code);
        jsonObject.put("userName",name);
        jsonObject.put("userId",email);
    }catch (JSONException e){
        e.printStackTrace();
    }

    Log.d("confirmRegister_JsonObj",jsonObject.toString());

    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url_confirmregister, jsonObject, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {

            confirmRegisterReceive confirmreceive = new confirmRegisterReceive();
            confirmreceive.setStatus(response.optString("status"));
            confirmreceive.setErrMsg(response.optString("errMsg"));
            confirmreceive.setRemainNum(response.optString("remainNum"));
            Log.d("confirmReceive_response",confirmreceive.getStatus()+" "+confirmreceive.getErrMsg()+" "+confirmreceive.getRemainNum());
            judge_confirmRegister(confirmreceive.getStatus(),confirmreceive.getErrMsg());

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e("confirmRegister",error.toString(),error);
        }
    });

    requestQueue.add(jsonObjectRequest);

}
 
Example 14
Project: MoreApps   File: MoreAppFragment.java   View Source Code Vote up 4 votes
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.more_app_fragment , container , false);

    getActivity().setTitle("More Apps");
    itemsArrayList = new ArrayList<>();
    recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(linearLayoutManager);
    adapter = new MoreAppAdapter(getActivity() , itemsArrayList , this);


    recyclerView.setAdapter(adapter);

    JsonArrayRequest movieReq = new JsonArrayRequest( url,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    Log.d(TAG_NAME, response.toString());



                    // Parsing json
                    for (int i = 0; i < response.length(); i++) {
                        try {

                            JSONObject obj = response.getJSONObject(i);
                            Items song = new Items();
                            song.setName(obj.getString("name"));
                            song.setImageId(obj.getString("image"));
                            song.setId(obj.getLong("rating"));
                            song.setLink(obj.getString("package_name"));
                            itemsArrayList.add(song);

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }

                    // notifying list adapter about data changes
                    // so that it renders the list view with updated data

                    adapter.notifyDataSetChanged();

                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            VolleyLog.d(TAG_NAME, "Error: " + error.getMessage());


        }
    });
    movieReq.setShouldCache(false);
    // Adding request to request queue
    App.getInstance().addToRequestQueue(movieReq);
    return view;
}
 
Example 15
Project: iReading   File: HttpRequestUtils.java   View Source Code Vote up 4 votes
/**
 * 注册第一步——检查手机号是否已注册
 *
 * @param button      Loading Button
 * @param activity    Register Activity
 * @param phoneNumber 手机号码
 */
public static void RegisterStep1Request(final LoadingButton button,
                                        final RegisterActivity activity, final String phoneNumber) {
    //请求地址
    String url = HttpRequestUtils.SERVER_ROOT + "iReading/*";
    String tag = "RegisterByPhoneNumberStep1";

    //取得请求队列
    RequestQueue requestQueue = MyApplication.getRequestQueue();

    //防止重复请求,所以先取消tag标识的请求队列
    requestQueue.cancelAll(tag);

    //创建StringRequest,定义字符串请求的请求方式为POST(省略第一个参数会默认为GET方式)
    final StringRequest request = new StringRequest(Request.Method.POST, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONObject jsonObject = (JSONObject) new JSONObject(response).get("params");
                        String result = jsonObject.getString("IsNew");
                        if (result.equals("true")) {
                            button.loadingSuccessful();
                        } else {
                            button.loadingFailed();
                            activity.showToast("该手机号已经被注册,验证手机号后可直接登录");
                        }
                    } catch (JSONException e) {
                        activity.showToast("网络请求发生错误,稍后请重试");
                        button.loadingFailed();
                        Log.e("TAG", e.getMessage(), e);
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            activity.showToast("网络请求发生错误,稍后请重试");
            button.loadingFailed();
            Log.e("TAG", error.getMessage(), error);
        }
    }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            params.put("RequestType", "Register");
            params.put("RegisterType", "RegisterByPhoneNumber");
            params.put("RegisterStep", "1");
            params.put("PhoneNumber", phoneNumber);
            return params;
        }
    };

    //设置Tag标签
    request.setTag(tag);

    //将请求添加到队列中
    requestQueue.add(request);
}
 
Example 16
Project: stitch-android-sdk   File: StitchClient.java   View Source Code Vote up 4 votes
/**
 * Gets all available auth providers for the current app.
 *
 * @return A task containing {@link AvailableAuthProviders} that can be resolved on completion
 * of the request.
 */
public Task<AvailableAuthProviders> getAuthProviders() {

    final TaskCompletionSource<AvailableAuthProviders> future = new TaskCompletionSource<>();
    final String url = getResourcePath(routes.AUTH_PROVIDERS);

    final JsonArrayRequest request = new JsonArrayRequest(
            Request.Method.GET,
            url,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(final JSONArray response) {
                    final AvailableAuthProviders.Builder builder = new AvailableAuthProviders.Builder();
                    for (int i = 0; i < response.length(); i++) {
                        try {
                            JSONObject info = response.getJSONObject(i);
                            switch (info.getString("type")) {
                                case FacebookAuthProviderInfo.FQ_NAME:
                                    final FacebookAuthProviderInfo fbInfo =
                                            _objMapper.readValue(info.toString(), FacebookAuthProviderInfo.class);
                                    builder.withFacebook(fbInfo);
                                    break;
                                case GoogleAuthProviderInfo.FQ_NAME:
                                    final GoogleAuthProviderInfo googleInfo =
                                            _objMapper.readValue(info.toString(), GoogleAuthProviderInfo.class);
                                    builder.withGoogle(googleInfo);
                                    break;
                                case AnonymousAuthProviderInfo.FQ_NAME:
                                    final AnonymousAuthProviderInfo anonInfo =
                                            _objMapper.readValue(info.toString(), AnonymousAuthProviderInfo.class);
                                    builder.withAnonymous(anonInfo);
                                    break;
                                case EmailPasswordAuthProviderInfo.FQ_NAME:
                                    final EmailPasswordAuthProviderInfo emailPassInfo =
                                            _objMapper.readValue(info.toString(), EmailPasswordAuthProviderInfo.class);
                                    builder.withEmailPass(emailPassInfo);
                                    break;
                                case CustomAuthProviderInfo.FQ_NAME:
                                    final CustomAuthProviderInfo customAuthProviderInfo =
                                            _objMapper.readValue(info.toString(), CustomAuthProviderInfo.class);
                                    builder.withCustomAuth(customAuthProviderInfo);
                            }
                        } catch (JSONException | IOException e) {
                            Log.e(
                                    TAG,
                                    "Error while getting auth provider info",
                                    e);
                            future.setException(e);
                            return;
                        }
                    }
                    future.setResult(builder.build());
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(final VolleyError error) {
                    Log.e(TAG, "Error while getting auth provider info", error);
                    future.setException(parseRequestError(error));
                }
            });
    request.setTag(this);
    _queue.add(request);

    return future.getTask();
}
 
Example 17
Project: swaggy-jenkins   File: RemoteAccessApi.java   View Source Code Vote up 4 votes
/**
 * 
 * Retrieve CSRF protection token

*/
public void getCrumb (final Response.Listener<DefaultCrumbIssuer> responseListener, final Response.ErrorListener errorListener) {
  Object postBody = null;


  // create path and map variables
  String path = "/crumbIssuer/api/json".replaceAll("\\{format\\}","json");

  // query params
  List<Pair> queryParams = new ArrayList<Pair>();
  // header params
  Map<String, String> headerParams = new HashMap<String, String>();
  // form params
  Map<String, String> formParams = new HashMap<String, String>();



  String[] contentTypes = {
    
  };
  String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";

  if (contentType.startsWith("multipart/form-data")) {
    // file uploading
    MultipartEntityBuilder localVarBuilder = MultipartEntityBuilder.create();
    

    HttpEntity httpEntity = localVarBuilder.build();
    postBody = httpEntity;
  } else {
    // normal form params
        }

  String[] authNames = new String[] { "jenkins_auth" };

  try {
    apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames,
      new Response.Listener<String>() {
        @Override
        public void onResponse(String localVarResponse) {
          try {
            responseListener.onResponse((DefaultCrumbIssuer) ApiInvoker.deserialize(localVarResponse,  "", DefaultCrumbIssuer.class));
          } catch (ApiException exception) {
             errorListener.onErrorResponse(new VolleyError(exception));
          }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
          errorListener.onErrorResponse(error);
        }
    });
  } catch (ApiException ex) {
    errorListener.onErrorResponse(new VolleyError(ex));
  }
}
 
Example 18
Project: rxinfo   File: MainActivity.java   View Source Code Vote up 4 votes
private void getDrugInfo(final List<String> possibleNdcs) {
    txtEmpty.setVisibility(View.INVISIBLE);
    progress.setVisibility(View.VISIBLE);
    final RequestQueue queue = Volley.newRequestQueue(this);
    String url = "https://api.fda.gov/drug/label.json?search=\""
            + possibleNdcs.get(0) + "\"";
    final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
            Request.Method.GET,
            url,
            null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Gson gson = new GsonBuilder()
                            .create();
                    Drug drug = gson
                            .fromJson(response.toString(), Drug.class);
                    drugs.add(drug);
                    drugAdapter.notifyDataSetChanged();
                    progress.setVisibility(View.GONE);
                }
            }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            if (possibleNdcs.size() == 1) {
                if (drugs.size() == 0) {
                    txtEmpty.setVisibility(View.VISIBLE);
                }
                progress.setVisibility(View.GONE);
                Toast.makeText(
                        MainActivity.this,
                        getString(R.string.result_not_found),
                        Toast.LENGTH_LONG).show();
            } else {
                possibleNdcs.remove(0);
                getDrugInfo(possibleNdcs);
            }
        }
    }
    );
    queue.add(jsonObjectRequest);
}
 
Example 19
Project: ez-volley   File: VolleyRequest.java   View Source Code Vote up 4 votes
/**
 * DELETE string request.
 *
 * @param url      URL for post API request
 * @param listener Listener
 */
public static void deleteRequest(String url, final VolleyResponseListener listener) {
    StringRequest stringRequest = new StringRequest(Request.Method.DELETE, url, new Response.Listener<String>() {
        @Override
        public void onResponse(String s) {
            listener.onResponse(s);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError volleyError) {
            if (volleyError != null) {
                listener.onError(volleyError);
            }
        }
    }) {
        @Override
        protected Response<String> parseNetworkResponse(NetworkResponse response) {
            listener.onNetworkResponse(response);
            return super.parseNetworkResponse(response);
        }

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> params = new HashMap<String, String>();
            params.put("Accept", "application/json");
            params.put("Content-Type", "application/json; charset=UTF-8");
            params.put("Cache-Control", "no-cache");
            params.put("Authorization", "");
            return params;
        }

        @Override
        public Priority getPriority() {
            return Priority.IMMEDIATE;
        }
    };

    stringRequest.setRetryPolicy(new DefaultRetryPolicy(0, -1, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    VolleySingleton.getInstance().getRequestQueue().add(stringRequest);
}
 
Example 20
Project: GitHub   File: ImageRequest.java   View Source Code Vote up 3 votes
/**
 * Creates a new image request, decoding to a maximum specified width and
 * height. If both width and height are zero, the image will be decoded to
 * its natural size. If one of the two is nonzero, that dimension will be
 * clamped and the other one will be set to preserve the image's aspect
 * ratio. If both width and height are nonzero, the image will be decoded to
 * be fit in the rectangle of dimensions width x height while keeping its
 * aspect ratio.
 *
 * @param url URL of the image
 * @param listener Listener to receive the decoded bitmap
 * @param maxWidth Maximum width to decode this bitmap to, or zero for none
 * @param maxHeight Maximum height to decode this bitmap to, or zero for
 *            none
 * @param scaleType The ImageViews ScaleType used to calculate the needed image size.
 * @param decodeConfig Format to decode the bitmap to
 * @param errorListener Error listener, or null to ignore errors
 */
public ImageRequest(String url, Response.Listener<Bitmap> listener, int maxWidth, int maxHeight,
        ScaleType scaleType, Config decodeConfig, Response.ErrorListener errorListener) {
    super(Method.GET, url, errorListener); 
    setRetryPolicy(
            new DefaultRetryPolicy(IMAGE_TIMEOUT_MS, IMAGE_MAX_RETRIES, IMAGE_BACKOFF_MULT));
    mListener = listener;
    mDecodeConfig = decodeConfig;
    mMaxWidth = maxWidth;
    mMaxHeight = maxHeight;
    mScaleType = scaleType;
}