5package io.flutter.embedding.engine.systemchannels;
8import androidx.annotation.NonNull;
9import androidx.annotation.Nullable;
11import io.flutter.plugin.common.BasicMessageChannel;
12import io.flutter.plugin.common.BinaryMessenger;
13import io.flutter.plugin.common.JSONMessageCodec;
14import java.util.HashMap;
16import org.json.JSONException;
17import org.json.JSONObject;
26 private static final String TAG =
"KeyEventChannel";
56 channel.
send(encodeKeyEvent(keyEvent, isKeyUp), createReplyHandler(responseHandler));
59 private Map<String, Object> encodeKeyEvent(@NonNull
FlutterKeyEvent keyEvent,
boolean isKeyUp) {
60 Map<String, Object>
message =
new HashMap<>();
61 message.put(
"type", isKeyUp ?
"keyup" :
"keydown");
62 message.put(
"keymap",
"android");
63 message.put(
"flags", keyEvent.event.getFlags());
64 message.put(
"plainCodePoint", keyEvent.event.getUnicodeChar(0x0));
65 message.put(
"codePoint", keyEvent.event.getUnicodeChar());
66 message.put(
"keyCode", keyEvent.event.getKeyCode());
67 message.put(
"scanCode", keyEvent.event.getScanCode());
68 message.put(
"metaState", keyEvent.event.getMetaState());
69 if (keyEvent.complexCharacter !=
null) {
70 message.put(
"character", keyEvent.complexCharacter.toString());
72 message.put(
"source", keyEvent.event.getSource());
73 message.put(
"deviceId", keyEvent.event.getDeviceId());
74 message.put(
"repeatCount", keyEvent.event.getRepeatCount());
83 private static BasicMessageChannel.Reply<Object> createReplyHandler(
84 @NonNull EventResponseHandler responseHandler) {
86 boolean isEventHandled =
false;
89 final JSONObject annotatedEvent = (JSONObject)
message;
90 isEventHandled = annotatedEvent.getBoolean(
"handled");
92 }
catch (JSONException
e) {
93 Log.e(TAG,
"Unable to unpack JSON message: " +
e);
95 responseHandler.onFrameworkResponse(isEventHandled);
114 this(androidKeyEvent,
null);
119 this.event = androidKeyEvent;
FlutterKeyEvent(@NonNull KeyEvent androidKeyEvent)
FlutterKeyEvent( @NonNull KeyEvent androidKeyEvent, @Nullable Character complexCharacter)
final Character complexCharacter
void sendFlutterKeyEvent( @NonNull FlutterKeyEvent keyEvent, boolean isKeyUp, @NonNull EventResponseHandler responseHandler)
KeyEventChannel(@NonNull BinaryMessenger binaryMessenger)
final BasicMessageChannel< Object > channel
void send(@Nullable T message)
static final JSONMessageCodec INSTANCE
void onFrameworkResponse(boolean isEventHandled)
void Log(const char *format,...) SK_PRINTF_LIKE(1