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

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

Issue 2810773002: Photo Picker Dialog: Recursively traverse the photo directories. (Closed)
Patch Set: Address feedback from Theresa 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
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.app.Activity; 7 import android.app.Activity;
8 import android.content.Context; 8 import android.content.Context;
9 import android.graphics.Rect; 9 import android.graphics.Rect;
10 import android.support.v7.widget.GridLayoutManager; 10 import android.support.v7.widget.GridLayoutManager;
11 import android.support.v7.widget.RecyclerView; 11 import android.support.v7.widget.RecyclerView;
12 import android.support.v7.widget.Toolbar.OnMenuItemClickListener; 12 import android.support.v7.widget.Toolbar.OnMenuItemClickListener;
13 import android.util.AttributeSet; 13 import android.util.AttributeSet;
14 import android.view.LayoutInflater; 14 import android.view.LayoutInflater;
15 import android.view.MenuItem; 15 import android.view.MenuItem;
16 import android.view.View; 16 import android.view.View;
17 import android.widget.RelativeLayout; 17 import android.widget.RelativeLayout;
18 18
19 import org.chromium.chrome.R; 19 import org.chromium.chrome.R;
20 import org.chromium.chrome.browser.widget.selection.SelectableListLayout; 20 import org.chromium.chrome.browser.widget.selection.SelectableListLayout;
21 import org.chromium.chrome.browser.widget.selection.SelectionDelegate; 21 import org.chromium.chrome.browser.widget.selection.SelectionDelegate;
22 import org.chromium.ui.PhotoPickerListener; 22 import org.chromium.ui.PhotoPickerListener;
23 23
24 import java.util.ArrayList;
25 import java.util.List; 24 import java.util.List;
26 25
27 /** 26 /**
28 * A class for keeping track of common data associated with showing photos in 27 * A class for keeping track of common data associated with showing photos in
29 * the photo picker, for example the RecyclerView and the bitmap caches. 28 * the photo picker, for example the RecyclerView and the bitmap caches.
30 */ 29 */
31 public class PickerCategoryView extends RelativeLayout implements OnMenuItemClic kListener { 30 public class PickerCategoryView extends RelativeLayout
31 implements FileEnumWorkerTask.FilesEnumeratedCallback, OnMenuItemClickLi stener {
32 // The dialog that owns us. 32 // The dialog that owns us.
33 private PhotoPickerDialog mDialog; 33 private PhotoPickerDialog mDialog;
34 34
35 // The view containing the RecyclerView and the toolbar, etc. 35 // The view containing the RecyclerView and the toolbar, etc.
36 private SelectableListLayout<PickerBitmap> mSelectableListLayout; 36 private SelectableListLayout<PickerBitmap> mSelectableListLayout;
37 37
38 // Our context. 38 // Our context.
39 private Context mContext; 39 private Context mContext;
40 40
41 // The list of images on disk, sorted by last-modified first. 41 // The list of images on disk, sorted by last-modified first.
(...skipping 20 matching lines...) Expand all
62 * are a mix). 62 * are a mix).
63 */ 63 */
64 private int mColumns; 64 private int mColumns;
65 65
66 // The padding between columns. See also comment for mColumns. 66 // The padding between columns. See also comment for mColumns.
67 private int mPadding; 67 private int mPadding;
68 68
69 // The size of the bitmaps (equal length for width and height). 69 // The size of the bitmaps (equal length for width and height).
70 private int mImageSize; 70 private int mImageSize;
71 71
72 // A worker task for asynchronously enumerating files off the main thread.
73 private FileEnumWorkerTask mWorkerTask;
74
72 public PickerCategoryView(Context context) { 75 public PickerCategoryView(Context context) {
73 super(context); 76 super(context);
74 postConstruction(context); 77 postConstruction(context);
75 } 78 }
76 79
77 public PickerCategoryView(Context context, AttributeSet attrs) { 80 public PickerCategoryView(Context context, AttributeSet attrs) {
78 super(context, attrs); 81 super(context, attrs);
79 postConstruction(context); 82 postConstruction(context);
80 } 83 }
81 84
82 public PickerCategoryView(Context context, AttributeSet attrs, int defStyle) { 85 public PickerCategoryView(Context context, AttributeSet attrs, int defStyle) {
Theresa 2017/04/11 17:01:28 nit:Are all three of these constructors necessary?
Finnur 2017/04/12 11:04:43 Only one is being used, currently (the single-para
83 super(context, attrs, defStyle); 86 super(context, attrs, defStyle);
84 postConstruction(context); 87 postConstruction(context);
85 } 88 }
86 89
87 /** 90 /**
88 * A helper function for initializing the PickerCategoryView. 91 * A helper function for initializing the PickerCategoryView.
89 * @param context The context to use. 92 * @param context The context to use.
90 */ 93 */
91 @SuppressWarnings("unchecked") // mSelectableListLayout 94 @SuppressWarnings("unchecked") // mSelectableListLayout
92 private void postConstruction(Context context) { 95 private void postConstruction(Context context) {
(...skipping 19 matching lines...) Expand all
112 RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(mConte xt, mColumns); 115 RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(mConte xt, mColumns);
113 mRecyclerView.setHasFixedSize(true); 116 mRecyclerView.setHasFixedSize(true);
114 mRecyclerView.setLayoutManager(mLayoutManager); 117 mRecyclerView.setLayoutManager(mLayoutManager);
115 // TODO(finnur): Implement grid spacing. 118 // TODO(finnur): Implement grid spacing.
116 // TODO(finnur): Implement caching. 119 // TODO(finnur): Implement caching.
117 // TODO(finnur): Remove this once the decoder service is in place. 120 // TODO(finnur): Remove this once the decoder service is in place.
118 prepareBitmaps(); 121 prepareBitmaps();
119 } 122 }
120 123
121 /** 124 /**
125 * Cancels any outstanding requests.
126 */
127 public void teardown() {
Theresa 2017/04/11 17:01:29 nit: I think teardown() is typically used in test
Finnur 2017/04/12 11:04:43 Done.
128 mWorkerTask.cancel(true);
129 }
130
131 /**
122 * Initializes the PickerCategoryView object. 132 * Initializes the PickerCategoryView object.
123 * @param dialog The dialog showing us. 133 * @param dialog The dialog showing us.
124 * @param listener The listener who should be notified of actions. 134 * @param listener The listener who should be notified of actions.
125 * @param multiSelectionAllowed Whether to allow the user to select more tha n one image. 135 * @param multiSelectionAllowed Whether to allow the user to select more tha n one image.
126 */ 136 */
127 public void initialize( 137 public void initialize(
128 PhotoPickerDialog dialog, PhotoPickerListener listener, boolean mult iSelectionAllowed) { 138 PhotoPickerDialog dialog, PhotoPickerListener listener, boolean mult iSelectionAllowed) {
129 // TODO(finnur): Change selection delegate to support single-selection. 139 // TODO(finnur): Change selection delegate to support single-selection.
130 140
131 mDialog = dialog; 141 mDialog = dialog;
132 mMultiSelectionAllowed = multiSelectionAllowed; 142 mMultiSelectionAllowed = multiSelectionAllowed;
133 mListener = listener; 143 mListener = listener;
134 } 144 }
135 145
146 // FileEnumWorkerTask.FilesEnumeratedCallback:
147
148 @Override
149 public void filesEnumeratedCallback(List<PickerBitmap> files) {
150 mPickerBitmaps = files;
151 if (files != null && files.size() > 0) {
152 mPickerAdapter.notifyDataSetChanged();
153 }
154 }
155
136 // OnMenuItemClickListener: 156 // OnMenuItemClickListener:
137 157
138 @Override 158 @Override
139 public boolean onMenuItemClick(MenuItem item) { 159 public boolean onMenuItemClick(MenuItem item) {
140 if (item.getItemId() == R.id.close_menu_id) { 160 if (item.getItemId() == R.id.close_menu_id) {
141 mListener.onPickerUserAction(PhotoPickerListener.Action.CANCEL, null ); 161 mListener.onPickerUserAction(PhotoPickerListener.Action.CANCEL, null );
142 mDialog.dismiss(); 162 mDialog.dismiss();
143 return true; 163 return true;
144 } else if (item.getItemId() == R.id.selection_mode_done_menu_id) { 164 } else if (item.getItemId() == R.id.selection_mode_done_menu_id) {
145 notifyPhotosSelected(); 165 notifyPhotosSelected();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 // Make sure columns and padding are either both even or both odd. 215 // Make sure columns and padding are either both even or both odd.
196 if (((mColumns % 2) == 0) != ((mPadding % 2) == 0)) { 216 if (((mColumns % 2) == 0) != ((mPadding % 2) == 0)) {
197 mPadding++; 217 mPadding++;
198 } 218 }
199 } 219 }
200 220
201 /** 221 /**
202 * Prepares bitmaps for loading. 222 * Prepares bitmaps for loading.
203 */ 223 */
204 private void prepareBitmaps() { 224 private void prepareBitmaps() {
205 // TODO(finnur): Use worker thread to fetch bitmaps instead of hard-codi ng. 225 if (mWorkerTask != null) {
206 mPickerBitmaps = new ArrayList<>(); 226 mWorkerTask.cancel(true);
207 mPickerBitmaps.add(0, new PickerBitmap("", 0, PickerBitmap.GALLERY)); 227 }
208 mPickerBitmaps.add(0, new PickerBitmap("", 0, PickerBitmap.CAMERA)); 228
209 mPickerBitmaps.add(new PickerBitmap("foo/bar1.jpg", 1, PickerBitmap.PICT URE)); 229 mWorkerTask = new FileEnumWorkerTask(this, new MimeTypeFileFilter("image /*"));
210 mPickerBitmaps.add(new PickerBitmap("foo/bar2.jpg", 2, PickerBitmap.PICT URE)); 230 mWorkerTask.execute();
211 mPickerBitmaps.add(new PickerBitmap("foo/bar3.jpg", 3, PickerBitmap.PICT URE));
212 mPickerBitmaps.add(new PickerBitmap("foo/bar4.jpg", 4, PickerBitmap.PICT URE));
213 mPickerAdapter.notifyDataSetChanged();
214 } 231 }
215 232
216 /** 233 /**
217 * Notifies any listeners that one or more photos have been selected. 234 * Notifies any listeners that one or more photos have been selected.
218 */ 235 */
219 private void notifyPhotosSelected() { 236 private void notifyPhotosSelected() {
220 List<PickerBitmap> selectedFiles = mSelectionDelegate.getSelectedItems() ; 237 List<PickerBitmap> selectedFiles = mSelectionDelegate.getSelectedItems() ;
221 String[] photos = new String[selectedFiles.size()]; 238 String[] photos = new String[selectedFiles.size()];
222 int i = 0; 239 int i = 0;
223 for (PickerBitmap bitmap : selectedFiles) { 240 for (PickerBitmap bitmap : selectedFiles) {
224 photos[i++] = bitmap.getFilePath(); 241 photos[i++] = bitmap.getFilePath();
225 } 242 }
226 243
227 mListener.onPickerUserAction(PhotoPickerListener.Action.PHOTOS_SELECTED, photos); 244 mListener.onPickerUserAction(PhotoPickerListener.Action.PHOTOS_SELECTED, photos);
228 } 245 }
229 } 246 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698