Merge pull request #7992 from osmandapp/fix_7394

Fix #7394
This commit is contained in:
max-klaus 2019-11-29 14:07:06 +03:00 committed by GitHub
commit fe29de8bdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 58 additions and 13 deletions

View file

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

View file

@ -410,6 +410,16 @@ public class MapUtils {
}
return rotate;
}
public static float normalizeDegrees360(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]

View file

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

View file

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

View file

@ -1607,6 +1607,8 @@ public class OsmandSettings {
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> SAVE_HEADING_TO_GPX = new BooleanPreference("save_heading_to_gpx", false).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 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_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_SPEED = "speed"; //$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_COL_DATE = "date"; //$NON-NLS-1$
@ -55,6 +56,8 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
public final static String POINT_COL_CATEGORY = "category"; //$NON-NLS-1$
public final static String POINT_COL_DESCRIPTION = "description"; //$NON-NLS-1$
public final static String POINT_COL_COLOR = "color"; //$NON-NLS-1$
public final static float NO_HEADING = -1.0f;
public final static Log log = PlatformUtil.getLog(SavingTrackHelper.class);
@ -82,8 +85,9 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
prepareCurrentTrackForRecording();
updateScript = "INSERT INTO " + TRACK_NAME + " (" + TRACK_COL_LAT + ", " + TRACK_COL_LON + ", "
+ TRACK_COL_ALTITUDE + ", " + TRACK_COL_SPEED + ", " + TRACK_COL_HDOP + ", " + TRACK_COL_DATE + ")"
+ " VALUES (?, ?, ?, ?, ?, ?)"; //$NON-NLS-1$ //$NON-NLS-2$
+ TRACK_COL_ALTITUDE + ", " + TRACK_COL_SPEED + ", " + TRACK_COL_HDOP + ", "
+ 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$
}
@ -97,7 +101,8 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
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$
+ 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){
@ -125,6 +130,9 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
if(oldVersion < 5){
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 +329,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
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$
+ 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 previousInterval = 0;
TrkSegment segment = null;
@ -336,6 +344,8 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
pt.hdop = query.getDouble(4);
long time = query.getLong(5);
pt.time = time;
float heading = query.getFloat(6);
pt.heading = heading == NO_HEADING ? Float.NaN : heading;
long currentInterval = Math.abs(time - previousTime);
boolean newInterval = pt.lat == 0 && pt.lon == 0;
@ -402,14 +412,19 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
public void startNewSegment() {
lastTimeUpdated = 0;
lastPoint = null;
execWithClose(updateScript, new Object[] { 0, 0, 0, 0, 0, System.currentTimeMillis()});
execWithClose(updateScript, new Object[] { 0, 0, 0, 0, 0, System.currentTimeMillis(), NO_HEADING});
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()
long locationTime = System.currentTimeMillis();
OsmandSettings settings = ctx.getSettings();
if (heading != null && settings.SAVE_HEADING_TO_GPX.get()) {
heading = MapUtils.normalizeDegrees360(heading);
} else {
heading = NO_HEADING;
}
boolean record = false;
if (location != null && OsmAndLocationProvider.isNotSimulatedLocation(location)) {
if (settings.SAVE_TRACK_TO_GPX.get()
@ -436,16 +451,16 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
}
if (record) {
insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getSpeed(),
location.getAccuracy(), locationTime, settings);
location.getAccuracy(), locationTime, heading, settings);
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) {
// * 1000 in next line seems to be wrong with new IntervalChooseDialog
// 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;
if (lastPoint == null || (time - lastTimeUpdated) > 180 * 1000) {
lastPoint = new LatLon(lat, lon);
@ -461,7 +476,8 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
lastPoint = new LatLon(lat, lon);
}
lastTimeUpdated = time;
WptPt pt = new GPXUtilities.WptPt(lat, lon, time, alt, speed, hdop);
heading = heading == NO_HEADING ? Float.NaN : heading;
WptPt pt = new GPXUtilities.WptPt(lat, lon, time, alt, speed, hdop, heading);
addTrackPoint(pt, newSegment, time);
trkPoints++;
}

View file

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