97 lines
4.0 KiB
Java
97 lines
4.0 KiB
Java
package io.flutter.embedding.engine.systemchannels;
|
|
|
|
import android.view.KeyEvent;
|
|
import com.google.firebase.crashlytics.internal.common.AbstractSpiCall;
|
|
import io.flutter.Log;
|
|
import io.flutter.embedding.engine.systemchannels.KeyEventChannel;
|
|
import io.flutter.plugin.common.BasicMessageChannel;
|
|
import io.flutter.plugin.common.BinaryMessenger;
|
|
import io.flutter.plugin.common.JSONMessageCodec;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public class KeyEventChannel {
|
|
private static final String TAG = "KeyEventChannel";
|
|
public final BasicMessageChannel<Object> channel;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public interface EventResponseHandler {
|
|
void onFrameworkResponse(boolean z);
|
|
}
|
|
|
|
public KeyEventChannel(BinaryMessenger binaryMessenger) {
|
|
this.channel = new BasicMessageChannel<>(binaryMessenger, "flutter/keyevent", JSONMessageCodec.INSTANCE);
|
|
}
|
|
|
|
public void sendFlutterKeyEvent(FlutterKeyEvent flutterKeyEvent, boolean z, EventResponseHandler eventResponseHandler) {
|
|
this.channel.send(encodeKeyEvent(flutterKeyEvent, z), createReplyHandler(eventResponseHandler));
|
|
}
|
|
|
|
private Map<String, Object> encodeKeyEvent(FlutterKeyEvent flutterKeyEvent, boolean z) {
|
|
HashMap hashMap = new HashMap();
|
|
hashMap.put("type", z ? "keyup" : "keydown");
|
|
hashMap.put("keymap", AbstractSpiCall.ANDROID_CLIENT_TYPE);
|
|
hashMap.put("flags", Integer.valueOf(flutterKeyEvent.event.getFlags()));
|
|
hashMap.put("plainCodePoint", Integer.valueOf(flutterKeyEvent.event.getUnicodeChar(0)));
|
|
hashMap.put("codePoint", Integer.valueOf(flutterKeyEvent.event.getUnicodeChar()));
|
|
hashMap.put("keyCode", Integer.valueOf(flutterKeyEvent.event.getKeyCode()));
|
|
hashMap.put("scanCode", Integer.valueOf(flutterKeyEvent.event.getScanCode()));
|
|
hashMap.put("metaState", Integer.valueOf(flutterKeyEvent.event.getMetaState()));
|
|
if (flutterKeyEvent.complexCharacter != null) {
|
|
hashMap.put("character", flutterKeyEvent.complexCharacter.toString());
|
|
}
|
|
hashMap.put("source", Integer.valueOf(flutterKeyEvent.event.getSource()));
|
|
hashMap.put("deviceId", Integer.valueOf(flutterKeyEvent.event.getDeviceId()));
|
|
hashMap.put("repeatCount", Integer.valueOf(flutterKeyEvent.event.getRepeatCount()));
|
|
return hashMap;
|
|
}
|
|
|
|
private static BasicMessageChannel.Reply<Object> createReplyHandler(final EventResponseHandler eventResponseHandler) {
|
|
return new BasicMessageChannel.Reply(eventResponseHandler) { // from class: io.flutter.embedding.engine.systemchannels.KeyEventChannel$$ExternalSyntheticLambda0
|
|
public final KeyEventChannel.EventResponseHandler f$0;
|
|
|
|
{
|
|
this.f$0 = eventResponseHandler;
|
|
}
|
|
|
|
@Override // io.flutter.plugin.common.BasicMessageChannel.Reply
|
|
public final void reply(Object obj) {
|
|
KeyEventChannel.lambda$createReplyHandler$0(this.f$0, obj);
|
|
}
|
|
};
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public static /* synthetic */ void lambda$createReplyHandler$0(EventResponseHandler eventResponseHandler, Object obj) {
|
|
boolean z;
|
|
if (obj != null) {
|
|
try {
|
|
z = ((JSONObject) obj).getBoolean("handled");
|
|
} catch (JSONException e) {
|
|
Log.e(TAG, "Unable to unpack JSON message: " + e);
|
|
}
|
|
eventResponseHandler.onFrameworkResponse(z);
|
|
}
|
|
z = false;
|
|
eventResponseHandler.onFrameworkResponse(z);
|
|
}
|
|
|
|
/* loaded from: classes6.dex */
|
|
public static class FlutterKeyEvent {
|
|
public final Character complexCharacter;
|
|
public final KeyEvent event;
|
|
|
|
public FlutterKeyEvent(KeyEvent keyEvent) {
|
|
this(keyEvent, null);
|
|
}
|
|
|
|
public FlutterKeyEvent(KeyEvent keyEvent, Character ch) {
|
|
this.event = keyEvent;
|
|
this.complexCharacter = ch;
|
|
}
|
|
}
|
|
}
|