summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGilles Debunne <debunne@google.com>2010-08-27 10:33:17 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-08-27 10:33:17 -0700
commit225ad9cb184c94e29e4e0fb89d5e7d043e399ca4 (patch)
treee3a4612e6e7497ff6afaf2d35af7aa20f6c28ff8 /core
parentb8fd047311e329f2b8dbe3d228488ba844718ee1 (diff)
parent45b2d699e10474f0167691774c0cfb93cfe2dae9 (diff)
downloadframeworks_base-225ad9cb184c94e29e4e0fb89d5e7d043e399ca4.zip
frameworks_base-225ad9cb184c94e29e4e0fb89d5e7d043e399ca4.tar.gz
frameworks_base-225ad9cb184c94e29e4e0fb89d5e7d043e399ca4.tar.bz2
Merge "DO NOT MERGE Text selection: tapping on selection opens context menu" into gingerbread
Diffstat (limited to 'core')
-rw-r--r--core/java/android/widget/TextView.java41
-rw-r--r--core/res/res/values/strings.xml3
2 files changed, 36 insertions, 8 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 248f6eb..6f35b61 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) {
@@ -6618,9 +6626,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
@@ -7221,9 +7230,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 {
/*
@@ -7272,10 +7278,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()) {
@@ -7299,6 +7307,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}.
@@ -7737,6 +7756,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
@@ -7884,12 +7905,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>