@@ -192,23 +192,24 @@ public boolean onGenericMotionEvent(@NonNull MotionEvent event) {
192192 boolean isMovementEvent =
193193 (event .getActionMasked () == MotionEvent .ACTION_HOVER_MOVE
194194 || event .getActionMasked () == MotionEvent .ACTION_SCROLL );
195- if (!isPointerEvent || !isMovementEvent ) {
196- return false ;
197- }
198195
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 ;
209211 }
210- renderer .dispatchPointerDataPacket (packet , packet .position ());
211- return true ;
212+ return false ;
212213 }
213214
214215 // TODO(mattcarroll): consider creating a PointerPacket class instead of using a procedure that
@@ -224,12 +225,6 @@ private void addPointerForIndex(
224225 return ;
225226 }
226227
227- long motionEventId = 0 ;
228- if (trackMotionEvents ) {
229- MotionEventTracker .MotionEventId trackedEvent = motionEventTracker .track (event );
230- motionEventId = trackedEvent .getId ();
231- }
232-
233228 int pointerKind = getPointerDeviceTypeForToolType (event .getToolType (pointerIndex ));
234229 // We use this in lieu of using event.getRawX and event.getRawY as we wish to support
235230 // earlier versions than API level 29.
@@ -252,7 +247,20 @@ private void addPointerForIndex(
252247 buttons = 0 ;
253248 }
254249
250+ int panZoomType = -1 ;
255251 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+ }
256264
257265 int signalKind =
258266 event .getActionMasked () == MotionEvent .ACTION_SCROLL
@@ -264,7 +272,7 @@ private void addPointerForIndex(
264272 packet .putLong (motionEventId ); // motionEventId
265273 packet .putLong (timeStamp ); // time_stamp
266274 if (isTrackpadPan ) {
267- packet .putLong (getPointerChangeForPanZoom ( pointerChange ) ); // change
275+ packet .putLong (panZoomType ); // change
268276 packet .putLong (PointerDeviceKind .TRACKPAD ); // kind
269277 } else {
270278 packet .putLong (pointerChange ); // change
@@ -355,7 +363,7 @@ private void addPointerForIndex(
355363 packet .putDouble (1.0 ); // scale
356364 packet .putDouble (0.0 ); // rotation
357365
358- if (isTrackpadPan && getPointerChangeForPanZoom ( pointerChange ) == PointerChange .PAN_ZOOM_END ) {
366+ if (isTrackpadPan && ( panZoomType == PointerChange .PAN_ZOOM_END ) ) {
359367 ongoingPans .remove (event .getPointerId (pointerIndex ));
360368 }
361369 }
@@ -401,7 +409,7 @@ private int getPointerChangeForPanZoom(int pointerChange) {
401409 } else if (pointerChange == PointerChange .UP || pointerChange == PointerChange .CANCEL ) {
402410 return PointerChange .PAN_ZOOM_END ;
403411 }
404- throw new AssertionError ( "Unexpected pointer change" ) ;
412+ return - 1 ;
405413 }
406414
407415 @ PointerDeviceKind
0 commit comments