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

Commit 30fe6aa9 authored by Lan Wei's avatar Lan Wei
Browse files

IME API: InputConnecton#setImeTemporarilyConsumesInput(boolean)

Add API to set IME will temporarily consumes the input, for
this case, the cursor will be invisible in the app.

Bug: 175362887
Test: atest FrameworksCoreTests:TextViewTest
Test: atest CtsWidgetTestCases:TextViewTest

Change-Id: Ic04cacfd73f1f4cb254bb16caf6b04c00c91a318
parent f7490769
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -50616,6 +50616,7 @@ package android.view.inputmethod {
    method public boolean sendKeyEvent(android.view.KeyEvent);
    method public boolean setComposingRegion(int, int);
    method public boolean setComposingText(CharSequence, int);
    method public default boolean setImeTemporarilyConsumesInput(boolean);
    method public boolean setSelection(int, int);
    field public static final int CURSOR_UPDATE_IMMEDIATE = 1; // 0x1
    field public static final int CURSOR_UPDATE_MONITOR = 2; // 0x2
+3 −1
Original line number Diff line number Diff line
@@ -163,11 +163,13 @@ public class BaseInputConnection implements InputConnection {
    }

    /**
     * Default implementation calls {@link #finishComposingText()}.
     * Default implementation calls {@link #finishComposingText()} and
     * {@code setImeTemporarilyConsumesInput(false)}.
     */
    @CallSuper
    public void closeConnection() {
        finishComposingText();
        setImeTemporarilyConsumesInput(false);
    }

    /**
+18 −0
Original line number Diff line number Diff line
@@ -1002,4 +1002,22 @@ public interface InputConnection {
     */
    boolean commitContent(@NonNull InputContentInfo inputContentInfo, int flags,
            @Nullable Bundle opts);

    /**
     * Called by the input method to indicate that it temporarily consumes all input for itself,
     * or no longer does so.
     *
     * <p>Editors should reflect that they are temporarily not receiving input by hiding the
     * cursor if {@code imeTemporarilyConsumesInput} is {@code true}, and resume showing the
     * cursor if it is {@code false}.
     *
     * @param imeTemporarilyConsumesInput {@code true} when the IME is temporarily consuming input
     * and the cursor should be hidden, {@code false} when input to the editor resumes and the
     * cursor should be shown again.
     * @return {@code true} on success, {@code false} if the input connection is no longer valid, or
     * the protocol is not supported.
     */
    default boolean setImeTemporarilyConsumesInput(boolean imeTemporarilyConsumesInput) {
        return false;
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -335,4 +335,13 @@ public class InputConnectionWrapper implements InputConnection {
    public boolean commitContent(InputContentInfo inputContentInfo, int flags, Bundle opts) {
        return mTarget.commitContent(inputContentInfo, flags, opts);
    }

    /**
     * {@inheritDoc}
     * @throws NullPointerException if the target is {@code null}.
     */
    @Override
    public boolean setImeTemporarilyConsumesInput(boolean imeTemporarilyConsumesInput) {
        return mTarget.setImeTemporarilyConsumesInput(imeTemporarilyConsumesInput);
    }
}
+33 −2
Original line number Diff line number Diff line
@@ -494,6 +494,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
    private TextUtils.TruncateAt mEllipsize;
    // A flag to indicate the cursor was hidden by IME.
    private boolean mImeTemporarilyConsumesInput;
    // Whether cursor is visible without regard to {@link mImeTemporarilyConsumesInput}.
    // {code true} is the default value.
    private boolean mCursorVisibleFromAttr = true;
    static class Drawables {
        static final int LEFT = 0;
        static final int TOP = 1;
@@ -10496,7 +10503,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
    /**
     * Set whether the cursor is visible. The default is true. Note that this property only
     * makes sense for editable TextView.
     * makes sense for editable TextView. If IME is temporarily consuming the input, the cursor will
     * be always invisible, visibility will be updated as the last state when IME does not consume
     * the input anymore.
     *
     * @see #isCursorVisible()
     *
@@ -10504,6 +10513,25 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     */
    @android.view.RemotableViewMethod
    public void setCursorVisible(boolean visible) {
        mCursorVisibleFromAttr = visible;
        updateCursorVisibleInternal();
    }
    /**
     * Sets the IME is temporarily consuming the input and make the cursor invisible if
     * {@code imeTemporarilyConsumesInput} is {@code true}. Otherwise, make the cursor visible.
     *
     * @param imeTemporarilyConsumesInput {@code true} if IME is temporarily consuming the input
     *
     * @hide
     */
    public void setImeTemporarilyConsumesInput(boolean imeTemporarilyConsumesInput) {
        mImeTemporarilyConsumesInput = imeTemporarilyConsumesInput;
        updateCursorVisibleInternal();
    }
    private void updateCursorVisibleInternal()  {
        boolean visible = mCursorVisibleFromAttr && !mImeTemporarilyConsumesInput;
        if (visible && mEditor == null) return; // visible is the default value with no edit data
        createEditorIfNeeded();
        if (mEditor.mCursorVisible != visible) {
@@ -10518,7 +10546,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
    }
    /**
     * @return whether or not the cursor is visible (assuming this TextView is editable)
     * @return whether or not the cursor is visible (assuming this TextView is editable). This
     * method may return {@code false} when the IME is temporarily consuming the input even if the
     * {@code mEditor.mCursorVisible} attribute is {@code true} or {@code #setCursorVisible(true)}
     * is called.
     *
     * @see #setCursorVisible(boolean)
     *
Loading