Source:
public synchronized SaveGpxResult saveDataToGpx(File dir) { List<String> warnings = new ArrayList<>(); List<String> filenames = new ArrayList<>(); dir.mkdirs(); if (dir.getParentFile().canWrite()) { if (dir.exists()) { Map<String, GPXFile> data = collectRecordedData(); for (final String f : data.keySet()) { log.debug("Filename: " + f); File fout = new File(dir, f + IndexConstants.GPX_FILE_EXT); if (!data.get(f).isEmpty()) { Locale locale = Locale.getDefault(); WptPt pt = data.get(f).findPointToShow(); String fileName = f + "_" + new SimpleDateFormat("HH-mm_EEE", locale).format(new Date(pt.time)); Integer track_storage_directory = ctx.getSettings().TRACK_STORAGE_DIRECTORY.get(); if (!track_storage_directory.equals(OsmandSettings.REC_DIRECTORY)) { SimpleDateFormat dateDirFormat = new SimpleDateFormat("yyyy-MM", locale); String dateDirName = dateDirFormat.format(new Date(pt.time)); File dateDir = new File(dir, dateDirName); dateDir.mkdirs(); if (dateDir.exists()) { fileName = dateDirName + File.separator + fileName; } } filenames.add(fileName); fout = new File(dir, fileName + IndexConstants.GPX_FILE_EXT); int ind = 1; while (fout.exists()) { fout = new File(dir, fileName + "_" + (++ind) + IndexConstants.GPX_FILE_EXT); } } Exception warn = GPXUtilities.writeGpxFile(fout, data.get(f)); if (warn != null) { warnings.add(warn.getMessage()); return new SaveGpxResult(warnings, new ArrayList<String>()); } GPXFile gpx = data.get(f); GPXTrackAnalysis analysis = gpx.getAnalysis(fout.lastModified()); GpxDataItem item = new GpxDataItem(fout, analysis); ctx.getGpxDbHelper().add(item); } } } clearRecordedData(warnings.isEmpty()); return new SaveGpxResult(warnings, filenames); }

Target:
public synchronized SaveGpxResult saveDataToGpx(File dir) { List<String> warnings = new ArrayList<>(); List<String> filenames = new ArrayList<>(); dir.mkdirs(); if (dir.getParentFile().canWrite()) { if (dir.exists()) { Map<String, GPXFile> data = collectRecordedData(); for (final String f : data.keySet()) { log.debug("Filename: " + f); File fout = new File(dir, f + IndexConstants.GPX_FILE_EXT); if (!data.get(f).isEmpty()) { WptPt pt = data.get(f).findPointToShow(); 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); String dateDirName = dateDirFormat.format(new Date(pt.time)); File dateDir = new File(dir, dateDirName); dateDir.mkdirs(); if (dateDir.exists()) { fileName = dateDirName + File.separator + fileName; } } filenames.add(fileName); fout = new File(dir, fileName + IndexConstants.GPX_FILE_EXT); int ind = 1; while (fout.exists()) { fout = new File(dir, fileName + "_" + (++ind) + IndexConstants.GPX_FILE_EXT); } } Exception warn = GPXUtilities.writeGpxFile(fout, data.get(f)); if (warn != null) { warnings.add(warn.getMessage()); return new SaveGpxResult(warnings, new ArrayList<String>()); } GPXFile gpx = data.get(f); GPXTrackAnalysis analysis = gpx.getAnalysis(fout.lastModified()); GpxDataItem item = new GpxDataItem(fout, analysis); ctx.getGpxDbHelper().add(item); } } } clearRecordedData(warnings.isEmpty()); return new SaveGpxResult(warnings, filenames); }