From 24d4109dc1c5465114ce80ef1bb7cfd2f6b4a62e Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 3 Jul 2017 11:40:04 +0300 Subject: [PATCH 1/5] Fix inaccuracy in the display of circles after zoom; fix the calculation of the distance if the map is tied to the location --- .../osmand/plus/views/RulerControlLayer.java | 2 +- .../mapwidgets/MapInfoWidgetsFactory.java | 30 +++++++++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java index f9e620d346..f967df10bb 100644 --- a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java @@ -208,7 +208,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()); From e8b2f594ba72cdcd5160cbd052aa6b9fa887d124 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 3 Jul 2017 13:29:19 +0300 Subject: [PATCH 2/5] Disable two pointers zoom out in ruler mode --- .../net/osmand/plus/views/OsmandMapLayer.java | 49 ++++++++++++------- .../osmand/plus/views/OsmandMapTileView.java | 20 ++++++++ .../osmand/plus/views/RulerControlLayer.java | 13 +++++ 3 files changed, 63 insertions(+), 19 deletions(-) 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..712f26d0c8 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -227,6 +227,11 @@ public class OsmandMapTileView implements IMapDownloaderCallback { public void onTwoFingerTap() { //afterTwoFingersTap = true; if (isZoomingAllowed(getZoom(), -1.1f)) { + for (OsmandMapLayer layer : layers) { + if (!layer.isMapGestureAllowed(OsmandMapLayer.MapGestureType.TWO_POINTERS_ZOOM_OUT)) { + return; + } + } getAnimatedDraggingThread().startZooming(getZoom() - 1, currentViewport.getZoomFloatPart(), false); if (wasMapLinkedBeforeGesture) { ctx.getMapViewTrackingUtilities().setMapLinkedToLocation(true); @@ -1015,6 +1020,11 @@ public class OsmandMapTileView implements IMapDownloaderCallback { @Override public void onZoomEnded(double relativeToStart) { + for (OsmandMapLayer layer : layers) { + if (!layer.isMapGestureAllowed(OsmandMapLayer.MapGestureType.DOUBLE_TAP_ZOOM_CHANGE)) { + return; + } + } // 1.5 works better even on dm.density=1 devices float dz = (float) ((relativeToStart - 1) * DoubleTapScaleDetector.SCALE_PER_SCREEN); setIntZoom(Math.round(dz) + initialViewport.getZoom()); @@ -1089,6 +1099,11 @@ public class OsmandMapTileView implements IMapDownloaderCallback { @Override public void onZooming(double relativeToStart) { + for (OsmandMapLayer layer : layers) { + if (!layer.isMapGestureAllowed(OsmandMapLayer.MapGestureType.DOUBLE_TAP_ZOOM_CHANGE)) { + return; + } + } double dz = (relativeToStart - 1) * DoubleTapScaleDetector.SCALE_PER_SCREEN; changeZoomPosition((float) dz, 0); } @@ -1096,6 +1111,11 @@ public class OsmandMapTileView implements IMapDownloaderCallback { @Override public boolean onDoubleTap(MotionEvent e) { LOG.debug("onDoubleTap getZoom()"); + for (OsmandMapLayer layer : layers) { + if (!layer.isMapGestureAllowed(OsmandMapLayer.MapGestureType.DOUBLE_TAP_ZOOM_IN)) { + return false; + } + } if (!doubleTapScaleDetector.isInZoomMode()) { if (isZoomingAllowed(getZoom(), 1.1f)) { final RotatedTileBox tb = getCurrentRotatedTileBox(); diff --git a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java index f967df10bb..f6eed167a5 100644 --- a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java @@ -42,6 +42,7 @@ public class RulerControlLayer extends OsmandMapLayer { private int radius; private double roundedDist; private boolean showTwoFingersDistance; + private boolean twoPointersZoomOutAllowed; private QuadPoint cacheCenter; private int cacheIntZoom; @@ -108,10 +109,20 @@ public class RulerControlLayer extends OsmandMapLayer { }; } + @Override + public boolean isMapGestureAllowed(MapGestureType type) { + if (type != MapGestureType.TWO_POINTERS_ZOOM_OUT) { + return true; + } else { + return twoPointersZoomOutAllowed; + } + } + @Override public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) { if (mapActivity.getMapLayers().getMapWidgetRegistry().isVisible("ruler") && rightWidgetsPanel.getVisibility() == View.VISIBLE) { + twoPointersZoomOutAllowed = false; lineAttrs.updatePaints(view, settings, tb); circleAttrs.updatePaints(view, settings, tb); circleAttrs.paint2.setStyle(Style.FILL); @@ -147,6 +158,8 @@ public class RulerControlLayer extends OsmandMapLayer { drawCircle(canvas, tb, i, center); } } + } else { + twoPointersZoomOutAllowed = true; } } From f6de5a6436b94ff2f413fbac88aa5e84b214a6e4 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 3 Jul 2017 13:52:35 +0300 Subject: [PATCH 3/5] Extract methods --- .../osmand/plus/views/OsmandMapTileView.java | 35 ++++++++++--------- .../osmand/plus/views/RulerControlLayer.java | 18 +++++----- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 712f26d0c8..b8ba1f3af0 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -226,12 +226,10 @@ 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)) { - for (OsmandMapLayer layer : layers) { - if (!layer.isMapGestureAllowed(OsmandMapLayer.MapGestureType.TWO_POINTERS_ZOOM_OUT)) { - return; - } - } getAnimatedDraggingThread().startZooming(getZoom() - 1, currentViewport.getZoomFloatPart(), false); if (wasMapLinkedBeforeGesture) { ctx.getMapViewTrackingUtilities().setMapLinkedToLocation(true); @@ -340,6 +338,15 @@ public class OsmandMapTileView implements IMapDownloaderCallback { this.wasZoomInMultiTouch = wasZoomInMultiTouch; } + private 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; @@ -1020,10 +1027,8 @@ public class OsmandMapTileView implements IMapDownloaderCallback { @Override public void onZoomEnded(double relativeToStart) { - for (OsmandMapLayer layer : layers) { - if (!layer.isMapGestureAllowed(OsmandMapLayer.MapGestureType.DOUBLE_TAP_ZOOM_CHANGE)) { - return; - } + if (!mapGestureAllowed(OsmandMapLayer.MapGestureType.DOUBLE_TAP_ZOOM_CHANGE)) { + return; } // 1.5 works better even on dm.density=1 devices float dz = (float) ((relativeToStart - 1) * DoubleTapScaleDetector.SCALE_PER_SCREEN); @@ -1099,10 +1104,8 @@ public class OsmandMapTileView implements IMapDownloaderCallback { @Override public void onZooming(double relativeToStart) { - for (OsmandMapLayer layer : layers) { - if (!layer.isMapGestureAllowed(OsmandMapLayer.MapGestureType.DOUBLE_TAP_ZOOM_CHANGE)) { - return; - } + if (!mapGestureAllowed(OsmandMapLayer.MapGestureType.DOUBLE_TAP_ZOOM_CHANGE)) { + return; } double dz = (relativeToStart - 1) * DoubleTapScaleDetector.SCALE_PER_SCREEN; changeZoomPosition((float) dz, 0); @@ -1111,10 +1114,8 @@ public class OsmandMapTileView implements IMapDownloaderCallback { @Override public boolean onDoubleTap(MotionEvent e) { LOG.debug("onDoubleTap getZoom()"); - for (OsmandMapLayer layer : layers) { - if (!layer.isMapGestureAllowed(OsmandMapLayer.MapGestureType.DOUBLE_TAP_ZOOM_IN)) { - return false; - } + if (!mapGestureAllowed(OsmandMapLayer.MapGestureType.DOUBLE_TAP_ZOOM_IN)) { + return false; } if (!doubleTapScaleDetector.isInZoomMode()) { if (isZoomingAllowed(getZoom(), 1.1f)) { diff --git a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java index f6eed167a5..50c809972d 100644 --- a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java @@ -42,7 +42,6 @@ public class RulerControlLayer extends OsmandMapLayer { private int radius; private double roundedDist; private boolean showTwoFingersDistance; - private boolean twoPointersZoomOutAllowed; private QuadPoint cacheCenter; private int cacheIntZoom; @@ -111,18 +110,16 @@ public class RulerControlLayer extends OsmandMapLayer { @Override public boolean isMapGestureAllowed(MapGestureType type) { - if (type != MapGestureType.TWO_POINTERS_ZOOM_OUT) { - return true; + if (rulerModeOn() && type == MapGestureType.TWO_POINTERS_ZOOM_OUT) { + return false; } else { - return twoPointersZoomOutAllowed; + return true; } } @Override public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) { - if (mapActivity.getMapLayers().getMapWidgetRegistry().isVisible("ruler") && - rightWidgetsPanel.getVisibility() == View.VISIBLE) { - twoPointersZoomOutAllowed = false; + if (rulerModeOn()) { lineAttrs.updatePaints(view, settings, tb); circleAttrs.updatePaints(view, settings, tb); circleAttrs.paint2.setStyle(Style.FILL); @@ -158,11 +155,14 @@ public class RulerControlLayer extends OsmandMapLayer { drawCircle(canvas, tb, i, center); } } - } else { - twoPointersZoomOutAllowed = true; } } + private boolean rulerModeOn() { + return mapActivity.getMapLayers().getMapWidgetRegistry().isVisible("ruler") && + rightWidgetsPanel.getVisibility() == View.VISIBLE; + } + public void refreshMapDelayed() { handler.sendEmptyMessageDelayed(0, DELAY + 50); } From 0b666b1009084506f22fb566cbce9067d12bc651 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 3 Jul 2017 15:24:46 +0300 Subject: [PATCH 4/5] Add small fixes --- .../src/net/osmand/plus/views/DoubleTapScaleDetector.java | 2 +- OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) 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/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index b8ba1f3af0..5f4f540fe9 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -338,7 +338,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback { this.wasZoomInMultiTouch = wasZoomInMultiTouch; } - private boolean mapGestureAllowed(OsmandMapLayer.MapGestureType type) { + public boolean mapGestureAllowed(OsmandMapLayer.MapGestureType type) { for (OsmandMapLayer layer : layers) { if (!layer.isMapGestureAllowed(type)) { return false; @@ -1027,9 +1027,6 @@ public class OsmandMapTileView implements IMapDownloaderCallback { @Override public void onZoomEnded(double relativeToStart) { - if (!mapGestureAllowed(OsmandMapLayer.MapGestureType.DOUBLE_TAP_ZOOM_CHANGE)) { - return; - } // 1.5 works better even on dm.density=1 devices float dz = (float) ((relativeToStart - 1) * DoubleTapScaleDetector.SCALE_PER_SCREEN); setIntZoom(Math.round(dz) + initialViewport.getZoom()); @@ -1104,9 +1101,6 @@ public class OsmandMapTileView implements IMapDownloaderCallback { @Override public void onZooming(double relativeToStart) { - if (!mapGestureAllowed(OsmandMapLayer.MapGestureType.DOUBLE_TAP_ZOOM_CHANGE)) { - return; - } double dz = (relativeToStart - 1) * DoubleTapScaleDetector.SCALE_PER_SCREEN; changeZoomPosition((float) dz, 0); } From 3165ad688cb2eb6298e877e87d450efb3ceaf945 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 3 Jul 2017 15:34:50 +0300 Subject: [PATCH 5/5] Remove unnecessary method call --- OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 5f4f540fe9..3b2dede705 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -1108,9 +1108,6 @@ public class OsmandMapTileView implements IMapDownloaderCallback { @Override public boolean onDoubleTap(MotionEvent e) { LOG.debug("onDoubleTap getZoom()"); - if (!mapGestureAllowed(OsmandMapLayer.MapGestureType.DOUBLE_TAP_ZOOM_IN)) { - return false; - } if (!doubleTapScaleDetector.isInZoomMode()) { if (isZoomingAllowed(getZoom(), 1.1f)) { final RotatedTileBox tb = getCurrentRotatedTileBox();