// Set when this TextView gained focus with some text selected. Will start selection mode.
boolean mCreatedWithASelection;
- boolean mDoubleTap = false;
- boolean mTripleClick = false;
+ // Indicates the current tap state (first tap, double tap, or triple click).
+ private int mTapState = TAP_STATE_INITIAL;
+ private long mLastTouchUpTime = 0;
+ private static final int TAP_STATE_INITIAL = 0;
+ private static final int TAP_STATE_FIRST_TAP = 1;
+ private static final int TAP_STATE_DOUBLE_TAP = 2;
+ // Only for mouse input.
+ private static final int TAP_STATE_TRIPLE_CLICK = 3;
private Runnable mInsertionActionModeRunnable;
}
}
+ private void updateTapState(MotionEvent event) {
+ final int action = event.getActionMasked();
+ if (action == MotionEvent.ACTION_DOWN) {
+ final boolean isMouse = event.isFromSource(InputDevice.SOURCE_MOUSE);
+ // Detect double tap and triple click.
+ if (((mTapState == TAP_STATE_FIRST_TAP)
+ || ((mTapState == TAP_STATE_DOUBLE_TAP) && isMouse))
+ && (SystemClock.uptimeMillis() - mLastTouchUpTime) <=
+ ViewConfiguration.getDoubleTapTimeout()) {
+ if (mTapState == TAP_STATE_FIRST_TAP) {
+ mTapState = TAP_STATE_DOUBLE_TAP;
+ } else {
+ mTapState = TAP_STATE_TRIPLE_CLICK;
+ }
+ } else {
+ mTapState = TAP_STATE_FIRST_TAP;
+ }
+ }
+ if (action == MotionEvent.ACTION_UP) {
+ mLastTouchUpTime = SystemClock.uptimeMillis();
+ }
+ }
+
void onTouchEvent(MotionEvent event) {
+ updateTapState(event);
updateFloatingToolbarVisibility(event);
if (hasSelectionController()) {
// Cancel the single tap delayed runnable.
if (mInsertionActionModeRunnable != null
- && (mDoubleTap || mTripleClick || isCursorInsideEasyCorrectionSpan())) {
+ && ((mTapState == TAP_STATE_DOUBLE_TAP)
+ || (mTapState == TAP_STATE_TRIPLE_CLICK)
+ || isCursorInsideEasyCorrectionSpan())) {
mTextView.removeCallbacks(mInsertionActionModeRunnable);
}
// Prepare and schedule the single tap runnable to run exactly after the double tap
// timeout has passed.
- if (!mDoubleTap && !mTripleClick && !isCursorInsideEasyCorrectionSpan()
+ if ((mTapState != TAP_STATE_DOUBLE_TAP) && (mTapState != TAP_STATE_TRIPLE_CLICK)
+ && !isCursorInsideEasyCorrectionSpan()
&& (durationSinceCutOrCopy < RECENT_CUT_COPY_DURATION)) {
if (mTextActionMode == null) {
if (mInsertionActionModeRunnable == null) {
// Double tap detection
if (mGestureStayedInTapRegion) {
- if (mDoubleTap || mTripleClick) {
+ if (mTapState == TAP_STATE_DOUBLE_TAP
+ || mTapState == TAP_STATE_TRIPLE_CLICK) {
final float deltaX = eventX - mDownPositionX;
final float deltaY = eventY - mDownPositionY;
final float distanceSquared = deltaX * deltaX + deltaY * deltaY;
distanceSquared < doubleTapSlop * doubleTapSlop;
if (stayedInArea && (isMouse || isPositionOnText(eventX, eventY))) {
- if (mDoubleTap) {
+ if (mTapState == TAP_STATE_DOUBLE_TAP) {
selectCurrentWordAndStartDrag();
- } else if (mTripleClick) {
+ } else if (mTapState == TAP_STATE_TRIPLE_CLICK) {
selectCurrentParagraphAndStartDrag();
}
mDiscardNextActionUp = true;
private final Paint mHighlightPaint;
private boolean mHighlightPathBogus = true;
- private boolean mFirstTouch = false;
- private long mLastTouchUpTime = 0;
-
// Although these fields are specific to editable text, they are not added to Editor because
// they are defined by the TextView's style and are theme-dependent.
int mCursorDrawableRes;
@Override
public boolean onTouchEvent(MotionEvent event) {
final int action = event.getActionMasked();
-
- if (mEditor != null && action == MotionEvent.ACTION_DOWN) {
- final boolean isMouse = event.isFromSource(InputDevice.SOURCE_MOUSE);
- // Detect double tap and triple click and inform the Editor.
- if ((mFirstTouch || (mEditor.mDoubleTap && isMouse))
- && (SystemClock.uptimeMillis() - mLastTouchUpTime) <=
- ViewConfiguration.getDoubleTapTimeout()) {
- if (mFirstTouch) {
- mEditor.mTripleClick = false;
- mEditor.mDoubleTap = true;
- mFirstTouch = false;
- } else {
- mEditor.mTripleClick = true;
- mEditor.mDoubleTap = false;
- mFirstTouch = false;
- }
- } else {
- mEditor.mTripleClick = false;
- mEditor.mDoubleTap = false;
- mFirstTouch = true;
- }
- }
-
- if (action == MotionEvent.ACTION_UP) {
- mLastTouchUpTime = SystemClock.uptimeMillis();
- }
-
if (mEditor != null) {
mEditor.onTouchEvent(event);