Issue 54 add miles/meters/foots metrics
This commit is contained in:
parent
d7464e19e6
commit
66151eacb0
7 changed files with 125 additions and 16 deletions
|
@ -1,5 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="unit_of_length_descr">Изменить единицы измерения длины и скорости</string>
|
||||
<string name="unit_of_length">Единицы измерения</string>
|
||||
<string name="si_mi_foots">Мили/футы</string>
|
||||
<string name="si_mi_yard">Мили/ярды</string>
|
||||
<string name="si_km_m">Километры/метры</string>
|
||||
<string name="yard">ярд</string>
|
||||
<string name="foot">фт</string>
|
||||
<string name="mile_per_hour">мл/ч</string>
|
||||
<string name="mile">мл</string>
|
||||
<string name="send_location_way_choose_title">Поделиться используя</string>
|
||||
<string name="send_location_sms_pattern">Tut : {0}\n{1}</string>
|
||||
<string name="send_location_email_pattern">Чтобы увидить местоположение следуйте ссылке {0} или android ссылке {1}</string>
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<resources>
|
||||
<string name="unit_of_length_descr">Change unit of length and speed</string>
|
||||
<string name="unit_of_length">Unit of length</string>
|
||||
<string name="si_mi_foots">Miles/foots</string>
|
||||
<string name="si_mi_yard">Miles/yards</string>
|
||||
<string name="si_km_m">Kilometers/meters</string>
|
||||
<string name="yard">yd</string>
|
||||
<string name="foot">ft</string>
|
||||
<string name="mile_per_hour">mph</string>
|
||||
<string name="mile">mi</string>
|
||||
<string name="send_location_way_choose_title">Share location using</string>
|
||||
<string name="send_location_sms_pattern">I\'m here : {0}\n{1}</string>
|
||||
<string name="send_location_email_pattern">To see location follow the web browser link {0} or android intent link {1}</string>
|
||||
|
|
|
@ -50,8 +50,9 @@
|
|||
<CheckBoxPreference android:key="show_view_angle" android:title="@string/show_view_angle" android:summary="@string/show_view_angle_descr"></CheckBoxPreference>
|
||||
<ListPreference android:key="rotate_map" android:title="@string/rotate_map_to_bearing" android:summary="@string/rotate_map_to_bearing_descr"></ListPreference>
|
||||
<ListPreference android:key="map_screen_orientation" android:title="@string/map_screen_orientation" android:summary="@string/map_screen_orientation_descr"></ListPreference>
|
||||
<ListPreference android:key="position_on_map" android:title="@string/position_on_map" android:summary="@string/position_on_map_descr"></ListPreference>
|
||||
<EditTextPreference android:title="@string/application_dir" android:key="external_storage_dir"></EditTextPreference>
|
||||
<ListPreference android:key="default_metric_system" android:title="@string/unit_of_length" android:summary="@string/unit_of_length_descr"></ListPreference>
|
||||
<ListPreference android:key="position_on_map" android:title="@string/position_on_map" android:summary="@string/position_on_map_descr"></ListPreference>
|
||||
<CheckBoxPreference android:key="use_trackball_for_movements" android:title="@string/use_trackball" android:summary="@string/use_trackball_descr"></CheckBoxPreference>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
|
|
@ -4,23 +4,57 @@ import java.text.MessageFormat;
|
|||
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.AmenityType;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.OsmandSettings.MetricsConstants;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class OsmAndFormatter {
|
||||
private final static float METERS_IN_KILOMETER = 1000f;
|
||||
private final static float METERS_IN_MILE = 1609.344f; // 1609.344
|
||||
private final static float YARDS_IN_METER = 1.0936f;
|
||||
private final static float FOOTS_IN_METER = YARDS_IN_METER * 3f;
|
||||
|
||||
public static String getFormattedDistance(int meters, Context ctx) {
|
||||
if (meters >= 100000) {
|
||||
return meters / 1000 + " " + ctx.getString(R.string.km); //$NON-NLS-1$
|
||||
} else if (meters >= 10000) {
|
||||
return MessageFormat.format("{0,number,#.#} " + ctx.getString(R.string.km), ((float) meters) / 1000); //$NON-NLS-1$
|
||||
} else if (meters > 1500) {
|
||||
return MessageFormat.format("{0,number,#.#} " + ctx.getString(R.string.km), ((float) meters) / 1000); //$NON-NLS-1$
|
||||
} else if (meters > 900) {
|
||||
return MessageFormat.format("{0,number,#.##} " + ctx.getString(R.string.km), ((float) meters) / 1000); //$NON-NLS-1$
|
||||
MetricsConstants mc = OsmandSettings.getDefaultMetricConstants(ctx);
|
||||
int mainUnitStr;
|
||||
float mainUnitInMeters;
|
||||
if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
|
||||
mainUnitStr = R.string.km;
|
||||
mainUnitInMeters = METERS_IN_KILOMETER;
|
||||
} else {
|
||||
return meters + " " + ctx.getString(R.string.m); //$NON-NLS-1$
|
||||
mainUnitStr = R.string.mile;
|
||||
mainUnitInMeters = METERS_IN_MILE;
|
||||
}
|
||||
|
||||
if (meters >= 100 * mainUnitInMeters) {
|
||||
return meters / mainUnitInMeters + " " + ctx.getString(mainUnitStr); //$NON-NLS-1$
|
||||
} else if (meters > 1.5f * mainUnitInMeters) {
|
||||
return MessageFormat.format("{0,number,#.#} " + ctx.getString(mainUnitStr), ((float) meters) / mainUnitInMeters); //$NON-NLS-1$
|
||||
} else if (meters > 0.9f * mainUnitInMeters) {
|
||||
return MessageFormat.format("{0,number,#.##} " + ctx.getString(mainUnitStr), ((float) meters) / mainUnitInMeters); //$NON-NLS-1$
|
||||
} else {
|
||||
if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
|
||||
return meters + " " + ctx.getString(R.string.m); //$NON-NLS-1$
|
||||
} else if (mc == MetricsConstants.MILES_AND_YARDS) {
|
||||
int yards = (int) (meters * YARDS_IN_METER);
|
||||
return yards + " " + ctx.getString(R.string.yard); //$NON-NLS-1$
|
||||
} else if(mc == MetricsConstants.MILES_AND_FOOTS) {
|
||||
int foots = (int) (meters * FOOTS_IN_METER);
|
||||
return foots + " " + ctx.getString(R.string.foot); //$NON-NLS-1$
|
||||
}
|
||||
return meters + " " + ctx.getString(R.string.m); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFormattedSpeed(float metersperseconds, Context ctx) {
|
||||
MetricsConstants mc = OsmandSettings.getDefaultMetricConstants(ctx);
|
||||
float kmh = metersperseconds * 3.6f;
|
||||
if(mc == MetricsConstants.KILOMETERS_AND_METERS){
|
||||
return ((int) kmh) + ctx.getString(R.string.km_h);
|
||||
} else {
|
||||
return ((int) (kmh * METERS_IN_KILOMETER / METERS_IN_MILE)) + ctx.getString(R.string.mile_per_hour);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -94,6 +94,22 @@ public class OsmandSettings {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
public enum MetricsConstants {
|
||||
KILOMETERS_AND_METERS(R.string.si_km_m),
|
||||
MILES_AND_YARDS(R.string.si_mi_yard),
|
||||
MILES_AND_FOOTS(R.string.si_mi_foots);
|
||||
|
||||
private final int key;
|
||||
MetricsConstants(int key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String toHumanString(Context ctx){
|
||||
return ctx.getResources().getString(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// These settings are stored in SharedPreferences
|
||||
public static final String SHARED_PREFERENCES_NAME = "net.osmand.settings"; //$NON-NLS-1$
|
||||
|
@ -147,7 +163,31 @@ public class OsmandSettings {
|
|||
}
|
||||
return internetConnectionAvailable;
|
||||
}
|
||||
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
public static final String DEFAULT_METRIC_SYSTEM = "default_metric_system"; //$NON-NLS-1$
|
||||
public static final int DEFAULT_METRIC_SYSTEM_DEF = 0;
|
||||
// cache of metrics constants as they are used very often
|
||||
private static MetricsConstants metricConstants = null;
|
||||
|
||||
public static MetricsConstants getDefaultMetricConstants(Context ctx) {
|
||||
if (metricConstants == null) {
|
||||
int value = getSharedPreferences(ctx).getInt(DEFAULT_METRIC_SYSTEM, DEFAULT_METRIC_SYSTEM_DEF);
|
||||
if (value >= MetricsConstants.values().length) {
|
||||
metricConstants = MetricsConstants.KILOMETERS_AND_METERS;
|
||||
} else {
|
||||
metricConstants = MetricsConstants.values()[value];
|
||||
}
|
||||
}
|
||||
return metricConstants;
|
||||
}
|
||||
|
||||
public static void setDefaultMetricConstants(Editor editor, MetricsConstants constants){
|
||||
editor.putInt(DEFAULT_METRIC_SYSTEM, constants.ordinal()).commit();
|
||||
metricConstants = constants;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
|
|
|
@ -21,6 +21,7 @@ import net.osmand.plus.ResourceManager;
|
|||
import net.osmand.plus.SQLiteTileSource;
|
||||
import net.osmand.plus.OsmandSettings.ApplicationMode;
|
||||
import net.osmand.plus.OsmandSettings.DayNightMode;
|
||||
import net.osmand.plus.OsmandSettings.MetricsConstants;
|
||||
import net.osmand.plus.activities.RouteProvider.RouteService;
|
||||
import net.osmand.plus.render.BaseOsmandRender;
|
||||
import net.osmand.plus.render.RendererRegistry;
|
||||
|
@ -97,6 +98,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
private ListPreference maxLevelToDownload;
|
||||
private ListPreference mapScreenOrientation;
|
||||
private ListPreference voicePreference;
|
||||
private ListPreference metricPreference;
|
||||
private ListPreference rendererPreference;
|
||||
private ListPreference routeServiceInterval;
|
||||
private ListPreference routeServiceWaitInterval;
|
||||
|
@ -162,16 +164,18 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
saveTrackInterval.setOnPreferenceChangeListener(this);
|
||||
positionOnMap =(ListPreference) screen.findPreference(OsmandSettings.POSITION_ON_MAP);
|
||||
positionOnMap.setOnPreferenceChangeListener(this);
|
||||
mapScreenOrientation =(ListPreference) screen.findPreference(OsmandSettings.MAP_SCREEN_ORIENTATION);
|
||||
mapScreenOrientation = (ListPreference) screen.findPreference(OsmandSettings.MAP_SCREEN_ORIENTATION);
|
||||
mapScreenOrientation.setOnPreferenceChangeListener(this);
|
||||
maxLevelToDownload =(ListPreference) screen.findPreference(OsmandSettings.MAX_LEVEL_TO_DOWNLOAD_TILE);
|
||||
maxLevelToDownload = (ListPreference) screen.findPreference(OsmandSettings.MAX_LEVEL_TO_DOWNLOAD_TILE);
|
||||
maxLevelToDownload.setOnPreferenceChangeListener(this);
|
||||
tileSourcePreference =(ListPreference) screen.findPreference(OsmandSettings.MAP_TILE_SOURCES);
|
||||
tileSourcePreference = (ListPreference) screen.findPreference(OsmandSettings.MAP_TILE_SOURCES);
|
||||
tileSourcePreference.setOnPreferenceChangeListener(this);
|
||||
routerPreference =(ListPreference) screen.findPreference(OsmandSettings.ROUTER_SERVICE);
|
||||
routerPreference = (ListPreference) screen.findPreference(OsmandSettings.ROUTER_SERVICE);
|
||||
routerPreference.setOnPreferenceChangeListener(this);
|
||||
voicePreference =(ListPreference) screen.findPreference(OsmandSettings.VOICE_PROVIDER);
|
||||
voicePreference = (ListPreference) screen.findPreference(OsmandSettings.VOICE_PROVIDER);
|
||||
voicePreference.setOnPreferenceChangeListener(this);
|
||||
metricPreference = (ListPreference) screen.findPreference(OsmandSettings.DEFAULT_METRIC_SYSTEM);
|
||||
metricPreference.setOnPreferenceChangeListener(this);
|
||||
rendererPreference =(ListPreference) screen.findPreference(OsmandSettings.RENDERER);
|
||||
rendererPreference.setOnPreferenceChangeListener(this);
|
||||
routeServiceInterval =(ListPreference) screen.findPreference(OsmandSettings.SERVICE_OFF_INTERVAL);
|
||||
|
@ -301,6 +305,15 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
entries[i] = RouteService.values()[i].getName();
|
||||
}
|
||||
fill(routerPreference, entries, entries, entry);
|
||||
|
||||
names = new String[MetricsConstants.values().length];
|
||||
values = new String[MetricsConstants.values().length];
|
||||
entry = OsmandSettings.getDefaultMetricConstants(this).name();
|
||||
for (int i = 0; i < MetricsConstants.values().length; i++) {
|
||||
values[i] = MetricsConstants.values()[i].name();
|
||||
names[i] = MetricsConstants.values()[i].toHumanString(this);
|
||||
}
|
||||
fill(metricPreference, names, values, entry);
|
||||
|
||||
// read available voice data
|
||||
File extStorage = OsmandSettings.extendOsmandPath(getApplicationContext(), ResourceManager.VOICE_PATH);
|
||||
|
@ -523,6 +536,9 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
}
|
||||
edit.commit();
|
||||
getMyApplication().initCommandPlayer();
|
||||
} else if (preference == metricPreference) {
|
||||
MetricsConstants mc = MetricsConstants.valueOf((String) newValue);
|
||||
OsmandSettings.setDefaultMetricConstants(edit, mc);
|
||||
} else if (preference == tileSourcePreference) {
|
||||
if(VECTOR_MAP.equals((String) newValue)){
|
||||
edit.putBoolean(OsmandSettings.MAP_VECTOR_DATA, true);
|
||||
|
|
|
@ -235,7 +235,7 @@ public class MapInfoLayer implements OsmandMapLayer {
|
|||
if(map.getLastKnownLocation() != null && map.getLastKnownLocation().hasSpeed()){
|
||||
if(Math.abs(map.getLastKnownLocation().getSpeed() - cachedSpeed) > .3f){
|
||||
cachedSpeed = map.getLastKnownLocation().getSpeed();
|
||||
cachedSpeedString = ((int) (cachedSpeed * 3.6f)) + map.getString(R.string.km_h);
|
||||
cachedSpeedString = OsmAndFormatter.getFormattedSpeed(cachedSpeed, map);
|
||||
float right = paintBlack.measureText(cachedSpeedString) + 8 * scaleCoefficient + boundsForSpeed.left;
|
||||
boundsForSpeed.right = boundsForDist.right = Math.max(right, boundsForDist.right);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue