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 |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f97ce3c8a2baa4b6c0b3eafbb55f172c228e077a |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerBitmapViewHolder.java |
@@ -0,0 +1,105 @@ |
+// 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.
|
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.chrome.browser.photo_picker; |
+ |
+import android.graphics.Bitmap; |
+import android.graphics.Canvas; |
+import android.graphics.Color; |
+import android.graphics.Paint; |
+import android.support.v7.widget.RecyclerView.ViewHolder; |
+import android.text.TextUtils; |
+import android.view.View; |
+ |
+import java.util.List; |
+ |
+/** |
+ * 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.
|
+ */ |
+public class PickerBitmapViewHolder extends ViewHolder { |
+ // Our parent category. |
+ private PickerCategoryView mCategoryView; |
+ |
+ // The bitmap view we are holding on to. |
+ private final PickerBitmapView mItemView; |
+ |
+ // The request we are showing the bitmap for. |
+ private PickerBitmap mRequest; |
Theresa
2017/04/04 15:48:33
Same question about this mRequest.
Finnur
2017/04/04 18:05:37
Done.
|
+ |
+ /** |
+ * The PickerBitmapViewHolder. |
+ * @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.
|
+ */ |
+ public PickerBitmapViewHolder(View itemView) { |
+ super(itemView); |
+ |
+ 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.
|
+ mItemView = (PickerBitmapView) itemView; |
+ } |
+ |
+ /** |
+ * The notification handler for when an image has been decoded. |
+ * @param filePath The file path for the newly decoded image. |
+ * @param bitmap The results of the decoding (or placeholder image, if failed). |
+ */ |
+ public void imageDecodedCallback(String filePath, Bitmap bitmap) { |
+ if (bitmap == null || bitmap.getWidth() == 0 || bitmap.getHeight() == 0) { |
+ return; |
+ } |
+ |
+ if (!TextUtils.equals(mRequest.getFilePath(), filePath)) { |
+ return; |
+ } |
+ |
+ mItemView.setThumbnailBitmap(bitmap); |
+ } |
+ |
+ /** |
+ * Display a single item from |position| in the PickerCategoryView. |
+ * @param categoryView The PickerCategoryView to use to fetch the image. |
+ * @param position The position of the item to fetch. |
+ */ |
+ public void displayItem(PickerCategoryView categoryView, int position) { |
+ mCategoryView = categoryView; |
+ |
+ List<PickerBitmap> pickerBitmaps = mCategoryView.getPickerBitmaps(); |
+ mRequest = pickerBitmaps.get(position); |
+ |
+ String filePath = mRequest.getFilePath(); |
+ if (mRequest.type() == PickerBitmap.TileTypes.CAMERA |
+ || mRequest.type() == PickerBitmap.TileTypes.GALLERY) { |
+ mItemView.initializeSpecialTile(mRequest); |
+ return; |
+ } |
+ |
+ // TODO(finnur): Use cached image, if available. |
+ |
+ // TODO(finnur): Use decoder instead. |
+ int size = mCategoryView.getImageSize(); |
+ imageDecodedCallback(mRequest.getFilePath(), createPlaceholderBitmap(size, size)); |
+ } |
+ |
+ /** |
+ * Creates a placeholder bitmap. |
+ * @param width The requested width of the resulting bitmap. |
+ * @param height The requested height of the resulting bitmap. |
+ * @return Placeholder bitmap. |
+ */ |
+ // TODO(finnur): Remove once the decoder is in place. |
+ private Bitmap createPlaceholderBitmap(int width, int height) { |
+ Bitmap placeholder = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
+ Canvas canvas = new Canvas(placeholder); |
+ Paint paint = new Paint(); |
+ paint.setColor(Color.GRAY); |
+ canvas.drawRect(0, 0, (float) width, (float) height, paint); |
+ return placeholder; |
+ } |
+ |
+ /** |
+ * Returns the file path of the current request. |
+ */ |
+ public String getFilePath() { |
+ return mRequest == null ? null : mRequest.getFilePath(); |
+ } |
+} |