From 981ddd553d665c3063df41a706c8297b361ee215 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 20 Nov 2012 20:05:07 +0100 Subject: [PATCH] Add descriptions to intermediate points (waypoints) --- OsmAnd/res/layout/calculate_route.xml | 8 +- OsmAnd/res/values/strings.xml | 4 + .../src/net/osmand/plus/OsmandSettings.java | 8 +- .../osmand/plus/activities/MapActivity.java | 4 +- .../plus/activities/MapActivityActions.java | 73 +++++++++++++++++-- 5 files changed, 86 insertions(+), 11 deletions(-) diff --git a/OsmAnd/res/layout/calculate_route.xml b/OsmAnd/res/layout/calculate_route.xml index f146857810..f0f729c144 100644 --- a/OsmAnd/res/layout/calculate_route.xml +++ b/OsmAnd/res/layout/calculate_route.xml @@ -4,13 +4,19 @@ android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > - + + + + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index d546bc0e86..c5436d70ee 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,10 @@ 1. 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 --> + Lat %1$.3f lon %2$.3f + Current location + From %1$s\nTo %2$s + From : %1$s\nVia : %2$s\nTo : %3$s No buildings found. Search city incrementally. Search villages/postcode diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 827e58842c..c55cb894b3 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1057,11 +1057,15 @@ public class OsmandSettings { return list; } - public boolean insertIntermediatePoint(double latitude, double longitude, String historyDescription, int index) { + public boolean insertIntermediatePoint(double latitude, double longitude, String historyDescription, int index, + boolean navigate) { List ps = getIntermediatePoints(); List ds = getIntermediatePointDescriptions(ps.size()); ps.add(index, new LatLon(latitude, longitude)); ds.add(index, historyDescription); + if(navigate) { + globalPreferences.edit().putString(POINT_NAVIGATE_ROUTE, "true").commit(); + } if (historyDescription != null) { SearchHistoryHelper.getInstance().addNewItemToHistory(latitude, longitude, historyDescription, ctx); } @@ -1106,7 +1110,7 @@ public class OsmandSettings { public boolean setPointToNavigate(double latitude, double longitude, boolean navigate, String historyDescription) { boolean add = globalPreferences.edit().putFloat(POINT_NAVIGATE_LAT, (float) latitude).putFloat(POINT_NAVIGATE_LON, (float) longitude).commit(); - globalPreferences.edit().putString(POINT_NAVIGATE_DESCRIPTION, historyDescription); + globalPreferences.edit().putString(POINT_NAVIGATE_DESCRIPTION, historyDescription).commit(); if(navigate) { globalPreferences.edit().putString(POINT_NAVIGATE_ROUTE, "true").commit(); } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index ecfa25ffe2..e2ec769ab1 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -1021,7 +1021,8 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe if(intermediate < 0) { settings.setPointToNavigate(point.getLatitude(), point.getLongitude(), null); } else { - settings.insertIntermediatePoint(point.getLatitude(), point.getLongitude(), null, intermediate); + settings.insertIntermediatePoint(point.getLatitude(), point.getLongitude(), null, + intermediate, false); } } else { settings.clearPointToNavigate(); @@ -1054,6 +1055,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe return mapLayers.getNavigationLayer().getIntermediatePoints(); } + public LatLon getFirstIntermediatePoint(){ List ip = mapLayers.getNavigationLayer().getIntermediatePoints(); if(ip.size() > 0) { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 472d20fe0c..7de75d8c59 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -11,6 +11,7 @@ import java.util.List; import net.londatiga.android.ActionItem; import net.londatiga.android.QuickAction; +import net.osmand.Algoritms; import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; import net.osmand.FavouritePoint; @@ -471,6 +472,48 @@ public class MapActivityActions implements DialogProvider { return true; } + public String getRoutePointDescription(double lat, double lon) { + return mapActivity.getString(R.string.route_descr_lat_lon, lat, lon); + } + + public String getRoutePointDescription(LatLon l, String d) { + if(d != null && d.length() > 0) { + return d.replace(':', ' '); + } + if(l != null) { + return mapActivity.getString(R.string.route_descr_lat_lon, l.getLatitude(), l.getLongitude()); + } + return ""; + } + + public String generateRouteDescription(Location fromOrCurrent, LatLon to) { + String from = mapActivity.getString(R.string.route_descr_current_location); + if (fromOrCurrent != null && fromOrCurrent.getProvider().equals("map")) { + from = getRoutePointDescription(fromOrCurrent.getLatitude(), + fromOrCurrent.getLongitude()); + } + + String tos; + if(to == null) { + tos = getRoutePointDescription(mapActivity.getPointToNavigate(), + settings.getPointNavigateDescription()); + } else { + tos = getRoutePointDescription(to, ""); + } + int sz = mapActivity.getIntermediatePoints().size(); + if(sz == 0) { + return mapActivity.getString(R.string.route_descr_from_to, from, tos); + } else { + String via = ""; + List names = settings.getIntermediatePointDescriptions(sz); + for (int i = 0; i < sz ; i++) { + via += "\n - " + getRoutePointDescription(mapActivity.getIntermediatePoints().get(i), + names.get(i)); + } + return mapActivity.getString(R.string.route_descr_from_to_via, from, via, tos); + } + } + public void getDirections(final Location fromOrCurrent, final LatLon to, boolean gpxRouteEnabled) { @@ -484,6 +527,9 @@ public class MapActivityActions implements DialogProvider { buttons[ApplicationMode.CAR.ordinal()] = (ToggleButton) view.findViewById(R.id.CarButton); buttons[ApplicationMode.BICYCLE.ordinal()] = (ToggleButton) view.findViewById(R.id.BicycleButton); buttons[ApplicationMode.PEDESTRIAN.ordinal()] = (ToggleButton) view.findViewById(R.id.PedestrianButton); + + TextView tv = ((TextView) view.findViewById(R.id.TextView)); + tv.setText(generateRouteDescription(fromOrCurrent, to)); ApplicationMode appMode = settings.getApplicationMode(); if(appMode == ApplicationMode.DEFAULT) { appMode = ApplicationMode.CAR; @@ -1125,17 +1171,29 @@ public class MapActivityActions implements DialogProvider { public void openIntermediatePointsDialog(){ Builder builder = new AlertDialog.Builder(mapActivity); final ArrayList intermediates = new ArrayList(mapActivity.getIntermediatePoints()); + final ArrayList names = new ArrayList(settings.getIntermediatePointDescriptions( + intermediates.size())); final int targetPointInd = mapActivity.getPointToNavigate() == null ? -1 : intermediates.size(); if(mapActivity.getPointToNavigate() != null) { intermediates.add(mapActivity.getPointToNavigate()); + if(settings.getPointNavigateDescription() != null) { + names.add(settings.getPointNavigateDescription()); + } else { + names.add(""); + } } final List intermediateNames = new ArrayList(); double lat = mapActivity.getMapView().getLatitude(); double lon = mapActivity.getMapView().getLongitude(); for (int i = 0; i < intermediates.size(); i++) { double meters = MapUtils.getDistance(intermediates.get(i), lat, lon); - intermediateNames.add((i+1)+". " + - mapActivity.getString(R.string.target_point, OsmAndFormatter.getFormattedDistance((float) meters, mapActivity))+ ""); + String distString = OsmAndFormatter.getFormattedDistance((float) meters, mapActivity); + String nm = (i+1)+". " + mapActivity.getString(R.string.target_point, distString); + String descr = names.get(i); + if(names.get(i) != null && descr.trim().length() > 0) { + nm += "\n" + descr; + } + intermediateNames.add(nm); } final boolean[] checkedIntermediates = new boolean[intermediateNames.size()]; ListAdapter listadapter = new ArrayAdapter(mapActivity, R.layout.layers_list_activity_item, R.id.title, @@ -1328,12 +1386,13 @@ public class MapActivityActions implements DialogProvider { app.getSettings().setPointToNavigate(lat, lon, true, name); } else if(which == 2) { int sz = app.getSettings().getIntermediatePoints().size(); - app.getSettings().insertIntermediatePoint(lat, lon, name, sz); - //LatLon pt = app.getSettings().getPointToNavigate(); -// app.getSettings().insertIntermediatePoint(pt.getLatitude(), pt.getLongitude(), null, sz); - //app.getSettings().setPointToNavigate(lat, lon, true, name); +// app.getSettings().insertIntermediatePoint(lat, lon, name, sz); + LatLon pt = app.getSettings().getPointToNavigate(); + app.getSettings().insertIntermediatePoint(pt.getLatitude(), pt.getLongitude(), + app.getSettings().getPointNavigateDescription(), sz, true); + app.getSettings().setPointToNavigate(lat, lon, true, name); } else { - app.getSettings().insertIntermediatePoint(lat, lon, name, 0); + app.getSettings().insertIntermediatePoint(lat, lon, name, 0, true); } MapActivity.launchMapActivityMoveToTop(activity); }