Improvement of doubletap scale gesture.

This commit is contained in:
GaidamakUA 2016-01-27 16:40:22 +02:00
parent 93f6c7f00e
commit a56535ee99

View file

@ -73,6 +73,9 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
private OsmandApplication application;
protected OsmandSettings settings = null;
private int maxZoom;
private int minZoom;
private class FPSMeasurement {
int fpsMeasureCount = 0;
int fpsMeasureMs = 0;
@ -167,8 +170,10 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
@Override
public void onTwoFingerTap() {
afterTwoFingerTap = true;
if (isZoomingAllowed(getZoom(), -1)) {
getAnimatedDraggingThread().startZooming(getZoom() - 1, currentViewport.getZoomFloatPart(), true);
}
}
};
private int displayHeightPx;
@ -301,7 +306,9 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
// ///////////////////////// NON UI PART (could be extracted in common) /////////////////////////////
public void setIntZoom(int zoom) {
if (mainLayer != null && zoom <= mainLayer.getMaximumShownMapZoom() && zoom >= mainLayer.getMinimumShownMapZoom()) {
zoom = zoom > maxZoom ? maxZoom : zoom;
zoom = zoom < minZoom ? minZoom : zoom;
if (mainLayer != null) {
animatedDraggingThread.stopAnimating();
currentViewport.setZoomAndAnimation(zoom, 0, 0);
currentViewport.setRotate(zoom > LOWEST_ZOOM_TO_ROTATE ? rotate : 0);
@ -310,7 +317,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
}
public void setComplexZoom(int zoom, double mapDensity) {
if (mainLayer != null && zoom <= mainLayer.getMaximumShownMapZoom() && zoom >= mainLayer.getMinimumShownMapZoom()) {
if (mainLayer != null && zoom <= maxZoom && zoom >= minZoom) {
animatedDraggingThread.stopAnimating();
currentViewport.setZoomAndAnimation(zoom, 0);
currentViewport.setMapDensity(mapDensity);
@ -396,11 +403,13 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
public void setMainLayer(BaseMapLayer mainLayer) {
this.mainLayer = mainLayer;
int zoom = currentViewport.getZoom();
if (mainLayer.getMaximumShownMapZoom() < zoom) {
zoom = mainLayer.getMaximumShownMapZoom();
maxZoom = mainLayer.getMaximumShownMapZoom() - 1;
minZoom = mainLayer.getMinimumShownMapZoom() + 1;
if (maxZoom < zoom) {
zoom = maxZoom;
}
if (mainLayer.getMinimumShownMapZoom() > zoom) {
zoom = mainLayer.getMinimumShownMapZoom();
if (minZoom > zoom) {
zoom = minZoom;
}
currentViewport.setZoomAndAnimation(zoom, 0, 0);
refreshMap();
@ -736,7 +745,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
// for internal usage
protected void zoomToAnimate(int zoom, double zoomToAnimate, boolean notify) {
if (mainLayer != null && mainLayer.getMaximumShownMapZoom() >= zoom && mainLayer.getMinimumShownMapZoom() <= zoom) {
if (mainLayer != null && maxZoom >= zoom && minZoom <= zoom) {
currentViewport.setZoomAndAnimation(zoom, zoomToAnimate);
currentViewport.setRotate(zoom > LOWEST_ZOOM_TO_ROTATE ? rotate : 0);
refreshMap();
@ -952,17 +961,16 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
final LatLon r = calc.getLatLonFromPixel(cp.x + dx, cp.y + dy);
setLatLon(r.getLatitude(), r.getLongitude());
int baseZoom = initialViewport.getZoom();
while (initialViewport.getZoomFloatPart() + dz > 1) {
while (initialViewport.getZoomFloatPart() + dz > 1 && isZoomingAllowed(baseZoom, dz)) {
dz--;
if (baseZoom < mainLayer.getMaximumShownMapZoom()) {
baseZoom++;
}
}
while (initialViewport.getZoomFloatPart() + dz < 0) {
while (initialViewport.getZoomFloatPart() + dz < 0 && isZoomingAllowed(baseZoom, dz)) {
dz++;
if (baseZoom > mainLayer.getMinimumShownMapZoom()) {
baseZoom--;
}
if (!isZoomingAllowed(baseZoom, dz)) {
dz = 0;
}
zoomToAnimate(baseZoom, dz, true);
rotateToAnimate(calcRotate);
@ -970,6 +978,22 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
}
private boolean isZoomingAllowed(int baseZoom, float dz) {
if (baseZoom > maxZoom) {
return false;
}
if (baseZoom == maxZoom - 2 && dz > 1) {
return false;
}
if (baseZoom < minZoom) {
return false;
}
if (baseZoom == minZoom + 2 && dz < -1) {
return false;
}
return true;
}
private class MapTileViewOnGestureListener extends SimpleOnGestureListener {
@Override
public boolean onDown(MotionEvent e) {
@ -1040,10 +1064,12 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
@Override
public boolean onDoubleTap(MotionEvent e) {
if (isZoomingAllowed(getZoom(), 1)) {
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;
}
}