diff options
author | 2016-03-31 15:08:43 -0700 | |
---|---|---|
committer | 2016-04-01 13:34:46 -0700 | |
commit | fa1832e469b544015e141d7be44e4d5b38708bb5 (patch) | |
tree | 136592fa17123321513f1e7dd73c6bafbd50de45 | |
parent | 4972d71090b4e98951102ddd37fad95052525786 (diff) |
Add metrics for keyboard shortcuts
Change-Id: I3a63efd856f25cc33d61b734970675b77645a26d
Fixed: 27942360
-rw-r--r-- | src/com/android/documentsui/BaseActivity.java | 2 | ||||
-rw-r--r-- | src/com/android/documentsui/FilesActivity.java | 3 | ||||
-rw-r--r-- | src/com/android/documentsui/Metrics.java | 60 | ||||
-rw-r--r-- | src/com/android/documentsui/dirlist/DirectoryFragment.java | 1 |
4 files changed, 66 insertions, 0 deletions
diff --git a/src/com/android/documentsui/BaseActivity.java b/src/com/android/documentsui/BaseActivity.java index 9606eab54..87136ef35 100644 --- a/src/com/android/documentsui/BaseActivity.java +++ b/src/com/android/documentsui/BaseActivity.java @@ -636,10 +636,12 @@ public abstract class BaseActivity extends Activity return true; } } else if (keyCode == KeyEvent.KEYCODE_TAB) { + Metrics.logKeyboardAction(this, keyCode); // Tab toggles focus on the navigation drawer. toggleNavDrawerFocus(); return true; } else if (keyCode == KeyEvent.KEYCODE_DEL) { + Metrics.logKeyboardAction(this, keyCode); popDir(); return true; } diff --git a/src/com/android/documentsui/FilesActivity.java b/src/com/android/documentsui/FilesActivity.java index e7d7ec432..d4439d8b4 100644 --- a/src/com/android/documentsui/FilesActivity.java +++ b/src/com/android/documentsui/FilesActivity.java @@ -349,18 +349,21 @@ public class FilesActivity extends BaseActivity { case KeyEvent.KEYCODE_A: dir = getDirectoryFragment(); if (dir != null) { + Metrics.logKeyboardAction(this, keyCode); dir.selectAllFiles(); } return true; case KeyEvent.KEYCODE_C: dir = getDirectoryFragment(); if (dir != null) { + Metrics.logKeyboardAction(this, keyCode); dir.copySelectedToClipboard(); } return true; case KeyEvent.KEYCODE_V: dir = getDirectoryFragment(); if (dir != null) { + Metrics.logKeyboardAction(this, keyCode); dir.pasteFromClipboard(); } return true; diff --git a/src/com/android/documentsui/Metrics.java b/src/com/android/documentsui/Metrics.java index 1e01c2205..a4a67f96a 100644 --- a/src/com/android/documentsui/Metrics.java +++ b/src/com/android/documentsui/Metrics.java @@ -29,6 +29,7 @@ import android.content.pm.ResolveInfo; import android.net.Uri; import android.provider.DocumentsContract; import android.util.Log; +import android.view.KeyEvent; import com.android.documentsui.State.ActionType; import com.android.documentsui.model.DocumentInfo; @@ -70,6 +71,7 @@ public final class Metrics { private static final String COUNT_DRAG_N_DROP = "docsui_drag_n_drop"; private static final String COUNT_SEARCH = "docsui_search"; private static final String COUNT_MENU_ACTION = "docsui_menu_action"; + private static final String COUNT_KEYBOARD_ACTION = "docsui_keyboard_action"; // Indices for bucketing roots in the roots histogram. "Other" is the catch-all index for any // root that is not explicitly recognized by the Metrics code (see {@link @@ -289,6 +291,31 @@ public final class Metrics { @Retention(RetentionPolicy.SOURCE) public @interface MetricsAction {} + // Codes representing different keyboard shortcut triggered actions. These are used for + // bucketing stats in the COUNT_KEYBOARD_ACTION histogram. + // Do not change or rearrange these values, that will break historical data. Only add to the + // list. + // Do not use negative numbers or zero; clearcut only handles positive integers. + private static final int ACTION_KEYBOARD_OTHER = 1; + private static final int ACTION_KEYBOARD_PASTE = 2; + private static final int ACTION_KEYBOARD_COPY = 3; + private static final int ACTION_KEYBOARD_DELETE = 4; + private static final int ACTION_KEYBOARD_SELECT_ALL = 5; + private static final int ACTION_KEYBOARD_BACK = 6; + private static final int ACTION_KEYBOARD_SWITCH_FOCUS = 7; + + @IntDef(flag = false, value = { + ACTION_KEYBOARD_OTHER, + ACTION_KEYBOARD_PASTE, + ACTION_KEYBOARD_COPY, + ACTION_KEYBOARD_DELETE, + ACTION_KEYBOARD_SELECT_ALL, + ACTION_KEYBOARD_BACK, + ACTION_KEYBOARD_SWITCH_FOCUS + }) + @Retention(RetentionPolicy.SOURCE) + public @interface KeyboardAction {} + // Codes representing different actions to open the drawer. They are used for bucketing stats in // the COUNT_DRAWER_OPENED histogram. // Do not change or rearrange these values, that will break historical data. Only add to the @@ -493,6 +520,39 @@ public final class Metrics { } /** + * Logs keyboard shortcut actions. Since keyboard shortcuts have their corresponding menu items, + * they are identified by menu item resource id for convenience. + * @param context + * @param keyCode + */ + public static void logKeyboardAction(Context context, int keyCode) { + @KeyboardAction int keyboardAction = ACTION_KEYBOARD_OTHER; + switch (keyCode) { + case KeyEvent.KEYCODE_V: + keyboardAction = ACTION_KEYBOARD_PASTE; + break; + case KeyEvent.KEYCODE_C: + keyboardAction = ACTION_KEYBOARD_COPY; + break; + case KeyEvent.KEYCODE_FORWARD_DEL: + keyboardAction = ACTION_KEYBOARD_DELETE; + break; + case KeyEvent.KEYCODE_A: + keyboardAction = ACTION_KEYBOARD_SELECT_ALL; + break; + case KeyEvent.KEYCODE_DEL: + keyboardAction = ACTION_KEYBOARD_BACK; + break; + case KeyEvent.KEYCODE_TAB: + keyboardAction = ACTION_KEYBOARD_SWITCH_FOCUS; + break; + default: + break; + } + logHistogram(context, COUNT_KEYBOARD_ACTION, keyboardAction); + } + + /** * Logs startup time in milliseconds. * @param context * @param startupMs Startup time in milliseconds. diff --git a/src/com/android/documentsui/dirlist/DirectoryFragment.java b/src/com/android/documentsui/dirlist/DirectoryFragment.java index d70a899c3..20316fff3 100644 --- a/src/com/android/documentsui/dirlist/DirectoryFragment.java +++ b/src/com/android/documentsui/dirlist/DirectoryFragment.java @@ -1339,6 +1339,7 @@ public class DirectoryFragment extends Fragment // This has to be handled here instead of in a keyboard shortcut, because // keyboard shortcuts all have to be modified with the 'Ctrl' key. if (mSelectionManager.hasSelection()) { + Metrics.logKeyboardAction(getContext(), keyCode); deleteDocuments(mSelectionManager.getSelection()); } // Always handle the key, even if there was nothing to delete. This is a |