[android ] - new gestures library (cp #11221) (#11332)

* [android] new gesture library - added SNAPSHOT dependency

* [android] new gesture library - cleaned up redundant classes

* [android] new gesture library - limiting scale when rotating

* [android] new gesture library - shove gesture filtering

* [android] new gesture library - increase rotation threshold when scaling

* [android] new gesture library - minimum angular velocity

* [android] new gesture library - exposed gestures execution listeners

* [android] new gesture library - notifying new listeners tests

* [android] new gesture library - removed tracking setting

* [android] new gesture library - resetting focal point with every scale/rotate callback

* [android] new gesture library - fixed camera change dispatcher callbacks

* [android] new gesture library - cancel velocity animations in maps onStop()

* [android] new gesture library - extracted telemetry pushes to a method

* [android] new gesture library - deprecated onScrollListener

* [android] new gesture library - unified shove listener name

(cherry picked from commit 7905bd6)
This commit is contained in:
Łukasz Paczos
2018-02-27 18:35:05 +01:00
committed by GitHub
parent 43a7db0b0b
commit 848d7dff4e
17 changed files with 1072 additions and 1689 deletions

View File

@@ -2,8 +2,13 @@ package com.mapbox.mapboxsdk.maps;
import android.graphics.PointF;
import com.mapbox.android.gestures.MoveGestureDetector;
import com.mapbox.android.gestures.RotateGestureDetector;
import com.mapbox.android.gestures.ShoveGestureDetector;
import com.mapbox.android.gestures.StandardScaleGestureDetector;
import com.mapbox.mapboxsdk.geometry.LatLng;
import org.junit.Before;
import org.junit.Test;
import static org.mockito.Mockito.mock;
@@ -13,16 +18,23 @@ import static org.mockito.Mockito.when;
public class MapTouchListenersTest {
@Test
public void onMapClickListenerTest() throws Exception {
LatLng latLng = new LatLng();
PointF pointF = new PointF();
private MapGestureDetector mapGestureDetector;
private LatLng latLng;
private PointF pointF;
@Before
public void setUp() throws Exception {
latLng = new LatLng();
pointF = new PointF();
Projection projection = mock(Projection.class);
when(projection.fromScreenLocation(pointF)).thenReturn(latLng);
MapGestureDetector mapGestureDetector = new MapGestureDetector(null,
null, projection, null, null, null, null);
mapGestureDetector = new MapGestureDetector(null,
null, projection, null, null, null);
}
@Test
public void onMapClickListenerTest() throws Exception {
MapboxMap.OnMapClickListener listener = mock(MapboxMap.OnMapClickListener.class);
mapGestureDetector.addOnMapClickListener(listener);
mapGestureDetector.notifyOnMapClickListeners(pointF);
@@ -35,14 +47,6 @@ public class MapTouchListenersTest {
@Test
public void onMapLongClickListenerTest() throws Exception {
LatLng latLng = new LatLng();
PointF pointF = new PointF();
Projection projection = mock(Projection.class);
when(projection.fromScreenLocation(pointF)).thenReturn(latLng);
MapGestureDetector mapGestureDetector = new MapGestureDetector(null,
null, projection, null, null, null, null);
MapboxMap.OnMapLongClickListener listener = mock(MapboxMap.OnMapLongClickListener.class);
mapGestureDetector.addOnMapLongClickListener(listener);
mapGestureDetector.notifyOnMapLongClickListeners(pointF);
@@ -55,14 +59,6 @@ public class MapTouchListenersTest {
@Test
public void onFlingListenerTest() throws Exception {
LatLng latLng = new LatLng();
PointF pointF = new PointF();
Projection projection = mock(Projection.class);
when(projection.fromScreenLocation(pointF)).thenReturn(latLng);
MapGestureDetector mapGestureDetector = new MapGestureDetector(null,
null, projection, null, null, null, null);
MapboxMap.OnFlingListener listener = mock(MapboxMap.OnFlingListener.class);
mapGestureDetector.addOnFlingListener(listener);
mapGestureDetector.notifyOnFlingListeners();
@@ -75,14 +71,6 @@ public class MapTouchListenersTest {
@Test
public void onScrollListenerTest() throws Exception {
LatLng latLng = new LatLng();
PointF pointF = new PointF();
Projection projection = mock(Projection.class);
when(projection.fromScreenLocation(pointF)).thenReturn(latLng);
MapGestureDetector mapGestureDetector = new MapGestureDetector(null,
null, projection, null, null, null, null);
MapboxMap.OnScrollListener listener = mock(MapboxMap.OnScrollListener.class);
mapGestureDetector.addOnScrollListener(listener);
mapGestureDetector.notifyOnScrollListeners();
@@ -92,4 +80,88 @@ public class MapTouchListenersTest {
mapGestureDetector.notifyOnScrollListeners();
verify(listener, times(1)).onScroll();
}
@Test
public void onMoveListenerTest() throws Exception {
MapboxMap.OnMoveListener listener = mock(MapboxMap.OnMoveListener.class);
MoveGestureDetector detector = mock(MoveGestureDetector.class);
mapGestureDetector.addOnMoveListener(listener);
mapGestureDetector.notifyOnMoveBeginListeners(detector);
mapGestureDetector.notifyOnMoveListeners(detector);
mapGestureDetector.notifyOnMoveEndListeners(detector);
verify(listener, times(1)).onMoveBegin(detector);
verify(listener, times(1)).onMove(detector);
verify(listener, times(1)).onMoveEnd(detector);
mapGestureDetector.removeOnMoveListener(listener);
mapGestureDetector.notifyOnMoveBeginListeners(detector);
mapGestureDetector.notifyOnMoveListeners(detector);
mapGestureDetector.notifyOnMoveEndListeners(detector);
verify(listener, times(1)).onMoveBegin(detector);
verify(listener, times(1)).onMove(detector);
verify(listener, times(1)).onMoveEnd(detector);
}
@Test
public void onRotateListenerTest() throws Exception {
MapboxMap.OnRotateListener listener = mock(MapboxMap.OnRotateListener.class);
RotateGestureDetector detector = mock(RotateGestureDetector.class);
mapGestureDetector.addOnRotateListener(listener);
mapGestureDetector.notifyOnRotateBeginListeners(detector);
mapGestureDetector.notifyOnRotateListeners(detector);
mapGestureDetector.notifyOnRotateEndListeners(detector);
verify(listener, times(1)).onRotateBegin(detector);
verify(listener, times(1)).onRotate(detector);
verify(listener, times(1)).onRotateEnd(detector);
mapGestureDetector.removeOnRotateListener(listener);
mapGestureDetector.notifyOnRotateBeginListeners(detector);
mapGestureDetector.notifyOnRotateListeners(detector);
mapGestureDetector.notifyOnRotateEndListeners(detector);
verify(listener, times(1)).onRotateBegin(detector);
verify(listener, times(1)).onRotate(detector);
verify(listener, times(1)).onRotateEnd(detector);
}
@Test
public void onScaleListenerTest() throws Exception {
MapboxMap.OnScaleListener listener = mock(MapboxMap.OnScaleListener.class);
StandardScaleGestureDetector detector = mock(StandardScaleGestureDetector.class);
mapGestureDetector.addOnScaleListener(listener);
mapGestureDetector.notifyOnScaleBeginListeners(detector);
mapGestureDetector.notifyOnScaleListeners(detector);
mapGestureDetector.notifyOnScaleEndListeners(detector);
verify(listener, times(1)).onScaleBegin(detector);
verify(listener, times(1)).onScale(detector);
verify(listener, times(1)).onScaleEnd(detector);
mapGestureDetector.removeOnScaleListener(listener);
mapGestureDetector.notifyOnScaleBeginListeners(detector);
mapGestureDetector.notifyOnScaleListeners(detector);
mapGestureDetector.notifyOnScaleEndListeners(detector);
verify(listener, times(1)).onScaleBegin(detector);
verify(listener, times(1)).onScale(detector);
verify(listener, times(1)).onScaleEnd(detector);
}
@Test
public void onShoveListenerTest() throws Exception {
MapboxMap.OnShoveListener listener = mock(MapboxMap.OnShoveListener.class);
ShoveGestureDetector detector = mock(ShoveGestureDetector.class);
mapGestureDetector.addShoveListener(listener);
mapGestureDetector.notifyOnShoveBeginListeners(detector);
mapGestureDetector.notifyOnShoveListeners(detector);
mapGestureDetector.notifyOnShoveEndListeners(detector);
verify(listener, times(1)).onShoveBegin(detector);
verify(listener, times(1)).onShove(detector);
verify(listener, times(1)).onShoveEnd(detector);
mapGestureDetector.removeShoveListener(listener);
mapGestureDetector.notifyOnShoveBeginListeners(detector);
mapGestureDetector.notifyOnShoveListeners(detector);
mapGestureDetector.notifyOnShoveEndListeners(detector);
verify(listener, times(1)).onShoveBegin(detector);
verify(listener, times(1)).onShove(detector);
verify(listener, times(1)).onShoveEnd(detector);
}
}

View File

@@ -23,7 +23,7 @@ public class MapboxMapTest {
mock(TrackingSettings.class),
mock(MyLocationViewSettings.class),
mock(Projection.class),
mock(MapboxMap.OnRegisterTouchListener.class),
mock(MapboxMap.OnGesturesManagerInteractionListener.class),
mock(AnnotationManager.class),
mock(CameraChangeDispatcher.class));
}