Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create GitHub Nightly Release
uses: softprops/action-gh-release@v2
uses: softprops/action-gh-release@v2.2.2
with:
tag_name: 'nightly'
name: 'Nightly Build'
Expand Down
31 changes: 20 additions & 11 deletions app/src/main/java/net/osmtracker/activity/DisplayTrackMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import net.osmtracker.R;
import net.osmtracker.db.TrackContentProvider;
import net.osmtracker.overlay.WayPointsOverlay;
import net.osmtracker.overlay.Polylines;

import org.osmdroid.api.IMapController;
import org.osmdroid.config.Configuration;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.CustomZoomButtonsController;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.Polyline;
import org.osmdroid.views.overlay.ScaleBarOverlay;
import org.osmdroid.views.overlay.mylocation.SimpleLocationOverlay;

Expand Down Expand Up @@ -114,7 +114,7 @@ public class DisplayTrackMap extends Activity {
/**
* OSM view overlay that displays current path
*/
private Polyline polyline;
private Polylines polylines;

/**
* OSM view overlay that displays waypoints
Expand Down Expand Up @@ -154,6 +154,11 @@ public class DisplayTrackMap extends Activity {
*/
private Integer lastTrackPointIdProcessed = null;

/**
* The id of the last segment
*/
private int prevSegmentId=-1;

/**
* Observes changes on track points
*/
Expand Down Expand Up @@ -291,6 +296,7 @@ private void resumeActivity() {
// This ensures that all waypoints for the track will be reloaded
// from the database to populate the path layout
lastTrackPointIdProcessed = null;
prevSegmentId = -1;

// Reload path
pathChanged();
Expand All @@ -309,7 +315,7 @@ protected void onPause() {
getContentResolver().unregisterContentObserver(trackpointContentObserver);

// Clear the points list.
polyline.setPoints(new ArrayList<>());
polylines.clear();

super.onPause();
}
Expand Down Expand Up @@ -375,12 +381,8 @@ private void createOverlays() {
this.getWindowManager().getDefaultDisplay().getMetrics(metrics);

// set with to hopefully DPI independent 0.5mm
polyline = new Polyline();
Paint paint = polyline.getOutlinePaint();
paint.setColor(Color.BLUE);
paint.setStrokeWidth((float) (metrics.densityDpi / 25.4 / 2));
osmView.getOverlayManager().add(polyline);

polylines = new Polylines(Color.BLUE, (float)(metrics.densityDpi / 25.4 / 2), osmView);

myLocationOverlay = new SimpleLocationOverlay(this);
osmView.getOverlays().add(myLocationOverlay);

Expand Down Expand Up @@ -427,7 +429,7 @@ private void pathChanged() {

// Projection: The columns to retrieve. Here, we want the latitude,
// longitude and primary key only
String[] projection = {TrackContentProvider.Schema.COL_LATITUDE, TrackContentProvider.Schema.COL_LONGITUDE, TrackContentProvider.Schema.COL_ID};
String[] projection = {TrackContentProvider.Schema.COL_LATITUDE, TrackContentProvider.Schema.COL_LONGITUDE, TrackContentProvider.Schema.COL_ID, TrackContentProvider.Schema.COL_SEG_ID };
// Selection: The where clause to use
String selection = null;
// SelectionArgs: The parameter replacements to use for the '?' in the selection
Expand Down Expand Up @@ -458,13 +460,20 @@ private void pathChanged() {
int primaryKeyColumnIndex = c.getColumnIndex(TrackContentProvider.Schema.COL_ID);
int latitudeColumnIndex = c.getColumnIndex(TrackContentProvider.Schema.COL_LATITUDE);
int longitudeColumnIndex = c.getColumnIndex(TrackContentProvider.Schema.COL_LONGITUDE);
int segmentIdColumnIndex = c.getColumnIndex(TrackContentProvider.Schema.COL_SEG_ID);

// Add each new point to the track
while (!c.isAfterLast()) {
lastLat = c.getDouble(latitudeColumnIndex);
lastLon = c.getDouble(longitudeColumnIndex);
lastTrackPointIdProcessed = c.getInt(primaryKeyColumnIndex);
polyline.addPoint(new GeoPoint(lastLat, lastLon));
int segmentId = c.getInt(segmentIdColumnIndex);
if(segmentId != prevSegmentId) {
polylines.nextSegment();
}
prevSegmentId = segmentId;

polylines.addPoint(new GeoPoint(lastLat, lastLon));
if (doInitialBoundsCalc) {
if (lastLat < minLat) minLat = lastLat;
if (lastLon < minLon) minLon = lastLon;
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/net/osmtracker/db/DataHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public DataHelper(Context c) {
* @param pressure
* atmospheric pressure
*/
public void track(long trackId, Location location, float azimuth, int accuracy, float pressure) {
public void track(long trackId, Location location, float azimuth, int accuracy, float pressure, boolean newSeg, long segId) {
Log.v(TAG, "Tracking (trackId=" + trackId + ") location: " + location + " azimuth: " + azimuth + ", accuracy: " + accuracy);
ContentValues values = new ContentValues();
values.put(TrackContentProvider.Schema.COL_TRACK_ID, trackId);
Expand Down Expand Up @@ -161,6 +161,8 @@ public void track(long trackId, Location location, float azimuth, int accuracy,
values.put(TrackContentProvider.Schema.COL_ATMOSPHERIC_PRESSURE, pressure);
}

values.put(TrackContentProvider.Schema.COL_SEG_ID, segId);

Uri trackUri = ContentUris.withAppendedId(TrackContentProvider.CONTENT_URI_TRACK, trackId);
contentResolver.insert(Uri.withAppendedPath(trackUri, TrackContentProvider.Schema.TBL_TRACKPOINT + "s"), values);
}
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/net/osmtracker/db/DatabaseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public class DatabaseHelper extends SQLiteOpenHelper {
+ TrackContentProvider.Schema.COL_TIMESTAMP + " long not null,"
+ TrackContentProvider.Schema.COL_COMPASS + " double null,"
+ TrackContentProvider.Schema.COL_COMPASS_ACCURACY + " integer null,"
+ TrackContentProvider.Schema.COL_ATMOSPHERIC_PRESSURE + " double null" + ")";
+ TrackContentProvider.Schema.COL_ATMOSPHERIC_PRESSURE + " double null,"
+ TrackContentProvider.Schema.COL_SEG_ID + " integer not null default 0"
+ ")";

/**
* SQL for creating index TRACKPOINT_idx (track id)
Expand Down Expand Up @@ -125,7 +127,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
* v17: add TBL_TRACKPOINT.COL_ATMOSPHERIC_PRESSURE and TBL_WAYPOINT.COL_ATMOSPHERIC_PRESSURE
*</pre>
*/
private static final int DB_VERSION = 17;
private static final int DB_VERSION = 18;

private Context context;

Expand Down Expand Up @@ -181,6 +183,8 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
case 16:
db.execSQL("alter table " + TrackContentProvider.Schema.TBL_TRACKPOINT + " add column " + TrackContentProvider.Schema.COL_ATMOSPHERIC_PRESSURE + " double null");
db.execSQL("alter table " + TrackContentProvider.Schema.TBL_WAYPOINT + " add column " + TrackContentProvider.Schema.COL_ATMOSPHERIC_PRESSURE + " double null");
case 17:
db.execSQL("alter table "+TrackContentProvider.Schema.TBL_TRACKPOINT + " add column " + TrackContentProvider.Schema.COL_SEG_ID + " integer default 0");
}
}

Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/net/osmtracker/db/TrackContentProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public class TrackContentProvider extends ContentProvider {
Schema.COL_OSM_VISIBILITY,
Schema.COL_START_DATE,
"count(" + Schema.TBL_TRACKPOINT + "." + Schema.COL_ID + ") as " + Schema.COL_TRACKPOINT_COUNT,
"(SELECT count("+Schema.TBL_WAYPOINT+"."+Schema.COL_TRACK_ID+") FROM "+Schema.TBL_WAYPOINT+" WHERE "+Schema.TBL_WAYPOINT+"."+Schema.COL_TRACK_ID+" = " + Schema.TBL_TRACK + "." + Schema.COL_ID + ") as " + Schema.COL_WAYPOINT_COUNT
"(SELECT count("+Schema.TBL_WAYPOINT+"."+Schema.COL_TRACK_ID+") FROM "+Schema.TBL_WAYPOINT+" WHERE "+Schema.TBL_WAYPOINT+"."+Schema.COL_TRACK_ID+" = " + Schema.TBL_TRACK + "." + Schema.COL_ID + ") as " + Schema.COL_WAYPOINT_COUNT,
"(SELECT max("+Schema.TBL_TRACKPOINT+"."+Schema.COL_SEG_ID+") FROM "+Schema.TBL_TRACKPOINT+" WHERE "+Schema.TBL_TRACKPOINT+"."+Schema.COL_TRACK_ID+" = " + Schema.TBL_TRACK + "." + Schema.COL_ID + ") as " + Schema.COL_MAX_SEG_ID
};

/**
Expand Down Expand Up @@ -495,10 +496,13 @@ public static final class Schema {
public static final String COL_COMPASS = "compass_heading";
public static final String COL_COMPASS_ACCURACY = "compass_accuracy";
public static final String COL_ATMOSPHERIC_PRESSURE = "atmospheric_pressure";


public static final String COL_SEG_ID = "segment_id";

// virtual colums that are used in some sqls but dont exist in database
public static final String COL_TRACKPOINT_COUNT = "tp_count";
public static final String COL_WAYPOINT_COUNT = "wp_count";
public static final String COL_MAX_SEG_ID = "max_segment_id";

// Codes for UriMatcher
public static final int URI_CODE_TRACK = 3;
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/net/osmtracker/db/model/Track.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static OSMVisibility fromPosition(int position) {
private String description;
private OSMVisibility visibility;
private List<String> tags = new ArrayList<String>();
private int tpCount, wpCount;
private int tpCount, wpCount, maxSegId;
private long trackDate;
private long trackId;

Expand Down Expand Up @@ -93,6 +93,8 @@ public static Track build(final long trackId, Cursor tc, ContentResolver cr, boo

out.wpCount = tc.getInt(tc.getColumnIndex(TrackContentProvider.Schema.COL_WAYPOINT_COUNT));

int maxSegIdIdx = tc.getColumnIndex(TrackContentProvider.Schema.COL_MAX_SEG_ID);
out.maxSegId = tc.isNull(maxSegIdIdx) ? 0 :tc.getInt(maxSegIdIdx);
if(withExtraInformation){
out.readExtraInformation();
}
Expand Down Expand Up @@ -145,6 +147,10 @@ public void setWpCount(int wpCount) {
this.wpCount = wpCount;
}

public void setMaxSegId(int maxSegId) {
this.maxSegId = maxSegId;
}

public void setTracktDate(long tracktDate) {
this.trackDate = tracktDate;
}
Expand Down Expand Up @@ -187,6 +193,10 @@ public Integer getWpCount() {
return wpCount;
}

public Integer getMaxSegId() {
return maxSegId;
}

public Integer getTpCount() {
return tpCount;
}
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/net/osmtracker/gpx/ExportTrackTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,16 @@ private void writeTrackPoints(String trackName, Writer fw, Cursor c, boolean fil
fw.write("\t\t" + "<trkseg>" + "\n");

int i=0;
int prevSegId=-1;
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext(),i++) {
StringBuffer out = new StringBuffer();
int segId = c.getInt(c.getColumnIndex(TrackContentProvider.Schema.COL_SEG_ID));
if(prevSegId != -1 && segId != prevSegId) {
fw.write("\t\t" + "</trkseg>" + "\n");
fw.write("\t\t" + "<trkseg>" + "\n");
}
prevSegId = segId;

out.append("\t\t\t" + "<trkpt lat=\""
+ c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_LATITUDE)) + "\" "
+ "lon=\"" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_LONGITUDE)) + "\">" + "\n");
Expand Down Expand Up @@ -625,4 +633,4 @@ public String sanitizeTrackName(String trackName){
public String getErrorMsg() {
return errorMsg;
}
}
}
61 changes: 61 additions & 0 deletions app/src/main/java/net/osmtracker/overlay/Polylines.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package net.osmtracker.overlay;

import java.util.ArrayList;
import java.util.List;

import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.Polyline;

import android.graphics.Paint;

/**
* Collection of Polylines, useful to draw interrupted paths
*/
public class Polylines {
private int color;
private float width;
private MapView osmView;
private boolean havePoint;

private int curIdx=0;

private List<Polyline> polylines = new ArrayList<Polyline>();

private void addPolyline() {
Polyline polyline = new Polyline();
Paint paint = polyline.getOutlinePaint();
paint.setColor(color);
paint.setStrokeWidth(width);

polylines.add(polyline);
osmView.getOverlayManager().add(polyline);
}

public void clear() {
for(Polyline polyline : polylines)
polyline.setPoints(new ArrayList<>());
curIdx=0;
}

public Polylines(int color, float width, MapView osmView) {
this.color=color;
this.width=width;
this.osmView = osmView;
addPolyline();
havePoint=false;
}

public void addPoint(GeoPoint gp) {
if(curIdx >= polylines.size())
addPolyline();
polylines.get(curIdx).addPoint(gp);
havePoint=true;
}

public void nextSegment() {
if(havePoint)
curIdx++;
havePoint=false;
}
}
Loading