what-the-bank/sources/io/flutter/embedding/android/KeyboardManager.java

153 lines
5.7 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package io.flutter.embedding.android;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import io.flutter.Log;
import io.flutter.embedding.engine.systemchannels.KeyEventChannel;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.editing.InputConnectionAdaptor;
import java.util.HashSet;
/* loaded from: classes6.dex */
public class KeyboardManager implements InputConnectionAdaptor.KeyboardDelegate {
private static final String TAG = "KeyboardManager";
private final HashSet<KeyEvent> redispatchedEvents = new HashSet<>();
protected final Responder[] responders;
private final ViewDelegate viewDelegate;
/* loaded from: classes6.dex */
public interface Responder {
/* loaded from: classes6.dex */
public interface OnKeyEventHandledCallback {
void onKeyEventHandled(boolean z);
}
void handleEvent(KeyEvent keyEvent, OnKeyEventHandledCallback onKeyEventHandledCallback);
}
/* loaded from: classes6.dex */
public interface ViewDelegate {
BinaryMessenger getBinaryMessenger();
boolean onTextInputKeyEvent(KeyEvent keyEvent);
void redispatch(KeyEvent keyEvent);
}
/* loaded from: classes6.dex */
public static class CharacterCombiner {
private int combiningCharacter = 0;
/* JADX INFO: Access modifiers changed from: package-private */
public Character applyCombiningCharacterToBaseCharacter(int i) {
char c = (char) i;
if ((Integer.MIN_VALUE & i) != 0) {
int i2 = i & Integer.MAX_VALUE;
int i3 = this.combiningCharacter;
if (i3 != 0) {
i2 = KeyCharacterMap.getDeadChar(i3, i2);
}
this.combiningCharacter = i2;
} else {
int i4 = this.combiningCharacter;
if (i4 != 0) {
int deadChar = KeyCharacterMap.getDeadChar(i4, i);
if (deadChar > 0) {
c = (char) deadChar;
}
this.combiningCharacter = 0;
}
}
return Character.valueOf(c);
}
}
public KeyboardManager(ViewDelegate viewDelegate) {
this.viewDelegate = viewDelegate;
this.responders = new Responder[]{new KeyEmbedderResponder(viewDelegate.getBinaryMessenger()), new KeyChannelResponder(new KeyEventChannel(viewDelegate.getBinaryMessenger()))};
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes6.dex */
public class PerEventCallbackBuilder {
boolean isEventHandled = false;
final KeyEvent keyEvent;
final KeyboardManager this$0;
int unrepliedCount;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes6.dex */
public class Callback implements Responder.OnKeyEventHandledCallback {
boolean isCalled;
final PerEventCallbackBuilder this$1;
private Callback(PerEventCallbackBuilder perEventCallbackBuilder) {
this.this$1 = perEventCallbackBuilder;
this.isCalled = false;
}
@Override // io.flutter.embedding.android.KeyboardManager.Responder.OnKeyEventHandledCallback
public void onKeyEventHandled(boolean z) {
if (this.isCalled) {
throw new IllegalStateException("The onKeyEventHandledCallback should be called exactly once.");
}
this.isCalled = true;
this.this$1.unrepliedCount--;
PerEventCallbackBuilder perEventCallbackBuilder = this.this$1;
perEventCallbackBuilder.isEventHandled = z | perEventCallbackBuilder.isEventHandled;
if (this.this$1.unrepliedCount != 0 || this.this$1.isEventHandled) {
return;
}
this.this$1.this$0.onUnhandled(this.this$1.keyEvent);
}
}
PerEventCallbackBuilder(KeyboardManager keyboardManager, KeyEvent keyEvent) {
this.this$0 = keyboardManager;
this.unrepliedCount = keyboardManager.responders.length;
this.keyEvent = keyEvent;
}
public Responder.OnKeyEventHandledCallback buildCallback() {
return new Callback();
}
}
@Override // io.flutter.plugin.editing.InputConnectionAdaptor.KeyboardDelegate
public boolean handleEvent(KeyEvent keyEvent) {
if (this.redispatchedEvents.remove(keyEvent)) {
return false;
}
if (this.responders.length > 0) {
PerEventCallbackBuilder perEventCallbackBuilder = new PerEventCallbackBuilder(this, keyEvent);
for (Responder responder : this.responders) {
responder.handleEvent(keyEvent, perEventCallbackBuilder.buildCallback());
}
return true;
}
onUnhandled(keyEvent);
return true;
}
public void destroy() {
int size = this.redispatchedEvents.size();
if (size > 0) {
Log.w(TAG, "A KeyboardManager was destroyed with " + String.valueOf(size) + " unhandled redispatch event(s).");
}
}
/* JADX INFO: Access modifiers changed from: private */
public void onUnhandled(KeyEvent keyEvent) {
ViewDelegate viewDelegate = this.viewDelegate;
if (viewDelegate == null || viewDelegate.onTextInputKeyEvent(keyEvent)) {
return;
}
this.redispatchedEvents.add(keyEvent);
this.viewDelegate.redispatch(keyEvent);
if (this.redispatchedEvents.remove(keyEvent)) {
Log.w(TAG, "A redispatched key event was consumed before reaching KeyboardManager");
}
}
}