fix small issues
implement save track to gpx git-svn-id: https://osmand.googlecode.com/svn/trunk@159 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
f6d509325b
commit
d3f51f9c0f
13 changed files with 325 additions and 34 deletions
|
@ -16,7 +16,6 @@ public class ToDoConstants {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write activity to show something about authors / donation ....
|
* 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)
|
// 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))
|
// ( 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)
|
// 8. Enable change POI directly on map (requires OSM login)
|
||||||
// 33. Build transport locations. Create transport index (transport-stops) (investigate) [TODO]
|
// 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.
|
// 42. Revise UI (icons/layouts). Support different devices. Add inactive/focus(!) icon versions.
|
||||||
// 36. Postcode search
|
// 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).
|
// 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)
|
// 40. Support simple vector road rendering (require new index file)
|
||||||
|
|
||||||
|
|
||||||
// 43. Enable poi filter by name
|
// 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. (?)
|
// 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
|
// BUGS Android
|
||||||
// 5. Improvement : Implement caching files existing on FS, implement specific method in RM
|
// 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)
|
// 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
|
// BUGS Swing
|
||||||
// 1. Bug renaming region
|
// 1. Bug renaming region
|
||||||
|
@ -57,19 +61,9 @@ public class ToDoConstants {
|
||||||
// 1. Download tiles without using dir tiles (?)
|
// 1. Download tiles without using dir tiles (?)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// DONE ANDROID :
|
// 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
|
// DONE SWING
|
||||||
// 2. Internal (Simplify MapPanel - introduce layers for it)
|
|
||||||
// 3. Implement clear progress.
|
|
||||||
}
|
}
|
||||||
|
|
10
DataExtractionOSM/src/com/osmand/Version.java
Normal file
10
DataExtractionOSM/src/com/osmand/Version.java
Normal file
|
@ -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;
|
||||||
|
|
||||||
|
}
|
|
@ -20,13 +20,9 @@ import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import com.osmand.Algoritms;
|
import com.osmand.Algoritms;
|
||||||
import com.osmand.LogUtil;
|
import com.osmand.LogUtil;
|
||||||
|
import com.osmand.Version;
|
||||||
|
|
||||||
public class MapTileDownloader {
|
public class MapTileDownloader {
|
||||||
// Application constants
|
|
||||||
public static String APP_NAME = "OsmAnd";
|
|
||||||
public static String APP_VERSION = "0.2";
|
|
||||||
|
|
||||||
|
|
||||||
// Download manager tile settings
|
// Download manager tile settings
|
||||||
public static int TILE_DOWNLOAD_THREADS = 4;
|
public static int TILE_DOWNLOAD_THREADS = 4;
|
||||||
public static int TILE_DOWNLOAD_SECONDS_TO_WORK = 25;
|
public static int TILE_DOWNLOAD_SECONDS_TO_WORK = 25;
|
||||||
|
@ -177,7 +173,7 @@ public class MapTileDownloader {
|
||||||
request.fileToSave.getParentFile().mkdirs();
|
request.fileToSave.getParentFile().mkdirs();
|
||||||
URL url = new URL(request.url);
|
URL url = new URL(request.url);
|
||||||
URLConnection connection = url.openConnection();
|
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);
|
BufferedInputStream inputStream = new BufferedInputStream(connection.getInputStream(), 8 * 1024);
|
||||||
FileOutputStream stream = null;
|
FileOutputStream stream = null;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -5,7 +5,9 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
|
|
||||||
public class TileSourceManager {
|
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 {
|
public static class TileSourceTemplate implements ITileSource {
|
||||||
private int maxZoom;
|
private int maxZoom;
|
||||||
private int minZoom;
|
private int minZoom;
|
||||||
|
@ -97,12 +99,16 @@ public class TileSourceManager {
|
||||||
list.add(getMapnikSource());
|
list.add(getMapnikSource());
|
||||||
list.add(getOsmaRenderSource());
|
list.add(getOsmaRenderSource());
|
||||||
list.add(getCycleMapSource());
|
list.add(getCycleMapSource());
|
||||||
|
list.add(getMapSurferSource());
|
||||||
|
list.add(getNavigationDebugSource());
|
||||||
// list.add(getAerialMapSource());
|
// list.add(getAerialMapSource());
|
||||||
|
|
||||||
list.add(getCloudMadeSource());
|
list.add(getCloudMadeSource());
|
||||||
list.add(getOpenPisteMapSource());
|
list.add(getOpenPisteMapSource());
|
||||||
list.add(getGoogleMapsSource());
|
list.add(getGoogleMapsSource());
|
||||||
list.add(getGoogleMapsSatelliteSource());
|
list.add(getGoogleMapsSatelliteSource());
|
||||||
list.add(getGoogleMapsTerrainSource());
|
list.add(getGoogleMapsTerrainSource());
|
||||||
|
|
||||||
list.add(getMicrosoftMapsSource());
|
list.add(getMicrosoftMapsSource());
|
||||||
list.add(getMicrosoftEarthSource());
|
list.add(getMicrosoftEarthSource());
|
||||||
list.add(getMicrosoftHybridSource());
|
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);
|
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(){
|
public static TileSourceTemplate getOpenPisteMapSource(){
|
||||||
return new TileSourceTemplate("OpenPisteMap", "http://openpistemap.org/tiles/contours/{0}/{1}/{2}.png", ".png", 17, 0, 256, 18000);
|
return new TileSourceTemplate("OpenPisteMap", "http://openpistemap.org/tiles/contours/{0}/{1}/{2}.png", ".png", 17, 0, 256, 18000);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
<string name="save_current_track_descr">Save current track to SD</string>
|
||||||
|
<string name="save_current_track">Save current track</string>
|
||||||
|
<string name="save_track_interval_descr">Choose time interval to save track</string>
|
||||||
|
<string name="save_track_interval">Save track interval</string>
|
||||||
|
<string name="monitor_preferences">Monitoring settings</string>
|
||||||
|
<string name="save_track_to_gpx_descrp">Tracks will be saved to track directory grouped by days</string>
|
||||||
|
<string name="save_track_to_gpx">Save track to gpx</string>
|
||||||
<string name="navigate_to">Navigate to</string>
|
<string name="navigate_to">Navigate to</string>
|
||||||
<string name="update_tile">Update map</string>
|
<string name="update_tile">Update map</string>
|
||||||
<string name="reload_tile">Reload tile</string>
|
<string name="reload_tile">Reload tile</string>
|
||||||
|
@ -29,14 +36,14 @@
|
||||||
<string name="map_view_3d">Map View 3D</string>
|
<string name="map_view_3d">Map View 3D</string>
|
||||||
<string name="rotate_map_to_bearing_descr">Rotate map to bearing of your direction</string>
|
<string name="rotate_map_to_bearing_descr">Rotate map to bearing of your direction</string>
|
||||||
<string name="rotate_map_to_bearing">Rotate map</string>
|
<string name="rotate_map_to_bearing">Rotate map</string>
|
||||||
<string name="show_poi_over_map_description">Show POI on map (zoom > 15)</string>
|
<string name="show_poi_over_map_description">Show POI over map (use last chosen filter)</string>
|
||||||
<string name="show_poi_over_map">Show POI</string>
|
<string name="show_poi_over_map">Show POI</string>
|
||||||
<string name="map_tile_source_descr">Choose the source of tiles:</string>
|
<string name="map_tile_source_descr">Choose the source of tiles:</string>
|
||||||
<string name="map_tile_source">Map tile source</string>
|
<string name="map_tile_source">Map tile source</string>
|
||||||
<string name="map_source">Map source</string>
|
<string name="map_source">Map source</string>
|
||||||
<string name="use_internet">Use internet</string>
|
<string name="use_internet">Use internet</string>
|
||||||
<string name="show_location">Show location</string>
|
<string name="show_location">Show location</string>
|
||||||
<string name="map_preferences">Map preferences</string>
|
<string name="map_preferences">Map settings</string>
|
||||||
<string name="settings_activity">Settings</string>
|
<string name="settings_activity">Settings</string>
|
||||||
<string name="show_gps_coordinates_text">Show gps coordinates on map</string>
|
<string name="show_gps_coordinates_text">Show gps coordinates on map</string>
|
||||||
<string name="use_internet_to_download_tile">Use internet to download missing tiles</string>
|
<string name="use_internet_to_download_tile">Use internet to download missing tiles</string>
|
||||||
|
|
|
@ -5,15 +5,19 @@
|
||||||
<EditTextPreference android:title="@string/user_name" android:summary="@string/user_name_descr" android:key="user_name"></EditTextPreference>
|
<EditTextPreference android:title="@string/user_name" android:summary="@string/user_name_descr" android:key="user_name"></EditTextPreference>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<PreferenceCategory android:title="@string/map_preferences">
|
<PreferenceCategory android:title="@string/map_preferences">
|
||||||
|
|
||||||
<CheckBoxPreference android:key="use_internet_to_download_tiles" android:title="@string/use_internet" android:summary="@string/use_internet_to_download_tile"></CheckBoxPreference>
|
<CheckBoxPreference android:key="use_internet_to_download_tiles" android:title="@string/use_internet" android:summary="@string/use_internet_to_download_tile"></CheckBoxPreference>
|
||||||
|
<ListPreference android:title="@string/map_tile_source" android:summary="@string/map_tile_source_descr" android:key="map_tile_sources"></ListPreference>
|
||||||
<CheckBoxPreference android:key="show_poi_over_map" android:title="@string/show_poi_over_map" android:summary="@string/show_poi_over_map_description"></CheckBoxPreference>
|
<CheckBoxPreference android:key="show_poi_over_map" android:title="@string/show_poi_over_map" android:summary="@string/show_poi_over_map_description"></CheckBoxPreference>
|
||||||
|
<CheckBoxPreference android:key="show_osm_bugs" android:title="@string/show_osm_bugs" android:summary="@string/show_osm_bugs_descr"></CheckBoxPreference>
|
||||||
<CheckBoxPreference android:key="rotate_map_to_bearing" android:title="@string/rotate_map_to_bearing" android:summary="@string/rotate_map_to_bearing_descr"></CheckBoxPreference>
|
<CheckBoxPreference android:key="rotate_map_to_bearing" android:title="@string/rotate_map_to_bearing" android:summary="@string/rotate_map_to_bearing_descr"></CheckBoxPreference>
|
||||||
<CheckBoxPreference android:key="show_view_angle" android:title="@string/show_view_angle" android:summary="@string/show_view_angle_descr"></CheckBoxPreference>
|
<CheckBoxPreference android:key="show_view_angle" android:title="@string/show_view_angle" android:summary="@string/show_view_angle_descr"></CheckBoxPreference>
|
||||||
<CheckBoxPreference android:key="show_osm_bugs" android:title="@string/show_osm_bugs" android:summary="@string/show_osm_bugs_descr"></CheckBoxPreference>
|
|
||||||
<ListPreference android:key="position_on_map" android:title="@string/position_on_map" android:summary="@string/position_on_map_descr"></ListPreference>
|
<ListPreference android:key="position_on_map" android:title="@string/position_on_map" android:summary="@string/position_on_map_descr"></ListPreference>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<PreferenceCategory android:title="@string/map_source"><ListPreference android:title="@string/map_tile_source" android:summary="@string/map_tile_source_descr" android:key="map_tile_sources"></ListPreference>
|
|
||||||
</PreferenceCategory>
|
|
||||||
|
|
||||||
|
|
||||||
|
<PreferenceCategory android:title="@string/monitor_preferences">
|
||||||
|
<CheckBoxPreference android:summary="@string/save_track_to_gpx_descrp" android:title="@string/save_track_to_gpx" android:key="save_track_to_gpx"></CheckBoxPreference>
|
||||||
|
<ListPreference android:summary="@string/save_track_interval_descr" android:title="@string/save_track_interval" android:key="save_track_interval"></ListPreference>
|
||||||
|
<Preference android:summary="@string/save_current_track_descr" android:title="@string/save_current_track" android:key="save_current_track"></Preference>
|
||||||
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
|
@ -45,6 +45,23 @@ public class OsmandSettings {
|
||||||
return prefs.edit().putString(USER_NAME, name).commit();
|
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
|
// this value string is synchronized with settings_pref.xml preference name
|
||||||
public static final String SHOW_OSM_BUGS = "show_osm_bugs";
|
public static final String SHOW_OSM_BUGS = "show_osm_bugs";
|
||||||
|
|
|
@ -101,7 +101,7 @@ public class PoiFiltersHelper {
|
||||||
private static List<PoiFilter> cacheUserDefinedFilters;
|
private static List<PoiFilter> cacheUserDefinedFilters;
|
||||||
public static List<PoiFilter> getUserDefinedPoiFilters(Context ctx){
|
public static List<PoiFilter> getUserDefinedPoiFilters(Context ctx){
|
||||||
if(cacheUserDefinedFilters == null){
|
if(cacheUserDefinedFilters == null){
|
||||||
ctx.deleteDatabase(PoiFilterDbHelper.DATABASE_NAME);
|
////ctx.deleteDatabase(PoiFilterDbHelper.DATABASE_NAME);
|
||||||
|
|
||||||
cacheUserDefinedFilters = new ArrayList<PoiFilter>();
|
cacheUserDefinedFilters = new ArrayList<PoiFilter>();
|
||||||
PoiFilterDbHelper helper = new PoiFilterDbHelper(ctx);
|
PoiFilterDbHelper helper = new PoiFilterDbHelper(ctx);
|
||||||
|
|
|
@ -90,7 +90,9 @@ public class MainMenuActivity extends Activity {
|
||||||
getPreferences(MODE_WORLD_READABLE).edit().putLong(EXCEPTION_FILE_SIZE, 0).commit();
|
getPreferences(MODE_WORLD_READABLE).edit().putLong(EXCEPTION_FILE_SIZE, 0).commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SavingTrackHelper helper = new SavingTrackHelper(this);
|
||||||
|
helper.saveDataToGpx();
|
||||||
|
helper.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,12 +64,15 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
||||||
private POIMapLayer poiMapLayer;
|
private POIMapLayer poiMapLayer;
|
||||||
private MapInfoLayer mapInfoLayer;
|
private MapInfoLayer mapInfoLayer;
|
||||||
private OsmBugsLayer osmBugsLayer;
|
private OsmBugsLayer osmBugsLayer;
|
||||||
|
private SavingTrackHelper savingTrackHelper;
|
||||||
|
|
||||||
private WakeLock wakeLock;
|
private WakeLock wakeLock;
|
||||||
private boolean sensorRegistered = false;
|
private boolean sensorRegistered = false;
|
||||||
|
|
||||||
private MenuItem navigateToPointMenu;
|
private MenuItem navigateToPointMenu;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private boolean isMapLinkedToLocation(){
|
private boolean isMapLinkedToLocation(){
|
||||||
return OsmandSettings.isMapSyncToGpsLocation(this);
|
return OsmandSettings.isMapSyncToGpsLocation(this);
|
||||||
}
|
}
|
||||||
|
@ -95,6 +98,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
||||||
mapInfoLayer = new MapInfoLayer(this);
|
mapInfoLayer = new MapInfoLayer(this);
|
||||||
mapView.addLayer(mapInfoLayer);
|
mapView.addLayer(mapInfoLayer);
|
||||||
osmBugsLayer = new OsmBugsLayer(this);
|
osmBugsLayer = new OsmBugsLayer(this);
|
||||||
|
savingTrackHelper = new SavingTrackHelper(this);
|
||||||
|
|
||||||
|
|
||||||
LatLon pointToNavigate = OsmandSettings.getPointToNavigate(this);
|
LatLon pointToNavigate = OsmandSettings.getPointToNavigate(this);
|
||||||
|
@ -202,11 +206,11 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
savingTrackHelper.close();
|
||||||
MapTileDownloader.getInstance().removeDownloaderCallback(mapView);
|
MapTileDownloader.getInstance().removeDownloaderCallback(mapView);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocation(Location location){
|
public void setLocation(Location location){
|
||||||
// Do very strange manipulation to call redraw only once
|
|
||||||
|
|
||||||
// show point view only if gps enabled
|
// show point view only if gps enabled
|
||||||
if(location == null){
|
if(location == null){
|
||||||
|
@ -272,6 +276,10 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(Location location) {
|
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);
|
setLocation(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
212
OsmAnd/src/com/osmand/activities/SavingTrackHelper.java
Normal file
212
OsmAnd/src/com/osmand/activities/SavingTrackHelper.java
Normal file
|
@ -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<String, List<List<TrkPt>>> 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<TrkPt> 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<String, List<List<TrkPt>>> data = new LinkedHashMap<String, List<List<TrkPt>>>();
|
||||||
|
List<TrkPt> segment = new ArrayList<TrkPt>();
|
||||||
|
List<List<TrkPt>> track = new ArrayList<List<TrkPt>>();
|
||||||
|
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<TrkPt>();
|
||||||
|
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<List<TrkPt>>();
|
||||||
|
data.put(date, track);
|
||||||
|
}
|
||||||
|
segment = new ArrayList<TrkPt>();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -30,6 +30,9 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
private CheckBoxPreference useEnglishNames;
|
private CheckBoxPreference useEnglishNames;
|
||||||
private CheckBoxPreference showOsmBugs;
|
private CheckBoxPreference showOsmBugs;
|
||||||
private EditTextPreference userName;
|
private EditTextPreference userName;
|
||||||
|
private CheckBoxPreference saveTrackToGpx;
|
||||||
|
private ListPreference saveTrackInterval;
|
||||||
|
private Preference saveCurrentTrack;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -46,11 +49,19 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
showViewAngle.setOnPreferenceChangeListener(this);
|
showViewAngle.setOnPreferenceChangeListener(this);
|
||||||
showOsmBugs =(CheckBoxPreference) screen.findPreference(OsmandSettings.SHOW_OSM_BUGS);
|
showOsmBugs =(CheckBoxPreference) screen.findPreference(OsmandSettings.SHOW_OSM_BUGS);
|
||||||
showOsmBugs.setOnPreferenceChangeListener(this);
|
showOsmBugs.setOnPreferenceChangeListener(this);
|
||||||
|
|
||||||
useEnglishNames =(CheckBoxPreference) screen.findPreference(OsmandSettings.USE_ENGLISH_NAMES);
|
useEnglishNames =(CheckBoxPreference) screen.findPreference(OsmandSettings.USE_ENGLISH_NAMES);
|
||||||
useEnglishNames.setOnPreferenceChangeListener(this);
|
useEnglishNames.setOnPreferenceChangeListener(this);
|
||||||
userName = (EditTextPreference) screen.findPreference(OsmandSettings.USER_NAME);
|
userName = (EditTextPreference) screen.findPreference(OsmandSettings.USER_NAME);
|
||||||
userName.setOnPreferenceChangeListener(this);
|
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 =(ListPreference) screen.findPreference(OsmandSettings.POSITION_ON_MAP);
|
||||||
positionOnMap.setOnPreferenceChangeListener(this);
|
positionOnMap.setOnPreferenceChangeListener(this);
|
||||||
tileSourcePreference =(ListPreference) screen.findPreference(OsmandSettings.MAP_TILE_SOURCES);
|
tileSourcePreference =(ListPreference) screen.findPreference(OsmandSettings.MAP_TILE_SOURCES);
|
||||||
|
@ -67,6 +78,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
rotateMapToBearing.setChecked(OsmandSettings.isRotateMapToBearing(this));
|
rotateMapToBearing.setChecked(OsmandSettings.isRotateMapToBearing(this));
|
||||||
showViewAngle.setChecked(OsmandSettings.isShowingViewAngle(this));
|
showViewAngle.setChecked(OsmandSettings.isShowingViewAngle(this));
|
||||||
showOsmBugs.setChecked(OsmandSettings.isShowingOsmBugs(this));
|
showOsmBugs.setChecked(OsmandSettings.isShowingOsmBugs(this));
|
||||||
|
saveTrackToGpx.setChecked(OsmandSettings.isSavingTrackToGpx(this));
|
||||||
useEnglishNames.setChecked(OsmandSettings.usingEnglishNames(this));
|
useEnglishNames.setChecked(OsmandSettings.usingEnglishNames(this));
|
||||||
String[] e = new String[] { "Center", "Bottom" };
|
String[] e = new String[] { "Center", "Bottom" };
|
||||||
positionOnMap.setEntryValues(e);
|
positionOnMap.setEntryValues(e);
|
||||||
|
@ -74,6 +86,10 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
positionOnMap.setValueIndex(OsmandSettings.getPositionOnMap(this));
|
positionOnMap.setValueIndex(OsmandSettings.getPositionOnMap(this));
|
||||||
userName.setText(OsmandSettings.getUserName(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<TileSourceTemplate> list = TileSourceManager.getKnownSourceTemplates();
|
List<TileSourceTemplate> list = TileSourceManager.getKnownSourceTemplates();
|
||||||
String[] entries = new String[list.size()];
|
String[] entries = new String[list.size()];
|
||||||
|
@ -105,6 +121,16 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||||
} else if(preference == useEnglishNames){
|
} else if(preference == useEnglishNames){
|
||||||
edit.putBoolean(OsmandSettings.USE_ENGLISH_NAMES, (Boolean) newValue);
|
edit.putBoolean(OsmandSettings.USE_ENGLISH_NAMES, (Boolean) newValue);
|
||||||
edit.commit();
|
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){
|
} else if(preference == userName){
|
||||||
edit.putString(OsmandSettings.USER_NAME, (String) newValue);
|
edit.putString(OsmandSettings.USER_NAME, (String) newValue);
|
||||||
edit.commit();
|
edit.commit();
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class MapInfoLayer implements OsmandMapLayer {
|
||||||
private String cachedDistString = null;
|
private String cachedDistString = null;
|
||||||
private int cachedMeters = 0;
|
private int cachedMeters = 0;
|
||||||
private String cachedSpeedString = null;
|
private String cachedSpeedString = null;
|
||||||
private int cachedSpeed = 0;
|
private float cachedSpeed = 0;
|
||||||
private int cachedZoom = 0;
|
private int cachedZoom = 0;
|
||||||
private String cachedZoomString = "";
|
private String cachedZoomString = "";
|
||||||
|
|
||||||
|
@ -127,9 +127,9 @@ public class MapInfoLayer implements OsmandMapLayer {
|
||||||
|
|
||||||
// draw speed
|
// draw speed
|
||||||
if(map.getLastKnownLocation() != null && map.getLastKnownLocation().hasSpeed()){
|
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();
|
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;
|
float right = paintBlack.measureText(cachedSpeedString) + 8 + boundsForSpeed.left;
|
||||||
boundsForSpeed.right = boundsForDist.right = Math.max(right, boundsForDist.right);
|
boundsForSpeed.right = boundsForDist.right = Math.max(right, boundsForDist.right);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue