use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.
the class MapActivityActions method enterRoutePlanningMode.
public void enterRoutePlanningMode(final LatLon from, final PointDescription fromName) {
final boolean useIntermediatePointsByDefault = true;
List<SelectedGpxFile> selectedGPXFiles = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedGPXFiles();
final List<GPXFile> gpxFiles = new ArrayList<>();
for (SelectedGpxFile gs : selectedGPXFiles) {
if (!gs.isShowCurrentTrack() && !gs.notShowNavigationDialog) {
if (gs.getGpxFile().hasRtePt() || gs.getGpxFile().hasTrkPt()) {
gpxFiles.add(gs.getGpxFile());
}
}
}
if (gpxFiles.size() > 0) {
AlertDialog.Builder bld = new AlertDialog.Builder(mapActivity);
if (gpxFiles.size() == 1) {
bld.setMessage(R.string.use_displayed_track_for_navigation);
bld.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
enterRoutePlanningModeGivenGpx(gpxFiles.get(0), from, fromName, useIntermediatePointsByDefault, true);
}
});
} else {
bld.setTitle(R.string.navigation_over_track);
ArrayAdapter<GPXFile> adapter = new ArrayAdapter<GPXFile>(mapActivity, R.layout.drawer_list_item, gpxFiles) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mapActivity.getLayoutInflater().inflate(R.layout.drawer_list_item, null);
}
String path = getItem(position).path;
String name = path.substring(path.lastIndexOf("/") + 1, path.length());
((TextView) convertView.findViewById(R.id.title)).setText(name);
convertView.findViewById(R.id.icon).setVisibility(View.GONE);
convertView.findViewById(R.id.toggle_item).setVisibility(View.GONE);
return convertView;
}
};
bld.setAdapter(adapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
enterRoutePlanningModeGivenGpx(gpxFiles.get(i), from, fromName, useIntermediatePointsByDefault, true);
}
});
}
bld.setNegativeButton(R.string.shared_string_no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
enterRoutePlanningModeGivenGpx(null, from, fromName, useIntermediatePointsByDefault, true);
}
});
bld.show();
} else {
enterRoutePlanningModeGivenGpx(null, from, fromName, useIntermediatePointsByDefault, true);
}
}
use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.
the class TrackActivity method addPoint.
public void addPoint(PointDescription pointDescription) {
Intent currentIntent = getIntent();
if (currentIntent != null) {
currentIntent.putExtra(TrackActivity.OPEN_POINTS_TAB, true);
}
final OsmandSettings settings = app.getSettings();
GPXFile gpx = getGpx();
LatLon location = settings.getLastKnownMapLocation();
QuadRect rect = getRect();
NewGpxPoint newGpxPoint = new NewGpxPoint(gpx, pointDescription, rect);
if (gpx != null && location != null) {
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.getLastKnownMapZoom(), pointDescription, false, newGpxPoint);
MapActivity.launchMapActivityMoveToTop(this);
}
}
use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.
the class SavingTrackHelper method collectRecordedData.
public Map<String, GPXFile> collectRecordedData() {
Map<String, GPXFile> data = new LinkedHashMap<String, GPXFile>();
SQLiteDatabase db = getReadableDatabase();
if (db != null && db.isOpen()) {
try {
collectDBPoints(db, data);
collectDBTracks(db, data);
} finally {
db.close();
}
}
return data;
}
use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.
the class SavingTrackHelper method loadGpxFromDatabase.
public void loadGpxFromDatabase() {
Map<String, GPXFile> files = collectRecordedData();
currentTrack.getModifiableGpxFile().tracks.clear();
for (Map.Entry<String, GPXFile> entry : files.entrySet()) {
ctx.getSelectedGpxHelper().addPoints(entry.getValue().getPoints(), currentTrack.getModifiableGpxFile());
currentTrack.getModifiableGpxFile().tracks.addAll(entry.getValue().tracks);
}
currentTrack.processPoints();
prepareCurrentTrackForRecording();
GPXTrackAnalysis analysis = currentTrack.getModifiableGpxFile().getAnalysis(System.currentTimeMillis());
distance = analysis.totalDistance;
points = analysis.wptPoints;
duration = analysis.timeSpan;
}
use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.
the class SavingTrackHelper method collectDBTracks.
private void collectDBTracks(SQLiteDatabase db, Map<String, GPXFile> dataTracks) {
Cursor query = db.rawQuery(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"SELECT " + TRACK_COL_LAT + "," + TRACK_COL_LON + "," + TRACK_COL_ALTITUDE + "," + TRACK_COL_SPEED + "," + TRACK_COL_HDOP + "," + TRACK_COL_DATE + " FROM " + TRACK_NAME + " ORDER BY " + TRACK_COL_DATE + " ASC", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
null);
long previousTime = 0;
long previousInterval = 0;
TrkSegment segment = null;
Track track = null;
if (query.moveToFirst()) {
do {
WptPt pt = new WptPt();
pt.lat = query.getDouble(0);
pt.lon = query.getDouble(1);
pt.ele = query.getDouble(2);
pt.speed = query.getDouble(3);
pt.hdop = query.getDouble(4);
long time = query.getLong(5);
pt.time = time;
long currentInterval = Math.abs(time - previousTime);
boolean newInterval = pt.lat == 0 && pt.lon == 0;
if (track != null && !newInterval && (!ctx.getSettings().AUTO_SPLIT_RECORDING.get() || currentInterval < 6 * 60 * 1000 || currentInterval < 10 * previousInterval)) {
// 6 minute - same segment
segment.points.add(pt);
} else if (track != null && (ctx.getSettings().AUTO_SPLIT_RECORDING.get() && currentInterval < 2 * 60 * 60 * 1000)) {
// 2 hour - same track
segment = new TrkSegment();
if (!newInterval) {
segment.points.add(pt);
}
track.segments.add(segment);
} else {
// check if date the same - new track otherwise new file
track = new Track();
segment = new TrkSegment();
track.segments.add(segment);
if (!newInterval) {
segment.points.add(pt);
}
// $NON-NLS-1$
String date = DateFormat.format("yyyy-MM-dd", time).toString();
if (dataTracks.containsKey(date)) {
GPXFile gpx = dataTracks.get(date);
gpx.tracks.add(track);
} else {
GPXFile file = new GPXFile();
file.tracks.add(track);
dataTracks.put(date, file);
}
}
previousInterval = currentInterval;
previousTime = time;
} while (query.moveToNext());
}
query.close();
}
Aggregations