Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1219)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java

Issue 2845773003: Photo Picker Dialog: Add caching for the decoded images. (Closed)
Patch Set: Remove dead var Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 62e4d5828d73b824792fe94a146dde5cef4f1036..84c2ddabc190b82b5d1715e72f8683a6106429a0 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,11 @@ 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.
+ mLowResBitmaps = new LruCache<String, Bitmap>(cacheSizeSmall);
+ mHighResBitmaps = new LruCache<String, Bitmap>(cacheSizeLarge);
}
/**
@@ -222,6 +238,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;
}

Powered by Google App Engine
This is Rietveld 408576698