@@ -244,37 +244,18 @@ public void run() {
244
244
245
245
@ Override
246
246
public void onTouch (@ NonNull PlatformViewsChannel .PlatformViewTouch touch ) {
247
- PointerProperties [] pointerProperties =
248
- parsePointerPropertiesList (touch .rawPointerPropertiesList )
249
- .toArray (new PointerProperties [touch .pointerCount ]);
250
- PointerCoords [] pointerCoords =
251
- parsePointerCoordsList (touch .rawPointerCoords , getDisplayDensity ())
252
- .toArray (new PointerCoords [touch .pointerCount ]);
253
-
254
- if (!vdControllers .containsKey (touch .viewId )) {
255
- throw new IllegalStateException (
256
- "Sending touch to an unknown view with id: " + touch .viewId );
257
- }
258
-
259
- MotionEvent event =
260
- MotionEvent .obtain (
261
- touch .downTime .longValue (),
262
- touch .eventTime .longValue (),
263
- touch .action ,
264
- touch .pointerCount ,
265
- pointerProperties ,
266
- pointerCoords ,
267
- touch .metaState ,
268
- touch .buttonState ,
269
- touch .xPrecision ,
270
- touch .yPrecision ,
271
- touch .deviceId ,
272
- touch .edgeFlags ,
273
- touch .source ,
274
- touch .flags );
275
-
247
+ final int viewId = touch .viewId ;
248
+ float density = context .getResources ().getDisplayMetrics ().density ;
276
249
ensureValidAndroidVersion (Build .VERSION_CODES .KITKAT_WATCH );
277
- vdControllers .get (touch .viewId ).dispatchTouchEvent (event );
250
+ final MotionEvent event = toMotionEvent (density , touch );
251
+ if (vdControllers .containsKey (viewId )) {
252
+ vdControllers .get (touch .viewId ).dispatchTouchEvent (event );
253
+ } else if (platformViews .get (viewId ) != null ) {
254
+ View view = platformViews .get (touch .viewId );
255
+ view .dispatchTouchEvent (event );
256
+ } else {
257
+ throw new IllegalStateException ("Sending touch to an unknown view with id: " + viewId );
258
+ }
278
259
}
279
260
280
261
@ TargetApi (Build .VERSION_CODES .JELLY_BEAN_MR1 )
@@ -317,6 +298,32 @@ private void ensureValidAndroidVersion(int minSdkVersion) {
317
298
}
318
299
};
319
300
301
+ private static MotionEvent toMotionEvent (
302
+ float density , PlatformViewsChannel .PlatformViewTouch touch ) {
303
+ PointerProperties [] pointerProperties =
304
+ parsePointerPropertiesList (touch .rawPointerPropertiesList )
305
+ .toArray (new PointerProperties [touch .pointerCount ]);
306
+ PointerCoords [] pointerCoords =
307
+ parsePointerCoordsList (touch .rawPointerCoords , density )
308
+ .toArray (new PointerCoords [touch .pointerCount ]);
309
+
310
+ return MotionEvent .obtain (
311
+ touch .downTime .longValue (),
312
+ touch .eventTime .longValue (),
313
+ touch .action ,
314
+ touch .pointerCount ,
315
+ pointerProperties ,
316
+ pointerCoords ,
317
+ touch .metaState ,
318
+ touch .buttonState ,
319
+ touch .xPrecision ,
320
+ touch .yPrecision ,
321
+ touch .deviceId ,
322
+ touch .edgeFlags ,
323
+ touch .source ,
324
+ touch .flags );
325
+ }
326
+
320
327
public PlatformViewsController () {
321
328
registry = new PlatformViewRegistryImpl ();
322
329
vdControllers = new HashMap <>();
0 commit comments