diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2016-07-25 19:23:54 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-07-25 19:23:56 +0000 |
commit | eadd9ca5aca0eed35f070fed6038f41e6d17ff5f (patch) | |
tree | 6e7f85da7cc442fcb617ca7e95cec64e73f125d1 /packages/DocumentsUI/src/com/android/documentsui/ThumbnailCache.java | |
parent | 7068bfc3834d0cd581881972d2516fefcad136c9 (diff) | |
parent | 996aa3ba1aa930d18120f6b6d6795413b17c04d6 (diff) |
Merge "Evict thumbnail caches and delay dismissing spinner on refresh finish."
Diffstat (limited to 'packages/DocumentsUI/src/com/android/documentsui/ThumbnailCache.java')
-rw-r--r-- | packages/DocumentsUI/src/com/android/documentsui/ThumbnailCache.java | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/packages/DocumentsUI/src/com/android/documentsui/ThumbnailCache.java b/packages/DocumentsUI/src/com/android/documentsui/ThumbnailCache.java index ecde685d29c4..639d4fb4feb3 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/ThumbnailCache.java +++ b/packages/DocumentsUI/src/com/android/documentsui/ThumbnailCache.java @@ -111,6 +111,13 @@ public class ThumbnailCache { return Result.obtainMiss(); } + /** + * Puts a thumbnail for the given uri and size in to the cache. + * @param uri the uri of the thumbnail + * @param size the size of the thumbnail + * @param thumbnail the thumbnail to put in cache + * @param lastModified last modified value of the thumbnail to track its validity + */ public void putThumbnail(Uri uri, Point size, Bitmap thumbnail, long lastModified) { Pair<Uri, Point> cacheKey = Pair.create(uri, size); @@ -130,14 +137,33 @@ public class ThumbnailCache { } } + /** + * Removes all thumbnail cache associated to the given uri. + * @param uri the uri which thumbnail cache to remove + */ + public void removeUri(Uri uri) { + TreeMap<Point, Pair<Uri, Point>> sizeMap; + synchronized (mSizeIndex) { + sizeMap = mSizeIndex.get(uri); + } + + if (sizeMap != null) { + // Create an array to hold all values to avoid ConcurrentModificationException because + // removeKey() will be called by LruCache but we can't modify the map while we're + // iterating over the collection of values. + for (Pair<Uri, Point> index : sizeMap.values().toArray(new Pair[0])) { + mCache.remove(index); + } + } + } + private void removeKey(Uri uri, Point size) { TreeMap<Point, Pair<Uri, Point>> sizeMap; synchronized (mSizeIndex) { sizeMap = mSizeIndex.get(uri); } - // LruCache tells us to remove a key, which should exist, so sizeMap can't be null. - assert (sizeMap != null); + assert(sizeMap != null); synchronized (sizeMap) { sizeMap.remove(size); } |