forked from firka/flutter
[android] Remove the FlutterView casting, add a @NonNull and fix code style (flutter/engine#30734)
This commit is contained in:
@@ -1193,7 +1193,7 @@ public class FlutterView extends FrameLayout implements MouseCursorPlugin.MouseC
|
||||
flutterEngine.getPlatformViewsController().detachFromView();
|
||||
|
||||
// Disconnect the FlutterEngine's PlatformViewsController from the AccessibilityBridge.
|
||||
flutterEngine.getPlatformViewsController().detachAccessibiltyBridge();
|
||||
flutterEngine.getPlatformViewsController().detachAccessibilityBridge();
|
||||
|
||||
// Disconnect and clean up the AccessibilityBridge.
|
||||
accessibilityBridge.release();
|
||||
|
||||
@@ -68,7 +68,7 @@ public interface PlatformView {
|
||||
*/
|
||||
// Default interface methods are supported on all min SDK versions of Android.
|
||||
@SuppressLint("NewApi")
|
||||
default void onInputConnectionLocked() {};
|
||||
default void onInputConnectionLocked() {}
|
||||
|
||||
/**
|
||||
* Callback fired when the platform input connection has been unlocked. See also {@link
|
||||
@@ -79,5 +79,5 @@ public interface PlatformView {
|
||||
*/
|
||||
// Default interface methods are supported on all min SDK versions of Android.
|
||||
@SuppressLint("NewApi")
|
||||
default void onInputConnectionUnlocked() {};
|
||||
default void onInputConnectionUnlocked() {}
|
||||
}
|
||||
|
||||
@@ -32,5 +32,5 @@ public interface PlatformViewsAccessibilityDelegate {
|
||||
* <p>Any accessibility events sent by platform views belonging to this delegate will be ignored
|
||||
* until a new accessibility bridge is attached.
|
||||
*/
|
||||
void detachAccessibiltyBridge();
|
||||
void detachAccessibilityBridge();
|
||||
}
|
||||
|
||||
@@ -41,8 +41,9 @@ import java.util.List;
|
||||
/**
|
||||
* Manages platform views.
|
||||
*
|
||||
* <p>Each {@link io.flutter.app.FlutterPluginRegistry} has a single platform views controller. A
|
||||
* platform views controller can be attached to at most one Flutter view.
|
||||
* <p>Each {@link io.flutter.embedding.engine.FlutterEngine} or {@link
|
||||
* io.flutter.app.FlutterPluginRegistry} has a single platform views controller. A platform views
|
||||
* controller can be attached to at most one Flutter view.
|
||||
*/
|
||||
public class PlatformViewsController implements PlatformViewsAccessibilityDelegate {
|
||||
private static final String TAG = "PlatformViewsController";
|
||||
@@ -55,8 +56,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
|
||||
private Context context;
|
||||
|
||||
// The View currently rendering the Flutter UI associated with these platform views.
|
||||
// TODO(egarciad): Investigate if this can be downcasted to `FlutterView`.
|
||||
private View flutterView;
|
||||
private FlutterView flutterView;
|
||||
|
||||
// The texture registry maintaining the textures into which the embedded views will be rendered.
|
||||
@Nullable private TextureRegistry textureRegistry;
|
||||
@@ -111,10 +111,10 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
|
||||
private boolean synchronizeToNativeViewHierarchy = true;
|
||||
|
||||
// Overlay layer IDs that were displayed since the start of the current frame.
|
||||
private HashSet<Integer> currentFrameUsedOverlayLayerIds;
|
||||
private final HashSet<Integer> currentFrameUsedOverlayLayerIds;
|
||||
|
||||
// Platform view IDs that were displayed since the start of the current frame.
|
||||
private HashSet<Integer> currentFrameUsedPlatformViewIds;
|
||||
private final HashSet<Integer> currentFrameUsedPlatformViewIds;
|
||||
|
||||
// Used to acquire the original motion events using the motionEventIds.
|
||||
private final MotionEventTracker motionEventTracker;
|
||||
@@ -290,12 +290,9 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
|
||||
vdController.resize(
|
||||
physicalWidth,
|
||||
physicalHeight,
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
unlockInputConnection(vdController);
|
||||
onComplete.run();
|
||||
}
|
||||
() -> {
|
||||
unlockInputConnection(vdController);
|
||||
onComplete.run();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -483,7 +480,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
|
||||
* This {@code PlatformViewsController} and its {@code FlutterEngine} is now attached to an
|
||||
* Android {@code View} that renders a Flutter UI.
|
||||
*/
|
||||
public void attachToView(@NonNull View flutterView) {
|
||||
public void attachToView(@NonNull FlutterView flutterView) {
|
||||
this.flutterView = flutterView;
|
||||
|
||||
// Inform all existing platform views that they are now associated with
|
||||
@@ -518,7 +515,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachAccessibiltyBridge() {
|
||||
public void detachAccessibilityBridge() {
|
||||
accessibilityEventsDelegate.setAccessibilityBridge(null);
|
||||
}
|
||||
|
||||
@@ -720,7 +717,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
|
||||
|
||||
private void initializeRootImageViewIfNeeded() {
|
||||
if (synchronizeToNativeViewHierarchy && !flutterViewConvertedToImageView) {
|
||||
((FlutterView) flutterView).convertToImageView();
|
||||
flutterView.convertToImageView();
|
||||
flutterViewConvertedToImageView = true;
|
||||
}
|
||||
}
|
||||
@@ -764,7 +761,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
|
||||
|
||||
platformViewParent.put(viewId, parentView);
|
||||
parentView.addView(platformView.getView());
|
||||
((FlutterView) flutterView).addView(parentView);
|
||||
flutterView.addView(parentView);
|
||||
}
|
||||
|
||||
public void attachToFlutterRenderer(FlutterRenderer flutterRenderer) {
|
||||
@@ -829,7 +826,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
|
||||
|
||||
final FlutterImageView overlayView = overlayLayerViews.get(id);
|
||||
if (overlayView.getParent() == null) {
|
||||
((FlutterView) flutterView).addView(overlayView);
|
||||
flutterView.addView(overlayView);
|
||||
}
|
||||
|
||||
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams((int) width, (int) height);
|
||||
@@ -852,14 +849,13 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
|
||||
* <p>This member is not intended for public use, and is only visible for testing.
|
||||
*/
|
||||
public void onEndFrame() {
|
||||
final FlutterView view = (FlutterView) flutterView;
|
||||
// If there are no platform views in the current frame,
|
||||
// then revert the image view surface and use the previous surface.
|
||||
//
|
||||
// Otherwise, acquire the latest image.
|
||||
if (flutterViewConvertedToImageView && currentFrameUsedPlatformViewIds.isEmpty()) {
|
||||
flutterViewConvertedToImageView = false;
|
||||
view.revertImageView(
|
||||
flutterView.revertImageView(
|
||||
() -> {
|
||||
// Destroy overlay surfaces once the surface reversion is completed.
|
||||
finishFrame(false);
|
||||
@@ -876,7 +872,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
|
||||
// dropped.
|
||||
// For example, a toolbar widget painted by Flutter may not be rendered.
|
||||
final boolean isFrameRenderedUsingImageReaders =
|
||||
flutterViewConvertedToImageView && view.acquireLatestImageViewFrame();
|
||||
flutterViewConvertedToImageView && flutterView.acquireLatestImageViewFrame();
|
||||
finishFrame(isFrameRenderedUsingImageReaders);
|
||||
}
|
||||
|
||||
@@ -886,7 +882,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
|
||||
final FlutterImageView overlayView = overlayLayerViews.valueAt(i);
|
||||
|
||||
if (currentFrameUsedOverlayLayerIds.contains(overlayId)) {
|
||||
((FlutterView) flutterView).attachOverlaySurfaceToRender(overlayView);
|
||||
flutterView.attachOverlaySurfaceToRender(overlayView);
|
||||
final boolean didAcquireOverlaySurfaceImage = overlayView.acquireLatestImage();
|
||||
isFrameRenderedUsingImageReaders &= didAcquireOverlaySurfaceImage;
|
||||
} else {
|
||||
@@ -970,12 +966,11 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
|
||||
*/
|
||||
public void destroyOverlaySurfaces() {
|
||||
for (int i = 0; i < overlayLayerViews.size(); i++) {
|
||||
int overlayId = overlayLayerViews.keyAt(i);
|
||||
FlutterImageView overlayView = overlayLayerViews.valueAt(i);
|
||||
overlayView.detachFromRenderer();
|
||||
overlayView.closeImageReader();
|
||||
if (flutterView != null) {
|
||||
((FlutterView) flutterView).removeView(overlayView);
|
||||
flutterView.removeView(overlayView);
|
||||
}
|
||||
}
|
||||
overlayLayerViews.clear();
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
package io.flutter.plugin.platform;
|
||||
|
||||
import static android.content.Context.INPUT_METHOD_SERVICE;
|
||||
import static android.content.Context.WINDOW_SERVICE;
|
||||
import static android.view.View.OnFocusChangeListener;
|
||||
|
||||
@@ -99,7 +98,7 @@ class SingleViewPresentation extends Presentation {
|
||||
// presentation.
|
||||
private FrameLayout container;
|
||||
|
||||
private PresentationState state;
|
||||
private final PresentationState state;
|
||||
|
||||
private boolean startFocused = false;
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ class VirtualDisplayController {
|
||||
private final OnFocusChangeListener focusChangeListener;
|
||||
private VirtualDisplay virtualDisplay;
|
||||
@VisibleForTesting SingleViewPresentation presentation;
|
||||
private Surface surface;
|
||||
private final Surface surface;
|
||||
|
||||
private VirtualDisplayController(
|
||||
Context context,
|
||||
|
||||
@@ -137,8 +137,7 @@ public class AccessibilityBridge extends AccessibilityNodeProvider {
|
||||
@NonNull private final AccessibilityViewEmbedder accessibilityViewEmbedder;
|
||||
|
||||
// The delegate for interacting with embedded platform views. Used to embed accessibility data for
|
||||
// an embedded
|
||||
// view in the accessibility tree.
|
||||
// an embedded view in the accessibility tree.
|
||||
@NonNull private final PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate;
|
||||
|
||||
// Android's {@link ContentResolver}, which is used to observe the global
|
||||
@@ -386,11 +385,7 @@ public class AccessibilityBridge extends AccessibilityNodeProvider {
|
||||
@NonNull AccessibilityChannel accessibilityChannel,
|
||||
@NonNull AccessibilityManager accessibilityManager,
|
||||
@NonNull ContentResolver contentResolver,
|
||||
// This should be @NonNull once the plumbing for
|
||||
// io.flutter.embedding.engine.android.FlutterView is done.
|
||||
// TODO(mattcarrol): Add the annotation once the plumbing is done.
|
||||
// https://github.com/flutter/flutter/issues/29618
|
||||
PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate) {
|
||||
@NonNull PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate) {
|
||||
this(
|
||||
rootAccessibilityView,
|
||||
accessibilityChannel,
|
||||
@@ -407,11 +402,7 @@ public class AccessibilityBridge extends AccessibilityNodeProvider {
|
||||
@NonNull AccessibilityManager accessibilityManager,
|
||||
@NonNull ContentResolver contentResolver,
|
||||
@NonNull AccessibilityViewEmbedder accessibilityViewEmbedder,
|
||||
// This should be @NonNull once the plumbing for
|
||||
// io.flutter.embedding.engine.android.FlutterView is done.
|
||||
// TODO(mattcarrol): Add the annotation once the plumbing is done.
|
||||
// https://github.com/flutter/flutter/issues/29618
|
||||
PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate) {
|
||||
@NonNull PlatformViewsAccessibilityDelegate platformViewsAccessibilityDelegate) {
|
||||
this.rootAccessibilityView = rootAccessibilityView;
|
||||
this.accessibilityChannel = accessibilityChannel;
|
||||
this.accessibilityManager = accessibilityManager;
|
||||
@@ -464,13 +455,7 @@ public class AccessibilityBridge extends AccessibilityNodeProvider {
|
||||
this.contentResolver.registerContentObserver(transitionUri, false, animationScaleObserver);
|
||||
}
|
||||
|
||||
// platformViewsAccessibilityDelegate should be @NonNull once the plumbing
|
||||
// for io.flutter.embedding.engine.android.FlutterView is done.
|
||||
// TODO(mattcarrol): Remove the null check once the plumbing is done.
|
||||
// https://github.com/flutter/flutter/issues/29618
|
||||
if (platformViewsAccessibilityDelegate != null) {
|
||||
platformViewsAccessibilityDelegate.attachAccessibilityBridge(this);
|
||||
}
|
||||
platformViewsAccessibilityDelegate.attachAccessibilityBridge(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -482,13 +467,7 @@ public class AccessibilityBridge extends AccessibilityNodeProvider {
|
||||
*/
|
||||
public void release() {
|
||||
isReleased = true;
|
||||
// platformViewsAccessibilityDelegate should be @NonNull once the plumbing
|
||||
// for io.flutter.embedding.engine.android.FlutterView is done.
|
||||
// TODO(mattcarrol): Remove the null check once the plumbing is done.
|
||||
// https://github.com/flutter/flutter/issues/29618
|
||||
if (platformViewsAccessibilityDelegate != null) {
|
||||
platformViewsAccessibilityDelegate.detachAccessibiltyBridge();
|
||||
}
|
||||
platformViewsAccessibilityDelegate.detachAccessibilityBridge();
|
||||
setOnAccessibilityChangeListener(null);
|
||||
accessibilityManager.removeAccessibilityStateChangeListener(accessibilityStateChangeListener);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
|
||||
@@ -61,7 +61,7 @@ public class PlatformViewsControllerTest {
|
||||
public void itNotifiesVirtualDisplayControllersOfViewAttachmentAndDetachment() {
|
||||
// Setup test structure.
|
||||
// Create a fake View that represents the View that renders a Flutter UI.
|
||||
View fakeFlutterView = new View(RuntimeEnvironment.systemContext);
|
||||
FlutterView fakeFlutterView = new FlutterView(RuntimeEnvironment.systemContext);
|
||||
|
||||
// Create fake VirtualDisplayControllers. This requires internal knowledge of
|
||||
// PlatformViewsController. We know that all PlatformViewsController does is
|
||||
|
||||
Reference in New Issue
Block a user