diff options
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/widget/Editor.java | 43 | ||||
| -rw-r--r-- | core/java/android/widget/TextView.java | 11 |
2 files changed, 33 insertions, 21 deletions
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index c8d824132228..dd7984418baa 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -262,6 +262,8 @@ public class Editor { } }; + boolean mIsInsertionActionModeStartPending = false; + Editor(TextView textView) { mTextView = textView; // Synchronize the filter list, which places the undo input filter at the end. @@ -990,7 +992,7 @@ public class Editor { } public boolean performLongClick(boolean handled) { - // Long press in empty space moves cursor and starts the selection action mode. + // Long press in empty space moves cursor and starts the insertion action mode. if (!handled && !isPositionOnText(mLastDownPositionX, mLastDownPositionY) && mInsertionControllerEnabled) { final int offset = mTextView.getOffsetForPosition(mLastDownPositionX, @@ -998,7 +1000,7 @@ public class Editor { stopTextActionMode(); Selection.setSelection((Spannable) mTextView.getText(), offset); getInsertionController().show(); - startInsertionActionMode(); + mIsInsertionActionModeStartPending = true; handled = true; } @@ -1710,14 +1712,14 @@ public class Editor { } /** - * @return true if the selection mode was actually started. + * Start an Insertion action mode. */ - private boolean startInsertionActionMode() { + void startInsertionActionMode() { if (mInsertionActionModeRunnable != null) { mTextView.removeCallbacks(mInsertionActionModeRunnable); } if (extractedTextModeWillBeStarted()) { - return false; + return; } stopTextActionMode(); @@ -1725,7 +1727,9 @@ public class Editor { new TextActionModeCallback(false /* hasSelection */); mTextActionMode = mTextView.startActionMode( actionModeCallback, ActionMode.TYPE_FLOATING); - return mTextActionMode != null; + if (mTextActionMode != null && getInsertionController() != null) { + getInsertionController().show(); + } } /** @@ -1797,7 +1801,7 @@ public class Editor { private boolean startSelectionActionModeInternal() { if (mTextActionMode != null) { - // Selection action mode is already started + // Text action mode is already started mTextActionMode.invalidate(); return false; } @@ -3875,7 +3879,7 @@ public class Editor { private static final int DELAY_BEFORE_HANDLE_FADES_OUT = 4000; private static final int RECENT_CUT_COPY_DURATION = 15 * 1000; // seconds - // Used to detect taps on the insertion handle, which will affect the selection action mode + // Used to detect taps on the insertion handle, which will affect the insertion action mode private float mDownPositionX, mDownPositionY; private Runnable mHider; @@ -3900,17 +3904,20 @@ public class Editor { // timeout has passed. if (!mDoubleTap && !isCursorInsideEasyCorrectionSpan() && (durationSinceCutOrCopy < RECENT_CUT_COPY_DURATION)) { - if (mInsertionActionModeRunnable == null) { - mInsertionActionModeRunnable = new Runnable() { - public void run() { - startInsertionActionMode(); - } - }; + if (mTextActionMode == null) { + if (mInsertionActionModeRunnable == null) { + mInsertionActionModeRunnable = new Runnable() { + @Override + public void run() { + startInsertionActionMode(); + } + }; + } + mTextView.postDelayed( + mInsertionActionModeRunnable, + ViewConfiguration.getDoubleTapTimeout() + 1); } - mTextView.postDelayed( - mInsertionActionModeRunnable, - ViewConfiguration.getDoubleTapTimeout() + 1); } hideAfterDelay(); @@ -3977,7 +3984,7 @@ public class Editor { final int touchSlop = viewConfiguration.getScaledTouchSlop(); if (distanceSquared < touchSlop * touchSlop) { - // Tapping on the handle toggles the selection action mode. + // Tapping on the handle toggles the insertion action mode. if (mTextActionMode != null) { mTextActionMode.finish(); } else { diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index b68934bfdb93..353901c06d58 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -8320,12 +8320,17 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener final boolean superResult = super.onTouchEvent(event); /* - * Don't handle the release after a long press, because it will - * move the selection away from whatever the menu action was - * trying to affect. + * Don't handle the release after a long press, because it will move the selection away from + * whatever the menu action was trying to affect. If the long press should have triggered an + * insertion action mode, we can now actually show it. */ if (mEditor != null && mEditor.mDiscardNextActionUp && action == MotionEvent.ACTION_UP) { mEditor.mDiscardNextActionUp = false; + + if (mEditor.mIsInsertionActionModeStartPending) { + mEditor.startInsertionActionMode(); + mEditor.mIsInsertionActionModeStartPending = false; + } return superResult; } |
