fix small issues with batch creator
implement replacing favorite git-svn-id: https://osmand.googlecode.com/svn/trunk@194 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
9f9a86d6f7
commit
8cbd93d122
10 changed files with 166 additions and 63 deletions
|
@ -27,17 +27,14 @@ public class ToDoConstants {
|
||||||
// DONE: Load transport routes in swing.
|
// DONE: Load transport routes in swing.
|
||||||
// IDEA TO HAVE :
|
// IDEA TO HAVE :
|
||||||
|
|
||||||
// 48. Enable change favorite point : (for example fav - "car") means last point you left car. It is not static point,
|
// 54. Invent screen to update index from internet (from osmand.googlecode.com)
|
||||||
// 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?
|
|
||||||
// 46. Implement downloading strategy for tiles : select max zoom to download [16,15,14,...]
|
// 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], ...
|
// 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
|
// 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),
|
// 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
|
// 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
|
// 43. Enable poi filter by name
|
||||||
// 45. Get clear <Use internet> settings. Move that setting on top settings screen.
|
// 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
|
// 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
|
// BUGS Swing
|
||||||
|
|
||||||
// DONE ANDROID :
|
// 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
|
// DONE SWING
|
||||||
|
|
|
@ -6,6 +6,8 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
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$
|
"sweden", "switzerland", "turkey", // 88, 83, 17 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||||
"ukraine", // 19 //$NON-NLS-1$
|
"ukraine", // 19 //$NON-NLS-1$
|
||||||
// TOTAL : 1129 MB
|
// TOTAL : 1129 MB
|
||||||
// "france", "czech_republic", "germany", // 519, 168, 860
|
// "czech_republic", "great_britain", "italy", // 168, 281, 246,
|
||||||
// "great_britain", "italy", "netherlands", // 281, 246, 375
|
// "netherlands", "france", "germany", //519, 375, 860
|
||||||
// ADD TO TOTAL : 2449 MB
|
// ADD TO TOTAL : 2449 MB
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -93,10 +95,10 @@ public class IndexBatchCreator {
|
||||||
|
|
||||||
protected void downloadFiles(){
|
protected void downloadFiles(){
|
||||||
// clean before downloading
|
// clean before downloading
|
||||||
for(File f : osmDirFiles.listFiles()){
|
// for(File f : osmDirFiles.listFiles()){
|
||||||
log.info("Delete old file " + f.getName()); //$NON-NLS-1$
|
// log.info("Delete old file " + f.getName()); //$NON-NLS-1$
|
||||||
f.delete();
|
// f.delete();
|
||||||
}
|
// }
|
||||||
for(String country : countriesToDownload){
|
for(String country : countriesToDownload){
|
||||||
String url = SITE_TO_DOWNLOAD + country +".osm.bz2"; //$NON-NLS-1$
|
String url = SITE_TO_DOWNLOAD + country +".osm.bz2"; //$NON-NLS-1$
|
||||||
log.info("Downloading country " + country + " from " + url); //$NON-NLS-1$//$NON-NLS-2$
|
log.info("Downloading country " + country + " from " + url); //$NON-NLS-1$//$NON-NLS-2$
|
||||||
|
@ -133,7 +135,7 @@ public class IndexBatchCreator {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void generatedIndexes() {
|
protected void generatedIndexes() {
|
||||||
for (File f : osmDirFiles.listFiles()) {
|
for (File f : getSortedFiles(osmDirFiles)) {
|
||||||
if (f.getName().endsWith(".osm.bz2") || f.getName().endsWith(".osm")) {
|
if (f.getName().endsWith(".osm.bz2") || f.getName().endsWith(".osm")) {
|
||||||
System.gc();
|
System.gc();
|
||||||
generateIndex(f);
|
generateIndex(f);
|
||||||
|
@ -154,9 +156,20 @@ public class IndexBatchCreator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected File[] getSortedFiles(File dir){
|
||||||
|
File[] listFiles = dir.listFiles();
|
||||||
|
Arrays.sort(listFiles, new Comparator<File>(){
|
||||||
|
@Override
|
||||||
|
public int compare(File o1, File o2) {
|
||||||
|
return o1.getName().compareTo(o2.getName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return listFiles;
|
||||||
|
}
|
||||||
|
|
||||||
protected void uploadIndexes(){
|
protected void uploadIndexes(){
|
||||||
MessageFormat format = new MessageFormat("{0,date,dd.MM.yyyy} : {1, number,##.#} MB", Locale.US);
|
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;
|
String summary;
|
||||||
double mbLengh = (double)f.length() / MB;
|
double mbLengh = (double)f.length() / MB;
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,15 @@ package com.osmand.impl;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import com.osmand.Algoritms;
|
import com.osmand.Algoritms;
|
||||||
import com.osmand.IProgress;
|
import com.osmand.IProgress;
|
||||||
|
import com.osmand.LogUtil;
|
||||||
|
|
||||||
public class ConsoleProgressImplementation implements IProgress {
|
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;
|
String currentTask;
|
||||||
int work;
|
int work;
|
||||||
|
@ -25,7 +29,7 @@ public class ConsoleProgressImplementation implements IProgress {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void finishTask() {
|
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;
|
this.currentTask = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -62,11 +66,11 @@ public class ConsoleProgressImplementation implements IProgress {
|
||||||
public void startTask(String taskName, int work) {
|
public void startTask(String taskName, int work) {
|
||||||
if(!Algoritms.objectEquals(currentTask, taskName)){
|
if(!Algoritms.objectEquals(currentTask, taskName)){
|
||||||
this.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) {
|
if (previousTaskStarted == 0) {
|
||||||
System.out.println(taskName + " started - " + work); //$NON-NLS-1$
|
log.info(taskName + " started - " + work); //$NON-NLS-1$
|
||||||
} else {
|
} 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();
|
previousTaskStarted = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
<string name="fav_points_edited">Отредактирована избранная точка</string>
|
||||||
|
<string name="fav_points_not_exist">Не существует избранных точек</string>
|
||||||
|
<string name="update_existing">Заменить</string>
|
||||||
<string name="only_show">Только показать</string>
|
<string name="only_show">Только показать</string>
|
||||||
<string name="follow">Следовать</string>
|
<string name="follow">Следовать</string>
|
||||||
<string name="recalculate_route_to_your_location">Пересчитывать маршрут в зависимости от местоположения</string>
|
<string name="recalculate_route_to_your_location">Пересчитывать маршрут в зависимости от местоположения</string>
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
<string name="fav_points_edited">Favorite point was edited</string>
|
||||||
|
<string name="fav_points_not_exist">None of favorite points exist</string>
|
||||||
|
<string name="update_existing">Replace</string>
|
||||||
<string name="only_show">Only show</string>
|
<string name="only_show">Only show</string>
|
||||||
<string name="follow">Follow</string>
|
<string name="follow">Follow</string>
|
||||||
<string name="recalculate_route_to_your_location">Recalculate route according to your location</string>
|
<string name="recalculate_route_to_your_location">Recalculate route according to your location</string>
|
||||||
|
|
|
@ -50,6 +50,9 @@ public class AmenityIndexRepository {
|
||||||
squery += " AND " + sql; //$NON-NLS-1$
|
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,
|
Cursor query = db.query(IndexPoiTable.getTable(), columns, squery,
|
||||||
new String[]{Double.toString(bottomLatitude),
|
new String[]{Double.toString(bottomLatitude),
|
||||||
Double.toString(topLatitude), Double.toString(leftLongitude), Double.toString(rightLongitude)}, null, null, null);
|
Double.toString(topLatitude), Double.toString(leftLongitude), Double.toString(rightLongitude)}, null, null, null);
|
||||||
|
|
|
@ -155,6 +155,8 @@ public class FavouritesActivity extends ListActivity {
|
||||||
public boolean addFavourite(FavouritePoint p){
|
public boolean addFavourite(FavouritePoint p){
|
||||||
SQLiteDatabase db = getWritableDatabase();
|
SQLiteDatabase db = getWritableDatabase();
|
||||||
if(db != null){
|
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$
|
db.execSQL("INSERT INTO " + FAVOURITE_TABLE_NAME + " VALUES (?, ?, ?)",new Object[]{p.getName(), p.getLatitude(), p.getLongitude()}); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -191,6 +193,17 @@ public class FavouritesActivity extends ListActivity {
|
||||||
return false;
|
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){
|
public boolean deleteFavourite(FavouritePoint p){
|
||||||
SQLiteDatabase db = getWritableDatabase();
|
SQLiteDatabase db = getWritableDatabase();
|
||||||
if(db != null){
|
if(db != null){
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.osmand.activities;
|
package com.osmand.activities;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
@ -42,6 +43,7 @@ import android.widget.ImageButton;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import android.widget.ZoomControls;
|
import android.widget.ZoomControls;
|
||||||
|
|
||||||
|
import com.osmand.Algoritms;
|
||||||
import com.osmand.LogUtil;
|
import com.osmand.LogUtil;
|
||||||
import com.osmand.OsmandSettings;
|
import com.osmand.OsmandSettings;
|
||||||
import com.osmand.R;
|
import com.osmand.R;
|
||||||
|
@ -81,15 +83,18 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
||||||
private ImageButton backToLocation;
|
private ImageButton backToLocation;
|
||||||
private ImageButton backToMenu;
|
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 PointLocationLayer locationLayer;
|
||||||
private PointNavigationLayer navigationLayer;
|
private PointNavigationLayer navigationLayer;
|
||||||
private POIMapLayer poiMapLayer;
|
|
||||||
private MapInfoLayer mapInfoLayer;
|
private MapInfoLayer mapInfoLayer;
|
||||||
private OsmBugsLayer osmBugsLayer;
|
|
||||||
private SavingTrackHelper savingTrackHelper;
|
private SavingTrackHelper savingTrackHelper;
|
||||||
private RoutingHelper routingHelper;
|
private RoutingHelper routingHelper;
|
||||||
private boolean calculateRouteOnGps = false;
|
private boolean calculateRouteOnGps = false;
|
||||||
private RouteLayer routeLayer;
|
|
||||||
|
|
||||||
private WakeLock wakeLock;
|
private WakeLock wakeLock;
|
||||||
private boolean sensorRegistered = false;
|
private boolean sensorRegistered = false;
|
||||||
|
@ -98,7 +103,6 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
||||||
private NotificationManager mNotificationManager;
|
private NotificationManager mNotificationManager;
|
||||||
private int APP_NOTIFICATION_ID;
|
private int APP_NOTIFICATION_ID;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private boolean isMapLinkedToLocation(){
|
private boolean isMapLinkedToLocation(){
|
||||||
|
@ -141,29 +145,34 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
||||||
});
|
});
|
||||||
|
|
||||||
mapView.setMapLocationListener(this);
|
mapView.setMapLocationListener(this);
|
||||||
poiMapLayer = new POIMapLayer();
|
routingHelper = RoutingHelper.getInstance(this);
|
||||||
mapView.addLayer(poiMapLayer);
|
// 1. route layer
|
||||||
routingHelper = new RoutingHelper(this);
|
|
||||||
routeLayer = new RouteLayer(routingHelper);
|
routeLayer = new RouteLayer(routingHelper);
|
||||||
mapView.addLayer(routeLayer);
|
mapView.addLayer(routeLayer);
|
||||||
|
// 2. osm bugs layer
|
||||||
osmBugsLayer = new OsmBugsLayer(this);
|
osmBugsLayer = new OsmBugsLayer(this);
|
||||||
mapInfoLayer = new MapInfoLayer(this, routeLayer);
|
// 3. poi layer
|
||||||
mapView.addLayer(mapInfoLayer);
|
poiMapLayer = new POIMapLayer();
|
||||||
|
// 4. point navigation layer
|
||||||
navigationLayer = new PointNavigationLayer();
|
navigationLayer = new PointNavigationLayer();
|
||||||
mapView.addLayer(navigationLayer);
|
mapView.addLayer(navigationLayer);
|
||||||
|
// 5. point location layer
|
||||||
locationLayer = new PointLocationLayer();
|
locationLayer = new PointLocationLayer();
|
||||||
mapView.addLayer(locationLayer);
|
mapView.addLayer(locationLayer);
|
||||||
|
// 6. map info layer
|
||||||
|
mapInfoLayer = new MapInfoLayer(this, routeLayer);
|
||||||
|
mapView.addLayer(mapInfoLayer);
|
||||||
|
|
||||||
|
|
||||||
savingTrackHelper = new SavingTrackHelper(this);
|
savingTrackHelper = new SavingTrackHelper(this);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
locationLayer.setAppMode(OsmandSettings.getApplicationMode(this));
|
locationLayer.setAppMode(OsmandSettings.getApplicationMode(this));
|
||||||
|
|
||||||
LatLon pointToNavigate = OsmandSettings.getPointToNavigate(this);
|
LatLon pointToNavigate = OsmandSettings.getPointToNavigate(this);
|
||||||
|
|
||||||
routingHelper.setAppMode(OsmandSettings.getApplicationMode(this));
|
routingHelper.setAppMode(OsmandSettings.getApplicationMode(this));
|
||||||
routingHelper.setFinalAndCurrentLocation(pointToNavigate, null);
|
if(!Algoritms.objectEquals(routingHelper.getFinalLocation(), pointToNavigate)){
|
||||||
|
routingHelper.setFinalAndCurrentLocation(pointToNavigate, null);
|
||||||
|
}
|
||||||
|
|
||||||
navigationLayer.setPointToNavigate(pointToNavigate);
|
navigationLayer.setPointToNavigate(pointToNavigate);
|
||||||
|
|
||||||
SharedPreferences prefs = getSharedPreferences(OsmandSettings.SHARED_PREFERENCES_NAME, MODE_WORLD_READABLE);
|
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) {
|
private void updateSpeedBearing(Location location) {
|
||||||
// For gps it's bad way. It's widely used for testing purposes
|
// 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) {
|
if (locationLayer.getLastKnownLocation().distanceTo(location) > 3) {
|
||||||
float d = location.distanceTo(locationLayer.getLastKnownLocation());
|
float d = location.distanceTo(locationLayer.getLastKnownLocation());
|
||||||
if (d > 100) {
|
if (d > 100) {
|
||||||
|
@ -329,7 +338,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
||||||
location.setSpeed(d);
|
location.setSpeed(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!providerSupportsBearing && locationLayer.getLastKnownLocation() != null){
|
if(!providerSupportsBearing && locationLayer.getLastKnownLocation() != null && location != null){
|
||||||
if(locationLayer.getLastKnownLocation().distanceTo(location) > 10){
|
if(locationLayer.getLastKnownLocation().distanceTo(location) > 10){
|
||||||
location.setBearing(locationLayer.getLastKnownLocation().bearingTo(location));
|
location.setBearing(locationLayer.getLastKnownLocation().bearingTo(location));
|
||||||
}
|
}
|
||||||
|
@ -337,7 +346,9 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocation(Location location){
|
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);
|
registerUnregisterSensor(location);
|
||||||
updateSpeedBearing(location);
|
updateSpeedBearing(location);
|
||||||
|
|
||||||
|
@ -509,14 +520,14 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
||||||
|
|
||||||
if(mapView.getLayers().contains(poiMapLayer) != OsmandSettings.isShowingPoiOverMap(this)){
|
if(mapView.getLayers().contains(poiMapLayer) != OsmandSettings.isShowingPoiOverMap(this)){
|
||||||
if(OsmandSettings.isShowingPoiOverMap(this)){
|
if(OsmandSettings.isShowingPoiOverMap(this)){
|
||||||
mapView.addLayer(poiMapLayer);
|
mapView.addLayer(poiMapLayer, routeLayer);
|
||||||
} else {
|
} else {
|
||||||
mapView.removeLayer(poiMapLayer);
|
mapView.removeLayer(poiMapLayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(mapView.getLayers().contains(osmBugsLayer) != OsmandSettings.isShowingOsmBugs(this)){
|
if(mapView.getLayers().contains(osmBugsLayer) != OsmandSettings.isShowingOsmBugs(this)){
|
||||||
if(OsmandSettings.isShowingOsmBugs(this)){
|
if(OsmandSettings.isShowingOsmBugs(this)){
|
||||||
mapView.addLayer(osmBugsLayer);
|
mapView.addLayer(osmBugsLayer, routeLayer);
|
||||||
} else {
|
} else {
|
||||||
mapView.removeLayer(osmBugsLayer);
|
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 Resources resources = this.getResources();
|
||||||
final FavouritePoint p = new FavouritesActivity.FavouritePoint();
|
final FavouritePoint p = new FavouritesActivity.FavouritePoint();
|
||||||
p.setLatitude(latitude);
|
p.setLatitude(latitude);
|
||||||
|
@ -730,6 +741,35 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
||||||
final EditText editText = new EditText(this);
|
final EditText editText = new EditText(this);
|
||||||
builder.setView(editText);
|
builder.setView(editText);
|
||||||
builder.setNegativeButton(R.string.default_buttons_cancel, null);
|
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<FavouritePoint> points = helper.getFavouritePoints();
|
||||||
|
final String[] ar = new String[points.size()];
|
||||||
|
for(int i=0;i<ar.length; i++){
|
||||||
|
ar[i]=points.get(i).getName();
|
||||||
|
}
|
||||||
|
b.setItems(ar, new DialogInterface.OnClickListener(){
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
if(helper.editFavourite(points.get(which), latitude, longitude)){
|
||||||
|
Toast.makeText(MapActivity.this, getString(R.string.fav_points_edited), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
helper.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if(ar.length == 0){
|
||||||
|
Toast.makeText(MapActivity.this, getString(R.string.fav_points_not_exist), Toast.LENGTH_SHORT).show();
|
||||||
|
helper.close();
|
||||||
|
} else {
|
||||||
|
b.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
builder.setPositiveButton(R.string.default_buttons_add, new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(R.string.default_buttons_add, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
@ -737,7 +777,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
||||||
p.setName(editText.getText().toString());
|
p.setName(editText.getText().toString());
|
||||||
boolean added = helper.addFavourite(p);
|
boolean added = helper.addFavourite(p);
|
||||||
if (added) {
|
if (added) {
|
||||||
Toast.makeText(MapActivity.this, MessageFormat.format(resources.getString(R.string.add_favorite_dialog_favourite_added_template), p.getName()), Toast.LENGTH_SHORT)
|
Toast.makeText(MapActivity.this, MessageFormat.format(getString(R.string.add_favorite_dialog_favourite_added_template), p.getName()), Toast.LENGTH_SHORT)
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
helper.close();
|
helper.close();
|
||||||
|
|
|
@ -31,7 +31,8 @@ public class RoutingHelper {
|
||||||
|
|
||||||
private static final org.apache.commons.logging.Log log = LogUtil.getLog(RoutingHelper.class);
|
private static final org.apache.commons.logging.Log log = LogUtil.getLog(RoutingHelper.class);
|
||||||
|
|
||||||
private final MapActivity activity;
|
// activity to show messages & refresh map when route is calculated
|
||||||
|
private MapActivity activity;
|
||||||
|
|
||||||
private List<Location> routeNodes = new ArrayList<Location>();
|
private List<Location> routeNodes = new ArrayList<Location>();
|
||||||
private int[] listDistance = null;
|
private int[] listDistance = null;
|
||||||
|
@ -63,11 +64,17 @@ public class RoutingHelper {
|
||||||
// END TEST CODE
|
// END TEST CODE
|
||||||
|
|
||||||
|
|
||||||
public RoutingHelper(MapActivity activity){
|
private RoutingHelper(){
|
||||||
this.activity = activity;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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){
|
public synchronized void setFinalAndCurrentLocation(LatLon finalLocation, Location currentLocation){
|
||||||
this.finalLocation = finalLocation;
|
this.finalLocation = finalLocation;
|
||||||
|
@ -104,7 +111,9 @@ public class RoutingHelper {
|
||||||
Location lastPoint = routeNodes.get(routeNodes.size() - 1);
|
Location lastPoint = routeNodes.get(routeNodes.size() - 1);
|
||||||
if(currentRoute > routeNodes.size() - 3 && currentLocation.distanceTo(lastPoint) < 60){
|
if(currentRoute > routeNodes.size() - 3 && currentLocation.distanceTo(lastPoint) < 60){
|
||||||
if(lastFixedLocation != null && lastFixedLocation.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;
|
currentRoute = routeNodes.size() - 1;
|
||||||
// clear final location to prevent all time showing message
|
// clear final location to prevent all time showing message
|
||||||
finalLocation = null;
|
finalLocation = null;
|
||||||
|
@ -250,17 +259,19 @@ public class RoutingHelper {
|
||||||
}
|
}
|
||||||
currentRunningJob = null;
|
currentRunningJob = null;
|
||||||
}
|
}
|
||||||
if(res.isCalculated()){
|
if (activity != null) {
|
||||||
showMessage(activity.getString(R.string.new_route_calculated_dist) + MapUtils.getFormattedDistance(sumDistance(res.list)));
|
if (res.isCalculated()) {
|
||||||
// be aware that is non ui thread
|
showMessage(activity.getString(R.string.new_route_calculated_dist) + MapUtils.getFormattedDistance(sumDistance(res.list)));
|
||||||
activity.getMapView().refreshMap();
|
// be aware that is non ui thread
|
||||||
} else {
|
activity.getMapView().refreshMap();
|
||||||
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 {
|
} 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();
|
lastTimeEvaluatedRoute = System.currentTimeMillis();
|
||||||
|
@ -283,12 +294,14 @@ public class RoutingHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showMessage(final String msg){
|
private void showMessage(final String msg){
|
||||||
activity.runOnUiThread(new Runnable(){
|
if (activity != null) {
|
||||||
@Override
|
activity.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
Toast.makeText(activity, msg, Toast.LENGTH_SHORT).show();
|
public void run() {
|
||||||
}
|
Toast.makeText(activity, msg, Toast.LENGTH_SHORT).show();
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPointsToShow(){
|
public boolean hasPointsToShow(){
|
||||||
|
|
|
@ -159,6 +159,16 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
||||||
// TODO clear cache ?
|
// 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){
|
public void addLayer(OsmandMapLayer layer){
|
||||||
layer.initLayer(this);
|
layer.initLayer(this);
|
||||||
layers.add(layer);
|
layers.add(layer);
|
||||||
|
|
Loading…
Reference in a new issue