Cleanup: export/import renaming.

This commit is contained in:
Dennis Guse
2025-03-28 18:21:15 +01:00
parent ed163b2083
commit 681b987927
13 changed files with 51 additions and 56 deletions
@@ -312,7 +312,7 @@ public class ExportImportTest {
contentProviderUtils.deleteTrack(context, trackId); contentProviderUtils.deleteTrack(context, trackId);
// 2. import // 2. import
KmzTrackImporter importer = new KmzTrackImporter(context, trackImporter); KMZTrackImporter importer = new KMZTrackImporter(context, trackImporter);
importTrackId = importer.importFile(tmpFileUri).get(0); importTrackId = importer.importFile(tmpFileUri).get(0);
// then // then
@@ -358,7 +358,7 @@ public class ExportImportTest {
// 2. import // 2. import
InputStream inputStream = context.getContentResolver().openInputStream(tmpFileUri); InputStream inputStream = context.getContentResolver().openInputStream(tmpFileUri);
XMLImporter importer = new XMLImporter(new KmlTrackImporter(context, trackImporter)); XMLImporter importer = new XMLImporter(new KMLTrackImporter(context, trackImporter));
importTrackId = importer.importFile(inputStream).get(0); importTrackId = importer.importFile(inputStream).get(0);
// then // then
@@ -383,7 +383,7 @@ public class ExportImportTest {
// 2. import // 2. import
InputStream inputStream = context.getContentResolver().openInputStream(tmpFileUri); InputStream inputStream = context.getContentResolver().openInputStream(tmpFileUri);
XMLImporter importer = new XMLImporter(new GpxTrackImporter(context, trackImporter)); XMLImporter importer = new XMLImporter(new GPXTrackImporter(context, trackImporter));
importTrackId = importer.importFile(inputStream).get(0); importTrackId = importer.importFile(inputStream).get(0);
// then // then
@@ -503,7 +503,7 @@ public class ExportImportTest {
// 2. import // 2. import
InputStream inputStream = context.getContentResolver().openInputStream(tmpFileUri); InputStream inputStream = context.getContentResolver().openInputStream(tmpFileUri);
XMLImporter importer = new XMLImporter(new GpxTrackImporter(context, trackImporter)); XMLImporter importer = new XMLImporter(new GPXTrackImporter(context, trackImporter));
importTrackId = importer.importFile(inputStream).get(0); importTrackId = importer.importFile(inputStream).get(0);
// then // then
@@ -68,7 +68,7 @@ public class GPXTrackImporterTest {
@Test @Test
public void gpx_with_pause_resume() throws IOException { public void gpx_with_pause_resume() throws IOException {
// given // given
XMLImporter importer = new XMLImporter(new GpxTrackImporter(context, trackImporter)); XMLImporter importer = new XMLImporter(new GPXTrackImporter(context, trackImporter));
InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.legacy_gpx_pause_resume); InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.legacy_gpx_pause_resume);
// when // when
@@ -132,7 +132,7 @@ public class GPXTrackImporterTest {
@Test @Test
public void gpx_without_speed() throws IOException { public void gpx_without_speed() throws IOException {
// given // given
XMLImporter importer = new XMLImporter(new GpxTrackImporter(context, trackImporter)); XMLImporter importer = new XMLImporter(new GPXTrackImporter(context, trackImporter));
InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.gpx11_without_speed); InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.gpx11_without_speed);
// when // when
@@ -187,7 +187,7 @@ public class GPXTrackImporterTest {
@Test @Test
public void gpx_speed_no_namespace() throws IOException { public void gpx_speed_no_namespace() throws IOException {
// given // given
XMLImporter importer = new XMLImporter(new GpxTrackImporter(context, trackImporter)); XMLImporter importer = new XMLImporter(new GPXTrackImporter(context, trackImporter));
InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.gpx11_with_speed_no_namespace); InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.gpx11_with_speed_no_namespace);
// when // when
@@ -246,7 +246,7 @@ public class GPXTrackImporterTest {
@Test @Test
public void gpx_legacy_trackpointextension() throws IOException { public void gpx_legacy_trackpointextension() throws IOException {
// given // given
XMLImporter importer = new XMLImporter(new GpxTrackImporter(context, trackImporter)); XMLImporter importer = new XMLImporter(new GPXTrackImporter(context, trackImporter));
InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.legacy_gpx_trackpointextensions_incorrect); InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.legacy_gpx_trackpointextensions_incorrect);
// when // when
@@ -317,7 +317,7 @@ public class GPXTrackImporterTest {
@Test @Test
public void importExportTest_timezone() throws IOException { public void importExportTest_timezone() throws IOException {
// given // given
XMLImporter importer = new XMLImporter(new GpxTrackImporter(context, trackImporter)); XMLImporter importer = new XMLImporter(new GPXTrackImporter(context, trackImporter));
InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.gpx_timezone); InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.gpx_timezone);
InputStream inputStreamExpected = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.gpx_timezone); InputStream inputStreamExpected = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.gpx_timezone);
@@ -62,7 +62,7 @@ public class KMLTrackImporterTest {
@Test @Test
public void kml22_order_location_and_when() throws IOException { public void kml22_order_location_and_when() throws IOException {
// given // given
XMLImporter importer = new XMLImporter(new KmlTrackImporter(context, trackImporter)); XMLImporter importer = new XMLImporter(new KMLTrackImporter(context, trackImporter));
InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.kml22_order_location_and_when); InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.kml22_order_location_and_when);
// when // when
@@ -118,7 +118,7 @@ public class KMLTrackImporterTest {
@Test @Test
public void kml22_time_decreases() throws IOException { public void kml22_time_decreases() throws IOException {
// given // given
XMLImporter importer = new XMLImporter(new KmlTrackImporter(context, trackImporter)); XMLImporter importer = new XMLImporter(new KMLTrackImporter(context, trackImporter));
InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.kml22_time_decreases); InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.kml22_time_decreases);
// when // when
@@ -159,7 +159,7 @@ public class KMLTrackImporterTest {
@Test @Test
public void kml22_with_statistics_marker() throws IOException { public void kml22_with_statistics_marker() throws IOException {
// given // given
XMLImporter importer = new XMLImporter(new KmlTrackImporter(context, trackImporter)); XMLImporter importer = new XMLImporter(new KMLTrackImporter(context, trackImporter));
InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.legacy_kml22_statistics_marker); InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.legacy_kml22_statistics_marker);
// when // when
@@ -243,7 +243,7 @@ public class KMLTrackImporterTest {
@Test(expected = ImportParserException.class) @Test(expected = ImportParserException.class)
public void kml_without_locations() throws IOException { public void kml_without_locations() throws IOException {
// given // given
XMLImporter importer = new XMLImporter(new KmlTrackImporter(context, trackImporter)); XMLImporter importer = new XMLImporter(new KMLTrackImporter(context, trackImporter));
InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.kml22_without_locations); InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.kml22_without_locations);
// when // when
@@ -254,7 +254,7 @@ public class KMLTrackImporterTest {
@Test(expected = ImportParserException.class) @Test(expected = ImportParserException.class)
public void kml_when_locations_different() throws IOException { public void kml_when_locations_different() throws IOException {
// given // given
XMLImporter importer = new XMLImporter(new KmlTrackImporter(context, trackImporter)); XMLImporter importer = new XMLImporter(new KMLTrackImporter(context, trackImporter));
InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.kml22_when_locations_different); InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.kml22_when_locations_different);
// when // when
@@ -15,7 +15,7 @@ import de.dennisguse.opentracks.data.ContentProviderUtils;
import de.dennisguse.opentracks.io.file.exporter.CSVTrackExporter; import de.dennisguse.opentracks.io.file.exporter.CSVTrackExporter;
import de.dennisguse.opentracks.io.file.exporter.GPXTrackExporter; import de.dennisguse.opentracks.io.file.exporter.GPXTrackExporter;
import de.dennisguse.opentracks.io.file.exporter.KMLTrackExporter; import de.dennisguse.opentracks.io.file.exporter.KMLTrackExporter;
import de.dennisguse.opentracks.io.file.exporter.KmzTrackExporter; import de.dennisguse.opentracks.io.file.exporter.KMZTrackExporter;
import de.dennisguse.opentracks.io.file.exporter.TrackExporter; import de.dennisguse.opentracks.io.file.exporter.TrackExporter;
/** /**
@@ -33,7 +33,7 @@ public enum TrackFileFormat {
@Override @Override
public String getMimeType() { public String getMimeType() {
return MIME_KML; return "application/vnd.google-earth.kml+xml";
} }
public String getExtension() { public String getExtension() {
@@ -49,12 +49,12 @@ public enum TrackFileFormat {
@Override @Override
public TrackExporter createTrackExporter(@NonNull Context context, @NonNull ContentProviderUtils contentProviderUtils) { public TrackExporter createTrackExporter(@NonNull Context context, @NonNull ContentProviderUtils contentProviderUtils) {
KMLTrackExporter exporter = new KMLTrackExporter(context, contentProviderUtils, exportPhotos); KMLTrackExporter exporter = new KMLTrackExporter(context, contentProviderUtils, exportPhotos);
return new KmzTrackExporter(context, contentProviderUtils, exporter, exportPhotos); return new KMZTrackExporter(context, contentProviderUtils, exporter, exportPhotos);
} }
@Override @Override
public String getMimeType() { public String getMimeType() {
return MIME_KMZ; return "application/vnd.google-earth.kmz";
} }
public String getExtension() { public String getExtension() {
@@ -74,12 +74,12 @@ public enum TrackFileFormat {
@Override @Override
public TrackExporter createTrackExporter(@NonNull Context context, @NonNull ContentProviderUtils contentProviderUtils) { public TrackExporter createTrackExporter(@NonNull Context context, @NonNull ContentProviderUtils contentProviderUtils) {
KMLTrackExporter exporter = new KMLTrackExporter(context, contentProviderUtils, exportPhotos); KMLTrackExporter exporter = new KMLTrackExporter(context, contentProviderUtils, exportPhotos);
return new KmzTrackExporter(context, contentProviderUtils, exporter, exportPhotos); return new KMZTrackExporter(context, contentProviderUtils, exporter, exportPhotos);
} }
@Override @Override
public String getMimeType() { public String getMimeType() {
return MIME_KMZ; return KMZ_WITH_TRACKDETAIL_AND_SENSORDATA.getMimeType();
} }
public String getExtension() { public String getExtension() {
@@ -126,17 +126,13 @@ public enum TrackFileFormat {
} }
}; };
private static final String MIME_KMZ = "application/vnd.google-earth.kmz";
private static final String MIME_KML = "application/vnd.google-earth.kml+xml";
private final String preferenceId; private final String preferenceId;
TrackFileFormat(String preferenceId) { TrackFileFormat(String preferenceId) {
this.preferenceId = preferenceId; this.preferenceId = preferenceId;
} }
public static Map<String, String> toPreferenceIdLabelMap(final Resources resources, final TrackFileFormat ... trackFileFormats) { public static Map<String, String> toPreferenceIdLabelMap(final Resources resources, final TrackFileFormat... trackFileFormats) {
Map<String, String> preferenceIdLabelMap = new LinkedHashMap<>(trackFileFormats.length); Map<String, String> preferenceIdLabelMap = new LinkedHashMap<>(trackFileFormats.length);
for (TrackFileFormat trackFileFormat : trackFileFormats) { for (TrackFileFormat trackFileFormat : trackFileFormats) {
String trackFileFormatUpperCase = trackFileFormat.getExtension().toUpperCase(Locale.US); //ASCII upper case String trackFileFormatUpperCase = trackFileFormat.getExtension().toUpperCase(Locale.US); //ASCII upper case
@@ -102,7 +102,6 @@ public class GPXTrackExporter implements TrackExporter {
try { try {
prepare(outputStream); prepare(outputStream);
writeHeader(); writeHeader();
for (Track track : tracks) { for (Track track : tracks) {
writeMarkers(track); writeMarkers(track);
} }
@@ -200,17 +199,17 @@ public class GPXTrackExporter implements TrackExporter {
} }
} }
public void prepare(OutputStream outputStream) { private void prepare(OutputStream outputStream) {
this.printWriter = new PrintWriter(outputStream); this.printWriter = new PrintWriter(outputStream);
} }
public void close() { private void close() {
printWriter.flush(); printWriter.flush();
printWriter = null; printWriter = null;
} }
public void writeHeader() { private void writeHeader() {
printWriter.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); printWriter.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
printWriter.println("<gpx"); printWriter.println("<gpx");
printWriter.println("version=\"1.1\""); printWriter.println("version=\"1.1\"");
@@ -233,7 +232,7 @@ public class GPXTrackExporter implements TrackExporter {
+ " http://opentracksapp.com/xmlschemas/v1 http://opentracksapp.com/xmlschemas/OpenTracks_v1.xsd\">"); + " http://opentracksapp.com/xmlschemas/v1 http://opentracksapp.com/xmlschemas/OpenTracks_v1.xsd\">");
} }
public void writeFooter() { private void writeFooter() {
printWriter.println("</gpx>"); printWriter.println("</gpx>");
} }
@@ -253,7 +252,7 @@ public class GPXTrackExporter implements TrackExporter {
} }
} }
public void writeMarker(ZoneOffset zoneOffset, Marker marker) { private void writeMarker(ZoneOffset zoneOffset, Marker marker) {
printWriter.println("<wpt " + formatLocation(marker.getLatitude(), marker.getLongitude()) + ">"); printWriter.println("<wpt " + formatLocation(marker.getLatitude(), marker.getLongitude()) + ">");
if (marker.hasAltitude()) { if (marker.hasAltitude()) {
printWriter.println("<ele>" + ALTITUDE_FORMAT.format(marker.getAltitude().toM()) + "</ele>"); printWriter.println("<ele>" + ALTITUDE_FORMAT.format(marker.getAltitude().toM()) + "</ele>");
@@ -265,7 +264,7 @@ public class GPXTrackExporter implements TrackExporter {
printWriter.println("</wpt>"); printWriter.println("</wpt>");
} }
public void writeBeginTrack(Track track) { private void writeBeginTrack(Track track) {
printWriter.println("<trk>"); printWriter.println("<trk>");
printWriter.println("<name>" + StringUtils.formatCData(track.getName()) + "</name>"); printWriter.println("<name>" + StringUtils.formatCData(track.getName()) + "</name>");
printWriter.println("<desc>" + StringUtils.formatCData(track.getDescription()) + "</desc>"); printWriter.println("<desc>" + StringUtils.formatCData(track.getDescription()) + "</desc>");
@@ -297,19 +296,19 @@ public class GPXTrackExporter implements TrackExporter {
printWriter.println("</extensions>"); printWriter.println("</extensions>");
} }
public void writeEndTrack() { private void writeEndTrack() {
printWriter.println("</trk>"); printWriter.println("</trk>");
} }
public void writeOpenSegment() { private void writeOpenSegment() {
printWriter.println("<trkseg>"); printWriter.println("<trkseg>");
} }
public void writeCloseSegment() { private void writeCloseSegment() {
printWriter.println("</trkseg>"); printWriter.println("</trkseg>");
} }
public Distance writeTrackPoint(ZoneOffset zoneOffset, TrackPoint trackPoint, List<TrackPoint> sensorPoints, Distance trackDistance) { private Distance writeTrackPoint(ZoneOffset zoneOffset, TrackPoint trackPoint, List<TrackPoint> sensorPoints, Distance trackDistance) {
Distance cumulativeDistance; Distance cumulativeDistance;
printWriter.println("<trkpt " + formatLocation(trackPoint.getLatitude(), trackPoint.getLongitude()) + ">"); printWriter.println("<trkpt " + formatLocation(trackPoint.getLatitude(), trackPoint.getLongitude()) + ">");
@@ -107,6 +107,7 @@ public class KMLTrackExporter implements TrackExporter {
this.contentProviderUtils = contentProviderUtils; this.contentProviderUtils = contentProviderUtils;
} }
@Override
public boolean writeTrack(List<Track> tracks, @NonNull OutputStream outputStream) { public boolean writeTrack(List<Track> tracks, @NonNull OutputStream outputStream) {
try { try {
prepare(outputStream); prepare(outputStream);
@@ -444,7 +445,7 @@ public class KMLTrackExporter implements TrackExporter {
writeTypeLocalized(marker.getCategory()); writeTypeLocalized(marker.getCategory());
if (exportPhotos) { if (exportPhotos) {
printWriter.println("<Icon><href>" + KmzTrackExporter.buildKmzImageFilePath(marker) + "</href></Icon>"); printWriter.println("<Icon><href>" + KMZTrackExporter.buildKmzImageFilePath(marker) + "</href></Icon>");
} }
printWriter.print("<ViewVolume>"); printWriter.print("<ViewVolume>");
@@ -43,12 +43,12 @@ import de.dennisguse.opentracks.util.FileUtils;
* *
* @author Jimmy Shih * @author Jimmy Shih
*/ */
public class KmzTrackExporter implements TrackExporter { public class KMZTrackExporter implements TrackExporter {
private static final String KMZ_IMAGES_DIR = "images"; private static final String KMZ_IMAGES_DIR = "images";
public static final String KMZ_KML_FILE = "doc.kml"; public static final String KMZ_KML_FILE = "doc.kml";
private static final String TAG = KmzTrackExporter.class.getSimpleName(); private static final String TAG = KMZTrackExporter.class.getSimpleName();
private static final int BUFFER_SIZE = 4096; private static final int BUFFER_SIZE = 4096;
private final ContentProviderUtils contentProviderUtils; private final ContentProviderUtils contentProviderUtils;
@@ -57,7 +57,7 @@ public class KmzTrackExporter implements TrackExporter {
private final boolean exportPhotos; private final boolean exportPhotos;
private final Context context; private final Context context;
public KmzTrackExporter(Context context, ContentProviderUtils contentProviderUtils, KMLTrackExporter trackExporter, boolean exportPhotos) { public KMZTrackExporter(Context context, ContentProviderUtils contentProviderUtils, KMLTrackExporter trackExporter, boolean exportPhotos) {
this.context = context; this.context = context;
this.contentProviderUtils = contentProviderUtils; this.contentProviderUtils = contentProviderUtils;
this.fileTrackExporter = trackExporter; this.fileTrackExporter = trackExporter;
@@ -52,9 +52,9 @@ import de.dennisguse.opentracks.util.StringUtils;
* *
* @author Jimmy Shih * @author Jimmy Shih
*/ */
public class GpxTrackImporter extends DefaultHandler implements XMLImporter.TrackParser { public class GPXTrackImporter extends DefaultHandler implements XMLImporter.TrackParser {
private static final String TAG = GpxTrackImporter.class.getSimpleName(); private static final String TAG = GPXTrackImporter.class.getSimpleName();
private static final String TAG_DESCRIPTION = "desc"; private static final String TAG_DESCRIPTION = "desc";
private static final String TAG_ALTITUDE = "ele"; private static final String TAG_ALTITUDE = "ele";
@@ -123,7 +123,7 @@ public class GpxTrackImporter extends DefaultHandler implements XMLImporter.Trac
private final TrackImporter trackImporter; private final TrackImporter trackImporter;
public GpxTrackImporter(Context context, TrackImporter trackImporter) { public GPXTrackImporter(Context context, TrackImporter trackImporter) {
this.context = context; this.context = context;
this.trackImporter = trackImporter; this.trackImporter = trackImporter;
} }
@@ -54,17 +54,16 @@ public class ImportService extends JobIntentService {
String fileExtension = FileUtils.getExtension(file); String fileExtension = FileUtils.getExtension(file);
try { try {
Distance maxRecordingDistance = PreferencesUtils.getMaxRecordingDistance(); Distance maxRecordingDistance = PreferencesUtils.getMaxRecordingDistance();
Distance recordingDistanceInterval = PreferencesUtils.getRecordingDistanceInterval();
boolean preventReimport = PreferencesUtils.getPreventReimportTracks(); boolean preventReimport = PreferencesUtils.getPreventReimportTracks();
TrackImporter trackImporter = new TrackImporter(this, new ContentProviderUtils(this), maxRecordingDistance, preventReimport); TrackImporter trackImporter = new TrackImporter(this, new ContentProviderUtils(this), maxRecordingDistance, preventReimport);
if (TrackFileFormat.GPX.getExtension().equals(fileExtension)) { if (TrackFileFormat.GPX.getExtension().equals(fileExtension)) {
trackIds.addAll(new XMLImporter(new GpxTrackImporter(this, trackImporter)).importFile(this, file.getUri())); trackIds.addAll(new XMLImporter(new GPXTrackImporter(this, trackImporter)).importFile(this, file.getUri()));
} else if (TrackFileFormat.KML_WITH_TRACKDETAIL_AND_SENSORDATA.getExtension().equals(fileExtension)) { } else if (TrackFileFormat.KML_WITH_TRACKDETAIL_AND_SENSORDATA.getExtension().equals(fileExtension)) {
trackIds.addAll(new XMLImporter(new KmlTrackImporter(this, trackImporter)).importFile(this, file.getUri())); trackIds.addAll(new XMLImporter(new KMLTrackImporter(this, trackImporter)).importFile(this, file.getUri()));
} else if (TrackFileFormat.KMZ_WITH_TRACKDETAIL_AND_SENSORDATA_AND_PICTURES.getExtension().equals(fileExtension)) { } else if (TrackFileFormat.KMZ_WITH_TRACKDETAIL_AND_SENSORDATA_AND_PICTURES.getExtension().equals(fileExtension)) {
trackIds.addAll(new KmzTrackImporter(this, trackImporter).importFile(file.getUri())); trackIds.addAll(new KMZTrackImporter(this, trackImporter).importFile(file.getUri()));
} else { } else {
Log.d(TAG, "Unsupported file format."); Log.d(TAG, "Unsupported file format.");
sendResult(ImportServiceResultReceiver.RESULT_CODE_ERROR, null, file, getString(R.string.import_unsupported_format)); sendResult(ImportServiceResultReceiver.RESULT_CODE_ERROR, null, file, getString(R.string.import_unsupported_format));
@@ -47,9 +47,9 @@ import de.dennisguse.opentracks.util.StringUtils;
* *
* @author Jimmy Shih * @author Jimmy Shih
*/ */
public class KmlTrackImporter extends DefaultHandler implements XMLImporter.TrackParser { public class KMLTrackImporter extends DefaultHandler implements XMLImporter.TrackParser {
private static final String TAG = KmlTrackImporter.class.getSimpleName(); private static final String TAG = KMLTrackImporter.class.getSimpleName();
private static final String MARKER_STYLE = "#" + KMLTrackExporter.MARKER_STYLE; private static final String MARKER_STYLE = "#" + KMLTrackExporter.MARKER_STYLE;
@@ -128,7 +128,7 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac
private final TrackImporter trackImporter; private final TrackImporter trackImporter;
public KmlTrackImporter(Context context, TrackImporter trackImporter) { public KMLTrackImporter(Context context, TrackImporter trackImporter) {
this.context = context; this.context = context;
this.trackImporter = trackImporter; this.trackImporter = trackImporter;
} }
@@ -44,9 +44,9 @@ import de.dennisguse.opentracks.util.FileUtils;
* *
* @author Jimmy Shih * @author Jimmy Shih
*/ */
public class KmzTrackImporter { public class KMZTrackImporter {
private static final String TAG = KmzTrackImporter.class.getSimpleName(); private static final String TAG = KMZTrackImporter.class.getSimpleName();
private static final String KML_FILE_EXTENSION = ".kml"; private static final String KML_FILE_EXTENSION = ".kml";
@@ -55,7 +55,7 @@ public class KmzTrackImporter {
private final Context context; private final Context context;
private final TrackImporter trackImporter; private final TrackImporter trackImporter;
public KmzTrackImporter(Context context, TrackImporter trackImporter) { public KMZTrackImporter(Context context, TrackImporter trackImporter) {
this.context = context; this.context = context;
this.trackImporter = trackImporter; this.trackImporter = trackImporter;
} }
@@ -211,7 +211,7 @@ public class KmzTrackImporter {
} }
private List<Track.Id> parseKml(ZipInputStream zipInputStream) throws IOException { private List<Track.Id> parseKml(ZipInputStream zipInputStream) throws IOException {
XMLImporter kmlFileTrackImporter = new XMLImporter(new KmlTrackImporter(context, trackImporter)); XMLImporter kmlFileTrackImporter = new XMLImporter(new KMLTrackImporter(context, trackImporter));
InputStream nonClosableInputStream = new FilterInputStream(zipInputStream) { InputStream nonClosableInputStream = new FilterInputStream(zipInputStream) {
@Override @Override
@@ -233,7 +233,7 @@ public class TrackImporter {
* @param externalPhotoUrl the file name * @param externalPhotoUrl the file name
*/ */
private Uri getInternalPhotoUrl(@NonNull Track.Id trackId, @NonNull Uri externalPhotoUrl) { private Uri getInternalPhotoUrl(@NonNull Track.Id trackId, @NonNull Uri externalPhotoUrl) {
String importFileName = KmzTrackImporter.importNameForFilename(externalPhotoUrl.toString()); String importFileName = KMZTrackImporter.importNameForFilename(externalPhotoUrl.toString());
File file = MarkerUtils.buildInternalPhotoFile(context, trackId, Uri.parse(importFileName)); File file = MarkerUtils.buildInternalPhotoFile(context, trackId, Uri.parse(importFileName));
if (file != null) { if (file != null) {
return FileUtils.getUriForFile(context, file); return FileUtils.getUriForFile(context, file);
@@ -47,7 +47,7 @@ public class XMLImporter {
return parser.getImportTrackIds(); return parser.getImportTrackIds();
} catch (SAXException | ParserConfigurationException | ParsingException e) { } catch (SAXException | ParserConfigurationException | ParsingException e) {
Log.e(TAG, "Unable to import file", e); Log.e(TAG, "Unable to import file", e);
if (parser.getImportTrackIds().size() > 0) { if (!parser.getImportTrackIds().isEmpty()) {
parser.cleanImport(); parser.cleanImport();
} }
throw new ImportParserException(e); throw new ImportParserException(e);