diff --git a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index 8bd35f62fdd7c..91644f3514b81 100644 --- a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -376,16 +376,11 @@ public void sendTextInputAppPrivateCommand(@NonNull String action, @NonNull Bund mImm.sendAppPrivateCommand(mView, action, data); } - private boolean canShowTextInput() { - if (configuration == null || configuration.inputType == null) { - return true; - } - return configuration.inputType.type != TextInputChannel.TextInputType.NONE; - } - @VisibleForTesting void showTextInput(View view) { - if (canShowTextInput()) { + if (configuration == null + || configuration.inputType == null + || configuration.inputType.type != TextInputChannel.TextInputType.NONE) { view.requestFocus(); mImm.showSoftInput(view, 0); } else { @@ -409,11 +404,7 @@ void setTextInputClient(int client, TextInputChannel.Configuration configuration // Call notifyViewExited on the previous field. notifyViewExited(); this.configuration = configuration; - if (canShowTextInput()) { - inputTarget = new InputTarget(InputTarget.Type.FRAMEWORK_CLIENT, client); - } else { - inputTarget = new InputTarget(InputTarget.Type.NO_TARGET, client); - } + inputTarget = new InputTarget(InputTarget.Type.FRAMEWORK_CLIENT, client); mEditable.removeEditingStateListener(this); mEditable = diff --git a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java index f73a74f6c942c..3bb087916080e 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -1,6 +1,7 @@ package io.flutter.plugin.editing; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.mockito.AdditionalMatchers.aryEq; @@ -1176,8 +1177,8 @@ public void destroy_clearTextInputMethodHandler() { @SuppressWarnings("deprecation") // DartExecutor.send is deprecated. - @Test - public void inputConnection_createsActionFromEnter() throws JSONException { + private void verifyInputConnection(TextInputChannel.TextInputType textInputType) + throws JSONException { TestImm testImm = Shadow.extract(ctx.getSystemService(Context.INPUT_METHOD_SERVICE)); FlutterJNI mockFlutterJni = mock(FlutterJNI.class); View testView = new View(ctx); @@ -1194,7 +1195,7 @@ public void inputConnection_createsActionFromEnter() throws JSONException { true, false, TextInputChannel.TextCapitalization.NONE, - new TextInputChannel.InputType(TextInputChannel.TextInputType.TEXT, false, false), + new TextInputChannel.InputType(textInputType, false, false), null, null, null, @@ -1232,6 +1233,16 @@ public void inputConnection_createsActionFromEnter() throws JSONException { new String[] {"0", "TextInputAction.done"}); } + @Test + public void inputConnection_createsActionFromEnter() throws JSONException { + verifyInputConnection(TextInputChannel.TextInputType.TEXT); + } + + @Test + public void inputConnection_respondsToKeyEvents_textInputTypeNone() throws JSONException { + verifyInputConnection(TextInputChannel.TextInputType.NONE); + } + @SuppressWarnings("deprecation") // InputMethodSubtype @Test public void inputConnection_finishComposingTextUpdatesIMM() throws JSONException { @@ -1310,7 +1321,7 @@ public void inputConnection_textInputTypeNone() { InputConnection connection = textInputPlugin.createInputConnection( testView, mock(KeyboardManager.class), new EditorInfo()); - assertEquals(connection, null); + assertNotNull(connection); } @Test