parent
6065d44c9a
commit
1a28958743
8 changed files with 184 additions and 60 deletions
|
@ -12,8 +12,10 @@
|
|||
|
||||
<!-- Not translatable -->
|
||||
<string name="last_release">
|
||||
- New road indexes (including)
|
||||
-
|
||||
- New road indexes (including map data, poi, address)
|
||||
- New speed system (knots and minutes per km)
|
||||
- New context menu
|
||||
- Drawer and start with the map
|
||||
</string>
|
||||
<string name="ga_api_key">UA-28342846-2</string>
|
||||
<string name="ga_dispatchPeriod">10</string>
|
||||
|
|
|
@ -9,6 +9,21 @@
|
|||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||
-->
|
||||
<string name="default_speed_system_descr">Define speed measurement system</string>
|
||||
<string name="default_speed_system">Speed measurement</string>
|
||||
<string name="nm">nm</string>
|
||||
<string name="si_nm">Nautical miles</string>
|
||||
<string name="si_kmh">Kilometers per hour</string>
|
||||
<string name="si_mph">Miles per hour</string>
|
||||
<string name="si_m_s">Meters per second</string>
|
||||
<string name="si_min_km">Minutes per kilometer</string>
|
||||
<string name="si_min_m">Minutes per mile</string>
|
||||
<string name="si_nm_h">Nautical miles per hour (knot)</string>
|
||||
<string name="nm_h">nmh</string>
|
||||
<string name="min_mile">min/m</string>
|
||||
<string name="min_km">min/km</string>
|
||||
<string name="m_s">m/s</string>
|
||||
|
||||
<string name="shared_string_trip_recording">Trip recording</string>
|
||||
<string name="shared_string_navigation">Navigation</string>
|
||||
<string name="osmand_running_in_background">Running in background</string>
|
||||
|
|
|
@ -23,6 +23,11 @@
|
|||
android:key="arrival_distance_factor"
|
||||
android:title="@string/arrival_distance"
|
||||
android:summary="@string/arrival_distance_descr" />
|
||||
<ListPreference
|
||||
android:key="default_speed_system"
|
||||
android:title="@string/default_speed_system"
|
||||
android:summary="@string/default_speed_system_descr" />
|
||||
|
||||
<ListPreference
|
||||
android:key="speed_limit_exceed"
|
||||
android:title="@string/speed_limit_exceed"
|
||||
|
|
|
@ -11,12 +11,15 @@ import net.osmand.osm.MapPoiTypes;
|
|||
import net.osmand.osm.PoiCategory;
|
||||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.plus.OsmandSettings.MetricsConstants;
|
||||
import net.osmand.plus.OsmandSettings.SpeedConstants;
|
||||
import net.osmand.util.Algorithms;
|
||||
import android.content.Context;
|
||||
|
||||
public class OsmAndFormatter {
|
||||
public final static float METERS_IN_KILOMETER = 1000f;
|
||||
public final static float METERS_IN_ONE_MILE = 1609.344f; // 1609.344
|
||||
public final static float METERS_IN_ONE_NAUTICALMILE = 1852f; // 1852
|
||||
|
||||
public final static float YARDS_IN_ONE_METER = 1.0936f;
|
||||
public final static float FOOTS_IN_ONE_METER = YARDS_IN_ONE_METER * 3f;
|
||||
private static final DecimalFormat fixed2 = new DecimalFormat("0.00");
|
||||
|
@ -36,6 +39,9 @@ public class OsmAndFormatter {
|
|||
if (mc == MetricsConstants.MILES_AND_FOOTS) {
|
||||
mainUnitInMeter = FOOTS_IN_ONE_METER;
|
||||
metersInSecondUnit = METERS_IN_ONE_MILE;
|
||||
} else if (mc == MetricsConstants.NAUTICAL_MILES) {
|
||||
mainUnitInMeter = 1;
|
||||
metersInSecondUnit = METERS_IN_ONE_NAUTICALMILE;
|
||||
} else if (mc == MetricsConstants.MILES_AND_YARDS) {
|
||||
mainUnitInMeter = YARDS_IN_ONE_METER;
|
||||
metersInSecondUnit = METERS_IN_ONE_MILE;
|
||||
|
@ -84,6 +90,9 @@ public class OsmAndFormatter {
|
|||
if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
|
||||
mainUnitStr = R.string.km;
|
||||
mainUnitInMeters = METERS_IN_KILOMETER;
|
||||
} else if (mc == MetricsConstants.NAUTICAL_MILES) {
|
||||
mainUnitStr = R.string.nm;
|
||||
mainUnitInMeters = METERS_IN_ONE_NAUTICALMILE;
|
||||
} else {
|
||||
mainUnitStr = R.string.mile;
|
||||
mainUnitInMeters = METERS_IN_ONE_MILE;
|
||||
|
@ -95,6 +104,8 @@ public class OsmAndFormatter {
|
|||
return MessageFormat.format("{0,number,#.#} " + ctx.getString(mainUnitStr), ((float) meters) / mainUnitInMeters).replace('\n', ' '); //$NON-NLS-1$
|
||||
} else if (meters > 0.999f * mainUnitInMeters) {
|
||||
return MessageFormat.format("{0,number,#.##} " + ctx.getString(mainUnitStr), ((float) meters) / mainUnitInMeters).replace('\n', ' '); //$NON-NLS-1$
|
||||
} else if (mc == MetricsConstants.NAUTICAL_MILES && meters > 0.09f * mainUnitInMeters) {
|
||||
return MessageFormat.format("{0,number,.##} " + ctx.getString(mainUnitStr), ((float) meters) / mainUnitInMeters).replace('\n', ' '); //$NON-NLS-1$
|
||||
} else {
|
||||
if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
|
||||
return ((int) (meters + 0.5)) + " " + ctx.getString(R.string.m); //$NON-NLS-1$
|
||||
|
@ -121,25 +132,62 @@ public class OsmAndFormatter {
|
|||
|
||||
public static String getFormattedSpeed(float metersperseconds, OsmandApplication ctx) {
|
||||
OsmandSettings settings = ctx.getSettings();
|
||||
MetricsConstants mc = settings.METRIC_SYSTEM.get();
|
||||
SpeedConstants mc = settings.SPEED_SYSTEM.get();
|
||||
ApplicationMode am = settings.getApplicationMode();
|
||||
float kmh = metersperseconds * 3.6f;
|
||||
if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
|
||||
if (mc == SpeedConstants.KILOMETERS_PER_HOUR) {
|
||||
// e.g. car case and for high-speeds: Display rounded to 1 km/h (5% precision at 20 km/h)
|
||||
if (kmh >= 20 || am.hasFastSpeed()) {
|
||||
return ((int) Math.round(kmh)) + " " + ctx.getString(R.string.km_h);
|
||||
return ((int) Math.round(kmh)) + " " + mc.toShortString(ctx);
|
||||
}
|
||||
// for smaller values display 1 decimal digit x.y km/h, (0.5% precision at 20 km/h)
|
||||
int kmh10 = (int) Math.round(kmh * 10f);
|
||||
return (kmh10 / 10f) + " " + ctx.getString(R.string.km_h);
|
||||
} else {
|
||||
return (kmh10 / 10f) + " " + mc.toShortString(ctx);
|
||||
} else if (mc == SpeedConstants.MILES_PER_HOUR) {
|
||||
float mph = kmh * METERS_IN_KILOMETER / METERS_IN_ONE_MILE;
|
||||
if (mph >= 20 || am.hasFastSpeed()) {
|
||||
return ((int) Math.round(mph)) + " " + ctx.getString(R.string.mile_per_hour);
|
||||
return ((int) Math.round(mph)) + " " + mc.toShortString(ctx);
|
||||
} else {
|
||||
int mph10 = (int) Math.round(mph * 10f);
|
||||
return (mph10 / 10f) + " " + ctx.getString(R.string.mile_per_hour);
|
||||
return (mph10 / 10f) + " " + mc.toShortString(ctx);
|
||||
}
|
||||
} else if (mc == SpeedConstants.NAUTICALMILES_PER_HOUR) {
|
||||
float mph = kmh * METERS_IN_KILOMETER / METERS_IN_ONE_NAUTICALMILE;
|
||||
if (mph >= 20 || am.hasFastSpeed()) {
|
||||
return ((int) Math.round(mph)) + " " + mc.toShortString(ctx);
|
||||
} else {
|
||||
int mph10 = (int) Math.round(mph * 10f);
|
||||
return (mph10 / 10f) + " " + mc.toShortString(ctx);
|
||||
}
|
||||
} else if (mc == SpeedConstants.MINUTES_PER_KILOMETER) {
|
||||
if (metersperseconds < 0.111111111) {
|
||||
return "-" + mc.toShortString(ctx);
|
||||
}
|
||||
float minperkm = METERS_IN_KILOMETER / (metersperseconds * 60);
|
||||
if (minperkm >= 10) {
|
||||
return ((int) Math.round(minperkm)) + " " + mc.toShortString(ctx);
|
||||
} else {
|
||||
int mph10 = (int) Math.round(minperkm * 10f);
|
||||
return (mph10 / 10f) + " " + mc.toShortString(ctx);
|
||||
}
|
||||
} else if (mc == SpeedConstants.MINUTES_PER_MILE) {
|
||||
if (metersperseconds < 0.111111111) {
|
||||
return "-" + mc.toShortString(ctx);
|
||||
}
|
||||
float minperm = (METERS_IN_ONE_MILE) / (metersperseconds * 60);
|
||||
if (minperm >= 10) {
|
||||
return ((int) Math.round(minperm)) + " " + mc.toShortString(ctx);
|
||||
} else {
|
||||
int mph10 = (int) Math.round(minperm * 10f);
|
||||
return (mph10 / 10f) + " " + mc.toShortString(ctx);
|
||||
}
|
||||
} else /*if (mc == SpeedConstants.METERS_PER_SECOND) */ {
|
||||
if (metersperseconds >= 10) {
|
||||
return ((int) Math.round(metersperseconds)) + " " + SpeedConstants.METERS_PER_SECOND.toShortString(ctx);
|
||||
}
|
||||
// for smaller values display 1 decimal digit x.y km/h, (0.5% precision at 20 km/h)
|
||||
int kmh10 = (int) Math.round(metersperseconds * 10f);
|
||||
return (kmh10 / 10f) + " " + SpeedConstants.METERS_PER_SECOND.toShortString(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,21 @@
|
|||
package net.osmand.plus;
|
||||
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.StateChangedListener;
|
||||
|
@ -28,22 +34,15 @@ import net.osmand.plus.helpers.SearchHistoryHelper;
|
|||
import net.osmand.plus.render.RendererRegistry;
|
||||
import net.osmand.plus.routing.RouteProvider.RouteService;
|
||||
import net.osmand.render.RenderingRulesStorage;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
|
||||
public class OsmandSettings {
|
||||
|
||||
|
@ -312,22 +311,12 @@ public class OsmandSettings {
|
|||
return ch;
|
||||
}
|
||||
|
||||
public T getProfileDefaultValue(){
|
||||
public T getProfileDefaultValue(ApplicationMode mode){
|
||||
if(global){
|
||||
return defaultValue;
|
||||
}
|
||||
if(defaultValues != null && defaultValues.containsKey(currentMode)){
|
||||
return defaultValues.get(currentMode);
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
protected T getDefaultValue(){
|
||||
if(global){
|
||||
return defaultValue;
|
||||
}
|
||||
if(defaultValues != null && defaultValues.containsKey(currentMode)){
|
||||
return defaultValues.get(currentMode);
|
||||
if(defaultValues != null && defaultValues.containsKey(mode)){
|
||||
return defaultValues.get(mode);
|
||||
}
|
||||
if(settingsAPI.contains(defaultProfilePreferences, getId())) {
|
||||
return getValue(defaultProfilePreferences, defaultValue);
|
||||
|
@ -336,6 +325,10 @@ public class OsmandSettings {
|
|||
}
|
||||
}
|
||||
|
||||
protected T getDefaultValue(){
|
||||
return getProfileDefaultValue(currentMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void overrideDefaultValue(T newDefaultValue) {
|
||||
this.defaultValue = newDefaultValue;
|
||||
|
@ -351,10 +344,7 @@ public class OsmandSettings {
|
|||
if(global) {
|
||||
return get();
|
||||
}
|
||||
T defaultV = defaultValue;
|
||||
if(defaultValues != null && defaultValues.containsKey(currentMode)){
|
||||
defaultV = defaultValues.get(currentMode);
|
||||
}
|
||||
T defaultV = getProfileDefaultValue(mode);
|
||||
return getValue(getProfilePreferences(mode), defaultV);
|
||||
}
|
||||
|
||||
|
@ -364,7 +354,7 @@ public class OsmandSettings {
|
|||
return cachedValue;
|
||||
}
|
||||
cachedPreference = getPreferences();
|
||||
cachedValue = getValue(cachedPreference, getDefaultValue());
|
||||
cachedValue = getValue(cachedPreference, getProfileDefaultValue(currentMode));
|
||||
return cachedValue;
|
||||
}
|
||||
|
||||
|
@ -375,10 +365,7 @@ public class OsmandSettings {
|
|||
|
||||
@Override
|
||||
public void resetToDefault(){
|
||||
T o = defaultValue;
|
||||
if(defaultValues != null && defaultValues.containsKey(currentMode)){
|
||||
o = defaultValues.get(currentMode);
|
||||
}
|
||||
T o = getProfileDefaultValue(currentMode);
|
||||
set(o);
|
||||
}
|
||||
|
||||
|
@ -708,6 +695,34 @@ public class OsmandSettings {
|
|||
}.makeGlobal().cache();
|
||||
|
||||
|
||||
public final OsmandPreference<SpeedConstants> SPEED_SYSTEM = new EnumIntPreference<SpeedConstants>(
|
||||
"default_speed_system", SpeedConstants.KILOMETERS_PER_HOUR, SpeedConstants.values()) {
|
||||
|
||||
@Override
|
||||
public SpeedConstants getProfileDefaultValue(ApplicationMode mode) {
|
||||
MetricsConstants mc = METRIC_SYSTEM.get();
|
||||
if(mode.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) {
|
||||
if(mc == MetricsConstants.KILOMETERS_AND_METERS) {
|
||||
return SpeedConstants.MINUTES_PER_KILOMETER;
|
||||
} else {
|
||||
return SpeedConstants.MILES_PER_HOUR;
|
||||
}
|
||||
}
|
||||
if(mode.isDerivedRoutingFrom(ApplicationMode.BOAT) ||
|
||||
mode.isDerivedRoutingFrom(ApplicationMode.AIRCRAFT)) {
|
||||
return SpeedConstants.NAUTICALMILES_PER_HOUR;
|
||||
}
|
||||
if(mc == MetricsConstants.NAUTICAL_MILES) {
|
||||
return SpeedConstants.NAUTICALMILES_PER_HOUR;
|
||||
} else if(mc == MetricsConstants.KILOMETERS_AND_METERS) {
|
||||
return SpeedConstants.KILOMETERS_PER_HOUR;
|
||||
} else {
|
||||
return SpeedConstants.MILES_PER_HOUR;
|
||||
}
|
||||
};
|
||||
|
||||
}.makeProfile().cache();
|
||||
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
// cache of metrics constants as they are used very often
|
||||
|
@ -1926,9 +1941,38 @@ public class OsmandSettings {
|
|||
|
||||
}
|
||||
|
||||
|
||||
public enum SpeedConstants {
|
||||
KILOMETERS_PER_HOUR(R.string.km_h, R.string.si_kmh),
|
||||
MILES_PER_HOUR(R.string.mile_per_hour, R.string.si_mph),
|
||||
METERS_PER_SECOND(R.string.m_s, R.string.si_m_s),
|
||||
MINUTES_PER_MILE(R.string.min_mile, R.string.si_min_m),
|
||||
MINUTES_PER_KILOMETER(R.string.min_km, R.string.si_min_km),
|
||||
NAUTICALMILES_PER_HOUR(R.string.nm_h, R.string.si_nm_h);
|
||||
|
||||
private final int key;
|
||||
private int descr;
|
||||
|
||||
SpeedConstants(int key, int descr) {
|
||||
this.key = key;
|
||||
this.descr = descr;
|
||||
}
|
||||
|
||||
public String toHumanString(Context ctx){
|
||||
return ctx.getString(descr);
|
||||
}
|
||||
|
||||
public String toShortString(Context ctx){
|
||||
return ctx.getString(key);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public enum MetricsConstants {
|
||||
KILOMETERS_AND_METERS(R.string.si_km_m,"km-m"),
|
||||
MILES_AND_FOOTS(R.string.si_mi_foots,"mi-f"),
|
||||
NAUTICAL_MILES(R.string.si_nm,"nm"),
|
||||
MILES_AND_YARDS(R.string.si_mi_yard,"mi-y");
|
||||
|
||||
private final int key;
|
||||
|
|
|
@ -660,6 +660,9 @@ public class MapActivity extends AccessibleActivity {
|
|||
}
|
||||
}
|
||||
wakeLockHelper.onStop(this);
|
||||
if(getMyApplication().getNavigationService() == null) {
|
||||
getMyApplication().getNotificationHelper().removeServiceNotificationCompletely();
|
||||
}
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
|
@ -671,9 +674,6 @@ public class MapActivity extends AccessibleActivity {
|
|||
getMyApplication().unsubscribeInitListener(initListener);
|
||||
mapViewTrackingUtilities.setMapView(null);
|
||||
cancelNotification();
|
||||
if(getMyApplication().getNavigationService() == null) {
|
||||
getMyApplication().getNotificationHelper().removeServiceNotificationCompletely();
|
||||
}
|
||||
app.getResourceManager().getMapTileDownloader().removeDownloaderCallback(mapView);
|
||||
if (atlasMapRendererView != null) {
|
||||
atlasMapRendererView.handleOnDestroy();
|
||||
|
|
|
@ -11,6 +11,7 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.OsmandSettings.AutoZoomMap;
|
||||
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
||||
import net.osmand.plus.OsmandSettings.SpeedConstants;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.routing.RouteProvider.RouteService;
|
||||
|
@ -136,6 +137,14 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
|||
}
|
||||
registerListPreference(settings.KEEP_INFORMING, screen, keepInformingNames, keepInformingValues);
|
||||
|
||||
|
||||
SpeedConstants[] speedValues = SpeedConstants.values();
|
||||
String[] speedNamesVls = new String[speedValues.length];
|
||||
for(int i = 0; i < speedValues.length; i++) {
|
||||
speedNamesVls[i] = speedValues[i].toHumanString(this);
|
||||
};
|
||||
registerListPreference(settings.SPEED_SYSTEM, screen, speedNamesVls, speedValues);
|
||||
|
||||
// screen power save option:
|
||||
Integer[] screenPowerSaveValues = new Integer[] { 0, 5, 10, 15, 20, 30, 45, 60 };
|
||||
String[] screenPowerSaveNames = new String[screenPowerSaveValues.length];
|
||||
|
|
|
@ -247,7 +247,8 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
|
|||
items.add(R.string.gpx_start_new_segment);
|
||||
if(settings.LIVE_MONITORING.get()) {
|
||||
items.add(R.string.live_monitoring_stop);
|
||||
} else if(!settings.LIVE_MONITORING_URL.getProfileDefaultValue().equals(settings.LIVE_MONITORING_URL.get())){
|
||||
} else if(!settings.LIVE_MONITORING_URL.getProfileDefaultValue(settings.APPLICATION_MODE.get()).
|
||||
equals(settings.LIVE_MONITORING_URL.get())){
|
||||
items.add(R.string.live_monitoring_start);
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue