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

Commit 041219c9 authored by Josep del Rio's avatar Josep del Rio Committed by Josep del Río
Browse files

Add IME action to Enter editor action

At the moment apps need to support pressing "Enter" to search
differently if they want to support physical keyboard, as
currently no editor action is sent from it. This is a proposal
that will resolve that issue by sending that information.

Bug: 269672396
Test: built, flashed on device, confirmed pressing enter starts
the search

Change-Id: I1694303540295603097db2fd4e4206f1ca71cec0
parent b62d832a
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -1117,7 +1117,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
         * @param actionId Identifier of the action.  This will be either the
         * identifier you supplied, or {@link EditorInfo#IME_NULL
         * EditorInfo.IME_NULL} if being called due to the enter key
         * being pressed.
         * being pressed. Starting from Android 14, the action identifier will
         * also be included when triggered by an enter key if the input is
         * constrained to a single line.
         * @param event If triggered by an enter key, this is the event;
         * otherwise, this is null.
         * @return Return true if you have consumed the action, else false.
@@ -9272,7 +9274,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                        // chance to consume the event.
                        if (mEditor.mInputContentType.onEditorActionListener != null
                                && mEditor.mInputContentType.onEditorActionListener.onEditorAction(
                                        this, EditorInfo.IME_NULL, event)) {
                                        this,
                                        getActionIdForEnterEvent(),
                                        event)) {
                            mEditor.mInputContentType.enterDown = true;
                            // We are consuming the enter key for them.
                            return KEY_EVENT_HANDLED;
@@ -9495,7 +9499,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                            && mEditor.mInputContentType.enterDown) {
                        mEditor.mInputContentType.enterDown = false;
                        if (mEditor.mInputContentType.onEditorActionListener.onEditorAction(
                                this, EditorInfo.IME_NULL, event)) {
                                this, getActionIdForEnterEvent(), event)) {
                            return true;
                        }
                    }
@@ -9559,6 +9563,15 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        return super.onKeyUp(keyCode, event);
    }
    private int getActionIdForEnterEvent() {
        // If it's not single line, no action
        if (!isSingleLine()) {
            return EditorInfo.IME_NULL;
        }
        // Return the action that was specified for Enter
        return getImeOptions() & EditorInfo.IME_MASK_ACTION;
    }
    @Override
    public boolean onCheckIsTextEditor() {
        return mEditor != null && mEditor.mInputType != EditorInfo.TYPE_NULL;