From 4fdffa4e8a2e0253a3da31f6445750192bb3d022 Mon Sep 17 00:00:00 2001 From: Erlend Fagerheim Date: Thu, 13 Aug 2015 13:29:13 +0200 Subject: added click, longclick, scroll, fling events --- .../java/com/mapbox/mapboxgl/views/MapView.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java index 20e7dfe56a..8c9a9f5b87 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java @@ -154,6 +154,24 @@ public class MapView extends FrameLayout implements LocationListener { // Used to manage Event Listeners private ArrayList mOnMapChangedListener; + public interface OnFlingListener { + void onFling(); + } + + public interface OnScrollListener { + void onScroll(); + } + + private OnFlingListener onFlingListener; + private OnScrollListener onScrollListener; + + public void setOnScrollListener(OnScrollListener onScrollListener) { + this.onScrollListener = onScrollListener; + } + + public void setOnFlingListener(OnFlingListener onFlingListener) { + this.onFlingListener = onFlingListener; + } // // Properties @@ -865,6 +883,8 @@ public class MapView extends FrameLayout implements LocationListener { // Cancel any animation mNativeMapView.cancelTransitions(); + performClick(); + return true; } @@ -878,6 +898,7 @@ public class MapView extends FrameLayout implements LocationListener { @Override public void onLongPress(MotionEvent e) { // TODO + performLongClick(); } // Called for flings @@ -905,6 +926,10 @@ public class MapView extends FrameLayout implements LocationListener { mNativeMapView.moveBy(velocityX * duration / 2.0 / mScreenDensity, velocityY * duration / 2.0 / mScreenDensity, (long) (duration * 1000.0f)); + if(onFlingListener != null){ + onFlingListener.onFling(); + } + return true; } @@ -922,6 +947,11 @@ public class MapView extends FrameLayout implements LocationListener { // Scroll the map mNativeMapView.moveBy(-distanceX / mScreenDensity, -distanceY / mScreenDensity); + + if(onScrollListener != null){ + onScrollListener.onScroll(); + } + return true; } } -- cgit v1.2.1