Add user event logging for page rearrangement and LEFT/RIGHT swipes
1. Call logOverviewRearrange logging call ONLY when the order actually changed
2. Call logActionOnContainer when containers are swiped.
Bug: 32457561
Bug: 32457561

06-30 11:23:04.082  6585  6585 D UserEvent: action:SWIPE direction=LEFT
06-30 11:23:04.082  6585  6585 D UserEvent:  Source child:WORKSPACE id=2
06-30 11:23:04.082  6585  6585 D UserEvent:  Elapsed container 50436 ms session 50436 ms action 0 ms
06-30 11:23:04.082  6585  6585 D UserEvent:  isInLandscapeMode false
06-30 11:23:04.082  6585  6585 D UserEvent:  isInMultiWindowMode false

06-30 11:23:08.266  6585  6585 D UserEvent: action:SWIPE direction=LEFT
06-30 11:23:08.266  6585  6585 D UserEvent:  Source child:WORKSPACE id=1
06-30 11:23:08.266  6585  6585 D UserEvent:  Elapsed container 54620 ms session 54620 ms action 0 ms
06-30 11:23:08.266  6585  6585 D UserEvent:  isInLandscapeMode false
06-30 11:23:08.266  6585  6585 D UserEvent:  isInMultiWindowMode false

06-30 11:23:10.742  6585  6585 D UserEvent: action:SWIPE direction=LEFT
06-30 11:23:10.742  6585  6585 D UserEvent:  Source child:WORKSPACE id=0
06-30 11:23:10.742  6585  6585 D UserEvent:  Elapsed container 57096 ms session 57096 ms action 0 ms
06-30 11:23:10.742  6585  6585 D UserEvent:  isInLandscapeMode false
06-30 11:23:10.742  6585  6585 D UserEvent:  isInMultiWindowMode false

06-30 11:23:17.286  6585  6585 D UserEvent: action:SWIPE direction=RIGHT
06-30 11:23:17.286  6585  6585 D UserEvent:  Source child:WORKSPACE id=-1
06-30 11:23:17.286  6585  6585 D UserEvent:  Elapsed container 63639 ms session 63639 ms action 0 ms
06-30 11:23:17.286  6585  6585 D UserEvent:  isInLandscapeMode false
06-30 11:23:17.286  6585  6585 D UserEvent:  isInMultiWindowMode false
06-30 11:23:19.879  6585  6585 D UserEvent: action:SWIPE direction=RIGHT
06-30 11:23:19.879  6585  6585 D UserEvent:  Source child:WORKSPACE id=0
06-30 11:23:19.879  6585  6585 D UserEvent:  Elapsed container 66233 ms session 66233 ms action 0 ms
06-30 11:23:19.879  6585  6585 D UserEvent:  isInLandscapeMode false
06-30 11:23:19.879  6585  6585 D UserEvent:  isInMultiWindowMode false

06-30 11:23:23.811  6585  6585 D UserEvent: action:SWIPE direction=RIGHT
06-30 11:23:23.811  6585  6585 D UserEvent:  Source child:WORKSPACE id=1
06-30 11:23:23.811  6585  6585 D UserEvent:  Elapsed container 70165 ms session 70165 ms action 0 ms
06-30 11:23:23.811  6585  6585 D UserEvent:  isInLandscapeMode false
06-30 11:23:23.811  6585  6585 D UserEvent:  isInMultiWindowMode false


Change-Id: I11a48ee44aaa87863e76ccf2b46f499c28e96748
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index ed225c9..dcc7a9d 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -408,9 +408,10 @@
         if (getChildCount() == 0) {
             return;
         }
+        int prevPage = mCurrentPage;
         mCurrentPage = validateNewPage(currentPage);
         updateCurrentPageScroll();
-        notifyPageSwitchListener();
+        notifyPageSwitchListener(prevPage);
         invalidate();
     }
 
@@ -418,7 +419,7 @@
      * Should be called whenever the page changes. In the case of a scroll, we wait until the page
      * has settled.
      */
-    protected void notifyPageSwitchListener() {
+    protected void notifyPageSwitchListener(int prevPage) {
         updatePageIndicator();
     }
 
@@ -585,9 +586,10 @@
         } else if (mNextPage != INVALID_PAGE && shouldInvalidate) {
             sendScrollAccessibilityEvent();
 
+            int prevPage = mCurrentPage;
             mCurrentPage = validateNewPage(mNextPage);
             mNextPage = INVALID_PAGE;
-            notifyPageSwitchListener();
+            notifyPageSwitchListener(prevPage);
 
             // We don't want to trigger a page end moving unless the page has settled
             // and the user has stopped scrolling
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index b1db7e8..56a5f9e 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -75,6 +75,7 @@
 import com.android.launcher3.graphics.PreloadIconDrawable;
 import com.android.launcher3.popup.PopupContainerWithArrow;
 import com.android.launcher3.shortcuts.ShortcutDragPreviewProvider;
+import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
 import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
 import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
 import com.android.launcher3.util.ItemInfoMatcher;
@@ -300,6 +301,7 @@
     boolean mScrollInteractionBegan;
     boolean mStartedSendingScrollEvents;
     float mLastOverlayScroll = 0;
+    boolean mOverlayShown = false;
 
     private boolean mForceDrawAdjacentPages = false;
     // Total over scrollX in the overlay direction.
@@ -1405,6 +1407,20 @@
      * The overlay scroll is being controlled locally, just update our overlay effect
      */
     public void onOverlayScrollChanged(float scroll) {
+
+        if (Float.compare(scroll, 1f) == 0) {
+            if (!mOverlayShown) {
+                mLauncher.getUserEventDispatcher().logActionOnContainer(Action.Touch.SWIPE,
+                        Action.Direction.LEFT, ContainerType.WORKSPACE, 0);
+            }
+            mOverlayShown = true;
+        } else if (Float.compare(scroll, 0f) == 0) {
+            if (mOverlayShown) {
+                mLauncher.getUserEventDispatcher().logActionOnContainer(Action.Touch.SWIPE,
+                        Action.Direction.RIGHT, ContainerType.WORKSPACE, -1);
+            }
+            mOverlayShown = false;
+        }
         float offset = 0f;
         float slip = 0f;
 
@@ -1515,9 +1531,13 @@
     }
 
     @Override
-    protected void notifyPageSwitchListener() {
-        super.notifyPageSwitchListener();
-
+    protected void notifyPageSwitchListener(int prevPage) {
+        super.notifyPageSwitchListener(prevPage);
+        if (prevPage != mCurrentPage) {
+            int swipeDirection = (prevPage < mCurrentPage) ? Action.Direction.RIGHT : Action.Direction.LEFT;
+            mLauncher.getUserEventDispatcher().logActionOnContainer(Action.Touch.SWIPE,
+                    swipeDirection, ContainerType.WORKSPACE, prevPage);
+        }
         if (hasCustomContent() && getNextPage() == 0 && !mCustomContentShowing) {
             mCustomContentShowing = true;
             if (mCustomContentCallbacks != null) {
@@ -1867,13 +1887,20 @@
             return;
         }
 
+        ArrayList<Long> prevScreenOrder = (ArrayList<Long>) mScreenOrder.clone();
         mScreenOrder.clear();
         int count = getChildCount();
         for (int i = 0; i < count; i++) {
             CellLayout cl = ((CellLayout) getChildAt(i));
             mScreenOrder.add(getIdForScreen(cl));
         }
-        mLauncher.getUserEventDispatcher().logOverviewReorder();
+
+        for (int i = 0; i < prevScreenOrder.size(); i++) {
+            if (mScreenOrder.get(i) != prevScreenOrder.get(i)) {
+                mLauncher.getUserEventDispatcher().logOverviewReorder();
+                break;
+            }
+        }
         LauncherModel.updateWorkspaceScreenOrder(mLauncher, mScreenOrder);
 
         // Re-enable auto layout transitions for page deletion.
diff --git a/src/com/android/launcher3/folder/FolderPagedView.java b/src/com/android/launcher3/folder/FolderPagedView.java
index bc26fbe..33ac5ba 100644
--- a/src/com/android/launcher3/folder/FolderPagedView.java
+++ b/src/com/android/launcher3/folder/FolderPagedView.java
@@ -547,8 +547,8 @@
     }
 
     @Override
-    protected void notifyPageSwitchListener() {
-        super.notifyPageSwitchListener();
+    protected void notifyPageSwitchListener(int prevPage) {
+        super.notifyPageSwitchListener(prevPage);
         if (mFolder != null) {
             mFolder.updateTextViewFocus();
         }
diff --git a/src/com/android/launcher3/logging/LoggerUtils.java b/src/com/android/launcher3/logging/LoggerUtils.java
index 329b7d5..72a083b 100644
--- a/src/com/android/launcher3/logging/LoggerUtils.java
+++ b/src/com/android/launcher3/logging/LoggerUtils.java
@@ -66,8 +66,14 @@
     }
 
     public static String getActionStr(Action action) {
+        String str = "";
         switch (action.type) {
-            case Action.Type.TOUCH: return getFieldName(action.touch, Action.Touch.class);
+            case Action.Type.TOUCH:
+                str += getFieldName(action.touch, Action.Touch.class);
+                if (action.touch == Action.Touch.SWIPE) {
+                    str += " direction=" + getFieldName(action.dir, Action.Direction.class);
+                }
+                return str;
             case Action.Type.COMMAND: return getFieldName(action.command, Action.Command.class);
             default: return UNKNOWN;
         }