use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.
the class TrackActivity method addNewGpxData.
public void addNewGpxData(NewGpxData.ActionType actionType, TrkSegment segment) {
GPXFile gpxFile = getGpx();
QuadRect rect = getRect();
NewGpxData newGpxData = new NewGpxData(gpxFile, rect, actionType, segment);
WptPt pointToShow = gpxFile != null ? gpxFile.findPointToShow() : null;
if (pointToShow != null) {
LatLon location = new LatLon(pointToShow.getLatitude(), pointToShow.getLongitude());
final OsmandSettings settings = app.getSettings();
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.getLastKnownMapZoom(), new PointDescription(PointDescription.POINT_TYPE_WPT, getString(R.string.add_line)), false, newGpxData);
MapActivity.launchMapActivityMoveToTop(this);
}
}
use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.
the class MapActivityLayers method showGPXFileLayer.
public AlertDialog showGPXFileLayer(List<String> files, final OsmandMapTileView mapView) {
final OsmandSettings settings = getApplication().getSettings();
CallbackWithObject<GPXFile[]> callbackWithObject = new CallbackWithObject<GPXFile[]>() {
@Override
public boolean processResult(GPXFile[] result) {
WptPt locToShow = null;
for (GPXFile g : result) {
if (g.showCurrentTrack) {
if (!settings.SAVE_TRACK_TO_GPX.get() && !settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) {
Toast.makeText(activity, R.string.gpx_monitoring_disabled_warn, Toast.LENGTH_LONG).show();
}
break;
} else {
locToShow = g.findPointToShow();
}
}
getApplication().getSelectedGpxHelper().setGpxFileToDisplay(result);
if (locToShow != null) {
mapView.getAnimatedDraggingThread().startMoving(locToShow.lat, locToShow.lon, mapView.getZoom(), true);
}
mapView.refreshMap();
activity.getDashboard().refreshContent(true);
return true;
}
};
return GpxUiHelper.selectGPXFiles(files, activity, callbackWithObject);
}
use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.
the class SavingTrackHelper method saveDataToGpx.
/**
* @return warnings
*/
public synchronized List<String> saveDataToGpx(File dir) {
List<String> warnings = new ArrayList<String>();
dir.mkdirs();
if (dir.getParentFile().canWrite()) {
if (dir.exists()) {
Map<String, GPXFile> data = collectRecordedData();
// save file
for (final String f : data.keySet()) {
// $NON-NLS-1$
File fout = new File(dir, f + ".gpx");
if (!data.get(f).isEmpty()) {
WptPt pt = data.get(f).findPointToShow();
File targetDir = dir;
if (ctx.getSettings().STORE_TRACKS_IN_MONTHLY_DIRECTORIES.get()) {
SimpleDateFormat dateDirFormat = new SimpleDateFormat("yyyy-MM");
String dateDirName = dateDirFormat.format(new Date(pt.time));
File dateDir = new File(dir, dateDirName);
dateDir.mkdirs();
if (dateDir.exists()) {
targetDir = dateDir;
}
}
// $NON-NLS-1$
String fileName = f + "_" + new SimpleDateFormat("HH-mm_EEE", Locale.US).format(new Date(pt.time));
// $NON-NLS-1$
fout = new File(targetDir, fileName + ".gpx");
int ind = 1;
while (fout.exists()) {
// $NON-NLS-1$ //$NON-NLS-2$
fout = new File(targetDir, fileName + "_" + (++ind) + ".gpx");
}
}
String warn = GPXUtilities.writeGpxFile(fout, data.get(f), ctx);
if (warn != null) {
warnings.add(warn);
return warnings;
}
GPXFile gpx = data.get(f);
GPXTrackAnalysis analysis = gpx.getAnalysis(fout.lastModified());
GpxDataItem item = new GpxDataItem(fout, analysis);
ctx.getGpxDatabase().add(item);
}
}
}
SQLiteDatabase db = getWritableDatabase();
if (db != null && warnings.isEmpty() && db.isOpen()) {
try {
// remove all from db
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
db.execSQL("DELETE FROM " + TRACK_NAME + " WHERE " + TRACK_COL_DATE + " <= ?", new Object[] { System.currentTimeMillis() });
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
db.execSQL("DELETE FROM " + POINT_NAME + " WHERE " + POINT_COL_DATE + " <= ?", new Object[] { System.currentTimeMillis() });
// delete all
// db.execSQL("DELETE FROM " + TRACK_NAME + " WHERE 1 = 1", new Object[] { }); //$NON-NLS-1$ //$NON-NLS-2$
// db.execSQL("DELETE FROM " + POINT_NAME + " WHERE 1 = 1", new Object[] { }); //$NON-NLS-1$ //$NON-NLS-2$
} finally {
db.close();
}
}
distance = 0;
points = 0;
duration = 0;
ctx.getSelectedGpxHelper().clearPoints(currentTrack.getModifiableGpxFile());
currentTrack.getModifiableGpxFile().tracks.clear();
currentTrack.getModifiablePointsToDisplay().clear();
currentTrack.getModifiableGpxFile().modifiedTime = System.currentTimeMillis();
prepareCurrentTrackForRecording();
return warnings;
}
use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.
the class GpxSelectionHelper method processSplit.
public void processSplit() {
List<GpxDataItem> items = app.getGpxDatabase().getItems();
for (GpxDataItem dataItem : items) {
if (dataItem.getSplitType() != 0) {
SelectedGpxFile selectedGpxFile = getSelectedFileByPath(dataItem.getFile().getAbsolutePath());
if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) {
GPXFile gpxFile = selectedGpxFile.getGpxFile();
List<GpxDisplayGroup> groups = app.getSelectedGpxHelper().collectDisplayGroups(gpxFile);
if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_NO_SPLIT) {
for (GpxDisplayGroup model : groups) {
model.noSplit(app);
}
selectedGpxFile.setDisplayGroups(groups);
} else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_DISTANCE) {
for (GpxDisplayGroup model : groups) {
model.splitByDistance(app, dataItem.getSplitInterval());
}
selectedGpxFile.setDisplayGroups(groups);
} else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_TIME) {
for (GpxDisplayGroup model : groups) {
model.splitByTime(app, (int) dataItem.getSplitInterval());
}
selectedGpxFile.setDisplayGroups(groups);
}
}
}
}
}
use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.
the class GpxSelectionHelper method syncGpx.
private void syncGpx(GPXFile gpxFile) {
File gpx = new File(gpxFile.path);
if (gpx.exists()) {
MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
mapMarkersHelper.runSynchronization(mapMarkersHelper.getOrCreateGroup(gpx));
}
}
Aggregations