Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java |
| index bbabd8086d38e6ce862d7c50e04f1a1f17e3f6f4..ea98c4d2745ba310a3fd397abd95b821863d646e 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java |
| @@ -6,10 +6,12 @@ package org.chromium.chrome.browser.photo_picker; |
| import android.app.Activity; |
| import android.content.Context; |
| +import android.graphics.Bitmap; |
| import android.graphics.Rect; |
| import android.support.v7.widget.GridLayoutManager; |
| import android.support.v7.widget.RecyclerView; |
| import android.support.v7.widget.Toolbar.OnMenuItemClickListener; |
| +import android.util.LruCache; |
| import android.view.LayoutInflater; |
| import android.view.MenuItem; |
| import android.view.View; |
| @@ -30,6 +32,8 @@ import java.util.List; |
| public class PickerCategoryView extends RelativeLayout |
| implements FileEnumWorkerTask.FilesEnumeratedCallback, RecyclerView.RecyclerListener, |
| DecoderServiceHost.ServiceReadyCallback, OnMenuItemClickListener { |
| + private static final int KILOBYTE = 1024; |
| + |
| // The dialog that owns us. |
| private PhotoPickerDialog mDialog; |
| @@ -60,6 +64,14 @@ public class PickerCategoryView extends RelativeLayout |
| // The {@link SelectionDelegate} keeping track of which images are selected. |
| private SelectionDelegate<PickerBitmap> mSelectionDelegate; |
| + // A low-resolution cache for images. Helpful for cache misses from the high-resolution cache |
| + // to avoid showing gray squares (we show pixelated versions instead until image can be loaded |
| + // off disk, which is much less jarring). |
| + private LruCache<String, Bitmap> mLowResBitmaps; |
| + |
| + // A high-resolution cache for images. |
| + private LruCache<String, Bitmap> mHighResBitmaps; |
| + |
| /** |
| * The number of columns to show. Note: mColumns and mPadding (see below) should both be even |
| * numbers or both odd, not a mix (the column padding will not be of uniform thickness if they |
| @@ -118,7 +130,21 @@ public class PickerCategoryView extends RelativeLayout |
| mRecyclerView.setLayoutManager(mLayoutManager); |
| mRecyclerView.addItemDecoration(new GridSpacingItemDecoration(mColumns, mPadding)); |
| - // TODO(finnur): Implement caching. |
| + final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / KILOBYTE); |
| + final int cacheSizeLarge = maxMemory / 2; // 1/2 of the available memory. |
| + final int cacheSizeSmall = maxMemory / 8; // 1/8th of the available memory. |
|
Theresa
2017/05/04 16:53:13
How many bitmaps can the small cache hold vs the l
Finnur
2017/05/05 20:41:45
On a Nexus 6 run on my test phone, this resulted i
Theresa
2017/05/08 19:34:42
Thank you for the detailed information!
|
| + mLowResBitmaps = new LruCache<String, Bitmap>(cacheSizeSmall) { |
| + @Override |
| + protected int sizeOf(String key, Bitmap bitmap) { |
|
Theresa
2017/05/04 16:53:13
What does this override do?
Finnur
2017/05/05 20:41:45
It presents the size of the cache in KB, since tha
Theresa
2017/05/08 19:34:42
I phrased my question poorly -- what is using this
Finnur
2017/05/09 11:53:56
It is for debugging. Removed.
|
| + return bitmap.getByteCount() / KILOBYTE; |
| + } |
| + }; |
| + mHighResBitmaps = new LruCache<String, Bitmap>(cacheSizeLarge) { |
| + @Override |
| + protected int sizeOf(String key, Bitmap bitmap) { |
| + return bitmap.getByteCount() / KILOBYTE; |
| + } |
| + }; |
| } |
| /** |
| @@ -222,6 +248,14 @@ public class PickerCategoryView extends RelativeLayout |
| return mDecoderServiceHost; |
| } |
| + public LruCache<String, Bitmap> getLowResBitmaps() { |
| + return mLowResBitmaps; |
| + } |
| + |
| + public LruCache<String, Bitmap> getHighResBitmaps() { |
| + return mHighResBitmaps; |
| + } |
| + |
| public boolean isMultiSelectAllowed() { |
| return mMultiSelectionAllowed; |
| } |