From 83f111d129fcb8c50b35da789f0d75604b9c0864 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Mon, 20 Apr 2009 21:03:13 -0700 Subject: [PATCH] Prevent race condition when cancelling long-press for scroll. When dragging between workspaces in rapid succession, the canceling of the original long-press timer wasn't being triggered correctly. (When the timer fires, it might read an invalid Workspace.allowLongPress() value.) This patchset correctly cancels any pending long-press timers once a desktop scroll begins, and we don't need to rely on the allowLongPress() value. --- src/com/android/launcher/CellLayout.java | 12 ++++++++++++ src/com/android/launcher/LauncherAppWidgetHostView.java | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/com/android/launcher/CellLayout.java b/src/com/android/launcher/CellLayout.java index 157bf56..160dd18 100644 --- a/src/com/android/launcher/CellLayout.java +++ b/src/com/android/launcher/CellLayout.java @@ -98,6 +98,18 @@ public class CellLayout extends ViewGroup { } } + @Override + public void cancelLongPress() { + super.cancelLongPress(); + + // Cancel long press for all children + final int count = getChildCount(); + for (int i = 0; i < count; i++) { + final View child = getChildAt(i); + child.cancelLongPress(); + } + } + int getCountX() { return mPortrait ? mShortAxisCells : mLongAxisCells; } diff --git a/src/com/android/launcher/LauncherAppWidgetHostView.java b/src/com/android/launcher/LauncherAppWidgetHostView.java index 1e21a19..da5b3a0 100644 --- a/src/com/android/launcher/LauncherAppWidgetHostView.java +++ b/src/com/android/launcher/LauncherAppWidgetHostView.java @@ -98,4 +98,14 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView { mPendingCheckForLongPress.rememberWindowAttachCount(); postDelayed(mPendingCheckForLongPress, ViewConfiguration.getLongPressTimeout()); } + + @Override + public void cancelLongPress() { + super.cancelLongPress(); + + mHasPerformedLongPress = false; + if (mPendingCheckForLongPress != null) { + removeCallbacks(mPendingCheckForLongPress); + } + } } -- 2.11.0