use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.
the class OsmandAidlApi method finishGpxImport.
@SuppressLint("StaticFieldLeak")
private void finishGpxImport(boolean destinationExists, File destination, String color, boolean show) {
final int col = GpxAppearanceAdapter.parseTrackColor(app.getRendererRegistry().getCurrentSelectedRenderer(), color);
if (!destinationExists) {
GpxDataItem gpxDataItem = new GpxDataItem(destination, col);
gpxDataItem.setApiImported(true);
app.getGpxDbHelper().add(gpxDataItem);
} else {
GpxDataItem item = app.getGpxDbHelper().getItem(destination);
if (item != null) {
app.getGpxDbHelper().updateColor(item, col);
}
}
final GpxSelectionHelper helper = app.getSelectedGpxHelper();
final SelectedGpxFile selectedGpx = helper.getSelectedFileByName(destination.getName());
if (selectedGpx != null) {
if (show) {
new AsyncTask<File, Void, GPXFile>() {
@Override
protected GPXFile doInBackground(File... files) {
return GPXUtilities.loadGPXFile(files[0]);
}
@Override
protected void onPostExecute(GPXFile gpx) {
if (gpx.error == null) {
if (col != -1) {
gpx.setColor(col);
}
selectedGpx.setGpxFile(gpx, app);
refreshMap();
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, destination);
} else {
helper.selectGpxFile(selectedGpx.getGpxFile(), false, false);
refreshMap();
}
} else if (show) {
new AsyncTask<File, Void, GPXFile>() {
@Override
protected GPXFile doInBackground(File... files) {
return GPXUtilities.loadGPXFile(files[0]);
}
@Override
protected void onPostExecute(GPXFile gpx) {
if (gpx.error == null) {
helper.selectGpxFile(gpx, true, false);
refreshMap();
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, destination);
}
}
use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.
the class OsmandAidlApi method getImportedGpx.
boolean getImportedGpx(List<AGpxFile> files) {
List<GpxDataItem> gpxDataItems = app.getGpxDbHelper().getItems();
for (GpxDataItem dataItem : gpxDataItems) {
File file = dataItem.getFile();
if (file.exists()) {
String fileName = file.getName();
boolean active = app.getSelectedGpxHelper().getSelectedFileByPath(file.getAbsolutePath()) != null;
long modifiedTime = dataItem.getFileLastModifiedTime();
long fileSize = file.length();
AGpxFileDetails details = null;
GPXTrackAnalysis analysis = dataItem.getAnalysis();
if (analysis != null) {
details = createGpxFileDetails(analysis);
}
files.add(new AGpxFile(fileName, modifiedTime, fileSize, active, details));
}
}
return true;
}
use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.
the class OsmandAidlApi method getImportedGpxV2.
boolean getImportedGpxV2(List<net.osmand.aidlapi.gpx.AGpxFile> files) {
List<GpxDataItem> gpxDataItems = app.getGpxDbHelper().getItems();
for (GpxDataItem dataItem : gpxDataItems) {
File file = dataItem.getFile();
if (file.exists()) {
String fileName = file.getName();
boolean active = app.getSelectedGpxHelper().getSelectedFileByPath(file.getAbsolutePath()) != null;
long modifiedTime = dataItem.getFileLastModifiedTime();
long fileSize = file.length();
int color = dataItem.getColor();
String colorName = "";
if (color != 0) {
colorName = GpxAppearanceAdapter.parseTrackColorName(app.getRendererRegistry().getCurrentSelectedRenderer(), color);
}
net.osmand.aidlapi.gpx.AGpxFileDetails details = null;
GPXTrackAnalysis analysis = dataItem.getAnalysis();
if (analysis != null) {
details = createGpxFileDetailsV2(analysis);
}
files.add(new net.osmand.aidlapi.gpx.AGpxFile(fileName, modifiedTime, fileSize, active, colorName, details));
}
}
return true;
}
use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.
the class SaveGpxAsyncTask method saveImport.
private String saveImport(GPXFile gpxFile, String fileName, boolean useImportDir) {
final String warning;
if (gpxFile.isEmpty() || fileName == null) {
warning = app.getString(R.string.error_reading_gpx);
} else {
final File importDir;
if (useImportDir) {
importDir = app.getAppPath(GPX_IMPORT_DIR);
} else {
importDir = app.getAppPath(GPX_INDEX_DIR);
}
// noinspection ResultOfMethodCallIgnored
importDir.mkdirs();
if (importDir.exists() && importDir.isDirectory() && importDir.canWrite()) {
final WptPt pt = gpxFile.findPointToShow();
final File toWrite = getFileToSave(fileName, importDir, pt);
boolean destinationExists = toWrite.exists();
Exception e = GPXUtilities.writeGpxFile(toWrite, gpxFile);
if (e == null) {
gpxFile.path = toWrite.getAbsolutePath();
File file = new File(gpxFile.path);
if (!destinationExists) {
GpxDataItem item = new GpxDataItem(file, gpxFile);
app.getGpxDbHelper().add(item);
} else {
GpxDataItem item = app.getGpxDbHelper().getItem(file);
if (item != null) {
app.getGpxDbHelper().clearAnalysis(item);
}
}
warning = null;
} else {
warning = app.getString(R.string.error_reading_gpx);
}
} else {
warning = app.getString(R.string.sd_dir_not_accessible);
}
}
return warning;
}
use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.
the class TrackBitmapDrawer method drawTrack.
private void drawTrack(Canvas canvas, RotatedTileBox tileBox, SelectedGpxFile selectedGpxFile) {
GpxDataItem gpxDataItem = null;
if (!selectedGpxFile.isShowCurrentTrack()) {
gpxDataItem = getGpxDataItem();
}
List<TrkSegment> segments = selectedGpxFile.getPointsToDisplay();
for (TrkSegment segment : segments) {
int color = getTrackColor(selectedGpxFile, segment, gpxDataItem);
if (segment.renderer == null && !segment.points.isEmpty()) {
if (selectedGpxFile.isShowCurrentTrack()) {
segment.renderer = new CurrentTrack(segment.points);
} else {
segment.renderer = new StandardTrack(segment.points, 17.2);
}
}
paint.setColor(color);
if (segment.renderer instanceof RenderableSegment) {
((RenderableSegment) segment.renderer).drawSegment(tileBox.getZoom(), paint, canvas, tileBox);
}
}
}
Aggregations