summaryrefslogtreecommitdiffstats
path: root/core/java/android/text/method
diff options
context:
space:
mode:
authorMaryam Garrett <mkamvar@google.com>2009-12-11 13:52:06 -0500
committerMaryam Garrett <mkamvar@google.com>2009-12-14 14:42:25 -0500
commit39f0efba92a4420f77e3abc53c367ea3cacde3cf (patch)
treecc42c5065bdbc2f2e8d57313f102982af89c49f2 /core/java/android/text/method
parentba8e4d240b3d5eaebbdba9351b247ac20bedadc5 (diff)
downloadframeworks_base-39f0efba92a4420f77e3abc53c367ea3cacde3cf.zip
frameworks_base-39f0efba92a4420f77e3abc53c367ea3cacde3cf.tar.gz
frameworks_base-39f0efba92a4420f77e3abc53c367ea3cacde3cf.tar.bz2
Fixes context-menu trigger behavior after scroll in TextView
This change fixes the context menu trigger behavior while the user is selecting via touch. How if a user is selecting text via dragging their finger, to trigger the context menu they will have to lift their finger up, then issue a longpress. This is consistent with the behavior of selecting via the trackball.
Diffstat (limited to 'core/java/android/text/method')
-rw-r--r--core/java/android/text/method/ArrowKeyMovementMethod.java79
1 files changed, 43 insertions, 36 deletions
diff --git a/core/java/android/text/method/ArrowKeyMovementMethod.java b/core/java/android/text/method/ArrowKeyMovementMethod.java
index e27804c..0d04b13 100644
--- a/core/java/android/text/method/ArrowKeyMovementMethod.java
+++ b/core/java/android/text/method/ArrowKeyMovementMethod.java
@@ -262,44 +262,51 @@ implements MovementMethod
widget.getParent().requestDisallowInterceptTouchEvent(true);
}
} else if (event.getAction() == MotionEvent.ACTION_MOVE ) {
- boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
- KeyEvent.META_SHIFT_ON) == 1) ||
- (MetaKeyKeyListener.getMetaState(buffer,
- MetaKeyKeyListener.META_SELECTING) != 0);
-
- if (cap) {
- // Update selection as we're moving the selection area.
+ boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
+ KeyEvent.META_SHIFT_ON) == 1) ||
+ (MetaKeyKeyListener.getMetaState(buffer,
+ MetaKeyKeyListener.META_SELECTING) != 0);
- // Get the current touch position
- int x = (int) event.getX();
- int y = (int) event.getY();
- int offset = getOffset(x, y, widget);
-
- // Get the last down touch position (the position at which the
- // user started the selection)
- int lastDownOffset = buffer.getSpanStart(LAST_TAP_DOWN);
-
- // Compute the selection boundries
- int spanstart;
- int spanend;
- if (offset >= lastDownOffset) {
- // Expand from word start of the original tap to new word
- // end, since we are selecting "forwards"
- spanstart = findWordStart(buffer, lastDownOffset);
- spanend = findWordEnd(buffer, offset);
- } else {
- // Expand to from new word start to word end of the original
- // tap since we are selecting "backwards".
- // The spanend will always need to be associated with the touch
- // up position, so that refining the selection with the
- // trackball will work as expected.
- spanstart = findWordEnd(buffer, lastDownOffset);
- spanend = findWordStart(buffer, offset);
+ if (cap & handled) {
+ // Before selecting, make sure we've moved out of the "slop".
+ // handled will be true, if we're in select mode AND we're
+ // OUT of the slop
+
+ // Turn long press off while we're selecting. User needs to
+ // re-tap on the selection to enable longpress
+ widget.cancelLongPress();
+
+ // Update selection as we're moving the selection area.
+
+ // Get the current touch position
+ int x = (int) event.getX();
+ int y = (int) event.getY();
+ int offset = getOffset(x, y, widget);
+
+ // Get the last down touch position (the position at which the
+ // user started the selection)
+ int lastDownOffset = buffer.getSpanStart(LAST_TAP_DOWN);
+
+ // Compute the selection boundries
+ int spanstart;
+ int spanend;
+ if (offset >= lastDownOffset) {
+ // Expand from word start of the original tap to new word
+ // end, since we are selecting "forwards"
+ spanstart = findWordStart(buffer, lastDownOffset);
+ spanend = findWordEnd(buffer, offset);
+ } else {
+ // Expand to from new word start to word end of the original
+ // tap since we are selecting "backwards".
+ // The spanend will always need to be associated with the touch
+ // up position, so that refining the selection with the
+ // trackball will work as expected.
+ spanstart = findWordEnd(buffer, lastDownOffset);
+ spanend = findWordStart(buffer, offset);
+ }
+ Selection.setSelection(buffer, spanstart, spanend);
+ return true;
}
-
- Selection.setSelection(buffer, spanstart, spanend);
- return true;
- }
} else if (event.getAction() == MotionEvent.ACTION_UP) {
// If we have scrolled, then the up shouldn't move the cursor,
// but we do need to make sure the cursor is still visible at