From b9ba427576d6597a3cbf15fcbba2b4ed14a6ca12 Mon Sep 17 00:00:00 2001 From: Hyunyoung Song Date: Mon, 16 Dec 2019 09:43:13 -0800 Subject: Fix shortcut componentname in workspace layout logging Bug: 146172747 Test: $ adb shell dumpsys activity provider com.google.android.apps.nexuslauncher/com.android.launcher3.LauncherProvider --proto --debug SHORTCUT, package=com.android.vending, component=VIEW_MY_DOWNLOADS, grid(3,4), span(1,1), pageIdx=0 user=0 Change-Id: Ic8537d499d66675fbe190f137b50fb693d6c21d5 --- .../launcher3/logging/DumpTargetWrapper.java | 32 +++++++++++++++++----- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/com/android/launcher3/logging/DumpTargetWrapper.java b/src/com/android/launcher3/logging/DumpTargetWrapper.java index 365e8f21e..067bdfdec 100644 --- a/src/com/android/launcher3/logging/DumpTargetWrapper.java +++ b/src/com/android/launcher3/logging/DumpTargetWrapper.java @@ -15,17 +15,22 @@ */ package com.android.launcher3.logging; +import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT; + +import android.content.ComponentName; import android.os.Process; import android.text.TextUtils; import com.android.launcher3.ItemInfo; import com.android.launcher3.LauncherAppWidgetInfo; import com.android.launcher3.LauncherSettings; +import com.android.launcher3.WorkspaceItemInfo; import com.android.launcher3.model.nano.LauncherDumpProto; import com.android.launcher3.model.nano.LauncherDumpProto.ContainerType; import com.android.launcher3.model.nano.LauncherDumpProto.DumpTarget; import com.android.launcher3.model.nano.LauncherDumpProto.ItemType; import com.android.launcher3.model.nano.LauncherDumpProto.UserType; +import com.android.launcher3.util.ShortcutUtil; import java.util.ArrayList; import java.util.List; @@ -73,20 +78,23 @@ public class DumpTargetWrapper { public DumpTarget newItemTarget(ItemInfo info) { DumpTarget dt = new DumpTarget(); dt.type = DumpTarget.Type.ITEM; - + if (info == null) { + return dt; + } switch (info.itemType) { case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: dt.itemType = ItemType.APP_ICON; break; - case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: - dt.itemType = ItemType.UNKNOWN_ITEMTYPE; - break; case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: dt.itemType = ItemType.WIDGET; break; - case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT: + case ITEM_TYPE_DEEP_SHORTCUT: + case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: dt.itemType = ItemType.SHORTCUT; break; + default: + dt.itemType = ItemType.UNKNOWN_ITEMTYPE; + break; } return dt; } @@ -120,6 +128,9 @@ public class DumpTargetWrapper { } private static String getItemStr(DumpTarget t) { + if (t == null) { + return ""; + } String typeStr = LoggerUtils.getFieldName(t.itemType, ItemType.class); if (!TextUtils.isEmpty(t.packageName)) { typeStr += ", package=" + t.packageName; @@ -132,8 +143,15 @@ public class DumpTargetWrapper { } public DumpTarget writeToDumpTarget(ItemInfo info) { - node.component = info.getTargetComponent() == null? "": - info.getTargetComponent().flattenToString(); + if (info == null) { + return node; + } + if (ShortcutUtil.isDeepShortcut(info)) { + node.component = ((WorkspaceItemInfo) info).getDeepShortcutId(); + } else { + ComponentName cmp = info.getTargetComponent(); + node.component = cmp == null ? "" : cmp.flattenToString(); + } node.packageName = info.getTargetComponent() == null? "": info.getTargetComponent().getPackageName(); if (info instanceof LauncherAppWidgetInfo) { -- cgit v1.2.3 From 848696ac1dcf1a90492f7bc794cd05747803dbc4 Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Sun, 22 Dec 2019 15:17:18 -0800 Subject: Increase drag distance threshold when drag starts from deep press Also don't update distance dragged until drag actually starts (otherwise we add a lot of motion before deep press triggers). Bug: 146146413 Change-Id: I28bd23707a9be53c709d7a4e779e84b9a0be9ce2 (cherry picked from commit a7704c09c70568208f8e08c2d98878e8dd9be1f5) --- .../launcher3/dragndrop/DragController.java | 31 ++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java index b72fd988a..dcdf5d616 100644 --- a/src/com/android/launcher3/dragndrop/DragController.java +++ b/src/com/android/launcher3/dragndrop/DragController.java @@ -19,6 +19,7 @@ package com.android.launcher3.dragndrop; import static com.android.launcher3.AbstractFloatingView.TYPE_DISCOVERY_BOUNCE; import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY; import static com.android.launcher3.LauncherState.NORMAL; +import static com.android.launcher3.Utilities.ATLEAST_Q; import android.animation.ValueAnimator; import android.content.ComponentName; @@ -56,6 +57,12 @@ import java.util.ArrayList; public class DragController implements DragDriver.EventListener, TouchController { private static final boolean PROFILE_DRAWING_DURING_DRAG = false; + /** + * When a drag is started from a deep press, you need to drag this much farther than normal to + * end a pre-drag. See {@link DragOptions.PreDragCondition#shouldStartDrag(double)}. + */ + private static final int DEEP_PRESS_DISTANCE_FACTOR = 3; + @Thunk Launcher mLauncher; private FlingToDeleteHelper mFlingToDeleteHelper; @@ -91,9 +98,10 @@ public class DragController implements DragDriver.EventListener, TouchController private DropTarget mLastDropTarget; - @Thunk int mLastTouch[] = new int[2]; - @Thunk long mLastTouchUpTime = -1; - @Thunk int mDistanceSinceScroll = 0; + private final int[] mLastTouch = new int[2]; + private long mLastTouchUpTime = -1; + private int mLastTouchClassification; + private int mDistanceSinceScroll = 0; private int mTmpPoint[] = new int[2]; private Rect mDragLayerRect = new Rect(); @@ -204,7 +212,7 @@ public class DragController implements DragDriver.EventListener, TouchController } mLauncher.getDragLayer().performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); - dragView.show(mMotionDownX, mMotionDownY); + dragView.show(mLastTouch[0], mLastTouch[1]); mDistanceSinceScroll = 0; if (!mIsInPreDrag) { @@ -213,9 +221,7 @@ public class DragController implements DragDriver.EventListener, TouchController mOptions.preDragCondition.onPreDragStart(mDragObject); } - mLastTouch[0] = mMotionDownX; - mLastTouch[1] = mMotionDownY; - handleMoveEvent(mMotionDownX, mMotionDownY); + handleMoveEvent(mLastTouch[0], mLastTouch[1]); mLauncher.getUserEventDispatcher().resetActionDurationMillis(); return dragView; } @@ -430,6 +436,11 @@ public class DragController implements DragDriver.EventListener, TouchController final int[] dragLayerPos = getClampedDragLayerPos(ev.getX(), ev.getY()); final int dragLayerX = dragLayerPos[0]; final int dragLayerY = dragLayerPos[1]; + mLastTouch[0] = dragLayerX; + mLastTouch[1] = dragLayerY; + if (ATLEAST_Q) { + mLastTouchClassification = ev.getClassification(); + } switch (action) { case MotionEvent.ACTION_DOWN: @@ -488,8 +499,12 @@ public class DragController implements DragDriver.EventListener, TouchController mLastTouch[0] = x; mLastTouch[1] = y; + int distanceDragged = mDistanceSinceScroll; + if (ATLEAST_Q && mLastTouchClassification == MotionEvent.CLASSIFICATION_DEEP_PRESS) { + distanceDragged /= DEEP_PRESS_DISTANCE_FACTOR; + } if (mIsInPreDrag && mOptions.preDragCondition != null - && mOptions.preDragCondition.shouldStartDrag(mDistanceSinceScroll)) { + && mOptions.preDragCondition.shouldStartDrag(distanceDragged)) { callOnDragStart(); } } -- cgit v1.2.3