diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java index 417eb021e0..52281f9d7a 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java @@ -15,10 +15,14 @@ import io.flutter.plugin.common.StandardMethodCodec; import io.flutter.view.FlutterView; import io.flutter.view.TextureRegistry; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import static android.view.MotionEvent.PointerCoords; +import static android.view.MotionEvent.PointerProperties; + /** * Manages platform views. *

@@ -191,19 +195,26 @@ public class PlatformViewsController implements MethodChannel.MethodCallHandler private void onTouch(MethodCall call, MethodChannel.Result result) { List args = call.arguments(); + float density = mFlutterView.getContext().getResources().getDisplayMetrics().density; + int id = (int) args.get(0); int downTime = (int) args.get(1); int eventTime = (int) args.get(2); int action = (int) args.get(3); - double x = (double) args.get(4); - double y = (double) args.get(5); - double pressure = (double) args.get(6); - double size = (double) args.get(7); - int metaState = (int) args.get(8); - double xPrecision = (double) args.get(9); - double yPrecision = (double) args.get(10); + int pointerCount = (int) args.get(4); + PointerProperties[] pointerProperties = + parsePointerPropertiesList(args.get(5)).toArray(new PointerProperties[pointerCount]); + PointerCoords[] pointerCoords = + parsePointerCoordsList(args.get(6), density).toArray(new PointerCoords[pointerCount]); + + int metaState = (int) args.get(7); + int buttonState = (int) args.get(8); + float xPrecision = (float) (double) args.get(9); + float yPrecision = (float) (double) args.get(10); int deviceId = (int) args.get(11); int edgeFlags = (int) args.get(12); + int source = (int) args.get(13); + int flags = (int) args.get(14); View view = vdControllers.get(id).getView(); if (view == null) { @@ -215,27 +226,72 @@ public class PlatformViewsController implements MethodChannel.MethodCallHandler return; } - float density = mFlutterView.getContext().getResources().getDisplayMetrics().density; - MotionEvent event = MotionEvent.obtain( downTime, eventTime, action, - (float) x * density, - (float) y * density, - (float) pressure, - (float) size, + pointerCount, + pointerProperties, + pointerCoords, metaState, - (float) xPrecision, - (float) yPrecision, + buttonState, + xPrecision, + yPrecision, deviceId, - edgeFlags + edgeFlags, + source, + flags ); view.onTouchEvent(event); result.success(null); } + @SuppressWarnings("unchecked") + private static List parsePointerPropertiesList(Object rawPropertiesList) { + List rawProperties = (List) rawPropertiesList; + List pointerProperties = new ArrayList<>(); + for (Object o : rawProperties) { + pointerProperties.add(parsePointerProperties(o)); + } + return pointerProperties; + } + + @SuppressWarnings("unchecked") + private static PointerProperties parsePointerProperties(Object rawProperties) { + List propertiesList = (List) rawProperties; + PointerProperties properties = new MotionEvent.PointerProperties(); + properties.id = (int) propertiesList.get(0); + properties.toolType = (int) propertiesList.get(1); + return properties; + } + + @SuppressWarnings("unchecked") + private static List parsePointerCoordsList(Object rawCoordsList, float density) { + List rawCoords = (List) rawCoordsList; + List pointerCoords = new ArrayList<>(); + for (Object o : rawCoords) { + pointerCoords.add(parsePointerCoords(o, density)); + } + return pointerCoords; + } + + @SuppressWarnings("unchecked") + private static PointerCoords parsePointerCoords(Object rawCoords, float density) { + List coordsList = (List) rawCoords; + PointerCoords coords = new MotionEvent.PointerCoords(); + coords.orientation = (float) (double) coordsList.get(0); + coords.pressure = (float) (double) coordsList.get(1); + coords.size = (float) (double) coordsList.get(2); + coords.toolMajor = (float) (double) coordsList.get(3) * density; + coords.toolMinor = (float) (double) coordsList.get(4) * density; + coords.touchMajor = (float) (double) coordsList.get(5) * density; + coords.touchMinor = (float) (double) coordsList.get(6) * density; + coords.x = (float) (double) coordsList.get(7) * density; + coords.y = (float) (double) coordsList.get(8) * density; + return coords; + } + private int toPhysicalPixels(double logicalPixels) { float density = mFlutterView.getContext().getResources().getDisplayMetrics().density; return (int) Math.round(logicalPixels * density);