Add angular unit selector to Settings. Now units changing in measurement tool and route info widget.
This commit is contained in:
parent
4edd8a4976
commit
e8f57a19dc
8 changed files with 59 additions and 7 deletions
|
@ -11,6 +11,10 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<string name="shared_string_degrees">Degrees</string>
|
||||
<string name="shared_string_milliradians">Milliradians</string>
|
||||
<string name="angular_measeurement">Angular measurement units</string>
|
||||
<string name="angular_measeurement_descr">Change what azimuth is measured in.</string>
|
||||
<string name="avoid_pt_types_descr">Select a public transport types you want to avoid during navigation:</string>
|
||||
<string name="avoid_pt_types">Avoid transport types…</string>
|
||||
<string name="shared_string_walk">Walk</string>
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<!-- ListPreference android:key="map_preferred_locale" android:title="@string/map_preferred_locale" android:summary="@string/map_preferred_locale_descr"></ListPreference -->
|
||||
<ListPreference android:key="default_metric_system" android:title="@string/unit_of_length" android:summary="@string/unit_of_length_descr"></ListPreference>
|
||||
<ListPreference android:key="coordinates_format" android:title="@string/coords_format" android:summary="@string/coords_format_descr"></ListPreference>
|
||||
<ListPreference android:key="angular_measurement" android:title="@string/angular_measeurement" android:summary="@string/angular_measeurement_descr"></ListPreference>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import net.osmand.osm.AbstractPoiType;
|
|||
import net.osmand.osm.MapPoiTypes;
|
||||
import net.osmand.osm.PoiCategory;
|
||||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.plus.OsmandSettings.AngularConstants;
|
||||
import net.osmand.plus.OsmandSettings.MetricsConstants;
|
||||
import net.osmand.plus.OsmandSettings.SpeedConstants;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -166,14 +167,20 @@ public class OsmAndFormatter {
|
|||
return df.format(meters / mainUnitInMeters) + " " + app.getString(mainUnitStr);
|
||||
}
|
||||
|
||||
public static String getFormattedAzimuth(float bearing) {
|
||||
public static String getFormattedAzimuth(float bearing, OsmandApplication app) {
|
||||
int azimuth;
|
||||
if (bearing < 0.0) {
|
||||
azimuth = (int) (360 + bearing);
|
||||
} else {
|
||||
azimuth = (int) bearing;
|
||||
}
|
||||
return azimuth + "°";
|
||||
|
||||
if (app.getSettings().ANGULAR_UNITS.get() == AngularConstants.MILLIRADS) {
|
||||
return (int) (azimuth * 17.4533) + " " + AngularConstants.MILLIRADS.getUnitSymbol();
|
||||
} else {
|
||||
return azimuth + AngularConstants.DEGREES.getUnitSymbol();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String getFormattedDistance(float meters, OsmandApplication ctx) {
|
||||
|
|
|
@ -930,6 +930,17 @@ public class OsmandSettings {
|
|||
;
|
||||
}.makeGlobal();
|
||||
|
||||
//public final OsmandPreference<Integer> COORDINATES_FORMAT = new IntPreference("coordinates_format", PointDescription.FORMAT_DEGREES).makeGlobal();
|
||||
|
||||
public final OsmandPreference<AngularConstants> ANGULAR_UNITS = new EnumIntPreference<AngularConstants>(
|
||||
"angular_measurement", AngularConstants.DEGREES, AngularConstants.values()) {
|
||||
@Override
|
||||
protected AngularConstants getValue(Object prefs, AngularConstants defaultValue) {
|
||||
return super.getValue(prefs, defaultValue);
|
||||
}
|
||||
}.makeGlobal();
|
||||
|
||||
|
||||
|
||||
public final OsmandPreference<SpeedConstants> SPEED_SYSTEM = new EnumIntPreference<SpeedConstants>(
|
||||
"default_speed_system", SpeedConstants.KILOMETERS_PER_HOUR, SpeedConstants.values()) {
|
||||
|
@ -2900,6 +2911,27 @@ public class OsmandSettings {
|
|||
|
||||
}
|
||||
|
||||
public enum AngularConstants {
|
||||
DEGREES(R.string.shared_string_degrees, "°"),
|
||||
MILLIRADS(R.string.shared_string_milliradians, "mil");
|
||||
|
||||
private final int key;
|
||||
private final String unit;
|
||||
|
||||
AngularConstants(int key, String unit) {
|
||||
this.key = key;
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public String toHumanString(Context ctx) {
|
||||
return ctx.getString(key);
|
||||
}
|
||||
public String getUnitSymbol() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum AutoZoomMap {
|
||||
FARTHEST(R.string.auto_zoom_farthest, 1f, 15.5f),
|
||||
FAR(R.string.auto_zoom_far, 1.4f, 17f),
|
||||
|
|
|
@ -38,6 +38,7 @@ import net.osmand.osm.io.NetworkUtils;
|
|||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.OsmandSettings.AngularConstants;
|
||||
import net.osmand.plus.OsmandSettings.DrivingRegion;
|
||||
import net.osmand.plus.OsmandSettings.MetricsConstants;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -209,6 +210,13 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
|
|||
entries[4] = PointDescription.formatToHumanString(this, PointDescription.OLC_FORMAT);
|
||||
registerListPreference(settings.COORDINATES_FORMAT, screen, entries, cvls);
|
||||
|
||||
AngularConstants[] ac = AngularConstants.values();
|
||||
entries = new String[ac.length];
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
entries[i] = ac[i].toHumanString(getMyApplication());
|
||||
}
|
||||
registerListPreference(settings.ANGULAR_UNITS, screen, entries, ac);
|
||||
|
||||
// See language list and statistics at: https://hosted.weblate.org/projects/osmand/main/
|
||||
// Hardy maintenance 2016-05-29:
|
||||
// - Include languages if their translation is >= ~10% (but any language will be visible if it is the device's system locale)
|
||||
|
|
|
@ -362,8 +362,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
|
|||
@Override
|
||||
public void onMeasure(float distance, float bearing) {
|
||||
String distStr = OsmAndFormatter.getFormattedDistance(distance, mapActivity.getMyApplication());
|
||||
String azimuthStr = OsmAndFormatter.getFormattedAzimuth(bearing);
|
||||
distanceToCenterTv.setText(" – " + distStr + " • " + azimuthStr);
|
||||
String azimuthStr = OsmAndFormatter.getFormattedAzimuth(bearing, getMyApplication());
|
||||
distanceToCenterTv.setText(String.format(" – %s • %s", distStr, azimuthStr));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ public class MeasurementToolAdapter extends RecyclerView.Adapter<MeasurementTool
|
|||
l2 = getLocationFromLL(points.get(0).lat, points.get(0).lon);
|
||||
text = text
|
||||
+ BULLET + OsmAndFormatter.getFormattedDistance(l1.distanceTo(l2), mapActivity.getMyApplication())
|
||||
+ BULLET + OsmAndFormatter.getFormattedAzimuth(l1.bearingTo(l2));
|
||||
+ BULLET + OsmAndFormatter.getFormattedAzimuth(l1.bearingTo(l2), mapActivity.getMyApplication());
|
||||
}
|
||||
holder.descr.setText(text);
|
||||
} else {
|
||||
|
@ -110,7 +110,7 @@ public class MeasurementToolAdapter extends RecyclerView.Adapter<MeasurementTool
|
|||
l2 = getLocationFromLL(points.get(i).lat, points.get(i).lon);
|
||||
dist += l1.distanceTo(l2);
|
||||
text = OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication())
|
||||
+ BULLET + OsmAndFormatter.getFormattedAzimuth(l1.bearingTo(l2));
|
||||
+ BULLET + OsmAndFormatter.getFormattedAzimuth(l1.bearingTo(l2), mapActivity.getMyApplication());
|
||||
}
|
||||
holder.descr.setText(text);
|
||||
}
|
||||
|
|
|
@ -681,7 +681,7 @@ public class RouteInfoWidgetsFactory {
|
|||
if (degreesChanged(cachedDegrees, b) || modeChanged) {
|
||||
cachedDegrees = b;
|
||||
if (b != -1000) {
|
||||
setText(String.valueOf(b) + "°" + (relative ? "" : " M"), null);
|
||||
setText(OsmAndFormatter.getFormattedAzimuth(b, getOsmandApplication()) + (relative ? "" : " M"), null);
|
||||
} else {
|
||||
setText(null, null);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue