Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 65dfc9e

Browse files
authored
[android] Remove the FlutterView casting, add a @nonnull and fix code style (#30734)
1 parent bd65330 commit 65dfc9e

File tree

8 files changed

+30
-57
lines changed

8 files changed

+30
-57
lines changed

shell/platform/android/io/flutter/embedding/android/FlutterView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ public void detachFromFlutterEngine() {
11931193
flutterEngine.getPlatformViewsController().detachFromView();
11941194

11951195
// Disconnect the FlutterEngine's PlatformViewsController from the AccessibilityBridge.
1196-
flutterEngine.getPlatformViewsController().detachAccessibiltyBridge();
1196+
flutterEngine.getPlatformViewsController().detachAccessibilityBridge();
11971197

11981198
// Disconnect and clean up the AccessibilityBridge.
11991199
accessibilityBridge.release();

shell/platform/android/io/flutter/plugin/platform/PlatformView.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ default void onFlutterViewDetached() {}
6868
*/
6969
// Default interface methods are supported on all min SDK versions of Android.
7070
@SuppressLint("NewApi")
71-
default void onInputConnectionLocked() {};
71+
default void onInputConnectionLocked() {}
7272

7373
/**
7474
* Callback fired when the platform input connection has been unlocked. See also {@link
@@ -79,5 +79,5 @@ default void onFlutterViewDetached() {}
7979
*/
8080
// Default interface methods are supported on all min SDK versions of Android.
8181
@SuppressLint("NewApi")
82-
default void onInputConnectionUnlocked() {};
82+
default void onInputConnectionUnlocked() {}
8383
}

shell/platform/android/io/flutter/plugin/platform/PlatformViewsAccessibilityDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ public interface PlatformViewsAccessibilityDelegate {
3232
* <p>Any accessibility events sent by platform views belonging to this delegate will be ignored
3333
* until a new accessibility bridge is attached.
3434
*/
35-
void detachAccessibiltyBridge();
35+
void detachAccessibilityBridge();
3636
}

shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@
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
*/
4748
public 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();

shell/platform/android/io/flutter/plugin/platform/SingleViewPresentation.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
package io.flutter.plugin.platform;
66

7-
import static android.content.Context.INPUT_METHOD_SERVICE;
87
import static android.content.Context.WINDOW_SERVICE;
98
import static android.view.View.OnFocusChangeListener;
109

@@ -99,7 +98,7 @@ static class PresentationState {
9998
// presentation.
10099
private FrameLayout container;
101100

102-
private PresentationState state;
101+
private final PresentationState state;
103102

104103
private boolean startFocused = false;
105104

shell/platform/android/io/flutter/plugin/platform/VirtualDisplayController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static VirtualDisplayController create(
6464
private final OnFocusChangeListener focusChangeListener;
6565
private VirtualDisplay virtualDisplay;
6666
@VisibleForTesting SingleViewPresentation presentation;
67-
private Surface surface;
67+
private final Surface surface;
6868

6969
private VirtualDisplayController(
7070
Context context,

shell/platform/android/io/flutter/view/AccessibilityBridge.java

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ public class AccessibilityBridge extends AccessibilityNodeProvider {
137137
@NonNull private final AccessibilityViewEmbedder accessibilityViewEmbedder;
138138

139139
// The delegate for interacting with embedded platform views. Used to embed accessibility data for
140-
// an embedded
141-
// view in the accessibility tree.
140+
// an embedded view in the accessibility tree.
142141
@NonNull private final PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate;
143142

144143
// Android's {@link ContentResolver}, which is used to observe the global
@@ -386,11 +385,7 @@ public AccessibilityBridge(
386385
@NonNull AccessibilityChannel accessibilityChannel,
387386
@NonNull AccessibilityManager accessibilityManager,
388387
@NonNull ContentResolver contentResolver,
389-
// This should be @NonNull once the plumbing for
390-
// io.flutter.embedding.engine.android.FlutterView is done.
391-
// TODO(mattcarrol): Add the annotation once the plumbing is done.
392-
// https://github.com/flutter/flutter/issues/29618
393-
PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate) {
388+
@NonNull PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate) {
394389
this(
395390
rootAccessibilityView,
396391
accessibilityChannel,
@@ -407,11 +402,7 @@ public AccessibilityBridge(
407402
@NonNull AccessibilityManager accessibilityManager,
408403
@NonNull ContentResolver contentResolver,
409404
@NonNull AccessibilityViewEmbedder accessibilityViewEmbedder,
410-
// This should be @NonNull once the plumbing for
411-
// io.flutter.embedding.engine.android.FlutterView is done.
412-
// TODO(mattcarrol): Add the annotation once the plumbing is done.
413-
// https://github.com/flutter/flutter/issues/29618
414-
PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate) {
405+
@NonNull PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate) {
415406
this.rootAccessibilityView = rootAccessibilityView;
416407
this.accessibilityChannel = accessibilityChannel;
417408
this.accessibilityManager = accessibilityManager;
@@ -464,13 +455,7 @@ public void onTouchExplorationStateChanged(boolean isTouchExplorationEnabled) {
464455
this.contentResolver.registerContentObserver(transitionUri, false, animationScaleObserver);
465456
}
466457

467-
// platformViewsAccessibilityDelegate should be @NonNull once the plumbing
468-
// for io.flutter.embedding.engine.android.FlutterView is done.
469-
// TODO(mattcarrol): Remove the null check once the plumbing is done.
470-
// https://github.com/flutter/flutter/issues/29618
471-
if (platformViewsAccessibilityDelegate != null) {
472-
platformViewsAccessibilityDelegate.attachAccessibilityBridge(this);
473-
}
458+
platformViewsAccessibilityDelegate.attachAccessibilityBridge(this);
474459
}
475460

476461
/**
@@ -482,13 +467,7 @@ public void onTouchExplorationStateChanged(boolean isTouchExplorationEnabled) {
482467
*/
483468
public void release() {
484469
isReleased = true;
485-
// platformViewsAccessibilityDelegate should be @NonNull once the plumbing
486-
// for io.flutter.embedding.engine.android.FlutterView is done.
487-
// TODO(mattcarrol): Remove the null check once the plumbing is done.
488-
// https://github.com/flutter/flutter/issues/29618
489-
if (platformViewsAccessibilityDelegate != null) {
490-
platformViewsAccessibilityDelegate.detachAccessibiltyBridge();
491-
}
470+
platformViewsAccessibilityDelegate.detachAccessibilityBridge();
492471
setOnAccessibilityChangeListener(null);
493472
accessibilityManager.removeAccessibilityStateChangeListener(accessibilityStateChangeListener);
494473
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class PlatformViewsControllerTest {
6161
public void itNotifiesVirtualDisplayControllersOfViewAttachmentAndDetachment() {
6262
// Setup test structure.
6363
// Create a fake View that represents the View that renders a Flutter UI.
64-
View fakeFlutterView = new View(RuntimeEnvironment.systemContext);
64+
FlutterView fakeFlutterView = new FlutterView(RuntimeEnvironment.systemContext);
6565

6666
// Create fake VirtualDisplayControllers. This requires internal knowledge of
6767
// PlatformViewsController. We know that all PlatformViewsController does is

0 commit comments

Comments
 (0)