-
-
Notifications
You must be signed in to change notification settings - Fork 255
Expand file tree
/
Copy pathExportTrackTask.java
More file actions
560 lines (474 loc) · 21.3 KB
/
ExportTrackTask.java
File metadata and controls
560 lines (474 loc) · 21.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
package net.osmtracker.gpx;
import android.Manifest;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.media.MediaScannerConnection;
import android.os.AsyncTask;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.widget.Toast;
import net.osmtracker.OSMTracker;
import net.osmtracker.R;
import net.osmtracker.db.DataHelper;
import net.osmtracker.db.TrackContentProvider;
import net.osmtracker.exception.ExportTrackException;
import net.osmtracker.util.FileSystemUtils;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.TimeZone;
import java.util.regex.Pattern;
/**
* Base class to writes a GPX file and export
* track media (Photos, Sounds)
*
* @author Nicolas Guillaumin
*
*/
public abstract class ExportTrackTask extends AsyncTask<Void, Long, Boolean> {
private static final String TAG = ExportTrackTask.class.getSimpleName();
/**
* Characters to replace in track filename, for use by {@link #buildGPXFilename(Cursor)}. <BR>
* The characters are: (space) ' " / \ * ? ~ @ < > <BR>
* In addition, ':' will be replaced by ';', before calling this pattern.
*/
private final static Pattern FILENAME_CHARS_BLACKLIST_PATTERN =
Pattern.compile("[ '\"/\\\\*?~@<>]"); // must double-escape \
/**
* XML header.
*/
private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
private static final String CDATA_START = "<![CDATA[";
private static final String CDATA_END = "]]>";
/**
* GPX opening tag
*/
private static final String TAG_GPX = "<gpx"
+ " xmlns=\"http://www.topografix.com/GPX/1/1\""
+ " version=\"1.1\""
+ " creator=\"OSMTracker for Android™ - https://github.com/labexp/osmtracker-android\""
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd \">";
/**
* Date format for a point timestamp.
*/
private SimpleDateFormat pointDateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
/**
* {@link Context} to get resources
*/
protected Context context;
/**
* Track IDs to export
*/
protected long[] trackIds;
/**
* Dialog to display while exporting
*/
protected ProgressDialog dialog;
/**
* Message in case of an error
*/
private String errorMsg = null;
/**
* @param startDate
* @return The directory in which the track file should be created
* @throws ExportTrackException
*/
protected abstract File getExportDirectory(Date startDate) throws ExportTrackException;
/**
* Whereas to export the media files or not
* @return
*/
protected abstract boolean exportMediaFiles();
/**
* Whereas to update the track export date in the database at the end or not
* @return
*/
protected abstract boolean updateExportDate();
public ExportTrackTask(Context context, long... trackIds) {
this.context = context;
this.trackIds = trackIds;
pointDateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
}
@Override
protected void onPreExecute() {
// Display dialog
dialog = new ProgressDialog(context);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setIndeterminate(true);
dialog.setCancelable(false);
dialog.setMessage(context.getResources().getString(R.string.trackmgr_exporting_prepare));
dialog.show();
}
@Override
protected Boolean doInBackground(Void... params) {
try {
for (int i=0; i<trackIds.length; i++) {
exportTrackAsGpx(trackIds[i]);
}
} catch (ExportTrackException ete) {
errorMsg = ete.getMessage();
return false;
}
return true;
}
@Override
protected void onProgressUpdate(Long... values) {
if (values.length == 1) {
// Standard progress update
dialog.incrementProgressBy(values[0].intValue());
} else if (values.length == 3) {
// To initialise the dialog, 3 values are passed to onProgressUpdate()
// trackId, number of track points, number of waypoints
dialog.dismiss();
dialog = new ProgressDialog(context);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setIndeterminate(false);
dialog.setCancelable(false);
dialog.setProgress(0);
dialog.setMax(values[1].intValue() + values[2].intValue());
dialog.setTitle(
context.getResources().getString(R.string.trackmgr_exporting)
.replace("{0}", Long.toString(values[0])));
dialog.show();
}
}
@Override
protected void onPostExecute(Boolean success) {
dialog.dismiss();
if (!success) {
new AlertDialog.Builder(context)
.setTitle(android.R.string.dialog_alert_title)
.setMessage(context.getResources()
.getString(R.string.trackmgr_export_error)
.replace("{0}", errorMsg))
.setIcon(android.R.drawable.ic_dialog_alert)
.setNeutralButton(android.R.string.ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.show();
}else{
Toast.makeText(this.context, R.string.various_export_finished, Toast.LENGTH_SHORT).show();
}
}
private void exportTrackAsGpx(long trackId) throws ExportTrackException {
String state = Environment.getExternalStorageState();
File sdRoot = Environment.getExternalStorageDirectory();
if (ContextCompat.checkSelfPermission(context,
Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
if (sdRoot.canWrite()) {
ContentResolver cr = context.getContentResolver();
Cursor c = context.getContentResolver().query(ContentUris.withAppendedId(
TrackContentProvider.CONTENT_URI_TRACK, trackId), null, null,
null, null);
// Get the startDate of this track
// TODO: Maybe we should be pulling the track name instead?
// We'd need to consider the possibility that two tracks were given the same name
// We could possibly disambiguate by including the track ID in the Folder Name
// to avoid overwriting another track on one hand or needlessly creating additional
// directories to avoid overwriting.
Date startDate = new Date();
if (null != c && 1 <= c.getCount()) {
c.moveToFirst();
long startDateInMilliseconds = c.getLong(c.getColumnIndex(TrackContentProvider.Schema.COL_START_DATE));
startDate.setTime(startDateInMilliseconds);
}
File trackGPXExportDirectory = getExportDirectory(startDate);
String filenameBase = buildGPXFilename(c);
String tags = c.getString(c.getColumnIndex(TrackContentProvider.Schema.COL_TAGS));
String track_description = c.getString(c.getColumnIndex(TrackContentProvider.Schema.COL_DESCRIPTION));
String track_name = c.getString(c.getColumnIndex(TrackContentProvider.Schema.COL_NAME));
c.close();
File trackFile = new File(trackGPXExportDirectory, filenameBase);
Cursor cTrackPoints = cr.query(TrackContentProvider.trackPointsUri(trackId), null,
null, null, TrackContentProvider.Schema.COL_TIMESTAMP + " asc");
Cursor cWayPoints = cr.query(TrackContentProvider.waypointsUri(trackId), null, null,
null, TrackContentProvider.Schema.COL_TIMESTAMP + " asc");
if (null != cTrackPoints && null != cWayPoints) {
publishProgress(new Long[]{trackId, (long) cTrackPoints.getCount(), (long) cWayPoints.getCount()});
try {
writeGpxFile(track_name, tags, track_description, cTrackPoints, cWayPoints, trackFile);
if (exportMediaFiles()) {
copyWaypointFiles(trackId, trackGPXExportDirectory);
}
if (updateExportDate()) {
DataHelper.setTrackExportDate(trackId, System.currentTimeMillis(), cr);
}
} catch (IOException ioe) {
throw new ExportTrackException(ioe.getMessage());
} finally {
cTrackPoints.close();
cWayPoints.close();
}
// Force rescan of directory
ArrayList<String> files = new ArrayList<String>();
for (File file : trackGPXExportDirectory.listFiles()) {
files.add(file.getAbsolutePath());
}
MediaScannerConnection.scanFile(context, files.toArray(new String[0]), null, null);
}
} else {
throw new ExportTrackException(context.getResources().getString(R.string.error_externalstorage_not_writable));
}
}
}
/**
* Writes the GPX file
* @param cTrackPoints Cursor to track points.
* @param cWayPoints Cursor to way points.
* @param target Target GPX file
* @throws IOException
*/
private void writeGpxFile(String trackName, String tags, String track_description, Cursor cTrackPoints, Cursor cWayPoints, File target) throws IOException {
String accuracyOutput = PreferenceManager.getDefaultSharedPreferences(context).getString(
OSMTracker.Preferences.KEY_OUTPUT_ACCURACY,
OSMTracker.Preferences.VAL_OUTPUT_ACCURACY);
boolean fillHDOP = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
OSMTracker.Preferences.KEY_OUTPUT_GPX_HDOP_APPROXIMATION,
OSMTracker.Preferences.VAL_OUTPUT_GPX_HDOP_APPROXIMATION);
String compassOutput = PreferenceManager.getDefaultSharedPreferences(context).getString(
OSMTracker.Preferences.KEY_OUTPUT_COMPASS,
OSMTracker.Preferences.VAL_OUTPUT_COMPASS);
Log.v(TAG, "write preferences: compass:" + compassOutput);
Writer writer = null;
try {
writer = new BufferedWriter(new FileWriter(target));
writer.write(XML_HEADER + "\n");
writer.write(TAG_GPX + "\n");
writer.write("\t<metadata>\n");
// Write the track's name to a tag
if((trackName != null && !trackName.equals(""))) writer.write("\t\t<name>"+ trackName +"</name>\n");
if (tags != null && !tags.equals("")) {
for (String tag : tags.split(","))
writer.write("\t\t<keywords>" + tag.trim() + "</keywords>\n");
}
if ((track_description != null && !track_description.equals(""))) writer.write("\t\t<desc>" + track_description + "</desc>\n");
writer.write("\t</metadata>\n");
writeWayPoints(writer, cWayPoints, accuracyOutput, fillHDOP, compassOutput);
writeTrackPoints(context.getResources().getString(R.string.gpx_track_name), writer, cTrackPoints, fillHDOP, compassOutput);
writer.write("</gpx>");
} finally {
if (writer != null) {
writer.close();
}
}
}
/**
* Iterates on track points and write them.
* @param trackName Name of the track (metadata).
* @param fw Writer to the target file.
* @param c Cursor to track points.
* @param fillHDOP Indicates whether fill <hdop> tag with approximation from location accuracy.
* @param compass Indicates if and how to write compass heading to the GPX ('none', 'comment', 'extension')
* @throws IOException
*/
private void writeTrackPoints(String trackName, Writer fw, Cursor c, boolean fillHDOP, String compass) throws IOException {
// Update dialog every 1%
int dialogUpdateThreshold = c.getCount() / 100;
if (dialogUpdateThreshold == 0) {
dialogUpdateThreshold++;
}
fw.write("<trk>" + "\n");
fw.write("<name>" + CDATA_START + trackName + CDATA_END + "</name>" + "\n");
if (fillHDOP) {
fw.write("<cmt>"
+ CDATA_START
+ context.getResources().getString(R.string.gpx_hdop_approximation_cmt)
+ CDATA_END
+ "</cmt>" + "\n");
}
fw.write("<trkseg>" + "\n");
int i=0;
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext(),i++) {
StringBuffer out = new StringBuffer();
out.append("<trkpt lat=\""
+ c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_LATITUDE)) + "\" "
+ "lon=\"" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_LONGITUDE)) + "\">");
if (! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_ELEVATION))) {
out.append("<ele>" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_ELEVATION)) + "</ele>");
}
out.append("<time>" + pointDateFormatter.format(new Date(c.getLong(c.getColumnIndex(TrackContentProvider.Schema.COL_TIMESTAMP)))) + "</time>");
if(fillHDOP && ! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_ACCURACY))) {
out.append("<hdop>" + (c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_ACCURACY)) / OSMTracker.HDOP_APPROXIMATION_FACTOR) + "</hdop>");
}
if(OSMTracker.Preferences.VAL_OUTPUT_COMPASS_COMMENT.equals(compass) && !c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS))) {
out.append("<cmt>"+CDATA_START+"compass: " +
c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS))+
" compAccuracy: " +
c.getLong(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS_ACCURACY))+
CDATA_END+"</cmt>");
}
String buff = "";
if(! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_SPEED))) {
buff += "<speed>" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_SPEED)) + "</speed>";
}
if(OSMTracker.Preferences.VAL_OUTPUT_COMPASS_EXTENSION.equals(compass) && !c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS))) {
buff += "<compass>" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS)) + "</compass>";
buff += "<compass_accuracy>" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS_ACCURACY)) + "</compass_accuracy>";
}
if(! buff.equals("")) {
out.append("<extensions>");
out.append(buff);
out.append("</extensions>");
}
out.append("</trkpt>" + "\n");
fw.write(out.toString());
if (i % dialogUpdateThreshold == 0) {
publishProgress((long) dialogUpdateThreshold);
}
}
fw.write("</trkseg>" + "\n");
fw.write("</trk>" + "\n");
}
/**
* Iterates on way points and write them.
* @param fw Writer to the target file.
* @param c Cursor to way points.
* @param accuracyInfo Constant describing how to include (or not) accuracy info for way points.
* @param fillHDOP Indicates whether fill <hdop> tag with approximation from location accuracy.
* @param compass Indicates if and how to write compass heading to the GPX ('none', 'comment', 'extension')
* @throws IOException
*/
private void writeWayPoints(Writer fw, Cursor c, String accuracyInfo, boolean fillHDOP, String compass) throws IOException {
// Update dialog every 1%
int dialogUpdateThreshold = c.getCount() / 100;
if (dialogUpdateThreshold == 0) {
dialogUpdateThreshold++;
}
// Label for meter unit
String meterUnit = context.getResources().getString(R.string.various_unit_meters);
// Word "accuracy"
String accuracy = context.getResources().getString(R.string.various_accuracy);
int i=0;
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext(), i++) {
StringBuffer out = new StringBuffer();
out.append("<wpt lat=\""
+ c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_LATITUDE)) + "\" "
+ "lon=\"" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_LONGITUDE)) + "\">");
if (! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_ELEVATION))) {
out.append("<ele>" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_ELEVATION)) + "</ele>");
}
out.append("<time>" + pointDateFormatter.format(new Date(c.getLong(c.getColumnIndex(TrackContentProvider.Schema.COL_TIMESTAMP)))) + "</time>");
String name = c.getString(c.getColumnIndex(TrackContentProvider.Schema.COL_NAME));
if (! OSMTracker.Preferences.VAL_OUTPUT_ACCURACY_NONE.equals(accuracyInfo) && ! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_ACCURACY))) {
// Outputs accuracy info for way point
if (OSMTracker.Preferences.VAL_OUTPUT_ACCURACY_WPT_NAME.equals(accuracyInfo)) {
// Output accuracy with name
out.append("<name>"
+ CDATA_START
+ name
+ " (" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_ACCURACY)) + meterUnit + ")"
+ CDATA_END
+ "</name>");
if (OSMTracker.Preferences.VAL_OUTPUT_COMPASS_COMMENT.equals(compass) &&
! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS))) {
out.append("<cmt>" + CDATA_START + "compass: " + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS)) +
" compass accuracy: " + c.getInt(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS_ACCURACY)) + CDATA_END + "</cmt>");
}
} else if (OSMTracker.Preferences.VAL_OUTPUT_ACCURACY_WPT_CMT.equals(accuracyInfo)) {
// Output accuracy in separate tag
out.append("<name>" + CDATA_START + name + CDATA_END + "</name>");
if (OSMTracker.Preferences.VAL_OUTPUT_COMPASS_COMMENT.equals(compass) &&
! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS))) {
out.append("<cmt>" + CDATA_START + accuracy + ": " + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_ACCURACY)) + meterUnit +
" compass heading: " + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS)) +
"deg compass accuracy: " + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS_ACCURACY)) +CDATA_END + "</cmt>");
} else {
out.append("<cmt>" + CDATA_START + accuracy + ": " + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_ACCURACY)) + meterUnit + CDATA_END + "</cmt>");
}
} else {
// Unknown value for accuracy info, shouldn't occur but who knows ?
// See issue #68. Output at least the name just in case.
out.append("<name>" + CDATA_START + name + CDATA_END + "</name>");
}
} else {
// No accuracy info requested, or available
out.append("<name>" + CDATA_START + name + CDATA_END + "</name>");
if (OSMTracker.Preferences.VAL_OUTPUT_COMPASS_COMMENT.equals(compass) &&
! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS))) {
out.append("<cmt>" + CDATA_START + "compass: " + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS)) +
" compass accuracy: " + c.getInt(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS_ACCURACY)) + CDATA_END + "</cmt>");
}
}
String link = c.getString(c.getColumnIndex(TrackContentProvider.Schema.COL_LINK));
if (link != null) {
out.append("<link href=\"" + URLEncoder.encode(link) + "\">");
out.append("<text>" + link +"</text>");
out.append("</link>");
}
if (! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_NBSATELLITES))) {
out.append("<sat>" + c.getInt(c.getColumnIndex(TrackContentProvider.Schema.COL_NBSATELLITES)) + "</sat>");
}
if(fillHDOP && ! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_ACCURACY))) {
out.append("<hdop>" + (c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_ACCURACY)) / OSMTracker.HDOP_APPROXIMATION_FACTOR) + "</hdop>");
}
if (OSMTracker.Preferences.VAL_OUTPUT_COMPASS_EXTENSION.equals(compass) &&
! c.isNull(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS))) {
out.append("<extensions>");
out.append("<compass>" + c.getDouble(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS)) + "</compass>");
out.append("<compass_accuracy>" + c.getInt(c.getColumnIndex(TrackContentProvider.Schema.COL_COMPASS_ACCURACY)) + "</compass_accuracy>");
out.append("</extensions>");
}
out.append("</wpt>" + "\n");
fw.write(out.toString());
if (i % dialogUpdateThreshold == 0) {
publishProgress((long) dialogUpdateThreshold);
}
}
}
/**
* Copy all files from the OSMTracker external storage location to gpxOutputDirectory
* @param gpxOutputDirectory The directory to which the track is being exported
*/
private void copyWaypointFiles(long trackId, File gpxOutputDirectory) {
// Get the new location where files related to these waypoints are/should be stored
File trackDir = DataHelper.getTrackDirectory(trackId);
if(trackDir != null){
Log.v(TAG, "Copying files from the standard TrackDir ["+trackDir+"] to the export directory ["+gpxOutputDirectory+"]");
FileSystemUtils.copyDirectoryContents(gpxOutputDirectory, trackDir);
}
}
/**
* Build GPX filename from track info, based on preferences.
* The filename will have the start date, and/or the track name if available.
* If no name is available, fall back to the start date and time.
* Track name characters will be sanitized using {@link #FILENAME_CHARS_BLACKLIST_PATTERN}.
* @param c Track info: {@link TrackContentProvider.Schema#COL_NAME}, {@link TrackContentProvider.Schema#COL_START_DATE}
* @return GPX filename, not including the path
*/
protected String buildGPXFilename(Cursor c) {
// Build GPX filename from track info & preferences
final String filenameOutput = PreferenceManager.getDefaultSharedPreferences(context).getString(
OSMTracker.Preferences.KEY_OUTPUT_FILENAME,
OSMTracker.Preferences.VAL_OUTPUT_FILENAME);
StringBuilder filenameBase = new StringBuilder();
final int colName = c.getColumnIndexOrThrow(TrackContentProvider.Schema.COL_NAME);
String tname = c.getString(colName);
if ((! c.isNull(colName))
&& (! filenameOutput.equals(OSMTracker.Preferences.VAL_OUTPUT_FILENAME_DATE))) {
final String tname_raw = tname.trim().replace(':', ';');
final String sanitized = FILENAME_CHARS_BLACKLIST_PATTERN.matcher(tname_raw).replaceAll("_");
filenameBase.append(sanitized);
}
filenameBase.append(DataHelper.EXTENSION_GPX);
return filenameBase.toString();
}
}