diff options
author | Ficus Kirkpatrick <ficus@android.com> | 2015-03-08 00:16:42 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-03-08 00:16:42 +0000 |
commit | 6ca45cdd92301d49e06572edf13edcbe9c5e94cc (patch) | |
tree | 31388f8e8245ac3574d20b09bb905e9d896109f7 | |
parent | bd674b13fbf958fe2f918c364a73222db2e338f9 (diff) | |
parent | cb913d5293f4281e836c51bfe9956dbed8f2cabf (diff) | |
download | volley-6ca45cdd92301d49e06572edf13edcbe9c5e94cc.tar.gz |
am cb913d52: am bd68d901: am 79d00f42: Merge "fix ImageLoader.getCacheKey()"
* commit 'cb913d5293f4281e836c51bfe9956dbed8f2cabf':
fix ImageLoader.getCacheKey()
-rw-r--r-- | src/main/java/com/android/volley/toolbox/ImageLoader.java | 26 | ||||
-rw-r--r-- | src/test/java/com/android/volley/toolbox/ImageLoaderTest.java | 2 |
2 files changed, 22 insertions, 6 deletions
diff --git a/src/main/java/com/android/volley/toolbox/ImageLoader.java b/src/main/java/com/android/volley/toolbox/ImageLoader.java index 995bb48..d5305e3 100644 --- a/src/main/java/com/android/volley/toolbox/ImageLoader.java +++ b/src/main/java/com/android/volley/toolbox/ImageLoader.java @@ -21,7 +21,6 @@ import android.os.Handler; import android.os.Looper; import android.widget.ImageView; import android.widget.ImageView.ScaleType; - import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.Response.ErrorListener; @@ -151,9 +150,22 @@ public class ImageLoader { * @return True if the item exists in cache, false otherwise. */ public boolean isCached(String requestUrl, int maxWidth, int maxHeight) { + return isCached(requestUrl, maxWidth, maxHeight, ScaleType.CENTER_INSIDE); + } + + /** + * Checks if the item is available in the cache. + * + * @param requestUrl The url of the remote image + * @param maxWidth The maximum width of the returned image. + * @param maxHeight The maximum height of the returned image. + * @param scaleType The scaleType of the imageView. + * @return True if the item exists in cache, false otherwise. + */ + public boolean isCached(String requestUrl, int maxWidth, int maxHeight, ScaleType scaleType) { throwIfNotOnMainThread(); - String cacheKey = getCacheKey(requestUrl, maxWidth, maxHeight); + String cacheKey = getCacheKey(requestUrl, maxWidth, maxHeight, scaleType); return mCache.getBitmap(cacheKey) != null; } @@ -194,11 +206,11 @@ public class ImageLoader { */ public ImageContainer get(String requestUrl, ImageListener imageListener, int maxWidth, int maxHeight, ScaleType scaleType) { - + // only fulfill requests that were initiated from the main thread. throwIfNotOnMainThread(); - final String cacheKey = getCacheKey(requestUrl, maxWidth, maxHeight); + final String cacheKey = getCacheKey(requestUrl, maxWidth, maxHeight, scaleType); // Try to look up the request in the cache of remote images. Bitmap cachedBitmap = mCache.getBitmap(cacheKey); @@ -485,9 +497,11 @@ public class ImageLoader { * @param url The URL of the request. * @param maxWidth The max-width of the output. * @param maxHeight The max-height of the output. + * @param scaleType The scaleType of the imageView. */ - private static String getCacheKey(String url, int maxWidth, int maxHeight) { + private static String getCacheKey(String url, int maxWidth, int maxHeight, ScaleType scaleType) { return new StringBuilder(url.length() + 12).append("#W").append(maxWidth) - .append("#H").append(maxHeight).append(url).toString(); + .append("#H").append(maxHeight).append("#S").append(scaleType.ordinal()).append(url) + .toString(); } } diff --git a/src/test/java/com/android/volley/toolbox/ImageLoaderTest.java b/src/test/java/com/android/volley/toolbox/ImageLoaderTest.java index 81de6fe..8a19817 100644 --- a/src/test/java/com/android/volley/toolbox/ImageLoaderTest.java +++ b/src/test/java/com/android/volley/toolbox/ImageLoaderTest.java @@ -84,6 +84,8 @@ public class ImageLoaderTest { assertNotNull(ImageLoader.class.getMethod("getImageListener", ImageView.class, int.class, int.class)); assertNotNull(ImageLoader.class.getMethod("isCached", String.class, int.class, int.class)); + assertNotNull(ImageLoader.class.getMethod("isCached", String.class, int.class, int.class, + ImageView.ScaleType.class)); assertNotNull(ImageLoader.class.getMethod("get", String.class, ImageLoader.ImageListener.class)); assertNotNull(ImageLoader.class.getMethod("get", String.class, |