This commit is contained in:
Nazar 2019-11-27 15:58:41 +02:00
parent aedb503597
commit c0c7254930
7 changed files with 54 additions and 13 deletions

View file

@ -187,6 +187,7 @@ public class GPXUtilities {
public double ele = Double.NaN; public double ele = Double.NaN;
public double speed = 0; public double speed = 0;
public double hdop = Double.NaN; public double hdop = Double.NaN;
public float heading = -1.0f;
public boolean deleted = false; public boolean deleted = false;
public int colourARGB = 0; // point colour (used for altitude/speed colouring) public int colourARGB = 0; // point colour (used for altitude/speed colouring)
public double distance = 0.0; // cumulative distance, if in a track public double distance = 0.0; // cumulative distance, if in a track
@ -208,6 +209,7 @@ public class GPXUtilities {
this.ele = wptPt.ele; this.ele = wptPt.ele;
this.speed = wptPt.speed; this.speed = wptPt.speed;
this.hdop = wptPt.hdop; this.hdop = wptPt.hdop;
this.heading = wptPt.heading;
this.deleted = wptPt.deleted; this.deleted = wptPt.deleted;
this.colourARGB = wptPt.colourARGB; this.colourARGB = wptPt.colourARGB;
this.distance = wptPt.distance; this.distance = wptPt.distance;
@ -233,14 +235,22 @@ public class GPXUtilities {
return lon; return lon;
} }
public float getHeading() {
return heading;
}
public WptPt(double lat, double lon, long time, double ele, double speed, double hdop) { public WptPt(double lat, double lon, long time, double ele, double speed, double hdop) {
this(lat, lon, time, ele, speed, hdop, -1.0f);
}
public WptPt(double lat, double lon, long time, double ele, double speed, double hdop, float heading) {
this.lat = lat; this.lat = lat;
this.lon = lon; this.lon = lon;
this.time = time; this.time = time;
this.ele = ele; this.ele = ele;
this.speed = speed; this.speed = speed;
this.hdop = hdop; this.hdop = hdop;
this.heading = heading;
} }
public boolean isVisible() { public boolean isVisible() {
@ -1606,6 +1616,9 @@ public class GPXUtilities {
if (p.speed > 0) { if (p.speed > 0) {
p.getExtensionsToWrite().put("speed", decimalFormat.format(p.speed)); p.getExtensionsToWrite().put("speed", decimalFormat.format(p.speed));
} }
if (p.heading >= 0) {
p.getExtensionsToWrite().put("heading", decimalFormat.format(p.heading));
}
writeExtensions(serializer, p); writeExtensions(serializer, p);
} }

View file

@ -410,6 +410,16 @@ public class MapUtils {
} }
return rotate; return rotate;
} }
public static float formatDegrees360(float degrees) {
while (degrees < 0.0f) {
degrees += 360.0f;
}
while (degrees >= 360.0f) {
degrees -= 360.0f;
}
return degrees;
}
/** /**
* @param diff align difference between 2 angles ]-PI, PI] * @param diff align difference between 2 angles ]-PI, PI]

View file

@ -11,6 +11,8 @@
Thx - Hardy Thx - Hardy
--> -->
<string name="calculate_heading">Calculate heading</string>
<string name="calculate_heading_descr">Calculate and save heading to each trackpoint while recording.</string>
<string name="rendering_value_walkingRoutesOSMCNodes_name">Node networks</string> <string name="rendering_value_walkingRoutesOSMCNodes_name">Node networks</string>
<string name="rendering_attr_showCycleNodeNetworkRoutes_name">Show node network cycle routes</string> <string name="rendering_attr_showCycleNodeNetworkRoutes_name">Show node network cycle routes</string>
<string name="join_segments">Join segments</string> <string name="join_segments">Join segments</string>

View file

@ -771,7 +771,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
if (continuous) { if (continuous) {
scheduleCheckIfGpsLost(location); scheduleCheckIfGpsLost(location);
} }
app.getSavingTrackHelper().updateLocation(location); app.getSavingTrackHelper().updateLocation(location, app.getLocationProvider().heading);
OsmandPlugin.updateLocationPlugins(location); OsmandPlugin.updateLocationPlugins(location);
app.getRoutingHelper().updateLocation(location); app.getRoutingHelper().updateLocation(location);
app.getWaypointHelper().locationChanged(location); app.getWaypointHelper().locationChanged(location);
@ -797,7 +797,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
final RoutingHelper routingHelper = app.getRoutingHelper(); final RoutingHelper routingHelper = app.getRoutingHelper();
// 1. Logging services // 1. Logging services
if (location != null) { if (location != null) {
app.getSavingTrackHelper().updateLocation(location); app.getSavingTrackHelper().updateLocation(location, app.getLocationProvider().heading);
OsmandPlugin.updateLocationPlugins(location); OsmandPlugin.updateLocationPlugins(location);
} }

View file

@ -1607,6 +1607,8 @@ public class OsmandSettings {
public static final Integer DAILY_DIRECTORY = 2; public static final Integer DAILY_DIRECTORY = 2;
public final CommonPreference<Boolean> DISABLE_RECORDING_ONCE_APP_KILLED = new BooleanPreference("disable_recording_once_app_killed", false).makeProfile().makeGeneral(); public final CommonPreference<Boolean> DISABLE_RECORDING_ONCE_APP_KILLED = new BooleanPreference("disable_recording_once_app_killed", false).makeProfile().makeGeneral();
public final CommonPreference<Boolean> CALCULATE_HEADING = new BooleanPreference("calculate_heading", false).makeProfile().makeGeneral();
public final CommonPreference<Integer> TRACK_STORAGE_DIRECTORY = new IntPreference("track_storage_directory", 0).makeProfile().makeGeneral(); public final CommonPreference<Integer> TRACK_STORAGE_DIRECTORY = new IntPreference("track_storage_directory", 0).makeProfile().makeGeneral();

View file

@ -37,7 +37,7 @@ import java.util.Map;
public class SavingTrackHelper extends SQLiteOpenHelper { public class SavingTrackHelper extends SQLiteOpenHelper {
public final static String DATABASE_NAME = "tracks"; //$NON-NLS-1$ public final static String DATABASE_NAME = "tracks"; //$NON-NLS-1$
public final static int DATABASE_VERSION = 5; public final static int DATABASE_VERSION = 6;
public final static String TRACK_NAME = "track"; //$NON-NLS-1$ public final static String TRACK_NAME = "track"; //$NON-NLS-1$
public final static String TRACK_COL_DATE = "date"; //$NON-NLS-1$ public final static String TRACK_COL_DATE = "date"; //$NON-NLS-1$
@ -46,6 +46,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
public final static String TRACK_COL_ALTITUDE = "altitude"; //$NON-NLS-1$ public final static String TRACK_COL_ALTITUDE = "altitude"; //$NON-NLS-1$
public final static String TRACK_COL_SPEED = "speed"; //$NON-NLS-1$ public final static String TRACK_COL_SPEED = "speed"; //$NON-NLS-1$
public final static String TRACK_COL_HDOP = "hdop"; //$NON-NLS-1$ public final static String TRACK_COL_HDOP = "hdop"; //$NON-NLS-1$
public final static String TRACK_COL_HEADING = "heading"; //$NON-NLS-1$
public final static String POINT_NAME = "point"; //$NON-NLS-1$ public final static String POINT_NAME = "point"; //$NON-NLS-1$
public final static String POINT_COL_DATE = "date"; //$NON-NLS-1$ public final static String POINT_COL_DATE = "date"; //$NON-NLS-1$
@ -82,8 +83,9 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
prepareCurrentTrackForRecording(); prepareCurrentTrackForRecording();
updateScript = "INSERT INTO " + TRACK_NAME + " (" + TRACK_COL_LAT + ", " + TRACK_COL_LON + ", " updateScript = "INSERT INTO " + TRACK_NAME + " (" + TRACK_COL_LAT + ", " + TRACK_COL_LON + ", "
+ TRACK_COL_ALTITUDE + ", " + TRACK_COL_SPEED + ", " + TRACK_COL_HDOP + ", " + TRACK_COL_DATE + ")" + TRACK_COL_ALTITUDE + ", " + TRACK_COL_SPEED + ", " + TRACK_COL_HDOP + ", "
+ " VALUES (?, ?, ?, ?, ?, ?)"; //$NON-NLS-1$ //$NON-NLS-2$ + TRACK_COL_DATE + ", " + TRACK_COL_HEADING + ")"
+ " VALUES (?, ?, ?, ?, ?, ?, ?)"; //$NON-NLS-1$ //$NON-NLS-2$
insertPointsScript = "INSERT INTO " + POINT_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?)"; //$NON-NLS-1$ //$NON-NLS-2$ insertPointsScript = "INSERT INTO " + POINT_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?)"; //$NON-NLS-1$ //$NON-NLS-2$
} }
@ -97,7 +99,8 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
private void createTableForTrack(SQLiteDatabase db){ private void createTableForTrack(SQLiteDatabase db){
db.execSQL("CREATE TABLE " + TRACK_NAME + " (" + TRACK_COL_LAT + " double, " + TRACK_COL_LON + " double, " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ db.execSQL("CREATE TABLE " + TRACK_NAME + " (" + TRACK_COL_LAT + " double, " + TRACK_COL_LON + " double, " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ TRACK_COL_ALTITUDE + " double, " + TRACK_COL_SPEED + " double, " //$NON-NLS-1$ //$NON-NLS-2$ + TRACK_COL_ALTITUDE + " double, " + TRACK_COL_SPEED + " double, " //$NON-NLS-1$ //$NON-NLS-2$
+ TRACK_COL_HDOP + " double, " + TRACK_COL_DATE + " long )"); //$NON-NLS-1$ //$NON-NLS-2$ + TRACK_COL_HDOP + " double, " + TRACK_COL_DATE + " long, "
+ TRACK_COL_HEADING + " float )"); //$NON-NLS-1$ //$NON-NLS-2$
} }
private void createTableForPoints(SQLiteDatabase db){ private void createTableForPoints(SQLiteDatabase db){
@ -125,6 +128,9 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
if(oldVersion < 5){ if(oldVersion < 5){
db.execSQL("ALTER TABLE " + POINT_NAME + " ADD " + POINT_COL_COLOR + " long"); db.execSQL("ALTER TABLE " + POINT_NAME + " ADD " + POINT_COL_COLOR + " long");
} }
if(oldVersion < 6){
db.execSQL("ALTER TABLE " + TRACK_NAME + " ADD " + TRACK_COL_HEADING + " float");
}
} }
@ -321,7 +327,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
private void collectDBTracks(SQLiteDatabase db, Map<String, GPXFile> dataTracks) { private void collectDBTracks(SQLiteDatabase db, Map<String, GPXFile> dataTracks) {
Cursor query = db.rawQuery("SELECT " + TRACK_COL_LAT + "," + TRACK_COL_LON + "," + TRACK_COL_ALTITUDE + "," //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ Cursor query = db.rawQuery("SELECT " + TRACK_COL_LAT + "," + TRACK_COL_LON + "," + TRACK_COL_ALTITUDE + "," //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ TRACK_COL_SPEED + "," + TRACK_COL_HDOP + "," + TRACK_COL_DATE + " FROM " + TRACK_NAME +" ORDER BY " + TRACK_COL_DATE +" ASC", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + TRACK_COL_SPEED + "," + TRACK_COL_HDOP + "," + TRACK_COL_DATE + "," + TRACK_COL_HEADING + " FROM " + TRACK_NAME +" ORDER BY " + TRACK_COL_DATE +" ASC", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
long previousTime = 0; long previousTime = 0;
long previousInterval = 0; long previousInterval = 0;
TrkSegment segment = null; TrkSegment segment = null;
@ -336,6 +342,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
pt.hdop = query.getDouble(4); pt.hdop = query.getDouble(4);
long time = query.getLong(5); long time = query.getLong(5);
pt.time = time; pt.time = time;
pt.heading = query.getFloat(6);
long currentInterval = Math.abs(time - previousTime); long currentInterval = Math.abs(time - previousTime);
boolean newInterval = pt.lat == 0 && pt.lon == 0; boolean newInterval = pt.lat == 0 && pt.lon == 0;
@ -402,14 +409,19 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
public void startNewSegment() { public void startNewSegment() {
lastTimeUpdated = 0; lastTimeUpdated = 0;
lastPoint = null; lastPoint = null;
execWithClose(updateScript, new Object[] { 0, 0, 0, 0, 0, System.currentTimeMillis()}); execWithClose(updateScript, new Object[] { 0, 0, 0, 0, 0, System.currentTimeMillis(), -1.0f});
addTrackPoint(null, true, System.currentTimeMillis()); addTrackPoint(null, true, System.currentTimeMillis());
} }
public void updateLocation(net.osmand.Location location) { public void updateLocation(net.osmand.Location location, Float heading) {
// use because there is a bug on some devices with location.getTime() // use because there is a bug on some devices with location.getTime()
long locationTime = System.currentTimeMillis(); long locationTime = System.currentTimeMillis();
OsmandSettings settings = ctx.getSettings(); OsmandSettings settings = ctx.getSettings();
if (heading != null && settings.CALCULATE_HEADING.get()) {
heading = MapUtils.formatDegrees360(heading);
} else {
heading = -1.0f;
}
boolean record = false; boolean record = false;
if (location != null && OsmAndLocationProvider.isNotSimulatedLocation(location)) { if (location != null && OsmAndLocationProvider.isNotSimulatedLocation(location)) {
if (settings.SAVE_TRACK_TO_GPX.get() if (settings.SAVE_TRACK_TO_GPX.get()
@ -436,16 +448,16 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
} }
if (record) { if (record) {
insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getSpeed(), insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getSpeed(),
location.getAccuracy(), locationTime, settings); location.getAccuracy(), locationTime, heading, settings);
ctx.getNotificationHelper().refreshNotification(NotificationType.GPX); ctx.getNotificationHelper().refreshNotification(NotificationType.GPX);
} }
} }
public void insertData(double lat, double lon, double alt, double speed, double hdop, long time, public void insertData(double lat, double lon, double alt, double speed, double hdop, long time, float heading,
OsmandSettings settings) { OsmandSettings settings) {
// * 1000 in next line seems to be wrong with new IntervalChooseDialog // * 1000 in next line seems to be wrong with new IntervalChooseDialog
// if (time - lastTimeUpdated > settings.SAVE_TRACK_INTERVAL.get() * 1000) { // if (time - lastTimeUpdated > settings.SAVE_TRACK_INTERVAL.get() * 1000) {
execWithClose(updateScript, new Object[] { lat, lon, alt, speed, hdop, time }); execWithClose(updateScript, new Object[] { lat, lon, alt, speed, hdop, time, heading });
boolean newSegment = false; boolean newSegment = false;
if (lastPoint == null || (time - lastTimeUpdated) > 180 * 1000) { if (lastPoint == null || (time - lastTimeUpdated) > 180 * 1000) {
lastPoint = new LatLon(lat, lon); lastPoint = new LatLon(lat, lon);
@ -461,7 +473,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
lastPoint = new LatLon(lat, lon); lastPoint = new LatLon(lat, lon);
} }
lastTimeUpdated = time; lastTimeUpdated = time;
WptPt pt = new GPXUtilities.WptPt(lat, lon, time, alt, speed, hdop); WptPt pt = new GPXUtilities.WptPt(lat, lon, time, alt, speed, hdop, heading);
addTrackPoint(pt, newSegment, time); addTrackPoint(pt, newSegment, time);
trkPoints++; trkPoints++;
} }

View file

@ -152,6 +152,8 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
R.string.auto_split_recording_descr)); R.string.auto_split_recording_descr));
cat.addPreference(createCheckBoxPreference(settings.DISABLE_RECORDING_ONCE_APP_KILLED, R.string.disable_recording_once_app_killed, cat.addPreference(createCheckBoxPreference(settings.DISABLE_RECORDING_ONCE_APP_KILLED, R.string.disable_recording_once_app_killed,
R.string.disable_recording_once_app_killed_descrp)); R.string.disable_recording_once_app_killed_descrp));
cat.addPreference(createCheckBoxPreference(settings.CALCULATE_HEADING, R.string.calculate_heading,
R.string.calculate_heading_descr));
Integer[] intValues = new Integer[]{REC_DIRECTORY, MONTHLY_DIRECTORY, DAILY_DIRECTORY}; Integer[] intValues = new Integer[]{REC_DIRECTORY, MONTHLY_DIRECTORY, DAILY_DIRECTORY};
names = new String[intValues.length]; names = new String[intValues.length];