26 private static final String TAG =
"PlatformViewsChannel";
28 private final MethodChannel channel;
32 if (channel ==
null) {
35 channel.invokeMethod(
"viewFocused", viewId);
38 private static String detailedExceptionString(Exception exception) {
42 private final MethodChannel.MethodCallHandler parsingHandler =
43 new MethodChannel.MethodCallHandler() {
45 public void onMethodCall(@NonNull
MethodCall call, @NonNull MethodChannel.Result
result) {
48 if (handler ==
null) {
52 Log.
v(TAG,
"Received '" + call.method +
"' message.");
53 switch (call.method) {
70 setDirection(call,
result);
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);
145 private void dispose(@NonNull
MethodCall call, @NonNull MethodChannel.Result
result) {
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);
157 private void resize(@NonNull
MethodCall call, @NonNull MethodChannel.Result
result) {
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);
195 private void touch(@NonNull
MethodCall call, @NonNull MethodChannel.Result
result) {
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);
224 private void setDirection(@NonNull
MethodCall call, @NonNull MethodChannel.Result
result) {
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);
237 private void clearFocus(@NonNull
MethodCall call, @NonNull MethodChannel.Result
result) {
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);
269 new MethodChannel(dartExecutor,
"flutter/platform_views", StandardMethodCodec.INSTANCE);
270 channel.setMethodCallHandler(parsingHandler);
278 this.handler = handler;
407 @Nullable
public final ByteBuffer
params;
418 @Nullable ByteBuffer
params) {
441 @Nullable ByteBuffer
params) {