OLD | NEW |
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.content.res.Resources; |
8 import android.graphics.Bitmap; | 8 import android.graphics.Bitmap; |
9 import android.os.AsyncTask; | 9 import android.os.AsyncTask; |
| 10 import android.os.SystemClock; |
10 import android.support.v7.widget.RecyclerView.ViewHolder; | 11 import android.support.v7.widget.RecyclerView.ViewHolder; |
11 import android.text.TextUtils; | 12 import android.text.TextUtils; |
12 | 13 |
| 14 import org.chromium.base.metrics.RecordHistogram; |
13 import org.chromium.chrome.R; | 15 import org.chromium.chrome.R; |
14 | 16 |
15 import java.util.List; | 17 import java.util.List; |
| 18 import java.util.concurrent.TimeUnit; |
16 | 19 |
17 /** | 20 /** |
18 * Holds on to a {@link PickerBitmapView} that displays information about a pick
er bitmap. | 21 * Holds on to a {@link PickerBitmapView} that displays information about a pick
er bitmap. |
19 */ | 22 */ |
20 public class PickerBitmapViewHolder | 23 public class PickerBitmapViewHolder |
21 extends ViewHolder implements DecoderServiceHost.ImageDecodedCallback { | 24 extends ViewHolder implements DecoderServiceHost.ImageDecodedCallback { |
22 // Our parent category. | 25 // Our parent category. |
23 private PickerCategoryView mCategoryView; | 26 private PickerCategoryView mCategoryView; |
24 | 27 |
25 // The bitmap view we are holding on to. | 28 // The bitmap view we are holding on to. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 65 |
63 if (mItemView.setThumbnailBitmap(bitmap)) { | 66 if (mItemView.setThumbnailBitmap(bitmap)) { |
64 mItemView.fadeInThumbnail(); | 67 mItemView.fadeInThumbnail(); |
65 } | 68 } |
66 } | 69 } |
67 | 70 |
68 /** | 71 /** |
69 * Display a single item from |position| in the PickerCategoryView. | 72 * Display a single item from |position| in the PickerCategoryView. |
70 * @param categoryView The PickerCategoryView to use to fetch the image. | 73 * @param categoryView The PickerCategoryView to use to fetch the image. |
71 * @param position The position of the item to fetch. | 74 * @param position The position of the item to fetch. |
| 75 * @return The decoding action required to display the item. |
72 */ | 76 */ |
73 public void displayItem(PickerCategoryView categoryView, int position) { | 77 public @PickerAdapter.DecodeActions int displayItem( |
| 78 PickerCategoryView categoryView, int position) { |
74 mCategoryView = categoryView; | 79 mCategoryView = categoryView; |
75 | 80 |
76 List<PickerBitmap> pickerBitmaps = mCategoryView.getPickerBitmaps(); | 81 List<PickerBitmap> pickerBitmaps = mCategoryView.getPickerBitmaps(); |
77 mBitmapDetails = pickerBitmaps.get(position); | 82 mBitmapDetails = pickerBitmaps.get(position); |
78 | 83 |
79 if (mBitmapDetails.type() == PickerBitmap.CAMERA | 84 if (mBitmapDetails.type() == PickerBitmap.CAMERA |
80 || mBitmapDetails.type() == PickerBitmap.GALLERY) { | 85 || mBitmapDetails.type() == PickerBitmap.GALLERY) { |
81 mItemView.initialize(mBitmapDetails, null, false); | 86 mItemView.initialize(mBitmapDetails, null, false); |
82 return; | 87 return PickerAdapter.NO_ACTION; |
83 } | 88 } |
84 | 89 |
85 String filePath = mBitmapDetails.getFilePath(); | 90 String filePath = mBitmapDetails.getFilePath(); |
86 Bitmap original = mCategoryView.getHighResBitmaps().get(filePath); | 91 Bitmap original = mCategoryView.getHighResBitmaps().get(filePath); |
87 if (original != null) { | 92 if (original != null) { |
88 mItemView.initialize(mBitmapDetails, original, false); | 93 mItemView.initialize(mBitmapDetails, original, false); |
89 return; | 94 return PickerAdapter.FROM_CACHE; |
90 } | 95 } |
91 | 96 |
92 int size = mCategoryView.getImageSize(); | 97 int size = mCategoryView.getImageSize(); |
93 Bitmap placeholder = mCategoryView.getLowResBitmaps().get(filePath); | 98 Bitmap placeholder = mCategoryView.getLowResBitmaps().get(filePath); |
94 if (placeholder != null) { | 99 if (placeholder != null) { |
95 // For performance stats see http://crbug.com/719919. | 100 // For performance stats see http://crbug.com/719919. |
| 101 long begin = SystemClock.elapsedRealtime(); |
96 placeholder = BitmapUtils.scale(placeholder, size, false); | 102 placeholder = BitmapUtils.scale(placeholder, size, false); |
| 103 long scaleTime = SystemClock.elapsedRealtime() - begin; |
| 104 RecordHistogram.recordTimesHistogram( |
| 105 "Android.PhotoPicker.UpscaleLowResBitmap", scaleTime, TimeUn
it.MILLISECONDS); |
| 106 |
97 mItemView.initialize(mBitmapDetails, placeholder, true); | 107 mItemView.initialize(mBitmapDetails, placeholder, true); |
98 } else { | 108 } else { |
99 mItemView.initialize(mBitmapDetails, null, true); | 109 mItemView.initialize(mBitmapDetails, null, true); |
100 } | 110 } |
101 | 111 |
102 mCategoryView.getDecoderServiceHost().decodeImage(filePath, size, this); | 112 mCategoryView.getDecoderServiceHost().decodeImage(filePath, size, this); |
| 113 return PickerAdapter.DECODE; |
103 } | 114 } |
104 | 115 |
105 /** | 116 /** |
106 * Returns the file path of the current request. | 117 * Returns the file path of the current request. |
107 */ | 118 */ |
108 public String getFilePath() { | 119 public String getFilePath() { |
109 return mBitmapDetails == null ? null : mBitmapDetails.getFilePath(); | 120 return mBitmapDetails == null ? null : mBitmapDetails.getFilePath(); |
110 } | 121 } |
111 } | 122 } |
OLD | NEW |