From a8aa190b7e8d8ad6eaec8f6ede014290df1bcb01 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 8 Jun 2017 18:29:11 +0300 Subject: [PATCH] Fix the number of circles and maximum radius --- OsmAnd/res/values/sizes.xml | 3 +- .../osmand/plus/views/RulerControlLayer.java | 33 +++++++++++++------ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index 3c369069ef..500b0e4f8b 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -65,7 +65,8 @@ 52dp 44dp 5dp - + + 100dp 120dp 9dp 78dp diff --git a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java index 86f73523e2..c3ccda1f92 100644 --- a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java @@ -9,6 +9,7 @@ import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.Rect; import android.text.TextPaint; +import android.util.DisplayMetrics; import net.osmand.Location; import net.osmand.data.QuadPoint; @@ -20,6 +21,8 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; +import java.util.ArrayList; + public class RulerControlLayer extends OsmandMapLayer { private static final int TEXT_SIZE = 14; @@ -29,9 +32,10 @@ public class RulerControlLayer extends OsmandMapLayer { private int maxRadius; private int radius; private int cacheZoom; + private int halfMaxSide; private double cacheTileX; private double cacheTileY; - private String[] cacheDistances; + private ArrayList cacheDistances; private Bitmap centerIcon; private Paint bitmapPaint; private Paint distancePaint; @@ -47,11 +51,17 @@ public class RulerControlLayer extends OsmandMapLayer { public void initLayer(OsmandMapTileView view) { app = mapActivity.getMyApplication(); portrait = AndroidUiHelper.isOrientationPortrait(mapActivity); - cacheDistances = new String[3]; - maxRadius = mapActivity.getResources().getDimensionPixelSize(R.dimen.map_ruler_width); + cacheDistances = new ArrayList<>(); + maxRadius = mapActivity.getResources().getDimensionPixelSize(R.dimen.map_ruler_radius); centerIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_ruler_center); + DisplayMetrics displayMetrics = new DisplayMetrics(); + mapActivity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); + int height = displayMetrics.heightPixels; + int width = displayMetrics.widthPixels; + halfMaxSide = (int) ((width > height ? width : height) / 2.2); + bitmapPaint = new Paint(); bitmapPaint.setAntiAlias(true); bitmapPaint.setDither(true); @@ -93,7 +103,8 @@ public class RulerControlLayer extends OsmandMapLayer { drawDistance(canvas, tb, center, currentLoc); } } else if (mode == RulerMode.SECOND) { - for (int i = 1; i < 4; i++) { + updateData(tb); + for (int i = 1; i <= cacheDistances.size(); i++) { drawCircle(canvas, tb, i, center); } } @@ -114,10 +125,8 @@ public class RulerControlLayer extends OsmandMapLayer { } private void drawCircle(Canvas canvas, RotatedTileBox tb, int circleNumber, QuadPoint center) { - updateData(tb); - Rect bounds = new Rect(); - String text = cacheDistances[circleNumber - 1]; + String text = cacheDistances.get(circleNumber - 1); textPaint.getTextBounds(text, 0, text.length(), bounds); float left; @@ -149,6 +158,7 @@ public class RulerControlLayer extends OsmandMapLayer { cacheZoom = tb.getZoom(); cacheTileX = tb.getCenterTileX(); cacheTileY = tb.getCenterTileY(); + cacheDistances.clear(); final double dist = tb.getDistance(0, tb.getPixHeight() / 2, tb.getPixWidth(), tb.getPixHeight() / 2); double pixDensity = tb.getPixWidth() / dist; @@ -156,9 +166,12 @@ public class RulerControlLayer extends OsmandMapLayer { OsmAndFormatter.calculateRoundedDist(maxRadius / pixDensity, app); radius = (int) (pixDensity * roundedDist); - for (int i = 0; i < 3; i++) { - cacheDistances[i] = OsmAndFormatter.getFormattedDistance((float) roundedDist * (i + 1), - app, false).replaceAll(" ", ""); + int halfSide = halfMaxSide; + int i = 1; + + while ((halfSide -= radius) > 0) { + cacheDistances.add(OsmAndFormatter.getFormattedDistance((float) roundedDist * i++, + app, false).replaceAll(" ", "")); } } }