Merge branch 'r3.4'
Conflicts: OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesHelper.java
This commit is contained in:
commit
1d58382138
2 changed files with 57 additions and 13 deletions
|
@ -31,40 +31,50 @@ public class LiveUpdatesHelper {
|
||||||
|
|
||||||
public static final int DEFAULT_LAST_CHECK = -1;
|
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(
|
public static OsmandSettings.CommonPreference<Boolean> preferenceForLocalIndex(
|
||||||
String fileName, OsmandSettings settings) {
|
String fileName, OsmandSettings settings) {
|
||||||
final String settingId = fileName + LIVE_UPDATES_ON_POSTFIX;
|
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(
|
public static OsmandSettings.CommonPreference<Boolean> preferenceLiveUpdatesOn(
|
||||||
String fileName, OsmandSettings settings) {
|
String fileName, OsmandSettings settings) {
|
||||||
final String settingId = fileName + LIVE_UPDATES_ON_POSTFIX;
|
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(
|
public static OsmandSettings.CommonPreference<Boolean> preferenceDownloadViaWiFi(
|
||||||
String fileName, OsmandSettings settings) {
|
String fileName, OsmandSettings settings) {
|
||||||
final String settingId = fileName + DOWNLOAD_VIA_WIFI_POSTFIX;
|
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(
|
public static OsmandSettings.CommonPreference<Integer> preferenceUpdateFrequency(
|
||||||
String fileName, OsmandSettings settings) {
|
String fileName, OsmandSettings settings) {
|
||||||
final String settingId = fileName + UPDATE_TIMES_POSTFIX;
|
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(
|
public static OsmandSettings.CommonPreference<Integer> preferenceTimeOfDayToUpdate(
|
||||||
String fileName, OsmandSettings settings) {
|
String fileName, OsmandSettings settings) {
|
||||||
final String settingId = fileName + TIME_OF_DAY_TO_UPDATE_POSTFIX;
|
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(
|
public static OsmandSettings.CommonPreference<Long> preferenceLastCheck(
|
||||||
String fileName, OsmandSettings settings) {
|
String fileName, OsmandSettings settings) {
|
||||||
final String settingId = fileName + LAST_UPDATE_ATTEMPT_ON_POSTFIX;
|
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) {
|
public static String getNameToDisplay(String fileName, OsmandActionBarActivity activity) {
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class RulerControlLayer extends OsmandMapLayer {
|
||||||
private static final long DELAY_BEFORE_DRAW = 500;
|
private static final long DELAY_BEFORE_DRAW = 500;
|
||||||
private static final int TEXT_SIZE = 14;
|
private static final int TEXT_SIZE = 14;
|
||||||
private static final int DISTANCE_TEXT_SIZE = 16;
|
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 final MapActivity mapActivity;
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
|
@ -277,9 +277,10 @@ public class RulerControlLayer extends OsmandMapLayer {
|
||||||
resetDrawingPaths();
|
resetDrawingPaths();
|
||||||
}
|
}
|
||||||
RenderingLineAttributes attrs = mode == RulerMode.FIRST ? circleAttrs : circleAttrsAlt;
|
RenderingLineAttributes attrs = mode == RulerMode.FIRST ? circleAttrs : circleAttrsAlt;
|
||||||
|
int compassCircleId = getCompassCircleId(tb, center);
|
||||||
for (int i = 1; i <= cacheDistances.size(); i++) {
|
for (int i = 1; i <= cacheDistances.size(); i++) {
|
||||||
if (showCompass && i == COMPASS_CIRCLE_ID) {
|
if (showCompass && i == compassCircleId) {
|
||||||
drawCompassCircle(canvas, tb, center, attrs);
|
drawCompassCircle(canvas, tb, compassCircleId, center, attrs);
|
||||||
} else {
|
} else {
|
||||||
drawCircle(canvas, tb, i, center, attrs);
|
drawCircle(canvas, tb, i, center, attrs);
|
||||||
}
|
}
|
||||||
|
@ -293,6 +294,39 @@ public class RulerControlLayer extends OsmandMapLayer {
|
||||||
rightWidgetsPanel.getVisibility() == View.VISIBLE;
|
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() {
|
private void updateHeading() {
|
||||||
Float heading = mapActivity.getMapViewTrackingUtilities().getHeading();
|
Float heading = mapActivity.getMapViewTrackingUtilities().getHeading();
|
||||||
if (heading != null && heading != cachedHeading) {
|
if (heading != null && heading != cachedHeading) {
|
||||||
|
@ -416,7 +450,6 @@ public class RulerControlLayer extends OsmandMapLayer {
|
||||||
cacheTileX = tb.getCenterTileX();
|
cacheTileX = tb.getCenterTileX();
|
||||||
cacheTileY = tb.getCenterTileY();
|
cacheTileY = tb.getCenterTileY();
|
||||||
cacheMapDensity = mapDensity.get();
|
cacheMapDensity = mapDensity.get();
|
||||||
cacheDistances.clear();
|
|
||||||
updateDistance(tb);
|
updateDistance(tb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -450,6 +483,7 @@ public class RulerControlLayer extends OsmandMapLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateText() {
|
private void updateText() {
|
||||||
|
cacheDistances.clear();
|
||||||
double maxCircleRadius = maxRadius;
|
double maxCircleRadius = maxRadius;
|
||||||
int i = 1;
|
int i = 1;
|
||||||
while ((maxCircleRadius -= radius) > 0) {
|
while ((maxCircleRadius -= radius) > 0) {
|
||||||
|
@ -512,10 +546,10 @@ public class RulerControlLayer extends OsmandMapLayer {
|
||||||
return new float[]{x1, y1, x2, y2};
|
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) {
|
RenderingLineAttributes attrs) {
|
||||||
if (!tileBox.isZoomAnimated()) {
|
if (!tileBox.isZoomAnimated()) {
|
||||||
float radiusLength = radius * COMPASS_CIRCLE_ID;
|
float radiusLength = radius * circleNumber;
|
||||||
float innerRadiusLength = radiusLength - attrs.paint.getStrokeWidth() / 2;
|
float innerRadiusLength = radiusLength - attrs.paint.getStrokeWidth() / 2;
|
||||||
|
|
||||||
updateArcShader(radiusLength, center);
|
updateArcShader(radiusLength, center);
|
||||||
|
@ -541,7 +575,7 @@ public class RulerControlLayer extends OsmandMapLayer {
|
||||||
canvas.drawPath(arrow, triangleHeadingPaint);
|
canvas.drawPath(arrow, triangleHeadingPaint);
|
||||||
canvas.rotate(-cachedHeading, center.x, center.y);
|
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);
|
String heading = OsmAndFormatter.getFormattedAzimuth(cachedHeading, app) + " " + getCardinalDirectionForDegrees(cachedHeading);
|
||||||
float[] textCoords = calculateTextCoords(distance, heading, radiusLength + AndroidUtils.dpToPx(app, 16), center, attrs);
|
float[] textCoords = calculateTextCoords(distance, heading, radiusLength + AndroidUtils.dpToPx(app, 16), center, attrs);
|
||||||
canvas.rotate(-tileBox.getRotate(), center.x, center.y);
|
canvas.rotate(-tileBox.getRotate(), center.x, center.y);
|
||||||
|
|
Loading…
Reference in a new issue