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

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

Issue 2845773003: Photo Picker Dialog: Add caching for the decoded images. (Closed)
Patch Set: Polish 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/PickerBitmapViewHolder.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerBitmapViewHolder.java b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerBitmapViewHolder.java
index bd8dba0de3b4683aba1e342f1edd57a12cc7ec72..28fa09d2153fecc10e2aff1a320469034aa9c89a 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerBitmapViewHolder.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerBitmapViewHolder.java
@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.photo_picker;
import android.graphics.Bitmap;
+import android.os.AsyncTask;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.text.TextUtils;
@@ -15,12 +16,18 @@ import java.util.List;
*/
public class PickerBitmapViewHolder
extends ViewHolder implements DecoderServiceHost.ImageDecodedCallback {
+ // The size (in dp) of the low-res thumbnails.
+ private static final int GRAINY_THUMBNAIL_SIZE_DP = 12;
Theresa 2017/05/08 19:34:42 Nit: Put this in dimens.xml and use Resources.getD
Finnur 2017/05/09 11:53:56 Done.
+
// Our parent category.
private PickerCategoryView mCategoryView;
// The bitmap view we are holding on to.
private final PickerBitmapView mItemView;
+ // The screen density.
+ private final float mDensity;
+
// The request we are showing the bitmap for.
private PickerBitmap mBitmapDetails;
@@ -31,6 +38,7 @@ public class PickerBitmapViewHolder
public PickerBitmapViewHolder(PickerBitmapView itemView) {
super(itemView);
mItemView = itemView;
+ mDensity = itemView.getContext().getResources().getDisplayMetrics().density;
}
// DecoderServiceHost.ImageDecodedCallback
@@ -41,6 +49,16 @@ public class PickerBitmapViewHolder
return;
}
+ if (mCategoryView.getHighResBitmaps().get(filePath) == null) {
+ mCategoryView.getHighResBitmaps().put(filePath, bitmap);
+ }
+
+ if (mCategoryView.getLowResBitmaps().get(filePath) == null) {
+ new BitmapScalerTask(mCategoryView.getLowResBitmaps(), filePath,
+ (int) (GRAINY_THUMBNAIL_SIZE_DP * mDensity))
+ .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, bitmap);
+ }
+
if (!TextUtils.equals(mBitmapDetails.getFilePath(), filePath)) {
return;
}
@@ -65,12 +83,24 @@ public class PickerBitmapViewHolder
return;
}
- // TODO(finnur): Use cached image, if available.
-
- mItemView.initialize(mBitmapDetails, null, true);
+ String filePath = mBitmapDetails.getFilePath();
+ Bitmap original = mCategoryView.getHighResBitmaps().get(filePath);
+ if (original != null) {
+ mItemView.initialize(mBitmapDetails, original, false);
+ return;
+ }
int size = mCategoryView.getImageSize();
- mCategoryView.getDecoderServiceHost().decodeImage(mBitmapDetails.getFilePath(), size, this);
+ Bitmap placeholder = mCategoryView.getLowResBitmaps().get(filePath);
+ if (placeholder != null) {
+ // Scaling the image up takes between 3-4 ms on average (Nexus 6 phone debug build).
Theresa 2017/05/08 19:34:42 nit: This type of information is likely to get out
Finnur 2017/05/09 11:53:56 Done.
+ placeholder = BitmapUtils.scale(placeholder, size, false);
+ mItemView.initialize(mBitmapDetails, placeholder, true);
+ } else {
+ mItemView.initialize(mBitmapDetails, null, true);
+ }
+
+ mCategoryView.getDecoderServiceHost().decodeImage(filePath, size, this);
}
/**

Powered by Google App Engine
This is Rietveld 408576698