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

Commit b71ddddf authored by Clara Bayarri's avatar Clara Bayarri
Browse files

Fix Floating tool bar flickers after long pressing on empty region.

Bug: 21452427
Change-Id: Icc70b85279fde1aa9d5c10bd89bb886797a49235
parent 3e85c1ed
Loading
Loading
Loading
Loading
+25 −18
Original line number Diff line number Diff line
@@ -262,6 +262,8 @@ public class Editor {
        }
    };

    boolean mIsInsertionActionModeStartPending = false;

    Editor(TextView textView) {
        mTextView = textView;
        // Synchronize the filter list, which places the undo input filter at the end.
@@ -990,7 +992,7 @@ public class Editor {
    }

    public boolean performLongClick(boolean handled) {
        // Long press in empty space moves cursor and starts the selection action mode.
        // Long press in empty space moves cursor and starts the insertion action mode.
        if (!handled && !isPositionOnText(mLastDownPositionX, mLastDownPositionY) &&
                mInsertionControllerEnabled) {
            final int offset = mTextView.getOffsetForPosition(mLastDownPositionX,
@@ -998,7 +1000,7 @@ public class Editor {
            stopTextActionMode();
            Selection.setSelection((Spannable) mTextView.getText(), offset);
            getInsertionController().show();
            startInsertionActionMode();
            mIsInsertionActionModeStartPending = true;
            handled = true;
        }

@@ -1710,14 +1712,14 @@ public class Editor {
    }

    /**
     * @return true if the selection mode was actually started.
     * Start an Insertion action mode.
     */
    private boolean startInsertionActionMode() {
    void startInsertionActionMode() {
        if (mInsertionActionModeRunnable != null) {
            mTextView.removeCallbacks(mInsertionActionModeRunnable);
        }
        if (extractedTextModeWillBeStarted()) {
            return false;
            return;
        }
        stopTextActionMode();

@@ -1725,7 +1727,9 @@ public class Editor {
                new TextActionModeCallback(false /* hasSelection */);
        mTextActionMode = mTextView.startActionMode(
                actionModeCallback, ActionMode.TYPE_FLOATING);
        return mTextActionMode != null;
        if (mTextActionMode != null && getInsertionController() != null) {
            getInsertionController().show();
        }
    }

    /**
@@ -1797,7 +1801,7 @@ public class Editor {

    private boolean startSelectionActionModeInternal() {
        if (mTextActionMode != null) {
            // Selection action mode is already started
            // Text action mode is already started
            mTextActionMode.invalidate();
            return false;
        }
@@ -3875,7 +3879,7 @@ public class Editor {
        private static final int DELAY_BEFORE_HANDLE_FADES_OUT = 4000;
        private static final int RECENT_CUT_COPY_DURATION = 15 * 1000; // seconds

        // Used to detect taps on the insertion handle, which will affect the selection action mode
        // Used to detect taps on the insertion handle, which will affect the insertion action mode
        private float mDownPositionX, mDownPositionY;
        private Runnable mHider;

@@ -3900,19 +3904,22 @@ public class Editor {
            // timeout has passed.
            if (!mDoubleTap && !isCursorInsideEasyCorrectionSpan()
                    && (durationSinceCutOrCopy < RECENT_CUT_COPY_DURATION)) {
                if (mTextActionMode == null) {
                    if (mInsertionActionModeRunnable == null) {
                        mInsertionActionModeRunnable = new Runnable() {
                            @Override
                            public void run() {
                                startInsertionActionMode();
                            }
                        };
                    }

                    mTextView.postDelayed(
                            mInsertionActionModeRunnable,
                            ViewConfiguration.getDoubleTapTimeout() + 1);
                }

            }

            hideAfterDelay();
        }

@@ -3977,7 +3984,7 @@ public class Editor {
                        final int touchSlop = viewConfiguration.getScaledTouchSlop();

                        if (distanceSquared < touchSlop * touchSlop) {
                            // Tapping on the handle toggles the selection action mode.
                            // Tapping on the handle toggles the insertion action mode.
                            if (mTextActionMode != null) {
                                mTextActionMode.finish();
                            } else {
+8 −3
Original line number Diff line number Diff line
@@ -8320,12 +8320,17 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        final boolean superResult = super.onTouchEvent(event);

        /*
         * Don't handle the release after a long press, because it will
         * move the selection away from whatever the menu action was
         * trying to affect.
         * Don't handle the release after a long press, because it will move the selection away from
         * whatever the menu action was trying to affect. If the long press should have triggered an
         * insertion action mode, we can now actually show it.
         */
        if (mEditor != null && mEditor.mDiscardNextActionUp && action == MotionEvent.ACTION_UP) {
            mEditor.mDiscardNextActionUp = false;

            if (mEditor.mIsInsertionActionModeStartPending) {
                mEditor.startInsertionActionMode();
                mEditor.mIsInsertionActionModeStartPending = false;
            }
            return superResult;
        }