summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Zugaldia <antonio@mapbox.com>2015-12-03 15:14:30 -0500
committerBrad Leege <bleege@gmail.com>2015-12-03 16:57:44 -0600
commitd40d8e0c59b532470c298c680e46cc604d6d0c33 (patch)
treec44138dbf0b42718df95422069e55d7780cf32ee
parent02feddb816900d025581076bb969c594f527aef8 (diff)
downloadqtlocation-mapboxgl-d40d8e0c59b532470c298c680e46cc604d6d0c33.tar.gz
[android] #2805 - basic tilt gesture working with ShoveGestureListener
-rw-r--r--android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java54
1 files changed, 49 insertions, 5 deletions
diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java
index f15591b4b3..1f6245a390 100644
--- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java
+++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java
@@ -2884,19 +2884,63 @@ public final class MapView extends FrameLayout {
// less than a 20 degree angle between them, this will detect movement on the Y-axis.)
private class ShoveGestureListener implements ShoveGestureDetector.OnShoveGestureListener {
- @Override
- public boolean onShove(ShoveGestureDetector detector) {
- return false;
- }
+ long mBeginTime = 0;
+ float mTotalDelta = 0.0f;
+ boolean mStarted = false;
@Override
public boolean onShoveBegin(ShoveGestureDetector detector) {
- return false;
+ if (!mTiltEnabled) {
+ return false;
+ }
+
+ mBeginTime = detector.getEventTime();
+ return true;
}
@Override
public void onShoveEnd(ShoveGestureDetector detector) {
+ mBeginTime = 0;
+ mTotalDelta = 0.0f;
+ mStarted = false;
+ }
+
+ @Override
+ public boolean onShove(ShoveGestureDetector detector) {
+ if (!mTiltEnabled) {
+ return false;
+ }
+
+ // If rotate is large enough ignore a tap
+ // Also is zoom already started, don't rotate
+ mTotalDelta += detector.getShovePixelsDelta();
+ if (!mZoomStarted && ((mTotalDelta > 10.0f) || (mTotalDelta < -10.0f))) {
+ mStarted = true;
+ }
+
+ // Ignore short touches in case it is a tap
+ // Also ignore small rotate
+ long time = detector.getEventTime();
+ long interval = time - mBeginTime;
+ if (!mStarted && (interval <= ViewConfiguration.getTapTimeout())) {
+ return false;
+ }
+ if (!mStarted) {
+ return false;
+ }
+
+ // Cancel any animation
+ mNativeMapView.cancelTransitions();
+
+ // Get rotate value
+ double pitch = mNativeMapView.getPitch();
+ pitch += detector.getShovePixelsDelta();
+
+ // Tilt the map
+ mNativeMapView.setPitch(pitch);
+
+ return true;
}
}