summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Paczos <lukasz.paczos@mapbox.com>2018-02-20 17:31:09 +0100
committerŁukasz Paczos <lukasz.paczos@mapbox.com>2018-02-20 17:31:09 +0100
commitb47339ce64bbe3ad92d3d08f3544d036394d4cc0 (patch)
treeb1c035f43954aeca671c732c7019e61b00cc29d7
parent87a3c1d5d071aec54f66ba838702b5937caa47e3 (diff)
downloadqtlocation-mapboxgl-b47339ce64bbe3ad92d3d08f3544d036394d4cc0.tar.gz
[android] new gesture library - notifying new listeners tests
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java72
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java130
2 files changed, 173 insertions, 29 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java
index ab328474a5..595978c4dd 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java
@@ -820,6 +820,78 @@ final class MapGestureDetector {
}
}
+ void notifyOnMoveBeginListeners(MoveGestureDetector detector) {
+ for (MapboxMap.OnMoveListener listener : onMoveListenerList) {
+ listener.onMoveBegin(detector);
+ }
+ }
+
+ void notifyOnMoveListeners(MoveGestureDetector detector) {
+ for (MapboxMap.OnMoveListener listener : onMoveListenerList) {
+ listener.onMove(detector);
+ }
+ }
+
+ void notifyOnMoveEndListeners(MoveGestureDetector detector) {
+ for (MapboxMap.OnMoveListener listener : onMoveListenerList) {
+ listener.onMoveEnd(detector);
+ }
+ }
+
+ void notifyOnRotateBeginListeners(RotateGestureDetector detector) {
+ for (MapboxMap.OnRotateListener listener : onRotateListenerList) {
+ listener.onRotateBegin(detector);
+ }
+ }
+
+ void notifyOnRotateListeners(RotateGestureDetector detector) {
+ for (MapboxMap.OnRotateListener listener : onRotateListenerList) {
+ listener.onRotate(detector);
+ }
+ }
+
+ void notifyOnRotateEndListeners(RotateGestureDetector detector) {
+ for (MapboxMap.OnRotateListener listener : onRotateListenerList) {
+ listener.onRotateEnd(detector);
+ }
+ }
+
+ void notifyOnScaleBeginListeners(StandardScaleGestureDetector detector) {
+ for (MapboxMap.OnScaleListener listener : onScaleListenerList) {
+ listener.onScaleBegin(detector);
+ }
+ }
+
+ void notifyOnScaleListeners(StandardScaleGestureDetector detector) {
+ for (MapboxMap.OnScaleListener listener : onScaleListenerList) {
+ listener.onScale(detector);
+ }
+ }
+
+ void notifyOnScaleEndListeners(StandardScaleGestureDetector detector) {
+ for (MapboxMap.OnScaleListener listener : onScaleListenerList) {
+ listener.onScaleEnd(detector);
+ }
+ }
+
+ void notifyOnShoveBeginListeners(ShoveGestureDetector detector) {
+ for (MapboxMap.OnShoveListener listener : onShoveListenerList) {
+ listener.onShoveBegin(detector);
+ }
+ }
+
+ void notifyOnShoveListeners(ShoveGestureDetector detector) {
+ for (MapboxMap.OnShoveListener listener : onShoveListenerList) {
+ listener.onShove(detector);
+ }
+ }
+
+ void notifyOnShoveEndListeners(ShoveGestureDetector detector) {
+ for (MapboxMap.OnShoveListener listener : onShoveListenerList) {
+ listener.onShoveEnd(detector);
+ }
+ }
+
void setOnMapClickListener(MapboxMap.OnMapClickListener onMapClickListener) {
this.onMapClickListener = onMapClickListener;
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java
index eeb00355bd..d63cbbe295 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java
@@ -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,
+ mapGestureDetector = new MapGestureDetector(null,
null, projection, null, 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);
+ }
}