| 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..97699c123a320f02c5c3b56a5132b46aea87328f 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
|
| @@ -15,12 +15,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;
|
| +
|
| // 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 +37,7 @@ public class PickerBitmapViewHolder
|
| public PickerBitmapViewHolder(PickerBitmapView itemView) {
|
| super(itemView);
|
| mItemView = itemView;
|
| + mDensity = itemView.getContext().getResources().getDisplayMetrics().density;
|
| }
|
|
|
| // DecoderServiceHost.ImageDecodedCallback
|
| @@ -41,6 +48,16 @@ public class PickerBitmapViewHolder
|
| return;
|
| }
|
|
|
| + if (mCategoryView.getHighResBitmaps().get(filePath) == null) {
|
| + mCategoryView.getHighResBitmaps().put(filePath, bitmap);
|
| + }
|
| +
|
| + if (mCategoryView.getLowResBitmaps().get(filePath) == null) {
|
| + new BitmapScalerWorkerTask(mCategoryView.getLowResBitmaps(), filePath, bitmap,
|
| + (int) (GRAINY_THUMBNAIL_SIZE_DP * mDensity))
|
| + .execute();
|
| + }
|
| +
|
| if (!TextUtils.equals(mBitmapDetails.getFilePath(), filePath)) {
|
| return;
|
| }
|
| @@ -65,11 +82,23 @@ 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();
|
| + 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).
|
| + placeholder = BitmapUtils.scale(placeholder, size, false);
|
| + mItemView.initialize(mBitmapDetails, placeholder, true);
|
| + } else {
|
| + mItemView.initialize(mBitmapDetails, null, true);
|
| + }
|
| +
|
| mCategoryView.getDecoderServiceHost().decodeImage(mBitmapDetails.getFilePath(), size, this);
|
| }
|
|
|
|
|