@@ -93,6 +93,13 @@ public class AndroidTouchProcessor {
93
93
94
94
private final Map <Integer , float []> ongoingPans = new HashMap <>();
95
95
96
+ private boolean isSkipVersionCheck = false ;
97
+
98
+ @ VisibleForTesting
99
+ public void setSkipVersionCheck (boolean enabled ) {
100
+ isSkipVersionCheck = enabled ;
101
+ }
102
+
96
103
/**
97
104
* Constructs an {@code AndroidTouchProcessor} that will send touch event data to the Flutter
98
105
* execution context represented by the given {@link FlutterRenderer}.
@@ -186,16 +193,18 @@ public boolean onTouchEvent(@NonNull MotionEvent event, @NonNull Matrix transfor
186
193
public boolean onGenericMotionEvent (@ NonNull MotionEvent event ) {
187
194
// Method isFromSource is only available in API 18+ (Jelly Bean MR2)
188
195
// Mouse hover support is not implemented for API < 18.
189
- boolean isPointerEvent =
190
- Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR2
191
- && event .isFromSource (InputDevice .SOURCE_CLASS_POINTER );
192
- boolean isMovementEvent =
193
- (event .getActionMasked () == MotionEvent .ACTION_HOVER_MOVE
194
- || event .getActionMasked () == MotionEvent .ACTION_SCROLL );
195
- if (!isPointerEvent || !isMovementEvent ) {
196
- return false ;
196
+ if (!isSkipVersionCheck ) {
197
+ boolean isPointerEvent =
198
+ Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR2
199
+ && event .isFromSource (InputDevice .SOURCE_CLASS_POINTER );
200
+ boolean isMovementEvent =
201
+ (event .getActionMasked () == MotionEvent .ACTION_HOVER_MOVE
202
+ || event .getActionMasked () == MotionEvent .ACTION_SCROLL );
203
+
204
+ if (!isPointerEvent || !isMovementEvent ) {
205
+ return false ;
206
+ }
197
207
}
198
-
199
208
int pointerChange = getPointerChangeForAction (event .getActionMasked ());
200
209
ByteBuffer packet =
201
210
ByteBuffer .allocateDirect (
@@ -224,12 +233,6 @@ private void addPointerForIndex(
224
233
return ;
225
234
}
226
235
227
- long motionEventId = 0 ;
228
- if (trackMotionEvents ) {
229
- MotionEventTracker .MotionEventId trackedEvent = motionEventTracker .track (event );
230
- motionEventId = trackedEvent .getId ();
231
- }
232
-
233
236
int pointerKind = getPointerDeviceTypeForToolType (event .getToolType (pointerIndex ));
234
237
// We use this in lieu of using event.getRawX and event.getRawY as we wish to support
235
238
// earlier versions than API level 29.
@@ -252,7 +255,20 @@ private void addPointerForIndex(
252
255
buttons = 0 ;
253
256
}
254
257
258
+ int panZoomType = -1 ;
255
259
boolean isTrackpadPan = ongoingPans .containsKey (event .getPointerId (pointerIndex ));
260
+ if (isTrackpadPan ) {
261
+ panZoomType = getPointerChangeForPanZoom (pointerChange );
262
+ if (panZoomType == -1 ) {
263
+ return ;
264
+ }
265
+ }
266
+
267
+ long motionEventId = 0 ;
268
+ if (trackMotionEvents ) {
269
+ MotionEventTracker .MotionEventId trackedEvent = motionEventTracker .track (event );
270
+ motionEventId = trackedEvent .getId ();
271
+ }
256
272
257
273
int signalKind =
258
274
event .getActionMasked () == MotionEvent .ACTION_SCROLL
@@ -264,7 +280,7 @@ private void addPointerForIndex(
264
280
packet .putLong (motionEventId ); // motionEventId
265
281
packet .putLong (timeStamp ); // time_stamp
266
282
if (isTrackpadPan ) {
267
- packet .putLong (getPointerChangeForPanZoom ( pointerChange ) ); // change
283
+ packet .putLong (panZoomType ); // change
268
284
packet .putLong (PointerDeviceKind .TRACKPAD ); // kind
269
285
} else {
270
286
packet .putLong (pointerChange ); // change
@@ -355,7 +371,7 @@ private void addPointerForIndex(
355
371
packet .putDouble (1.0 ); // scale
356
372
packet .putDouble (0.0 ); // rotation
357
373
358
- if (isTrackpadPan && getPointerChangeForPanZoom ( pointerChange ) == PointerChange .PAN_ZOOM_END ) {
374
+ if (isTrackpadPan && ( panZoomType == PointerChange .PAN_ZOOM_END ) ) {
359
375
ongoingPans .remove (event .getPointerId (pointerIndex ));
360
376
}
361
377
}
@@ -401,7 +417,7 @@ private int getPointerChangeForPanZoom(int pointerChange) {
401
417
} else if (pointerChange == PointerChange .UP || pointerChange == PointerChange .CANCEL ) {
402
418
return PointerChange .PAN_ZOOM_END ;
403
419
}
404
- throw new AssertionError ( "Unexpected pointer change" ) ;
420
+ return - 1 ;
405
421
}
406
422
407
423
@ PointerDeviceKind
0 commit comments