5package io.flutter.embedding.engine.systemchannels;
7import androidx.annotation.NonNull;
8import androidx.annotation.Nullable;
10import io.flutter.embedding.engine.dart.DartExecutor;
11import io.flutter.plugin.common.MethodCall;
12import io.flutter.plugin.common.MethodChannel;
13import io.flutter.plugin.common.StandardMethodCodec;
14import java.nio.ByteBuffer;
15import java.util.HashMap;
26 private static final String TAG =
"PlatformViewsChannel";
32 if (channel ==
null) {
38 private static String detailedExceptionString(Exception exception) {
42 private final MethodChannel.MethodCallHandler parsingHandler =
43 new MethodChannel.MethodCallHandler() {
48 if (handler ==
null) {
52 Log.
v(TAG,
"Received '" +
call.method +
"' message.");
53 switch (
call.method) {
75 case "synchronizeToNativeViewHierarchy":
76 synchronizeToNativeViewHierarchy(
call,
result);
84 final Map<String, Object> createArgs =
call.arguments();
86 final boolean usesPlatformViewLayer =
87 createArgs.containsKey(
"hybrid") && (boolean) createArgs.get(
"hybrid");
88 final ByteBuffer additionalParams =
89 createArgs.containsKey(
"params")
90 ? ByteBuffer.wrap((
byte[]) createArgs.get(
"params"))
93 if (usesPlatformViewLayer) {
94 final PlatformViewCreationRequest request =
95 new PlatformViewCreationRequest(
96 (
int) createArgs.get(
"id"),
97 (String) createArgs.get(
"viewType"),
102 (
int) createArgs.get(
"direction"),
103 PlatformViewCreationRequest.RequestedDisplayMode.HYBRID_ONLY,
108 final boolean hybridFallback =
109 createArgs.containsKey(
"hybridFallback")
110 && (boolean) createArgs.get(
"hybridFallback");
111 final PlatformViewCreationRequest.RequestedDisplayMode displayMode =
113 ? PlatformViewCreationRequest.RequestedDisplayMode
114 .TEXTURE_WITH_HYBRID_FALLBACK
115 : PlatformViewCreationRequest.RequestedDisplayMode
116 .TEXTURE_WITH_VIRTUAL_FALLBACK;
117 final PlatformViewCreationRequest request =
118 new PlatformViewCreationRequest(
119 (
int) createArgs.get(
"id"),
120 (String) createArgs.get(
"viewType"),
121 createArgs.containsKey(
"top") ? (
double) createArgs.get(
"top") : 0.0,
122 createArgs.containsKey(
"left") ? (
double) createArgs.get(
"left") : 0.0,
123 (
double) createArgs.get(
"width"),
124 (
double) createArgs.get(
"height"),
125 (
int) createArgs.get(
"direction"),
129 if (textureId == PlatformViewsHandler.NON_TEXTURE_FALLBACK) {
130 if (!hybridFallback) {
131 throw new AssertionError(
132 "Platform view attempted to fall back to hybrid mode when not requested.");
137 result.success(textureId);
140 }
catch (IllegalStateException exception) {
141 result.error(
"error", detailedExceptionString(exception),
null);
146 Map<String, Object> disposeArgs =
call.arguments();
147 int viewId = (
int) disposeArgs.get(
"id");
152 }
catch (IllegalStateException exception) {
153 result.error(
"error", detailedExceptionString(exception),
null);
158 Map<String, Object> resizeArgs =
call.arguments();
159 PlatformViewResizeRequest resizeRequest =
160 new PlatformViewResizeRequest(
161 (
int) resizeArgs.get(
"id"),
162 (
double) resizeArgs.get(
"width"),
163 (
double) resizeArgs.get(
"height"));
167 (PlatformViewBufferSize bufferSize) -> {
168 if (bufferSize ==
null) {
169 result.error(
"error",
"Failed to resize the platform view",
null);
171 final Map<String, Object> response =
new HashMap<>();
172 response.put(
"width", (
double) bufferSize.width);
173 response.put(
"height", (
double) bufferSize.height);
177 }
catch (IllegalStateException exception) {
178 result.error(
"error", detailedExceptionString(exception),
null);
183 Map<String, Object> offsetArgs =
call.arguments();
186 (
int) offsetArgs.get(
"id"),
187 (
double) offsetArgs.get(
"top"),
188 (
double) offsetArgs.get(
"left"));
190 }
catch (IllegalStateException exception) {
191 result.error(
"error", detailedExceptionString(exception),
null);
197 PlatformViewTouch touch =
198 new PlatformViewTouch(
200 (Number)
args.get(1),
201 (Number)
args.get(2),
208 (
float) (
double)
args.get(9),
209 (
float) (
double)
args.get(10),
214 ((Number)
args.get(15)).longValue());
219 }
catch (IllegalStateException exception) {
220 result.error(
"error", detailedExceptionString(exception),
null);
225 Map<String, Object> setDirectionArgs =
call.arguments();
226 int newDirectionViewId = (
int) setDirectionArgs.get(
"id");
227 int direction = (
int) setDirectionArgs.get(
"direction");
232 }
catch (IllegalStateException exception) {
233 result.error(
"error", detailedExceptionString(exception),
null);
238 int viewId =
call.arguments();
242 }
catch (IllegalStateException exception) {
243 result.error(
"error", detailedExceptionString(exception),
null);
247 private void synchronizeToNativeViewHierarchy(
249 boolean yes =
call.arguments();
253 }
catch (IllegalStateException exception) {
254 result.error(
"error", detailedExceptionString(exception),
null);
278 this.handler = handler;
337 void offset(
int viewId,
double top,
double left);
407 @Nullable
public final ByteBuffer
params;
418 @Nullable ByteBuffer
params) {
441 @Nullable ByteBuffer
params) {
static String getStackTraceString(@Nullable Throwable tr)
static void v(@NonNull String tag, @NonNull String message)
void setMethodCallHandler(final @Nullable MethodCallHandler handler)
void invokeMethod(@NonNull String method, @Nullable Object arguments)
static final StandardMethodCodec INSTANCE
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args