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

Commit 545c4d44 authored by Gilles Debunne's avatar Gilles Debunne
Browse files

Rationalize blinking cursor test.

Moved full test into shouldBlink() to make the condition consistent.

Change-Id: Id8abf38e180e1a00eb132476f102361f0feb56da
parent f3aa0f78
Loading
Loading
Loading
Loading
+10 −9
Original line number Original line Diff line number Diff line
@@ -1202,14 +1202,17 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                imm.hideSoftInputFromWindow(getWindowToken(), 0);
                imm.hideSoftInputFromWindow(getWindowToken(), 0);
            }
            }
        }
        }

        super.setEnabled(enabled);
        super.setEnabled(enabled);
        prepareCursorControllers();

        if (enabled) {
        if (enabled) {
            // Make sure IME is updated with current editor info.
            // Make sure IME is updated with current editor info.
            InputMethodManager imm = InputMethodManager.peekInstance();
            InputMethodManager imm = InputMethodManager.peekInstance();
            if (imm != null) imm.restartInput(this);
            if (imm != null) imm.restartInput(this);
        }
        }


        prepareCursorControllers();

        // start or stop the cursor blinking as appropriate
        // start or stop the cursor blinking as appropriate
        makeBlink();
        makeBlink();
    }
    }
@@ -8575,7 +8578,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     * @return True when the TextView isFocused and has a valid zero-length selection (cursor).
     * @return True when the TextView isFocused and has a valid zero-length selection (cursor).
     */
     */
    private boolean shouldBlink() {
    private boolean shouldBlink() {
        if (!isFocused()) return false;
        if (!isCursorVisible() || !isFocused()) return false;


        final int start = getSelectionStart();
        final int start = getSelectionStart();
        if (start < 0) return false;
        if (start < 0) return false;
@@ -8587,13 +8590,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
    }
    }


    private void makeBlink() {
    private void makeBlink() {
        if (isCursorVisible()) {
        if (shouldBlink()) {
        if (shouldBlink()) {
            mShowCursor = SystemClock.uptimeMillis();
            mShowCursor = SystemClock.uptimeMillis();
            if (mBlink == null) mBlink = new Blink(this);
            if (mBlink == null) mBlink = new Blink(this);
            mBlink.removeCallbacks(mBlink);
            mBlink.removeCallbacks(mBlink);
            mBlink.postAtTime(mBlink, mShowCursor + BLINK);
            mBlink.postAtTime(mBlink, mShowCursor + BLINK);
            }
        } else {
        } else {
            if (mBlink != null) mBlink.removeCallbacks(mBlink);
            if (mBlink != null) mBlink.removeCallbacks(mBlink);
        }
        }