com.android.volley.Response.ErrorListener Java Examples

The following examples show how to use com.android.volley.Response.ErrorListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImageLoader.java    From volley with Apache License 2.0 6 votes vote down vote up
protected Request<Bitmap> makeImageRequest(
        String requestUrl,
        int maxWidth,
        int maxHeight,
        ScaleType scaleType,
        final String cacheKey) {
    return new ImageRequest(
            requestUrl,
            new Listener<Bitmap>() {
                @Override
                public void onResponse(Bitmap response) {
                    onGetImageSuccess(cacheKey, response);
                }
            },
            maxWidth,
            maxHeight,
            scaleType,
            Config.RGB_565,
            new ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    onGetImageError(cacheKey, error);
                }
            });
}
 
Example #2
Source File: JsonRequest.java    From volley with Apache License 2.0 5 votes vote down vote up
public JsonRequest(
        int method,
        String url,
        @Nullable String requestBody,
        Listener<T> listener,
        @Nullable ErrorListener errorListener) {
    super(method, url, errorListener);
    mListener = listener;
    mRequestBody = requestBody;
}
 
Example #3
Source File: ArticleAPIImpl.java    From the-tech-frontier-app with MIT License 5 votes vote down vote up
@Override
public void fetchArticleContent(String post_id, final DataListener<String> listener,
        ErrorListener errorListener) {
    StringRequest request = new StringRequest(
            "http://www.devtf.cn/api/v1/?type=article&post_id=" + post_id,
            new Listener<String>() {

                @Override
                public void onResponse(String html) {
                    listener.onComplete(html);
                }

            }, errorListener);
    performRequest(request);
}
 
Example #4
Source File: GsonRequest.java    From ting with Apache License 2.0 5 votes vote down vote up
public GsonRequest(int method, String url, Class<T> clazz, Map<String, String> header,
                   Listener<T> listener, ErrorListener errorListener) {
    super(method, url, errorListener);
    mClazz = clazz;
    mListener = listener;
    mHeader = header;
}
 
Example #5
Source File: GetManufacturersAndDevicesRequest.java    From device-database with Apache License 2.0 5 votes vote down vote up
public GetManufacturersAndDevicesRequest(Object tag,
                                         Listener<Response> listener,
                                         ErrorListener errorListener) {
    super(Method.GET,
          "http://www.mocky.io/v2/570bbaf6110000b003d17e3a",
            Response.class,
            listener,
            errorListener);

    this.setTag(tag);
}
 
Example #6
Source File: GsonRequest.java    From VolleyX with Apache License 2.0 5 votes vote down vote up
public GsonRequest(int method, String url, Class<T> cls, Listener<T> listener,
                   ErrorListener errorListener) {
    super(method, url, errorListener);
    mGson = new Gson();
    mJavaClass = cls;
    mListener1 = listener;
}
 
Example #7
Source File: ImageLoader.java    From volley_demo with Apache License 2.0 5 votes vote down vote up
protected Request<Bitmap> makeImageRequest(String requestUrl, int maxWidth, int maxHeight,
        ScaleType scaleType, final String cacheKey) {
    return new ImageRequest(requestUrl, new Listener<Bitmap>() {
        @Override
        public void onResponse(Bitmap response) {
            onGetImageSuccess(cacheKey, response);
        }
    }, maxWidth, maxHeight, scaleType, Config.RGB_565, new ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            onGetImageError(cacheKey, error);
        }
    });
}
 
Example #8
Source File: JsonObjectRequest.java    From SaveVolley with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor which defaults to <code>GET</code> if <code>jsonRequest</code> is
 * <code>null</code>, <code>POST</code> otherwise.
 *
 * @see #JsonObjectRequest(int, String, JSONObject, Listener, ErrorListener)
 */
/*
 * 如果 请求数据 jsonRequest 为 null,方法设置为 GET 请求
 * 如果 请求数据 jsonRequest 不为 null,方法设置为 POST 请求
 */
public JsonObjectRequest(String url, JSONObject jsonRequest, Listener<JSONObject> listener, ErrorListener errorListener) {
    this(jsonRequest == null ? Method.GET : Method.POST, url, jsonRequest, listener,
            errorListener);
}
 
Example #9
Source File: StringRequest.java    From volley with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new request with the given method.
 *
 * @param method the request {@link Method} to use
 * @param url URL to fetch the string at
 * @param listener Listener to receive the String response
 * @param errorListener Error listener, or null to ignore errors
 */
public StringRequest(
        int method,
        String url,
        Listener<String> listener,
        @Nullable ErrorListener errorListener) {
    super(method, url, errorListener);
    mListener = listener;
}
 
Example #10
Source File: JsonArrayRequest.java    From volley with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new request.
 *
 * @param method the HTTP method to use
 * @param url URL to fetch the JSON from
 * @param jsonRequest A {@link JSONArray} to post with the request. Null indicates no parameters
 *     will be posted along with request.
 * @param listener Listener to receive the JSON response
 * @param errorListener Error listener, or null to ignore errors.
 */
public JsonArrayRequest(
        int method,
        String url,
        @Nullable JSONArray jsonRequest,
        Listener<JSONArray> listener,
        @Nullable ErrorListener errorListener) {
    super(
            method,
            url,
            (jsonRequest == null) ? null : jsonRequest.toString(),
            listener,
            errorListener);
}
 
Example #11
Source File: JsonObjectRequest.java    From volley with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor which defaults to <code>GET</code> if <code>jsonRequest</code> is <code>null
 * </code> , <code>POST</code> otherwise.
 *
 * @see #JsonObjectRequest(int, String, JSONObject, Listener, ErrorListener)
 */
public JsonObjectRequest(
        String url,
        @Nullable JSONObject jsonRequest,
        Listener<JSONObject> listener,
        @Nullable ErrorListener errorListener) {
    this(
            jsonRequest == null ? Method.GET : Method.POST,
            url,
            jsonRequest,
            listener,
            errorListener);
}
 
Example #12
Source File: ImageLoader.java    From TitanjumNote with Apache License 2.0 5 votes vote down vote up
protected Request<Bitmap> makeImageRequest(String requestUrl, int maxWidth, int maxHeight,
        ScaleType scaleType, final String cacheKey) {
    return new ImageRequest(requestUrl, new Listener<Bitmap>() {
        @Override
        public void onResponse(Bitmap response) {
            onGetImageSuccess(cacheKey, response);
        }
    }, maxWidth, maxHeight, scaleType, Config.RGB_565, new ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            onGetImageError(cacheKey, error);
        }
    });
}
 
Example #13
Source File: GsonRequest.java    From Rocko-Android-Demos with Apache License 2.0 4 votes vote down vote up
public GsonRequest(String url, Class<T> clazz, Listener<T> listener, ErrorListener errorListener) {
    this(Method.GET, url, clazz, listener, errorListener);
}
 
Example #14
Source File: JsonRequest.java    From device-database with Apache License 2.0 4 votes vote down vote up
public JsonRequest(int method, String url, String requestBody, Listener<T> listener,
        ErrorListener errorListener) {
    super(method, url, errorListener);
    mListener = listener;
    mRequestBody = requestBody;
}
 
Example #15
Source File: RawRequest.java    From fresco with MIT License 4 votes vote down vote up
public RawRequest(String url, Listener<byte[]> listener, ErrorListener errorListener) {
  super(0, url, errorListener);
  this.mListener = listener;
  setShouldCache(false);
}
 
Example #16
Source File: GsonRequest.java    From SimplifyReader with Apache License 2.0 4 votes vote down vote up
public GsonRequest(String url, String requestBody, Type type, Listener<T> listener,
                   ErrorListener errorListener) {
    this(Method.GET, url, requestBody, type, listener, errorListener);
}
 
Example #17
Source File: JsonRequest.java    From android-common-utils with Apache License 2.0 4 votes vote down vote up
public JsonRequest(int method, String url, String requestBody, Listener<T> listener,
        ErrorListener errorListener) {
    super(method, url, errorListener);
    mListener = listener;
    mRequestBody = requestBody;
}
 
Example #18
Source File: JsonRequest.java    From TitanjumNote with Apache License 2.0 4 votes vote down vote up
public JsonRequest(int method, String url, String requestBody, Listener<T> listener,
        ErrorListener errorListener) {
    super(method, url, errorListener);
    mListener = listener;
    mRequestBody = requestBody;
}
 
Example #19
Source File: JsonRequest.java    From volley_demo with Apache License 2.0 4 votes vote down vote up
public JsonRequest(int method, String url, String requestBody, Listener<T> listener,
        ErrorListener errorListener) {
    super(method, url, errorListener);
    mListener = listener;
    mRequestBody = requestBody;
}
 
Example #20
Source File: MockRequest.java    From android-project-wo2b with Apache License 2.0 4 votes vote down vote up
public MockRequest(String url, ErrorListener listener) {
    super(Request.Method.GET, url, listener);
}
 
Example #21
Source File: JsonRequest.java    From SaveVolley with Apache License 2.0 4 votes vote down vote up
public JsonRequest(int method, String url, String requestBody, Listener<T> listener, ErrorListener errorListener) {
    super(method, url, errorListener);
    mListener = listener;
    mRequestBody = requestBody;
}
 
Example #22
Source File: ArticleAPIImpl.java    From the-tech-frontier-app with MIT License 4 votes vote down vote up
@Override
public void loadMore(int category, DataListener<List<Article>> listener,
        ErrorListener errorListener) {
    performRequest(++mPage, category, listener, errorListener);
}
 
Example #23
Source File: MockRequest.java    From device-database with Apache License 2.0 4 votes vote down vote up
public MockRequest(String url, ErrorListener listener) {
    super(Request.Method.GET, url, listener);
}
 
Example #24
Source File: BaseNetwork.java    From Airbnb-Android-Google-Map-View with MIT License 4 votes vote down vote up
/**
 * For Post Method with parameters in the content body
 *
 * @param methodType   Type of network call eg, GET,POST, etc.
 * @param url          The url to hit
 * @param paramsObject JsonObject for POST request, null for GET request
 * @param requestType  Type of Network request
 */
public void getJSONObjectForRequest(int methodType, String url, JSONObject paramsObject, final int requestType) {
    if (NetworkUtil.isInternetConnected(mContext)) {
        JsonObjectRequest jsObjRequest = new JsonObjectRequest
                (methodType, url, paramsObject, new Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject response) {
                        try {
                            handleResponse(response, requestType);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        handleError(error);
                    }
                }) {

            @Override
            public String getBodyContentType() {
                return "application/x-www-form-urlencoded; charset=UTF-8";
            }


            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                return getRequestHeaderForAuthorization();
            }

            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> params = new HashMap<String, String>();
                return params;
            }
        };
        int socketTimeout = 5000;//30 seconds - change to what you want
        RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, 2, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
        jsObjRequest.setRetryPolicy(policy);
        CustomVolleyRequestQueue.getInstance(mContext).getRequestQueue().add(jsObjRequest);
    }
}
 
Example #25
Source File: ImageLoader.java    From android-discourse with Apache License 2.0 4 votes vote down vote up
/**
 * Issues a bitmap request with the given URL if that image is not available in the cache, and returns a bitmap container that contains
 * all of the data relating to the request (as well as the default image if the requested image is not available).
 *
 * @param requestUrl    The url of the remote image
 * @param imageListener The listener to call when the remote image is loaded
 * @param maxWidth      The maximum width of the returned image.
 * @param maxHeight     The maximum height of the returned image.
 * @return A container object that contains all of the properties of the request, as well as the currently available image (default if
 * remote is not loaded).
 */
public ImageContainer get(String requestUrl, ImageListener imageListener, int maxWidth, int maxHeight) {
    // only fulfill requests that were initiated from the main thread.
    throwIfNotOnMainThread();

    final String cacheKey = getCacheKey(requestUrl, maxWidth, maxHeight);

    // Try to look up the request in the cache of remote images.
    Bitmap cachedBitmap = mCache.getBitmap(cacheKey);
    if (cachedBitmap != null) {
        // Return the cached bitmap.
        ImageContainer container = new ImageContainer(cachedBitmap, requestUrl, null, null);
        imageListener.onResponse(container, true);
        return container;
    }

    // The bitmap did not exist in the cache, fetch it!
    ImageContainer imageContainer = new ImageContainer(null, requestUrl, cacheKey, imageListener);

    // Update the caller to let them know that they should use the default bitmap.
    imageListener.onResponse(imageContainer, true);

    // Check to see if a request is already in-flight.
    BatchedImageRequest request = mInFlightRequests.get(cacheKey);
    if (request != null) {
        // If it is, add this request to the list of listeners.
        request.addContainer(imageContainer);
        return imageContainer;
    }

    // The request is not already in flight. Send the new request to the network and
    // track it.
    Request<?> newRequest = new ImageRequest(requestUrl, new Listener<Bitmap>() {
        @Override
        public void onResponse(Bitmap response) {
            onGetImageSuccess(cacheKey, response);
        }
    }, maxWidth, maxHeight, Config.RGB_565, new ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            onGetImageError(cacheKey, error);
        }
    });

    mRequestQueue.add(newRequest);
    mInFlightRequests.put(cacheKey, new BatchedImageRequest(newRequest, imageContainer));
    return imageContainer;
}
 
Example #26
Source File: GsonRequest.java    From ting with Apache License 2.0 4 votes vote down vote up
public GsonRequest(String url,Class clazz, ErrorListener errorListener){
    this(Method.GET, url,clazz, null, null, errorListener);
    type = new TypeToken<List<Comments>>(){
    }.getType();
}
 
Example #27
Source File: GsonRequest.java    From ting with Apache License 2.0 4 votes vote down vote up
public GsonRequest(int method, String url, Class<T> clazz, Map<String, String> header,
                   ErrorListener errorListener) {
    this(method, url, clazz, header, null, errorListener);
}
 
Example #28
Source File: GsonRequest.java    From ting with Apache License 2.0 4 votes vote down vote up
public GsonRequest(String url, Class clazz, Listener<T> listener, ErrorListener errorListener) {
    this(Method.GET, url, clazz, null, listener, errorListener);
}
 
Example #29
Source File: JsonRequest.java    From android-project-wo2b with Apache License 2.0 4 votes vote down vote up
public JsonRequest(int method, String url, String requestBody, Listener<T> listener,
        ErrorListener errorListener) {
    super(method, url, errorListener);
    mListener = listener;
    mRequestBody = requestBody;
}
 
Example #30
Source File: JsonArrayRequest.java    From SaveVolley with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new request.
 *
 * @param url URL to fetch the JSON from
 * @param listener Listener to receive the JSON response
 * @param errorListener Error listener, or null to ignore errors.
 */
/*
 * Method 默认为:GET 请求
 */
public JsonArrayRequest(String url, Listener<JSONArray> listener, ErrorListener errorListener) {
    super(Method.GET, url, null, listener, errorListener);
}