diff options
author | Ficus Kirkpatrick <ficus@android.com> | 2014-09-03 17:13:29 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-09-03 17:13:30 +0000 |
commit | ef2ac654aec476e6d377166f3ff77701bf325dc7 (patch) | |
tree | b3f0737484771b15aa364618069f1b6368a2a41e /src | |
parent | 71d91b4ea41c3ec2324343541f6626c35b316f05 (diff) | |
parent | 6c8ba96246e9c1f0056341d9f1d16208489ba555 (diff) | |
download | volley-ef2ac654aec476e6d377166f3ff77701bf325dc7.tar.gz |
Merge "allow use of custom ImageRequests in ImageLoader"
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/volley/toolbox/ImageLoader.java | 34 |
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); |