Skip to content

Commit 7071dc7

Browse files
authored
NO_SUGGESTIONS keyboard flag in Android (flutter#13099)
Add the enableSuggestions parameter to control Android's keyboard suggestions
1 parent 195425e commit 7071dc7

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ public static Configuration fromJson(@NonNull JSONObject json) throws JSONExcept
271271
return new Configuration(
272272
json.optBoolean("obscureText"),
273273
json.optBoolean("autocorrect", true),
274+
json.optBoolean("enableSuggestions"),
274275
TextCapitalization.fromValue(json.getString("textCapitalization")),
275276
InputType.fromJson(json.getJSONObject("inputType")),
276277
inputAction,
@@ -307,6 +308,7 @@ private static Integer inputActionFromTextInputAction(@NonNull String inputActio
307308

308309
public final boolean obscureText;
309310
public final boolean autocorrect;
311+
public final boolean enableSuggestions;
310312
@NonNull
311313
public final TextCapitalization textCapitalization;
312314
@NonNull
@@ -319,13 +321,15 @@ private static Integer inputActionFromTextInputAction(@NonNull String inputActio
319321
public Configuration(
320322
boolean obscureText,
321323
boolean autocorrect,
324+
boolean enableSuggestions,
322325
@NonNull TextCapitalization textCapitalization,
323326
@NonNull InputType inputType,
324327
@Nullable Integer inputAction,
325328
@Nullable String actionLabel
326329
) {
327330
this.obscureText = obscureText;
328331
this.autocorrect = autocorrect;
332+
this.enableSuggestions = enableSuggestions;
329333
this.textCapitalization = textCapitalization;
330334
this.inputType = inputType;
331335
this.inputAction = inputAction;

shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ private static int inputTypeFromTextInputType(
138138
TextInputChannel.InputType type,
139139
boolean obscureText,
140140
boolean autocorrect,
141+
boolean enableSuggestions,
141142
TextInputChannel.TextCapitalization textCapitalization
142143
) {
143144
if (type.type == TextInputChannel.TextInputType.DATETIME) {
@@ -172,6 +173,7 @@ private static int inputTypeFromTextInputType(
172173
textType |= InputType.TYPE_TEXT_VARIATION_PASSWORD;
173174
} else {
174175
if (autocorrect) textType |= InputType.TYPE_TEXT_FLAG_AUTO_CORRECT;
176+
if (!enableSuggestions) textType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
175177
}
176178

177179
if (textCapitalization == TextInputChannel.TextCapitalization.CHARACTERS) {
@@ -203,6 +205,7 @@ public InputConnection createInputConnection(View view, EditorInfo outAttrs) {
203205
configuration.inputType,
204206
configuration.obscureText,
205207
configuration.autocorrect,
208+
configuration.enableSuggestions,
206209
configuration.textCapitalization
207210
);
208211
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN;

shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void setTextInputEditingState_doesNotRestartWhenTextIsIdentical() {
3636
testImm.setCurrentInputMethodSubtype(inputMethodSubtype);
3737
View testView = new View(RuntimeEnvironment.application);
3838
TextInputPlugin textInputPlugin = new TextInputPlugin(testView, mock(DartExecutor.class), mock(PlatformViewsController.class));
39-
textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, TextInputChannel.TextCapitalization.NONE, null, null, null));
39+
textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, true, TextInputChannel.TextCapitalization.NONE, null, null, null));
4040
// There's a pending restart since we initialized the text input client. Flush that now.
4141
textInputPlugin.setTextInputEditingState(testView, new TextInputChannel.TextEditState("", 0, 0));
4242

@@ -61,7 +61,7 @@ public void setTextInputEditingState_alwaysRestartsOnAffectedDevices2() {
6161
testImm.setCurrentInputMethodSubtype(inputMethodSubtype);
6262
View testView = new View(RuntimeEnvironment.application);
6363
TextInputPlugin textInputPlugin = new TextInputPlugin(testView, mock(DartExecutor.class), mock(PlatformViewsController.class));
64-
textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, TextInputChannel.TextCapitalization.NONE, null, null, null));
64+
textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, true, TextInputChannel.TextCapitalization.NONE, null, null, null));
6565
// There's a pending restart since we initialized the text input client. Flush that now.
6666
textInputPlugin.setTextInputEditingState(testView, new TextInputChannel.TextEditState("", 0, 0));
6767

@@ -83,7 +83,7 @@ public void setTextInputEditingState_doesNotRestartOnUnaffectedDevices() {
8383
testImm.setCurrentInputMethodSubtype(inputMethodSubtype);
8484
View testView = new View(RuntimeEnvironment.application);
8585
TextInputPlugin textInputPlugin = new TextInputPlugin(testView, mock(DartExecutor.class), mock(PlatformViewsController.class));
86-
textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, TextInputChannel.TextCapitalization.NONE, null, null, null));
86+
textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, true, TextInputChannel.TextCapitalization.NONE, null, null, null));
8787
// There's a pending restart since we initialized the text input client. Flush that now.
8888
textInputPlugin.setTextInputEditingState(testView, new TextInputChannel.TextEditState("", 0, 0));
8989

@@ -102,7 +102,7 @@ public void setTextInputEditingState_nullInputMethodSubtype() {
102102

103103
View testView = new View(RuntimeEnvironment.application);
104104
TextInputPlugin textInputPlugin = new TextInputPlugin(testView, mock(DartExecutor.class), mock(PlatformViewsController.class));
105-
textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, TextInputChannel.TextCapitalization.NONE, null, null, null));
105+
textInputPlugin.setTextInputClient(0, new TextInputChannel.Configuration(false, false, true, TextInputChannel.TextCapitalization.NONE, null, null, null));
106106
// There's a pending restart since we initialized the text input client. Flush that now.
107107
textInputPlugin.setTextInputEditingState(testView, new TextInputChannel.TextEditState("", 0, 0));
108108
assertEquals(1, testImm.getRestartCount(testView));

0 commit comments

Comments
 (0)