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:
Victor Shcherb 2010-06-22 07:55:24 +00:00
parent 9f9a86d6f7
commit 8cbd93d122
10 changed files with 166 additions and 63 deletions

View file

@ -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]
// 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 <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
@ -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

View file

@ -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<File>(){
@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;

View file

@ -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;
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();
}

View file

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<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="follow">Следовать</string>
<string name="recalculate_route_to_your_location">Пересчитывать маршрут в зависимости от местоположения</string>

View file

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<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="follow">Follow</string>
<string name="recalculate_route_to_your_location">Recalculate route according to your location</string>

View file

@ -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);

View file

@ -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){

View file

@ -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;
@ -100,7 +105,6 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
private boolean isMapLinkedToLocation(){
return OsmandSettings.isMapSyncToGpsLocation(this);
}
@ -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<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() {
@Override
public void onClick(DialogInterface dialog, int which) {
@ -737,7 +777,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
p.setName(editText.getText().toString());
boolean added = helper.addFavourite(p);
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();
}
helper.close();

View file

@ -31,7 +31,8 @@ public class RoutingHelper {
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 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(){

View file

@ -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);