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

Commit bc7a4c8c authored by Gilles Debunne's avatar Gilles Debunne
Browse files

Tuning the touch up filter.

Bug 3436027

A movement has to happen recently, and there has to have been a stable
period before this.

Also fixes a problem with the paste popup that could be displayed for very
fast motion since it was only based on time and not on distance.

Change-Id: I02264b4d54e4d1323ebc2d1b5102769ba2d8569a
parent a4738cf7
Loading
Loading
Loading
Loading
+48 −40
Original line number Diff line number Diff line
@@ -8715,7 +8715,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener

        // Touch-up filter: number of previous positions remembered
        private static final int HISTORY_SIZE = 5;
        private static final int TOUCH_UP_FILTER_DELAY = 150;
        private static final int TOUCH_UP_FILTER_DELAY_AFTER = 150;
        private static final int TOUCH_UP_FILTER_DELAY_BEFORE = 350;
        private final long[] mPreviousOffsetsTimes = new long[HISTORY_SIZE];
        private final int[] mPreviousOffsets = new int[HISTORY_SIZE];
        private int mPreviousOffsetIndex = 0;
@@ -8742,16 +8743,18 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        public void filterOnTouchUp() {
            final long now = SystemClock.uptimeMillis();
            int i = 0;
            int index = 0;
            int index = mPreviousOffsetIndex;
            final int iMax = Math.min(mNumberPreviousOffsets, HISTORY_SIZE);
            while (i < iMax) {
                index = (mPreviousOffsetIndex - i + HISTORY_SIZE) % HISTORY_SIZE;
                if ((now - mPreviousOffsetsTimes[index]) >= TOUCH_UP_FILTER_DELAY) break;
            while (i < iMax && (now - mPreviousOffsetsTimes[index]) < TOUCH_UP_FILTER_DELAY_AFTER) {
                i++;
                index = (mPreviousOffsetIndex - i + HISTORY_SIZE) % HISTORY_SIZE;
            }

            if (i > 0 && i < iMax &&
                    (now - mPreviousOffsetsTimes[index]) > TOUCH_UP_FILTER_DELAY_BEFORE) {
                mController.updateOffset(this, mPreviousOffsets[index]);
            }
        }

        public static final int LEFT = 0;
        public static final int CENTER = 1;
@@ -8985,6 +8988,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                    if (mIsInsertionHandle) {
                        long delay = SystemClock.uptimeMillis() - mTouchTimer;
                        if (delay < ViewConfiguration.getTapTimeout()) {
                            final float deltaX = mDownPositionX - ev.getRawX();
                            final float deltaY = mDownPositionY - ev.getRawY();
                            final float distanceSquared = deltaX * deltaX + deltaY * deltaY;
                            if (distanceSquared < mSquaredTouchSlopDistance) {
                                if (mPastePopupWindow != null && mPastePopupWindow.isShowing()) {
                                    // Tapping on the handle dismisses the displayed paste view,
                                    mPastePopupWindow.hide();
@@ -8993,6 +9000,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                                }
                            }
                        }
                    }
                    filterOnTouchUp();
                    mIsDragging = false;
                    break;