summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGilles Debunne <debunne@google.com>2010-10-27 14:56:22 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-10-27 14:56:22 -0700
commitc5cf04c5047fc6fa90cb1acdebe1ce33e4d6bc8c (patch)
tree8767fda9b276c9e0eaa6c446cbf458ed91890fa6
parent3d773def6c77ab708e511a7749d19a8c2fb19221 (diff)
parent5347c588465b66ee7cc6169c87928d22d347bae3 (diff)
downloadframeworks_base-c5cf04c5047fc6fa90cb1acdebe1ce33e4d6bc8c.zip
frameworks_base-c5cf04c5047fc6fa90cb1acdebe1ce33e4d6bc8c.tar.gz
frameworks_base-c5cf04c5047fc6fa90cb1acdebe1ce33e4d6bc8c.tar.bz2
Merge "Text selection can be started with a double tap in TextView"
-rw-r--r--core/java/android/widget/TextView.java54
1 files changed, 38 insertions, 16 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 6897537..257dbf0 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -6903,14 +6903,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
@Override
public boolean onTouchEvent(MotionEvent event) {
final int action = event.getActionMasked();
- if (action == MotionEvent.ACTION_DOWN) {
- if (mInsertionPointCursorController != null) {
- mInsertionPointCursorController.onTouchEvent(event);
- }
- if (mSelectionModifierCursorController != null) {
- mSelectionModifierCursorController.onTouchEvent(event);
- }
+ if (mInsertionPointCursorController != null) {
+ mInsertionPointCursorController.onTouchEvent(event);
+ }
+ if (mSelectionModifierCursorController != null) {
+ mSelectionModifierCursorController.onTouchEvent(event);
+ }
+ if (action == MotionEvent.ACTION_DOWN) {
// Reset this state; it will be re-set if super.onTouchEvent
// causes focus to move to the view.
mTouchFocusSelected = false;
@@ -6931,13 +6931,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
if ((mMovement != null || onCheckIsTextEditor()) && isEnabled()
&& mText instanceof Spannable && mLayout != null) {
- if (mInsertionPointCursorController != null) {
- mInsertionPointCursorController.onTouchEvent(event);
- }
- if (mSelectionModifierCursorController != null) {
- mSelectionModifierCursorController.onTouchEvent(event);
- }
-
boolean handled = false;
// Save previous selection, in case this event is used to show the IME.
@@ -6946,7 +6939,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
final int oldScrollX = mScrollX;
final int oldScrollY = mScrollY;
-
+
if (mMovement != null) {
handled |= mMovement.onTouchEvent(this, (Spannable) mText, event);
}
@@ -7981,7 +7974,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
mDrawable = mSelectHandleLeft;
handleWidth = mDrawable.getIntrinsicWidth();
- mHotspotX = handleWidth / 4 * 3;
+ mHotspotX = (handleWidth * 3) / 4;
break;
}
@@ -8264,6 +8257,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
// Whether selection anchors are active
private boolean mIsShowing;
+ // Double tap detection
+ private long mPreviousTapUpTime = 0;
+ private int mPreviousTapPositionX;
+ private int mPreviousTapPositionY;
+
private static final int DELAY_BEFORE_FADE_OUT = 4100;
private final Runnable mHider = new Runnable() {
@@ -8369,6 +8367,26 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
// Remember finger down position, to be able to start selection from there
mMinTouchOffset = mMaxTouchOffset = getOffset(x, y);
+ // Double tap detection
+ long duration = SystemClock.uptimeMillis() - mPreviousTapUpTime;
+ if (duration <= ViewConfiguration.getDoubleTapTimeout()) {
+ final int deltaX = x - mPreviousTapPositionX;
+ final int deltaY = y - mPreviousTapPositionY;
+ final int distanceSquared = deltaX * deltaX + deltaY * deltaY;
+ final int doubleTapSlop =
+ ViewConfiguration.get(getContext()).getScaledDoubleTapSlop();
+ final int slopSquared = doubleTapSlop * doubleTapSlop;
+ if (distanceSquared < slopSquared) {
+ startSelectionActionMode();
+ // Hacky: onTapUpEvent will open a context menu with cut/copy
+ // Prevent this by hiding handles which will be revived instead.
+ hide();
+ }
+ }
+
+ mPreviousTapPositionX = x;
+ mPreviousTapPositionY = y;
+
break;
case MotionEvent.ACTION_POINTER_DOWN:
@@ -8380,6 +8398,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
updateMinAndMaxOffsets(event);
}
break;
+
+ case MotionEvent.ACTION_UP:
+ mPreviousTapUpTime = SystemClock.uptimeMillis();
+ break;
}
}
return false;