Consolidating a few log util methods
LoggerUtils had a lot of methods with same name and similar arguments
but completely different behavior.
Instead only defining macros in LoggerUtils and movoing the action
logic in the UserEventDispatcher.
Change-Id: Ibce8ea1a0890499b47c950930accb9b28473f44c
diff --git a/src/com/android/launcher3/logging/LoggerUtils.java b/src/com/android/launcher3/logging/LoggerUtils.java
index 395daa5..f1a12ff 100644
--- a/src/com/android/launcher3/logging/LoggerUtils.java
+++ b/src/com/android/launcher3/logging/LoggerUtils.java
@@ -10,6 +10,7 @@
import com.android.launcher3.UninstallDropTarget;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
+import com.android.launcher3.userevent.nano.LauncherLogProto.LauncherEvent;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
/**
@@ -153,88 +154,14 @@
return str + " id=" + t.pageIndex;
}
- /**
- * Used for launching an event by tapping on an icon.
- */
- public static LauncherLogProto.LauncherEvent initLauncherEvent(
- int actionType,
- View v,
- int parentTargetType){
- LauncherLogProto.LauncherEvent event = new LauncherLogProto.LauncherEvent();
-
- event.srcTarget = new LauncherLogProto.Target[2];
- event.srcTarget[0] = initTarget(v);
- event.srcTarget[1] = new LauncherLogProto.Target();
- event.srcTarget[1].type = parentTargetType;
-
- event.action = new LauncherLogProto.Action();
- event.action.type = actionType;
- return event;
+ public static Target newItemTarget(View v) {
+ return (v.getTag() instanceof ItemInfo)
+ ? newItemTarget((ItemInfo) v.getTag())
+ : newTarget(Target.ITEM);
}
- /**
- * Used for clicking on controls and buttons.
- */
- public static LauncherLogProto.LauncherEvent initLauncherEvent(
- int actionType,
- int childTargetType){
- LauncherLogProto.LauncherEvent event = new LauncherLogProto.LauncherEvent();
-
- event.srcTarget = new LauncherLogProto.Target[1];
- event.srcTarget[0] = new LauncherLogProto.Target();
- event.srcTarget[0].type = childTargetType;
-
- event.action = new LauncherLogProto.Action();
- event.action.type = actionType;
- return event;
- }
-
- /**
- * Used for commands.
- */
- public static LauncherLogProto.LauncherEvent initLauncherEvent(int command,
- boolean createSrcTarget) {
- LauncherLogProto.LauncherEvent event = new LauncherLogProto.LauncherEvent();
- event.action = new LauncherLogProto.Action();
- event.action.type = Action.COMMAND;
- event.action.command = command;
- event.srcTarget = null;
-
- if (createSrcTarget) {
- event.srcTarget = new LauncherLogProto.Target[1];
- event.srcTarget[0] = new LauncherLogProto.Target();
- event.srcTarget[0].type = Target.CONTAINER;
- }
- return event;
- }
-
- /**
- * Used for drag and drop interaction.
- */
- public static LauncherLogProto.LauncherEvent initLauncherEvent(
- int actionType,
- ItemInfo info,
- int parentSrcTargetType,
- View parentDestTargetType){
- LauncherLogProto.LauncherEvent event = new LauncherLogProto.LauncherEvent();
-
- event.srcTarget = new LauncherLogProto.Target[2];
- event.srcTarget[0] = initTarget(info);
- event.srcTarget[1] = new LauncherLogProto.Target();
- event.srcTarget[1].type = parentSrcTargetType;
-
- event.destTarget = new LauncherLogProto.Target[2];
- event.destTarget[0] = initTarget(info);
- event.destTarget[1] = initDropTarget(parentDestTargetType);
-
- event.action = new LauncherLogProto.Action();
- event.action.type = actionType;
- return event;
- }
-
- private static Target initTarget(ItemInfo info) {
- Target t = new LauncherLogProto.Target();
- t.type = Target.ITEM;
+ public static Target newItemTarget(ItemInfo info) {
+ Target t = newTarget(Target.ITEM);
switch (info.itemType) {
case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
t.itemType = LauncherLogProto.APP_ICON;
@@ -255,13 +182,11 @@
return t;
}
- private static Target initDropTarget(View v) {
- Target t = new LauncherLogProto.Target();
- t.type = (v instanceof ButtonDropTarget)? Target.CONTROL : Target.CONTAINER;
- if (t.type == Target.CONTAINER) {
- return t;
+ public static Target newDropTarget(View v) {
+ if (!(v instanceof ButtonDropTarget)) {
+ return newTarget(Target.CONTAINER);
}
-
+ Target t = newTarget(Target.CONTROL);
if (v instanceof InfoDropTarget) {
t.controlType = LauncherLogProto.APPINFO_TARGET;
} else if (v instanceof UninstallDropTarget) {
@@ -272,12 +197,37 @@
return t;
}
- private static Target initTarget(View v) {
+ public static Target newTarget(int targetType) {
Target t = new LauncherLogProto.Target();
- t.type = Target.ITEM;
- if (!(v.getTag() instanceof ItemInfo)) {
- return t;
- }
- return initTarget((ItemInfo) v.getTag());
+ t.type = targetType;
+ return t;
+ }
+ public static Target newContainerTarget(int containerType) {
+ Target t = newTarget(Target.CONTAINER);
+ t.containerType = containerType;
+ return t;
+ }
+
+ public static Action newAction(int type) {
+ Action a = new Action();
+ a.type = type;
+ return a;
+ }
+ public static Action newCommandAction(int command) {
+ Action a = newAction(Action.COMMAND);
+ a.command = command;
+ return a;
+ }
+ public static Action newTouchAction(int touch) {
+ Action a = newAction(Action.TOUCH);
+ a.touch = touch;
+ return a;
+ }
+
+ public static LauncherEvent newLauncherEvent(Action action, Target... srcTargets) {
+ LauncherLogProto.LauncherEvent event = new LauncherLogProto.LauncherEvent();
+ event.srcTarget = srcTargets;
+ event.action = action;
+ return event;
}
}
diff --git a/src/com/android/launcher3/logging/UserEventDispatcher.java b/src/com/android/launcher3/logging/UserEventDispatcher.java
index 2fcdd39..4bc5819 100644
--- a/src/com/android/launcher3/logging/UserEventDispatcher.java
+++ b/src/com/android/launcher3/logging/UserEventDispatcher.java
@@ -36,6 +36,14 @@
import java.util.List;
import java.util.Locale;
+import static com.android.launcher3.logging.LoggerUtils.newCommandAction;
+import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
+import static com.android.launcher3.logging.LoggerUtils.newDropTarget;
+import static com.android.launcher3.logging.LoggerUtils.newItemTarget;
+import static com.android.launcher3.logging.LoggerUtils.newLauncherEvent;
+import static com.android.launcher3.logging.LoggerUtils.newTarget;
+import static com.android.launcher3.logging.LoggerUtils.newTouchAction;
+
/**
* Manages the creation of {@link LauncherEvent}.
* To debug this class, execute following command before side loading a new apk.
@@ -113,9 +121,8 @@
// --------------------------------------------------------------
protected LauncherEvent createLauncherEvent(View v, Intent intent) {
- LauncherEvent event = LoggerUtils.initLauncherEvent(
- Action.TOUCH, v, Target.CONTAINER);
- event.action.touch = Action.TAP;
+ LauncherEvent event = newLauncherEvent(newTouchAction(Action.TAP),
+ newItemTarget(v), newTarget(Target.CONTAINER));
// TODO: make idx percolate up the view hierarchy if needed.
int idx = 0;
@@ -159,8 +166,8 @@
}
public void logActionCommand(int command, int containerType, int pageIndex) {
- LauncherEvent event = LoggerUtils.initLauncherEvent(command, true);
- event.srcTarget[0].containerType = containerType;
+ LauncherEvent event = newLauncherEvent(
+ newCommandAction(command), newContainerTarget(containerType));
event.srcTarget[0].pageIndex = pageIndex;
dispatchUserEvent(event, null);
}
@@ -169,9 +176,9 @@
* TODO: Make this function work when a container view is passed as the 2nd param.
*/
public void logActionCommand(int command, View itemView, int containerType) {
- LauncherEvent event = LoggerUtils.initLauncherEvent(Action.COMMAND, itemView,
- Target.CONTAINER);
- event.action.command = command;
+ LauncherEvent event = newLauncherEvent(
+ newCommandAction(command), newItemTarget(itemView), newTarget(Target.CONTAINER));
+
if (fillInLogContainerData(event, itemView)) {
// TODO: Remove the following two lines once fillInLogContainerData can take in a
// container view.
@@ -182,8 +189,7 @@
}
public void logActionOnControl(int action, int controlType) {
- LauncherEvent event = LoggerUtils.initLauncherEvent(Action.TOUCH, Target.CONTROL);
- event.action.touch = action;
+ LauncherEvent event = newLauncherEvent(newTouchAction(action), newTarget(Target.CONTROL));
event.srcTarget[0].controlType = controlType;
dispatchUserEvent(event, null);
}
@@ -193,24 +199,22 @@
}
public void logActionOnContainer(int action, int dir, int containerType, int pageIndex) {
- LauncherEvent event = LoggerUtils.initLauncherEvent(Action.TOUCH, Target.CONTAINER);
- event.action.touch = action;
+ LauncherEvent event = newLauncherEvent(newTouchAction(action),
+ newContainerTarget(containerType));
event.action.dir = dir;
- event.srcTarget[0].containerType = containerType;
event.srcTarget[0].pageIndex = pageIndex;
dispatchUserEvent(event, null);
}
public void logDeepShortcutsOpen(View icon) {
- LauncherEvent event = LoggerUtils.initLauncherEvent(
- Action.TOUCH, icon, Target.CONTAINER);
LogContainerProvider provider = getLaunchProviderRecursive(icon);
if (icon == null && !(icon.getTag() instanceof ItemInfo)) {
return;
}
ItemInfo info = (ItemInfo) icon.getTag();
+ LauncherEvent event = newLauncherEvent(
+ newTouchAction(Action.LONGPRESS), newItemTarget(info), newTarget(Target.CONTAINER));
provider.fillInLogContainerData(icon, info, event.srcTarget[0], event.srcTarget[1]);
- event.action.touch = Action.LONGPRESS;
dispatchUserEvent(event, null);
resetElapsedContainerMillis();
@@ -223,28 +227,18 @@
/* Currently we are only interested in whether this event happens or not and don't
* care about which screen moves to where. */
public void logOverviewReorder() {
- LauncherEvent event = new LauncherLogProto.LauncherEvent();
-
- event.srcTarget = new LauncherLogProto.Target[2];
- event.srcTarget[0] = new LauncherLogProto.Target();
- event.srcTarget[0].type = Target.CONTAINER;
- event.srcTarget[0].containerType = LauncherLogProto.WORKSPACE;
- event.srcTarget[1] = new LauncherLogProto.Target();
- event.srcTarget[1].type = Target.CONTAINER;
- event.srcTarget[1].containerType = LauncherLogProto.OVERVIEW;
-
- event.action = new LauncherLogProto.Action();
- event.action.type = Action.TOUCH;
- event.action.touch = Action.DRAGDROP;
+ LauncherEvent event = newLauncherEvent(newTouchAction(Action.DRAGDROP),
+ newContainerTarget(LauncherLogProto.WORKSPACE),
+ newContainerTarget(LauncherLogProto.OVERVIEW));
dispatchUserEvent(event, null);
-
}
+
public void logDragNDrop(DropTarget.DragObject dragObj, View dropTargetAsView) {
- LauncherEvent event = LoggerUtils.initLauncherEvent(Action.TOUCH,
- dragObj.originalDragInfo,
- Target.CONTAINER,
- dropTargetAsView);
- event.action.touch = Action.DRAGDROP;
+ LauncherEvent event = newLauncherEvent(newTouchAction(Action.DRAGDROP),
+ newItemTarget(dragObj.originalDragInfo), newTarget(Target.CONTAINER));
+ event.destTarget = new LauncherLogProto.Target[] {
+ newItemTarget(dragObj.originalDragInfo), newDropTarget(dropTargetAsView)
+ };
dragObj.dragSource.fillInLogContainerData(null, dragObj.originalDragInfo,
event.srcTarget[0], event.srcTarget[1]);