Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] #2805 - basic tilt gesture working with ShoveGestureListener
Browse files Browse the repository at this point in the history
  • Loading branch information
zugaldia authored and bleege committed Dec 3, 2015
1 parent 02feddb commit d40d8e0
Showing 1 changed file with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2884,19 +2884,63 @@ public boolean onRotate(RotateGestureDetector detector) {
// 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;
}
}

Expand Down

0 comments on commit d40d8e0

Please sign in to comment.