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

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

Fix for TextView's error popup behavior when using soft keyboard.

Bug 3370191

The documented behavior is to hide the error when the text changes.
However, this should not be the case if the error was reset by a text watcher.

Comparing errorBefore and errorAfter as was done before is not sufficient in the
case where the error is reset to the same value. String pool optimization will re-use
the same Object and it will look like the error has not been modified (hence the
blinking behavior reported in the bug).

For this reason, TextView has a mErrorWasChanged flag. The fix is to export methods
that can use this flag as in done inside TextView when a physical keyboard is used.

These methods are hidden.

Change-Id: Ie3ec59a368f3b1588b81242890b971ac48e8ff7e
parent 270cbcc1
Loading
Loading
Loading
Loading
+28 −16
Original line number Diff line number Diff line
@@ -4608,9 +4608,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                mInput.onKeyDown(this, (Editable)mText, keyCode, down);
                mInput.onKeyUp(this, (Editable)mText, keyCode, up);
            }
            if (mError != null && !mErrorWasChanged) {
                setError(null, null);
            }
            hideErrorIfUnchanged();

        } else if (which == 2) {
            mMovement.onKeyUp(this, (Spannable)mText, keyCode, up);
@@ -4731,13 +4729,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        }

        if (mInput != null) {
            /*
             * Keep track of what the error was before doing the input
             * so that if an input filter changed the error, we leave
             * that error showing.  Otherwise, we take down whatever
             * error was showing when the user types something.
             */
            mErrorWasChanged = false;
            resetErrorChangedFlag();

            boolean doDown = true;
            if (otherEvent != null) {
@@ -4745,9 +4737,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                    beginBatchEdit();
                    boolean handled = mInput.onKeyOther(this, (Editable) mText,
                            otherEvent);
                    if (mError != null && !mErrorWasChanged) {
                        setError(null, null);
                    }
                    hideErrorIfUnchanged();
                    doDown = false;
                    if (handled) {
                        return -1;
@@ -4764,9 +4754,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                beginBatchEdit();
                if (mInput.onKeyDown(this, (Editable) mText, keyCode, event)) {
                    endBatchEdit();
                    if (mError != null && !mErrorWasChanged) {
                        setError(null, null);
                    }
                    hideErrorIfUnchanged();
                    return 1;
                }
                endBatchEdit();
@@ -4800,6 +4788,30 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        return 0;
    }

    /**
     * Resets the mErrorWasChanged flag, so that future calls to {@link #setError(CharSequence)}
     * can be recorded.
     * @hide
     */
    public void resetErrorChangedFlag() {
        /*
         * Keep track of what the error was before doing the input
         * so that if an input filter changed the error, we leave
         * that error showing.  Otherwise, we take down whatever
         * error was showing when the user types something.
         */
        mErrorWasChanged = false;
    }

    /**
     * @hide
     */
    public void hideErrorIfUnchanged() {
        if (mError != null && !mErrorWasChanged) {
            setError(null, null);
        }
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if (!isEnabled()) {
+2 −2
Original line number Diff line number Diff line
@@ -138,9 +138,9 @@ public class EditableInputConnection extends BaseInputConnection {
            return super.commitText(text, newCursorPosition);
        }

        CharSequence errorBefore = mTextView.getError();
        mTextView.resetErrorChangedFlag();
        boolean success = super.commitText(text, newCursorPosition);
        CharSequence errorAfter = mTextView.getError();
        mTextView.hideErrorIfUnchanged();

        return success;
    }