diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesHelper.java b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesHelper.java index 9796a715aa..f570390f97 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesHelper.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesHelper.java @@ -31,40 +31,50 @@ public class LiveUpdatesHelper { public static final int DEFAULT_LAST_CHECK = -1; + private static OsmandSettings.CommonPreference checkPref(OsmandSettings.CommonPreference p) { + if(p.isSet()) { + T vl = p.get(); + p = p.makeGlobal(); + p.set(vl); + } else { + p = p.makeGlobal(); + } + return p; + } public static OsmandSettings.CommonPreference preferenceForLocalIndex( String fileName, OsmandSettings settings) { final String settingId = fileName + LIVE_UPDATES_ON_POSTFIX; - return settings.registerBooleanPreference(settingId, false).makeGlobal(); + return checkPref(settings.registerBooleanPreference(settingId, false)); } public static OsmandSettings.CommonPreference preferenceLiveUpdatesOn( String fileName, OsmandSettings settings) { final String settingId = fileName + LIVE_UPDATES_ON_POSTFIX; - return settings.registerBooleanPreference(settingId, false).makeGlobal(); + return checkPref(settings.registerBooleanPreference(settingId, false)); } public static OsmandSettings.CommonPreference preferenceDownloadViaWiFi( String fileName, OsmandSettings settings) { final String settingId = fileName + DOWNLOAD_VIA_WIFI_POSTFIX; - return settings.registerBooleanPreference(settingId, false).makeGlobal(); + return checkPref(settings.registerBooleanPreference(settingId, false)); } public static OsmandSettings.CommonPreference preferenceUpdateFrequency( String fileName, OsmandSettings settings) { final String settingId = fileName + UPDATE_TIMES_POSTFIX; - return settings.registerIntPreference(settingId, UpdateFrequency.HOURLY.ordinal()).makeGlobal(); + return checkPref(settings.registerIntPreference(settingId, UpdateFrequency.HOURLY.ordinal())); } public static OsmandSettings.CommonPreference preferenceTimeOfDayToUpdate( String fileName, OsmandSettings settings) { final String settingId = fileName + TIME_OF_DAY_TO_UPDATE_POSTFIX; - return settings.registerIntPreference(settingId, TimeOfDay.NIGHT.ordinal()).makeGlobal(); + return checkPref(settings.registerIntPreference(settingId, TimeOfDay.NIGHT.ordinal())); } public static OsmandSettings.CommonPreference preferenceLastCheck( String fileName, OsmandSettings settings) { final String settingId = fileName + LAST_UPDATE_ATTEMPT_ON_POSTFIX; - return settings.registerLongPreference(settingId, DEFAULT_LAST_CHECK).makeGlobal(); + return checkPref(settings.registerLongPreference(settingId, DEFAULT_LAST_CHECK)); } public static String getNameToDisplay(String fileName, OsmandActionBarActivity activity) { diff --git a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java index 14d3e39105..37bfc70cf2 100644 --- a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java @@ -43,7 +43,7 @@ public class RulerControlLayer extends OsmandMapLayer { private static final long DELAY_BEFORE_DRAW = 500; private static final int TEXT_SIZE = 14; private static final int DISTANCE_TEXT_SIZE = 16; - private static final int COMPASS_CIRCLE_ID = 2; + private static final float COMPASS_CIRCLE_FITTING_RADIUS_COEF = 1.25f; private final MapActivity mapActivity; private OsmandApplication app; @@ -277,9 +277,10 @@ public class RulerControlLayer extends OsmandMapLayer { resetDrawingPaths(); } RenderingLineAttributes attrs = mode == RulerMode.FIRST ? circleAttrs : circleAttrsAlt; + int compassCircleId = getCompassCircleId(tb, center); for (int i = 1; i <= cacheDistances.size(); i++) { - if (showCompass && i == COMPASS_CIRCLE_ID) { - drawCompassCircle(canvas, tb, center, attrs); + if (showCompass && i == compassCircleId) { + drawCompassCircle(canvas, tb, compassCircleId, center, attrs); } else { drawCircle(canvas, tb, i, center, attrs); } @@ -293,6 +294,39 @@ public class RulerControlLayer extends OsmandMapLayer { rightWidgetsPanel.getVisibility() == View.VISIBLE; } + private int getCompassCircleId(RotatedTileBox tileBox, QuadPoint center) { + int compassCircleId = 2; + float radiusLength = radius * compassCircleId; + float top = center.y - radiusLength; + float bottom = center.y + radiusLength; + float left = center.x - radiusLength; + float right = center.x + radiusLength; + + int width = tileBox.getPixWidth(); + int height = tileBox.getPixHeight(); + + if (top < 0) { + top = 0; + } + if (bottom > height) { + bottom = height; + } + if (left < 0) { + left = 0; + } + if (right > width) { + right = width; + } + int horizontal = (int) (bottom - top) / 2; + int vertical = (int) (right - left) / 2; + int minFittingRadius = Math.min(horizontal, vertical); + if (radiusLength > minFittingRadius * COMPASS_CIRCLE_FITTING_RADIUS_COEF) { + compassCircleId = 1; + } + + return compassCircleId; + } + private void updateHeading() { Float heading = mapActivity.getMapViewTrackingUtilities().getHeading(); if (heading != null && heading != cachedHeading) { @@ -416,7 +450,6 @@ public class RulerControlLayer extends OsmandMapLayer { cacheTileX = tb.getCenterTileX(); cacheTileY = tb.getCenterTileY(); cacheMapDensity = mapDensity.get(); - cacheDistances.clear(); updateDistance(tb); } } @@ -450,6 +483,7 @@ public class RulerControlLayer extends OsmandMapLayer { } private void updateText() { + cacheDistances.clear(); double maxCircleRadius = maxRadius; int i = 1; while ((maxCircleRadius -= radius) > 0) { @@ -512,10 +546,10 @@ public class RulerControlLayer extends OsmandMapLayer { return new float[]{x1, y1, x2, y2}; } - private void drawCompassCircle(Canvas canvas, RotatedTileBox tileBox, QuadPoint center, + private void drawCompassCircle(Canvas canvas, RotatedTileBox tileBox,int circleNumber, QuadPoint center, RenderingLineAttributes attrs) { if (!tileBox.isZoomAnimated()) { - float radiusLength = radius * COMPASS_CIRCLE_ID; + float radiusLength = radius * circleNumber; float innerRadiusLength = radiusLength - attrs.paint.getStrokeWidth() / 2; updateArcShader(radiusLength, center); @@ -541,7 +575,7 @@ public class RulerControlLayer extends OsmandMapLayer { canvas.drawPath(arrow, triangleHeadingPaint); canvas.rotate(-cachedHeading, center.x, center.y); - String distance = cacheDistances.get(COMPASS_CIRCLE_ID - 1); + String distance = cacheDistances.get(circleNumber - 1); String heading = OsmAndFormatter.getFormattedAzimuth(cachedHeading, app) + " " + getCardinalDirectionForDegrees(cachedHeading); float[] textCoords = calculateTextCoords(distance, heading, radiusLength + AndroidUtils.dpToPx(app, 16), center, attrs); canvas.rotate(-tileBox.getRotate(), center.x, center.y);