From e28454a23723c76b4eebdf9651692d85aa2a4737 Mon Sep 17 00:00:00 2001 From: Gilles Debunne Date: Wed, 7 Sep 2011 18:03:44 -0700 Subject: [PATCH] No vibration when long pressing in the empty part of an EditText Bug 5272224. Vibration should be limited to the start of an action mode, which is not the case here. Change-Id: I0f2263edb24e73f10297d27e109bb37c46fe96bc --- core/java/android/widget/TextView.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index d8aaa19ff8864..332ddf52a7b02 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -9228,21 +9228,23 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener @Override public boolean performLongClick() { + boolean handled = false; + boolean vibrate = true; + if (super.performLongClick()) { mDiscardNextActionUp = true; - return true; + handled = true; } - boolean handled = false; - // Long press in empty space moves cursor and shows the Paste affordance if available. - if (!isPositionOnText(mLastDownPositionX, mLastDownPositionY) && + if (!handled && !isPositionOnText(mLastDownPositionX, mLastDownPositionY) && mInsertionControllerEnabled) { final int offset = getOffsetForPosition(mLastDownPositionX, mLastDownPositionY); stopSelectionActionMode(); Selection.setSelection((Spannable) mText, offset); getInsertionController().showWithActionPopup(); handled = true; + vibrate = false; } if (!handled && mSelectionActionMode != null) { @@ -9264,10 +9266,15 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } // Start a new selection - handled |= !handled && startSelectionActionMode(); + if (!handled) { + handled = startSelectionActionMode(); + } + + if (vibrate) { + performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); + } if (handled) { - performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); mDiscardNextActionUp = true; }