Make Metrics.logKeyboardAction() method take @KeyboardAction type

instead of KeyEvent

Change-Id: Ib9a19532612b679141b6d611e448247d3b0bab23

Fixing: b/27942360
This commit is contained in:
Aga Wronska
2016-04-04 14:02:02 -07:00
parent bcff1431dd
commit d42a9bed93
4 changed files with 15 additions and 38 deletions

View File

@@ -636,12 +636,12 @@ public abstract class BaseActivity extends Activity
return true;
}
} else if (keyCode == KeyEvent.KEYCODE_TAB) {
Metrics.logKeyboardAction(this, keyCode);
Metrics.logKeyboardAction(this, Metrics.ACTION_KEYBOARD_SWITCH_FOCUS);
// Tab toggles focus on the navigation drawer.
toggleNavDrawerFocus();
return true;
} else if (keyCode == KeyEvent.KEYCODE_DEL) {
Metrics.logKeyboardAction(this, keyCode);
Metrics.logKeyboardAction(this, Metrics.ACTION_KEYBOARD_BACK);
popDir();
return true;
}

View File

@@ -349,21 +349,21 @@ public class FilesActivity extends BaseActivity {
case KeyEvent.KEYCODE_A:
dir = getDirectoryFragment();
if (dir != null) {
Metrics.logKeyboardAction(this, keyCode);
Metrics.logKeyboardAction(this, Metrics.ACTION_KEYBOARD_SELECT_ALL);
dir.selectAllFiles();
}
return true;
case KeyEvent.KEYCODE_C:
dir = getDirectoryFragment();
if (dir != null) {
Metrics.logKeyboardAction(this, keyCode);
Metrics.logKeyboardAction(this, Metrics.ACTION_KEYBOARD_COPY);
dir.copySelectedToClipboard();
}
return true;
case KeyEvent.KEYCODE_V:
dir = getDirectoryFragment();
if (dir != null) {
Metrics.logKeyboardAction(this, keyCode);
Metrics.logKeyboardAction(this, Metrics.ACTION_KEYBOARD_PASTE);
dir.pasteFromClipboard();
}
return true;

View File

@@ -296,13 +296,13 @@ public final class Metrics {
// 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;
public static final int ACTION_KEYBOARD_OTHER = 1;
public static final int ACTION_KEYBOARD_PASTE = 2;
public static final int ACTION_KEYBOARD_COPY = 3;
public static final int ACTION_KEYBOARD_DELETE = 4;
public static final int ACTION_KEYBOARD_SELECT_ALL = 5;
public static final int ACTION_KEYBOARD_BACK = 6;
public static final int ACTION_KEYBOARD_SWITCH_FOCUS = 7;
@IntDef(flag = false, value = {
ACTION_KEYBOARD_OTHER,
@@ -525,31 +525,8 @@ public final class Metrics {
* @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);
public static void logKeyboardAction(Context context, @KeyboardAction int action) {
logHistogram(context, COUNT_KEYBOARD_ACTION, action);
}
/**

View File

@@ -1339,7 +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);
Metrics.logKeyboardAction(getContext(), Metrics.ACTION_KEYBOARD_DELETE);
deleteDocuments(mSelectionManager.getSelection());
}
// Always handle the key, even if there was nothing to delete. This is a