Importing creates content:// for attached pictures. Also, exporting without points bug fixed and images href contains relative link. Fixes #166 and #176.

This commit is contained in:
Román
2020-04-06 19:04:39 +02:00
committed by Dennis Guse
parent dfc3837739
commit 1b69f29751
4 changed files with 23 additions and 8 deletions
@@ -74,7 +74,7 @@ public class KmlTrackWriter implements TrackWriter {
/**
* @param context the context
* @param hasMultipleTracks should encode multiple tracks into one file?
* @param exportTrackDetail should detailed information about the track be exported (e.g., title, description, waypoints, timing)?
* @param exportTrackDetail should detailed information about the track be exported (e.g., title, description, waypoints, timing)?
* @param exportSensorData should {@link SensorDataSet} be exported?
* @param exportPhotos should pictures be exported (if true: exports to KMZ)?
*/
@@ -192,7 +192,8 @@ public class KmlTrackWriter implements TrackWriter {
this.startTrackPoint = startTrackPoint;
if (printWriter != null) {
String name = context.getString(R.string.marker_label_start, track.getName());
writePlacemark(name, "", "", START_STYLE, startTrackPoint.getLocation());
Location location = startTrackPoint != null ? startTrackPoint.getLocation() : null;
writePlacemark(name, "", "", START_STYLE, location);
printWriter.println("<Placemark>");
if (exportTrackDetail) {
@@ -218,7 +219,8 @@ public class KmlTrackWriter implements TrackWriter {
if (exportTrackDetail) {
String name = context.getString(R.string.marker_label_end, track.getName());
String description = descriptionGenerator.generateTrackDescription(track, false);
writePlacemark(name, "", description, END_STYLE, endTrackPoint.getLocation());
Location location = endTrackPoint != null ? endTrackPoint.getLocation() : null;
writePlacemark(name, "", description, END_STYLE, location);
}
}
}
@@ -345,7 +347,7 @@ public class KmlTrackWriter implements TrackWriter {
writeCategory(category);
if (exportPhotos) {
printWriter.println("<Icon><href>" + Uri.decode(photoUrl) + "</href></Icon>");
printWriter.println("<Icon><href>" + KmzTrackExporter.buildKmzImageFilePath(Uri.parse(photoUrl)) + "</href></Icon>");
}
printWriter.print("<ViewVolume>");
@@ -126,7 +126,7 @@ public class KmzTrackExporter implements TrackExporter {
Uri uri = Uri.parse(photoUrl);
try (InputStream inputStream = context.getContentResolver().openInputStream(uri)) {
ZipEntry zipEntry = new ZipEntry(KMZ_IMAGES_DIR + File.separatorChar + FileUtils.sanitizeFileName(uri.getLastPathSegment()));
ZipEntry zipEntry = new ZipEntry(buildKmzImageFilePath(uri));
zipOutputStream.putNextEntry(zipEntry);
if (inputStream == null) throw new FileNotFoundException();
@@ -147,4 +147,13 @@ public class KmzTrackExporter implements TrackExporter {
outputStream.write(buffer, 0, byteCount);
}
}
/**
* Builds and returns the path for the file that will be saved inside KMZ_IMAGES_DIR.
*
* @param uri URI object.
*/
public static String buildKmzImageFilePath(Uri uri) {
return KMZ_IMAGES_DIR + File.separatorChar + FileUtils.sanitizeFileName(uri.getLastPathSegment());
}
}
@@ -372,9 +372,13 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
if (importTrackId == -1L) {
return null;
}
File dir = FileUtils.getPhotoDir(context, importTrackId);
File file = new File(dir, fileName);
return Uri.fromFile(file).toString();
Uri photoUri = FileUtils.getUriForFile(context, file);
return photoUri.toString();
}
/**
@@ -186,9 +186,9 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
return;
}
// If there is photoUrl it has to be changed because that url in kml file isn't a valid content:// to the imported one.
if (photoUrl != null) {
Uri uri = Uri.parse(photoUrl);
photoUrl = getPhotoUrl(uri.getLastPathSegment());
photoUrl = getPhotoUrl(Uri.parse(photoUrl).getLastPathSegment());
}
addWaypoint();