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

Commit 76327dc0 authored by Gilles Debunne's avatar Gilles Debunne Committed by Android (Google) Code Review
Browse files

Merge "Tuning the touch up filter."

parents 103b42d8 bc7a4c8c
Loading
Loading
Loading
Loading
+48 −40
Original line number Diff line number Diff line
@@ -8678,7 +8678,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;
@@ -8705,16 +8706,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;
@@ -8948,6 +8951,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();
@@ -8956,6 +8963,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                                }
                            }
                        }
                    }
                    filterOnTouchUp();
                    mIsDragging = false;
                    break;