diff options
Diffstat (limited to 'main/src/cgeo/geocaching/export')
| -rw-r--r-- | main/src/cgeo/geocaching/export/FieldnoteExport.java | 41 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/export/GpxExport.java | 2 |
2 files changed, 19 insertions, 24 deletions
diff --git a/main/src/cgeo/geocaching/export/FieldnoteExport.java b/main/src/cgeo/geocaching/export/FieldnoteExport.java index 6d0364e..65dc291 100644 --- a/main/src/cgeo/geocaching/export/FieldnoteExport.java +++ b/main/src/cgeo/geocaching/export/FieldnoteExport.java @@ -12,7 +12,9 @@ import cgeo.geocaching.network.Network; import cgeo.geocaching.network.Parameters; import cgeo.geocaching.utils.Log; +import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringUtils; +import org.mapsforge.core.IOUtils; import android.app.Activity; import android.app.AlertDialog; @@ -154,32 +156,25 @@ class FieldnoteExport extends AbstractExport { fieldNoteBuffer.append('\n'); - if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { - exportLocation.mkdirs(); + if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { + return false; + } - SimpleDateFormat fileNameDateFormat = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US); - exportFile = new File(exportLocation.toString() + '/' + fileNameDateFormat.format(new Date()) + ".txt"); + exportLocation.mkdirs(); - Writer fw = null; - try { - OutputStream os = new FileOutputStream(exportFile); - fw = new OutputStreamWriter(os, "UTF-16"); - fw.write(fieldNoteBuffer.toString()); - } catch (IOException e) { - Log.e("FieldnoteExport.ExportTask export", e); - return false; - } finally { - if (fw != null) { - try { - fw.close(); - } catch (IOException e) { - Log.e("FieldnoteExport.ExportTask export", e); - return false; - } - } - } - } else { + SimpleDateFormat fileNameDateFormat = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US); + exportFile = new File(exportLocation.toString() + '/' + fileNameDateFormat.format(new Date()) + ".txt"); + + Writer fw = null; + try { + OutputStream os = new FileOutputStream(exportFile); + fw = new OutputStreamWriter(os, CharEncoding.UTF_16); + fw.write(fieldNoteBuffer.toString()); + } catch (IOException e) { + Log.e("FieldnoteExport.ExportTask export", e); return false; + } finally { + IOUtils.closeQuietly(fw); } if (upload) { diff --git a/main/src/cgeo/geocaching/export/GpxExport.java b/main/src/cgeo/geocaching/export/GpxExport.java index b1834b9..3aec114 100644 --- a/main/src/cgeo/geocaching/export/GpxExport.java +++ b/main/src/cgeo/geocaching/export/GpxExport.java @@ -51,7 +51,7 @@ class GpxExport extends AbstractExport { if (null == activity) { // No activity given, so no user interaction possible. // Start export with default parameters. - new ExportTask(caches, activity).execute((Void) null); + new ExportTask(caches, null).execute((Void) null); } else { // Show configuration dialog |
