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

This commit is contained in:
Victor Shcherb 2011-10-04 01:19:45 +02:00
parent 83bd84aff3
commit 795356741e
8 changed files with 91 additions and 47 deletions

View file

@ -12,11 +12,9 @@
<item android:id="@+id/map_mute" android:title="@string/menu_mute_off" android:visible="false"></item> <item android:id="@+id/map_mute" android:title="@string/menu_mute_off" android:visible="false"></item>
<item android:id="@+id/map_get_directions" android:title="@string/get_directions" android:icon="@android:drawable/ic_menu_directions"></item> <item android:id="@+id/map_get_directions" android:title="@string/get_directions" android:icon="@android:drawable/ic_menu_directions"></item>
<item android:id="@+id/map_save_directions" android:title="@string/menu_save_directions" android:icon="@android:drawable/ic_menu_save" visible="false"></item>
<item android:title="@string/context_menu_item_search" android:id="@+id/map_specify_point" android:icon="@android:drawable/ic_menu_search"></item> <item android:title="@string/context_menu_item_search" android:id="@+id/map_specify_point" android:icon="@android:drawable/ic_menu_search"></item>
<item android:title="@string/show_gps_status" android:id="@+id/map_show_gps_status" android:icon="@android:drawable/ic_menu_compass"></item> <item android:title="@string/show_gps_status" android:id="@+id/map_show_gps_status" android:icon="@android:drawable/ic_menu_compass"></item>
<item android:title="@string/map_route_by_gpx" android:id="@+id/map_gpx_routing"></item>
<item android:id="@+id/map_show_point_options" android:title="@string/show_point_options"></item> <item android:id="@+id/map_show_point_options" android:title="@string/show_point_options"></item>
</group> </group>

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?> <?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources> <resources>
<string name="gpx_navigation">GPX route</string>
<string name="poi_query_by_name_matches_categories">Some poi categories matching to the query were found :</string> <string name="poi_query_by_name_matches_categories">Some poi categories matching to the query were found :</string>
<string name="data_to_search_poi_not_available">Local data to search POI is not present.</string> <string name="data_to_search_poi_not_available">Local data to search POI is not present.</string>
<string name="poi_filter_by_name">Search by name</string> <string name="poi_filter_by_name">Search by name</string>

View file

@ -83,9 +83,9 @@ public class AsyncLoadingThread extends Thread {
progress = BusyIndicator.STATUS_BLUE; progress = BusyIndicator.STATUS_BLUE;
} else if (!requests.isEmpty()) { } else if (!requests.isEmpty()) {
progress = BusyIndicator.STATUS_BLACK; progress = BusyIndicator.STATUS_BLACK;
} else if(poiLoadRequest != null && !poiLoadRequest.isFinished()) { } else if(poiLoadRequest != null && poiLoadRequest.isRunning()) {
progress = BusyIndicator.STATUS_BLACK; progress = BusyIndicator.STATUS_BLACK;
} else if(transportLoadRequest != null && !transportLoadRequest.isFinished()) { } else if(transportLoadRequest != null && transportLoadRequest.isRunning()) {
progress = BusyIndicator.STATUS_BLACK; progress = BusyIndicator.STATUS_BLACK;
} }
return progress; return progress;
@ -211,7 +211,7 @@ public class AsyncLoadingThread extends Thread {
protected double leftLongitude; protected double leftLongitude;
protected double rightLongitude; protected double rightLongitude;
protected boolean cancelled = false; 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) { public boolean isContains(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude) {
boolean inside = this.topLatitude >= topLatitude && this.leftLongitude <= leftLongitude boolean inside = this.topLatitude >= topLatitude && this.leftLongitude <= leftLongitude
@ -226,12 +226,16 @@ public class AsyncLoadingThread extends Thread {
this.rightLongitude = rightLongitude; this.rightLongitude = rightLongitude;
} }
public boolean isFinished() { public boolean isRunning() {
return finished; return running && !cancelled;
}
public void start() {
running = true;
} }
public void finish() { public void finish() {
finished = true; running = false;
// use downloader callback // use downloader callback
for (IMapDownloaderCallback c : downloader.getDownloaderCallbacks()) { for (IMapDownloaderCallback c : downloader.getDownloaderCallbacks()) {
c.tileDownloaded(null); c.tileDownloaded(null);
@ -271,12 +275,16 @@ public class AsyncLoadingThread extends Thread {
return new Runnable() { return new Runnable() {
@Override @Override
public void run() { public void run() {
start();
try {
for (AmenityIndexRepository repository : res) { for (AmenityIndexRepository repository : res) {
repository.evaluateCachedAmenities(ntopLatitude, nleftLongitude, nbottomLatitude, nrightLongitude, zoom, filter, repository.evaluateCachedAmenities(ntopLatitude, nleftLongitude, nbottomLatitude, nrightLongitude, zoom,
AmenityLoadRequest.this); filter, AmenityLoadRequest.this);
} }
} finally {
finish(); finish();
} }
}
}; };
} }
@ -308,12 +316,16 @@ public class AsyncLoadingThread extends Thread {
return new Runnable() { return new Runnable() {
@Override @Override
public void run() { public void run() {
start();
try {
for (TransportIndexRepository repository : repos) { for (TransportIndexRepository repository : repos) {
repository.evaluateCachedTransportStops(ntopLatitude, nleftLongitude, nbottomLatitude, nrightLongitude, zoom, repository.evaluateCachedTransportStops(ntopLatitude, nleftLongitude, nbottomLatitude, nrightLongitude, zoom,
LIMIT_TRANSPORT, TransportLoadRequest.this); LIMIT_TRANSPORT, TransportLoadRequest.this);
} }
} finally {
finish(); finish();
} }
}
}; };
} }

View file

@ -121,10 +121,10 @@ public class TransportIndexRepositoryBinary implements TransportIndexRepository
@Override @Override
public void evaluateCachedTransportStops(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, public void evaluateCachedTransportStops(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude,
int zoom, int limit, ResultMatcher<TransportStop> matcher) { int zoom, int limit, ResultMatcher<TransportStop> matcher) {
cTopLatitude = topLatitude + (topLatitude - bottomLatitude); cTopLatitude = topLatitude ;
cBottomLatitude = bottomLatitude - (topLatitude - bottomLatitude); cBottomLatitude = bottomLatitude ;
cLeftLongitude = leftLongitude - (rightLongitude - leftLongitude); cLeftLongitude = leftLongitude ;
cRightLongitude = rightLongitude + (rightLongitude - leftLongitude); cRightLongitude = rightLongitude ;
cZoom = zoom; cZoom = zoom;
// first of all put all entities in temp list in order to not freeze other read threads // first of all put all entities in temp list in order to not freeze other read threads
ArrayList<TransportStop> tempList = new ArrayList<TransportStop>(); ArrayList<TransportStop> tempList = new ArrayList<TransportStop>();

View file

@ -961,9 +961,11 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
muteMenu.setVisible(false); muteMenu.setVisible(false);
} }
} }
MenuItem saveMenu = menu.findItem(R.id.map_save_directions); MenuItem directions = menu.findItem(R.id.map_get_directions);
if(saveMenu != null){ if(routingHelper.isRouteCalculated()){
saveMenu.setVisible(routingHelper.isRouteCalculated()); directions.setTitle(R.string.show_route);
} else {
directions.setTitle(R.string.get_directions);
} }
return val; return val;
@ -984,19 +986,20 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
startGpsStatusIntent(); startGpsStatusIntent();
return true; return true;
case R.id.map_get_directions: case R.id.map_get_directions:
if(routingHelper.isRouteCalculated()){
mapActions.aboutRoute();
} else {
Location loc = getLastKnownLocation(); Location loc = getLastKnownLocation();
if(loc != null){ if (loc != null) {
mapActions.getDirections(loc.getLatitude(), loc.getLongitude(), true); mapActions.getDirections(loc.getLatitude(), loc.getLongitude(), true);
} else { } else {
mapActions.getDirections(mapView.getLatitude(), mapView.getLongitude(), true); mapActions.getDirections(mapView.getLatitude(), mapView.getLongitude(), true);
} }
}
return true; return true;
case R.id.map_layers: case R.id.map_layers:
mapLayers.openLayerSelectionDialog(mapView); mapLayers.openLayerSelectionDialog(mapView);
return true; return true;
case R.id.map_save_directions :
mapActions.saveDirections();
return true;
case R.id.map_specify_point: case R.id.map_specify_point:
// next 2 lines replaced for Issue 493, replaced by new 3 lines // next 2 lines replaced for Issue 493, replaced by new 3 lines
// NavigatePointActivity dlg = new NavigatePointActivity(this); // NavigatePointActivity dlg = new NavigatePointActivity(this);
@ -1025,9 +1028,6 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
} }
mapView.refreshMap(); mapView.refreshMap();
return true; return true;
case R.id.map_gpx_routing:
mapActions.navigateUsingGPX();
return true;
case R.id.map_show_point_options: case R.id.map_show_point_options:
contextMenuPoint(mapView.getLatitude(), mapView.getLongitude()); contextMenuPoint(mapView.getLatitude(), mapView.getLongitude());
return true; return true;
@ -1140,7 +1140,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
if(standardId == R.string.context_menu_item_navigate_point){ if(standardId == R.string.context_menu_item_navigate_point){
navigateToPoint(new LatLon(latitude, longitude)); navigateToPoint(new LatLon(latitude, longitude));
} else if(standardId == R.string.context_menu_item_show_route){ } 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){ } else if(standardId == R.string.context_menu_item_search){
Intent intent = new Intent(MapActivity.this, SearchActivity.class); Intent intent = new Intent(MapActivity.this, SearchActivity.class);
intent.putExtra(SearchActivity.SEARCH_LAT, latitude); intent.putExtra(SearchActivity.SEARCH_LAT, latitude);

View file

@ -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){ protected void getDirections(final double lat, final double lon, boolean followEnabled){
MapActivityLayers mapLayers = mapActivity.getMapLayers(); MapActivityLayers mapLayers = mapActivity.getMapLayers();
final OsmandSettings settings = OsmandSettings.getOsmandSettings(mapActivity); final OsmandSettings settings = OsmandSettings.getOsmandSettings(mapActivity);
@ -393,12 +417,13 @@ public class MapActivityActions {
getMyApplication().showDialogInitializingCommandPlayer(mapActivity); getMyApplication().showDialogInitializingCommandPlayer(mapActivity);
} }
}; };
DialogInterface.OnClickListener showRoute = new DialogInterface.OnClickListener(){
DialogInterface.OnClickListener useGpxNavigation = new DialogInterface.OnClickListener(){
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(mapActivity, ShowRouteInfoActivity.class); ApplicationMode mode = getAppMode(buttons, settings);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); navigateUsingGPX(mode);
mapActivity.startActivity(intent);
} }
}; };
@ -406,9 +431,7 @@ public class MapActivityActions {
if (followEnabled) { if (followEnabled) {
builder.setTitle(R.string.follow_route); builder.setTitle(R.string.follow_route);
builder.setPositiveButton(R.string.follow, followCall); builder.setPositiveButton(R.string.follow, followCall);
if (routingHelper.isRouterEnabled() && routingHelper.isRouteCalculated()) { builder.setNeutralButton(R.string.gpx_navigation, useGpxNavigation);
builder.setNeutralButton(R.string.route_about, showRoute);
}
builder.setNegativeButton(R.string.only_show, onlyShowCall); builder.setNegativeButton(R.string.only_show, onlyShowCall);
} else { } else {
builder.setTitle(R.string.show_route); builder.setTitle(R.string.show_route);
@ -433,7 +456,7 @@ public class MapActivityActions {
return location; return location;
} }
public void navigateUsingGPX() { public void navigateUsingGPX(final ApplicationMode appMode) {
final LatLon endForRouting = mapActivity.getPointToNavigate(); final LatLon endForRouting = mapActivity.getPointToNavigate();
final MapActivityLayers mapLayers = mapActivity.getMapLayers(); final MapActivityLayers mapLayers = mapActivity.getMapLayers();
final OsmandSettings settings = OsmandSettings.getOsmandSettings(mapActivity); final OsmandSettings settings = OsmandSettings.getOsmandSettings(mapActivity);
@ -481,6 +504,11 @@ public class MapActivityActions {
mapLayers.getNavigationLayer().setPointToNavigate(point); mapLayers.getNavigationLayer().setPointToNavigate(point);
} }
} }
// change global settings
boolean changed = settings.APPLICATION_MODE.set(appMode);
if (changed) {
mapActivity.updateApplicationModeSettings();
}
mapActivity.getMapView().refreshMap(); mapActivity.getMapView().refreshMap();
if(endPoint != null){ if(endPoint != null){
settings.FOLLOW_THE_ROUTE.set(true); settings.FOLLOW_THE_ROUTE.set(true);

View file

@ -1,5 +1,6 @@
package net.osmand.plus.activities; package net.osmand.plus.activities;
import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -370,6 +371,14 @@ public class RoutingHelper {
return 0; 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){ public Location getLocationFromRouteDirection(RouteDirectionInfo i){
if(i.routePointOffset < routeNodes.size()){ if(i.routePointOffset < routeNodes.size()){
return routeNodes.get(i.routePointOffset); return routeNodes.get(i.routePointOffset);

View file

@ -60,11 +60,7 @@ public class ShowRouteInfoActivity extends ListActivity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
int dist = helper.getLeftDistance(); header.setText(helper.getGeneralRouteInformation());
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));
float f = Math.min(dm.widthPixels/(dm.density*160),dm.heightPixels/(dm.density*160)); float f = Math.min(dm.widthPixels/(dm.density*160),dm.heightPixels/(dm.density*160));
if (f >= 3) { if (f >= 3) {
// large screen // large screen