commit
74ef2955f7
1 changed files with 36 additions and 4 deletions
|
@ -230,7 +230,7 @@ public class ImportHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
private void handleFavouritesImport(final Uri gpxFile, final String fileName, final boolean save, final boolean useImportDir, final boolean forceImportFavourites) {
|
private void handleFavouritesImport(final Uri fileUri, final String fileName, final boolean save, final boolean useImportDir, final boolean forceImportFavourites) {
|
||||||
new AsyncTask<Void, Void, GPXFile>() {
|
new AsyncTask<Void, Void, GPXFile>() {
|
||||||
ProgressDialog progress = null;
|
ProgressDialog progress = null;
|
||||||
|
|
||||||
|
@ -242,12 +242,39 @@ public class ImportHelper {
|
||||||
@Override
|
@Override
|
||||||
protected GPXFile doInBackground(Void... nothing) {
|
protected GPXFile doInBackground(Void... nothing) {
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
|
ZipInputStream zis = null;
|
||||||
try {
|
try {
|
||||||
final ParcelFileDescriptor pFD = app.getContentResolver().openFileDescriptor(gpxFile, "r");
|
final ParcelFileDescriptor pFD = app.getContentResolver().openFileDescriptor(fileUri, "r");
|
||||||
|
|
||||||
if (pFD != null) {
|
if (pFD != null) {
|
||||||
is = new FileInputStream(pFD.getFileDescriptor());
|
is = new FileInputStream(pFD.getFileDescriptor());
|
||||||
return GPXUtilities.loadGPXFile(is);
|
|
||||||
|
if (fileName != null && fileName.endsWith(KML_SUFFIX)) {
|
||||||
|
final String result = Kml2Gpx.toGpx(is);
|
||||||
|
if (result != null) {
|
||||||
|
try {
|
||||||
|
return GPXUtilities.loadGPXFile(new ByteArrayInputStream(result.getBytes("UTF-8")));
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (fileName != null && fileName.endsWith(KMZ_SUFFIX)) {
|
||||||
|
try {
|
||||||
|
zis = new ZipInputStream(is);
|
||||||
|
zis.getNextEntry();
|
||||||
|
final String result = Kml2Gpx.toGpx(zis);
|
||||||
|
if (result != null) {
|
||||||
|
try {
|
||||||
|
return GPXUtilities.loadGPXFile(new ByteArrayInputStream(result.getBytes("UTF-8")));
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return GPXUtilities.loadGPXFile(is);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
//
|
//
|
||||||
|
@ -256,6 +283,10 @@ public class ImportHelper {
|
||||||
is.close();
|
is.close();
|
||||||
} catch (IOException ignore) {
|
} catch (IOException ignore) {
|
||||||
}
|
}
|
||||||
|
if (zis != null) try {
|
||||||
|
zis.close();
|
||||||
|
} catch (IOException ignore) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -265,6 +296,7 @@ public class ImportHelper {
|
||||||
if (isActivityNotDestroyed(activity)) {
|
if (isActivityNotDestroyed(activity)) {
|
||||||
progress.dismiss();
|
progress.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
importFavourites(result, fileName, save, useImportDir, forceImportFavourites);
|
importFavourites(result, fileName, save, useImportDir, forceImportFavourites);
|
||||||
}
|
}
|
||||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
|
Loading…
Reference in a new issue