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.
This commit is contained in:
Maryam Garrett
2009-12-11 13:52:06 -05:00
parent ba8e4d240b
commit 39f0efba92
2 changed files with 46 additions and 51 deletions

View File

@@ -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);
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.
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
// Get the current touch position
int x = (int) event.getX();
int y = (int) event.getY();
int offset = getOffset(x, y, widget);
// Turn long press off while we're selecting. User needs to
// re-tap on the selection to enable longpress
widget.cancelLongPress();
// Get the last down touch position (the position at which the
// user started the selection)
int lastDownOffset = buffer.getSpanStart(LAST_TAP_DOWN);
// Update selection as we're moving the selection area.
// 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);
// 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

View File

@@ -2726,9 +2726,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
setPressed(false);
if (!mHasPerformedLongPress) {
if (mPendingCheckForLongPress != null) {
removeCallbacks(mPendingCheckForLongPress);
}
cancelLongPress();
}
}
}
@@ -3750,9 +3748,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
if (imm != null && (mPrivateFlags & FOCUSED) != 0) {
imm.focusOut(this);
}
if (mPendingCheckForLongPress != null) {
removeCallbacks(mPendingCheckForLongPress);
}
cancelLongPress();
onFocusLost();
} else if (imm != null && (mPrivateFlags & FOCUSED) != 0) {
imm.focusIn(this);
@@ -3998,9 +3994,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
if (!mHasPerformedLongPress) {
// This is a tap, so remove the longpress check
if (mPendingCheckForLongPress != null) {
removeCallbacks(mPendingCheckForLongPress);
}
cancelLongPress();
result = performClick();
}
@@ -4190,9 +4184,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
if (!mHasPerformedLongPress) {
// This is a tap, so remove the longpress check
if (mPendingCheckForLongPress != null) {
removeCallbacks(mPendingCheckForLongPress);
}
cancelLongPress();
// Only perform take click actions if we were in the pressed state
if (!focusTaken) {
@@ -4235,9 +4227,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
// Outside button
if ((mPrivateFlags & PRESSED) != 0) {
// Remove any future long press checks
if (mPendingCheckForLongPress != null) {
removeCallbacks(mPendingCheckForLongPress);
}
cancelLongPress();
// Need to switch from pressed to not pressed
mPrivateFlags &= ~PRESSED;
@@ -5769,9 +5759,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see #onAttachedToWindow()
*/
protected void onDetachedFromWindow() {
if (mPendingCheckForLongPress != null) {
removeCallbacks(mPendingCheckForLongPress);
}
cancelLongPress();
destroyDrawingCache();
}