Improving double tap and double tap scale gesture recognition.

This commit is contained in:
GaidamakUA 2016-06-08 17:42:56 +03:00
parent 52d98989e6
commit 3d66b5bf22
2 changed files with 33 additions and 25 deletions

View file

@ -56,13 +56,18 @@ public class DoubleTapScaleDetector {
}
long currentTime = System.currentTimeMillis();
if (event.getAction() == MotionEvent.ACTION_UP) {
secondDown = null;
if (isDoubleTapping) {
secondDown = null;
isDoubleTapping = false;
listener.onZoomEnded(scale);
return true;
} else {
if (secondDown != null &&
calculateSqaredDistance(secondDown, event) < mDoubleTapSlopSquare) {
listener.onDoubleTap(event);
}
firstUp = MotionEvent.obtain(event);
secondDown = null;
}
} else {
if (event.getAction() == MotionEvent.ACTION_DOWN && !isDoubleTapping) {
@ -111,17 +116,18 @@ public class DoubleTapScaleDetector {
return false;
}
int deltaXDown = (int) firstDown.getX() - (int) secondDown.getX();
int deltaYDown = (int) firstDown.getY() - (int) secondDown.getY();
int squaredDown = deltaXDown * deltaXDown + deltaYDown * deltaYDown;
int deltaXUp = (int) firstUp.getX() - (int) secondDown.getX();
int deltaYUp = (int) firstUp.getY() - (int) secondDown.getY();
int squaredUp = deltaXUp * deltaXUp + deltaYUp * deltaYUp;
int squaredDown = calculateSqaredDistance(firstDown, secondDown);
int squaredUp = calculateSqaredDistance(firstUp, secondDown);
return squaredDown < mDoubleTapSlopSquare && squaredUp < mDoubleTapSlopSquare;
}
private static int calculateSqaredDistance(MotionEvent first,
MotionEvent second) {
int deltaXDown = (int) first.getX() - (int) second.getX();
int deltaYDown = (int) first.getY() - (int) second.getY();
return deltaXDown * deltaXDown + deltaYDown * deltaYDown;
}
private static final boolean isConfirmedScale(MotionEvent secondDown,
MotionEvent moveEvent) {
if (secondDown == null || moveEvent == null) {
@ -146,5 +152,7 @@ public class DoubleTapScaleDetector {
void onZoomEnded(double relativeToStart);
void onGestureInit(float x1, float y1, float x2, float y2);
boolean onDoubleTap(MotionEvent e);
}
}

View file

@ -978,6 +978,22 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
changeZoomPosition((float) dz, 0);
}
@Override
public boolean onDoubleTap(MotionEvent e) {
LOG.debug("onDoubleTap getZoom()");
if (!doubleTapScaleDetector.isInZoomMode()) {
if (isZoomingAllowed(getZoom(), 1.1f)) {
final RotatedTileBox tb = getCurrentRotatedTileBox();
final double lat = tb.getLatFromPixel(e.getX(), e.getY());
final double lon = tb.getLonFromPixel(e.getX(), e.getY());
getAnimatedDraggingThread().startMoving(lat, lon, getZoom() + 1, true);
}
return true;
} else {
return false;
}
}
private void changeZoomPosition(float dz, float angle) {
final QuadPoint cp = initialViewport.getCenterPixelPoint();
float dx = cp.x - initialMultiTouchCenterPoint.x;
@ -1092,22 +1108,6 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
}
return false;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
LOG.debug("onDoubleTap getZoom()");
if (!doubleTapScaleDetector.isInZoomMode()) {
if (isZoomingAllowed(getZoom(), 1.1f)) {
final RotatedTileBox tb = getCurrentRotatedTileBox();
final double lat = tb.getLatFromPixel(e.getX(), e.getY());
final double lon = tb.getLonFromPixel(e.getX(), e.getY());
getAnimatedDraggingThread().startMoving(lat, lon, getZoom() + 1, true);
}
return true;
} else {
return false;
}
}
}
public Resources getResources() {