aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKevin Schultz <krschultz@gmail.com>2014-07-16 16:30:57 -0400
committerKevin Schultz <krschultz@gmail.com>2014-07-16 16:30:57 -0400
commit6c8ba96246e9c1f0056341d9f1d16208489ba555 (patch)
tree4ca5e73f50c43333a19df453e051984e9b5f3e16 /src
parent0e406003b5d434d8f16d7d6ad97d446060b788e6 (diff)
downloadvolley-6c8ba96246e9c1f0056341d9f1d16208489ba555.tar.gz
allow use of custom ImageRequests in ImageLoader
This seems like the smallest change that will allow developers to supply their own ImageRequest class to the ImageLoader without changing the API. There are several use cases for supplying custom ImageRequests, including setting custom headers, adjusting the priority of ImageRequests, and working around Issue #71928. Change-Id: Ic47452b5f8cada2491a6513cb56f383261c73c3a
Diffstat (limited to 'src')
-rw-r--r--src/com/android/volley/toolbox/ImageLoader.java34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/com/android/volley/toolbox/ImageLoader.java b/src/com/android/volley/toolbox/ImageLoader.java
index fe0f32a..5348dc6 100644
--- a/src/com/android/volley/toolbox/ImageLoader.java
+++ b/src/com/android/volley/toolbox/ImageLoader.java
@@ -26,7 +26,6 @@ import com.android.volley.RequestQueue;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
-import com.android.volley.toolbox.ImageRequest;
import java.util.HashMap;
import java.util.LinkedList;
@@ -216,19 +215,7 @@ public class ImageLoader {
// 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);
- }
- });
+ Request<Bitmap> newRequest = makeImageRequest(requestUrl, maxWidth, maxHeight, cacheKey);
mRequestQueue.add(newRequest);
mInFlightRequests.put(cacheKey,
@@ -236,6 +223,21 @@ public class ImageLoader {
return imageContainer;
}
+ protected Request<Bitmap> makeImageRequest(String requestUrl, int maxWidth, int maxHeight, final String cacheKey) {
+ return 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);
+ }
+ });
+ }
+
/**
* Sets the amount of time to wait after the first response arrives before delivering all
* responses. Batching can be disabled entirely by passing in 0.
@@ -250,7 +252,7 @@ public class ImageLoader {
* @param cacheKey The cache key that is associated with the image request.
* @param response The bitmap that was returned from the network.
*/
- private void onGetImageSuccess(String cacheKey, Bitmap response) {
+ protected void onGetImageSuccess(String cacheKey, Bitmap response) {
// cache the image that was fetched.
mCache.putBitmap(cacheKey, response);
@@ -270,7 +272,7 @@ public class ImageLoader {
* Handler for when an image failed to load.
* @param cacheKey The cache key that is associated with the image request.
*/
- private void onGetImageError(String cacheKey, VolleyError error) {
+ protected void onGetImageError(String cacheKey, VolleyError error) {
// Notify the requesters that something failed via a null result.
// Remove this request from the list of in-flight requests.
BatchedImageRequest request = mInFlightRequests.remove(cacheKey);