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