mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2025-01-09 13:43:22 +00:00
345 lines
14 KiB
Java
345 lines
14 KiB
Java
package io.flutter.plugin.platform;
|
|
|
|
import android.app.AlertDialog;
|
|
import android.app.Presentation;
|
|
import android.content.Context;
|
|
import android.content.ContextWrapper;
|
|
import android.content.MutableContextWrapper;
|
|
import android.graphics.Rect;
|
|
import android.graphics.drawable.ColorDrawable;
|
|
import android.os.Bundle;
|
|
import android.view.Display;
|
|
import android.view.Gravity;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.WindowManager;
|
|
import android.view.accessibility.AccessibilityEvent;
|
|
import android.view.inputmethod.InputMethodManager;
|
|
import android.widget.FrameLayout;
|
|
import io.flutter.Log;
|
|
import java.lang.reflect.InvocationHandler;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Proxy;
|
|
|
|
/* loaded from: classes3.dex */
|
|
class SingleViewPresentation extends Presentation {
|
|
private static final String TAG = "PlatformViewsController";
|
|
private final AccessibilityEventsDelegate accessibilityEventsDelegate;
|
|
private FrameLayout container;
|
|
private final View.OnFocusChangeListener focusChangeListener;
|
|
private final Context outerContext;
|
|
private AccessibilityDelegatingFrameLayout rootView;
|
|
private boolean startFocused;
|
|
private final PresentationState state;
|
|
private int viewId;
|
|
|
|
/* loaded from: classes3.dex */
|
|
static class PresentationState {
|
|
private FakeWindowViewGroup fakeWindowViewGroup;
|
|
private PlatformView platformView;
|
|
private WindowManagerHandler windowManagerHandler;
|
|
|
|
PresentationState() {
|
|
}
|
|
}
|
|
|
|
public SingleViewPresentation(Context context, Display display, PlatformView platformView, AccessibilityEventsDelegate accessibilityEventsDelegate, int i, View.OnFocusChangeListener onFocusChangeListener) {
|
|
super(new ImmContext(context), display);
|
|
this.startFocused = false;
|
|
this.accessibilityEventsDelegate = accessibilityEventsDelegate;
|
|
this.viewId = i;
|
|
this.focusChangeListener = onFocusChangeListener;
|
|
this.outerContext = context;
|
|
PresentationState presentationState = new PresentationState();
|
|
this.state = presentationState;
|
|
presentationState.platformView = platformView;
|
|
getWindow().setFlags(8, 8);
|
|
getWindow().setType(2030);
|
|
}
|
|
|
|
public SingleViewPresentation(Context context, Display display, AccessibilityEventsDelegate accessibilityEventsDelegate, PresentationState presentationState, View.OnFocusChangeListener onFocusChangeListener, boolean z) {
|
|
super(new ImmContext(context), display);
|
|
this.startFocused = false;
|
|
this.accessibilityEventsDelegate = accessibilityEventsDelegate;
|
|
this.state = presentationState;
|
|
this.focusChangeListener = onFocusChangeListener;
|
|
this.outerContext = context;
|
|
getWindow().setFlags(8, 8);
|
|
this.startFocused = z;
|
|
}
|
|
|
|
@Override // android.app.Dialog
|
|
protected void onCreate(Bundle bundle) {
|
|
super.onCreate(bundle);
|
|
getWindow().setBackgroundDrawable(new ColorDrawable(0));
|
|
if (this.state.fakeWindowViewGroup == null) {
|
|
this.state.fakeWindowViewGroup = new FakeWindowViewGroup(getContext());
|
|
}
|
|
if (this.state.windowManagerHandler == null) {
|
|
this.state.windowManagerHandler = new WindowManagerHandler((WindowManager) getContext().getSystemService("window"), this.state.fakeWindowViewGroup);
|
|
}
|
|
this.container = new FrameLayout(getContext());
|
|
PresentationContext presentationContext = new PresentationContext(getContext(), this.state.windowManagerHandler, this.outerContext);
|
|
View view = this.state.platformView.getView();
|
|
if (view.getContext() instanceof MutableContextWrapper) {
|
|
((MutableContextWrapper) view.getContext()).setBaseContext(presentationContext);
|
|
} else {
|
|
Log.w(TAG, "Unexpected platform view context for view ID " + this.viewId + "; some functionality may not work correctly. When constructing a platform view in the factory, ensure that the view returned from PlatformViewFactory#create returns the provided context from getContext(). If you are unable to associate the view with that context, consider using Hybrid Composition instead.");
|
|
}
|
|
this.container.addView(view);
|
|
AccessibilityDelegatingFrameLayout accessibilityDelegatingFrameLayout = new AccessibilityDelegatingFrameLayout(getContext(), this.accessibilityEventsDelegate, view);
|
|
this.rootView = accessibilityDelegatingFrameLayout;
|
|
accessibilityDelegatingFrameLayout.addView(this.container);
|
|
this.rootView.addView(this.state.fakeWindowViewGroup);
|
|
view.setOnFocusChangeListener(this.focusChangeListener);
|
|
this.rootView.setFocusableInTouchMode(true);
|
|
if (this.startFocused) {
|
|
view.requestFocus();
|
|
} else {
|
|
this.rootView.requestFocus();
|
|
}
|
|
setContentView(this.rootView);
|
|
}
|
|
|
|
public PresentationState detachState() {
|
|
FrameLayout frameLayout = this.container;
|
|
if (frameLayout != null) {
|
|
frameLayout.removeAllViews();
|
|
}
|
|
AccessibilityDelegatingFrameLayout accessibilityDelegatingFrameLayout = this.rootView;
|
|
if (accessibilityDelegatingFrameLayout != null) {
|
|
accessibilityDelegatingFrameLayout.removeAllViews();
|
|
}
|
|
return this.state;
|
|
}
|
|
|
|
public PlatformView getView() {
|
|
return this.state.platformView;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes3.dex */
|
|
public static class FakeWindowViewGroup extends ViewGroup {
|
|
private final Rect childRect;
|
|
private final Rect viewBounds;
|
|
|
|
public FakeWindowViewGroup(Context context) {
|
|
super(context);
|
|
this.viewBounds = new Rect();
|
|
this.childRect = new Rect();
|
|
}
|
|
|
|
@Override // android.view.ViewGroup, android.view.View
|
|
protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
|
|
for (int i5 = 0; i5 < getChildCount(); i5++) {
|
|
View childAt = getChildAt(i5);
|
|
WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) childAt.getLayoutParams();
|
|
this.viewBounds.set(i, i2, i3, i4);
|
|
Gravity.apply(layoutParams.gravity, childAt.getMeasuredWidth(), childAt.getMeasuredHeight(), this.viewBounds, layoutParams.x, layoutParams.y, this.childRect);
|
|
childAt.layout(this.childRect.left, this.childRect.top, this.childRect.right, this.childRect.bottom);
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View
|
|
protected void onMeasure(int i, int i2) {
|
|
for (int i3 = 0; i3 < getChildCount(); i3++) {
|
|
getChildAt(i3).measure(atMost(i), atMost(i2));
|
|
}
|
|
super.onMeasure(i, i2);
|
|
}
|
|
|
|
private static int atMost(int i) {
|
|
return View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.getSize(i), Integer.MIN_VALUE);
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes3.dex */
|
|
private static class ImmContext extends ContextWrapper {
|
|
private final InputMethodManager inputMethodManager;
|
|
|
|
ImmContext(Context context) {
|
|
this(context, null);
|
|
}
|
|
|
|
private ImmContext(Context context, InputMethodManager inputMethodManager) {
|
|
super(context);
|
|
this.inputMethodManager = inputMethodManager == null ? (InputMethodManager) context.getSystemService("input_method") : inputMethodManager;
|
|
}
|
|
|
|
@Override // android.content.ContextWrapper, android.content.Context
|
|
public Object getSystemService(String str) {
|
|
return "input_method".equals(str) ? this.inputMethodManager : super.getSystemService(str);
|
|
}
|
|
|
|
@Override // android.content.ContextWrapper, android.content.Context
|
|
public Context createDisplayContext(Display display) {
|
|
return new ImmContext(super.createDisplayContext(display), this.inputMethodManager);
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes3.dex */
|
|
private static class PresentationContext extends ContextWrapper {
|
|
private final Context flutterAppWindowContext;
|
|
private WindowManager windowManager;
|
|
private final WindowManagerHandler windowManagerHandler;
|
|
|
|
PresentationContext(Context context, WindowManagerHandler windowManagerHandler, Context context2) {
|
|
super(context);
|
|
this.windowManagerHandler = windowManagerHandler;
|
|
this.flutterAppWindowContext = context2;
|
|
}
|
|
|
|
@Override // android.content.ContextWrapper, android.content.Context
|
|
public Object getSystemService(String str) {
|
|
if ("window".equals(str)) {
|
|
if (isCalledFromAlertDialog()) {
|
|
return this.flutterAppWindowContext.getSystemService(str);
|
|
}
|
|
return getWindowManager();
|
|
}
|
|
return super.getSystemService(str);
|
|
}
|
|
|
|
private WindowManager getWindowManager() {
|
|
if (this.windowManager == null) {
|
|
this.windowManager = this.windowManagerHandler.getWindowManager();
|
|
}
|
|
return this.windowManager;
|
|
}
|
|
|
|
private boolean isCalledFromAlertDialog() {
|
|
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
|
for (int i = 0; i < stackTrace.length && i < 11; i++) {
|
|
if (stackTrace[i].getClassName().equals(AlertDialog.class.getCanonicalName()) && stackTrace[i].getMethodName().equals("<init>")) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes3.dex */
|
|
public static class WindowManagerHandler implements InvocationHandler {
|
|
private static final String TAG = "PlatformViewsController";
|
|
private final WindowManager delegate;
|
|
FakeWindowViewGroup fakeWindowRootView;
|
|
|
|
WindowManagerHandler(WindowManager windowManager, FakeWindowViewGroup fakeWindowViewGroup) {
|
|
this.delegate = windowManager;
|
|
this.fakeWindowRootView = fakeWindowViewGroup;
|
|
}
|
|
|
|
public WindowManager getWindowManager() {
|
|
return (WindowManager) Proxy.newProxyInstance(WindowManager.class.getClassLoader(), new Class[]{WindowManager.class}, this);
|
|
}
|
|
|
|
@Override // java.lang.reflect.InvocationHandler
|
|
public Object invoke(Object obj, Method method, Object[] objArr) throws Throwable {
|
|
String name = method.getName();
|
|
name.hashCode();
|
|
char c = 65535;
|
|
switch (name.hashCode()) {
|
|
case -1148522778:
|
|
if (name.equals("addView")) {
|
|
c = 0;
|
|
break;
|
|
}
|
|
break;
|
|
case 542766184:
|
|
if (name.equals("removeViewImmediate")) {
|
|
c = 1;
|
|
break;
|
|
}
|
|
break;
|
|
case 931413976:
|
|
if (name.equals("updateViewLayout")) {
|
|
c = 2;
|
|
break;
|
|
}
|
|
break;
|
|
case 1098630473:
|
|
if (name.equals("removeView")) {
|
|
c = 3;
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
switch (c) {
|
|
case 0:
|
|
addView(objArr);
|
|
return null;
|
|
case 1:
|
|
removeViewImmediate(objArr);
|
|
return null;
|
|
case 2:
|
|
updateViewLayout(objArr);
|
|
return null;
|
|
case 3:
|
|
removeView(objArr);
|
|
return null;
|
|
default:
|
|
try {
|
|
return method.invoke(this.delegate, objArr);
|
|
} catch (InvocationTargetException e) {
|
|
throw e.getCause();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void addView(Object[] objArr) {
|
|
FakeWindowViewGroup fakeWindowViewGroup = this.fakeWindowRootView;
|
|
if (fakeWindowViewGroup == null) {
|
|
Log.w(TAG, "Embedded view called addView while detached from presentation");
|
|
} else {
|
|
fakeWindowViewGroup.addView((View) objArr[0], (WindowManager.LayoutParams) objArr[1]);
|
|
}
|
|
}
|
|
|
|
private void removeView(Object[] objArr) {
|
|
FakeWindowViewGroup fakeWindowViewGroup = this.fakeWindowRootView;
|
|
if (fakeWindowViewGroup == null) {
|
|
Log.w(TAG, "Embedded view called removeView while detached from presentation");
|
|
} else {
|
|
fakeWindowViewGroup.removeView((View) objArr[0]);
|
|
}
|
|
}
|
|
|
|
private void removeViewImmediate(Object[] objArr) {
|
|
if (this.fakeWindowRootView == null) {
|
|
Log.w(TAG, "Embedded view called removeViewImmediate while detached from presentation");
|
|
return;
|
|
}
|
|
View view = (View) objArr[0];
|
|
view.clearAnimation();
|
|
this.fakeWindowRootView.removeView(view);
|
|
}
|
|
|
|
private void updateViewLayout(Object[] objArr) {
|
|
FakeWindowViewGroup fakeWindowViewGroup = this.fakeWindowRootView;
|
|
if (fakeWindowViewGroup == null) {
|
|
Log.w(TAG, "Embedded view called updateViewLayout while detached from presentation");
|
|
} else {
|
|
fakeWindowViewGroup.updateViewLayout((View) objArr[0], (WindowManager.LayoutParams) objArr[1]);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes3.dex */
|
|
private static class AccessibilityDelegatingFrameLayout extends FrameLayout {
|
|
private final AccessibilityEventsDelegate accessibilityEventsDelegate;
|
|
private final View embeddedView;
|
|
|
|
public AccessibilityDelegatingFrameLayout(Context context, AccessibilityEventsDelegate accessibilityEventsDelegate, View view) {
|
|
super(context);
|
|
this.accessibilityEventsDelegate = accessibilityEventsDelegate;
|
|
this.embeddedView = view;
|
|
}
|
|
|
|
@Override // android.view.ViewGroup, android.view.ViewParent
|
|
public boolean requestSendAccessibilityEvent(View view, AccessibilityEvent accessibilityEvent) {
|
|
return this.accessibilityEventsDelegate.requestSendAccessibilityEvent(this.embeddedView, view, accessibilityEvent);
|
|
}
|
|
}
|
|
}
|