diff options
author | Ralph Bergmann <ralph@the4thfloor.eu> | 2015-03-05 16:30:58 +0100 |
---|---|---|
committer | Ralph Bergmann <ralph@the4thfloor.eu> | 2015-03-06 10:57:05 +0100 |
commit | d95219cb1c414de049f90c97fccad638b11bdc85 (patch) | |
tree | 526f6ffad13c2df90ddd21232b1f0ece4ac77e78 /src/main | |
parent | eee4bbd6448e6f9914722f245b2a7d7d30b54bf2 (diff) | |
download | volley-d95219cb1c414de049f90c97fccad638b11bdc85.tar.gz |
fix ImageLoader.getCacheKey()
The ScaleType was missing.
Change-Id: I57cba7cbf60df1e47ea9d8baf480765c6e39d821
Signed-off-by: Ralph Bergmann <ralph@the4thfloor.eu>
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/android/volley/toolbox/ImageLoader.java | 26 |
1 files changed, 20 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 151e022..babaece 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; } @@ -195,11 +207,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); @@ -487,9 +499,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(); } } |