Add descriptions to intermediate points (waypoints)

This commit is contained in:
Victor Shcherb 2012-11-20 20:05:07 +01:00
parent e80304a7f1
commit 981ddd553d
5 changed files with 86 additions and 11 deletions

View file

@ -4,13 +4,19 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical" >
<TextView android:id="@+id/TextView" android:layout_width="fill_parent" android:textSize="18dp" android:layout_height="wrap_content" android:gravity="center" android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:text="@string/recalculate_route_to_your_location"></TextView>
<TextView android:layout_width="fill_parent" android:textSize="18dp" android:layout_height="wrap_content" android:gravity="center" android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:text="@string/recalculate_route_to_your_location"></TextView>
<LinearLayout android:id="@+id/LinearLayout" android:layout_width="fill_parent" android:gravity="center" android:layout_height="wrap_content" android:orientation="horizontal">
<ToggleButton android:contentDescription="@string/app_mode_car" android:textOn="" android:textOff="" android:id="@+id/CarButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/car_icon" android:layout_marginLeft="10dp" />
<ToggleButton android:contentDescription="@string/app_mode_bicycle" android:textOn="" android:textOff="" android:id="@+id/BicycleButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:background="@drawable/bicycle_icon"/>
<ToggleButton android:contentDescription="@string/app_mode_pedestrian" android:textOn="" android:textOff="" android:id="@+id/PedestrianButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:background="@drawable/pedestrian_icon"/>
</LinearLayout>
<ScrollView android:layout_height="wrap_content" android:layout_width="fill_parent"
android:layout_marginTop="5dp" android:layout_marginBottom="5dp" android:layout_marginLeft="10dp">
<TextView android:id="@+id/TextView" android:gravity="left" android:textSize="18dp"
android:layout_height="wrap_content" android:layout_width="fill_parent"
/>
</ScrollView>
<CheckBox android:id="@+id/OptimalCheckox" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/non_optimal_route_calculation"/>

View file

@ -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
-->
<string name="route_descr_lat_lon">Lat %1$.3f lon %2$.3f</string>
<string name="route_descr_current_location">Current location</string>
<string name="route_descr_from_to">From %1$s\nTo %2$s</string>
<string name="route_descr_from_to_via">From : %1$s\nVia : %2$s\nTo : %3$s</string>
<string name="no_buildings_found">No buildings found.</string>
<string name="incremental_search_city">Search city incrementally.</string>
<string name="search_villages_and_postcodes">Search villages/postcode </string>

View file

@ -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<LatLon> ps = getIntermediatePoints();
List<String> 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();
}

View file

@ -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<LatLon> ip = mapLayers.getNavigationLayer().getIntermediatePoints();
if(ip.size() > 0) {

View file

@ -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<String> 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<LatLon> intermediates = new ArrayList<LatLon>(mapActivity.getIntermediatePoints());
final ArrayList<String> names = new ArrayList<String>(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<String> intermediateNames = new ArrayList<String>();
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<String>(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);
}