Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 import android.view.View; | |
| 14 | |
| 15 import java.util.List; | |
| 16 | |
| 17 /** | |
| 18 * Holds onto a View that displays information about a picker bitmap. | |
| 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; | |
| 29 | |
| 30 /** | |
| 31 * The PickerBitmapViewHolder. | |
| 32 * @param itemView The PickerBitmap view for showing the image. | |
| 33 */ | |
| 34 public PickerBitmapViewHolder(View itemView) { | |
| 35 super(itemView); | |
| 36 | |
| 37 assert itemView instanceof PickerBitmapView; | |
| 38 mItemView = (PickerBitmapView) itemView; | |
| 39 } | |
| 40 | |
| 41 public void imageDecodedCallback(String filePath, Bitmap bitmap) { | |
|
Theresa
2017/03/31 18:05:56
nit: JavaDoc
Finnur
2017/04/03 17:30:30
Done.
| |
| 42 if (bitmap == null || bitmap.getWidth() == 0 || bitmap.getHeight() == 0) { | |
| 43 return; | |
| 44 } | |
| 45 | |
| 46 if (!TextUtils.equals(mRequest.getFilePath(), filePath)) { | |
| 47 return; | |
| 48 } | |
| 49 | |
| 50 mItemView.setThumbnailBitmap(bitmap); | |
| 51 } | |
| 52 | |
| 53 /** | |
| 54 * Display a single item from |position| in the PickerCategoryView. | |
| 55 * @param categoryView The PickerCategoryView to use to fetch the image. | |
| 56 * @param position The position of the item to fetch. | |
| 57 */ | |
| 58 public void displayItem(PickerCategoryView categoryView, int position) { | |
| 59 mCategoryView = categoryView; | |
| 60 | |
| 61 List<PickerBitmap> pickerBitmaps = mCategoryView.getPickerBitmaps(); | |
| 62 mRequest = pickerBitmaps.get(position); | |
| 63 | |
| 64 String filePath = mRequest.getFilePath(); | |
| 65 if (mRequest.type() == PickerBitmap.TileTypes.CAMERA | |
| 66 || mRequest.type() == PickerBitmap.TileTypes.GALLERY) { | |
| 67 mItemView.initialize(mRequest, null, false); | |
| 68 mItemView.initializeSpecialTile(); | |
|
Theresa
2017/03/31 18:05:56
Can PickerBitmapView call initializeSpecialTile di
Finnur
2017/04/03 17:30:29
When I went to make that change I realized initial
| |
| 69 return; | |
| 70 } | |
| 71 | |
| 72 // TODO(finnur): Use cached image, if available. | |
| 73 | |
| 74 // TODO(finnur): Use decoder instead. | |
| 75 int size = mCategoryView.getImageSize(); | |
| 76 imageDecodedCallback(mRequest.getFilePath(), createPlaceholderBitmap(siz e, size)); | |
| 77 } | |
| 78 | |
| 79 /** | |
| 80 * Creates a placeholder bitmap. | |
| 81 * @param width The requested width of the resulting bitmap. | |
| 82 * @param height The requested height of the resulting bitmap. | |
| 83 * @return Placeholder bitmap. | |
| 84 */ | |
| 85 // TODO(finnur): Remove once the decoder is in place. | |
| 86 private Bitmap createPlaceholderBitmap(int width, int height) { | |
| 87 Bitmap placeholder = Bitmap.createBitmap(width, height, Bitmap.Config.AR GB_8888); | |
| 88 Canvas canvas = new Canvas(placeholder); | |
| 89 Paint paint = new Paint(); | |
| 90 paint.setColor(Color.GRAY); | |
| 91 canvas.drawRect(0, 0, (float) width, (float) height, paint); | |
| 92 return placeholder; | |
| 93 } | |
| 94 | |
| 95 /** | |
| 96 * Returns the file path of the current request. | |
| 97 */ | |
| 98 public String getFilePath() { | |
| 99 return mRequest == null ? null : mRequest.getFilePath(); | |
| 100 } | |
| 101 } | |
| OLD | NEW |