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

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

Issue 2758313002: Implement the new Photo picker, part two. (Closed)
Patch Set: Address feedback Created 3 years, 8 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
Theresa 2017/04/04 15:48:33 s/2016/2017
Finnur 2017/04/04 18:05:37 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.photo_picker;
6
7 import android.graphics.Bitmap;
8 import android.graphics.Canvas;
9 import android.graphics.Color;
10 import android.graphics.Paint;
11 import android.support.v7.widget.RecyclerView.ViewHolder;
12 import android.text.TextUtils;
13 import android.view.View;
14
15 import java.util.List;
16
17 /**
18 * Holds onto a View that displays information about a picker bitmap.
Theresa 2017/04/04 15:48:33 s/onto/on to s/View/{@link PickerBitmapView}?
Finnur 2017/04/04 18:05:37 Done.
19 */
20 public class PickerBitmapViewHolder extends ViewHolder {
21 // Our parent category.
22 private PickerCategoryView mCategoryView;
23
24 // The bitmap view we are holding on to.
25 private final PickerBitmapView mItemView;
26
27 // The request we are showing the bitmap for.
28 private PickerBitmap mRequest;
Theresa 2017/04/04 15:48:33 Same question about this mRequest.
Finnur 2017/04/04 18:05:37 Done.
29
30 /**
31 * The PickerBitmapViewHolder.
32 * @param itemView The PickerBitmap view for showing the image.
Theresa 2017/04/04 15:48:33 nit: s/PickerBitmap view/{@link PickerBitmapView}
Finnur 2017/04/04 18:05:37 Done.
33 */
34 public PickerBitmapViewHolder(View itemView) {
35 super(itemView);
36
37 assert itemView instanceof PickerBitmapView;
Theresa 2017/04/04 15:48:33 Can we make itemView a PickerBitmapView instead of
Finnur 2017/04/04 18:05:37 Done.
38 mItemView = (PickerBitmapView) itemView;
39 }
40
41 /**
42 * The notification handler for when an image has been decoded.
43 * @param filePath The file path for the newly decoded image.
44 * @param bitmap The results of the decoding (or placeholder image, if faile d).
45 */
46 public void imageDecodedCallback(String filePath, Bitmap bitmap) {
47 if (bitmap == null || bitmap.getWidth() == 0 || bitmap.getHeight() == 0) {
48 return;
49 }
50
51 if (!TextUtils.equals(mRequest.getFilePath(), filePath)) {
52 return;
53 }
54
55 mItemView.setThumbnailBitmap(bitmap);
56 }
57
58 /**
59 * Display a single item from |position| in the PickerCategoryView.
60 * @param categoryView The PickerCategoryView to use to fetch the image.
61 * @param position The position of the item to fetch.
62 */
63 public void displayItem(PickerCategoryView categoryView, int position) {
64 mCategoryView = categoryView;
65
66 List<PickerBitmap> pickerBitmaps = mCategoryView.getPickerBitmaps();
67 mRequest = pickerBitmaps.get(position);
68
69 String filePath = mRequest.getFilePath();
70 if (mRequest.type() == PickerBitmap.TileTypes.CAMERA
71 || mRequest.type() == PickerBitmap.TileTypes.GALLERY) {
72 mItemView.initializeSpecialTile(mRequest);
73 return;
74 }
75
76 // TODO(finnur): Use cached image, if available.
77
78 // TODO(finnur): Use decoder instead.
79 int size = mCategoryView.getImageSize();
80 imageDecodedCallback(mRequest.getFilePath(), createPlaceholderBitmap(siz e, size));
81 }
82
83 /**
84 * Creates a placeholder bitmap.
85 * @param width The requested width of the resulting bitmap.
86 * @param height The requested height of the resulting bitmap.
87 * @return Placeholder bitmap.
88 */
89 // TODO(finnur): Remove once the decoder is in place.
90 private Bitmap createPlaceholderBitmap(int width, int height) {
91 Bitmap placeholder = Bitmap.createBitmap(width, height, Bitmap.Config.AR GB_8888);
92 Canvas canvas = new Canvas(placeholder);
93 Paint paint = new Paint();
94 paint.setColor(Color.GRAY);
95 canvas.drawRect(0, 0, (float) width, (float) height, paint);
96 return placeholder;
97 }
98
99 /**
100 * Returns the file path of the current request.
101 */
102 public String getFilePath() {
103 return mRequest == null ? null : mRequest.getFilePath();
104 }
105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698