diff options
author | Gilles Debunne <debunne@google.com> | 2010-08-27 10:34:56 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2010-08-27 10:34:56 -0700 |
commit | dfad42760f3c9c3b8439ff4b365256474471abe4 (patch) | |
tree | f95d54495a4fd000b1c134bbacff31ec361e36bd /core | |
parent | 084dd872b1bf9f7de87554d40d89df1f30b11c45 (diff) | |
parent | 225ad9cb184c94e29e4e0fb89d5e7d043e399ca4 (diff) | |
download | frameworks_base-dfad42760f3c9c3b8439ff4b365256474471abe4.zip frameworks_base-dfad42760f3c9c3b8439ff4b365256474471abe4.tar.gz frameworks_base-dfad42760f3c9c3b8439ff4b365256474471abe4.tar.bz2 |
am 225ad9cb: Merge "DO NOT MERGE Text selection: tapping on selection opens context menu" into gingerbread
Merge commit '225ad9cb184c94e29e4e0fb89d5e7d043e399ca4' into gingerbread-plus-aosp
* commit '225ad9cb184c94e29e4e0fb89d5e7d043e399ca4':
DO NOT MERGE Text selection: tapping on selection opens context menu
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/widget/TextView.java | 41 | ||||
-rw-r--r-- | core/res/res/values/strings.xml | 3 |
2 files changed, 36 insertions, 8 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 44f30f4..c888026 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -4303,6 +4303,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (shouldAdvanceFocusOnEnter()) { return 0; } + break; + + case KeyEvent.KEYCODE_BACK: + if (mIsInTextSelectionMode) { + stopTextSelectionMode(); + return -1; + } + break; } if (mInput != null) { @@ -6623,9 +6631,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener end = mPrevEnd; } else { if ((mPrevStart != mPrevEnd) && (start == end)) { - if ((start >= mPrevStart) && (start <= mPrevEnd)) { + if ((start >= mPrevStart) && (start < mPrevEnd)) { // Tapping inside the selection does nothing Selection.setSelection((Spannable) mText, mPrevStart, mPrevEnd); + showContextMenu(); return; } else { // Tapping outside stops selection mode, if any @@ -7226,9 +7235,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener setAlphabeticShortcut('v'); } - menu.add(0, ID_STOP_SELECTING_TEXT, 0, com.android.internal.R.string.stopSelectingText). - setOnMenuItemClickListener(handler); - added = true; } else { /* @@ -7277,10 +7283,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } - if (canPaste()) { + // Paste location is too imprecise. Only allow on empty text fields. + if (canPaste() && textIsOnlySpaces()) { menu.add(0, ID_PASTE, 0, com.android.internal.R.string.paste). setOnMenuItemClickListener(handler). setAlphabeticShortcut('v'); + added = true; } if (isInputMethodTarget()) { @@ -7304,6 +7312,17 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } + private boolean textIsOnlySpaces() { + final int length = mTransformed.length(); + for (int i=0; i<length; i++) { + final char c = mTransformed.charAt(i); + final int type = Character.getType(c); + if (type != Character.SPACE_SEPARATOR) + return false; + } + return true; + } + /** * Returns whether this text view is a current input method target. The * default implementation just checks with {@link InputMethodManager}. @@ -7742,6 +7761,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener private boolean mStartIsDragged = false; // Starting time of the fade timer private long mFadeOutTimerStart; + // Used to detect a tap (vs drag) on the controller + private long mOnDownTimerStart; // The cursor controller images private final Handle mStartHandle, mEndHandle; // Offset between finger hot point on active cursor controller and actual cursor @@ -7889,12 +7910,22 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener mOffsetX = (bounds.left + bounds.right) / 2.0f - x; mOffsetY = draggedHandle.mHotSpotVerticalPosition - y; + mOnDownTimerStart = event.getEventTime(); ((ArrowKeyMovementMethod)mMovement).setCursorController(this); } } } break; + case MotionEvent.ACTION_UP: + int time = (int) (event.getEventTime() - mOnDownTimerStart); + + if (time <= ViewConfiguration.getTapTimeout()) { + // A tap on the controller (not a drag) opens the contextual Copy menu + showContextMenu(); + } + break; + case MotionEvent.ACTION_POINTER_DOWN: case MotionEvent.ACTION_POINTER_UP: // Handle multi-point gestures. Keep min and max offset positions. diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 52abe45..09fc0f0 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -1856,9 +1856,6 @@ <!-- Item on EditText context menu. This action is used to start selecting text in the edit field. --> <string name="selectText">Select word</string> - <!-- Item on EditText context menu. This action is used to stop selecting text in the edit field. --> - <string name="stopSelectingText">Stop selecting text</string> - <!-- Item on EditText context menu. This action is used to cut selected the text into the clipboard. --> <string name="cut">Cut</string> |