214 lines
9.3 KiB
Java
214 lines
9.3 KiB
Java
package io.flutter.plugin.platform;
|
|
|
|
import android.content.Context;
|
|
import android.hardware.display.DisplayManager;
|
|
import android.hardware.display.VirtualDisplay;
|
|
import android.view.MotionEvent;
|
|
import android.view.Surface;
|
|
import android.view.View;
|
|
import android.view.ViewTreeObserver;
|
|
import com.huawei.hms.support.api.entity.common.CommonConstant;
|
|
import io.flutter.plugin.platform.SingleViewPresentation;
|
|
import io.flutter.view.TextureRegistry;
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes6.dex */
|
|
public class VirtualDisplayController {
|
|
private static String TAG = "VirtualDisplayController";
|
|
private final AccessibilityEventsDelegate accessibilityEventsDelegate;
|
|
private int bufferHeight;
|
|
private int bufferWidth;
|
|
private final Context context;
|
|
private final int densityDpi;
|
|
private final View.OnFocusChangeListener focusChangeListener;
|
|
SingleViewPresentation presentation;
|
|
private final Surface surface;
|
|
private final TextureRegistry.SurfaceTextureEntry textureEntry;
|
|
private VirtualDisplay virtualDisplay;
|
|
|
|
public int getBufferHeight() {
|
|
return this.bufferHeight;
|
|
}
|
|
|
|
public int getBufferWidth() {
|
|
return this.bufferWidth;
|
|
}
|
|
|
|
public static VirtualDisplayController create(Context context, AccessibilityEventsDelegate accessibilityEventsDelegate, PlatformView platformView, TextureRegistry.SurfaceTextureEntry surfaceTextureEntry, int i, int i2, int i3, Object obj, View.OnFocusChangeListener onFocusChangeListener) {
|
|
context.getResources().getDisplayMetrics();
|
|
if (i == 0 || i2 == 0) {
|
|
return null;
|
|
}
|
|
surfaceTextureEntry.surfaceTexture().setDefaultBufferSize(i, i2);
|
|
Surface surface = new Surface(surfaceTextureEntry.surfaceTexture());
|
|
VirtualDisplay createVirtualDisplay = ((DisplayManager) context.getSystemService(CommonConstant.ReqAccessTokenParam.DISPLAY_LABEL)).createVirtualDisplay("flutter-vd", i, i2, context.getResources().getDisplayMetrics().densityDpi, surface, 0);
|
|
if (createVirtualDisplay == null) {
|
|
return null;
|
|
}
|
|
VirtualDisplayController virtualDisplayController = new VirtualDisplayController(context, accessibilityEventsDelegate, createVirtualDisplay, platformView, surface, surfaceTextureEntry, onFocusChangeListener, i3, obj);
|
|
virtualDisplayController.bufferWidth = i;
|
|
virtualDisplayController.bufferHeight = i2;
|
|
return virtualDisplayController;
|
|
}
|
|
|
|
private VirtualDisplayController(Context context, AccessibilityEventsDelegate accessibilityEventsDelegate, VirtualDisplay virtualDisplay, PlatformView platformView, Surface surface, TextureRegistry.SurfaceTextureEntry surfaceTextureEntry, View.OnFocusChangeListener onFocusChangeListener, int i, Object obj) {
|
|
this.context = context;
|
|
this.accessibilityEventsDelegate = accessibilityEventsDelegate;
|
|
this.textureEntry = surfaceTextureEntry;
|
|
this.focusChangeListener = onFocusChangeListener;
|
|
this.surface = surface;
|
|
this.virtualDisplay = virtualDisplay;
|
|
this.densityDpi = context.getResources().getDisplayMetrics().densityDpi;
|
|
SingleViewPresentation singleViewPresentation = new SingleViewPresentation(context, this.virtualDisplay.getDisplay(), platformView, accessibilityEventsDelegate, i, onFocusChangeListener);
|
|
this.presentation = singleViewPresentation;
|
|
singleViewPresentation.show();
|
|
}
|
|
|
|
public void resize(int i, int i2, Runnable runnable) {
|
|
boolean isFocused = getView().isFocused();
|
|
SingleViewPresentation.PresentationState detachState = this.presentation.detachState();
|
|
this.virtualDisplay.setSurface(null);
|
|
this.virtualDisplay.release();
|
|
this.bufferWidth = i;
|
|
this.bufferHeight = i2;
|
|
this.textureEntry.surfaceTexture().setDefaultBufferSize(i, i2);
|
|
this.virtualDisplay = ((DisplayManager) this.context.getSystemService(CommonConstant.ReqAccessTokenParam.DISPLAY_LABEL)).createVirtualDisplay("flutter-vd", i, i2, this.densityDpi, this.surface, 0);
|
|
View view = getView();
|
|
view.addOnAttachStateChangeListener(new AnonymousClass1(this, view, runnable));
|
|
SingleViewPresentation singleViewPresentation = new SingleViewPresentation(this.context, this.virtualDisplay.getDisplay(), this.accessibilityEventsDelegate, detachState, this.focusChangeListener, isFocused);
|
|
singleViewPresentation.show();
|
|
this.presentation.cancel();
|
|
this.presentation = singleViewPresentation;
|
|
}
|
|
|
|
/* renamed from: io.flutter.plugin.platform.VirtualDisplayController$1, reason: invalid class name */
|
|
/* loaded from: classes6.dex */
|
|
class AnonymousClass1 implements View.OnAttachStateChangeListener {
|
|
final VirtualDisplayController this$0;
|
|
final View val$embeddedView;
|
|
final Runnable val$onNewSizeFrameAvailable;
|
|
|
|
@Override // android.view.View.OnAttachStateChangeListener
|
|
public void onViewDetachedFromWindow(View view) {
|
|
}
|
|
|
|
AnonymousClass1(VirtualDisplayController virtualDisplayController, View view, Runnable runnable) {
|
|
this.this$0 = virtualDisplayController;
|
|
this.val$embeddedView = view;
|
|
this.val$onNewSizeFrameAvailable = runnable;
|
|
}
|
|
|
|
@Override // android.view.View.OnAttachStateChangeListener
|
|
public void onViewAttachedToWindow(View view) {
|
|
OneTimeOnDrawListener.schedule(this.val$embeddedView, new Runnable(this) { // from class: io.flutter.plugin.platform.VirtualDisplayController.1.1
|
|
final AnonymousClass1 this$1;
|
|
|
|
{
|
|
this.this$1 = this;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$1.val$embeddedView.postDelayed(this.this$1.val$onNewSizeFrameAvailable, 128L);
|
|
}
|
|
});
|
|
this.val$embeddedView.removeOnAttachStateChangeListener(this);
|
|
}
|
|
}
|
|
|
|
public void dispose() {
|
|
this.presentation.cancel();
|
|
this.presentation.detachState();
|
|
this.virtualDisplay.release();
|
|
this.textureEntry.release();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public void onFlutterViewAttached(View view) {
|
|
SingleViewPresentation singleViewPresentation = this.presentation;
|
|
if (singleViewPresentation == null || singleViewPresentation.getView() == null) {
|
|
return;
|
|
}
|
|
this.presentation.getView().onFlutterViewAttached(view);
|
|
}
|
|
|
|
void onFlutterViewDetached() {
|
|
SingleViewPresentation singleViewPresentation = this.presentation;
|
|
if (singleViewPresentation == null || singleViewPresentation.getView() == null) {
|
|
return;
|
|
}
|
|
this.presentation.getView().onFlutterViewDetached();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public void onInputConnectionLocked() {
|
|
SingleViewPresentation singleViewPresentation = this.presentation;
|
|
if (singleViewPresentation == null || singleViewPresentation.getView() == null) {
|
|
return;
|
|
}
|
|
this.presentation.getView().onInputConnectionLocked();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public void onInputConnectionUnlocked() {
|
|
SingleViewPresentation singleViewPresentation = this.presentation;
|
|
if (singleViewPresentation == null || singleViewPresentation.getView() == null) {
|
|
return;
|
|
}
|
|
this.presentation.getView().onInputConnectionUnlocked();
|
|
}
|
|
|
|
public View getView() {
|
|
SingleViewPresentation singleViewPresentation = this.presentation;
|
|
if (singleViewPresentation == null) {
|
|
return null;
|
|
}
|
|
return singleViewPresentation.getView().getView();
|
|
}
|
|
|
|
public void dispatchTouchEvent(MotionEvent motionEvent) {
|
|
SingleViewPresentation singleViewPresentation = this.presentation;
|
|
if (singleViewPresentation == null) {
|
|
return;
|
|
}
|
|
singleViewPresentation.dispatchTouchEvent(motionEvent);
|
|
}
|
|
|
|
/* loaded from: classes6.dex */
|
|
static class OneTimeOnDrawListener implements ViewTreeObserver.OnDrawListener {
|
|
Runnable mOnDrawRunnable;
|
|
final View mView;
|
|
|
|
static void schedule(View view, Runnable runnable) {
|
|
view.getViewTreeObserver().addOnDrawListener(new OneTimeOnDrawListener(view, runnable));
|
|
}
|
|
|
|
OneTimeOnDrawListener(View view, Runnable runnable) {
|
|
this.mView = view;
|
|
this.mOnDrawRunnable = runnable;
|
|
}
|
|
|
|
@Override // android.view.ViewTreeObserver.OnDrawListener
|
|
public void onDraw() {
|
|
Runnable runnable = this.mOnDrawRunnable;
|
|
if (runnable == null) {
|
|
return;
|
|
}
|
|
runnable.run();
|
|
this.mOnDrawRunnable = null;
|
|
this.mView.post(new Runnable(this) { // from class: io.flutter.plugin.platform.VirtualDisplayController.OneTimeOnDrawListener.1
|
|
final OneTimeOnDrawListener this$0;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$0.mView.getViewTreeObserver().removeOnDrawListener(this.this$0);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|