1616/** Sends touch information from Android to Flutter in a format that Flutter understands. */
1717public class AndroidTouchProcessor {
1818
19+ private static final String TAG = "AndroidTouchProcessor" ;
1920 // Must match the PointerChange enum in pointer.dart.
2021 @ IntDef ({
2122 PointerChange .CANCEL ,
@@ -186,29 +187,31 @@ public boolean onTouchEvent(@NonNull MotionEvent event, @NonNull Matrix transfor
186187 public boolean onGenericMotionEvent (@ NonNull MotionEvent event ) {
187188 // Method isFromSource is only available in API 18+ (Jelly Bean MR2)
188189 // Mouse hover support is not implemented for API < 18.
190+
189191 boolean isPointerEvent =
190192 Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR2
191193 && event .isFromSource (InputDevice .SOURCE_CLASS_POINTER );
194+
192195 boolean isMovementEvent =
193196 (event .getActionMasked () == MotionEvent .ACTION_HOVER_MOVE
194197 || event .getActionMasked () == MotionEvent .ACTION_SCROLL );
195- if (!isPointerEvent || !isMovementEvent ) {
196- return false ;
197- }
198-
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 );
204198
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." );
199+ if (isPointerEvent || isMovementEvent ) {
200+ int pointerChange = getPointerChangeForAction (event .getActionMasked ());
201+ ByteBuffer packet =
202+ ByteBuffer .allocateDirect (
203+ event .getPointerCount () * POINTER_DATA_FIELD_COUNT * BYTES_PER_FIELD );
204+ packet .order (ByteOrder .LITTLE_ENDIAN );
205+
206+ // ACTION_HOVER_MOVE always applies to a single pointer only.
207+ addPointerForIndex (event , event .getActionIndex (), pointerChange , 0 , IDENTITY_TRANSFORM , packet );
208+ if (packet .position () % (POINTER_DATA_FIELD_COUNT * BYTES_PER_FIELD ) != 0 ) {
209+ throw new AssertionError ("Packet position is not on field boundary." );
210+ }
211+ renderer .dispatchPointerDataPacket (packet , packet .position ());
212+ return true ;
209213 }
210- renderer .dispatchPointerDataPacket (packet , packet .position ());
211- return true ;
214+ return false ;
212215 }
213216
214217 // TODO(mattcarroll): consider creating a PointerPacket class instead of using a procedure that
@@ -252,6 +255,7 @@ private void addPointerForIndex(
252255 buttons = 0 ;
253256 }
254257
258+ int panZoomType = -1 ;
255259 boolean isTrackpadPan = ongoingPans .containsKey (event .getPointerId (pointerIndex ));
256260
257261 int signalKind =
@@ -264,8 +268,9 @@ private void addPointerForIndex(
264268 packet .putLong (motionEventId ); // motionEventId
265269 packet .putLong (timeStamp ); // time_stamp
266270 if (isTrackpadPan ) {
267- packet .putLong (getPointerChangeForPanZoom (pointerChange )); // change
268- packet .putLong (PointerDeviceKind .TRACKPAD ); // kind
271+ panZoomType = getPointerChangeForPanZoom (pointerChange );
272+ packet .putLong (panZoomType ); // change
273+ packet .putLong (PointerDeviceKind .TRACKPAD ); // kind
269274 } else {
270275 packet .putLong (pointerChange ); // change
271276 packet .putLong (pointerKind ); // kind
@@ -355,7 +360,7 @@ private void addPointerForIndex(
355360 packet .putDouble (1.0 ); // scale
356361 packet .putDouble (0.0 ); // rotation
357362
358- if (isTrackpadPan && getPointerChangeForPanZoom ( pointerChange ) == PointerChange .PAN_ZOOM_END ) {
363+ if (isTrackpadPan && ( panZoomType == PointerChange .PAN_ZOOM_END ) ) {
359364 ongoingPans .remove (event .getPointerId (pointerIndex ));
360365 }
361366 }
@@ -396,12 +401,12 @@ private int getPointerChangeForAction(int maskedAction) {
396401 private int getPointerChangeForPanZoom (int pointerChange ) {
397402 if (pointerChange == PointerChange .DOWN ) {
398403 return PointerChange .PAN_ZOOM_START ;
399- } else if (pointerChange == PointerChange .MOVE ) {
404+ } else if (pointerChange == PointerChange .MOVE || pointerChange == PointerChange . HOVER ) {
400405 return PointerChange .PAN_ZOOM_UPDATE ;
401406 } else if (pointerChange == PointerChange .UP || pointerChange == PointerChange .CANCEL ) {
402407 return PointerChange .PAN_ZOOM_END ;
403408 }
404- throw new AssertionError ( "Unexpected pointer change" ) ;
409+ return - 1 ;
405410 }
406411
407412 @ PointerDeviceKind
0 commit comments