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

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: Address feedback from Mark 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;
24 import org.chromium.chrome.browser.util.ConversionUtils;
23 import org.chromium.chrome.browser.widget.selection.SelectableListLayout; 25 import org.chromium.chrome.browser.widget.selection.SelectableListLayout;
24 import org.chromium.chrome.browser.widget.selection.SelectionDelegate; 26 import org.chromium.chrome.browser.widget.selection.SelectionDelegate;
25 import org.chromium.ui.PhotoPickerListener; 27 import org.chromium.ui.PhotoPickerListener;
26 28
27 import java.util.ArrayList; 29 import java.util.ArrayList;
28 import java.util.Arrays; 30 import java.util.Arrays;
29 import java.util.List; 31 import java.util.List;
30 32
31 /** 33 /**
32 * A class for keeping track of common data associated with showing photos in 34 * 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. 35 * the photo picker, for example the RecyclerView and the bitmap caches.
34 */ 36 */
35 public class PickerCategoryView extends RelativeLayout 37 public class PickerCategoryView extends RelativeLayout
36 implements FileEnumWorkerTask.FilesEnumeratedCallback, RecyclerView.Recy clerListener, 38 implements FileEnumWorkerTask.FilesEnumeratedCallback, RecyclerView.Recy clerListener,
37 DecoderServiceHost.ServiceReadyCallback, View.OnClickListener { 39 DecoderServiceHost.ServiceReadyCallback, View.OnClickListener {
38 private static final int KILOBYTE = 1024; 40 // These values are written to logs. New enum values can be added, but exis ting
41 // enums must never be renumbered or deleted and reused.
42 private static final int ACTION_CANCEL = 0;
43 private static final int ACTION_PHOTO_PICKED = 1;
44 private static final int ACTION_NEW_PHOTO = 2;
45 private static final int ACTION_BROWSE = 3;
46 private static final int ACTION_BOUNDARY = 4;
39 47
40 // The dialog that owns us. 48 // The dialog that owns us.
41 private PhotoPickerDialog mDialog; 49 private PhotoPickerDialog mDialog;
42 50
43 // The view containing the RecyclerView and the toolbar, etc. 51 // The view containing the RecyclerView and the toolbar, etc.
44 private SelectableListLayout<PickerBitmap> mSelectableListLayout; 52 private SelectableListLayout<PickerBitmap> mSelectableListLayout;
45 53
46 // Our context. 54 // Our context.
47 private Context mContext; 55 private Context mContext;
48 56
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 doneButton.setOnClickListener(this); 146 doneButton.setOnClickListener(this);
139 147
140 calculateGridMetrics(); 148 calculateGridMetrics();
141 149
142 mLayoutManager = new GridLayoutManager(mContext, mColumns); 150 mLayoutManager = new GridLayoutManager(mContext, mColumns);
143 mRecyclerView.setHasFixedSize(true); 151 mRecyclerView.setHasFixedSize(true);
144 mRecyclerView.setLayoutManager(mLayoutManager); 152 mRecyclerView.setLayoutManager(mLayoutManager);
145 mSpacingDecoration = new GridSpacingItemDecoration(mColumns, mPadding); 153 mSpacingDecoration = new GridSpacingItemDecoration(mColumns, mPadding);
146 mRecyclerView.addItemDecoration(mSpacingDecoration); 154 mRecyclerView.addItemDecoration(mSpacingDecoration);
147 155
148 final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / KILOBYTE ); 156 final long maxMemory = ConversionUtils.bytesToKilobytes(Runtime.getRunti me().maxMemory());
149 final int cacheSizeLarge = maxMemory / 2; // 1/2 of the available memory . 157 final long cacheSizeLarge = maxMemory / 2; // 1/2 of the available memor y.
150 final int cacheSizeSmall = maxMemory / 8; // 1/8th of the available memo ry. 158 final long cacheSizeSmall = maxMemory / 8; // 1/8th of the available mem ory.
151 mLowResBitmaps = new LruCache<String, Bitmap>(cacheSizeSmall); 159 mLowResBitmaps = new LruCache<String, Bitmap>((int) (cacheSizeSmall));
152 mHighResBitmaps = new LruCache<String, Bitmap>(cacheSizeLarge); 160 mHighResBitmaps = new LruCache<String, Bitmap>((int) (cacheSizeLarge));
153 } 161 }
154 162
155 @Override 163 @Override
156 public void onConfigurationChanged(Configuration newConfig) { 164 public void onConfigurationChanged(Configuration newConfig) {
157 super.onConfigurationChanged(newConfig); 165 super.onConfigurationChanged(newConfig);
158 166
159 calculateGridMetrics(); 167 calculateGridMetrics();
160 mLayoutManager.setSpanCount(mColumns); 168 mLayoutManager.setSpanCount(mColumns);
161 mRecyclerView.removeItemDecoration(mSpacingDecoration); 169 mRecyclerView.removeItemDecoration(mSpacingDecoration);
162 mSpacingDecoration = new GridSpacingItemDecoration(mColumns, mPadding); 170 mSpacingDecoration = new GridSpacingItemDecoration(mColumns, mPadding);
(...skipping 25 matching lines...) Expand all
188 PhotoPickerDialog dialog, PhotoPickerListener listener, boolean mult iSelectionAllowed) { 196 PhotoPickerDialog dialog, PhotoPickerListener listener, boolean mult iSelectionAllowed) {
189 if (!multiSelectionAllowed) mSelectionDelegate.setSingleSelectionMode(); 197 if (!multiSelectionAllowed) mSelectionDelegate.setSingleSelectionMode();
190 198
191 mDialog = dialog; 199 mDialog = dialog;
192 mMultiSelectionAllowed = multiSelectionAllowed; 200 mMultiSelectionAllowed = multiSelectionAllowed;
193 mListener = listener; 201 mListener = listener;
194 202
195 mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { 203 mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
196 @Override 204 @Override
197 public void onCancel(DialogInterface dialog) { 205 public void onCancel(DialogInterface dialog) {
206 recordFinalUmaStats(ACTION_CANCEL);
198 mListener.onPickerUserAction(PhotoPickerListener.Action.CANCEL, null); 207 mListener.onPickerUserAction(PhotoPickerListener.Action.CANCEL, null);
199 } 208 }
200 }); 209 });
201 } 210 }
202 211
203 // FileEnumWorkerTask.FilesEnumeratedCallback: 212 // FileEnumWorkerTask.FilesEnumeratedCallback:
204 213
205 @Override 214 @Override
206 public void filesEnumeratedCallback(List<PickerBitmap> files) { 215 public void filesEnumeratedCallback(List<PickerBitmap> files) {
207 mPickerBitmaps = files; 216 mPickerBitmaps = files;
(...skipping 17 matching lines...) Expand all
225 if (filePath != null) { 234 if (filePath != null) {
226 getDecoderServiceHost().cancelDecodeImage(filePath); 235 getDecoderServiceHost().cancelDecodeImage(filePath);
227 } 236 }
228 } 237 }
229 238
230 // OnClickListener: 239 // OnClickListener:
231 240
232 @Override 241 @Override
233 public void onClick(View view) { 242 public void onClick(View view) {
234 if (view.getId() == R.id.done) { 243 if (view.getId() == R.id.done) {
244 recordFinalUmaStats(ACTION_PHOTO_PICKED);
235 notifyPhotosSelected(); 245 notifyPhotosSelected();
236 } else { 246 } else {
247 recordFinalUmaStats(ACTION_CANCEL);
237 mListener.onPickerUserAction(PhotoPickerListener.Action.CANCEL, null ); 248 mListener.onPickerUserAction(PhotoPickerListener.Action.CANCEL, null );
238 } 249 }
239 250
240 mDialog.dismiss(); 251 mDialog.dismiss();
241 } 252 }
242 253
243 /** 254 /**
244 * Start loading of bitmaps, once files have been enumerated and service is 255 * Start loading of bitmaps, once files have been enumerated and service is
245 * ready to decode. 256 * ready to decode.
246 */ 257 */
(...skipping 30 matching lines...) Expand all
277 } 288 }
278 289
279 public boolean isMultiSelectAllowed() { 290 public boolean isMultiSelectAllowed() {
280 return mMultiSelectionAllowed; 291 return mMultiSelectionAllowed;
281 } 292 }
282 293
283 /** 294 /**
284 * Notifies the listener that the user selected to launch the gallery. 295 * Notifies the listener that the user selected to launch the gallery.
285 */ 296 */
286 public void showGallery() { 297 public void showGallery() {
298 recordFinalUmaStats(ACTION_BROWSE);
287 mListener.onPickerUserAction(PhotoPickerListener.Action.LAUNCH_GALLERY, null); 299 mListener.onPickerUserAction(PhotoPickerListener.Action.LAUNCH_GALLERY, null);
288 } 300 }
289 301
290 /** 302 /**
291 * Notifies the listener that the user selected to launch the camera intent. 303 * Notifies the listener that the user selected to launch the camera intent.
292 */ 304 */
293 public void showCamera() { 305 public void showCamera() {
306 recordFinalUmaStats(ACTION_NEW_PHOTO);
294 mListener.onPickerUserAction(PhotoPickerListener.Action.LAUNCH_CAMERA, n ull); 307 mListener.onPickerUserAction(PhotoPickerListener.Action.LAUNCH_CAMERA, n ull);
295 } 308 }
296 309
297 /** 310 /**
298 * Calculates image size and how many columns can fit on-screen. 311 * Calculates image size and how many columns can fit on-screen.
299 */ 312 */
300 private void calculateGridMetrics() { 313 private void calculateGridMetrics() {
301 Rect appRect = new Rect(); 314 Rect appRect = new Rect();
302 ((Activity) mContext).getWindow().getDecorView().getWindowVisibleDisplay Frame(appRect); 315 ((Activity) mContext).getWindow().getDecorView().getWindowVisibleDisplay Frame(appRect);
303 316
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 if (position < mSpanCount) { 389 if (position < mSpanCount) {
377 top = mSpacing; 390 top = mSpacing;
378 } 391 }
379 bottom = mSpacing; 392 bottom = mSpacing;
380 } 393 }
381 394
382 outRect.set(left, top, right, bottom); 395 outRect.set(left, top, right, bottom);
383 } 396 }
384 } 397 }
385 398
399 /**
400 * Record UMA statistics (what action was taken in the dialog and other perf ormance stats).
401 * @param action The action the user took in the dialog.
402 */
403 private void recordFinalUmaStats(int action) {
404 RecordHistogram.recordEnumeratedHistogram(
405 "Android.PhotoPicker.DialogAction", action, ACTION_BOUNDARY);
406 RecordHistogram.recordCountHistogram(
407 "Android.PhotoPicker.DecodeRequests", mPickerAdapter.getDecodeRe questCount());
408 RecordHistogram.recordCountHistogram(
409 "Android.PhotoPicker.CacheHits", mPickerAdapter.getCacheHitCount ());
410 }
411
386 /** Sets a list of files to use as data for the dialog. For testing use only . */ 412 /** Sets a list of files to use as data for the dialog. For testing use only . */
387 @VisibleForTesting 413 @VisibleForTesting
388 public static void setTestFiles(List<PickerBitmap> testFiles) { 414 public static void setTestFiles(List<PickerBitmap> testFiles) {
389 sTestFiles = new ArrayList<>(testFiles); 415 sTestFiles = new ArrayList<>(testFiles);
390 } 416 }
391 417
392 @VisibleForTesting 418 @VisibleForTesting
393 public SelectionDelegate<PickerBitmap> getSelectionDelegateForTesting() { 419 public SelectionDelegate<PickerBitmap> getSelectionDelegateForTesting() {
394 return mSelectionDelegate; 420 return mSelectionDelegate;
395 } 421 }
396 } 422 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698