use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.
the class TrackAppearanceFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
app = requireMyApplication();
settings = app.getSettings();
gpxDbHelper = app.getGpxDbHelper();
if (savedInstanceState != null) {
trackDrawInfo = new TrackDrawInfo(savedInstanceState);
if (selectedGpxFile == null) {
restoreSelectedGpxFile(trackDrawInfo.getFilePath(), trackDrawInfo.isCurrentRecording());
}
if (!trackDrawInfo.isCurrentRecording()) {
gpxDataItem = gpxDbHelper.getItem(new File(trackDrawInfo.getFilePath()));
}
showStartFinishIconsInitialValue = savedInstanceState.getBoolean(SHOW_START_FINISH_ICONS_INITIAL_VALUE_KEY, settings.SHOW_START_FINISH_ICONS.get());
} else {
showStartFinishIconsInitialValue = settings.SHOW_START_FINISH_ICONS.get();
if (selectedGpxFile.isShowCurrentTrack()) {
trackDrawInfo = new TrackDrawInfo(app, true);
} else {
GpxDataItemCallback callback = new GpxDataItemCallback() {
@Override
public boolean isCancelled() {
return false;
}
@Override
public void onGpxDataItemReady(GpxDataItem item) {
if (item != null) {
gpxDataItem = item;
trackDrawInfo.updateParams(item);
}
if (view != null) {
initContent();
}
}
};
String filePath = selectedGpxFile.getGpxFile().path;
gpxDataItem = gpxDbHelper.getItem(new File(filePath), callback);
trackDrawInfo = new TrackDrawInfo(filePath, gpxDataItem, false);
}
}
requireMyActivity().getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
public void handleOnBackPressed() {
dismiss();
}
});
}
use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.
the class GpxUiHelper method getDataItem.
private static GpxDataItem getDataItem(@NonNull final OsmandApplication app, @NonNull final GPXFile gpxFile) {
GpxDataItemCallback itemCallback = new GpxDataItemCallback() {
@Override
public boolean isCancelled() {
return false;
}
@Override
public void onGpxDataItemReady(GpxDataItem item) {
addAppearanceToGpx(gpxFile, item);
saveAndShareGpx(app, gpxFile);
}
};
return app.getGpxDbHelper().getItem(new File(gpxFile.path), itemCallback);
}
use of net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem in project Osmand by osmandapp.
the class SavingTrackHelper method saveDataToGpx.
/**
* @return warnings, gpxFilesByName
*/
public synchronized SaveGpxResult saveDataToGpx(@NonNull File dir) {
List<String> warnings = new ArrayList<>();
Map<String, GPXFile> gpxFilesByName = new LinkedHashMap<>();
dir.mkdirs();
if (dir.getParentFile().canWrite() && dir.exists()) {
Map<String, GPXFile> data = collectRecordedData();
for (Map.Entry<String, GPXFile> entry : data.entrySet()) {
String f = entry.getKey();
GPXFile gpx = entry.getValue();
log.debug("Filename: " + f);
File fout = new File(dir, f + IndexConstants.GPX_FILE_EXT);
if (!gpx.isEmpty()) {
WptPt pt = gpx.findPointToShow();
// $NON-NLS-1$
String fileName = f + "_" + new SimpleDateFormat("HH-mm_EEE", Locale.US).format(new Date(pt.time));
Integer trackStorageDirectory = ctx.getSettings().TRACK_STORAGE_DIRECTORY.get();
if (!OsmandSettings.REC_DIRECTORY.equals(trackStorageDirectory)) {
SimpleDateFormat dateDirFormat = new SimpleDateFormat("yyyy-MM", Locale.US);
// if (trackStorageDirectory == OsmandSettings.DAILY_DIRECTORY) {
// dateDirFormat = new SimpleDateFormat("yyyy-MM-dd");
// }
String dateDirName = dateDirFormat.format(new Date(pt.time));
File dateDir = new File(dir, dateDirName);
dateDir.mkdirs();
if (dateDir.exists()) {
fileName = dateDirName + File.separator + fileName;
}
}
gpxFilesByName.put(fileName, gpx);
fout = new File(dir, fileName + IndexConstants.GPX_FILE_EXT);
int ind = 1;
while (fout.exists()) {
// $NON-NLS-1$
fout = new File(dir, fileName + "_" + (++ind) + IndexConstants.GPX_FILE_EXT);
}
}
Exception warn = GPXUtilities.writeGpxFile(fout, gpx);
if (warn != null) {
warnings.add(warn.getMessage());
return new SaveGpxResult(warnings, new HashMap<String, GPXFile>());
}
GPXTrackAnalysis analysis = gpx.getAnalysis(fout.lastModified());
GpxDataItem item = new GpxDataItem(fout, analysis);
ctx.getGpxDbHelper().add(item);
lastTimeFileSaved = fout.lastModified();
}
clearRecordedData(warnings.isEmpty());
}
return new SaveGpxResult(warnings, gpxFilesByName);
}
Aggregations