OLD | NEW |
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.Bitmap; | 9 import android.graphics.Bitmap; |
10 import android.graphics.Rect; | 10 import android.graphics.Rect; |
11 import android.support.v7.widget.GridLayoutManager; | 11 import android.support.v7.widget.GridLayoutManager; |
12 import android.support.v7.widget.RecyclerView; | 12 import android.support.v7.widget.RecyclerView; |
13 import android.util.LruCache; | 13 import android.util.LruCache; |
14 import android.view.LayoutInflater; | 14 import android.view.LayoutInflater; |
15 import android.view.View; | 15 import android.view.View; |
16 import android.widget.Button; | 16 import android.widget.Button; |
17 import android.widget.RelativeLayout; | 17 import android.widget.RelativeLayout; |
18 | 18 |
| 19 import org.chromium.base.VisibleForTesting; |
19 import org.chromium.chrome.R; | 20 import org.chromium.chrome.R; |
20 import org.chromium.chrome.browser.widget.selection.SelectableListLayout; | 21 import org.chromium.chrome.browser.widget.selection.SelectableListLayout; |
21 import org.chromium.chrome.browser.widget.selection.SelectionDelegate; | 22 import org.chromium.chrome.browser.widget.selection.SelectionDelegate; |
22 import org.chromium.ui.PhotoPickerListener; | 23 import org.chromium.ui.PhotoPickerListener; |
23 | 24 |
| 25 import java.util.ArrayList; |
24 import java.util.Arrays; | 26 import java.util.Arrays; |
25 import java.util.List; | 27 import java.util.List; |
26 | 28 |
27 /** | 29 /** |
28 * A class for keeping track of common data associated with showing photos in | 30 * 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. | 31 * the photo picker, for example the RecyclerView and the bitmap caches. |
30 */ | 32 */ |
31 public class PickerCategoryView extends RelativeLayout | 33 public class PickerCategoryView extends RelativeLayout |
32 implements FileEnumWorkerTask.FilesEnumeratedCallback, RecyclerView.Recy
clerListener, | 34 implements FileEnumWorkerTask.FilesEnumeratedCallback, RecyclerView.Recy
clerListener, |
33 DecoderServiceHost.ServiceReadyCallback, View.OnClickListener
{ | 35 DecoderServiceHost.ServiceReadyCallback, View.OnClickListener
{ |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 85 |
84 // The size of the bitmaps (equal length for width and height). | 86 // The size of the bitmaps (equal length for width and height). |
85 private int mImageSize; | 87 private int mImageSize; |
86 | 88 |
87 // A worker task for asynchronously enumerating files off the main thread. | 89 // A worker task for asynchronously enumerating files off the main thread. |
88 private FileEnumWorkerTask mWorkerTask; | 90 private FileEnumWorkerTask mWorkerTask; |
89 | 91 |
90 // Whether the connection to the service has been established. | 92 // Whether the connection to the service has been established. |
91 private boolean mServiceReady; | 93 private boolean mServiceReady; |
92 | 94 |
| 95 // A list of files to use for testing (instead of reading files on disk). |
| 96 private static List<PickerBitmap> sTestFiles; |
| 97 |
93 public PickerCategoryView(Context context) { | 98 public PickerCategoryView(Context context) { |
94 super(context); | 99 super(context); |
95 postConstruction(context); | 100 postConstruction(context); |
96 } | 101 } |
97 | 102 |
98 /** | 103 /** |
99 * A helper function for initializing the PickerCategoryView. | 104 * A helper function for initializing the PickerCategoryView. |
100 * @param context The context to use. | 105 * @param context The context to use. |
101 */ | 106 */ |
102 @SuppressWarnings("unchecked") // mSelectableListLayout | 107 @SuppressWarnings("unchecked") // mSelectableListLayout |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 // Make sure columns and padding are either both even or both odd. | 283 // Make sure columns and padding are either both even or both odd. |
279 if (((mColumns % 2) == 0) != ((mPadding % 2) == 0)) { | 284 if (((mColumns % 2) == 0) != ((mPadding % 2) == 0)) { |
280 mPadding++; | 285 mPadding++; |
281 } | 286 } |
282 } | 287 } |
283 | 288 |
284 /** | 289 /** |
285 * Asynchronously enumerates bitmaps on disk. | 290 * Asynchronously enumerates bitmaps on disk. |
286 */ | 291 */ |
287 private void enumerateBitmaps() { | 292 private void enumerateBitmaps() { |
| 293 if (sTestFiles != null) { |
| 294 filesEnumeratedCallback(sTestFiles); |
| 295 return; |
| 296 } |
| 297 |
288 if (mWorkerTask != null) { | 298 if (mWorkerTask != null) { |
289 mWorkerTask.cancel(true); | 299 mWorkerTask.cancel(true); |
290 } | 300 } |
291 | 301 |
292 mWorkerTask = | 302 mWorkerTask = |
293 new FileEnumWorkerTask(this, new MimeTypeFileFilter(Arrays.asLis
t("image/*"))); | 303 new FileEnumWorkerTask(this, new MimeTypeFileFilter(Arrays.asLis
t("image/*"))); |
294 mWorkerTask.execute(); | 304 mWorkerTask.execute(); |
295 } | 305 } |
296 | 306 |
297 /** | 307 /** |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 347 |
338 if (position < mSpanCount) { | 348 if (position < mSpanCount) { |
339 top = mSpacing; | 349 top = mSpacing; |
340 } | 350 } |
341 bottom = mSpacing; | 351 bottom = mSpacing; |
342 } | 352 } |
343 | 353 |
344 outRect.set(left, top, right, bottom); | 354 outRect.set(left, top, right, bottom); |
345 } | 355 } |
346 } | 356 } |
| 357 |
| 358 /** Sets a list of files to use as data for the dialog. For testing use only
. */ |
| 359 @VisibleForTesting |
| 360 public static void setTestFiles(List<PickerBitmap> testFiles) { |
| 361 sTestFiles = new ArrayList<>(testFiles); |
| 362 } |
| 363 |
| 364 @VisibleForTesting |
| 365 public SelectionDelegate<PickerBitmap> getSelectionDelegateForTesting() { |
| 366 return mSelectionDelegate; |
| 367 } |
347 } | 368 } |
OLD | NEW |