diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index 1d5fe1bac8..4373b697e9 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -69,7 +69,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi private float[] calculations = new float[2]; private final RenderingLineAttributes lineAttrs = new RenderingLineAttributes("measureDistanceLine"); - private final RenderingLineAttributes textAttrs = new RenderingLineAttributes("rulerCircle"); + private final RenderingLineAttributes textAttrs = new RenderingLineAttributes("rulerLineFont"); private Paint paint; private Path path; private List route = new ArrayList<>(); @@ -77,7 +77,6 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi private TIntArrayList tx = new TIntArrayList(); private TIntArrayList ty = new TIntArrayList(); private Path linePath = new Path(); - private String distanceText; private ContextMenuLayer contextMenuLayer; @@ -141,8 +140,8 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi paint.setAlpha(200); float textSize = TEXT_SIZE * map.getResources().getDisplayMetrics().density; + textAttrs.paint.setTextSize(textSize); textAttrs.paint2.setTextSize(textSize); - textAttrs.paint3.setTextSize(textSize); widgetsFactory = new MapMarkersWidgetsFactory(map); @@ -219,25 +218,18 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi } @Override - public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) { - - Location myLoc = map.getMyApplication().getLocationProvider().getLastStaleKnownLocation(); - widgetsFactory.updateInfo(myLoc == null - ? tileBox.getCenterLatLon() : new LatLon(myLoc.getLatitude(), myLoc.getLongitude()), tileBox.getZoom()); + public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) { OsmandSettings settings = map.getMyApplication().getSettings(); - - if (tileBox.getZoom() < 3 || !settings.USE_MAP_MARKERS.get()) { - return; - } - + Location myLoc = map.getMapViewTrackingUtilities().getMyLocation(); MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper(); + List activeMapMarkers = markersHelper.getMapMarkers(); + if (route.size() > 0) { path.reset(); boolean first = true; - Location myLocation = map.getMapViewTrackingUtilities().getMyLocation(); - if (markersHelper.isStartFromMyLocation() && myLocation != null) { - int locationX = tileBox.getPixXFromLonNoRot(myLocation.getLongitude()); - int locationY = tileBox.getPixYFromLatNoRot(myLocation.getLatitude()); + if (markersHelper.isStartFromMyLocation() && myLoc != null) { + int locationX = tileBox.getPixXFromLonNoRot(myLoc.getLongitude()); + int locationY = tileBox.getPixYFromLatNoRot(myLoc.getLatitude()); path.moveTo(locationX, locationY); first = false; } @@ -254,12 +246,10 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi canvas.drawPath(path, paint); } - List activeMapMarkers = markersHelper.getMapMarkers(); - if (settings.SHOW_LINES_TO_FIRST_MARKERS.get() && myLoc != null) { lineAttrs.updatePaints(view, nightMode, tileBox); textAttrs.updatePaints(view, nightMode, tileBox); - textAttrs.paint2.setStyle(Paint.Style.FILL); + textAttrs.paint.setStyle(Paint.Style.FILL); int locX = (int) tileBox.getPixXFromLatLon(myLoc.getLatitude(), myLoc.getLongitude()); int locY = (int) tileBox.getPixYFromLatLon(myLoc.getLatitude(), myLoc.getLongitude()); @@ -286,6 +276,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi float generalDist = (float) MapUtils.getDistance(myLoc.getLatitude(), myLoc.getLongitude(), marker.getLatitude(), marker.getLongitude()); String generalDistSt = OsmAndFormatter.getFormattedDistance(generalDist, view.getApplication()); boolean locationInvisible = locX < 0 || locX > tileBox.getPixWidth() || locY < 0 || locY > tileBox.getPixHeight(); + String distanceText; if (locationInvisible) { float centerToMarkerDist = (float) MapUtils.getDistance(tileBox.getLatLonFromPixel(pos[0], pos[1]), marker.getLatitude(), marker.getLongitude()); String centerToMarkerDistSt = OsmAndFormatter.getFormattedDistance(centerToMarkerDist, view.getApplication()); @@ -298,7 +289,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi distanceText = generalDistSt; } Rect bounds = new Rect(); - textAttrs.paint2.getTextBounds(distanceText, 0, distanceText.length(), bounds); + textAttrs.paint.getTextBounds(distanceText, 0, distanceText.length(), bounds); float hOffset = pm.getLength() / 2 - bounds.width() / 2; lineAttrs.paint.setColor(colors[marker.colorIndex]); @@ -309,18 +300,32 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi } if (locX >= markerX) { canvas.rotate(180, pos[0], pos[1]); - canvas.drawTextOnPath(distanceText, linePath, hOffset, bounds.height() + VERTICAL_OFFSET, textAttrs.paint3); canvas.drawTextOnPath(distanceText, linePath, hOffset, bounds.height() + VERTICAL_OFFSET, textAttrs.paint2); + canvas.drawTextOnPath(distanceText, linePath, hOffset, bounds.height() + VERTICAL_OFFSET, textAttrs.paint); canvas.rotate(-180, pos[0], pos[1]); } else { - canvas.drawTextOnPath(distanceText, linePath, hOffset, -VERTICAL_OFFSET, textAttrs.paint3); canvas.drawTextOnPath(distanceText, linePath, hOffset, -VERTICAL_OFFSET, textAttrs.paint2); + canvas.drawTextOnPath(distanceText, linePath, hOffset, -VERTICAL_OFFSET, textAttrs.paint); } canvas.rotate(tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); } } + } - for (MapMarker marker : activeMapMarkers) { + @Override + public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) { + Location myLoc = map.getMyApplication().getLocationProvider().getLastStaleKnownLocation(); + widgetsFactory.updateInfo(myLoc == null + ? tileBox.getCenterLatLon() : new LatLon(myLoc.getLatitude(), myLoc.getLongitude()), tileBox.getZoom()); + OsmandSettings settings = map.getMyApplication().getSettings(); + + if (tileBox.getZoom() < 3 || !settings.USE_MAP_MARKERS.get()) { + return; + } + + MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper(); + + for (MapMarker marker : markersHelper.getMapMarkers()) { if (isLocationVisible(tileBox, marker) && !overlappedByWaypoint(marker) && !isInMotion(marker)) { Bitmap bmp = getMapMarkerBitmap(marker.colorIndex); @@ -336,9 +341,8 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi if (settings.SHOW_ARROWS_TO_FIRST_MARKERS.get()) { LatLon loc = tileBox.getCenterLatLon(); - List mapMarkers = markersHelper.getMapMarkers(); int i = 0; - for (MapMarker marker : mapMarkers) { + for (MapMarker marker : markersHelper.getMapMarkers()) { if (!isLocationVisible(tileBox, marker) && !isInMotion(marker)) { canvas.save(); net.osmand.Location.distanceBetween(loc.getLatitude(), loc.getLongitude(), diff --git a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java index d605728a18..583d5d42db 100644 --- a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java @@ -76,10 +76,9 @@ public class RulerControlLayer extends OsmandMapLayer { private Bitmap centerIconNight; private Paint bitmapPaint; private RenderingLineAttributes lineAttrs; + private RenderingLineAttributes lineFontAttrs; private RenderingLineAttributes circleAttrs; private RenderingLineAttributes circleAttrsAlt; - private float circleTextSize; - private float lineTextSize; private Handler handler; @@ -122,8 +121,12 @@ public class RulerControlLayer extends OsmandMapLayer { lineAttrs = new RenderingLineAttributes("rulerLine"); - circleTextSize = TEXT_SIZE * mapActivity.getResources().getDisplayMetrics().density; - lineTextSize = DISTANCE_TEXT_SIZE * mapActivity.getResources().getDisplayMetrics().density; + float circleTextSize = TEXT_SIZE * mapActivity.getResources().getDisplayMetrics().density; + float lineTextSize = DISTANCE_TEXT_SIZE * mapActivity.getResources().getDisplayMetrics().density; + + lineFontAttrs = new RenderingLineAttributes("rulerLineFont"); + lineFontAttrs.paint.setTextSize(lineTextSize); + lineFontAttrs.paint2.setTextSize(lineTextSize); circleAttrs = new RenderingLineAttributes("rulerCircle"); circleAttrs.paint2.setTextSize(circleTextSize); @@ -179,6 +182,8 @@ public class RulerControlLayer extends OsmandMapLayer { public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) { if (rulerModeOn()) { lineAttrs.updatePaints(view, settings, tb); + lineFontAttrs.updatePaints(view, settings, tb); + lineFontAttrs.paint.setStyle(Style.FILL); circleAttrs.updatePaints(view, settings, tb); circleAttrs.paint2.setStyle(Style.FILL); circleAttrsAlt.updatePaints(view, settings, tb); @@ -221,14 +226,7 @@ public class RulerControlLayer extends OsmandMapLayer { } if (mode == RulerMode.FIRST || mode == RulerMode.SECOND) { updateData(tb, center); - RenderingLineAttributes attrs; - if (mode == RulerMode.FIRST) { - circleAttrs.paint2.setTextSize(circleTextSize); - circleAttrs.paint3.setTextSize(circleTextSize); - attrs = circleAttrs; - } else { - attrs = circleAttrsAlt; - } + RenderingLineAttributes attrs = mode == RulerMode.FIRST ? circleAttrs : circleAttrsAlt; for (int i = 1; i <= cacheDistances.size(); i++) { drawCircle(canvas, tb, i, center, attrs); } @@ -268,22 +266,19 @@ public class RulerControlLayer extends OsmandMapLayer { private void drawTextOnCenterOfPath(Canvas canvas, float x1, float x2, Path path, String text) { PathMeasure pm = new PathMeasure(path, false); Rect bounds = new Rect(); - circleAttrs.paint2.getTextBounds(text, 0, text.length(), bounds); + lineFontAttrs.paint.getTextBounds(text, 0, text.length(), bounds); float hOffset = pm.getLength() / 2 - bounds.width() / 2; - circleAttrs.paint2.setTextSize(lineTextSize); - circleAttrs.paint3.setTextSize(lineTextSize); - if (x1 >= x2) { float[] pos = new float[2]; pm.getPosTan(pm.getLength() / 2, pos, null); canvas.rotate(180, pos[0], pos[1]); - canvas.drawTextOnPath(text, path, hOffset, bounds.height() + VERTICAL_OFFSET, circleAttrs.paint3); - canvas.drawTextOnPath(text, path, hOffset, bounds.height() + VERTICAL_OFFSET, circleAttrs.paint2); + canvas.drawTextOnPath(text, path, hOffset, bounds.height() + VERTICAL_OFFSET, lineFontAttrs.paint2); + canvas.drawTextOnPath(text, path, hOffset, bounds.height() + VERTICAL_OFFSET, lineFontAttrs.paint); canvas.rotate(-180, pos[0], pos[1]); } else { - canvas.drawTextOnPath(text, path, hOffset, -VERTICAL_OFFSET, circleAttrs.paint3); - canvas.drawTextOnPath(text, path, hOffset, -VERTICAL_OFFSET, circleAttrs.paint2); + canvas.drawTextOnPath(text, path, hOffset, -VERTICAL_OFFSET, lineFontAttrs.paint2); + canvas.drawTextOnPath(text, path, hOffset, -VERTICAL_OFFSET, lineFontAttrs.paint); } }