diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index fd1cc3befd..ec931dcc49 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -27,17 +27,14 @@ public class ToDoConstants { // DONE: Load transport routes in swing. // IDEA TO HAVE : - // 48. Enable change favorite point : (for example fav - "car") means last point you left car. It is not static point, - // you can always use the same name for different locations. - // 51. Implement console application that prepare indexes to upload on server... - // 0) run in background 1) download from internet 2) generates indices for Europe (take care about memory) 3) upload? + // 54. Invent screen to update index from internet (from osmand.googlecode.com) // 46. Implement downloading strategy for tiles : select max zoom to download [16,15,14,...] // That means you can save internet because from [16 -> zoom -> 18], [14 -> zoom -> 16 - suitable for speed > 40], ... // 50. Invent opening hours editor in order to edit POI hours better on device - // 52. Make good distribution of POI on map (when POI a lot they are coupling in one place on the south) // 53. Add progress bars (for search adresses activity - show that something is loaded in background), // to internet communication activities [editing/commiting/deleting poi], do not hide edit poi dialog if operation failed - // [move close buttons from alertdialog to own view] + // [move close buttons from alertdialog to own view] + // 55. Update POI data from internet for selected area [suggest to create new POI index or extend exising of none exist] // 43. Enable poi filter by name // 45. Get clear settings. Move that setting on top settings screen. // That setting should rule all activities that use internet. It should ask whenever internet is used @@ -60,7 +57,11 @@ public class ToDoConstants { // BUGS Swing // DONE ANDROID : - + // 48. Enable change favorite point : (for example fav - "car") means last point you left car. It is not static point, + // you can always use the same name for different locations. + // 52. Make good distribution of POI on map (when POI a lot they are coupling in one place on the south) + // 51. Implement console application that prepare indexes to upload on server... + // 0) run in background 1) download from internet 2) generates indices for Europe (take care about memory) 3) upload? // DONE SWING diff --git a/DataExtractionOSM/src/com/osmand/data/index/IndexBatchCreator.java b/DataExtractionOSM/src/com/osmand/data/index/IndexBatchCreator.java index fdf2434827..0daefa5b3a 100644 --- a/DataExtractionOSM/src/com/osmand/data/index/IndexBatchCreator.java +++ b/DataExtractionOSM/src/com/osmand/data/index/IndexBatchCreator.java @@ -6,6 +6,8 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.text.MessageFormat; +import java.util.Arrays; +import java.util.Comparator; import java.util.Date; import java.util.Locale; @@ -35,8 +37,8 @@ public class IndexBatchCreator { "sweden", "switzerland", "turkey", // 88, 83, 17 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ "ukraine", // 19 //$NON-NLS-1$ // TOTAL : 1129 MB - // "france", "czech_republic", "germany", // 519, 168, 860 - // "great_britain", "italy", "netherlands", // 281, 246, 375 + // "czech_republic", "great_britain", "italy", // 168, 281, 246, + // "netherlands", "france", "germany", //519, 375, 860 // ADD TO TOTAL : 2449 MB }; @@ -93,10 +95,10 @@ public class IndexBatchCreator { protected void downloadFiles(){ // clean before downloading - for(File f : osmDirFiles.listFiles()){ - log.info("Delete old file " + f.getName()); //$NON-NLS-1$ - f.delete(); - } +// for(File f : osmDirFiles.listFiles()){ +// log.info("Delete old file " + f.getName()); //$NON-NLS-1$ +// f.delete(); +// } for(String country : countriesToDownload){ String url = SITE_TO_DOWNLOAD + country +".osm.bz2"; //$NON-NLS-1$ log.info("Downloading country " + country + " from " + url); //$NON-NLS-1$//$NON-NLS-2$ @@ -133,7 +135,7 @@ public class IndexBatchCreator { } protected void generatedIndexes() { - for (File f : osmDirFiles.listFiles()) { + for (File f : getSortedFiles(osmDirFiles)) { if (f.getName().endsWith(".osm.bz2") || f.getName().endsWith(".osm")) { System.gc(); generateIndex(f); @@ -154,9 +156,20 @@ public class IndexBatchCreator { } } + protected File[] getSortedFiles(File dir){ + File[] listFiles = dir.listFiles(); + Arrays.sort(listFiles, new Comparator(){ + @Override + public int compare(File o1, File o2) { + return o1.getName().compareTo(o2.getName()); + } + }); + return listFiles; + } + protected void uploadIndexes(){ MessageFormat format = new MessageFormat("{0,date,dd.MM.yyyy} : {1, number,##.#} MB", Locale.US); - for(File f : indexDirFiles.listFiles()){ + for(File f : getSortedFiles(indexDirFiles)){ String summary; double mbLengh = (double)f.length() / MB; diff --git a/DataExtractionOSM/src/com/osmand/impl/ConsoleProgressImplementation.java b/DataExtractionOSM/src/com/osmand/impl/ConsoleProgressImplementation.java index 957770000f..9793aa25a8 100644 --- a/DataExtractionOSM/src/com/osmand/impl/ConsoleProgressImplementation.java +++ b/DataExtractionOSM/src/com/osmand/impl/ConsoleProgressImplementation.java @@ -2,11 +2,15 @@ package com.osmand.impl; import java.text.MessageFormat; +import org.apache.commons.logging.Log; + import com.osmand.Algoritms; import com.osmand.IProgress; +import com.osmand.LogUtil; public class ConsoleProgressImplementation implements IProgress { - public static double deltaPercentsToPrint = 3.5; + public static double deltaPercentsToPrint = 3.5; + private static Log log = LogUtil.getLog(ConsoleProgressImplementation.class); String currentTask; int work; @@ -25,7 +29,7 @@ public class ConsoleProgressImplementation implements IProgress { @Override public void finishTask() { - System.out.println("Task " + currentTask + " is finished "); //$NON-NLS-1$ //$NON-NLS-2$ + log.info("Task " + currentTask + " is finished "); //$NON-NLS-1$ //$NON-NLS-2$ this.currentTask = null; } @@ -62,11 +66,11 @@ public class ConsoleProgressImplementation implements IProgress { public void startTask(String taskName, int work) { if(!Algoritms.objectEquals(currentTask, taskName)){ this.currentTask = taskName; - System.out.println("Memory before task exec: " + Runtime.getRuntime().totalMemory() + " free : " + Runtime.getRuntime().freeMemory()); //$NON-NLS-1$ //$NON-NLS-2$ + log.info("Memory before task exec: " + Runtime.getRuntime().totalMemory() + " free : " + Runtime.getRuntime().freeMemory()); //$NON-NLS-1$ //$NON-NLS-2$ if (previousTaskStarted == 0) { - System.out.println(taskName + " started - " + work); //$NON-NLS-1$ + log.info(taskName + " started - " + work); //$NON-NLS-1$ } else { - System.out.println(taskName + " started after " + (System.currentTimeMillis() - previousTaskStarted) + " ms" + " - " + work); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + log.info(taskName + " started after " + (System.currentTimeMillis() - previousTaskStarted) + " ms" + " - " + work); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } previousTaskStarted = System.currentTimeMillis(); } diff --git a/OsmAnd/res/values-ru-rRU/strings.xml b/OsmAnd/res/values-ru-rRU/strings.xml index 7596cb2570..710f9f3e96 100644 --- a/OsmAnd/res/values-ru-rRU/strings.xml +++ b/OsmAnd/res/values-ru-rRU/strings.xml @@ -1,5 +1,8 @@ + Отредактирована избранная точка + Не существует избранных точек + Заменить Только показать Следовать Пересчитывать маршрут в зависимости от местоположения diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 214de0a88b..8235a3619e 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,5 +1,8 @@ + Favorite point was edited + None of favorite points exist + Replace Only show Follow Recalculate route according to your location diff --git a/OsmAnd/src/com/osmand/AmenityIndexRepository.java b/OsmAnd/src/com/osmand/AmenityIndexRepository.java index b2e2630cd7..a873ecd2cc 100644 --- a/OsmAnd/src/com/osmand/AmenityIndexRepository.java +++ b/OsmAnd/src/com/osmand/AmenityIndexRepository.java @@ -50,6 +50,9 @@ public class AmenityIndexRepository { squery += " AND " + sql; //$NON-NLS-1$ } } + if(limit != -1){ + squery += " ORDER BY RANDOM() LIMIT " +limit; //$NON-NLS-1$ + } Cursor query = db.query(IndexPoiTable.getTable(), columns, squery, new String[]{Double.toString(bottomLatitude), Double.toString(topLatitude), Double.toString(leftLongitude), Double.toString(rightLongitude)}, null, null, null); diff --git a/OsmAnd/src/com/osmand/activities/FavouritesActivity.java b/OsmAnd/src/com/osmand/activities/FavouritesActivity.java index 79851e24f9..02c4131653 100644 --- a/OsmAnd/src/com/osmand/activities/FavouritesActivity.java +++ b/OsmAnd/src/com/osmand/activities/FavouritesActivity.java @@ -155,6 +155,8 @@ public class FavouritesActivity extends ListActivity { public boolean addFavourite(FavouritePoint p){ SQLiteDatabase db = getWritableDatabase(); if(db != null){ + // delete with same name before + deleteFavourite(p); db.execSQL("INSERT INTO " + FAVOURITE_TABLE_NAME + " VALUES (?, ?, ?)",new Object[]{p.getName(), p.getLatitude(), p.getLongitude()}); //$NON-NLS-1$ //$NON-NLS-2$ return true; } @@ -191,6 +193,17 @@ public class FavouritesActivity extends ListActivity { return false; } + public boolean editFavourite(FavouritePoint p, double lat, double lon){ + SQLiteDatabase db = getWritableDatabase(); + if(db != null){ + db.execSQL("UPDATE " + FAVOURITE_TABLE_NAME + " SET latitude = ?, longitude = ? WHERE name = ?",new Object[]{lat, lon, p.getName()}); //$NON-NLS-1$ //$NON-NLS-2$ + p.setLatitude(lat); + p.setLongitude(lon); + return true; + } + return false; + } + public boolean deleteFavourite(FavouritePoint p){ SQLiteDatabase db = getWritableDatabase(); if(db != null){ diff --git a/OsmAnd/src/com/osmand/activities/MapActivity.java b/OsmAnd/src/com/osmand/activities/MapActivity.java index 1b4988d932..69b049073b 100644 --- a/OsmAnd/src/com/osmand/activities/MapActivity.java +++ b/OsmAnd/src/com/osmand/activities/MapActivity.java @@ -1,6 +1,7 @@ package com.osmand.activities; import java.text.MessageFormat; +import java.util.List; import android.app.Activity; import android.app.AlertDialog; @@ -42,6 +43,7 @@ import android.widget.ImageButton; import android.widget.Toast; import android.widget.ZoomControls; +import com.osmand.Algoritms; import com.osmand.LogUtil; import com.osmand.OsmandSettings; import com.osmand.R; @@ -81,15 +83,18 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat private ImageButton backToLocation; private ImageButton backToMenu; + // the order of layer should be preserved ! when you are inserting new layer + private RouteLayer routeLayer; + private OsmBugsLayer osmBugsLayer; + private POIMapLayer poiMapLayer; private PointLocationLayer locationLayer; private PointNavigationLayer navigationLayer; - private POIMapLayer poiMapLayer; private MapInfoLayer mapInfoLayer; - private OsmBugsLayer osmBugsLayer; + private SavingTrackHelper savingTrackHelper; private RoutingHelper routingHelper; private boolean calculateRouteOnGps = false; - private RouteLayer routeLayer; + private WakeLock wakeLock; private boolean sensorRegistered = false; @@ -98,7 +103,6 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat private NotificationManager mNotificationManager; private int APP_NOTIFICATION_ID; - private boolean isMapLinkedToLocation(){ @@ -141,29 +145,34 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat }); mapView.setMapLocationListener(this); - poiMapLayer = new POIMapLayer(); - mapView.addLayer(poiMapLayer); - routingHelper = new RoutingHelper(this); + routingHelper = RoutingHelper.getInstance(this); + // 1. route layer routeLayer = new RouteLayer(routingHelper); mapView.addLayer(routeLayer); + // 2. osm bugs layer osmBugsLayer = new OsmBugsLayer(this); - mapInfoLayer = new MapInfoLayer(this, routeLayer); - mapView.addLayer(mapInfoLayer); + // 3. poi layer + poiMapLayer = new POIMapLayer(); + // 4. point navigation layer navigationLayer = new PointNavigationLayer(); mapView.addLayer(navigationLayer); + // 5. point location layer locationLayer = new PointLocationLayer(); mapView.addLayer(locationLayer); + // 6. map info layer + mapInfoLayer = new MapInfoLayer(this, routeLayer); + mapView.addLayer(mapInfoLayer); + savingTrackHelper = new SavingTrackHelper(this); - - - - locationLayer.setAppMode(OsmandSettings.getApplicationMode(this)); - LatLon pointToNavigate = OsmandSettings.getPointToNavigate(this); + routingHelper.setAppMode(OsmandSettings.getApplicationMode(this)); - routingHelper.setFinalAndCurrentLocation(pointToNavigate, null); + if(!Algoritms.objectEquals(routingHelper.getFinalLocation(), pointToNavigate)){ + routingHelper.setFinalAndCurrentLocation(pointToNavigate, null); + } + navigationLayer.setPointToNavigate(pointToNavigate); SharedPreferences prefs = getSharedPreferences(OsmandSettings.SHARED_PREFERENCES_NAME, MODE_WORLD_READABLE); @@ -320,7 +329,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat private void updateSpeedBearing(Location location) { // For gps it's bad way. It's widely used for testing purposes - if(!providerSupportsSpeed && locationLayer.getLastKnownLocation() != null){ + if(!providerSupportsSpeed && locationLayer.getLastKnownLocation() != null && location != null){ if (locationLayer.getLastKnownLocation().distanceTo(location) > 3) { float d = location.distanceTo(locationLayer.getLastKnownLocation()); if (d > 100) { @@ -329,7 +338,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat location.setSpeed(d); } } - if(!providerSupportsBearing && locationLayer.getLastKnownLocation() != null){ + if(!providerSupportsBearing && locationLayer.getLastKnownLocation() != null && location != null){ if(locationLayer.getLastKnownLocation().distanceTo(location) > 10){ location.setBearing(locationLayer.getLastKnownLocation().bearingTo(location)); } @@ -337,7 +346,9 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat } public void setLocation(Location location){ - + if(Log.isLoggable(LogUtil.TAG, Log.DEBUG)){ + Log.d(LogUtil.TAG, "Location changed " + location.getProvider()); //$NON-NLS-1$ + } registerUnregisterSensor(location); updateSpeedBearing(location); @@ -509,14 +520,14 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat if(mapView.getLayers().contains(poiMapLayer) != OsmandSettings.isShowingPoiOverMap(this)){ if(OsmandSettings.isShowingPoiOverMap(this)){ - mapView.addLayer(poiMapLayer); + mapView.addLayer(poiMapLayer, routeLayer); } else { mapView.removeLayer(poiMapLayer); } } if(mapView.getLayers().contains(osmBugsLayer) != OsmandSettings.isShowingOsmBugs(this)){ if(OsmandSettings.isShowingOsmBugs(this)){ - mapView.addLayer(osmBugsLayer); + mapView.addLayer(osmBugsLayer, routeLayer); } else { mapView.removeLayer(osmBugsLayer); } @@ -718,7 +729,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat } - protected void addFavouritePoint(double latitude, double longitude){ + protected void addFavouritePoint(final double latitude, final double longitude){ final Resources resources = this.getResources(); final FavouritePoint p = new FavouritesActivity.FavouritePoint(); p.setLatitude(latitude); @@ -730,6 +741,35 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat final EditText editText = new EditText(this); builder.setView(editText); builder.setNegativeButton(R.string.default_buttons_cancel, null); + builder.setNeutralButton(R.string.update_existing, new DialogInterface.OnClickListener(){ + + @Override + public void onClick(DialogInterface dialog, int which) { + Builder b = new AlertDialog.Builder(MapActivity.this); + final FavouritesDbHelper helper = new FavouritesActivity.FavouritesDbHelper(MapActivity.this); + final List points = helper.getFavouritePoints(); + final String[] ar = new String[points.size()]; + for(int i=0;i routeNodes = new ArrayList(); private int[] listDistance = null; @@ -63,11 +64,17 @@ public class RoutingHelper { // END TEST CODE - public RoutingHelper(MapActivity activity){ - this.activity = activity; - + private RoutingHelper(){ } + private static RoutingHelper INSTANCE = new RoutingHelper(); + public static RoutingHelper getInstance(MapActivity activity){ + INSTANCE.activity = activity; + return INSTANCE; + } + + + public synchronized void setFinalAndCurrentLocation(LatLon finalLocation, Location currentLocation){ this.finalLocation = finalLocation; @@ -104,7 +111,9 @@ 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)); + if(activity != null){ + showMessage(activity.getString(R.string.arrived_at_destination)); + } currentRoute = routeNodes.size() - 1; // clear final location to prevent all time showing message finalLocation = null; @@ -250,17 +259,19 @@ public class RoutingHelper { } currentRunningJob = null; } - if(res.isCalculated()){ - showMessage(activity.getString(R.string.new_route_calculated_dist) + MapUtils.getFormattedDistance(sumDistance(res.list))); - // be aware that is non ui thread - activity.getMapView().refreshMap(); - } else { - if(res.errorMessage != null){ - showMessage(activity.getString(R.string.error_calculating_route)+ res.errorMessage); - } else if(res.list == null){ - showMessage(activity.getString(R.string.error_calculating_route_occured)); + if (activity != null) { + if (res.isCalculated()) { + showMessage(activity.getString(R.string.new_route_calculated_dist) + MapUtils.getFormattedDistance(sumDistance(res.list))); + // be aware that is non ui thread + activity.getMapView().refreshMap(); } else { - showMessage(activity.getString(R.string.empty_route_calculated)); + if (res.errorMessage != null) { + showMessage(activity.getString(R.string.error_calculating_route) + res.errorMessage); + } else if (res.list == null) { + showMessage(activity.getString(R.string.error_calculating_route_occured)); + } else { + showMessage(activity.getString(R.string.empty_route_calculated)); + } } } lastTimeEvaluatedRoute = System.currentTimeMillis(); @@ -283,12 +294,14 @@ public class RoutingHelper { } private void showMessage(final String msg){ - activity.runOnUiThread(new Runnable(){ - @Override - public void run() { - Toast.makeText(activity, msg, Toast.LENGTH_SHORT).show(); - } - }); + if (activity != null) { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + Toast.makeText(activity, msg, Toast.LENGTH_SHORT).show(); + } + }); + } } public boolean hasPointsToShow(){ diff --git a/OsmAnd/src/com/osmand/views/OsmandMapTileView.java b/OsmAnd/src/com/osmand/views/OsmandMapTileView.java index aaf1f9ac81..ee31c7fcf0 100644 --- a/OsmAnd/src/com/osmand/views/OsmandMapTileView.java +++ b/OsmAnd/src/com/osmand/views/OsmandMapTileView.java @@ -159,6 +159,16 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall // TODO clear cache ? } + public void addLayer(OsmandMapLayer layer, OsmandMapLayer afterIt){ + layer.initLayer(this); + int i = layers.indexOf(afterIt); + if(i == -1){ + layers.add(layer); + } else { + layers.add(i, layer); + } + } + public void addLayer(OsmandMapLayer layer){ layer.initLayer(this); layers.add(layer);