5package io.flutter.plugin.platform;
7import static io.flutter.Build.API_LEVELS;
9import android.annotation.SuppressLint;
10import android.annotation.TargetApi;
15import android.graphics.PorterDuff;
21import android.view.ViewTreeObserver;
22import android.view.accessibility.AccessibilityEvent;
23import android.widget.FrameLayout;
24import androidx.annotation.NonNull;
25import androidx.annotation.Nullable;
26import androidx.annotation.VisibleForTesting;
28import io.flutter.embedding.android.AndroidTouchProcessor;
29import io.flutter.embedding.engine.renderer.FlutterRenderer;
30import io.flutter.util.ViewUtils;
43@TargetApi(API_LEVELS.API_23)
45 private static final String
TAG =
"PlatformViewWrapper";
54 private ViewTreeObserver.OnGlobalFocusChangeListener activeFocusListener;
58 setWillNotDraw(
false);
64 this.renderTarget = renderTarget;
66 Surface
surface = renderTarget.getSurface();
68 final Canvas canvas =
surface.lockHardwareCanvas();
70 canvas.drawColor(
Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
72 surface.unlockCanvasAndPost(canvas);
83 touchProcessor = newTouchProcessor;
92 super.setLayoutParams(
params);
99 if (renderTarget !=
null) {
105 if (renderTarget !=
null) {
112 if (renderTarget !=
null) {
120 if (renderTarget !=
null) {
133 final View embeddedView = getChildAt(0);
134 if (embeddedView !=
null
135 && embeddedView.getImportantForAccessibility()
136 == View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) {
143 return super.requestSendAccessibilityEvent(child,
event);
147 @SuppressLint(
"NewApi")
150 super.onDescendantInvalidated(child,
target);
157 return super.invalidateChildInParent(location, dirty);
161 @SuppressLint(
"NewApi")
162 public
void draw(Canvas canvas) {
163 if (renderTarget ==
null) {
165 Log.
e(
TAG,
"Platform view cannot be composed without a RenderTarget.");
168 final Surface targetSurface = renderTarget.
getSurface();
169 final Canvas targetCanvas = targetSurface.lockHardwareCanvas();
170 if (targetCanvas ==
null) {
179 targetCanvas.drawColor(
Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
181 super.draw(targetCanvas);
184 targetSurface.unlockCanvasAndPost(targetCanvas);
189 @SuppressLint(
"ClickableViewAccessibility")
190 public
boolean onTouchEvent(@NonNull MotionEvent
event) {
191 if (touchProcessor ==
null) {
192 return super.onTouchEvent(
event);
195 switch (
event.getAction()) {
196 case MotionEvent.ACTION_DOWN:
199 screenMatrix.postTranslate(left, top);
201 case MotionEvent.ACTION_MOVE:
204 screenMatrix.postTranslate(prevLeft, prevTop);
208 case MotionEvent.ACTION_UP:
210 screenMatrix.postTranslate(left, top);
218 return this.activeFocusListener;
222 unsetOnDescendantFocusChangeListener();
223 final ViewTreeObserver observer = getViewTreeObserver();
224 if (observer.isAlive() && activeFocusListener ==
null) {
225 activeFocusListener =
226 new ViewTreeObserver.OnGlobalFocusChangeListener() {
228 public void onGlobalFocusChanged(View oldFocus, View newFocus) {
229 userFocusListener.onFocusChange(
233 observer.addOnGlobalFocusChangeListener(activeFocusListener);
238 final ViewTreeObserver observer = getViewTreeObserver();
239 if (observer.isAlive() && activeFocusListener !=
null) {
240 final ViewTreeObserver.OnGlobalFocusChangeListener currFocusListener = activeFocusListener;
241 activeFocusListener =
null;
242 observer.removeOnGlobalFocusChangeListener(currFocusListener);
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
static void e(@NonNull String tag, @NonNull String message)
boolean onTouchEvent(@NonNull MotionEvent event)
static boolean debugDisableSurfaceClear
static boolean childHasFocus(@Nullable View root)
const EmbeddedViewParams * params
SK_API sk_sp< SkShader > Color(SkColor)
SK_API sk_sp< PrecompileColorFilter > Matrix()