From 9a909cc6c3ae16906c60910f277f268728303ade Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Fri, 1 Jul 2016 18:58:43 +0300 Subject: [PATCH] Fix #2680 --- OsmAnd/res/values/strings.xml | 2 + OsmAnd/res/xml/general_settings.xml | 3 +- .../src/net/osmand/data/PointDescription.java | 17 ++++++- .../activities/NavigatePointFragment.java | 51 ++++++++----------- .../activities/SettingsGeneralActivity.java | 13 +++++ 5 files changed, 53 insertions(+), 33 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 19331ffff3..2c74a54c4d 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,8 @@ 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 --> + Coordinate format + Format for the geographical coordinates Bus Train Current track diff --git a/OsmAnd/res/xml/general_settings.xml b/OsmAnd/res/xml/general_settings.xml index fe4923c7a2..e93c371faa 100644 --- a/OsmAnd/res/xml/general_settings.xml +++ b/OsmAnd/res/xml/general_settings.xml @@ -9,7 +9,8 @@ - + + diff --git a/OsmAnd/src/net/osmand/data/PointDescription.java b/OsmAnd/src/net/osmand/data/PointDescription.java index 81a316d4a3..a75f8f2962 100644 --- a/OsmAnd/src/net/osmand/data/PointDescription.java +++ b/OsmAnd/src/net/osmand/data/PointDescription.java @@ -303,7 +303,22 @@ public class PointDescription { public static final int FORMAT_SECONDS = 2; public static final int UTM_FORMAT = 3; private static final char DELIM = ':'; - + + public static String formatToHumanString(Context ctx, int format) { + switch (format) { + case FORMAT_DEGREES: + return ctx.getString(R.string.navigate_point_format_D); + case FORMAT_MINUTES: + return ctx.getString(R.string.navigate_point_format_DM); + case FORMAT_SECONDS: + return ctx.getString(R.string.navigate_point_format_DMS); + case UTM_FORMAT: + return "UTM"; + default: + return "Unknown format"; + } + } + /** * Converts a String in one of the formats described by * FORMAT_DEGREES, FORMAT_MINUTES, or FORMAT_SECONDS into a diff --git a/OsmAnd/src/net/osmand/plus/activities/NavigatePointFragment.java b/OsmAnd/src/net/osmand/plus/activities/NavigatePointFragment.java index a7fa1b856c..ce36ba4797 100644 --- a/OsmAnd/src/net/osmand/plus/activities/NavigatePointFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/NavigatePointFragment.java @@ -1,19 +1,5 @@ package net.osmand.plus.activities; -import net.osmand.PlatformUtil; -import net.osmand.data.LatLon; -import net.osmand.data.PointDescription; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.R; -import net.osmand.plus.TargetPointsHelper; -import net.osmand.plus.activities.search.SearchActivity; -import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild; -import net.osmand.plus.dialogs.DirectionsDialogs; -import net.osmand.plus.dialogs.FavoriteDialogs; -import net.osmand.plus.helpers.AndroidUiHelper; -import net.osmand.util.Algorithms; -import net.osmand.util.MapUtils; -import android.app.Dialog; import android.content.Intent; import android.location.Location; import android.os.Bundle; @@ -37,16 +23,22 @@ import android.widget.TextView; import com.jwetherell.openmap.common.LatLonPoint; import com.jwetherell.openmap.common.UTMPoint; +import net.osmand.PlatformUtil; +import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.activities.search.SearchActivity; +import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild; +import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.util.Algorithms; +import net.osmand.util.MapUtils; + public class NavigatePointFragment extends Fragment implements SearchActivityChild { int currentFormat = Location.FORMAT_DEGREES; public static final String SEARCH_LAT = SearchActivity.SEARCH_LAT; public static final String SEARCH_LON = SearchActivity.SEARCH_LON; - public static final String SEARCH_NORTHING = "NORTHING"; - public static final String SEARCH_EASTING = "EASTING"; - public static final String SEARCH_ZONE = "ZONE"; - private static final String SELECTION = "SELECTION"; - private static final int SHOW_ON_MAP = 3; @@ -82,8 +74,6 @@ public class NavigatePointFragment extends Fragment implements SearchActivityChi String lat = savedInstanceState.getString(SEARCH_LAT); String lon = savedInstanceState.getString(SEARCH_LON); if(lat != null && lon != null && lat.length() > 0 && lon.length() > 0) { - ((Spinner)view.findViewById(R.id.Format)).setSelection(savedInstanceState.getInt(SELECTION, 0)); - currentFormat = savedInstanceState.getInt(SELECTION, 0); ((TextView)view.findViewById(R.id.LatitudeEdit)).setText(lat); ((TextView)view.findViewById(R.id.LongitudeEdit)).setText(lon); } @@ -99,7 +89,6 @@ public class NavigatePointFragment extends Fragment implements SearchActivityChi final TextView lonEdit = ((TextView)view.findViewById(R.id.LongitudeEdit)); outState.putString(SEARCH_LAT, latEdit.getText().toString()); outState.putString(SEARCH_LON, lonEdit.getText().toString()); - outState.putInt(SELECTION, ((Spinner)view.findViewById(R.id.Format)).getSelectedItemPosition()); } } @@ -205,27 +194,27 @@ public class NavigatePointFragment extends Fragment implements SearchActivityChi showCurrentFormat(new LatLon(latitude, longitude)); final Spinner format = ((Spinner)view.findViewById(R.id.Format)); ArrayAdapter adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_spinner_item, new String[] { - getString(R.string.navigate_point_format_D), - getString(R.string.navigate_point_format_DM), - getString(R.string.navigate_point_format_DMS), - "UTM" + PointDescription.formatToHumanString(this.getContext(), PointDescription.FORMAT_DEGREES), + PointDescription.formatToHumanString(this.getContext(), PointDescription.FORMAT_MINUTES), + PointDescription.formatToHumanString(this.getContext(), PointDescription.FORMAT_SECONDS), + PointDescription.formatToHumanString(this.getContext(), PointDescription.UTM_FORMAT), }); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); format.setAdapter(adapter); - format.setSelection(0); + format.setSelection(currentFormat); format.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View v, int position, long id) { int newFormat = currentFormat; String itm = (String) format.getItemAtPosition(position); - if(getString(R.string.navigate_point_format_D).equals(itm)){ + if (PointDescription.formatToHumanString(v.getContext(), PointDescription.FORMAT_DEGREES).equals(itm)) { newFormat = PointDescription.FORMAT_DEGREES; - } else if(getString(R.string.navigate_point_format_DM).equals(itm)){ + } else if (PointDescription.formatToHumanString(v.getContext(), PointDescription.FORMAT_MINUTES).equals(itm)) { newFormat = PointDescription.FORMAT_MINUTES; - } else if(getString(R.string.navigate_point_format_DMS).equals(itm)){ + } else if (PointDescription.formatToHumanString(v.getContext(), PointDescription.FORMAT_SECONDS).equals(itm)) { newFormat = PointDescription.FORMAT_SECONDS; - } else if (position == PointDescription.UTM_FORMAT) { + } else if (PointDescription.formatToHumanString(v.getContext(), PointDescription.UTM_FORMAT).equals(itm)) { newFormat = PointDescription.UTM_FORMAT; } try { diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java index 2f69799bda..0e42c0d300 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java @@ -28,6 +28,7 @@ import android.widget.Toast; import net.osmand.IProgress; import net.osmand.IndexConstants; +import net.osmand.data.PointDescription; import net.osmand.osm.io.NetworkUtils; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; @@ -150,6 +151,18 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR } registerListPreference(settings.METRIC_SYSTEM, screen, entries, mvls); + Integer[] cvls = new Integer[4]; + cvls[0] = PointDescription.FORMAT_DEGREES; + cvls[1] = PointDescription.FORMAT_MINUTES; + cvls[2] = PointDescription.FORMAT_SECONDS; + cvls[3] = PointDescription.UTM_FORMAT; + entries = new String[4]; + entries[0] = PointDescription.formatToHumanString(this, PointDescription.FORMAT_DEGREES); + entries[1] = PointDescription.formatToHumanString(this, PointDescription.FORMAT_MINUTES); + entries[2] = PointDescription.formatToHumanString(this, PointDescription.FORMAT_SECONDS); + entries[3] = PointDescription.formatToHumanString(this, PointDescription.UTM_FORMAT); + registerListPreference(settings.COORDINATES_FORMAT, screen, entries, cvls); + // 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)