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

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: Augment comment 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
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 */ 129 */
127 public void initialize( 130 public void initialize(
128 PhotoPickerDialog dialog, PhotoPickerListener listener, boolean mult iSelectionAllowed) { 131 PhotoPickerDialog dialog, PhotoPickerListener listener, boolean mult iSelectionAllowed) {
129 // TODO(finnur): Change selection delegate to support single-selection. 132 // TODO(finnur): Change selection delegate to support single-selection.
130 133
131 mDialog = dialog; 134 mDialog = dialog;
132 mMultiSelectionAllowed = multiSelectionAllowed; 135 mMultiSelectionAllowed = multiSelectionAllowed;
133 mListener = listener; 136 mListener = listener;
134 } 137 }
135 138
139 // FileEnumWorkerTask.FilesEnumeratedCallback:
140
141 @Override
142 public void filesEnumeratedCallback(List<PickerBitmap> files) {
143 mPickerBitmaps = files;
144 if (files != null && files.size() > 0) {
145 mPickerAdapter.notifyDataSetChanged();
146 } else {
147 setVisibility(View.GONE);
Theresa 2017/04/10 18:01:14 If there are no files, we will still display the g
Finnur 2017/04/11 11:30:57 Ah, yes. I thought I'd deleted that line. Good cat
148 }
149 }
150
136 // OnMenuItemClickListener: 151 // OnMenuItemClickListener:
137 152
138 @Override 153 @Override
139 public boolean onMenuItemClick(MenuItem item) { 154 public boolean onMenuItemClick(MenuItem item) {
140 if (item.getItemId() == R.id.close_menu_id) { 155 if (item.getItemId() == R.id.close_menu_id) {
141 mListener.onPickerUserAction(PhotoPickerListener.Action.CANCEL, null ); 156 mListener.onPickerUserAction(PhotoPickerListener.Action.CANCEL, null );
142 mDialog.dismiss(); 157 mDialog.dismiss();
143 return true; 158 return true;
144 } else if (item.getItemId() == R.id.selection_mode_done_menu_id) { 159 } else if (item.getItemId() == R.id.selection_mode_done_menu_id) {
145 notifyPhotosSelected(); 160 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. 210 // Make sure columns and padding are either both even or both odd.
196 if (((mColumns % 2) == 0) != ((mPadding % 2) == 0)) { 211 if (((mColumns % 2) == 0) != ((mPadding % 2) == 0)) {
197 mPadding++; 212 mPadding++;
198 } 213 }
199 } 214 }
200 215
201 /** 216 /**
202 * Prepares bitmaps for loading. 217 * Prepares bitmaps for loading.
203 */ 218 */
204 private void prepareBitmaps() { 219 private void prepareBitmaps() {
205 // TODO(finnur): Use worker thread to fetch bitmaps instead of hard-codi ng. 220 if (mWorkerTask != null) {
206 mPickerBitmaps = new ArrayList<>(); 221 mWorkerTask.cancel(true);
207 mPickerBitmaps.add(0, new PickerBitmap("", 0, PickerBitmap.GALLERY)); 222 }
208 mPickerBitmaps.add(0, new PickerBitmap("", 0, PickerBitmap.CAMERA)); 223
209 mPickerBitmaps.add(new PickerBitmap("foo/bar1.jpg", 1, PickerBitmap.PICT URE)); 224 mWorkerTask = new FileEnumWorkerTask(this, new AttrAcceptFileFilter("ima ge/*,video/*"));
210 mPickerBitmaps.add(new PickerBitmap("foo/bar2.jpg", 2, PickerBitmap.PICT URE)); 225 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 } 226 }
215 227
216 /** 228 /**
217 * Notifies any listeners that one or more photos have been selected. 229 * Notifies any listeners that one or more photos have been selected.
218 */ 230 */
219 private void notifyPhotosSelected() { 231 private void notifyPhotosSelected() {
220 List<PickerBitmap> selectedFiles = mSelectionDelegate.getSelectedItems() ; 232 List<PickerBitmap> selectedFiles = mSelectionDelegate.getSelectedItems() ;
221 String[] photos = new String[selectedFiles.size()]; 233 String[] photos = new String[selectedFiles.size()];
222 int i = 0; 234 int i = 0;
223 for (PickerBitmap bitmap : selectedFiles) { 235 for (PickerBitmap bitmap : selectedFiles) {
224 photos[i++] = bitmap.getFilePath(); 236 photos[i++] = bitmap.getFilePath();
225 } 237 }
226 238
227 mListener.onPickerUserAction(PhotoPickerListener.Action.PHOTOS_SELECTED, photos); 239 mListener.onPickerUserAction(PhotoPickerListener.Action.PHOTOS_SELECTED, photos);
228 } 240 }
229 } 241 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698