From 1dce6f2503844b23315b53e07ebd0750c7572f37 Mon Sep 17 00:00:00 2001 From: Juan Sebastian Martinez Date: Mon, 27 Jan 2025 09:09:31 -0800 Subject: [PATCH] Avoiding MSDL haptics when first starting a drag in workspace. The MSDL token to play haptics when dragging was being played as soon as a widget was long-pressed but not dragged over a new drop-off location. Haptics should only play while the UI item is being hovered over new cells. The new condition checks if the drag cell and drag cell span are cleared and avoids playing haptics in this initial state. Test: manual. Verified haptics while dragging icons over Workspace and Hotseat only when actually dragging over new cells. Test: manual. Verified haptics with adb shell dumpsys of Launcher and checking the MSDL token history. Flag: com.android.launcher3.msdl_feedback Bug: 376103470 Change-Id: I7b2056f1c713b65f9df37f3138c1acf3b5376822 --- src/com/android/launcher3/CellLayout.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index 3d71ff178e..7f0c68fdc6 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -170,6 +170,7 @@ public class CellLayout extends ViewGroup { private boolean mDragging = false; public boolean mHasOnLayoutBeenCalled = false; + private boolean mPlayDragHaptics = false; private final TimeInterpolator mEaseOutInterpolator; protected final ShortcutAndWidgetContainer mShortcutsAndWidgets; @@ -1160,7 +1161,8 @@ public class CellLayout extends ViewGroup { DropTarget.DragObject dragObject) { if (mDragCell[0] != cellX || mDragCell[1] != cellY || mDragCellSpan[0] != spanX || mDragCellSpan[1] != spanY) { - if (Flags.msdlFeedback()) { + determineIfDragHapticsPlay(); + if (mPlayDragHaptics && Flags.msdlFeedback()) { mMSDLPlayerWrapper.playToken(MSDLToken.DRAG_INDICATOR_DISCRETE); } mDragCell[0] = cellX; @@ -1188,6 +1190,14 @@ public class CellLayout extends ViewGroup { } } + private void determineIfDragHapticsPlay() { + if (mDragCell[0] != -1 || mDragCell[1] != -1 + || mDragCellSpan[0] != -1 || mDragCellSpan[1] != -1) { + // The nearest cell is known and we can play haptics + mPlayDragHaptics = true; + } + } + @SuppressLint("StringFormatMatches") public String getItemMoveDescription(int cellX, int cellY) { if (mContainerType == HOTSEAT) { @@ -1789,6 +1799,7 @@ public class CellLayout extends ViewGroup { * @param child The child that is being dropped */ void onDropChild(View child) { + mPlayDragHaptics = false; if (child != null) { CellLayoutLayoutParams lp = (CellLayoutLayoutParams) child.getLayoutParams();