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

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

Issue 2915863002: Photo Picker dialog: Add UMA statistics. (Closed)
Patch Set: Created 3 years, 6 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.content.DialogInterface; 9 import android.content.DialogInterface;
10 import android.content.res.Configuration; 10 import android.content.res.Configuration;
11 import android.graphics.Bitmap; 11 import android.graphics.Bitmap;
12 import android.graphics.Rect; 12 import android.graphics.Rect;
13 import android.support.v7.widget.GridLayoutManager; 13 import android.support.v7.widget.GridLayoutManager;
14 import android.support.v7.widget.RecyclerView; 14 import android.support.v7.widget.RecyclerView;
15 import android.util.LruCache; 15 import android.util.LruCache;
16 import android.view.LayoutInflater; 16 import android.view.LayoutInflater;
17 import android.view.View; 17 import android.view.View;
18 import android.widget.Button; 18 import android.widget.Button;
19 import android.widget.RelativeLayout; 19 import android.widget.RelativeLayout;
20 20
21 import org.chromium.base.VisibleForTesting; 21 import org.chromium.base.VisibleForTesting;
22 import org.chromium.base.metrics.RecordHistogram;
22 import org.chromium.chrome.R; 23 import org.chromium.chrome.R;
23 import org.chromium.chrome.browser.widget.selection.SelectableListLayout; 24 import org.chromium.chrome.browser.widget.selection.SelectableListLayout;
24 import org.chromium.chrome.browser.widget.selection.SelectionDelegate; 25 import org.chromium.chrome.browser.widget.selection.SelectionDelegate;
25 import org.chromium.ui.PhotoPickerListener; 26 import org.chromium.ui.PhotoPickerListener;
26 27
27 import java.util.ArrayList; 28 import java.util.ArrayList;
28 import java.util.Arrays; 29 import java.util.Arrays;
29 import java.util.List; 30 import java.util.List;
30 31
31 /** 32 /**
32 * A class for keeping track of common data associated with showing photos in 33 * A class for keeping track of common data associated with showing photos in
33 * the photo picker, for example the RecyclerView and the bitmap caches. 34 * the photo picker, for example the RecyclerView and the bitmap caches.
34 */ 35 */
35 public class PickerCategoryView extends RelativeLayout 36 public class PickerCategoryView extends RelativeLayout
36 implements FileEnumWorkerTask.FilesEnumeratedCallback, RecyclerView.Recy clerListener, 37 implements FileEnumWorkerTask.FilesEnumeratedCallback, RecyclerView.Recy clerListener,
37 DecoderServiceHost.ServiceReadyCallback, View.OnClickListener { 38 DecoderServiceHost.ServiceReadyCallback, View.OnClickListener {
38 private static final int KILOBYTE = 1024; 39 private static final int KILOBYTE = 1024;
39 40
41 // The UMA key for tracking the actions taken in the dialog.
42 private static final String HISTOGRAM_NAME = "Android.PhotoPicker.DialogActi on";
Theresa 2017/05/31 18:40:02 optional nit: The downside to using a static final
Finnur 2017/06/01 15:13:55 Done.
43
44 // Note: these values must match the PhotoPickerDialogAction enum values in histograms.xml.
45 // Only add new values at the end, right before ACTIONS. We depend on these specific values in
46 // UMA histograms.
47 private static final int ACTION_CANCEL = 0;
48 private static final int ACTION_PHOTO_PICKED = 1;
49 private static final int ACTION_NEW_PHOTO = 2;
50 private static final int ACTION_BROWSE = 3;
51 private static final int NUM_ACTIONS = 4;
Theresa 2017/05/31 18:40:02 nit: ACTIONS_BOUNDARY is more consistent with how
Finnur 2017/06/01 15:13:55 Done.
52
40 // The dialog that owns us. 53 // The dialog that owns us.
41 private PhotoPickerDialog mDialog; 54 private PhotoPickerDialog mDialog;
42 55
43 // The view containing the RecyclerView and the toolbar, etc. 56 // The view containing the RecyclerView and the toolbar, etc.
44 private SelectableListLayout<PickerBitmap> mSelectableListLayout; 57 private SelectableListLayout<PickerBitmap> mSelectableListLayout;
45 58
46 // Our context. 59 // Our context.
47 private Context mContext; 60 private Context mContext;
48 61
49 // The list of images on disk, sorted by last-modified first. 62 // The list of images on disk, sorted by last-modified first.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 PhotoPickerDialog dialog, PhotoPickerListener listener, boolean mult iSelectionAllowed) { 201 PhotoPickerDialog dialog, PhotoPickerListener listener, boolean mult iSelectionAllowed) {
189 if (!multiSelectionAllowed) mSelectionDelegate.setSingleSelectionMode(); 202 if (!multiSelectionAllowed) mSelectionDelegate.setSingleSelectionMode();
190 203
191 mDialog = dialog; 204 mDialog = dialog;
192 mMultiSelectionAllowed = multiSelectionAllowed; 205 mMultiSelectionAllowed = multiSelectionAllowed;
193 mListener = listener; 206 mListener = listener;
194 207
195 mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { 208 mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
196 @Override 209 @Override
197 public void onCancel(DialogInterface dialog) { 210 public void onCancel(DialogInterface dialog) {
211 RecordHistogram.recordEnumeratedHistogram(
212 HISTOGRAM_NAME, ACTION_CANCEL, NUM_ACTIONS);
198 mListener.onPickerUserAction(PhotoPickerListener.Action.CANCEL, null); 213 mListener.onPickerUserAction(PhotoPickerListener.Action.CANCEL, null);
199 } 214 }
200 }); 215 });
201 } 216 }
202 217
203 // FileEnumWorkerTask.FilesEnumeratedCallback: 218 // FileEnumWorkerTask.FilesEnumeratedCallback:
204 219
205 @Override 220 @Override
206 public void filesEnumeratedCallback(List<PickerBitmap> files) { 221 public void filesEnumeratedCallback(List<PickerBitmap> files) {
207 mPickerBitmaps = files; 222 mPickerBitmaps = files;
(...skipping 17 matching lines...) Expand all
225 if (filePath != null) { 240 if (filePath != null) {
226 getDecoderServiceHost().cancelDecodeImage(filePath); 241 getDecoderServiceHost().cancelDecodeImage(filePath);
227 } 242 }
228 } 243 }
229 244
230 // OnClickListener: 245 // OnClickListener:
231 246
232 @Override 247 @Override
233 public void onClick(View view) { 248 public void onClick(View view) {
234 if (view.getId() == R.id.done) { 249 if (view.getId() == R.id.done) {
250 RecordHistogram.recordEnumeratedHistogram(
251 HISTOGRAM_NAME, ACTION_PHOTO_PICKED, NUM_ACTIONS);
235 notifyPhotosSelected(); 252 notifyPhotosSelected();
236 } else { 253 } else {
254 RecordHistogram.recordEnumeratedHistogram(HISTOGRAM_NAME, ACTION_CAN CEL, NUM_ACTIONS);
237 mListener.onPickerUserAction(PhotoPickerListener.Action.CANCEL, null ); 255 mListener.onPickerUserAction(PhotoPickerListener.Action.CANCEL, null );
238 } 256 }
239 257
240 mDialog.dismiss(); 258 mDialog.dismiss();
241 } 259 }
242 260
243 /** 261 /**
244 * Start loading of bitmaps, once files have been enumerated and service is 262 * Start loading of bitmaps, once files have been enumerated and service is
245 * ready to decode. 263 * ready to decode.
246 */ 264 */
(...skipping 30 matching lines...) Expand all
277 } 295 }
278 296
279 public boolean isMultiSelectAllowed() { 297 public boolean isMultiSelectAllowed() {
280 return mMultiSelectionAllowed; 298 return mMultiSelectionAllowed;
281 } 299 }
282 300
283 /** 301 /**
284 * Notifies the listener that the user selected to launch the gallery. 302 * Notifies the listener that the user selected to launch the gallery.
285 */ 303 */
286 public void showGallery() { 304 public void showGallery() {
305 RecordHistogram.recordEnumeratedHistogram(HISTOGRAM_NAME, ACTION_BROWSE, NUM_ACTIONS);
287 mListener.onPickerUserAction(PhotoPickerListener.Action.LAUNCH_GALLERY, null); 306 mListener.onPickerUserAction(PhotoPickerListener.Action.LAUNCH_GALLERY, null);
288 } 307 }
289 308
290 /** 309 /**
291 * Notifies the listener that the user selected to launch the camera intent. 310 * Notifies the listener that the user selected to launch the camera intent.
292 */ 311 */
293 public void showCamera() { 312 public void showCamera() {
313 RecordHistogram.recordEnumeratedHistogram(HISTOGRAM_NAME, ACTION_NEW_PHO TO, NUM_ACTIONS);
294 mListener.onPickerUserAction(PhotoPickerListener.Action.LAUNCH_CAMERA, n ull); 314 mListener.onPickerUserAction(PhotoPickerListener.Action.LAUNCH_CAMERA, n ull);
295 } 315 }
296 316
297 /** 317 /**
298 * Calculates image size and how many columns can fit on-screen. 318 * Calculates image size and how many columns can fit on-screen.
299 */ 319 */
300 private void calculateGridMetrics() { 320 private void calculateGridMetrics() {
301 Rect appRect = new Rect(); 321 Rect appRect = new Rect();
302 ((Activity) mContext).getWindow().getDecorView().getWindowVisibleDisplay Frame(appRect); 322 ((Activity) mContext).getWindow().getDecorView().getWindowVisibleDisplay Frame(appRect);
303 323
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 @VisibleForTesting 407 @VisibleForTesting
388 public static void setTestFiles(List<PickerBitmap> testFiles) { 408 public static void setTestFiles(List<PickerBitmap> testFiles) {
389 sTestFiles = new ArrayList<>(testFiles); 409 sTestFiles = new ArrayList<>(testFiles);
390 } 410 }
391 411
392 @VisibleForTesting 412 @VisibleForTesting
393 public SelectionDelegate<PickerBitmap> getSelectionDelegateForTesting() { 413 public SelectionDelegate<PickerBitmap> getSelectionDelegateForTesting() {
394 return mSelectionDelegate; 414 return mSelectionDelegate;
395 } 415 }
396 } 416 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698