Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5e6a0a63 authored by Christopher Lais's avatar Christopher Lais
Browse files

TextView: don't show context menu for double-tap

Use the mechanism long-press uses to prevent the context menu
from being shown.  hide()ing the selection was not working properly.

Also, prevent a triple-tap from being seen as two double-tap events.

BEWARE: Google has apparently already fixed this internally in 2.3.4,
but we do not have the source for that version at this time, nor is it
clear that the 2.3.4 fix will be available in time for a final release.

Change-Id: Iae68839f01162729d565df5861f37f400bf569d8
parent 967f40d2
Loading
Loading
Loading
Loading
+22 −13
Original line number Diff line number Diff line
@@ -8187,6 +8187,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                        mMinTouchOffset = mMaxTouchOffset = getOffset(x, y);

                        // Double tap detection
                        if (mPreviousTapUpTime != 0) {
                            long duration = SystemClock.uptimeMillis() - mPreviousTapUpTime;
                            if (duration <= ViewConfiguration.getDoubleTapTimeout()) {
                                final int deltaX = x - mPreviousTapPositionX;
@@ -8197,10 +8198,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                                if (distanceSquared < slopSquared) {
                                    startTextSelectionMode();
                                    // Hacky: onTapUpEvent will open a context menu with cut/copy
                                // Prevent this by hiding handles which will be revived instead.
                                hide();
                                    // Prevent this by eating the event.
                                    mEatTouchRelease = true;
                                }
                            }
                        }

                        mPreviousTapPositionX = x;
                        mPreviousTapPositionY = y;

@@ -8217,7 +8220,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                        break;

                    case MotionEvent.ACTION_UP:
                        // If this was a double-tap event, don't consider
                        // the next touch event to be a double-tap.
                        if (mEatTouchRelease) {
                            mPreviousTapUpTime = 0;
                        } else {
                            mPreviousTapUpTime = SystemClock.uptimeMillis();
                        }
                        break;
                }
            }