Merge branch 'r3.4'

Conflicts:
	OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesHelper.java
This commit is contained in:
Victor Shcherb 2019-07-22 13:09:05 +02:00
commit 1d58382138
2 changed files with 57 additions and 13 deletions

View file

@ -31,40 +31,50 @@ public class LiveUpdatesHelper {
public static final int DEFAULT_LAST_CHECK = -1;
private static <T> OsmandSettings.CommonPreference<T> checkPref(OsmandSettings.CommonPreference<T> p) {
if(p.isSet()) {
T vl = p.get();
p = p.makeGlobal();
p.set(vl);
} else {
p = p.makeGlobal();
}
return p;
}
public static OsmandSettings.CommonPreference<Boolean> 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<Boolean> 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<Boolean> 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<Integer> 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<Integer> 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<Long> 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) {

View file

@ -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);