@@ -192,23 +192,24 @@ public boolean onGenericMotionEvent(@NonNull MotionEvent event) {
192
192
boolean isMovementEvent =
193
193
(event .getActionMasked () == MotionEvent .ACTION_HOVER_MOVE
194
194
|| event .getActionMasked () == MotionEvent .ACTION_SCROLL );
195
- if (!isPointerEvent || !isMovementEvent ) {
196
- return false ;
197
- }
198
195
199
- int pointerChange = getPointerChangeForAction (event .getActionMasked ());
200
- ByteBuffer packet =
201
- ByteBuffer .allocateDirect (
202
- event .getPointerCount () * POINTER_DATA_FIELD_COUNT * BYTES_PER_FIELD );
203
- packet .order (ByteOrder .LITTLE_ENDIAN );
204
-
205
- // ACTION_HOVER_MOVE always applies to a single pointer only.
206
- addPointerForIndex (event , event .getActionIndex (), pointerChange , 0 , IDENTITY_TRANSFORM , packet );
207
- if (packet .position () % (POINTER_DATA_FIELD_COUNT * BYTES_PER_FIELD ) != 0 ) {
208
- throw new AssertionError ("Packet position is not on field boundary." );
196
+ if (isPointerEvent || isMovementEvent ) {
197
+ int pointerChange = getPointerChangeForAction (event .getActionMasked ());
198
+ ByteBuffer packet =
199
+ ByteBuffer .allocateDirect (
200
+ event .getPointerCount () * POINTER_DATA_FIELD_COUNT * BYTES_PER_FIELD );
201
+ packet .order (ByteOrder .LITTLE_ENDIAN );
202
+
203
+ // ACTION_HOVER_MOVE always applies to a single pointer only.
204
+ addPointerForIndex (
205
+ event , event .getActionIndex (), pointerChange , 0 , IDENTITY_TRANSFORM , packet );
206
+ if (packet .position () % (POINTER_DATA_FIELD_COUNT * BYTES_PER_FIELD ) != 0 ) {
207
+ throw new AssertionError ("Packet position is not on field boundary." );
208
+ }
209
+ renderer .dispatchPointerDataPacket (packet , packet .position ());
210
+ return true ;
209
211
}
210
- renderer .dispatchPointerDataPacket (packet , packet .position ());
211
- return true ;
212
+ return false ;
212
213
}
213
214
214
215
// TODO(mattcarroll): consider creating a PointerPacket class instead of using a procedure that
@@ -224,12 +225,6 @@ private void addPointerForIndex(
224
225
return ;
225
226
}
226
227
227
- long motionEventId = 0 ;
228
- if (trackMotionEvents ) {
229
- MotionEventTracker .MotionEventId trackedEvent = motionEventTracker .track (event );
230
- motionEventId = trackedEvent .getId ();
231
- }
232
-
233
228
int pointerKind = getPointerDeviceTypeForToolType (event .getToolType (pointerIndex ));
234
229
// We use this in lieu of using event.getRawX and event.getRawY as we wish to support
235
230
// earlier versions than API level 29.
@@ -252,7 +247,20 @@ private void addPointerForIndex(
252
247
buttons = 0 ;
253
248
}
254
249
250
+ int panZoomType = -1 ;
255
251
boolean isTrackpadPan = ongoingPans .containsKey (event .getPointerId (pointerIndex ));
252
+ if (isTrackpadPan ) {
253
+ panZoomType = getPointerChangeForPanZoom (pointerChange );
254
+ if (panZoomType == -1 ) {
255
+ return ;
256
+ }
257
+ }
258
+
259
+ long motionEventId = 0 ;
260
+ if (trackMotionEvents ) {
261
+ MotionEventTracker .MotionEventId trackedEvent = motionEventTracker .track (event );
262
+ motionEventId = trackedEvent .getId ();
263
+ }
256
264
257
265
int signalKind =
258
266
event .getActionMasked () == MotionEvent .ACTION_SCROLL
@@ -264,7 +272,7 @@ private void addPointerForIndex(
264
272
packet .putLong (motionEventId ); // motionEventId
265
273
packet .putLong (timeStamp ); // time_stamp
266
274
if (isTrackpadPan ) {
267
- packet .putLong (getPointerChangeForPanZoom ( pointerChange ) ); // change
275
+ packet .putLong (panZoomType ); // change
268
276
packet .putLong (PointerDeviceKind .TRACKPAD ); // kind
269
277
} else {
270
278
packet .putLong (pointerChange ); // change
@@ -355,7 +363,7 @@ private void addPointerForIndex(
355
363
packet .putDouble (1.0 ); // scale
356
364
packet .putDouble (0.0 ); // rotation
357
365
358
- if (isTrackpadPan && getPointerChangeForPanZoom ( pointerChange ) == PointerChange .PAN_ZOOM_END ) {
366
+ if (isTrackpadPan && ( panZoomType == PointerChange .PAN_ZOOM_END ) ) {
359
367
ongoingPans .remove (event .getPointerId (pointerIndex ));
360
368
}
361
369
}
@@ -401,7 +409,7 @@ private int getPointerChangeForPanZoom(int pointerChange) {
401
409
} else if (pointerChange == PointerChange .UP || pointerChange == PointerChange .CANCEL ) {
402
410
return PointerChange .PAN_ZOOM_END ;
403
411
}
404
- throw new AssertionError ( "Unexpected pointer change" ) ;
412
+ return - 1 ;
405
413
}
406
414
407
415
@ PointerDeviceKind
0 commit comments