From 92453b435c7d948917260cbcd39d1e695f24a57f Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 4 Jul 2010 22:07:45 +0000 Subject: [PATCH] fixin small bugs git-svn-id: https://osmand.googlecode.com/svn/trunk@282 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- .../src/com/osmand/ToDoConstants.java | 9 ++- .../src/com/osmand/data/MapObject.java | 2 +- OsmAnd/res/layout/main.xml | 2 +- OsmAnd/res/layout/search_transport.xml | 2 +- OsmAnd/res/menu/map_menu.xml | 5 +- OsmAnd/res/values-ru-rRU/strings.xml | 9 ++- OsmAnd/res/values/strings.xml | 1 + .../com/osmand/activities/MapActivity.java | 4 + .../activities/TransportRouteHelper.java | 23 ++++++ .../activities/search/SearchActivity.java | 2 +- .../search/SearchTransportActivity.java | 75 ++++++++++++------- .../com/osmand/views/TransportStopsLayer.java | 5 +- 12 files changed, 98 insertions(+), 41 deletions(-) create mode 100644 OsmAnd/src/com/osmand/activities/TransportRouteHelper.java diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index c24b67434a..c53201b0d8 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -24,9 +24,7 @@ public class ToDoConstants { // 60. Audio guidance for routing // 61. Provide route information for YOURS (calclate turns/angle/expected time). // Fix some missing turns in CloudMade (for secondary roads wo name). Add them (if dist to prev/next turn > 150m) [dacha] - // 33. Build transport locations. Create transport index (transport-stops) (investigate) - // DONE : Load transport routes in swing, init - // TODO : add show on map key stops, update current stop with gps, add transport activity to map (remove tab) + // 66. Transport routing (show next stop, total distance, show stop get out). @@ -46,6 +44,8 @@ public class ToDoConstants { // FIXME !!!! Check agains ID is not unique ! (for relation/node/way - it could be the same) - checked for data extraction & index creator // REFACTOR Settings activity ( for check box properties!) // Download index show current index information + // Fix bugs with test data (bug with follow turn / left time / add turn) + // Fix description on android // TODO swing // 9. Fix issues with big files (such as netherlands) - save memory (!) - very slow due to transport index ! @@ -57,7 +57,8 @@ public class ToDoConstants { // BUGS Swing // DONE ANDROID : - + // 33. Build transport locations. Create transport index (transport-stops) (investigate) + // Not implemented : show key/transit stops on map, follow mode (show next stop) // DONE SWING diff --git a/DataExtractionOSM/src/com/osmand/data/MapObject.java b/DataExtractionOSM/src/com/osmand/data/MapObject.java index 8a7cc3ad56..a8c5a97e95 100644 --- a/DataExtractionOSM/src/com/osmand/data/MapObject.java +++ b/DataExtractionOSM/src/com/osmand/data/MapObject.java @@ -106,7 +106,7 @@ public abstract class MapObject implements Comparable { @Override public String toString() { - return getClass().getSimpleName() + " " + name +"("+id+")"; + return getClass().getSimpleName() + " " + name +"("+id+")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } } diff --git a/OsmAnd/res/layout/main.xml b/OsmAnd/res/layout/main.xml index 2ea9df1cac..7801fa3403 100644 --- a/OsmAnd/res/layout/main.xml +++ b/OsmAnd/res/layout/main.xml @@ -8,7 +8,7 @@ android:layout_width="100dp" android:layout_height="wrap_content" android:layout_gravity="bottom|right">> - + diff --git a/OsmAnd/res/layout/search_transport.xml b/OsmAnd/res/layout/search_transport.xml index 3d6b6b1ad9..c7b6d2d8a3 100644 --- a/OsmAnd/res/layout/search_transport.xml +++ b/OsmAnd/res/layout/search_transport.xml @@ -13,7 +13,7 @@ android:layout_height="wrap_content" android:layout_below="@+id/listView" > + android:layout_alignParentTop="true" android:layout_height="wrap_content" > diff --git a/OsmAnd/res/menu/map_menu.xml b/OsmAnd/res/menu/map_menu.xml index e092dcb5c7..f41957cb1d 100644 --- a/OsmAnd/res/menu/map_menu.xml +++ b/OsmAnd/res/menu/map_menu.xml @@ -3,11 +3,12 @@ xmlns:android="http://schemas.android.com/apk/res/android"> - - + + + diff --git a/OsmAnd/res/values-ru-rRU/strings.xml b/OsmAnd/res/values-ru-rRU/strings.xml index 01b976f225..5e6b9f558a 100644 --- a/OsmAnd/res/values-ru-rRU/strings.xml +++ b/OsmAnd/res/values-ru-rRU/strings.xml @@ -1,13 +1,14 @@ + Маршруты Остановка остановок Искать транспорт (нет цели) Искать {0} маршрут нету - Искать маршрут после - Искать маршрут до - Остановить поиск + Маршрут после + Маршрут до + Закончить поиск Выберите остановку идти после идти до @@ -146,7 +147,7 @@ Выберите регион Установить расположение текущей позиции на карте Текущая позиция - Перейти к точке + Координаты Показывать угол обзора в соответствии с компасом Угол обзора Снять отметку diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index b8673ca765..ba362988eb 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,5 +1,6 @@ + Routes Stop stops Searching transport (no target) diff --git a/OsmAnd/src/com/osmand/activities/MapActivity.java b/OsmAnd/src/com/osmand/activities/MapActivity.java index 49dc05a991..7f5c2a7381 100644 --- a/OsmAnd/src/com/osmand/activities/MapActivity.java +++ b/OsmAnd/src/com/osmand/activities/MapActivity.java @@ -58,6 +58,7 @@ import com.osmand.Version; import com.osmand.activities.FavouritesActivity.FavouritePoint; import com.osmand.activities.FavouritesActivity.FavouritesDbHelper; import com.osmand.activities.search.SearchActivity; +import com.osmand.activities.search.SearchTransportActivity; import com.osmand.data.Amenity; import com.osmand.data.preparation.MapTileDownloader; import com.osmand.data.preparation.MapTileDownloader.DownloadRequest; @@ -683,6 +684,9 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat Toast.makeText(this, getString(R.string.gps_status_app_not_found), Toast.LENGTH_LONG).show(); } return true; + } else if (item.getItemId() == R.id.map_transport) { + startActivity(new Intent(this, SearchTransportActivity.class)); + return true; } else if (item.getItemId() == R.id.map_mark_point) { contextMenuPoint(mapView.getLatitude(), mapView.getLongitude(), true); return true; diff --git a/OsmAnd/src/com/osmand/activities/TransportRouteHelper.java b/OsmAnd/src/com/osmand/activities/TransportRouteHelper.java new file mode 100644 index 0000000000..72fc1ae741 --- /dev/null +++ b/OsmAnd/src/com/osmand/activities/TransportRouteHelper.java @@ -0,0 +1,23 @@ +package com.osmand.activities; + +import java.util.ArrayList; +import java.util.List; + +import com.osmand.TransportIndexRepository.RouteInfoLocation; + +public class TransportRouteHelper { + private static TransportRouteHelper inst = new TransportRouteHelper(); + public static TransportRouteHelper getInstance(){ + return inst; + } + + private List route = new ArrayList(); + + public List getRoute() { + return route; + } + + public void setRoute(List route) { + this.route = route; + } +} diff --git a/OsmAnd/src/com/osmand/activities/search/SearchActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchActivity.java index 57a76191de..bf2ba90ca4 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchActivity.java @@ -30,7 +30,7 @@ public class SearchActivity extends TabActivity { addressSpec = host.newTabSpec("Search_Address").setIndicator(getString(R.string.address)).setContent(new Intent(this, SearchAddressActivity.class));//$NON-NLS-1$ host.addTab(addressSpec); host.addTab(host.newTabSpec("Search_Location").setIndicator(getString(R.string.search_tabs_location)).setContent(new Intent(this, NavigatePointActivity.class))); //$NON-NLS-1$ - host.addTab(host.newTabSpec("Search_Transport").setIndicator(getString(R.string.transport)).setContent(new Intent(this, SearchTransportActivity.class))); //$NON-NLS-1$ +// host.addTab(host.newTabSpec("Search_Transport").setIndicator(getString(R.string.transport)).setContent(new Intent(this, SearchTransportActivity.class))); //$NON-NLS-1$ host.addTab(host.newTabSpec("Search_History").setIndicator(getString(R.string.history)).setContent(new Intent(this, SearchHistoryActivity.class))); //$NON-NLS-1$ } diff --git a/OsmAnd/src/com/osmand/activities/search/SearchTransportActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchTransportActivity.java index dfe9a064e5..8351a50520 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchTransportActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchTransportActivity.java @@ -25,12 +25,14 @@ import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; +import com.osmand.Algoritms; import com.osmand.Messages; import com.osmand.OsmandSettings; import com.osmand.R; import com.osmand.ResourceManager; import com.osmand.TransportIndexRepository; import com.osmand.TransportIndexRepository.RouteInfoLocation; +import com.osmand.activities.TransportRouteHelper; import com.osmand.data.TransportRoute; import com.osmand.data.TransportStop; import com.osmand.osm.LatLon; @@ -64,7 +66,7 @@ public class SearchTransportActivity extends ListActivity { private TransportRouteAdapter intermediateListAdapater; - private static List lastEditedRoute = new ArrayList(); + @Override public void onCreate(Bundle icicle) { @@ -88,25 +90,37 @@ public class SearchTransportActivity extends ListActivity { ListView intermediateList = (ListView) findViewById(R.id.listView); - intermediateListAdapater = new TransportRouteAdapter(lastEditedRoute); + intermediateListAdapater = new TransportRouteAdapter(TransportRouteHelper.getInstance().getRoute()); intermediateList.setAdapter(intermediateListAdapater); - intermediateListAdapater.add(null); + if(intermediateList.getCount() == 0){ + intermediateListAdapater.add(null); + } - lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(this); - destinationLocation = OsmandSettings.getPointToNavigate(this); - searchTransport(); } @Override protected void onDestroy() { super.onDestroy(); - lastEditedRoute.clear(); + ArrayList lastEditedRoute = new ArrayList(); for(int i= 0; i< intermediateListAdapater.getCount(); i++){ RouteInfoLocation item = intermediateListAdapater.getItem(i); if(item != null){ lastEditedRoute.add(item); } } + TransportRouteHelper.getInstance().setRoute(lastEditedRoute); + } + + @Override + protected void onResume() { + super.onResume(); + if(!Algoritms.objectEquals(OsmandSettings.getLastKnownMapLocation(this), this.lastKnownMapLocation) || + !Algoritms.objectEquals(OsmandSettings.getPointToNavigate(this), this.destinationLocation)){ + lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(this); + destinationLocation = OsmandSettings.getPointToNavigate(this); + searchTransport(); + } + } public String getSearchArea(){ @@ -176,7 +190,8 @@ public class SearchTransportActivity extends ListActivity { for (TransportStop s : stops) { if (s == route.getStart()) { stInd = ind; - } else if (s == route.getStop()) { + } + if (s == route.getStop()) { eInd = ind; } if (ind > stInd && ind <= eInd) { @@ -187,10 +202,17 @@ public class SearchTransportActivity extends ListActivity { text.append(getString(R.string.transport_route_distance)).append(" ").append(MapUtils.getFormattedDistance((int) dist)); //$NON-NLS-1$/ if(!part){ text.append(", ").append(getString(R.string.transport_stops_to_pass)).append(" ").append(eInd - stInd); //$NON-NLS-1$ //$NON-NLS-2$ - String before = MapUtils.getFormattedDistance((int) MapUtils.getDistance(getEndStop(position - 1), route.getStart().getLocation())); - String after = MapUtils.getFormattedDistance((int) MapUtils.getDistance(getStartStop(position + 1), route.getStop().getLocation())); - text.append(", ").append(getString(R.string.transport_to_go_before)).append(" ").append(before).append(", "); //$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-1$ - text.append(getString(R.string.transport_to_go_after)).append(" ").append(after); //$NON-NLS-1$ + LatLon endStop = getEndStop(position - 1); + if (endStop != null) { + String before = MapUtils.getFormattedDistance((int) MapUtils.getDistance(endStop, route.getStart().getLocation())); + text.append(", ").append(getString(R.string.transport_to_go_before)).append(" ").append(before); //$NON-NLS-2$//$NON-NLS-1$ + } + + LatLon stStop = getStartStop(position + 1); + if (stStop != null) { + String after = MapUtils.getFormattedDistance((int) MapUtils.getDistance(stStop, route.getStop().getLocation())); + text.append(", ").append(getString(R.string.transport_to_go_after)).append(" ").append(after); //$NON-NLS-1$ //$NON-NLS-2$ + } } return text.toString(); @@ -218,9 +240,11 @@ public class SearchTransportActivity extends ListActivity { if(locationToGo != null){ n.append(name).append(" - ["); //$NON-NLS-1$ n.append(MapUtils.getFormattedDistance((int) MapUtils.getDistance(locationToGo, st.getLocation()))).append("]"); //$NON-NLS-1$ - } else { + } else if(locationToStart != null){ n.append("[").append(MapUtils.getFormattedDistance((int) MapUtils.getDistance(locationToStart, st.getLocation()))).append("] - "); //$NON-NLS-1$ //$NON-NLS-2$ n.append(name); + } else { + n.append(name); } items.add(n.toString()); } @@ -270,7 +294,7 @@ public class SearchTransportActivity extends ListActivity { public void showContextMenuOnRoute(final RouteInfoLocation route, final int routeInd) { Builder b = new AlertDialog.Builder(this); List stops = route.getDirection() ? route.getRoute().getForwardStops() : route.getRoute().getBackwardStops(); - boolean en = OsmandSettings.isUsingInternetToDownloadTiles(this); + boolean en = OsmandSettings.usingEnglishNames(this); String info = getInformation(route, stops, routeInd, false); StringBuilder txt = new StringBuilder(300); @@ -337,7 +361,6 @@ public class SearchTransportActivity extends ListActivity { return getStartStop(getCurrentRouteLocation() + 1); } - // TODO always check for null public LatLon getStartStop(int position){ if(position == intermediateListAdapater.getCount()){ return destinationLocation; @@ -349,8 +372,6 @@ public class SearchTransportActivity extends ListActivity { return item.getStart().getLocation(); } - - // TODO always check for null public LatLon getEndStop(int position){ if(position == -1){ return lastKnownMapLocation; @@ -417,7 +438,8 @@ public class SearchTransportActivity extends ListActivity { } else { icon.setImageResource(R.drawable.closed_poi); } - int dist = (int) (MapUtils.getDistance(stop.getStart().getLocation(), locationToStart)); + + int dist = locationToStart == null ? 0 : (int) (MapUtils.getDistance(stop.getStart().getLocation(), locationToStart)); distanceLabel.setText(" " + MapUtils.getFormattedDistance(dist)); //$NON-NLS-1$ return (row); @@ -432,13 +454,13 @@ public class SearchTransportActivity extends ListActivity { public View getView(final int position, View convertView, ViewGroup parent) { View row = convertView; - int currentRouteLocation = getCurrentRouteLocation(); - if(position == currentRouteLocation){ + final RouteInfoLocation info = getItem(position); + if(info == null){ TextView text = new TextView(getContext()); LatLon st = getStartStop(position + 1); LatLon end = getEndStop(position - 1); - if(st != null){ + if(st != null && end != null){ int dist = (int) MapUtils.getDistance(st, end); text.setText(MessageFormat.format(getString(R.string.transport_searching_route), MapUtils.getFormattedDistance(dist))); } else { @@ -460,12 +482,12 @@ public class SearchTransportActivity extends ListActivity { }); return text; } - + int currentRouteLocation = getCurrentRouteLocation(); if (row == null || row instanceof TextView) { LayoutInflater inflater = getLayoutInflater(); row = inflater.inflate(R.layout.search_transport_route_item, parent, false); } - final RouteInfoLocation info = getItem(position); + TextView label = (TextView) row.findViewById(R.id.label); ImageButton icon = (ImageButton) row.findViewById(R.id.remove); @@ -482,8 +504,11 @@ public class SearchTransportActivity extends ListActivity { int startDist = (int) MapUtils.getDistance(getEndStop(position - 1), info.getStart().getLocation()); labelW.append(getString(R.string.transport_to_go_before)).append(" ").append(MapUtils.getFormattedDistance(startDist)); //$NON-NLS-1$ if (position == getCount() - 1) { - int endDist = (int) MapUtils.getDistance(getStartStop(position + 1), info.getStop().getLocation()); - labelW.append(", ").append(getString(R.string.transport_to_go_after)).append(" ").append(MapUtils.getFormattedDistance(endDist)); //$NON-NLS-1$ //$NON-NLS-2$ + LatLon stop = getStartStop(position + 1); + if(stop != null) { + int endDist = (int) MapUtils.getDistance(stop, info.getStop().getLocation()); + labelW.append(", ").append(getString(R.string.transport_to_go_after)).append(" ").append(MapUtils.getFormattedDistance(endDist)); //$NON-NLS-1$ //$NON-NLS-2$ + } } labelW.append(")"); //$NON-NLS-1$ diff --git a/OsmAnd/src/com/osmand/views/TransportStopsLayer.java b/OsmAnd/src/com/osmand/views/TransportStopsLayer.java index 803eb20247..4aa81b3488 100644 --- a/OsmAnd/src/com/osmand/views/TransportStopsLayer.java +++ b/OsmAnd/src/com/osmand/views/TransportStopsLayer.java @@ -13,6 +13,7 @@ import android.graphics.RectF; import android.widget.Toast; import com.osmand.OsmandSettings; +import com.osmand.R; import com.osmand.ResourceManager; import com.osmand.TransportIndexRepository; import com.osmand.activities.search.SearchTransportActivity; @@ -76,8 +77,8 @@ public class TransportStopsLayer implements OsmandMapLayer { TransportStop n = getFromPoint(point); if(n != null){ StringBuilder text = new StringBuilder(250); - text.append("Stop").append(" : ").append(n.getName(OsmandSettings.usingEnglishNames(view.getContext()))); //$NON-NLS-2$ - text.append("\n").append("Routes").append(" : "); //$NON-NLS-1$//$NON-NLS-3$ + text.append(view.getContext().getString(R.string.transport_Stop)).append(" : ").append(n.getName(OsmandSettings.usingEnglishNames(view.getContext()))); //$NON-NLS-1$ + text.append("\n").append(view.getContext().getString(R.string.transport_Routes)).append(" : "); //$NON-NLS-1$ //$NON-NLS-2$ List reps = ResourceManager.getResourceManager().searchTransportRepositories(n.getLocation().getLatitude(), n.getLocation().getLongitude()); if(!reps.isEmpty()){ List l;