@@ -50,13 +50,12 @@ final class MapGestureDetector {
50
50
51
51
private PointF focalPoint ;
52
52
53
- private boolean twoTap = false ;
54
- private boolean zoomStarted = false ;
55
- private boolean dragStarted = false ;
56
- private boolean quickZoom = false ;
57
- private boolean scrollInProgress = false ;
58
- private boolean scaleGestureOccurred = false ;
59
- private boolean recentScaleGestureOccurred = false ;
53
+ private boolean twoTap ;
54
+ private boolean quickZoom ;
55
+ private boolean tiltGestureOccurred ;
56
+ private boolean scrollGestureOccurred ;
57
+ private boolean scaleGestureOccurred ;
58
+ private boolean recentScaleGestureOccurred ;
60
59
61
60
MapGestureDetector (Context context , Transform transform , Projection projection , UiSettings uiSettings ,
62
61
TrackingSettings trackingSettings , AnnotationManager annotationManager ,
@@ -193,10 +192,10 @@ boolean onTouchEvent(MotionEvent event) {
193
192
}
194
193
195
194
// Scroll / Pan Has Stopped
196
- if (scrollInProgress ) {
195
+ if (scrollGestureOccurred ) {
197
196
MapboxTelemetry .getInstance ().pushEvent (MapboxEventWrapper .buildMapDragEndEvent (
198
197
getLocationFromGesture (event .getX (), event .getY ()), transform ));
199
- scrollInProgress = false ;
198
+ scrollGestureOccurred = false ;
200
199
cameraChangeDispatcher .onCameraIdle ();
201
200
}
202
201
@@ -393,20 +392,18 @@ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float d
393
392
return false ;
394
393
}
395
394
396
- if (dragStarted ) {
395
+ if (tiltGestureOccurred ) {
397
396
return false ;
398
397
}
399
398
400
- if (scaleGestureOccurred ) {
401
- return false ;
402
- }
403
-
404
- if (!scrollInProgress ) {
405
- scrollInProgress = true ;
399
+ if (!scrollGestureOccurred ) {
400
+ scrollGestureOccurred = true ;
406
401
407
402
// Cancel any animation
408
- transform .cancelTransitions ();
409
- cameraChangeDispatcher .onCameraMoveStarted (REASON_API_GESTURE );
403
+ if (!scaleGestureOccurred ) {
404
+ transform .cancelTransitions ();
405
+ cameraChangeDispatcher .onCameraMoveStarted (REASON_API_GESTURE );
406
+ }
410
407
411
408
MapboxTelemetry .getInstance ().pushEvent (MapboxEventWrapper .buildMapClickEvent (
412
409
getLocationFromGesture (e1 .getX (), e1 .getY ()),
@@ -456,7 +453,6 @@ public void onScaleEnd(ScaleGestureDetector detector) {
456
453
scaleGestureOccurred = false ;
457
454
beginTime = 0 ;
458
455
scaleFactor = 1.0f ;
459
- zoomStarted = false ;
460
456
cameraChangeDispatcher .onCameraIdle ();
461
457
}
462
458
@@ -468,27 +464,27 @@ public boolean onScale(ScaleGestureDetector detector) {
468
464
return super .onScale (detector );
469
465
}
470
466
471
- // If scale is large enough ignore a tap
472
- scaleFactor *= detector .getScaleFactor ();
473
- if ((scaleFactor > 1.05f ) || (scaleFactor < 0.95f )) {
474
- // notify camera change listener
475
- cameraChangeDispatcher .onCameraMoveStarted (REASON_API_GESTURE );
476
- zoomStarted = true ;
467
+ if (tiltGestureOccurred ) {
468
+ return false ;
477
469
}
478
470
479
471
// Ignore short touches in case it is a tap
480
472
// Also ignore small scales
481
473
long time = detector .getEventTime ();
482
474
long interval = time - beginTime ;
483
- if (!zoomStarted && (interval <= ViewConfiguration .getTapTimeout ())) {
475
+ if (!scaleGestureOccurred && (interval <= ViewConfiguration .getTapTimeout ())) {
484
476
return false ;
485
477
}
486
478
487
- if (!zoomStarted ) {
488
- return false ;
479
+ // If scale is large enough ignore a tap
480
+ scaleFactor *= detector .getScaleFactor ();
481
+ if ((scaleFactor > 1.05f ) || (scaleFactor < 0.95f )) {
482
+ // notify camera change listener
483
+ cameraChangeDispatcher .onCameraMoveStarted (REASON_API_GESTURE );
484
+ scaleGestureOccurred = true ;
489
485
}
490
486
491
- if (dragStarted ) {
487
+ if (! scaleGestureOccurred ) {
492
488
return false ;
493
489
}
494
490
@@ -506,18 +502,20 @@ public boolean onScale(ScaleGestureDetector detector) {
506
502
// Scale the map
507
503
if (focalPoint != null ) {
508
504
// arround user provided focal point
509
- transform .zoomBy (Math .log (detector .getScaleFactor ()) / Math .log (2 ), focalPoint .x , focalPoint .y );
505
+ transform .zoomBy (Math .log (detector .getScaleFactor ()) / Math .log (Math . PI / 2 ), focalPoint .x , focalPoint .y );
510
506
} else if (quickZoom ) {
511
507
cameraChangeDispatcher .onCameraMove ();
512
508
// clamp scale factors we feed to core #7514
513
509
float scaleFactor = MathUtils .clamp (detector .getScaleFactor (),
514
510
MapboxConstants .MINIMUM_SCALE_FACTOR_CLAMP ,
515
511
MapboxConstants .MAXIMUM_SCALE_FACTOR_CLAMP );
516
512
// around center map
517
- transform .zoomBy (Math .log (scaleFactor ) / Math .log (2 ), uiSettings .getWidth () / 2 , uiSettings .getHeight () / 2 );
513
+ transform .zoomBy (Math .log (scaleFactor ) / Math .log (Math .PI / 2 ),
514
+ uiSettings .getWidth () / 2 , uiSettings .getHeight () / 2 );
518
515
} else {
519
516
// around gesture
520
- transform .zoomBy (Math .log (detector .getScaleFactor ()) / Math .log (2 ), detector .getFocusX (), detector .getFocusY ());
517
+ transform .zoomBy (Math .log (detector .getScaleFactor ()) / Math .log (Math .PI / 2 ),
518
+ detector .getFocusX (), detector .getFocusY ());
521
519
}
522
520
523
521
return true ;
@@ -544,9 +542,6 @@ public boolean onRotateBegin(RotateGestureDetector detector) {
544
542
cameraChangeDispatcher .onCameraMoveStarted (REASON_API_GESTURE );
545
543
546
544
beginTime = detector .getEventTime ();
547
- MapboxTelemetry .getInstance ().pushEvent (MapboxEventWrapper .buildMapClickEvent (
548
- getLocationFromGesture (detector .getFocusX (), detector .getFocusY ()),
549
- MapboxEvent .GESTURE_ROTATION_START , transform ));
550
545
return true ;
551
546
}
552
547
@@ -563,17 +558,10 @@ public void onRotateEnd(RotateGestureDetector detector) {
563
558
// Called for rotation
564
559
@ Override
565
560
public boolean onRotate (RotateGestureDetector detector ) {
566
- if (!trackingSettings .isRotateGestureCurrentlyEnabled () || dragStarted ) {
561
+ if (!trackingSettings .isRotateGestureCurrentlyEnabled () || tiltGestureOccurred ) {
567
562
return false ;
568
563
}
569
564
570
- // If rotate is large enough ignore a tap
571
- // Also is zoom already started, don't rotate
572
- totalAngle += detector .getRotationDegreesDelta ();
573
- if (totalAngle > 20.0f || totalAngle < -20.0f ) {
574
- started = true ;
575
- }
576
-
577
565
// Ignore short touches in case it is a tap
578
566
// Also ignore small rotate
579
567
long time = detector .getEventTime ();
@@ -582,6 +570,16 @@ public boolean onRotate(RotateGestureDetector detector) {
582
570
return false ;
583
571
}
584
572
573
+ // If rotate is large enough ignore a tap
574
+ // Also is zoom already started, don't rotate
575
+ totalAngle += detector .getRotationDegreesDelta ();
576
+ if (totalAngle > 35.0f || totalAngle < -35.0f ) {
577
+ MapboxTelemetry .getInstance ().pushEvent (MapboxEventWrapper .buildMapClickEvent (
578
+ getLocationFromGesture (detector .getFocusX (), detector .getFocusY ()),
579
+ MapboxEvent .GESTURE_ROTATION_START , transform ));
580
+ started = true ;
581
+ }
582
+
585
583
if (!started ) {
586
584
return false ;
587
585
}
@@ -610,9 +608,8 @@ public boolean onRotate(RotateGestureDetector detector) {
610
608
*/
611
609
private class ShoveGestureListener implements ShoveGestureDetector .OnShoveGestureListener {
612
610
613
- long beginTime = 0 ;
614
- float totalDelta = 0.0f ;
615
- boolean started = false ;
611
+ private long beginTime = 0 ;
612
+ private float totalDelta = 0.0f ;
616
613
617
614
@ Override
618
615
public boolean onShoveBegin (ShoveGestureDetector detector ) {
@@ -622,19 +619,14 @@ public boolean onShoveBegin(ShoveGestureDetector detector) {
622
619
623
620
// notify camera change listener
624
621
cameraChangeDispatcher .onCameraMoveStarted (REASON_API_GESTURE );
625
- beginTime = detector .getEventTime ();
626
- MapboxTelemetry .getInstance ().pushEvent (MapboxEventWrapper .buildMapClickEvent (
627
- getLocationFromGesture (detector .getFocusX (), detector .getFocusY ()),
628
- MapboxEvent .GESTURE_PITCH_START , transform ));
629
622
return true ;
630
623
}
631
624
632
625
@ Override
633
626
public void onShoveEnd (ShoveGestureDetector detector ) {
634
627
beginTime = 0 ;
635
628
totalDelta = 0.0f ;
636
- started = false ;
637
- dragStarted = false ;
629
+ tiltGestureOccurred = false ;
638
630
}
639
631
640
632
@ Override
@@ -643,22 +635,26 @@ public boolean onShove(ShoveGestureDetector detector) {
643
635
return false ;
644
636
}
645
637
646
- // If tilt is large enough ignore a tap
647
- // Also if zoom already started, don't tilt
648
- totalDelta += detector .getShovePixelsDelta ();
649
- if (!zoomStarted && ((totalDelta > 10.0f ) || (totalDelta < -10.0f ))) {
650
- started = true ;
651
- }
652
-
653
638
// Ignore short touches in case it is a tap
654
639
// Also ignore small tilt
655
640
long time = detector .getEventTime ();
656
641
long interval = time - beginTime ;
657
- if (!started && (interval <= ViewConfiguration .getTapTimeout ())) {
642
+ if (!tiltGestureOccurred && (interval <= ViewConfiguration .getTapTimeout ())) {
658
643
return false ;
659
644
}
660
645
661
- if (!started ) {
646
+ // If tilt is large enough ignore a tap
647
+ // Also if zoom already started, don't tilt
648
+ totalDelta += detector .getShovePixelsDelta ();
649
+ if (!tiltGestureOccurred && ((totalDelta > 10.0f ) || (totalDelta < -10.0f ))) {
650
+ tiltGestureOccurred = true ;
651
+ beginTime = detector .getEventTime ();
652
+ MapboxTelemetry .getInstance ().pushEvent (MapboxEventWrapper .buildMapClickEvent (
653
+ getLocationFromGesture (detector .getFocusX (), detector .getFocusY ()),
654
+ MapboxEvent .GESTURE_PITCH_START , transform ));
655
+ }
656
+
657
+ if (!tiltGestureOccurred ) {
662
658
return false ;
663
659
}
664
660
@@ -669,9 +665,6 @@ public boolean onShove(ShoveGestureDetector detector) {
669
665
670
666
// Tilt the map
671
667
transform .setTilt (pitch );
672
-
673
- dragStarted = true ;
674
-
675
668
return true ;
676
669
}
677
670
}
0 commit comments