aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/files
diff options
context:
space:
mode:
authorcampbeb <bpcampbell@gmail.com>2013-06-08 11:03:22 -1000
committercampbeb <bpcampbell@gmail.com>2013-06-08 11:03:22 -1000
commit7e6781394149e552b8e13787ed44c09fe327f501 (patch)
tree27aa72053b8ea3bf1aedb4da8b30587ac07c4233 /main/src/cgeo/geocaching/files
parent75ef80dc91bea395f7c7d089d8ca16b83d93e01f (diff)
downloadcgeo-7e6781394149e552b8e13787ed44c09fe327f501.zip
cgeo-7e6781394149e552b8e13787ed44c09fe327f501.tar.gz
cgeo-7e6781394149e552b8e13787ed44c09fe327f501.tar.bz2
Fix #2862 - Support LOC file import via intent
Fixes #2862
Diffstat (limited to 'main/src/cgeo/geocaching/files')
-rw-r--r--main/src/cgeo/geocaching/files/GPXImporter.java33
1 files changed, 31 insertions, 2 deletions
diff --git a/main/src/cgeo/geocaching/files/GPXImporter.java b/main/src/cgeo/geocaching/files/GPXImporter.java
index e146fca..10d791b 100644
--- a/main/src/cgeo/geocaching/files/GPXImporter.java
+++ b/main/src/cgeo/geocaching/files/GPXImporter.java
@@ -49,6 +49,7 @@ public class GPXImporter {
static final int IMPORT_STEP_STATIC_MAPS_SKIPPED = 9;
public static final String GPX_FILE_EXTENSION = ".gpx";
+ public static final String LOC_FILE_EXTENSION = ".loc";
public static final String ZIP_FILE_EXTENSION = ".zip";
public static final String WAYPOINTS_FILE_SUFFIX = "-wpts";
public static final String WAYPOINTS_FILE_SUFFIX_AND_EXTENSION = WAYPOINTS_FILE_SUFFIX + GPX_FILE_EXTENSION;
@@ -101,7 +102,7 @@ public class GPXImporter {
// Google search says: there is no solution for this problem
// Gmail doesn't work at all, see #967
if (mimeType == null) {
- if (StringUtils.endsWithIgnoreCase(uri.getPath(), GPX_FILE_EXTENSION)) {
+ if (StringUtils.endsWithIgnoreCase(uri.getPath(), GPX_FILE_EXTENSION) || StringUtils.endsWithIgnoreCase(uri.getPath(), LOC_FILE_EXTENSION)) {
mimeType = "application/xml";
} else {
// if we can't determine a better type, default to zip import
@@ -112,7 +113,11 @@ public class GPXImporter {
Log.i("importGPX: " + uri + ", mimetype=" + mimeType);
if (GPX_MIME_TYPES.contains(mimeType)) {
- new ImportGpxAttachmentThread(uri, contentResolver, listId, importStepHandler, progressHandler).start();
+ if (StringUtils.endsWithIgnoreCase(uri.getPath(), LOC_FILE_EXTENSION)) {
+ new ImportLocAttachmentThread(uri, contentResolver, listId, importStepHandler, progressHandler).start();
+ } else {
+ new ImportGpxAttachmentThread(uri, contentResolver, listId, importStepHandler, progressHandler).start();
+ }
} else if (ZIP_MIME_TYPES.contains(mimeType)) {
new ImportGpxZipAttachmentThread(uri, contentResolver, listId, importStepHandler, progressHandler).start();
} else {
@@ -207,6 +212,30 @@ public class GPXImporter {
}
}
+ static class ImportLocAttachmentThread extends ImportThread {
+ private final Uri uri;
+ private ContentResolver contentResolver;
+
+ public ImportLocAttachmentThread(Uri uri, ContentResolver contentResolver, int listId, Handler importStepHandler, CancellableHandler progressHandler) {
+ super(listId, importStepHandler, progressHandler);
+ this.uri = uri;
+ this.contentResolver = contentResolver;
+ }
+
+ @Override
+ protected Collection<Geocache> doImport() throws IOException, ParserException {
+ Log.i("Import LOC from uri: " + uri);
+ importStepHandler.sendMessage(importStepHandler.obtainMessage(IMPORT_STEP_READ_FILE, R.string.gpx_import_loading_caches, -1));
+ InputStream is = contentResolver.openInputStream(uri);
+ LocParser parser = new LocParser(listId);
+ try {
+ return parser.parse(is, progressHandler);
+ } finally {
+ is.close();
+ }
+ }
+ }
+
static abstract class ImportGpxThread extends ImportThread {
protected ImportGpxThread(int listId, Handler importStepHandler, CancellableHandler progressHandler) {