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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.photo_picker; 5 package org.chromium.chrome.browser.photo_picker;
6 6
7 import android.content.res.Resources;
7 import android.graphics.Bitmap; 8 import android.graphics.Bitmap;
9 import android.os.AsyncTask;
8 import android.support.v7.widget.RecyclerView.ViewHolder; 10 import android.support.v7.widget.RecyclerView.ViewHolder;
9 import android.text.TextUtils; 11 import android.text.TextUtils;
10 12
13 import org.chromium.chrome.R;
14
11 import java.util.List; 15 import java.util.List;
12 16
13 /** 17 /**
14 * Holds on to a {@link PickerBitmapView} that displays information about a pick er bitmap. 18 * Holds on to a {@link PickerBitmapView} that displays information about a pick er bitmap.
15 */ 19 */
16 public class PickerBitmapViewHolder 20 public class PickerBitmapViewHolder
17 extends ViewHolder implements DecoderServiceHost.ImageDecodedCallback { 21 extends ViewHolder implements DecoderServiceHost.ImageDecodedCallback {
18 // Our parent category. 22 // Our parent category.
19 private PickerCategoryView mCategoryView; 23 private PickerCategoryView mCategoryView;
20 24
(...skipping 13 matching lines...) Expand all
34 } 38 }
35 39
36 // DecoderServiceHost.ImageDecodedCallback 40 // DecoderServiceHost.ImageDecodedCallback
37 41
38 @Override 42 @Override
39 public void imageDecodedCallback(String filePath, Bitmap bitmap) { 43 public void imageDecodedCallback(String filePath, Bitmap bitmap) {
40 if (bitmap == null || bitmap.getWidth() == 0 || bitmap.getHeight() == 0) { 44 if (bitmap == null || bitmap.getWidth() == 0 || bitmap.getHeight() == 0) {
41 return; 45 return;
42 } 46 }
43 47
48 if (mCategoryView.getHighResBitmaps().get(filePath) == null) {
49 mCategoryView.getHighResBitmaps().put(filePath, bitmap);
50 }
51
52 if (mCategoryView.getLowResBitmaps().get(filePath) == null) {
53 Resources resources = mItemView.getContext().getResources();
54 new BitmapScalerTask(mCategoryView.getLowResBitmaps(), filePath,
55 resources.getDimensionPixelSize(R.dimen.photo_picker_grainy_ thumbnail_size))
56 .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, bitmap);
57 }
58
44 if (!TextUtils.equals(mBitmapDetails.getFilePath(), filePath)) { 59 if (!TextUtils.equals(mBitmapDetails.getFilePath(), filePath)) {
45 return; 60 return;
46 } 61 }
47 62
48 if (mItemView.setThumbnailBitmap(bitmap)) { 63 if (mItemView.setThumbnailBitmap(bitmap)) {
49 mItemView.fadeInThumbnail(); 64 mItemView.fadeInThumbnail();
50 } 65 }
51 } 66 }
52 67
53 /** 68 /**
54 * Display a single item from |position| in the PickerCategoryView. 69 * Display a single item from |position| in the PickerCategoryView.
55 * @param categoryView The PickerCategoryView to use to fetch the image. 70 * @param categoryView The PickerCategoryView to use to fetch the image.
56 * @param position The position of the item to fetch. 71 * @param position The position of the item to fetch.
57 */ 72 */
58 public void displayItem(PickerCategoryView categoryView, int position) { 73 public void displayItem(PickerCategoryView categoryView, int position) {
59 mCategoryView = categoryView; 74 mCategoryView = categoryView;
60 75
61 List<PickerBitmap> pickerBitmaps = mCategoryView.getPickerBitmaps(); 76 List<PickerBitmap> pickerBitmaps = mCategoryView.getPickerBitmaps();
62 mBitmapDetails = pickerBitmaps.get(position); 77 mBitmapDetails = pickerBitmaps.get(position);
63 78
64 if (mBitmapDetails.type() == PickerBitmap.CAMERA 79 if (mBitmapDetails.type() == PickerBitmap.CAMERA
65 || mBitmapDetails.type() == PickerBitmap.GALLERY) { 80 || mBitmapDetails.type() == PickerBitmap.GALLERY) {
66 mItemView.initialize(mBitmapDetails, null, false); 81 mItemView.initialize(mBitmapDetails, null, false);
67 return; 82 return;
68 } 83 }
69 84
70 // TODO(finnur): Use cached image, if available. 85 String filePath = mBitmapDetails.getFilePath();
71 86 Bitmap original = mCategoryView.getHighResBitmaps().get(filePath);
72 mItemView.initialize(mBitmapDetails, null, true); 87 if (original != null) {
88 mItemView.initialize(mBitmapDetails, original, false);
89 return;
90 }
73 91
74 int size = mCategoryView.getImageSize(); 92 int size = mCategoryView.getImageSize();
75 mCategoryView.getDecoderServiceHost().decodeImage(mBitmapDetails.getFile Path(), size, this); 93 Bitmap placeholder = mCategoryView.getLowResBitmaps().get(filePath);
94 if (placeholder != null) {
95 // For performance stats see http://crbug.com/719919.
96 placeholder = BitmapUtils.scale(placeholder, size, false);
97 mItemView.initialize(mBitmapDetails, placeholder, true);
98 } else {
99 mItemView.initialize(mBitmapDetails, null, true);
100 }
101
102 mCategoryView.getDecoderServiceHost().decodeImage(filePath, size, this);
76 } 103 }
77 104
78 /** 105 /**
79 * Returns the file path of the current request. 106 * Returns the file path of the current request.
80 */ 107 */
81 public String getFilePath() { 108 public String getFilePath() {
82 return mBitmapDetails == null ? null : mBitmapDetails.getFilePath(); 109 return mBitmapDetails == null ? null : mBitmapDetails.getFilePath();
83 } 110 }
84 } 111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698