未验证 提交 760fea25 编写于 作者: A Amir Hardon 提交者: GitHub

remove m prefix from fields in the Android PlatformViews code (#9020)

上级 75678602
......@@ -8,14 +8,14 @@ import android.content.Context;
import io.flutter.plugin.common.MessageCodec;
public abstract class PlatformViewFactory {
private final MessageCodec<Object> mCreateArgsCodec;
private final MessageCodec<Object> createArgsCodec;
/**
*
* @param createArgsCodec the codec used to decode the args parameter of {@link #create}.
*/
public PlatformViewFactory(MessageCodec<Object> createArgsCodec) {
mCreateArgsCodec = createArgsCodec;
this.createArgsCodec = createArgsCodec;
}
/**
......@@ -33,6 +33,6 @@ public abstract class PlatformViewFactory {
* Returns the codec to be used for decoding the args parameter of {@link #create}.
*/
public final MessageCodec<Object> getCreateArgsCodec() {
return mCreateArgsCodec;
return createArgsCodec;
}
}
......@@ -41,26 +41,26 @@ public class PlatformViewsController implements MethodChannel.MethodCallHandler,
// API level 20 is required for VirtualDisplay#setSurface which we use when resizing a platform view.
private static final int MINIMAL_SDK = Build.VERSION_CODES.KITKAT_WATCH;
private final PlatformViewRegistryImpl mRegistry;
private final PlatformViewRegistryImpl registry;
// The context of the Activity or Fragment hosting the render target for the Flutter engine.
private Context mContext;
private Context context;
// The texture registry maintaining the textures into which the embedded views will be rendered.
private TextureRegistry mTextureRegistry;
private TextureRegistry textureRegistry;
// The messenger used to communicate with the framework over the platform views channel.
private BinaryMessenger mMessenger;
private BinaryMessenger messenger;
// The accessibility bridge to which accessibility events form the platform views will be dispatched.
private final AccessibilityEventsDelegate mAccessibilityEventsDelegate;
private final AccessibilityEventsDelegate accessibilityEventsDelegate;
private final HashMap<Integer, VirtualDisplayController> vdControllers;
public PlatformViewsController() {
mRegistry = new PlatformViewRegistryImpl();
registry = new PlatformViewRegistryImpl();
vdControllers = new HashMap<>();
mAccessibilityEventsDelegate = new AccessibilityEventsDelegate();
accessibilityEventsDelegate = new AccessibilityEventsDelegate();
}
/**
......@@ -73,15 +73,15 @@ public class PlatformViewsController implements MethodChannel.MethodCallHandler,
* @param messenger The Flutter application on the other side of this messenger drives this platform views controller.
*/
public void attach(Context context, TextureRegistry textureRegistry, BinaryMessenger messenger) {
if (mContext != null) {
if (this.context != null) {
throw new AssertionError(
"A PlatformViewsController can only be attached to a single output target.\n" +
"attach was called while the PlatformViewsController was already attached."
);
}
mContext = context;
mTextureRegistry = textureRegistry;
mMessenger = messenger;
this.context = context;
this.textureRegistry = textureRegistry;
this.messenger = messenger;
MethodChannel channel = new MethodChannel(messenger, CHANNEL_NAME, StandardMethodCodec.INSTANCE);
channel.setMethodCallHandler(this);
}
......@@ -95,24 +95,24 @@ public class PlatformViewsController implements MethodChannel.MethodCallHandler,
*/
@UiThread
public void detach() {
mMessenger.setMessageHandler(CHANNEL_NAME, null);
mMessenger = null;
mContext = null;
mTextureRegistry = null;
messenger.setMessageHandler(CHANNEL_NAME, null);
messenger = null;
context = null;
textureRegistry = null;
}
@Override
public void attachAccessibilityBridge(AccessibilityBridge accessibilityBridge) {
mAccessibilityEventsDelegate.setAccessibilityBridge(accessibilityBridge);
accessibilityEventsDelegate.setAccessibilityBridge(accessibilityBridge);
}
@Override
public void detachAccessibiltyBridge() {
mAccessibilityEventsDelegate.setAccessibilityBridge(null);
accessibilityEventsDelegate.setAccessibilityBridge(null);
}
public PlatformViewRegistry getRegistry() {
return mRegistry;
return registry;
}
public void onFlutterViewDestroyed() {
......@@ -186,7 +186,7 @@ public class PlatformViewsController implements MethodChannel.MethodCallHandler,
return;
}
PlatformViewFactory viewFactory = mRegistry.getFactory(viewType);
PlatformViewFactory viewFactory = registry.getFactory(viewType);
if (viewFactory == null) {
result.error(
"error",
......@@ -205,10 +205,10 @@ public class PlatformViewsController implements MethodChannel.MethodCallHandler,
int physicalHeight = toPhysicalPixels(logicalHeight);
validateVirtualDisplayDimensions(physicalWidth, physicalHeight);
TextureRegistry.SurfaceTextureEntry textureEntry = mTextureRegistry.createSurfaceTexture();
TextureRegistry.SurfaceTextureEntry textureEntry = textureRegistry.createSurfaceTexture();
VirtualDisplayController vdController = VirtualDisplayController.create(
mContext,
mAccessibilityEventsDelegate,
context,
accessibilityEventsDelegate,
viewFactory,
textureEntry,
physicalWidth,
......@@ -287,7 +287,7 @@ public class PlatformViewsController implements MethodChannel.MethodCallHandler,
private void onTouch(MethodCall call, MethodChannel.Result result) {
List<Object> args = call.arguments();
float density = mContext.getResources().getDisplayMetrics().density;
float density = context.getResources().getDisplayMetrics().density;
int id = (int) args.get(0);
Number downTime = (Number) args.get(1);
......@@ -420,7 +420,7 @@ public class PlatformViewsController implements MethodChannel.MethodCallHandler,
// Creating a VirtualDisplay larger than the size of the device screen size
// could cause the device to restart: https://github.com/flutter/flutter/issues/28978
private void validateVirtualDisplayDimensions(int width, int height) {
DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
if (height > metrics.heightPixels || width > metrics.widthPixels) {
String error = "Creating a virtual display of size: "
+ "[" + width + ", " + height + "]"
......@@ -431,7 +431,7 @@ public class PlatformViewsController implements MethodChannel.MethodCallHandler,
}
private int toPhysicalPixels(double logicalPixels) {
float density = mContext.getResources().getDisplayMetrics().density;
float density = context.getResources().getDisplayMetrics().density;
return (int) Math.round(logicalPixels * density);
}
......
......@@ -24,15 +24,15 @@ import static android.content.Context.WINDOW_SERVICE;
* A presentation used for hosting a single Android view in a virtual display.
*
* This presentation overrides the WindowManager's addView/removeView/updateViewLayout methods, such that views added
* directly to the WindowManager are added as part of the presentation's view hierarchy (to mFakeWindowRootView).
* directly to the WindowManager are added as part of the presentation's view hierarchy (to fakeWindowViewGroup).
*
* The view hierarchy for the presentation is as following:
*
* mRootView
* rootView
* / \
* / \
* / \
* mContainer mState.mFakeWindowRootView
* container state.fakeWindowViewGroup
* |
* EmbeddedView
*/
......@@ -46,37 +46,37 @@ class SingleViewPresentation extends Presentation {
*/
static class PresentationState {
// The Android view we are embedding in the Flutter app.
private PlatformView mView;
private PlatformView platformView;
// The InvocationHandler for a WindowManager proxy. This is essentially the custom window manager for the
// presentation.
private WindowManagerHandler mWindowManagerHandler;
private WindowManagerHandler windowManagerHandler;
// Contains views that were added directly to the window manager (e.g android.widget.PopupWindow).
private FakeWindowViewGroup mFakeWindowRootView;
private FakeWindowViewGroup fakeWindowViewGroup;
}
private final PlatformViewFactory mViewFactory;
private final PlatformViewFactory viewFactory;
// A reference to the current accessibility bridge to which accessibility events will be delegated.
private final AccessibilityEventsDelegate mAccessibilityEventsDelegate;
private final AccessibilityEventsDelegate accessibilityEventsDelegate;
// This is the view id assigned by the Flutter framework to the embedded view, we keep it here
// so when we create the platform view we can tell it its view id.
private int mViewId;
private int viewId;
// This is the creation parameters for the platform view, we keep it here
// so when we create the platform view we can tell it its view id.
private Object mCreateParams;
private Object createParams;
// The root view for the presentation, it has 2 childs: mContainer which contains the embedded view, and
// mFakeWindowRootView which contains views that were added directly to the presentation's window manager.
private AccessibilityDelegatingFrameLayout mRootView;
// The root view for the presentation, it has 2 childs: container which contains the embedded view, and
// fakeWindowViewGroup which contains views that were added directly to the presentation's window manager.
private AccessibilityDelegatingFrameLayout rootView;
// Contains the embedded platform view (mView.getView()) when it is attached to the presentation.
private FrameLayout mContainer;
// Contains the embedded platform view (platformView.getView()) when it is attached to the presentation.
private FrameLayout container;
private PresentationState mState;
private PresentationState state;
/**
* Creates a presentation that will use the view factory to create a new
......@@ -91,11 +91,11 @@ class SingleViewPresentation extends Presentation {
Object createParams
) {
super(outerContext, display);
mViewFactory = viewFactory;
mAccessibilityEventsDelegate = accessibilityEventsDelegate;
mViewId = viewId;
mCreateParams = createParams;
mState = new PresentationState();
this.viewFactory = viewFactory;
this.accessibilityEventsDelegate = accessibilityEventsDelegate;
this.viewId = viewId;
this.createParams = createParams;
state = new PresentationState();
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
......@@ -116,9 +116,9 @@ class SingleViewPresentation extends Presentation {
PresentationState state
) {
super(outerContext, display);
mAccessibilityEventsDelegate = accessibilityEventsDelegate;
mViewFactory = null;
mState = state;
this.accessibilityEventsDelegate = accessibilityEventsDelegate;
viewFactory = null;
this.state = state;
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
......@@ -128,39 +128,39 @@ class SingleViewPresentation extends Presentation {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (mState.mFakeWindowRootView == null) {
mState.mFakeWindowRootView = new FakeWindowViewGroup(getContext());
if (state.fakeWindowViewGroup == null) {
state.fakeWindowViewGroup = new FakeWindowViewGroup(getContext());
}
if (mState.mWindowManagerHandler == null) {
if (state.windowManagerHandler == null) {
WindowManager windowManagerDelegate = (WindowManager) getContext().getSystemService(WINDOW_SERVICE);
mState.mWindowManagerHandler = new WindowManagerHandler(windowManagerDelegate, mState.mFakeWindowRootView);
state.windowManagerHandler = new WindowManagerHandler(windowManagerDelegate, state.fakeWindowViewGroup);
}
mContainer = new FrameLayout(getContext());
PresentationContext context = new PresentationContext(getContext(), mState.mWindowManagerHandler);
container = new FrameLayout(getContext());
PresentationContext context = new PresentationContext(getContext(), state.windowManagerHandler);
if (mState.mView == null) {
mState.mView = mViewFactory.create(context, mViewId, mCreateParams);
if (state.platformView == null) {
state.platformView = viewFactory.create(context, viewId, createParams);
}
View embeddedView = mState.mView.getView();
mContainer.addView(embeddedView);
mRootView = new AccessibilityDelegatingFrameLayout(getContext(), mAccessibilityEventsDelegate, embeddedView);
mRootView.addView(mContainer);
mRootView.addView(mState.mFakeWindowRootView);
setContentView(mRootView);
View embeddedView = state.platformView.getView();
container.addView(embeddedView);
rootView = new AccessibilityDelegatingFrameLayout(getContext(), accessibilityEventsDelegate, embeddedView);
rootView.addView(container);
rootView.addView(state.fakeWindowViewGroup);
setContentView(rootView);
}
public PresentationState detachState() {
mContainer.removeAllViews();
mRootView.removeAllViews();
return mState;
container.removeAllViews();
rootView.removeAllViews();
return state;
}
public PlatformView getView() {
if (mState.mView == null)
if (state.platformView == null)
return null;
return mState.mView;
return state.platformView;
}
/*
......@@ -172,16 +172,16 @@ class SingleViewPresentation extends Presentation {
static class FakeWindowViewGroup extends ViewGroup {
// Used in onLayout to keep the bounds of the current view.
// We keep it as a member to avoid object allocations during onLayout which are discouraged.
private final Rect mViewBounds;
private final Rect viewBounds;
// Used in onLayout to keep the bounds of the child views.
// We keep it as a member to avoid object allocations during onLayout which are discouraged.
private final Rect mChildRect;
private final Rect childRect;
public FakeWindowViewGroup(Context context) {
super(context);
mViewBounds = new Rect();
mChildRect = new Rect();
viewBounds = new Rect();
childRect = new Rect();
}
@Override
......@@ -189,10 +189,10 @@ class SingleViewPresentation extends Presentation {
for(int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
WindowManager.LayoutParams params = (WindowManager.LayoutParams) child.getLayoutParams();
mViewBounds.set(l, t, r, b);
Gravity.apply(params.gravity, child.getMeasuredWidth(), child.getMeasuredHeight(), mViewBounds, params.x,
params.y, mChildRect);
child.layout(mChildRect.left, mChildRect.top, mChildRect.right, mChildRect.bottom);
viewBounds.set(l, t, r, b);
Gravity.apply(params.gravity, child.getMeasuredWidth(), child.getMeasuredHeight(), viewBounds, params.x,
params.y, childRect);
child.layout(childRect.left, childRect.top, childRect.right, childRect.bottom);
}
}
......@@ -214,12 +214,12 @@ class SingleViewPresentation extends Presentation {
* Proxies a Context replacing the WindowManager with our custom instance.
*/
static class PresentationContext extends ContextWrapper {
private WindowManager mWindowManager;
private final WindowManagerHandler mWindowManagerHandler;
private WindowManager windowManager;
private final WindowManagerHandler windowManagerHandler;
PresentationContext(Context base, WindowManagerHandler windowManagerHandler) {
super(base);
mWindowManagerHandler = windowManagerHandler;
this.windowManagerHandler = windowManagerHandler;
}
@Override
......@@ -231,10 +231,10 @@ class SingleViewPresentation extends Presentation {
}
private WindowManager getWindowManager() {
if (mWindowManager == null) {
mWindowManager = mWindowManagerHandler.getWindowManager();
if (windowManager == null) {
windowManager = windowManagerHandler.getWindowManager();
}
return mWindowManager;
return windowManager;
}
}
......@@ -256,12 +256,12 @@ class SingleViewPresentation extends Presentation {
static class WindowManagerHandler implements InvocationHandler {
private static final String TAG = "PlatformViewsController";
private final WindowManager mDelegate;
FakeWindowViewGroup mFakeWindowRootView;
private final WindowManager delegate;
FakeWindowViewGroup fakeWindowRootView;
WindowManagerHandler(WindowManager delegate, FakeWindowViewGroup fakeWindowViewGroup) {
mDelegate = delegate;
mFakeWindowRootView = fakeWindowViewGroup;
this.delegate = delegate;
fakeWindowRootView = fakeWindowViewGroup;
}
public WindowManager getWindowManager() {
......@@ -289,69 +289,69 @@ class SingleViewPresentation extends Presentation {
return null;
}
try {
return method.invoke(mDelegate, args);
return method.invoke(delegate, args);
} catch (InvocationTargetException e) {
throw e.getCause();
}
}
private void addView(Object[] args) {
if (mFakeWindowRootView == null) {
if (fakeWindowRootView == null) {
Log.w(TAG, "Embedded view called addView while detached from presentation");
return;
}
View view = (View) args[0];
WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) args[1];
mFakeWindowRootView.addView(view, layoutParams);
fakeWindowRootView.addView(view, layoutParams);
}
private void removeView(Object[] args) {
if (mFakeWindowRootView == null) {
if (fakeWindowRootView == null) {
Log.w(TAG, "Embedded view called removeView while detached from presentation");
return;
}
View view = (View) args[0];
mFakeWindowRootView.removeView(view);
fakeWindowRootView.removeView(view);
}
private void removeViewImmediate(Object[] args) {
if (mFakeWindowRootView == null) {
if (fakeWindowRootView == null) {
Log.w(TAG, "Embedded view called removeViewImmediate while detached from presentation");
return;
}
View view = (View) args[0];
view.clearAnimation();
mFakeWindowRootView.removeView(view);
fakeWindowRootView.removeView(view);
}
private void updateViewLayout(Object[] args) {
if (mFakeWindowRootView == null) {
if (fakeWindowRootView == null) {
Log.w(TAG, "Embedded view called updateViewLayout while detached from presentation");
return;
}
View view = (View) args[0];
WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) args[1];
mFakeWindowRootView.updateViewLayout(view, layoutParams);
fakeWindowRootView.updateViewLayout(view, layoutParams);
}
}
private static class AccessibilityDelegatingFrameLayout extends FrameLayout {
private final AccessibilityEventsDelegate mAccessibilityEventsDelegate;
private final View mEmbeddedView;
private final AccessibilityEventsDelegate accessibilityEventsDelegate;
private final View embeddedView;
public AccessibilityDelegatingFrameLayout(
Context context,
AccessibilityEventsDelegate accessibilityEventsDelegate,
View ebeddedView
View embeddedView
) {
super(context);
mAccessibilityEventsDelegate = accessibilityEventsDelegate;
mEmbeddedView = ebeddedView;
this.accessibilityEventsDelegate = accessibilityEventsDelegate;
this.embeddedView = embeddedView;
}
@Override
public boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event) {
return mAccessibilityEventsDelegate.requestSendAccessibilityEvent(mEmbeddedView, child, event);
return accessibilityEventsDelegate.requestSendAccessibilityEvent(embeddedView, child, event);
}
}
}
......@@ -49,13 +49,13 @@ class VirtualDisplayController {
context, accessibilityEventsDelegate, virtualDisplay, viewFactory, surface, textureEntry, viewId, createParams);
}
private final Context mContext;
private final AccessibilityEventsDelegate mAccessibilityEventsDelegate;
private final int mDensityDpi;
private final TextureRegistry.SurfaceTextureEntry mTextureEntry;
private VirtualDisplay mVirtualDisplay;
private SingleViewPresentation mPresentation;
private Surface mSurface;
private final Context context;
private final AccessibilityEventsDelegate accessibilityEventsDelegate;
private final int densityDpi;
private final TextureRegistry.SurfaceTextureEntry textureEntry;
private VirtualDisplay virtualDisplay;
private SingleViewPresentation presentation;
private Surface surface;
private VirtualDisplayController(
......@@ -68,35 +68,35 @@ class VirtualDisplayController {
int viewId,
Object createParams
) {
mContext = context;
mAccessibilityEventsDelegate = accessibilityEventsDelegate;
mTextureEntry = textureEntry;
mSurface = surface;
mVirtualDisplay = virtualDisplay;
mDensityDpi = context.getResources().getDisplayMetrics().densityDpi;
mPresentation = new SingleViewPresentation(
context, mVirtualDisplay.getDisplay(), viewFactory, accessibilityEventsDelegate, viewId, createParams);
mPresentation.show();
this.context = context;
this.accessibilityEventsDelegate = accessibilityEventsDelegate;
this.textureEntry = textureEntry;
this.surface = surface;
this.virtualDisplay = virtualDisplay;
densityDpi = context.getResources().getDisplayMetrics().densityDpi;
presentation = new SingleViewPresentation(
context, this.virtualDisplay.getDisplay(), viewFactory, accessibilityEventsDelegate, viewId, createParams);
presentation.show();
}
public void resize(final int width, final int height, final Runnable onNewSizeFrameAvailable) {
final SingleViewPresentation.PresentationState presentationState = mPresentation.detachState();
final SingleViewPresentation.PresentationState presentationState = presentation.detachState();
// We detach the surface to prevent it being destroyed when releasing the vd.
//
// setSurface is only available starting API 20. We could support API 19 by re-creating a new
// SurfaceTexture here. This will require refactoring the TextureRegistry to allow recycling texture
// entry IDs.
mVirtualDisplay.setSurface(null);
mVirtualDisplay.release();
virtualDisplay.setSurface(null);
virtualDisplay.release();
mTextureEntry.surfaceTexture().setDefaultBufferSize(width, height);
DisplayManager displayManager = (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE);
mVirtualDisplay = displayManager.createVirtualDisplay(
textureEntry.surfaceTexture().setDefaultBufferSize(width, height);
DisplayManager displayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
virtualDisplay = displayManager.createVirtualDisplay(
"flutter-vd",
width,
height,
mDensityDpi,
mSurface,
densityDpi,
surface,
0
);
......@@ -125,22 +125,22 @@ class VirtualDisplayController {
public void onViewDetachedFromWindow(View v) {}
});
mPresentation = new SingleViewPresentation(mContext, mVirtualDisplay.getDisplay(), mAccessibilityEventsDelegate, presentationState);
mPresentation.show();
presentation = new SingleViewPresentation(context, virtualDisplay.getDisplay(), accessibilityEventsDelegate, presentationState);
presentation.show();
}
public void dispose() {
PlatformView view = mPresentation.getView();
mPresentation.detachState();
PlatformView view = presentation.getView();
presentation.detachState();
view.dispose();
mVirtualDisplay.release();
mTextureEntry.release();
virtualDisplay.release();
textureEntry.release();
}
public View getView() {
if (mPresentation == null)
if (presentation == null)
return null;
PlatformView platformView = mPresentation.getView();
PlatformView platformView = presentation.getView();
return platformView.getView();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册