From 795356741ebe6c9418bbd1e1194d4ba1d69608a2 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 4 Oct 2011 01:19:45 +0200 Subject: [PATCH] Update menu of Route (Route has 3 options : GPX, Follow and Show; If route calculated Route -> About Route and has 3 options : Save route, About route and close --- OsmAnd/res/menu/map_menu.xml | 2 - OsmAnd/res/values/strings.xml | 1 + .../net/osmand/plus/AsyncLoadingThread.java | 40 +++++++++++------ .../plus/TransportIndexRepositoryBinary.java | 8 ++-- .../osmand/plus/activities/MapActivity.java | 28 ++++++------ .../plus/activities/MapActivityActions.java | 44 +++++++++++++++---- .../osmand/plus/activities/RoutingHelper.java | 9 ++++ .../activities/ShowRouteInfoActivity.java | 6 +-- 8 files changed, 91 insertions(+), 47 deletions(-) diff --git a/OsmAnd/res/menu/map_menu.xml b/OsmAnd/res/menu/map_menu.xml index 2fa2b87f62..110ca47a57 100644 --- a/OsmAnd/res/menu/map_menu.xml +++ b/OsmAnd/res/menu/map_menu.xml @@ -12,11 +12,9 @@ - - diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 2324b62ac9..69b32fcfc8 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,5 +1,6 @@ + GPX route Some poi categories matching to the query were found : Local data to search POI is not present. Search by name diff --git a/OsmAnd/src/net/osmand/plus/AsyncLoadingThread.java b/OsmAnd/src/net/osmand/plus/AsyncLoadingThread.java index 878643e072..9c82329d07 100644 --- a/OsmAnd/src/net/osmand/plus/AsyncLoadingThread.java +++ b/OsmAnd/src/net/osmand/plus/AsyncLoadingThread.java @@ -83,9 +83,9 @@ public class AsyncLoadingThread extends Thread { progress = BusyIndicator.STATUS_BLUE; } else if (!requests.isEmpty()) { progress = BusyIndicator.STATUS_BLACK; - } else if(poiLoadRequest != null && !poiLoadRequest.isFinished()) { + } else if(poiLoadRequest != null && poiLoadRequest.isRunning()) { progress = BusyIndicator.STATUS_BLACK; - } else if(transportLoadRequest != null && !transportLoadRequest.isFinished()) { + } else if(transportLoadRequest != null && transportLoadRequest.isRunning()) { progress = BusyIndicator.STATUS_BLACK; } return progress; @@ -211,7 +211,7 @@ public class AsyncLoadingThread extends Thread { protected double leftLongitude; protected double rightLongitude; protected boolean cancelled = false; - protected volatile boolean finished = false; + protected volatile boolean running = false; public boolean isContains(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude) { boolean inside = this.topLatitude >= topLatitude && this.leftLongitude <= leftLongitude @@ -226,12 +226,16 @@ public class AsyncLoadingThread extends Thread { this.rightLongitude = rightLongitude; } - public boolean isFinished() { - return finished; + public boolean isRunning() { + return running && !cancelled; + } + + public void start() { + running = true; } public void finish() { - finished = true; + running = false; // use downloader callback for (IMapDownloaderCallback c : downloader.getDownloaderCallbacks()) { c.tileDownloaded(null); @@ -271,11 +275,15 @@ public class AsyncLoadingThread extends Thread { return new Runnable() { @Override public void run() { - for (AmenityIndexRepository repository : res) { - repository.evaluateCachedAmenities(ntopLatitude, nleftLongitude, nbottomLatitude, nrightLongitude, zoom, filter, - AmenityLoadRequest.this); + start(); + try { + for (AmenityIndexRepository repository : res) { + repository.evaluateCachedAmenities(ntopLatitude, nleftLongitude, nbottomLatitude, nrightLongitude, zoom, + filter, AmenityLoadRequest.this); + } + } finally { + finish(); } - finish(); } }; } @@ -308,11 +316,15 @@ public class AsyncLoadingThread extends Thread { return new Runnable() { @Override public void run() { - for (TransportIndexRepository repository : repos) { - repository.evaluateCachedTransportStops(ntopLatitude, nleftLongitude, nbottomLatitude, nrightLongitude, zoom, - LIMIT_TRANSPORT, TransportLoadRequest.this); + start(); + try { + for (TransportIndexRepository repository : repos) { + repository.evaluateCachedTransportStops(ntopLatitude, nleftLongitude, nbottomLatitude, nrightLongitude, zoom, + LIMIT_TRANSPORT, TransportLoadRequest.this); + } + } finally { + finish(); } - finish(); } }; } diff --git a/OsmAnd/src/net/osmand/plus/TransportIndexRepositoryBinary.java b/OsmAnd/src/net/osmand/plus/TransportIndexRepositoryBinary.java index 0ebe8ae508..918f5356cf 100644 --- a/OsmAnd/src/net/osmand/plus/TransportIndexRepositoryBinary.java +++ b/OsmAnd/src/net/osmand/plus/TransportIndexRepositoryBinary.java @@ -121,10 +121,10 @@ public class TransportIndexRepositoryBinary implements TransportIndexRepository @Override public void evaluateCachedTransportStops(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, int limit, ResultMatcher matcher) { - cTopLatitude = topLatitude + (topLatitude - bottomLatitude); - cBottomLatitude = bottomLatitude - (topLatitude - bottomLatitude); - cLeftLongitude = leftLongitude - (rightLongitude - leftLongitude); - cRightLongitude = rightLongitude + (rightLongitude - leftLongitude); + cTopLatitude = topLatitude ; + cBottomLatitude = bottomLatitude ; + cLeftLongitude = leftLongitude ; + cRightLongitude = rightLongitude ; cZoom = zoom; // first of all put all entities in temp list in order to not freeze other read threads ArrayList tempList = new ArrayList(); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 7cfcf704fb..5852e2a87a 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -961,9 +961,11 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso muteMenu.setVisible(false); } } - MenuItem saveMenu = menu.findItem(R.id.map_save_directions); - if(saveMenu != null){ - saveMenu.setVisible(routingHelper.isRouteCalculated()); + MenuItem directions = menu.findItem(R.id.map_get_directions); + if(routingHelper.isRouteCalculated()){ + directions.setTitle(R.string.show_route); + } else { + directions.setTitle(R.string.get_directions); } return val; @@ -984,19 +986,20 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso startGpsStatusIntent(); return true; case R.id.map_get_directions: - Location loc = getLastKnownLocation(); - if(loc != null){ - mapActions.getDirections(loc.getLatitude(), loc.getLongitude(), true); + if(routingHelper.isRouteCalculated()){ + mapActions.aboutRoute(); } else { - mapActions.getDirections(mapView.getLatitude(), mapView.getLongitude(), true); + Location loc = getLastKnownLocation(); + if (loc != null) { + mapActions.getDirections(loc.getLatitude(), loc.getLongitude(), true); + } else { + mapActions.getDirections(mapView.getLatitude(), mapView.getLongitude(), true); + } } return true; case R.id.map_layers: mapLayers.openLayerSelectionDialog(mapView); return true; - case R.id.map_save_directions : - mapActions.saveDirections(); - return true; case R.id.map_specify_point: // next 2 lines replaced for Issue 493, replaced by new 3 lines // NavigatePointActivity dlg = new NavigatePointActivity(this); @@ -1025,9 +1028,6 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso } mapView.refreshMap(); return true; - case R.id.map_gpx_routing: - mapActions.navigateUsingGPX(); - return true; case R.id.map_show_point_options: contextMenuPoint(mapView.getLatitude(), mapView.getLongitude()); return true; @@ -1140,7 +1140,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso if(standardId == R.string.context_menu_item_navigate_point){ navigateToPoint(new LatLon(latitude, longitude)); } else if(standardId == R.string.context_menu_item_show_route){ - mapActions. getDirections(latitude, longitude, false); + mapActions.getDirections(latitude, longitude, false); } else if(standardId == R.string.context_menu_item_search){ Intent intent = new Intent(MapActivity.this, SearchActivity.class); intent.putExtra(SearchActivity.SEARCH_LAT, latitude); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 7109193492..97152c3654 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -303,6 +303,30 @@ public class MapActivityActions { } + protected void aboutRoute() { + DialogInterface.OnClickListener showRoute = new DialogInterface.OnClickListener(){ + @Override + public void onClick(DialogInterface dialog, int which) { + Intent intent = new Intent(mapActivity, ShowRouteInfoActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + mapActivity.startActivity(intent); + } + }; + DialogInterface.OnClickListener saveDirections = new DialogInterface.OnClickListener(){ + @Override + public void onClick(DialogInterface dialog, int which) { + saveDirections(); + } + }; + Builder builder = new AlertDialog.Builder(mapActivity); + builder.setTitle(R.string.show_route); + builder.setMessage(mapActivity.getRoutingHelper().getGeneralRouteInformation()); + builder.setPositiveButton(R.string.default_buttons_save, saveDirections); + builder.setNeutralButton(R.string.route_about, showRoute); + builder.setNegativeButton(R.string.close, null); + builder.show(); + } + protected void getDirections(final double lat, final double lon, boolean followEnabled){ MapActivityLayers mapLayers = mapActivity.getMapLayers(); final OsmandSettings settings = OsmandSettings.getOsmandSettings(mapActivity); @@ -393,12 +417,13 @@ public class MapActivityActions { getMyApplication().showDialogInitializingCommandPlayer(mapActivity); } }; - DialogInterface.OnClickListener showRoute = new DialogInterface.OnClickListener(){ + + + DialogInterface.OnClickListener useGpxNavigation = new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { - Intent intent = new Intent(mapActivity, ShowRouteInfoActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - mapActivity.startActivity(intent); + ApplicationMode mode = getAppMode(buttons, settings); + navigateUsingGPX(mode); } }; @@ -406,9 +431,7 @@ public class MapActivityActions { if (followEnabled) { builder.setTitle(R.string.follow_route); builder.setPositiveButton(R.string.follow, followCall); - if (routingHelper.isRouterEnabled() && routingHelper.isRouteCalculated()) { - builder.setNeutralButton(R.string.route_about, showRoute); - } + builder.setNeutralButton(R.string.gpx_navigation, useGpxNavigation); builder.setNegativeButton(R.string.only_show, onlyShowCall); } else { builder.setTitle(R.string.show_route); @@ -433,7 +456,7 @@ public class MapActivityActions { return location; } - public void navigateUsingGPX() { + public void navigateUsingGPX(final ApplicationMode appMode) { final LatLon endForRouting = mapActivity.getPointToNavigate(); final MapActivityLayers mapLayers = mapActivity.getMapLayers(); final OsmandSettings settings = OsmandSettings.getOsmandSettings(mapActivity); @@ -481,6 +504,11 @@ public class MapActivityActions { mapLayers.getNavigationLayer().setPointToNavigate(point); } } + // change global settings + boolean changed = settings.APPLICATION_MODE.set(appMode); + if (changed) { + mapActivity.updateApplicationModeSettings(); + } mapActivity.getMapView().refreshMap(); if(endPoint != null){ settings.FOLLOW_THE_ROUTE.set(true); diff --git a/OsmAnd/src/net/osmand/plus/activities/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/activities/RoutingHelper.java index b666f1aea2..7850987252 100644 --- a/OsmAnd/src/net/osmand/plus/activities/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/RoutingHelper.java @@ -1,5 +1,6 @@ package net.osmand.plus.activities; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -370,6 +371,14 @@ public class RoutingHelper { return 0; } + public String getGeneralRouteInformation(){ + int dist = getLeftDistance(); + int hours = getLeftTime() / (60 * 60); + int minutes = (getLeftTime() / 60) % 60; + return MessageFormat.format(context.getString(R.string.route_general_information), OsmAndFormatter.getFormattedDistance(dist, context), + hours, minutes); + } + public Location getLocationFromRouteDirection(RouteDirectionInfo i){ if(i.routePointOffset < routeNodes.size()){ return routeNodes.get(i.routePointOffset); diff --git a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java index 1cd8605024..426666a733 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java @@ -60,11 +60,7 @@ public class ShowRouteInfoActivity extends ListActivity { @Override protected void onResume() { super.onResume(); - int dist = helper.getLeftDistance(); - int hours = helper.getLeftTime() / (60 * 60); - int minutes = (helper.getLeftTime() / 60) % 60; - header.setText(MessageFormat.format(getString(R.string.route_general_information), OsmAndFormatter.getFormattedDistance(dist, this), - hours, minutes)); + header.setText(helper.getGeneralRouteInformation()); float f = Math.min(dm.widthPixels/(dm.density*160),dm.heightPixels/(dm.density*160)); if (f >= 3) { // large screen