From d3f51f9c0ff6c14d84ef73e44f531d02010ecf95 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 14 Jun 2010 10:53:07 +0000 Subject: [PATCH] fix small issues implement save track to gpx git-svn-id: https://osmand.googlecode.com/svn/trunk@159 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- .../src/com/osmand/ToDoConstants.java | 24 +- DataExtractionOSM/src/com/osmand/Version.java | 10 + .../data/preparation/MapTileDownloader.java | 8 +- .../src/com/osmand/map/TileSourceManager.java | 17 +- OsmAnd/res/values/strings.xml | 11 +- OsmAnd/res/xml/settings_pref.xml | 12 +- OsmAnd/src/com/osmand/OsmandSettings.java | 17 ++ OsmAnd/src/com/osmand/PoiFiltersHelper.java | 2 +- .../osmand/activities/MainMenuActivity.java | 4 +- .../com/osmand/activities/MapActivity.java | 10 +- .../osmand/activities/SavingTrackHelper.java | 212 ++++++++++++++++++ .../osmand/activities/SettingsActivity.java | 26 +++ OsmAnd/src/com/osmand/views/MapInfoLayer.java | 6 +- 13 files changed, 325 insertions(+), 34 deletions(-) create mode 100644 DataExtractionOSM/src/com/osmand/Version.java create mode 100644 OsmAnd/src/com/osmand/activities/SavingTrackHelper.java diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index 9210522c75..bec71c7915 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -16,7 +16,6 @@ public class ToDoConstants { // } // } - /** * Write activity to show something about authors / donation .... */ @@ -27,8 +26,12 @@ public class ToDoConstants { // 32. Introduce POI predefined filters (car filter(other-fuel, transportation-car_wash, show-car) and others) // ( 1) predefined filters, 2) choose subtype's, 3) filter by name, 4) opening hours (filter)) +// 20. Implement save track/route to gpx // 8. Enable change POI directly on map (requires OSM login) // 33. Build transport locations. Create transport index (transport-stops) (investigate) [TODO] +// 44. Introduce settings presets (car/bicycle/pedestrian/default) - show different icons for car (bigger), +// possibly change fonts, position +// 45. Autozoom feature (for car navigatoin) // 42. Revise UI (icons/layouts). Support different devices. Add inactive/focus(!) icon versions. // 36. Postcode search @@ -37,14 +40,15 @@ public class ToDoConstants { // 34. Suppport navigation for calculated route (example of get route from internet is in swing app). // 40. Support simple vector road rendering (require new index file) - // 43. Enable poi filter by name // 26. Show the whole street on map (when it is chosen in search activity). Possibly extend that story to show layer with streets. (?) -// 20. Implement save track/route to gpx (?) + // BUGS Android // 5. Improvement : Implement caching files existing on FS, implement specific method in RM // Introducing cache of file names that are on disk (creating new File() consumes a lot of memory) + // 6. Bug : loading from internet tile (when internet is not accessible). For rotated map investigate loading tile mechanism. + // // BUGS Swing // 1. Bug renaming region @@ -57,19 +61,9 @@ public class ToDoConstants { // 1. Download tiles without using dir tiles (?) - // DONE ANDROID : -// 39. Support old-versionned resources (1) odb indexes, 2) favourites table, 3) atomic settings (?)) [TODO] -// 41. POI layer over map (shows poi by selected filter) -// 38. Add button in search "navigate to" -// 16. Support open street bugs api (supports viewing, deleting). -// 13. Save point as favorite & introduce favorite points dialog -// 29. Show opened/closed amenities (in search poi). -// 3. Revise osmand UI. Preparing new icons (revise UI 18, 2, ). Main application icon, back to location icon. -// 14. Show zoom level on map -// 35. Enable trackball navigation in android + // DONE SWING - // 2. Internal (Simplify MapPanel - introduce layers for it) - // 3. Implement clear progress. + } diff --git a/DataExtractionOSM/src/com/osmand/Version.java b/DataExtractionOSM/src/com/osmand/Version.java new file mode 100644 index 0000000000..4785376c48 --- /dev/null +++ b/DataExtractionOSM/src/com/osmand/Version.java @@ -0,0 +1,10 @@ +package com.osmand; + +public class Version { + + public static final String APP_VERSION = "0.2"; + public static final String APP_NAME = "OsmAnd"; + + public static final String APP_NAME_VERSION = APP_NAME + " " + APP_VERSION; + +} diff --git a/DataExtractionOSM/src/com/osmand/data/preparation/MapTileDownloader.java b/DataExtractionOSM/src/com/osmand/data/preparation/MapTileDownloader.java index fa0eadea19..486904578c 100644 --- a/DataExtractionOSM/src/com/osmand/data/preparation/MapTileDownloader.java +++ b/DataExtractionOSM/src/com/osmand/data/preparation/MapTileDownloader.java @@ -20,13 +20,9 @@ import org.apache.commons.logging.Log; import com.osmand.Algoritms; import com.osmand.LogUtil; +import com.osmand.Version; public class MapTileDownloader { - // Application constants - public static String APP_NAME = "OsmAnd"; - public static String APP_VERSION = "0.2"; - - // Download manager tile settings public static int TILE_DOWNLOAD_THREADS = 4; public static int TILE_DOWNLOAD_SECONDS_TO_WORK = 25; @@ -177,7 +173,7 @@ public class MapTileDownloader { request.fileToSave.getParentFile().mkdirs(); URL url = new URL(request.url); URLConnection connection = url.openConnection(); - connection.setRequestProperty("User-Agent", APP_NAME + "/" + APP_VERSION); + connection.setRequestProperty("User-Agent", Version.APP_NAME_VERSION); BufferedInputStream inputStream = new BufferedInputStream(connection.getInputStream(), 8 * 1024); FileOutputStream stream = null; try { diff --git a/DataExtractionOSM/src/com/osmand/map/TileSourceManager.java b/DataExtractionOSM/src/com/osmand/map/TileSourceManager.java index c767a9f92e..ee21644999 100644 --- a/DataExtractionOSM/src/com/osmand/map/TileSourceManager.java +++ b/DataExtractionOSM/src/com/osmand/map/TileSourceManager.java @@ -5,7 +5,9 @@ import java.util.ArrayList; public class TileSourceManager { - +// transport "http://tile.xn--pnvkarte-m4a.de/tilegen/${z}/${x}/${y}.png", {numZoomLevels: 19,displayInLayerSwitcher:true,buffer:0}); +// var navdebug = new OpenLayers.Layer.OSM("Navigation Debug", "http://ec2-184-73-15-218.compute-1.amazonaws.com/6700/256/${z}/${x}/${y}.png", {numZoomLevels: 18,displayInLayerSwitcher:true,buffer:0}); +// "Mapsurfer Road", "http://tiles1.mapsurfer.net/tms_r.ashx?", { numZoomLevels: 19, isBaseLayer: true, type: 'png', getURL: osm_getTileURL, displayOutsideMaxExtent: true }) public static class TileSourceTemplate implements ITileSource { private int maxZoom; private int minZoom; @@ -97,12 +99,16 @@ public class TileSourceManager { list.add(getMapnikSource()); list.add(getOsmaRenderSource()); list.add(getCycleMapSource()); + list.add(getMapSurferSource()); + list.add(getNavigationDebugSource()); // list.add(getAerialMapSource()); + list.add(getCloudMadeSource()); list.add(getOpenPisteMapSource()); list.add(getGoogleMapsSource()); list.add(getGoogleMapsSatelliteSource()); list.add(getGoogleMapsTerrainSource()); + list.add(getMicrosoftMapsSource()); list.add(getMicrosoftEarthSource()); list.add(getMicrosoftHybridSource()); @@ -135,6 +141,15 @@ public class TileSourceManager { return new TileSourceTemplate("Cloudmade", "http://tile.cloudmade.com/7ded028e030c5929b28bf823486ce84f/1/256/{0}/{1}/{2}.png", ".png", 18, 0, 256, 18000); } + public static TileSourceTemplate getMapSurferSource(){ + return new TileSourceTemplate("MapSurfer", "http://tiles1.mapsurfer.net/tms_r.ashx?z={0}&x={1}&y={2}", ".png", 19, 0, 256, 18000); + } + + public static TileSourceTemplate getNavigationDebugSource(){ + return new TileSourceTemplate("NavigationDebug", "http://ec2-184-73-15-218.compute-1.amazonaws.com/6700/256/{0}/{1}/{2}.png", ".png", 18, 0, 256, 18000); + } + + public static TileSourceTemplate getOpenPisteMapSource(){ return new TileSourceTemplate("OpenPisteMap", "http://openpistemap.org/tiles/contours/{0}/{1}/{2}.png", ".png", 17, 0, 256, 18000); } diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index ca00d1ad02..6d33f601ea 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,5 +1,12 @@ + Save current track to SD + Save current track + Choose time interval to save track + Save track interval + Monitoring settings + Tracks will be saved to track directory grouped by days + Save track to gpx Navigate to Update map Reload tile @@ -29,14 +36,14 @@ Map View 3D Rotate map to bearing of your direction Rotate map - Show POI on map (zoom > 15) + Show POI over map (use last chosen filter) Show POI Choose the source of tiles: Map tile source Map source Use internet Show location - Map preferences + Map settings Settings Show gps coordinates on map Use internet to download missing tiles diff --git a/OsmAnd/res/xml/settings_pref.xml b/OsmAnd/res/xml/settings_pref.xml index fa1acb1c6d..1e7b1047c8 100644 --- a/OsmAnd/res/xml/settings_pref.xml +++ b/OsmAnd/res/xml/settings_pref.xml @@ -5,15 +5,19 @@ - + + - - - + + + + + + diff --git a/OsmAnd/src/com/osmand/OsmandSettings.java b/OsmAnd/src/com/osmand/OsmandSettings.java index c09ed31e1f..dc4f0ee3b1 100644 --- a/OsmAnd/src/com/osmand/OsmandSettings.java +++ b/OsmAnd/src/com/osmand/OsmandSettings.java @@ -45,6 +45,23 @@ public class OsmandSettings { return prefs.edit().putString(USER_NAME, name).commit(); } + // this value string is synchronized with settings_pref.xml preference name + public static final String SAVE_CURRENT_TRACK = "save_current_track"; + + // this value string is synchronized with settings_pref.xml preference name + public static final String SAVE_TRACK_TO_GPX = "save_track_to_gpx"; + public static boolean isSavingTrackToGpx(Context ctx){ + SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + return prefs.getBoolean(SAVE_TRACK_TO_GPX, false); + } + + // this value string is synchronized with settings_pref.xml preference name + public static final String SAVE_TRACK_INTERVAL = "save_track_interval"; + public static int getSavingTrackInterval(Context ctx){ + SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + return prefs.getInt(SAVE_TRACK_INTERVAL, 5); + } + // this value string is synchronized with settings_pref.xml preference name public static final String SHOW_OSM_BUGS = "show_osm_bugs"; diff --git a/OsmAnd/src/com/osmand/PoiFiltersHelper.java b/OsmAnd/src/com/osmand/PoiFiltersHelper.java index 957a3d6ea0..a58d656ddd 100644 --- a/OsmAnd/src/com/osmand/PoiFiltersHelper.java +++ b/OsmAnd/src/com/osmand/PoiFiltersHelper.java @@ -101,7 +101,7 @@ public class PoiFiltersHelper { private static List cacheUserDefinedFilters; public static List getUserDefinedPoiFilters(Context ctx){ if(cacheUserDefinedFilters == null){ - ctx.deleteDatabase(PoiFilterDbHelper.DATABASE_NAME); + ////ctx.deleteDatabase(PoiFilterDbHelper.DATABASE_NAME); cacheUserDefinedFilters = new ArrayList(); PoiFilterDbHelper helper = new PoiFilterDbHelper(ctx); diff --git a/OsmAnd/src/com/osmand/activities/MainMenuActivity.java b/OsmAnd/src/com/osmand/activities/MainMenuActivity.java index 72f9804728..efe67158a8 100644 --- a/OsmAnd/src/com/osmand/activities/MainMenuActivity.java +++ b/OsmAnd/src/com/osmand/activities/MainMenuActivity.java @@ -90,7 +90,9 @@ public class MainMenuActivity extends Activity { getPreferences(MODE_WORLD_READABLE).edit().putLong(EXCEPTION_FILE_SIZE, 0).commit(); } } - + SavingTrackHelper helper = new SavingTrackHelper(this); + helper.saveDataToGpx(); + helper.close(); } } diff --git a/OsmAnd/src/com/osmand/activities/MapActivity.java b/OsmAnd/src/com/osmand/activities/MapActivity.java index 99192c2c4a..1a3c8a01d7 100644 --- a/OsmAnd/src/com/osmand/activities/MapActivity.java +++ b/OsmAnd/src/com/osmand/activities/MapActivity.java @@ -64,12 +64,15 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat private POIMapLayer poiMapLayer; private MapInfoLayer mapInfoLayer; private OsmBugsLayer osmBugsLayer; + private SavingTrackHelper savingTrackHelper; private WakeLock wakeLock; private boolean sensorRegistered = false; private MenuItem navigateToPointMenu; + + private boolean isMapLinkedToLocation(){ return OsmandSettings.isMapSyncToGpsLocation(this); } @@ -95,6 +98,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat mapInfoLayer = new MapInfoLayer(this); mapView.addLayer(mapInfoLayer); osmBugsLayer = new OsmBugsLayer(this); + savingTrackHelper = new SavingTrackHelper(this); LatLon pointToNavigate = OsmandSettings.getPointToNavigate(this); @@ -202,11 +206,11 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat @Override protected void onDestroy() { super.onDestroy(); + savingTrackHelper.close(); MapTileDownloader.getInstance().removeDownloaderCallback(mapView); } public void setLocation(Location location){ - // Do very strange manipulation to call redraw only once // show point view only if gps enabled if(location == null){ @@ -272,6 +276,10 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat @Override public void onLocationChanged(Location location) { + if(location != null && OsmandSettings.isSavingTrackToGpx(this)){ + savingTrackHelper.insertData(location.getLatitude(), location.getLongitude(), + location.getAltitude(), location.getSpeed(), location.getTime()); + } setLocation(location); } diff --git a/OsmAnd/src/com/osmand/activities/SavingTrackHelper.java b/OsmAnd/src/com/osmand/activities/SavingTrackHelper.java new file mode 100644 index 0000000000..3e9cb9679e --- /dev/null +++ b/OsmAnd/src/com/osmand/activities/SavingTrackHelper.java @@ -0,0 +1,212 @@ +package com.osmand.activities; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.xmlpull.v1.XmlSerializer; + +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.os.Environment; +import android.text.format.DateFormat; +import android.util.Xml; +import android.widget.Toast; + +import com.osmand.LogUtil; +import com.osmand.OsmandSettings; +import com.osmand.Version; + +public class SavingTrackHelper extends SQLiteOpenHelper { + public final static String TRACKS_PATH = "tracks"; + + public final static String DATABASE_NAME = "tracks"; + public final static int DATABASE_VERSION = 1; + + public final static String TRACK_NAME = "track"; + public final static String TRACK_COL_DATE = "date"; + public final static String TRACK_COL_LAT = "lat"; + public final static String TRACK_COL_LON = "lon"; + public final static String TRACK_COL_ALTITUDE = "altitude"; + public final static String TRACK_COL_SPEED = "speed"; + + public final static Log log = LogUtil.getLog(SavingTrackHelper.class); + + + private String updateScript; + private long lastTimeUpdated = 0; + private final Context ctx; + + public SavingTrackHelper(Context ctx){ + super(ctx, DATABASE_NAME, null, DATABASE_VERSION); + this.ctx = ctx; + updateScript = "INSERT INTO " + TRACK_NAME + " VALUES (?, ?, ?, ?, ?)"; + } + + @Override + public void onCreate(SQLiteDatabase db) { + db.execSQL("CREATE TABLE " + TRACK_NAME+ " ("+TRACK_COL_LAT +" double, " + TRACK_COL_LON+" double, " + + TRACK_COL_ALTITUDE+" double, " + TRACK_COL_SPEED+" double, " + + TRACK_COL_DATE +" long )" ); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + } + + private static class TrkPt { + public double lat; + public double lon; + public double ele; + public double speed; + public long time; + } + + + protected void saveToXMLFiles(File dir, Map>> data ){ + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); + try { + for (String f : data.keySet()) { + FileOutputStream output = new FileOutputStream(new File(dir, f + ".gpx")); + XmlSerializer serializer = Xml.newSerializer(); + serializer.setOutput(output, "UTF-8"); + serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); + serializer.startDocument("UTF-8", true); + serializer.startTag(null, "gpx"); + serializer.attribute(null, "version", "1.1"); + serializer.attribute(null, "creator", Version.APP_NAME_VERSION); + serializer.attribute("xmlns", "xsi", "http://www.w3.org/2001/XMLSchema-instance"); + serializer.attribute("xsi", "schemaLocation", "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"); + serializer.attribute(null, "xmlns", "http://www.topografix.com/GPX/1/1"); + + serializer.startTag(null, "trk"); + for(List l : data.get(f)){ + serializer.startTag(null, "trkseg"); + for(TrkPt p : l){ + serializer.startTag(null, "trkpt"); + serializer.attribute(null, "lat", p.lat+""); + serializer.attribute(null, "lon", p.lon+""); + serializer.startTag(null, "time"); + serializer.text(format.format(new Date(p.time))); + serializer.endTag(null, "time"); + serializer.startTag(null, "ele"); + serializer.text(p.ele+""); + serializer.endTag(null, "ele"); + if (p.speed > 0) { + serializer.startTag(null, "speed"); + serializer.text(p.speed + ""); + serializer.endTag(null, "speed"); + } + + serializer.endTag(null, "trkpt"); + } + serializer.endTag(null, "trkseg"); + } + serializer.endTag(null, "trk"); + + serializer.endTag(null, "gpx"); + serializer.flush(); + serializer.endDocument(); + + + } + } catch (RuntimeException e) { + log.error("Error saving gpx"); + Toast.makeText(ctx, "Exception occurred while saving gpx", Toast.LENGTH_LONG); + } catch (IOException e) { + log.error("Error saving gpx"); + Toast.makeText(ctx, "Exception occurred while saving gpx", Toast.LENGTH_LONG); + } + } + + public void saveDataToGpx(){ + SQLiteDatabase db = getReadableDatabase(); + File file = Environment.getExternalStorageDirectory(); + if(db != null && file.canWrite()){ + file = new File(file, "/osmand/"+TRACKS_PATH); + file.mkdirs(); + if (file.exists()) { + Cursor query = db.rawQuery("SELECT " + TRACK_COL_LAT + "," + TRACK_COL_LON + "," + TRACK_COL_ALTITUDE + "," + + TRACK_COL_SPEED + "," + TRACK_COL_DATE + " FROM " + TRACK_NAME, null); + long previousTime = 0; + Map>> data = new LinkedHashMap>>(); + List segment = new ArrayList(); + List> track = new ArrayList>(); + track.add(segment); + if (query.moveToFirst()) { + do { + TrkPt pt = new TrkPt(); + pt.lat = query.getDouble(0); + pt.lon = query.getDouble(1); + pt.ele = query.getDouble(2); + pt.speed = query.getDouble(3); + long time = query.getLong(4); + pt.time = time; + + if (previousTime == 0) { + data.put(DateFormat.format("yyyy-MM-dd", time).toString(), track); + segment.add(pt); + } else if (Math.abs(time - previousTime) < 60000) { + // 1 hour - same segment + segment.add(pt); + } else if (Math.abs(time - previousTime) < 3600000) { + // 1 hour - same track + segment = new ArrayList(); + segment.add(pt); + track.add(segment); + } else { + // check day (possibly better create new track (not new segment) + String date = DateFormat.format("yyyy-MM-dd", time).toString(); + if (data.containsKey(date)) { + track = data.get(date); + } else { + track = new ArrayList>(); + data.put(date, track); + } + segment = new ArrayList(); + segment.add(pt); + track.add(segment); + } + + previousTime = time; + } while (query.moveToNext()); + } + query.close(); + saveToXMLFiles(file, data); + } + } + + db = getWritableDatabase(); + if(db != null){ + Calendar cal = Calendar.getInstance(); + cal.setTime(new java.util.Date()); + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MILLISECOND, 0); + db.execSQL("DELETE FROM " + TRACK_NAME+ " WHERE " + TRACK_COL_DATE + " <= ?", new Object[]{cal.getTimeInMillis()}); + } + } + + public void insertData(double lat, double lon, double alt, double speed, long time){ + if (time - lastTimeUpdated > OsmandSettings.getSavingTrackInterval(ctx)) { + SQLiteDatabase db = getWritableDatabase(); + if (db != null) { + db.execSQL(updateScript, new Object[] { lat, lon, alt, speed, time }); + } + lastTimeUpdated = time; + } + } + + +} diff --git a/OsmAnd/src/com/osmand/activities/SettingsActivity.java b/OsmAnd/src/com/osmand/activities/SettingsActivity.java index deef9db364..8780be1ad1 100644 --- a/OsmAnd/src/com/osmand/activities/SettingsActivity.java +++ b/OsmAnd/src/com/osmand/activities/SettingsActivity.java @@ -30,6 +30,9 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference private CheckBoxPreference useEnglishNames; private CheckBoxPreference showOsmBugs; private EditTextPreference userName; + private CheckBoxPreference saveTrackToGpx; + private ListPreference saveTrackInterval; + private Preference saveCurrentTrack; @Override public void onCreate(Bundle savedInstanceState) { @@ -46,11 +49,19 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference showViewAngle.setOnPreferenceChangeListener(this); showOsmBugs =(CheckBoxPreference) screen.findPreference(OsmandSettings.SHOW_OSM_BUGS); showOsmBugs.setOnPreferenceChangeListener(this); + useEnglishNames =(CheckBoxPreference) screen.findPreference(OsmandSettings.USE_ENGLISH_NAMES); useEnglishNames.setOnPreferenceChangeListener(this); userName = (EditTextPreference) screen.findPreference(OsmandSettings.USER_NAME); userName.setOnPreferenceChangeListener(this); + saveTrackToGpx =(CheckBoxPreference) screen.findPreference(OsmandSettings.SAVE_TRACK_TO_GPX); + saveTrackToGpx.setOnPreferenceChangeListener(this); + saveTrackInterval =(ListPreference) screen.findPreference(OsmandSettings.SAVE_TRACK_INTERVAL); + saveTrackInterval.setOnPreferenceChangeListener(this); + saveCurrentTrack =(Preference) screen.findPreference(OsmandSettings.SAVE_CURRENT_TRACK); + saveCurrentTrack.setOnPreferenceChangeListener(this); + positionOnMap =(ListPreference) screen.findPreference(OsmandSettings.POSITION_ON_MAP); positionOnMap.setOnPreferenceChangeListener(this); tileSourcePreference =(ListPreference) screen.findPreference(OsmandSettings.MAP_TILE_SOURCES); @@ -67,6 +78,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference rotateMapToBearing.setChecked(OsmandSettings.isRotateMapToBearing(this)); showViewAngle.setChecked(OsmandSettings.isShowingViewAngle(this)); showOsmBugs.setChecked(OsmandSettings.isShowingOsmBugs(this)); + saveTrackToGpx.setChecked(OsmandSettings.isSavingTrackToGpx(this)); useEnglishNames.setChecked(OsmandSettings.usingEnglishNames(this)); String[] e = new String[] { "Center", "Bottom" }; positionOnMap.setEntryValues(e); @@ -74,6 +86,10 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference positionOnMap.setValueIndex(OsmandSettings.getPositionOnMap(this)); userName.setText(OsmandSettings.getUserName(this)); + saveTrackInterval.setEntries(new String[]{"1 second", "2 seconds", "5 seconds", "15 seconds", "30 seconds", "1 minute", "5 minute"}); + saveTrackInterval.setEntryValues(new String[]{"1", "2", "5", "15", "30", "60", "300"}); + saveTrackInterval.setValue(OsmandSettings.getSavingTrackInterval(this)+""); + List list = TileSourceManager.getKnownSourceTemplates(); String[] entries = new String[list.size()]; @@ -105,6 +121,16 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference } else if(preference == useEnglishNames){ edit.putBoolean(OsmandSettings.USE_ENGLISH_NAMES, (Boolean) newValue); edit.commit(); + } else if(preference == saveTrackToGpx){ + edit.putBoolean(OsmandSettings.SAVE_TRACK_TO_GPX, (Boolean) newValue); + edit.commit(); + } else if(preference == saveCurrentTrack){ + SavingTrackHelper helper = new SavingTrackHelper(this); + helper.saveDataToGpx(); + helper.close(); + } else if(preference == saveTrackInterval){ + edit.putInt(OsmandSettings.SAVE_TRACK_INTERVAL, Integer.parseInt(newValue.toString())); + edit.commit(); } else if(preference == userName){ edit.putString(OsmandSettings.USER_NAME, (String) newValue); edit.commit(); diff --git a/OsmAnd/src/com/osmand/views/MapInfoLayer.java b/OsmAnd/src/com/osmand/views/MapInfoLayer.java index b15fda466a..c52decfbb3 100644 --- a/OsmAnd/src/com/osmand/views/MapInfoLayer.java +++ b/OsmAnd/src/com/osmand/views/MapInfoLayer.java @@ -35,7 +35,7 @@ public class MapInfoLayer implements OsmandMapLayer { private String cachedDistString = null; private int cachedMeters = 0; private String cachedSpeedString = null; - private int cachedSpeed = 0; + private float cachedSpeed = 0; private int cachedZoom = 0; private String cachedZoomString = ""; @@ -127,9 +127,9 @@ public class MapInfoLayer implements OsmandMapLayer { // draw speed if(map.getLastKnownLocation() != null && map.getLastKnownLocation().hasSpeed()){ - if(cachedSpeed != (int) map.getLastKnownLocation().getSpeed()){ + if(Math.abs(map.getLastKnownLocation().getSpeed() - cachedSpeed) > .3f){ cachedSpeed = (int) map.getLastKnownLocation().getSpeed(); - cachedSpeedString = ((int) (cachedSpeed * 3.6d)) + " km/h"; + cachedSpeedString = ((int) (cachedSpeed * 3.6f)) + " km/h"; float right = paintBlack.measureText(cachedSpeedString) + 8 + boundsForSpeed.left; boundsForSpeed.right = boundsForDist.right = Math.max(right, boundsForDist.right); }