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

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

Fix hint text updates in Extracted text mode

Updates to the hint on a TextView were not notified to the
ExtractEditText, so there was no way it could know to update.
This change pipes through the hint value when the extracted
mode becomes visible and informs it of changes.

The Editor#reportExtractedText method has been refactored to
be more readable. Note that checks on whether the content
changed are done in the two places in the code that already
called this method, and we explicitely don't want to check
contents when there is a hint change.

Bug: 63980155
Bug: 65691495
Test: bit CtsWidgetTestCases:.TextViewTest
Change-Id: I357dd5c74b61d149cf8612d1f52c7118ec70c696
parent 925c00b4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -48368,6 +48368,7 @@ package android.view.inputmethod {
    field public static final int FLAG_SELECTING = 2; // 0x2
    field public static final int FLAG_SINGLE_LINE = 1; // 0x1
    field public int flags;
    field public java.lang.CharSequence hint;
    field public int partialEndOffset;
    field public int partialStartOffset;
    field public int selectionEnd;
+1 −0
Original line number Diff line number Diff line
@@ -52061,6 +52061,7 @@ package android.view.inputmethod {
    field public static final int FLAG_SELECTING = 2; // 0x2
    field public static final int FLAG_SINGLE_LINE = 1; // 0x1
    field public int flags;
    field public java.lang.CharSequence hint;
    field public int partialEndOffset;
    field public int partialStartOffset;
    field public int selectionEnd;
+1 −0
Original line number Diff line number Diff line
@@ -48865,6 +48865,7 @@ package android.view.inputmethod {
    field public static final int FLAG_SELECTING = 2; // 0x2
    field public static final int FLAG_SINGLE_LINE = 1; // 0x1
    field public int flags;
    field public java.lang.CharSequence hint;
    field public int partialEndOffset;
    field public int partialStartOffset;
    field public int selectionEnd;
+18 −11
Original line number Diff line number Diff line
@@ -86,6 +86,11 @@ public class ExtractedText implements Parcelable {
     */
    public int flags;

    /**
     * The hint that has been extracted.
     */
    public CharSequence hint;

    /**
     * Used to package this object into a {@link Parcel}.
     *
@@ -100,6 +105,7 @@ public class ExtractedText implements Parcelable {
        dest.writeInt(selectionStart);
        dest.writeInt(selectionEnd);
        dest.writeInt(this.flags);
        TextUtils.writeToParcel(hint, dest, flags);
    }

    /**
@@ -116,6 +122,7 @@ public class ExtractedText implements Parcelable {
                    res.selectionStart = source.readInt();
                    res.selectionEnd = source.readInt();
                    res.flags = source.readInt();
                    res.hint = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
                    return res;
                }

+38 −38
Original line number Diff line number Diff line
@@ -1585,27 +1585,31 @@ public class Editor {
        outText.startOffset = 0;
        outText.selectionStart = mTextView.getSelectionStart();
        outText.selectionEnd = mTextView.getSelectionEnd();
        outText.hint = mTextView.getHint();
        return true;
    }

    boolean reportExtractedText() {
        final Editor.InputMethodState ims = mInputMethodState;
        if (ims != null) {
            final boolean contentChanged = ims.mContentChanged;
            if (contentChanged || ims.mSelectionModeChanged) {
                ims.mContentChanged = false;
        if (ims == null) {
            return false;
        }
        ims.mSelectionModeChanged = false;
        final ExtractedTextRequest req = ims.mExtractedTextRequest;
                if (req != null) {
                    InputMethodManager imm = InputMethodManager.peekInstance();
                    if (imm != null) {
        if (req == null) {
            return false;
        }
        final InputMethodManager imm = InputMethodManager.peekInstance();
        if (imm == null) {
            return false;
        }
        if (TextView.DEBUG_EXTRACT) {
            Log.v(TextView.LOG_TAG, "Retrieving extracted start="
                    + ims.mChangedStart
                    + " end=" + ims.mChangedEnd
                    + " delta=" + ims.mChangedDelta);
        }
                        if (ims.mChangedStart < 0 && !contentChanged) {
        if (ims.mChangedStart < 0 && !ims.mContentChanged) {
            ims.mChangedStart = EXTRACT_NOTHING;
        }
        if (extractTextInternal(req, ims.mChangedStart, ims.mChangedEnd,
@@ -1625,10 +1629,6 @@ public class Editor {
            ims.mContentChanged = false;
            return true;
        }
                    }
                }
            }
        }
        return false;
    }

Loading