diff --git a/OsmAnd/src/net/osmand/plus/views/DoubleTapScaleDetector.java b/OsmAnd/src/net/osmand/plus/views/DoubleTapScaleDetector.java index 1d4399c5f6..47b0d34622 100644 --- a/OsmAnd/src/net/osmand/plus/views/DoubleTapScaleDetector.java +++ b/OsmAnd/src/net/osmand/plus/views/DoubleTapScaleDetector.java @@ -53,7 +53,7 @@ public class DoubleTapScaleDetector { } public boolean onTouchEvent(MotionEvent event) { - if (event.getPointerCount() != 1) { + if (event.getPointerCount() != 1 || !view.mapGestureAllowed(OsmandMapLayer.MapGestureType.DOUBLE_TAP_ZOOM_CHANGE)) { resetEvents(); mIsDoubleTapping = false; mScrolling = false; diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java index 61adf47196..313638f195 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java @@ -1,24 +1,5 @@ package net.osmand.plus.views; -import gnu.trove.list.array.TIntArrayList; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import net.osmand.data.LatLon; -import net.osmand.data.QuadRect; -import net.osmand.data.QuadTree; -import net.osmand.data.RotatedTileBox; -import net.osmand.plus.ContextMenuAdapter; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.render.OsmandRenderer; -import net.osmand.plus.render.OsmandRenderer.RenderingContext; -import net.osmand.render.RenderingRuleSearchRequest; -import net.osmand.render.RenderingRulesStorage; -import net.osmand.util.MapAlgorithms; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; @@ -34,11 +15,41 @@ import android.os.AsyncTask; import android.support.annotation.NonNull; import android.view.MotionEvent; +import net.osmand.data.LatLon; +import net.osmand.data.QuadRect; +import net.osmand.data.QuadTree; +import net.osmand.data.RotatedTileBox; +import net.osmand.plus.ContextMenuAdapter; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.render.OsmandRenderer; +import net.osmand.plus.render.OsmandRenderer.RenderingContext; +import net.osmand.render.RenderingRuleSearchRequest; +import net.osmand.render.RenderingRulesStorage; +import net.osmand.util.MapAlgorithms; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import gnu.trove.list.array.TIntArrayList; + public abstract class OsmandMapLayer { protected List fullObjectsLatLon; protected List smallObjectsLatLon; + public enum MapGestureType { + DOUBLE_TAP_ZOOM_IN, + DOUBLE_TAP_ZOOM_CHANGE, + TWO_POINTERS_ZOOM_OUT + } + + public boolean isMapGestureAllowed(MapGestureType type) { + return true; + } + public abstract void initLayer(OsmandMapTileView view); public abstract void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings); diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 0f670da124..3b2dede705 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -226,6 +226,9 @@ public class OsmandMapTileView implements IMapDownloaderCallback { @Override public void onTwoFingerTap() { //afterTwoFingersTap = true; + if (!mapGestureAllowed(OsmandMapLayer.MapGestureType.TWO_POINTERS_ZOOM_OUT)) { + return; + } if (isZoomingAllowed(getZoom(), -1.1f)) { getAnimatedDraggingThread().startZooming(getZoom() - 1, currentViewport.getZoomFloatPart(), false); if (wasMapLinkedBeforeGesture) { @@ -335,6 +338,15 @@ public class OsmandMapTileView implements IMapDownloaderCallback { this.wasZoomInMultiTouch = wasZoomInMultiTouch; } + public boolean mapGestureAllowed(OsmandMapLayer.MapGestureType type) { + for (OsmandMapLayer layer : layers) { + if (!layer.isMapGestureAllowed(type)) { + return false; + } + } + return true; + } + public void setIntZoom(int zoom) { zoom = zoom > getMaxZoom() ? getMaxZoom() : zoom; zoom = zoom < getMinZoom() ? getMinZoom() : zoom; diff --git a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java index f9e620d346..50c809972d 100644 --- a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java @@ -108,10 +108,18 @@ public class RulerControlLayer extends OsmandMapLayer { }; } + @Override + public boolean isMapGestureAllowed(MapGestureType type) { + if (rulerModeOn() && type == MapGestureType.TWO_POINTERS_ZOOM_OUT) { + return false; + } else { + return true; + } + } + @Override public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) { - if (mapActivity.getMapLayers().getMapWidgetRegistry().isVisible("ruler") && - rightWidgetsPanel.getVisibility() == View.VISIBLE) { + if (rulerModeOn()) { lineAttrs.updatePaints(view, settings, tb); circleAttrs.updatePaints(view, settings, tb); circleAttrs.paint2.setStyle(Style.FILL); @@ -150,6 +158,11 @@ public class RulerControlLayer extends OsmandMapLayer { } } + private boolean rulerModeOn() { + return mapActivity.getMapLayers().getMapWidgetRegistry().isVisible("ruler") && + rightWidgetsPanel.getVisibility() == View.VISIBLE; + } + public void refreshMapDelayed() { handler.sendEmptyMessageDelayed(0, DELAY + 50); } @@ -208,7 +221,7 @@ public class RulerControlLayer extends OsmandMapLayer { boolean move = tb.getZoom() != cacheIntZoom || Math.abs(tb.getCenterTileX() - cacheTileX) > 1 || Math.abs(tb.getCenterTileY() - cacheTileY) > 1; - if (!mapActivity.getMapView().isZooming() && move) { + if (!tb.isZoomAnimated() && move) { cacheIntZoom = tb.getZoom(); cacheTileX = tb.getCenterTileX(); cacheTileY = tb.getCenterTileY(); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java index ab47bd1c0f..b7841bbd13 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java @@ -207,8 +207,12 @@ public class MapInfoWidgetsFactory { LatLon centerLoc = map.getMapLocation(); if (currentLoc != null && centerLoc != null) { - setDistanceText(currentLoc.getLatitude(), currentLoc.getLongitude(), - centerLoc.getLatitude(), centerLoc.getLongitude()); + if (map.getMapViewTrackingUtilities().isMapLinkedToLocation()) { + setDistanceText(0); + } else { + setDistanceText(currentLoc.getLatitude(), currentLoc.getLongitude(), + centerLoc.getLatitude(), centerLoc.getLongitude()); + } } } else { setText(title, null); @@ -216,13 +220,21 @@ public class MapInfoWidgetsFactory { return true; } - private void setDistanceText(double firstLat, double firstLon, double secondLat, double secondLon) { - float dist = (float) MapUtils.getDistance(firstLat, firstLon, secondLat, secondLon); - String distance = OsmAndFormatter.getFormattedDistance(dist, map.getMyApplication()); - int ls = distance.lastIndexOf(' '); - setText(distance.substring(0, ls), distance.substring(ls + 1)); - } - }; + private void setDistanceText(float dist) { + calculateAndSetText(dist); + } + + private void setDistanceText(double firstLat, double firstLon, double secondLat, double secondLon) { + float dist = (float) MapUtils.getDistance(firstLat, firstLon, secondLat, secondLon); + calculateAndSetText(dist); + } + + private void calculateAndSetText(float dist) { + String distance = OsmAndFormatter.getFormattedDistance(dist, map.getMyApplication()); + int ls = distance.lastIndexOf(' '); + setText(distance.substring(0, ls), distance.substring(ls + 1)); + } + }; rulerControl.setText(title, null); setRulerControlIcon(rulerControl, map.getMyApplication().getSettings().RULER_MODE.get());