From ba3d4ff5eb0699abff703b6022faeb7715be6b76 Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Thu, 10 Oct 2019 15:41:45 -0700 Subject: [PATCH 1/3] Allow control over NO_SUGGESTIONS keyboard flag in Android --- .../embedding/engine/systemchannels/TextInputChannel.java | 4 ++++ .../android/io/flutter/plugin/editing/TextInputPlugin.java | 3 +++ 2 files changed, 7 insertions(+) diff --git a/shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java b/shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java index 55386eeba5b45..1baa407ab7add 100644 --- a/shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java +++ b/shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java @@ -271,6 +271,7 @@ public static Configuration fromJson(@NonNull JSONObject json) throws JSONExcept return new Configuration( json.optBoolean("obscureText"), json.optBoolean("autocorrect", true), + json.optBoolean("noSuggestions"), TextCapitalization.fromValue(json.getString("textCapitalization")), InputType.fromJson(json.getJSONObject("inputType")), inputAction, @@ -307,6 +308,7 @@ private static Integer inputActionFromTextInputAction(@NonNull String inputActio public final boolean obscureText; public final boolean autocorrect; + public final boolean noSuggestions; @NonNull public final TextCapitalization textCapitalization; @NonNull @@ -319,6 +321,7 @@ private static Integer inputActionFromTextInputAction(@NonNull String inputActio public Configuration( boolean obscureText, boolean autocorrect, + boolean noSuggestions, @NonNull TextCapitalization textCapitalization, @NonNull InputType inputType, @Nullable Integer inputAction, @@ -326,6 +329,7 @@ public Configuration( ) { this.obscureText = obscureText; this.autocorrect = autocorrect; + this.noSuggestions = noSuggestions; this.textCapitalization = textCapitalization; this.inputType = inputType; this.inputAction = inputAction; diff --git a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index 5c23ea40beca9..0c2e0574a3341 100644 --- a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -138,6 +138,7 @@ private static int inputTypeFromTextInputType( TextInputChannel.InputType type, boolean obscureText, boolean autocorrect, + boolean noSuggestions, TextInputChannel.TextCapitalization textCapitalization ) { if (type.type == TextInputChannel.TextInputType.DATETIME) { @@ -172,6 +173,7 @@ private static int inputTypeFromTextInputType( textType |= InputType.TYPE_TEXT_VARIATION_PASSWORD; } else { if (autocorrect) textType |= InputType.TYPE_TEXT_FLAG_AUTO_CORRECT; + if (noSuggestions) textType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; } if (textCapitalization == TextInputChannel.TextCapitalization.CHARACTERS) { @@ -203,6 +205,7 @@ public InputConnection createInputConnection(View view, EditorInfo outAttrs) { configuration.inputType, configuration.obscureText, configuration.autocorrect, + configuration.noSuggestions, configuration.textCapitalization ); outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN; From 31d230283bdbc52dfb8e5204c556cfa501e61f1b Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Mon, 14 Oct 2019 09:09:20 -0700 Subject: [PATCH 2/3] Update tests to include noSuggestions param --- .../io/flutter/plugin/editing/TextInputPluginTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 cd5eb377861dc..3ed54eb8724a5 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -36,7 +36,7 @@ public void setTextInputEditingState_doesNotRestartWhenTextIsIdentical() { testImm.setCurrentInputMethodSubtype(inputMethodSubtype); View testView = new View(RuntimeEnvironment.application); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, mock(DartExecutor.class), mock(PlatformViewsController.class)); - textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, TextInputChannel.TextCapitalization.NONE, null, null, null)); + textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, false, TextInputChannel.TextCapitalization.NONE, null, null, null)); // There's a pending restart since we initialized the text input client. Flush that now. textInputPlugin.setTextInputEditingState(testView, new TextInputChannel.TextEditState("", 0, 0)); @@ -61,7 +61,7 @@ public void setTextInputEditingState_alwaysRestartsOnAffectedDevices2() { testImm.setCurrentInputMethodSubtype(inputMethodSubtype); View testView = new View(RuntimeEnvironment.application); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, mock(DartExecutor.class), mock(PlatformViewsController.class)); - textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, TextInputChannel.TextCapitalization.NONE, null, null, null)); + textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, false, TextInputChannel.TextCapitalization.NONE, null, null, null)); // There's a pending restart since we initialized the text input client. Flush that now. textInputPlugin.setTextInputEditingState(testView, new TextInputChannel.TextEditState("", 0, 0)); @@ -83,7 +83,7 @@ public void setTextInputEditingState_doesNotRestartOnUnaffectedDevices() { testImm.setCurrentInputMethodSubtype(inputMethodSubtype); View testView = new View(RuntimeEnvironment.application); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, mock(DartExecutor.class), mock(PlatformViewsController.class)); - textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, TextInputChannel.TextCapitalization.NONE, null, null, null)); + textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, false, TextInputChannel.TextCapitalization.NONE, null, null, null)); // There's a pending restart since we initialized the text input client. Flush that now. textInputPlugin.setTextInputEditingState(testView, new TextInputChannel.TextEditState("", 0, 0)); @@ -102,7 +102,7 @@ public void setTextInputEditingState_nullInputMethodSubtype() { View testView = new View(RuntimeEnvironment.application); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, mock(DartExecutor.class), mock(PlatformViewsController.class)); - textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, TextInputChannel.TextCapitalization.NONE, null, null, null)); + textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, false, TextInputChannel.TextCapitalization.NONE, null, null, null)); // There's a pending restart since we initialized the text input client. Flush that now. textInputPlugin.setTextInputEditingState(testView, new TextInputChannel.TextEditState("", 0, 0)); assertEquals(1, testImm.getRestartCount(testView)); From 9cf6705cd2bfcf5c1ea67e5b91738184466af670 Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Mon, 21 Oct 2019 11:22:04 -0700 Subject: [PATCH 3/3] Change noSuggestions to enableSuggestions --- .../embedding/engine/systemchannels/TextInputChannel.java | 8 ++++---- .../io/flutter/plugin/editing/TextInputPlugin.java | 6 +++--- .../io/flutter/plugin/editing/TextInputPluginTest.java | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java b/shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java index 1baa407ab7add..8432269407288 100644 --- a/shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java +++ b/shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java @@ -271,7 +271,7 @@ public static Configuration fromJson(@NonNull JSONObject json) throws JSONExcept return new Configuration( json.optBoolean("obscureText"), json.optBoolean("autocorrect", true), - json.optBoolean("noSuggestions"), + json.optBoolean("enableSuggestions"), TextCapitalization.fromValue(json.getString("textCapitalization")), InputType.fromJson(json.getJSONObject("inputType")), inputAction, @@ -308,7 +308,7 @@ private static Integer inputActionFromTextInputAction(@NonNull String inputActio public final boolean obscureText; public final boolean autocorrect; - public final boolean noSuggestions; + public final boolean enableSuggestions; @NonNull public final TextCapitalization textCapitalization; @NonNull @@ -321,7 +321,7 @@ private static Integer inputActionFromTextInputAction(@NonNull String inputActio public Configuration( boolean obscureText, boolean autocorrect, - boolean noSuggestions, + boolean enableSuggestions, @NonNull TextCapitalization textCapitalization, @NonNull InputType inputType, @Nullable Integer inputAction, @@ -329,7 +329,7 @@ public Configuration( ) { this.obscureText = obscureText; this.autocorrect = autocorrect; - this.noSuggestions = noSuggestions; + this.enableSuggestions = enableSuggestions; this.textCapitalization = textCapitalization; this.inputType = inputType; this.inputAction = inputAction; diff --git a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index 0c2e0574a3341..68efb65142e78 100644 --- a/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -138,7 +138,7 @@ private static int inputTypeFromTextInputType( TextInputChannel.InputType type, boolean obscureText, boolean autocorrect, - boolean noSuggestions, + boolean enableSuggestions, TextInputChannel.TextCapitalization textCapitalization ) { if (type.type == TextInputChannel.TextInputType.DATETIME) { @@ -173,7 +173,7 @@ private static int inputTypeFromTextInputType( textType |= InputType.TYPE_TEXT_VARIATION_PASSWORD; } else { if (autocorrect) textType |= InputType.TYPE_TEXT_FLAG_AUTO_CORRECT; - if (noSuggestions) textType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; + if (!enableSuggestions) textType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; } if (textCapitalization == TextInputChannel.TextCapitalization.CHARACTERS) { @@ -205,7 +205,7 @@ public InputConnection createInputConnection(View view, EditorInfo outAttrs) { configuration.inputType, configuration.obscureText, configuration.autocorrect, - configuration.noSuggestions, + configuration.enableSuggestions, configuration.textCapitalization ); outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN; 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 3ed54eb8724a5..0342668e21d7a 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java @@ -36,7 +36,7 @@ public void setTextInputEditingState_doesNotRestartWhenTextIsIdentical() { testImm.setCurrentInputMethodSubtype(inputMethodSubtype); View testView = new View(RuntimeEnvironment.application); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, mock(DartExecutor.class), mock(PlatformViewsController.class)); - textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, false, TextInputChannel.TextCapitalization.NONE, null, null, null)); + textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, true, TextInputChannel.TextCapitalization.NONE, null, null, null)); // There's a pending restart since we initialized the text input client. Flush that now. textInputPlugin.setTextInputEditingState(testView, new TextInputChannel.TextEditState("", 0, 0)); @@ -61,7 +61,7 @@ public void setTextInputEditingState_alwaysRestartsOnAffectedDevices2() { testImm.setCurrentInputMethodSubtype(inputMethodSubtype); View testView = new View(RuntimeEnvironment.application); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, mock(DartExecutor.class), mock(PlatformViewsController.class)); - textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, false, TextInputChannel.TextCapitalization.NONE, null, null, null)); + textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, true, TextInputChannel.TextCapitalization.NONE, null, null, null)); // There's a pending restart since we initialized the text input client. Flush that now. textInputPlugin.setTextInputEditingState(testView, new TextInputChannel.TextEditState("", 0, 0)); @@ -83,7 +83,7 @@ public void setTextInputEditingState_doesNotRestartOnUnaffectedDevices() { testImm.setCurrentInputMethodSubtype(inputMethodSubtype); View testView = new View(RuntimeEnvironment.application); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, mock(DartExecutor.class), mock(PlatformViewsController.class)); - textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, false, TextInputChannel.TextCapitalization.NONE, null, null, null)); + textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, true, TextInputChannel.TextCapitalization.NONE, null, null, null)); // There's a pending restart since we initialized the text input client. Flush that now. textInputPlugin.setTextInputEditingState(testView, new TextInputChannel.TextEditState("", 0, 0)); @@ -102,7 +102,7 @@ public void setTextInputEditingState_nullInputMethodSubtype() { View testView = new View(RuntimeEnvironment.application); TextInputPlugin textInputPlugin = new TextInputPlugin(testView, mock(DartExecutor.class), mock(PlatformViewsController.class)); - textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, false, TextInputChannel.TextCapitalization.NONE, null, null, null)); + textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, true, TextInputChannel.TextCapitalization.NONE, null, null, null)); // There's a pending restart since we initialized the text input client. Flush that now. textInputPlugin.setTextInputEditingState(testView, new TextInputChannel.TextEditState("", 0, 0)); assertEquals(1, testImm.getRestartCount(testView));