am 39f0efba: Fixes context-menu trigger behavior after scroll in TextView

Merge commit '39f0efba92a4420f77e3abc53c367ea3cacde3cf' into eclair-mr2-plus-aosp

* commit '39f0efba92a4420f77e3abc53c367ea3cacde3cf':
  Fixes context-menu trigger behavior after scroll in TextView
This commit is contained in:
Maryam Garrett
2009-12-14 15:26:33 -08:00
committed by Android Git Automerger
2 changed files with 46 additions and 51 deletions

View File

@@ -262,44 +262,51 @@ implements MovementMethod
widget.getParent().requestDisallowInterceptTouchEvent(true); widget.getParent().requestDisallowInterceptTouchEvent(true);
} }
} else if (event.getAction() == MotionEvent.ACTION_MOVE ) { } else if (event.getAction() == MotionEvent.ACTION_MOVE ) {
boolean cap = (MetaKeyKeyListener.getMetaState(buffer, boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
KeyEvent.META_SHIFT_ON) == 1) || KeyEvent.META_SHIFT_ON) == 1) ||
(MetaKeyKeyListener.getMetaState(buffer, (MetaKeyKeyListener.getMetaState(buffer,
MetaKeyKeyListener.META_SELECTING) != 0); MetaKeyKeyListener.META_SELECTING) != 0);
if (cap) { if (cap & handled) {
// Update selection as we're moving the selection area. // 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 // Turn long press off while we're selecting. User needs to
int x = (int) event.getX(); // re-tap on the selection to enable longpress
int y = (int) event.getY(); widget.cancelLongPress();
int offset = getOffset(x, y, widget);
// Get the last down touch position (the position at which the // Update selection as we're moving the selection area.
// user started the selection)
int lastDownOffset = buffer.getSpanStart(LAST_TAP_DOWN);
// Compute the selection boundries // Get the current touch position
int spanstart; int x = (int) event.getX();
int spanend; int y = (int) event.getY();
if (offset >= lastDownOffset) { int offset = getOffset(x, y, widget);
// Expand from word start of the original tap to new word
// end, since we are selecting "forwards" // Get the last down touch position (the position at which the
spanstart = findWordStart(buffer, lastDownOffset); // user started the selection)
spanend = findWordEnd(buffer, offset); int lastDownOffset = buffer.getSpanStart(LAST_TAP_DOWN);
} else {
// Expand to from new word start to word end of the original // Compute the selection boundries
// tap since we are selecting "backwards". int spanstart;
// The spanend will always need to be associated with the touch int spanend;
// up position, so that refining the selection with the if (offset >= lastDownOffset) {
// trackball will work as expected. // Expand from word start of the original tap to new word
spanstart = findWordEnd(buffer, lastDownOffset); // end, since we are selecting "forwards"
spanend = findWordStart(buffer, offset); 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) { } else if (event.getAction() == MotionEvent.ACTION_UP) {
// If we have scrolled, then the up shouldn't move the cursor, // 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 // 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); setPressed(false);
if (!mHasPerformedLongPress) { if (!mHasPerformedLongPress) {
if (mPendingCheckForLongPress != null) { cancelLongPress();
removeCallbacks(mPendingCheckForLongPress);
}
} }
} }
} }
@@ -3750,9 +3748,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
if (imm != null && (mPrivateFlags & FOCUSED) != 0) { if (imm != null && (mPrivateFlags & FOCUSED) != 0) {
imm.focusOut(this); imm.focusOut(this);
} }
if (mPendingCheckForLongPress != null) { cancelLongPress();
removeCallbacks(mPendingCheckForLongPress);
}
onFocusLost(); onFocusLost();
} else if (imm != null && (mPrivateFlags & FOCUSED) != 0) { } else if (imm != null && (mPrivateFlags & FOCUSED) != 0) {
imm.focusIn(this); imm.focusIn(this);
@@ -3998,9 +3994,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
if (!mHasPerformedLongPress) { if (!mHasPerformedLongPress) {
// This is a tap, so remove the longpress check // This is a tap, so remove the longpress check
if (mPendingCheckForLongPress != null) { cancelLongPress();
removeCallbacks(mPendingCheckForLongPress);
}
result = performClick(); result = performClick();
} }
@@ -4190,9 +4184,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
if (!mHasPerformedLongPress) { if (!mHasPerformedLongPress) {
// This is a tap, so remove the longpress check // This is a tap, so remove the longpress check
if (mPendingCheckForLongPress != null) { cancelLongPress();
removeCallbacks(mPendingCheckForLongPress);
}
// Only perform take click actions if we were in the pressed state // Only perform take click actions if we were in the pressed state
if (!focusTaken) { if (!focusTaken) {
@@ -4235,9 +4227,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
// Outside button // Outside button
if ((mPrivateFlags & PRESSED) != 0) { if ((mPrivateFlags & PRESSED) != 0) {
// Remove any future long press checks // Remove any future long press checks
if (mPendingCheckForLongPress != null) { cancelLongPress();
removeCallbacks(mPendingCheckForLongPress);
}
// Need to switch from pressed to not pressed // Need to switch from pressed to not pressed
mPrivateFlags &= ~PRESSED; mPrivateFlags &= ~PRESSED;
@@ -5769,9 +5759,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
* @see #onAttachedToWindow() * @see #onAttachedToWindow()
*/ */
protected void onDetachedFromWindow() { protected void onDetachedFromWindow() {
if (mPendingCheckForLongPress != null) { cancelLongPress();
removeCallbacks(mPendingCheckForLongPress);
}
destroyDrawingCache(); destroyDrawingCache();
} }