110 lines
3.7 KiB
Java
110 lines
3.7 KiB
Java
package androidx.core.view;
|
|
|
|
import android.app.ActionBar;
|
|
import android.app.Activity;
|
|
import android.app.Dialog;
|
|
import android.content.DialogInterface;
|
|
import android.os.Build;
|
|
import android.view.KeyEvent;
|
|
import android.view.View;
|
|
import android.view.Window;
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class KeyEventDispatcher {
|
|
private static boolean a = false;
|
|
private static Method b = null;
|
|
private static boolean c = false;
|
|
private static Field d;
|
|
|
|
public interface Component {
|
|
boolean superDispatchKeyEvent(KeyEvent keyEvent);
|
|
}
|
|
|
|
public static boolean a(View view, KeyEvent keyEvent) {
|
|
return ViewCompat.b(view, keyEvent);
|
|
}
|
|
|
|
public static boolean a(Component component, View view, Window.Callback callback, KeyEvent keyEvent) {
|
|
if (component == null) {
|
|
return false;
|
|
}
|
|
return Build.VERSION.SDK_INT >= 28 ? component.superDispatchKeyEvent(keyEvent) : callback instanceof Activity ? a((Activity) callback, keyEvent) : callback instanceof Dialog ? a((Dialog) callback, keyEvent) : (view != null && ViewCompat.a(view, keyEvent)) || component.superDispatchKeyEvent(keyEvent);
|
|
}
|
|
|
|
private static boolean a(ActionBar actionBar, KeyEvent keyEvent) {
|
|
if (!a) {
|
|
try {
|
|
b = actionBar.getClass().getMethod("onMenuKeyEvent", KeyEvent.class);
|
|
} catch (NoSuchMethodException unused) {
|
|
}
|
|
a = true;
|
|
}
|
|
Method method = b;
|
|
if (method != null) {
|
|
try {
|
|
return ((Boolean) method.invoke(actionBar, keyEvent)).booleanValue();
|
|
} catch (IllegalAccessException | InvocationTargetException unused2) {
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private static boolean a(Activity activity, KeyEvent keyEvent) {
|
|
activity.onUserInteraction();
|
|
Window window = activity.getWindow();
|
|
if (window.hasFeature(8)) {
|
|
ActionBar actionBar = activity.getActionBar();
|
|
if (keyEvent.getKeyCode() == 82 && actionBar != null && a(actionBar, keyEvent)) {
|
|
return true;
|
|
}
|
|
}
|
|
if (window.superDispatchKeyEvent(keyEvent)) {
|
|
return true;
|
|
}
|
|
View decorView = window.getDecorView();
|
|
if (ViewCompat.a(decorView, keyEvent)) {
|
|
return true;
|
|
}
|
|
return keyEvent.dispatch(activity, decorView != null ? decorView.getKeyDispatcherState() : null, activity);
|
|
}
|
|
|
|
private static DialogInterface.OnKeyListener a(Dialog dialog) {
|
|
if (!c) {
|
|
try {
|
|
d = Dialog.class.getDeclaredField("mOnKeyListener");
|
|
d.setAccessible(true);
|
|
} catch (NoSuchFieldException unused) {
|
|
}
|
|
c = true;
|
|
}
|
|
Field field = d;
|
|
if (field == null) {
|
|
return null;
|
|
}
|
|
try {
|
|
return (DialogInterface.OnKeyListener) field.get(dialog);
|
|
} catch (IllegalAccessException unused2) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private static boolean a(Dialog dialog, KeyEvent keyEvent) {
|
|
DialogInterface.OnKeyListener a2 = a(dialog);
|
|
if (a2 != null && a2.onKey(dialog, keyEvent.getKeyCode(), keyEvent)) {
|
|
return true;
|
|
}
|
|
Window window = dialog.getWindow();
|
|
if (window.superDispatchKeyEvent(keyEvent)) {
|
|
return true;
|
|
}
|
|
View decorView = window.getDecorView();
|
|
if (ViewCompat.a(decorView, keyEvent)) {
|
|
return true;
|
|
}
|
|
return keyEvent.dispatch(dialog, decorView != null ? decorView.getKeyDispatcherState() : null, dialog);
|
|
}
|
|
}
|