4141/**
4242 * Manages platform views.
4343 *
44- * <p>Each {@link io.flutter.app.FlutterPluginRegistry} has a single platform views controller. A
45- * platform views controller can be attached to at most one Flutter view.
44+ * <p>Each {@link io.flutter.embedding.engine.FlutterEngine} or {@link
45+ * io.flutter.app.FlutterPluginRegistry} has a single platform views controller. A platform views
46+ * controller can be attached to at most one Flutter view.
4647 */
4748public class PlatformViewsController implements PlatformViewsAccessibilityDelegate {
4849 private static final String TAG = "PlatformViewsController" ;
@@ -55,8 +56,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
5556 private Context context ;
5657
5758 // The View currently rendering the Flutter UI associated with these platform views.
58- // TODO(egarciad): Investigate if this can be downcasted to `FlutterView`.
59- private View flutterView ;
59+ private FlutterView flutterView ;
6060
6161 // The texture registry maintaining the textures into which the embedded views will be rendered.
6262 @ Nullable private TextureRegistry textureRegistry ;
@@ -111,10 +111,10 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
111111 private boolean synchronizeToNativeViewHierarchy = true ;
112112
113113 // Overlay layer IDs that were displayed since the start of the current frame.
114- private HashSet <Integer > currentFrameUsedOverlayLayerIds ;
114+ private final HashSet <Integer > currentFrameUsedOverlayLayerIds ;
115115
116116 // Platform view IDs that were displayed since the start of the current frame.
117- private HashSet <Integer > currentFrameUsedPlatformViewIds ;
117+ private final HashSet <Integer > currentFrameUsedPlatformViewIds ;
118118
119119 // Used to acquire the original motion events using the motionEventIds.
120120 private final MotionEventTracker motionEventTracker ;
@@ -290,12 +290,9 @@ public void resizePlatformView(
290290 vdController .resize (
291291 physicalWidth ,
292292 physicalHeight ,
293- new Runnable () {
294- @ Override
295- public void run () {
296- unlockInputConnection (vdController );
297- onComplete .run ();
298- }
293+ () -> {
294+ unlockInputConnection (vdController );
295+ onComplete .run ();
299296 });
300297 }
301298
@@ -483,7 +480,7 @@ public void detach() {
483480 * This {@code PlatformViewsController} and its {@code FlutterEngine} is now attached to an
484481 * Android {@code View} that renders a Flutter UI.
485482 */
486- public void attachToView (@ NonNull View flutterView ) {
483+ public void attachToView (@ NonNull FlutterView flutterView ) {
487484 this .flutterView = flutterView ;
488485
489486 // Inform all existing platform views that they are now associated with
@@ -518,7 +515,7 @@ public void attachAccessibilityBridge(AccessibilityBridge accessibilityBridge) {
518515 }
519516
520517 @ Override
521- public void detachAccessibiltyBridge () {
518+ public void detachAccessibilityBridge () {
522519 accessibilityEventsDelegate .setAccessibilityBridge (null );
523520 }
524521
@@ -720,7 +717,7 @@ private void flushAllViews() {
720717
721718 private void initializeRootImageViewIfNeeded () {
722719 if (synchronizeToNativeViewHierarchy && !flutterViewConvertedToImageView ) {
723- (( FlutterView ) flutterView ) .convertToImageView ();
720+ flutterView .convertToImageView ();
724721 flutterViewConvertedToImageView = true ;
725722 }
726723 }
@@ -764,7 +761,7 @@ void initializePlatformViewIfNeeded(int viewId) {
764761
765762 platformViewParent .put (viewId , parentView );
766763 parentView .addView (platformView .getView ());
767- (( FlutterView ) flutterView ) .addView (parentView );
764+ flutterView .addView (parentView );
768765 }
769766
770767 public void attachToFlutterRenderer (FlutterRenderer flutterRenderer ) {
@@ -829,7 +826,7 @@ public void onDisplayOverlaySurface(int id, int x, int y, int width, int height)
829826
830827 final FlutterImageView overlayView = overlayLayerViews .get (id );
831828 if (overlayView .getParent () == null ) {
832- (( FlutterView ) flutterView ) .addView (overlayView );
829+ flutterView .addView (overlayView );
833830 }
834831
835832 FrameLayout .LayoutParams layoutParams = new FrameLayout .LayoutParams ((int ) width , (int ) height );
@@ -852,14 +849,13 @@ public void onBeginFrame() {
852849 * <p>This member is not intended for public use, and is only visible for testing.
853850 */
854851 public void onEndFrame () {
855- final FlutterView view = (FlutterView ) flutterView ;
856852 // If there are no platform views in the current frame,
857853 // then revert the image view surface and use the previous surface.
858854 //
859855 // Otherwise, acquire the latest image.
860856 if (flutterViewConvertedToImageView && currentFrameUsedPlatformViewIds .isEmpty ()) {
861857 flutterViewConvertedToImageView = false ;
862- view .revertImageView (
858+ flutterView .revertImageView (
863859 () -> {
864860 // Destroy overlay surfaces once the surface reversion is completed.
865861 finishFrame (false );
@@ -876,7 +872,7 @@ public void onEndFrame() {
876872 // dropped.
877873 // For example, a toolbar widget painted by Flutter may not be rendered.
878874 final boolean isFrameRenderedUsingImageReaders =
879- flutterViewConvertedToImageView && view .acquireLatestImageViewFrame ();
875+ flutterViewConvertedToImageView && flutterView .acquireLatestImageViewFrame ();
880876 finishFrame (isFrameRenderedUsingImageReaders );
881877 }
882878
@@ -886,7 +882,7 @@ private void finishFrame(boolean isFrameRenderedUsingImageReaders) {
886882 final FlutterImageView overlayView = overlayLayerViews .valueAt (i );
887883
888884 if (currentFrameUsedOverlayLayerIds .contains (overlayId )) {
889- (( FlutterView ) flutterView ) .attachOverlaySurfaceToRender (overlayView );
885+ flutterView .attachOverlaySurfaceToRender (overlayView );
890886 final boolean didAcquireOverlaySurfaceImage = overlayView .acquireLatestImage ();
891887 isFrameRenderedUsingImageReaders &= didAcquireOverlaySurfaceImage ;
892888 } else {
@@ -970,12 +966,11 @@ public FlutterOverlaySurface createOverlaySurface() {
970966 */
971967 public void destroyOverlaySurfaces () {
972968 for (int i = 0 ; i < overlayLayerViews .size (); i ++) {
973- int overlayId = overlayLayerViews .keyAt (i );
974969 FlutterImageView overlayView = overlayLayerViews .valueAt (i );
975970 overlayView .detachFromRenderer ();
976971 overlayView .closeImageReader ();
977972 if (flutterView != null ) {
978- (( FlutterView ) flutterView ) .removeView (overlayView );
973+ flutterView .removeView (overlayView );
979974 }
980975 }
981976 overlayLayerViews .clear ();
0 commit comments