diff options
author | Bananeweizen <Bananeweizen@gmx.de> | 2012-06-17 00:32:55 -0700 |
---|---|---|
committer | Bananeweizen <Bananeweizen@gmx.de> | 2012-06-17 00:32:55 -0700 |
commit | 0b4e82013287e8001f1a523fd0cf03d1f704f9a5 (patch) | |
tree | 64bad43e6ca598ad8db0f6a5f3c3ac468c179eda /main/src/cgeo | |
parent | 311266e7833c575895378bfc7c647c83fc7fbd51 (diff) | |
parent | b08b83527cdb10fa8b54acbb1e7295c6950f91bd (diff) | |
download | cgeo-0b4e82013287e8001f1a523fd0cf03d1f704f9a5.zip cgeo-0b4e82013287e8001f1a523fd0cf03d1f704f9a5.tar.gz cgeo-0b4e82013287e8001f1a523fd0cf03d1f704f9a5.tar.bz2 |
Merge pull request #1571 from triakcz/bluetooth_gpx_sharing
GPX export sharing menu after successful export
Diffstat (limited to 'main/src/cgeo')
-rw-r--r-- | main/src/cgeo/geocaching/Settings.java | 21 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/SettingsActivity.java | 1 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/export/GpxExport.java | 58 |
3 files changed, 74 insertions, 6 deletions
diff --git a/main/src/cgeo/geocaching/Settings.java b/main/src/cgeo/geocaching/Settings.java index 70d6851..e610844 100644 --- a/main/src/cgeo/geocaching/Settings.java +++ b/main/src/cgeo/geocaching/Settings.java @@ -91,6 +91,7 @@ public final class Settings { private static final String KEY_SETTINGS_VERSION = "settingsversion"; private static final String KEY_DB_ON_SDCARD = "dbonsdcard"; private static final String KEY_LAST_TRACKABLE_ACTION = "trackableaction"; + private static final String KEY_SHARE_AFTER_EXPORT = "shareafterexport"; private final static int unitsMetric = 1; @@ -199,7 +200,7 @@ public final class Settings { e.putBoolean(KEY_HIDE_LIVE_MAP_HINT, old.getInt(KEY_HIDE_LIVE_MAP_HINT, 0) != 0); e.putInt(KEY_LIVE_MAP_HINT_SHOW_COUNT, old.getInt(KEY_LIVE_MAP_HINT_SHOW_COUNT, 0)); - e.putInt(KEY_SETTINGS_VERSION, 1) ; // mark migrated + e.putInt(KEY_SETTINGS_VERSION, 1); // mark migrated e.commit(); } } @@ -1089,7 +1090,6 @@ public final class Settings { }); } - public static boolean isDebug() { return Log.isDebug(); } @@ -1097,7 +1097,8 @@ public final class Settings { public static void setDebug(final boolean debug) { editSharedSettings(new PrefRunnable() { - @Override public void edit(Editor edit) { + @Override + public void edit(Editor edit) { edit.putBoolean(KEY_DEBUG, debug); } }); @@ -1138,7 +1139,6 @@ public final class Settings { public static void setDbOnSDCard(final boolean dbOnSDCard) { editSharedSettings(new PrefRunnable() { - @Override public void edit(Editor edit) { edit.putBoolean(KEY_DB_ON_SDCARD, dbOnSDCard); @@ -1146,6 +1146,15 @@ public final class Settings { }); } + public static void setShareAfterExport(final boolean shareAfterExport) { + editSharedSettings(new PrefRunnable() { + @Override + public void edit(Editor edit) { + edit.putBoolean(KEY_SHARE_AFTER_EXPORT, shareAfterExport); + } + }); + } + public static int getTrackableAction() { return sharedPrefs.getInt(KEY_LAST_TRACKABLE_ACTION, LogType.RETRIEVED_IT.id); } @@ -1158,6 +1167,10 @@ public final class Settings { edit.putInt(KEY_LAST_TRACKABLE_ACTION, trackableAction); } }); + } + + public static boolean getShareAfterExport() { + return sharedPrefs.getBoolean(KEY_SHARE_AFTER_EXPORT, true); } public static String getPreferencesName() { diff --git a/main/src/cgeo/geocaching/SettingsActivity.java b/main/src/cgeo/geocaching/SettingsActivity.java index d9aaf37..d70b300 100644 --- a/main/src/cgeo/geocaching/SettingsActivity.java +++ b/main/src/cgeo/geocaching/SettingsActivity.java @@ -597,6 +597,7 @@ public class SettingsActivity extends AbstractActivity { textView.setText(getItem(position).app.getName()); return textView; } + @Override public View getDropDownView(int position, View convertView, ViewGroup parent) { TextView textView = (TextView) super.getDropDownView(position, convertView, parent); diff --git a/main/src/cgeo/geocaching/export/GpxExport.java b/main/src/cgeo/geocaching/export/GpxExport.java index afae7ae..2a3b321 100644 --- a/main/src/cgeo/geocaching/export/GpxExport.java +++ b/main/src/cgeo/geocaching/export/GpxExport.java @@ -2,6 +2,7 @@ package cgeo.geocaching.export; import cgeo.geocaching.LogEntry; import cgeo.geocaching.R; +import cgeo.geocaching.Settings; import cgeo.geocaching.cgCache; import cgeo.geocaching.cgWaypoint; import cgeo.geocaching.cgeoapplication; @@ -16,9 +17,15 @@ import cgeo.geocaching.utils.Log; import org.apache.commons.lang3.StringEscapeUtils; import android.app.Activity; +import android.app.AlertDialog; import android.app.ProgressDialog; +import android.content.Intent; +import android.net.Uri; import android.os.AsyncTask; import android.os.Environment; +import android.view.View; +import android.widget.Button; +import android.widget.CheckBox; import java.io.BufferedWriter; import java.io.File; @@ -39,7 +46,48 @@ class GpxExport extends AbstractExport { @Override public void export(final List<cgCache> caches, final Activity activity) { - new ExportTask(caches, activity).execute((Void) null); + if (null == activity) { + // No activity given, so no user interaction possible. + // Start export with default parameters. + new ExportTask(caches, activity).execute((Void) null); + + } else { + // Show configuration dialog + new ExportOptionsDialog(caches, activity).show(); + } + } + + /** + * A dialog to allow the user to set options for the export. + * + * Currently available option is: opening of share menu after successful export + */ + private class ExportOptionsDialog extends AlertDialog { + public ExportOptionsDialog(final List<cgCache> caches, final Activity activity) { + super(activity); + + View layout = activity.getLayoutInflater().inflate(R.layout.gpx_export_dialog, null); + setView(layout); + + final CheckBox shareOption = (CheckBox) layout.findViewById(R.id.share); + + shareOption.setChecked(Settings.getShareAfterExport()); + + shareOption.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Settings.setShareAfterExport(shareOption.isChecked()); + } + }); + + ((Button) layout.findViewById(R.id.export)).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + dismiss(); + new ExportTask(caches, activity).execute((Void) null); + } + }); + } } private class ExportTask extends AsyncTask<Void, Integer, Boolean> { @@ -88,7 +136,6 @@ class GpxExport extends AbstractExport { gpx.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); gpx.write("<gpx version=\"1.0\" creator=\"c:geo - http://www.cgeo.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.topografix.com/GPX/1/0\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd http://www.groundspeak.com/cache/1/0/1 http://www.groundspeak.com/cache/1/0/1/cache.xsd\">"); - for (int i = 0; i < caches.size(); i++) { // reload the cache. otherwise logs, attributes and other detailed information is not available final cgCache cache = cgeoapplication.getInstance().loadCache(caches.get(i).getGeocode(), LoadFlags.LOAD_ALL_DB_ONLY); @@ -322,6 +369,13 @@ class GpxExport extends AbstractExport { progress.dismiss(); if (result) { ActivityMixin.showToast(activity, getName() + ' ' + getString(R.string.export_exportedto) + ": " + exportFile.toString()); + if (Settings.getShareAfterExport()) { + Intent shareIntent = new Intent(); + shareIntent.setAction(Intent.ACTION_SEND); + shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(exportFile)); + shareIntent.setType("application/xml"); + activity.startActivity(Intent.createChooser(shareIntent, getString(R.string.export_gpx_to))); + } } else { ActivityMixin.showToast(activity, getString(R.string.export_failed)); } |