Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 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 | |
| 14 import java.util.List; | |
| 15 | |
| 16 /** | |
| 17 * Holds on to a {@link PickerBitmapView} that displays information about a pick er bitmap. | |
| 18 */ | |
| 19 public class PickerBitmapViewHolder extends ViewHolder { | |
| 20 // Our parent category. | |
| 21 private PickerCategoryView mCategoryView; | |
| 22 | |
| 23 // The bitmap view we are holding on to. | |
| 24 private final PickerBitmapView mItemView; | |
| 25 | |
| 26 // The request we are showing the bitmap for. | |
| 27 private PickerBitmap mBitmapDetails; | |
| 28 | |
| 29 /** | |
| 30 * The PickerBitmapViewHolder. | |
| 31 * @param itemView The {@link PickerBitmapView} view for showing the image. | |
| 32 */ | |
| 33 public PickerBitmapViewHolder(PickerBitmapView itemView) { | |
| 34 super(itemView); | |
| 35 mItemView = itemView; | |
| 36 } | |
| 37 | |
| 38 /** | |
| 39 * The notification handler for when an image has been decoded. | |
| 40 * @param filePath The file path for the newly decoded image. | |
| 41 * @param bitmap The results of the decoding (or placeholder image, if faile d). | |
| 42 */ | |
| 43 public void imageDecodedCallback(String filePath, Bitmap bitmap) { | |
| 44 if (bitmap == null || bitmap.getWidth() == 0 || bitmap.getHeight() == 0) { | |
| 45 return; | |
| 46 } | |
| 47 | |
| 48 if (!TextUtils.equals(mBitmapDetails.getFilePath(), filePath)) { | |
| 49 return; | |
| 50 } | |
| 51 | |
| 52 mItemView.setThumbnailBitmap(bitmap); | |
| 53 } | |
| 54 | |
| 55 /** | |
| 56 * Display a single item from |position| in the PickerCategoryView. | |
| 57 * @param categoryView The PickerCategoryView to use to fetch the image. | |
| 58 * @param position The position of the item to fetch. | |
| 59 */ | |
| 60 public void displayItem(PickerCategoryView categoryView, int position) { | |
| 61 mCategoryView = categoryView; | |
| 62 | |
| 63 List<PickerBitmap> pickerBitmaps = mCategoryView.getPickerBitmaps(); | |
| 64 mBitmapDetails = pickerBitmaps.get(position); | |
| 65 | |
| 66 String filePath = mBitmapDetails.getFilePath(); | |
|
Theresa
2017/04/06 15:15:29
nit: findbugs reported a deadstore for this variab
Finnur
2017/04/06 15:46:47
Done.
| |
| 67 if (mBitmapDetails.type() == PickerBitmap.TileTypes.CAMERA | |
| 68 || mBitmapDetails.type() == PickerBitmap.TileTypes.GALLERY) { | |
| 69 mItemView.initializeSpecialTile(mBitmapDetails); | |
| 70 return; | |
| 71 } | |
| 72 | |
| 73 // TODO(finnur): Use cached image, if available. | |
| 74 | |
| 75 // TODO(finnur): Use decoder instead. | |
| 76 int size = mCategoryView.getImageSize(); | |
| 77 imageDecodedCallback(mBitmapDetails.getFilePath(), createPlaceholderBitm ap(size, size)); | |
| 78 } | |
| 79 | |
| 80 /** | |
| 81 * Creates a placeholder bitmap. | |
| 82 * @param width The requested width of the resulting bitmap. | |
| 83 * @param height The requested height of the resulting bitmap. | |
| 84 * @return Placeholder bitmap. | |
| 85 */ | |
| 86 // TODO(finnur): Remove once the decoder is in place. | |
| 87 private Bitmap createPlaceholderBitmap(int width, int height) { | |
| 88 Bitmap placeholder = Bitmap.createBitmap(width, height, Bitmap.Config.AR GB_8888); | |
| 89 Canvas canvas = new Canvas(placeholder); | |
| 90 Paint paint = new Paint(); | |
| 91 paint.setColor(Color.GRAY); | |
| 92 canvas.drawRect(0, 0, (float) width, (float) height, paint); | |
| 93 return placeholder; | |
| 94 } | |
| 95 | |
| 96 /** | |
| 97 * Returns the file path of the current request. | |
| 98 */ | |
| 99 public String getFilePath() { | |
| 100 return mBitmapDetails == null ? null : mBitmapDetails.getFilePath(); | |
| 101 } | |
| 102 } | |
| OLD | NEW |