implement some fixes

git-svn-id: https://osmand.googlecode.com/svn/trunk@364 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-07-19 07:10:27 +00:00
parent 25c8c96c08
commit fb49f25a33
6 changed files with 87 additions and 40 deletions

View file

@ -24,11 +24,18 @@ public class ToDoConstants {
// Improvement : download with wget
// Improvement : cloudmade as map?
// Yandex traffic : http://jgo.maps.yandex.net/tiles?l=trf
// Improvement : show route info after route is calculated and/or calculate route from context menu
// (continue follow previous route)
// Improvement : show route info (directly after route is calc & do not show if it is not calc)
// FIXME
// 1. Bug with duplicated turns
// 2. Bug with network location while routing (?)
// 2. Bug with network location while routing (?) - fixed ?
// 3. TODO options : using trackball as an option
// 4. Add last turn as go straight (+)
// 5. After return if there was previous route (countinue follow)
// 6. Bug 13.
// Not clear if it is really needed
@ -56,18 +63,7 @@ public class ToDoConstants {
// BUGS Swing
// DONE ANDROID :
// 43. Enable poi filter by name (find lake by name or shop) - case sensitive search DB - make only search filter (on UI)!
// 45. Get clear <Use internet> settings. Move that setting on top settings screen.
// That setting should rule all activities that use internet. It should ask whenever internet is used
// (would you like to use internet for that operation - if using internet is not checked).
// Internet using now for : edit POI osm, show osm bugs layer, download tiles - not needed.
// 58. Upload/Download zip-index from site & unzip them on phone
// 69. Multitouch zoom, animated zoom, animate map shift (when select some point to see)!
// 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)
// Not implemented : show key/transit stops on map, follow mode (show next stop)
// DONE SWING

View file

@ -8,9 +8,11 @@ import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.widget.Toast;
import com.osmand.activities.RoutingHelper;
import com.osmand.activities.SavingTrackHelper;
public class NavigationService extends Service implements LocationListener {
@ -22,6 +24,9 @@ public class NavigationService extends Service implements LocationListener {
private int serviceOffInterval;
private String serviceOffProvider;
private SavingTrackHelper savingTrackHelper;
private Handler handler;
private int serviceError;
private RoutingHelper routingHelper;
@Override
public IBinder onBind(Intent intent) {
@ -30,16 +35,38 @@ public class NavigationService extends Service implements LocationListener {
private void delayedAction(final boolean register, long delay){
handler.postDelayed(new Runnable(){
@Override
public void run() {
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if(register){
locationManager.requestLocationUpdates(serviceOffProvider, serviceOffInterval, 0, NavigationService.this);
delayedAction(false, serviceError);
} else {
locationManager.removeUpdates(NavigationService.this);
delayedAction(true, serviceOffInterval);
}
}
}, serviceError);
}
@Override
public void onCreate() {
super.onCreate();
setForeground(true);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
handler = new Handler();
serviceOffInterval = OsmandSettings.getServiceOffInterval(this);
serviceOffProvider = OsmandSettings.getServiceOffProvider(this);
locationManager.requestLocationUpdates(serviceOffProvider, serviceOffInterval, 0, this);
serviceError = OsmandSettings.getServiceOffErrorInterval(this);
savingTrackHelper = new SavingTrackHelper(this);
delayedAction(true, 500);
routingHelper = RoutingHelper.getInstance(this);
OsmandSettings.setServiceOffEnabled(this, true);
}
@ -57,9 +84,11 @@ public class NavigationService extends Service implements LocationListener {
@Override
public void onLocationChanged(Location location) {
if(location != null && !OsmandSettings.getMapActivityEnabled(this)){
// TODO update voice navigation
savingTrackHelper.insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(),
location.getSpeed(), location.getTime());
if(routingHelper.isFollowingMode()){
routingHelper.setCurrentLocation(location);
}
}
}

View file

@ -57,7 +57,7 @@ public class ResourceManager {
}
// it is not good investigated but no more than 64 (satellite images)
// Only 8 MB (from 16 Mb whole mem) available for images : image 64K * 128 = 8 MB (8 bit), 64 - 16 bit, 32 - 128 bit
// Only 8 MB (from 16 Mb whole mem) available for images : image 64K * 128 = 8 MB (8 bit), 64 - 16 bit, 32 - 32 bit
protected final int maxImgCacheSize = 48;
protected Map<String, Bitmap> cacheOfImages = new LinkedHashMap<String, Bitmap>();
@ -444,7 +444,7 @@ public class ResourceManager {
}
protected void clearTiles(){
protected synchronized void clearTiles(){
log.info("Cleaning tiles - size = " + cacheOfImages.size()); //$NON-NLS-1$
ArrayList<String> list = new ArrayList<String>(cacheOfImages.keySet());
// remove first images (as we think they are older)

View file

@ -473,18 +473,28 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
}
return false;
}
private boolean useOnlyGPS(){
return (routingHelper != null && routingHelper.isFollowingMode()) || isRunningOnEmulator();
}
// Working with location listeners
private LocationListener networkListener = new LocationListener(){
@Override
public void onLocationChanged(Location location) {
setLocation(location);
// double check about use only gps
if(!useOnlyGPS()){
setLocation(location);
}
}
@Override
public void onProviderDisabled(String provider) {
setLocation(null);
if(!useOnlyGPS()){
setLocation(null);
}
}
@Override
@ -493,7 +503,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
if(LocationProvider.OUT_OF_SERVICE == status){
if(LocationProvider.OUT_OF_SERVICE == status && !useOnlyGPS()){
setLocation(null);
}
}
@ -523,7 +533,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
setLocation(null);
}
// do not use it in routing
if (!isRunningOnEmulator() && !routingHelper.isFollowingMode() &&
if (!useOnlyGPS() &&
service.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
if (!Algoritms.objectEquals(currentLocationProvider, LocationManager.NETWORK_PROVIDER)) {
currentLocationProvider = LocationManager.NETWORK_PROVIDER;
@ -623,7 +633,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
service.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST, gpsListener);
currentLocationProvider = LocationManager.GPS_PROVIDER;
if(!isRunningOnEmulator()){
if(!useOnlyGPS()){
// try to always ask for network provide : it is faster way to find location
service.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, GPS_TIMEOUT_REQUEST, GPS_DIST_REQUEST, networkListener);
currentLocationProvider = LocationManager.NETWORK_PROVIDER;

View file

@ -306,6 +306,17 @@ public class RouteProvider {
previousInfo.expectedTime = (int) (previousInfo.distance / speed);
previousInfo.descriptionRoute += " " + MapUtils.getFormattedDistance(previousInfo.distance); //$NON-NLS-1$
// add last direction go straight (to show arrow in screen after all turns)
if(previousInfo.distance > 350){
RouteDirectionInfo info = new RouteDirectionInfo();
info.expectedTime = 0;
info.distance = 0;
info.descriptionRoute = ""; //$NON-NLS-1$
info.turnType = TurnType.valueOf(TurnType.C);
info.routePointOffset = locations.size() - 1;
directions.add(info);
}
if(res.directions == null || res.directions.isEmpty()){

View file

@ -5,6 +5,7 @@ import java.util.Collections;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.util.FloatMath;
import android.widget.Toast;
@ -23,7 +24,7 @@ public class RoutingHelper {
private static final org.apache.commons.logging.Log log = LogUtil.getLog(RoutingHelper.class);
// activity to show messages & refresh map when route is calculated
private Activity activity;
private Context context;
private boolean isFollowingMode = false;
@ -71,8 +72,8 @@ public class RoutingHelper {
}
private static RoutingHelper INSTANCE = new RoutingHelper();
public static RoutingHelper getInstance(Activity ctx){
INSTANCE.activity = ctx;
public static RoutingHelper getInstance(Context ctx){
INSTANCE.context = ctx;
INSTANCE.voiceRouter.init(ctx);
return INSTANCE;
}
@ -128,7 +129,7 @@ public class RoutingHelper {
Location lastPoint = routeNodes.get(routeNodes.size() - 1);
if(currentRoute > routeNodes.size() - 3 && currentLocation.distanceTo(lastPoint) < 60){
if(lastFixedLocation != null && lastFixedLocation.distanceTo(lastPoint) < 60){
showMessage(activity.getString(R.string.arrived_at_destination));
showMessage(context.getString(R.string.arrived_at_destination));
voiceRouter.arrivedDestinationPoint();
updateCurrentRoute(routeNodes.size() - 1);
// clear final location to prevent all time showing message
@ -388,7 +389,7 @@ public class RoutingHelper {
}
public void calculateRoute(final Location start, final LatLon end){
final RouteService service = OsmandSettings.getRouterService(activity);
final RouteService service = OsmandSettings.getRouterService(context);
if(currentRunningJob == null){
// do not evaluate very often
if (System.currentTimeMillis() - lastTimeEvaluatedRoute > evalWaitInterval) {
@ -396,7 +397,7 @@ public class RoutingHelper {
currentRunningJob = new Thread(new Runnable() {
@Override
public void run() {
RouteCalculationResult res = provider.calculateRouteImpl(start, end, mode, service, activity);
RouteCalculationResult res = provider.calculateRouteImpl(start, end, mode, service, context);
synchronized (RoutingHelper.this) {
if (res.isCalculated()) {
setNewRoute(res);
@ -414,18 +415,18 @@ public class RoutingHelper {
if (res.isCalculated()) {
int[] dist = res.getListDistance();
int l = dist != null && dist.length > 0 ? dist[0] : 0;
showMessage(activity.getString(R.string.new_route_calculated_dist) +" : "+ MapUtils.getFormattedDistance(l)); //$NON-NLS-1$
if (activity instanceof MapActivity) {
showMessage(context.getString(R.string.new_route_calculated_dist) +" : "+ MapUtils.getFormattedDistance(l)); //$NON-NLS-1$
if (context instanceof MapActivity) {
// be aware that is non ui thread
((MapActivity) activity).getMapView().refreshMap();
((MapActivity) context).getMapView().refreshMap();
}
} else {
if (res.getErrorMessage() != null) {
showMessage(activity.getString(R.string.error_calculating_route)+" : " + res.getErrorMessage()); //$NON-NLS-1$
showMessage(context.getString(R.string.error_calculating_route)+" : " + res.getErrorMessage()); //$NON-NLS-1$
} else if (res.getLocations() == null) {
showMessage(activity.getString(R.string.error_calculating_route_occured));
showMessage(context.getString(R.string.error_calculating_route_occured));
} else {
showMessage(activity.getString(R.string.empty_route_calculated));
showMessage(context.getString(R.string.empty_route_calculated));
}
}
lastTimeEvaluatedRoute = System.currentTimeMillis();
@ -438,11 +439,11 @@ public class RoutingHelper {
}
private void showMessage(final String msg){
if (activity != null) {
activity.runOnUiThread(new Runnable() {
if (context instanceof Activity) {
((Activity)context).runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(activity, msg, Toast.LENGTH_SHORT).show();
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
}
});
}