Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
io.flutter.plugin.platform.PlatformViewWrapper Class Reference
Inheritance diagram for io.flutter.plugin.platform.PlatformViewWrapper:

Public Member Functions

 PlatformViewWrapper (@NonNull Context context)
 
 PlatformViewWrapper ( @NonNull Context context, @NonNull PlatformViewRenderTarget renderTarget)
 
void setTouchProcessor (@Nullable AndroidTouchProcessor newTouchProcessor)
 
void setLayoutParams (@NonNull FrameLayout.LayoutParams params)
 
void resizeRenderTarget (int width, int height)
 
int getRenderTargetWidth ()
 
int getRenderTargetHeight ()
 
void release ()
 
boolean onInterceptTouchEvent (@NonNull MotionEvent event)
 
boolean requestSendAccessibilityEvent (View child, AccessibilityEvent event)
 
void onDescendantInvalidated (@NonNull View child, @NonNull View target)
 
ViewParent invalidateChildInParent (int[] location, Rect dirty)
 
void draw (Canvas canvas)
 
boolean onTouchEvent (@NonNull MotionEvent event)
 
ViewTreeObserver.OnGlobalFocusChangeListener getActiveFocusListener ()
 
void setOnDescendantFocusChangeListener (@NonNull OnFocusChangeListener userFocusListener)
 
void unsetOnDescendantFocusChangeListener ()
 

Detailed Description

Wraps a platform view to intercept gestures and project this view onto a PlatformViewRenderTarget.

An Android platform view is composed by the engine using a TextureLayer. The view is embeded to the Android view hierarchy like a normal view, but it's projected onto a PlatformViewRenderTarget, so it can be efficiently composed by the engine.

Since the view is in the Android view hierarchy, keyboard and accessibility interactions behave normally.

Definition at line 44 of file PlatformViewWrapper.java.

Constructor & Destructor Documentation

◆ PlatformViewWrapper() [1/2]

io.flutter.plugin.platform.PlatformViewWrapper.PlatformViewWrapper ( @NonNull Context  context)
inline

Definition at line 56 of file PlatformViewWrapper.java.

56 {
57 super(context);
58 setWillNotDraw(false);
59 }

◆ PlatformViewWrapper() [2/2]

io.flutter.plugin.platform.PlatformViewWrapper.PlatformViewWrapper ( @NonNull Context  context,
@NonNull PlatformViewRenderTarget  renderTarget 
)
inline

Definition at line 61 of file PlatformViewWrapper.java.

62 {
63 this(context);
64 this.renderTarget = renderTarget;
65
66 Surface surface = renderTarget.getSurface();
67 if (surface != null && !FlutterRenderer.debugDisableSurfaceClear) {
68 final Canvas canvas = surface.lockHardwareCanvas();
69 try {
70 canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
71 } finally {
72 surface.unlockCanvasAndPost(canvas);
73 }
74 }
75 }
VkSurfaceKHR surface
Definition main.cc:49

Member Function Documentation

◆ draw()

void io.flutter.plugin.platform.PlatformViewWrapper.draw ( Canvas  canvas)
inline

Definition at line 162 of file PlatformViewWrapper.java.

162 {
163 if (renderTarget == null) {
164 super.draw(canvas);
165 Log.e(TAG, "Platform view cannot be composed without a RenderTarget.");
166 return;
167 }
168 final Surface targetSurface = renderTarget.getSurface();
169 final Canvas targetCanvas = targetSurface.lockHardwareCanvas();
170 if (targetCanvas == null) {
171 // Cannot render right now.
172 invalidate();
173 return;
174 }
175
176 try {
177 // Fill the render target with transparent pixels. This is needed for platform views that
178 // expect a transparent background.
179 targetCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
180 // Override the canvas that this subtree of views will use to draw.
181 super.draw(targetCanvas);
182 } finally {
183 renderTarget.scheduleFrame();
184 targetSurface.unlockCanvasAndPost(targetCanvas);
185 }
186 }
void Log(const char *format,...) SK_PRINTF_LIKE(1

◆ getActiveFocusListener()

ViewTreeObserver.OnGlobalFocusChangeListener io.flutter.plugin.platform.PlatformViewWrapper.getActiveFocusListener ( )
inline

Definition at line 217 of file PlatformViewWrapper.java.

217 {
218 return this.activeFocusListener;
219 }

◆ getRenderTargetHeight()

int io.flutter.plugin.platform.PlatformViewWrapper.getRenderTargetHeight ( )
inline

Definition at line 111 of file PlatformViewWrapper.java.

111 {
112 if (renderTarget != null) {
113 return renderTarget.getHeight();
114 }
115 return 0;
116 }

◆ getRenderTargetWidth()

int io.flutter.plugin.platform.PlatformViewWrapper.getRenderTargetWidth ( )
inline

Definition at line 104 of file PlatformViewWrapper.java.

104 {
105 if (renderTarget != null) {
106 return renderTarget.getWidth();
107 }
108 return 0;
109 }

◆ invalidateChildInParent()

ViewParent io.flutter.plugin.platform.PlatformViewWrapper.invalidateChildInParent ( int[]  location,
Rect  dirty 
)
inline

Definition at line 155 of file PlatformViewWrapper.java.

155 {
156 invalidate();
157 return super.invalidateChildInParent(location, dirty);
158 }

◆ onDescendantInvalidated()

void io.flutter.plugin.platform.PlatformViewWrapper.onDescendantInvalidated ( @NonNull View  child,
@NonNull View  target 
)
inline

Used on Android O+, invalidateChildInParent used for previous versions.

Definition at line 149 of file PlatformViewWrapper.java.

149 {
150 super.onDescendantInvalidated(child, target);
151 invalidate();
152 }
uint32_t * target

◆ onInterceptTouchEvent()

boolean io.flutter.plugin.platform.PlatformViewWrapper.onInterceptTouchEvent ( @NonNull MotionEvent  event)
inline

Definition at line 127 of file PlatformViewWrapper.java.

127 {
128 return true;
129 }

◆ onTouchEvent()

boolean io.flutter.plugin.platform.PlatformViewWrapper.onTouchEvent ( @NonNull MotionEvent  event)
inline

Definition at line 190 of file PlatformViewWrapper.java.

190 {
191 if (touchProcessor == null) {
192 return super.onTouchEvent(event);
193 }
194 final Matrix screenMatrix = new Matrix();
195 switch (event.getAction()) {
196 case MotionEvent.ACTION_DOWN:
197 prevLeft = left;
198 prevTop = top;
199 screenMatrix.postTranslate(left, top);
200 break;
201 case MotionEvent.ACTION_MOVE:
202 // While the view is dragged, use the left and top positions as
203 // they were at the moment the touch event fired.
204 screenMatrix.postTranslate(prevLeft, prevTop);
205 prevLeft = left;
206 prevTop = top;
207 break;
208 case MotionEvent.ACTION_UP:
209 default:
210 screenMatrix.postTranslate(left, top);
211 break;
212 }
213 return touchProcessor.onTouchEvent(event, screenMatrix);
214 }
FlKeyEvent * event

◆ release()

void io.flutter.plugin.platform.PlatformViewWrapper.release ( )
inline

Releases resources.

Definition at line 119 of file PlatformViewWrapper.java.

119 {
120 if (renderTarget != null) {
121 renderTarget.release();
122 renderTarget = null;
123 }
124 }

◆ requestSendAccessibilityEvent()

boolean io.flutter.plugin.platform.PlatformViewWrapper.requestSendAccessibilityEvent ( View  child,
AccessibilityEvent  event 
)
inline

Definition at line 132 of file PlatformViewWrapper.java.

132 {
133 final View embeddedView = getChildAt(0);
134 if (embeddedView != null
135 && embeddedView.getImportantForAccessibility()
136 == View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) {
137 return false;
138 }
139 // Forward the request only if the embedded view is in the Flutter accessibility tree.
140 // The embedded view may be ignored when the framework doesn't populate a SemanticNode
141 // for the current platform view.
142 // See AccessibilityBridge for more.
143 return super.requestSendAccessibilityEvent(child, event);
144 }

◆ resizeRenderTarget()

void io.flutter.plugin.platform.PlatformViewWrapper.resizeRenderTarget ( int  width,
int  height 
)
inline

Definition at line 98 of file PlatformViewWrapper.java.

98 {
99 if (renderTarget != null) {
100 renderTarget.resize(width, height);
101 }
102 }
int32_t height
int32_t width

◆ setLayoutParams()

void io.flutter.plugin.platform.PlatformViewWrapper.setLayoutParams ( @NonNull FrameLayout.LayoutParams  params)
inline

Sets the layout parameters for this view.

Parameters
paramsThe new parameters.

Definition at line 91 of file PlatformViewWrapper.java.

91 {
92 super.setLayoutParams(params);
93
94 left = params.leftMargin;
95 top = params.topMargin;
96 }
const EmbeddedViewParams * params

◆ setOnDescendantFocusChangeListener()

void io.flutter.plugin.platform.PlatformViewWrapper.setOnDescendantFocusChangeListener ( @NonNull OnFocusChangeListener  userFocusListener)
inline

Definition at line 221 of file PlatformViewWrapper.java.

221 {
223 final ViewTreeObserver observer = getViewTreeObserver();
224 if (observer.isAlive() && activeFocusListener == null) {
225 activeFocusListener =
226 new ViewTreeObserver.OnGlobalFocusChangeListener() {
227 @Override
228 public void onGlobalFocusChanged(View oldFocus, View newFocus) {
229 userFocusListener.onFocusChange(
230 PlatformViewWrapper.this, ViewUtils.childHasFocus(PlatformViewWrapper.this));
231 }
232 };
233 observer.addOnGlobalFocusChangeListener(activeFocusListener);
234 }
235 }

◆ setTouchProcessor()

void io.flutter.plugin.platform.PlatformViewWrapper.setTouchProcessor ( @Nullable AndroidTouchProcessor  newTouchProcessor)
inline

Sets the touch processor that allows to intercept gestures.

Parameters
newTouchProcessorThe touch processor.

Definition at line 82 of file PlatformViewWrapper.java.

82 {
83 touchProcessor = newTouchProcessor;
84 }

◆ unsetOnDescendantFocusChangeListener()

void io.flutter.plugin.platform.PlatformViewWrapper.unsetOnDescendantFocusChangeListener ( )
inline

Definition at line 237 of file PlatformViewWrapper.java.

237 {
238 final ViewTreeObserver observer = getViewTreeObserver();
239 if (observer.isAlive() && activeFocusListener != null) {
240 final ViewTreeObserver.OnGlobalFocusChangeListener currFocusListener = activeFocusListener;
241 activeFocusListener = null;
242 observer.removeOnGlobalFocusChangeListener(currFocusListener);
243 }
244 }

The documentation for this class was generated from the following file: