diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 788f04aa16ecb..4176ed115237f 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -2726,7 +2726,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility setPressed(false); if (!mHasPerformedLongPress) { - cancelLongPress(); + removeLongPressCallback(); } } } @@ -3748,7 +3748,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility if (imm != null && (mPrivateFlags & FOCUSED) != 0) { imm.focusOut(this); } - cancelLongPress(); + removeLongPressCallback(); onFocusLost(); } else if (imm != null && (mPrivateFlags & FOCUSED) != 0) { imm.focusIn(this); @@ -3994,7 +3994,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility if (!mHasPerformedLongPress) { // This is a tap, so remove the longpress check - cancelLongPress(); + removeLongPressCallback(); result = performClick(); } @@ -4184,7 +4184,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility if (!mHasPerformedLongPress) { // This is a tap, so remove the longpress check - cancelLongPress(); + removeLongPressCallback(); // Only perform take click actions if we were in the pressed state if (!focusTaken) { @@ -4227,7 +4227,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility // Outside button if ((mPrivateFlags & PRESSED) != 0) { // Remove any future long press checks - cancelLongPress(); + removeLongPressCallback(); // Need to switch from pressed to not pressed mPrivateFlags &= ~PRESSED; @@ -4249,6 +4249,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility return false; } + /** + * Remove the longpress detection timer. + */ + private void removeLongPressCallback() { + if (mPendingCheckForLongPress != null) { + removeCallbacks(mPendingCheckForLongPress); + } + } + /** * Cancels a pending long press. Your subclass can use this if you * want the context menu to come up if the user presses and holds @@ -4256,9 +4265,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility * and then move around enough to cause scrolling. */ public void cancelLongPress() { - if (mPendingCheckForLongPress != null) { - removeCallbacks(mPendingCheckForLongPress); - } + removeLongPressCallback(); } /** @@ -5759,7 +5766,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility * @see #onAttachedToWindow() */ protected void onDetachedFromWindow() { - cancelLongPress(); + removeLongPressCallback(); destroyDrawingCache(); }