5package io.flutter.plugin.platform;
7import static android.view.View.OnFocusChangeListener;
8import static io.flutter.Build.API_LEVELS;
10import android.annotation.TargetApi;
12import android.hardware.display.DisplayManager;
13import android.hardware.display.VirtualDisplay;
15import android.util.DisplayMetrics;
18import android.view.View.OnFocusChangeListener;
19import android.view.ViewTreeObserver;
20import androidx.annotation.NonNull;
21import androidx.annotation.VisibleForTesting;
24 private static String TAG =
"VirtualDisplayController";
26 private static VirtualDisplay.Callback callback =
27 new VirtualDisplay.Callback() {
29 public void onPaused() {}
32 public void onResumed() {}
44 OnFocusChangeListener focusChangeListener) {
49 DisplayManager displayManager =
50 (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
51 final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
65 VirtualDisplay virtualDisplay =
66 displayManager.createVirtualDisplay(
67 "flutter-vd#" + viewId,
76 if (virtualDisplay ==
null) {
82 accessibilityEventsDelegate,
94 private final Context context;
96 private final int densityDpi;
97 private final int viewId;
99 private final OnFocusChangeListener focusChangeListener;
101 private VirtualDisplay virtualDisplay;
106 VirtualDisplay virtualDisplay,
109 OnFocusChangeListener focusChangeListener,
111 Object createParams) {
112 this.context = context;
113 this.accessibilityEventsDelegate = accessibilityEventsDelegate;
114 this.renderTarget = renderTarget;
115 this.focusChangeListener = focusChangeListener;
116 this.viewId = viewId;
117 this.virtualDisplay = virtualDisplay;
118 this.densityDpi = context.getResources().getDisplayMetrics().densityDpi;
122 this.virtualDisplay.getDisplay(),
124 accessibilityEventsDelegate,
126 focusChangeListener);
131 if (renderTarget !=
null) {
138 if (renderTarget !=
null) {
148 getView().postDelayed(onNewSizeFrameAvailable, 0);
155 boolean isFocused =
getView().isFocused();
158 virtualDisplay.setSurface(
null);
159 virtualDisplay.release();
161 final DisplayManager displayManager =
162 (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
166 displayManager.createVirtualDisplay(
167 "flutter-vd#" + viewId,
176 final View embeddedView =
getView();
181 embeddedView.addOnAttachStateChangeListener(
182 new View.OnAttachStateChangeListener() {
184 public void onViewAttachedToWindow(View v) {
185 OneTimeOnDrawListener.schedule(
199 embeddedView.postDelayed(onNewSizeFrameAvailable, 128);
202 embeddedView.removeOnAttachStateChangeListener(this);
206 public void onViewDetachedFromWindow(View v) {}
216 virtualDisplay.getDisplay(),
217 accessibilityEventsDelegate,
221 newPresentation.show();
228 presentation.cancel();
229 presentation.detachState();
230 virtualDisplay.release();
236 private
void resize31(
237 View embeddedView,
int width,
int height, final Runnable onNewSizeFrameAvailable) {
241 virtualDisplay.setSurface(renderTarget.
getSurface());
242 embeddedView.postDelayed(onNewSizeFrameAvailable, 0);
247 if (presentation ==
null || presentation.getView() ==
null) {
250 presentation.getView().onFlutterViewAttached(flutterView);
255 if (presentation ==
null || presentation.getView() ==
null) {
258 presentation.getView().onFlutterViewDetached();
262 if (presentation ==
null || presentation.getView() ==
null) {
265 presentation.getView().onInputConnectionLocked();
269 if (presentation ==
null || presentation.getView() ==
null) {
272 presentation.getView().onInputConnectionUnlocked();
276 if (presentation ==
null)
return null;
283 if (presentation ==
null)
return;
284 presentation.dispatchTouchEvent(
event);
288 virtualDisplay.setSurface(
null);
292 final int width = getRenderTargetWidth();
293 final int height = getRenderTargetHeight();
294 final boolean isFocused = getView().isFocused();
295 final SingleViewPresentation.PresentationState presentationState = presentation.detachState();
298 virtualDisplay.setSurface(
null);
299 virtualDisplay.release();
300 final DisplayManager displayManager =
301 (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
304 displayManager.createVirtualDisplay(
305 "flutter-vd#" + viewId,
320 virtualDisplay.getDisplay(),
321 accessibilityEventsDelegate,
325 newPresentation.show();
326 presentation.cancel();
327 presentation = newPresentation;
331 static void schedule(View view, Runnable runnable) {
333 view.getViewTreeObserver().addOnDrawListener(listener);
341 this.mOnDrawRunnable = onDrawRunnable;
346 if (mOnDrawRunnable ==
null) {
349 mOnDrawRunnable.run();
350 mOnDrawRunnable =
null;
FlutterSemanticsFlag flags
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
def Build(configs, env, options)