Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Public Attributes | Package Attributes | List of all members
io.flutter.embedding.engine.systemchannels.TextInputChannel Class Reference

Classes

class  Configuration
 
class  InputType
 
enum  TextCapitalization
 
class  TextEditState
 
interface  TextInputMethodHandler
 
enum  TextInputType
 

Public Member Functions

 TextInputChannel (@NonNull DartExecutor dartExecutor)
 
void requestExistingInputState ()
 
void updateEditingState (int inputClientId, @NonNull String text, int selectionStart, int selectionEnd, int composingStart, int composingEnd)
 
void updateEditingStateWithDeltas (int inputClientId, @NonNull ArrayList< TextEditingDelta > batchDeltas)
 
void updateEditingStateWithTag (int inputClientId, @NonNull HashMap< String, TextEditState > editStates)
 
void newline (int inputClientId)
 
void go (int inputClientId)
 
void search (int inputClientId)
 
void send (int inputClientId)
 
void done (int inputClientId)
 
void next (int inputClientId)
 
void previous (int inputClientId)
 
void unspecifiedAction (int inputClientId)
 
void commitContent (int inputClientId, Map< String, Object > content)
 
void performPrivateCommand (int inputClientId, @NonNull String action, @NonNull Bundle data)
 
void setTextInputMethodHandler (@Nullable TextInputMethodHandler textInputMethodHandler)
 

Public Attributes

final MethodChannel channel
 

Package Attributes

final MethodChannel.MethodCallHandler parsingMethodHandler
 

Detailed Description

TextInputChannel is a platform channel between Android and Flutter that is used to communicate information about the user's text input.

When the user presses an action button like "done" or "next", that action is sent from Android to Flutter through this TextInputChannel.

When an input system in the Flutter app wants to show the keyboard, or hide it, or configure editing state, etc. a message is sent from Flutter to Android through this TextInputChannel.

TextInputChannel comes with a default io.flutter.plugin.common.MethodChannel.MethodCallHandler that parses incoming messages from Flutter. Register a TextInputMethodHandler to respond to standard Flutter text input messages.

Definition at line 44 of file TextInputChannel.java.

Constructor & Destructor Documentation

◆ TextInputChannel()

io.flutter.embedding.engine.systemchannels.TextInputChannel.TextInputChannel ( @NonNull DartExecutor  dartExecutor)
inline

Constructs a TextInputChannel that connects Android to the Dart code running in
dartExecutor
.

The given dartExecutor is permitted to be idle or executing code.

See DartExecutor.

Definition at line 168 of file TextInputChannel.java.

168 {
169 this.channel = new MethodChannel(dartExecutor, "flutter/textinput", JSONMethodCodec.INSTANCE);
170 channel.setMethodCallHandler(parsingMethodHandler);
171 }

Member Function Documentation

◆ commitContent()

void io.flutter.embedding.engine.systemchannels.TextInputChannel.commitContent ( int  inputClientId,
Map< String, Object >  content 
)
inline

Instructs Flutter to commit inserted content back to the text channel.

Definition at line 332 of file TextInputChannel.java.

332 {
333 Log.v(TAG, "Sending 'commitContent' message.");
334 channel.invokeMethod(
335 "TextInputClient.performAction",
336 Arrays.asList(inputClientId, "TextInputAction.commitContent", content));
337 }
union flutter::testing::@2838::KeyboardChange::@76 content
void Log(const char *format,...) SK_PRINTF_LIKE(1

◆ done()

void io.flutter.embedding.engine.systemchannels.TextInputChannel.done ( int  inputClientId)
inline

Instructs Flutter to execute a "done" action.

Definition at line 303 of file TextInputChannel.java.

303 {
304 Log.v(TAG, "Sending 'done' message.");
305 channel.invokeMethod(
306 "TextInputClient.performAction", Arrays.asList(inputClientId, "TextInputAction.done"));
307 }

◆ go()

void io.flutter.embedding.engine.systemchannels.TextInputChannel.go ( int  inputClientId)
inline

Instructs Flutter to execute a "go" action.

Definition at line 282 of file TextInputChannel.java.

282 {
283 Log.v(TAG, "Sending 'go' message.");
284 channel.invokeMethod(
285 "TextInputClient.performAction", Arrays.asList(inputClientId, "TextInputAction.go"));
286 }

◆ newline()

void io.flutter.embedding.engine.systemchannels.TextInputChannel.newline ( int  inputClientId)
inline

Instructs Flutter to execute a "newline" action.

Definition at line 275 of file TextInputChannel.java.

275 {
276 Log.v(TAG, "Sending 'newline' message.");
277 channel.invokeMethod(
278 "TextInputClient.performAction", Arrays.asList(inputClientId, "TextInputAction.newline"));
279 }

◆ next()

void io.flutter.embedding.engine.systemchannels.TextInputChannel.next ( int  inputClientId)
inline

Instructs Flutter to execute a "next" action.

Definition at line 310 of file TextInputChannel.java.

310 {
311 Log.v(TAG, "Sending 'next' message.");
312 channel.invokeMethod(
313 "TextInputClient.performAction", Arrays.asList(inputClientId, "TextInputAction.next"));
314 }

◆ performPrivateCommand()

void io.flutter.embedding.engine.systemchannels.TextInputChannel.performPrivateCommand ( int  inputClientId,
@NonNull String  action,
@NonNull Bundle  data 
)
inline

Definition at line 339 of file TextInputChannel.java.

340 {
341 HashMap<Object, Object> json = new HashMap<>();
342 json.put("action", action);
343 if (data != null) {
344 HashMap<String, Object> dataMap = new HashMap<>();
345 Set<String> keySet = data.keySet();
346 for (String key : keySet) {
347 Object value = data.get(key);
348 if (value instanceof byte[]) {
349 dataMap.put(key, data.getByteArray(key));
350 } else if (value instanceof Byte) {
351 dataMap.put(key, data.getByte(key));
352 } else if (value instanceof char[]) {
353 dataMap.put(key, data.getCharArray(key));
354 } else if (value instanceof Character) {
355 dataMap.put(key, data.getChar(key));
356 } else if (value instanceof CharSequence[]) {
357 dataMap.put(key, data.getCharSequenceArray(key));
358 } else if (value instanceof CharSequence) {
359 dataMap.put(key, data.getCharSequence(key));
360 } else if (value instanceof float[]) {
361 dataMap.put(key, data.getFloatArray(key));
362 } else if (value instanceof Float) {
363 dataMap.put(key, data.getFloat(key));
364 }
365 }
366 json.put("data", dataMap);
367 }
368 channel.invokeMethod(
369 "TextInputClient.performPrivateCommand", Arrays.asList(inputClientId, json));
370 }
uint8_t value
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41

◆ previous()

void io.flutter.embedding.engine.systemchannels.TextInputChannel.previous ( int  inputClientId)
inline

Instructs Flutter to execute a "previous" action.

Definition at line 317 of file TextInputChannel.java.

317 {
318 Log.v(TAG, "Sending 'previous' message.");
319 channel.invokeMethod(
320 "TextInputClient.performAction", Arrays.asList(inputClientId, "TextInputAction.previous"));
321 }

◆ requestExistingInputState()

void io.flutter.embedding.engine.systemchannels.TextInputChannel.requestExistingInputState ( )
inline

Instructs Flutter to reattach the last active text input client, if any.

This is necessary when the view hierarchy has been detached and reattached to a io.flutter.embedding.engine.FlutterEngine, as the engine may have kept alive a text editing client on the Dart side.

Definition at line 180 of file TextInputChannel.java.

180 {
181 channel.invokeMethod("TextInputClient.requestExistingInputState", null);
182 }

◆ search()

void io.flutter.embedding.engine.systemchannels.TextInputChannel.search ( int  inputClientId)
inline

Instructs Flutter to execute a "search" action.

Definition at line 289 of file TextInputChannel.java.

289 {
290 Log.v(TAG, "Sending 'search' message.");
291 channel.invokeMethod(
292 "TextInputClient.performAction", Arrays.asList(inputClientId, "TextInputAction.search"));
293 }

◆ send()

void io.flutter.embedding.engine.systemchannels.TextInputChannel.send ( int  inputClientId)
inline

Instructs Flutter to execute a "send" action.

Definition at line 296 of file TextInputChannel.java.

296 {
297 Log.v(TAG, "Sending 'send' message.");
298 channel.invokeMethod(
299 "TextInputClient.performAction", Arrays.asList(inputClientId, "TextInputAction.send"));
300 }

◆ setTextInputMethodHandler()

void io.flutter.embedding.engine.systemchannels.TextInputChannel.setTextInputMethodHandler ( @Nullable TextInputMethodHandler  textInputMethodHandler)
inline

Sets the TextInputMethodHandler which receives all events and requests that are parsed from the underlying platform channel.

Definition at line 376 of file TextInputChannel.java.

376 {
377 this.textInputMethodHandler = textInputMethodHandler;
378 }

◆ unspecifiedAction()

void io.flutter.embedding.engine.systemchannels.TextInputChannel.unspecifiedAction ( int  inputClientId)
inline

Instructs Flutter to execute an "unspecified" action.

Definition at line 324 of file TextInputChannel.java.

324 {
325 Log.v(TAG, "Sending 'unspecified' message.");
326 channel.invokeMethod(
327 "TextInputClient.performAction",
328 Arrays.asList(inputClientId, "TextInputAction.unspecified"));
329 }

◆ updateEditingState()

void io.flutter.embedding.engine.systemchannels.TextInputChannel.updateEditingState ( int  inputClientId,
@NonNull String  text,
int  selectionStart,
int  selectionEnd,
int  composingStart,
int  composingEnd 
)
inline

Instructs Flutter to update its text input editing state to reflect the given configuration.

Definition at line 209 of file TextInputChannel.java.

215 {
216 Log.v(
217 TAG,
218 "Sending message to update editing state: \n"
219 + "Text: "
220 + text
221 + "\n"
222 + "Selection start: "
223 + selectionStart
224 + "\n"
225 + "Selection end: "
226 + selectionEnd
227 + "\n"
228 + "Composing start: "
229 + composingStart
230 + "\n"
231 + "Composing end: "
232 + composingEnd);
233
234 final HashMap<Object, Object> state =
235 createEditingStateJSON(text, selectionStart, selectionEnd, composingStart, composingEnd);
236
237 channel.invokeMethod("TextInputClient.updateEditingState", Arrays.asList(inputClientId, state));
238 }
AtkStateType state
std::u16string text

◆ updateEditingStateWithDeltas()

void io.flutter.embedding.engine.systemchannels.TextInputChannel.updateEditingStateWithDeltas ( int  inputClientId,
@NonNull ArrayList< TextEditingDelta >  batchDeltas 
)
inline

Definition at line 240 of file TextInputChannel.java.

241 {
242
243 Log.v(
244 TAG,
245 "Sending message to update editing state with deltas: \n"
246 + "Number of deltas: "
247 + batchDeltas.size());
248
249 final HashMap<Object, Object> state = createEditingDeltaJSON(batchDeltas);
250
251 channel.invokeMethod(
252 "TextInputClient.updateEditingStateWithDeltas", Arrays.asList(inputClientId, state));
253 }

◆ updateEditingStateWithTag()

void io.flutter.embedding.engine.systemchannels.TextInputChannel.updateEditingStateWithTag ( int  inputClientId,
@NonNull HashMap< String, TextEditState editStates 
)
inline

Definition at line 255 of file TextInputChannel.java.

256 {
257 Log.v(
258 TAG,
259 "Sending message to update editing state for "
260 + String.valueOf(editStates.size())
261 + " field(s).");
262
263 final HashMap<String, HashMap<Object, Object>> json = new HashMap<>();
264 for (Map.Entry<String, TextEditState> element : editStates.entrySet()) {
265 final TextEditState state = element.getValue();
266 json.put(
267 element.getKey(),
268 createEditingStateJSON(state.text, state.selectionStart, state.selectionEnd, -1, -1));
269 }
270 channel.invokeMethod(
271 "TextInputClient.updateEditingStateWithTag", Arrays.asList(inputClientId, json));
272 }

Member Data Documentation

◆ channel

final MethodChannel io.flutter.embedding.engine.systemchannels.TextInputChannel.channel

Definition at line 47 of file TextInputChannel.java.

◆ parsingMethodHandler

final MethodChannel.MethodCallHandler io.flutter.embedding.engine.systemchannels.TextInputChannel.parsingMethodHandler
package

Definition at line 51 of file TextInputChannel.java.

52 {
53 @Override
54 public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
55 if (textInputMethodHandler == null) {
56 // If no explicit TextInputMethodHandler has been registered then we don't
57 // need to forward this call to an API. Return.
58 return;
59 }
60
61 String method = call.method;
62 Object args = call.arguments;
63 Log.v(TAG, "Received '" + method + "' message.");
64 switch (method) {
65 case "TextInput.show":
66 textInputMethodHandler.show();
67 result.success(null);
68 break;
69 case "TextInput.hide":
70 textInputMethodHandler.hide();
71 result.success(null);
72 break;
73 case "TextInput.setClient":
74 try {
75 final JSONArray argumentList = (JSONArray) args;
76 final int textInputClientId = argumentList.getInt(0);
77 final JSONObject jsonConfiguration = argumentList.getJSONObject(1);
78 textInputMethodHandler.setClient(
79 textInputClientId, Configuration.fromJson(jsonConfiguration));
80 result.success(null);
81 } catch (JSONException | NoSuchFieldException exception) {
82 // JSONException: missing keys or bad value types.
83 // NoSuchFieldException: one or more values were invalid.
84 result.error("error", exception.getMessage(), null);
85 }
86 break;
87 case "TextInput.requestAutofill":
88 textInputMethodHandler.requestAutofill();
89 result.success(null);
90 break;
91 case "TextInput.setPlatformViewClient":
92 try {
93 final JSONObject arguments = (JSONObject) args;
94 final int platformViewId = arguments.getInt("platformViewId");
95 final boolean usesVirtualDisplay =
96 arguments.optBoolean("usesVirtualDisplay", false);
97 textInputMethodHandler.setPlatformViewClient(platformViewId, usesVirtualDisplay);
98 result.success(null);
99 } catch (JSONException exception) {
100 result.error("error", exception.getMessage(), null);
101 }
102 break;
103 case "TextInput.setEditingState":
104 try {
105 final JSONObject editingState = (JSONObject) args;
106 textInputMethodHandler.setEditingState(TextEditState.fromJson(editingState));
107 result.success(null);
108 } catch (JSONException exception) {
109 result.error("error", exception.getMessage(), null);
110 }
111 break;
112 case "TextInput.setEditableSizeAndTransform":
113 try {
114 final JSONObject arguments = (JSONObject) args;
115 final double width = arguments.getDouble("width");
116 final double height = arguments.getDouble("height");
117 final JSONArray jsonMatrix = arguments.getJSONArray("transform");
118 final double[] matrix = new double[16];
119 for (int i = 0; i < 16; i++) {
120 matrix[i] = jsonMatrix.getDouble(i);
121 }
122
123 textInputMethodHandler.setEditableSizeAndTransform(width, height, matrix);
124 result.success(null);
125 } catch (JSONException exception) {
126 result.error("error", exception.getMessage(), null);
127 }
128 break;
129 case "TextInput.clearClient":
130 textInputMethodHandler.clearClient();
131 result.success(null);
132 break;
133 case "TextInput.sendAppPrivateCommand":
134 try {
135 final JSONObject arguments = (JSONObject) args;
136 final String action = arguments.getString("action");
137 final String data = arguments.getString("data");
138 Bundle bundle = null;
139 if (data != null && !data.isEmpty()) {
140 bundle = new Bundle();
141 bundle.putString("data", data);
142 }
143 textInputMethodHandler.sendAppPrivateCommand(action, bundle);
144 result.success(null);
145 } catch (JSONException exception) {
146 result.error("error", exception.getMessage(), null);
147 }
148 break;
149 case "TextInput.finishAutofillContext":
150 textInputMethodHandler.finishAutofillContext((boolean) args);
151 result.success(null);
152 break;
153 default:
154 result.notImplemented();
155 break;
156 }
157 }
158 };
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static ::testing::Matcher< GBytes * > MethodCall(const std::string &name, ::testing::Matcher< FlValue * > args)
GAsyncResult * result
void sendAppPrivateCommand(@NonNull String action, @NonNull Bundle data)
void setClient(int textInputClientId, @NonNull Configuration configuration)
void setEditableSizeAndTransform(double width, double height, @NonNull double[] transform)
unsigned useCenter Optional< SkMatrix > matrix
Definition SkRecords.h:258
call(args)
Definition dom.py:159
int32_t height
int32_t width

The documentation for this class was generated from the following file: