diff options
Diffstat (limited to 'main/src/cgeo/geocaching/export')
| -rw-r--r-- | main/src/cgeo/geocaching/export/ExportFactory.java | 67 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/export/FieldnoteExport.java | 26 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/export/GpxExport.java | 41 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/export/GpxSerializer.java | 6 |
4 files changed, 44 insertions, 96 deletions
diff --git a/main/src/cgeo/geocaching/export/ExportFactory.java b/main/src/cgeo/geocaching/export/ExportFactory.java deleted file mode 100644 index e743eb2..0000000 --- a/main/src/cgeo/geocaching/export/ExportFactory.java +++ /dev/null @@ -1,67 +0,0 @@ -package cgeo.geocaching.export; - -import cgeo.geocaching.Geocache; -import cgeo.geocaching.R; -import cgeo.geocaching.utils.Log; - -import android.app.Activity; -import android.app.AlertDialog; -import android.content.DialogInterface; -import android.widget.ArrayAdapter; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * Factory to create a dialog with all available exporters. - */ -public abstract class ExportFactory { - - /** - * Contains instances of all available exporter classes. - */ - private static final List<Class<? extends Export>> exporterClasses; - - static { - final ArrayList<Class<? extends Export>> temp = new ArrayList<Class<? extends Export>>(); - temp.add(FieldnoteExport.class); - temp.add(GpxExport.class); - exporterClasses = Collections.unmodifiableList(temp); - } - - /** - * Creates a dialog so that the user can select an exporter. - * - * @param caches - * The {@link List} of {@link cgeo.geocaching.Geocache} to be exported - * @param activity - * The {@link Activity} in whose context the dialog should be shown - */ - public static void showExportMenu(final List<Geocache> caches, final Activity activity) { - final AlertDialog.Builder builder = new AlertDialog.Builder(activity); - builder.setTitle(R.string.export).setIcon(R.drawable.ic_menu_share); - - final ArrayList<Export> export = new ArrayList<Export>(); - for (Class<? extends Export> exporterClass : exporterClasses) { - try { - export.add(exporterClass.newInstance()); - } catch (Exception ex) { - Log.e("showExportMenu", ex); - } - } - - final ArrayAdapter<Export> adapter = new ArrayAdapter<Export>(activity, android.R.layout.select_dialog_item, export); - - builder.setAdapter(adapter, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int item) { - dialog.dismiss(); - final Export selectedExport = adapter.getItem(item); - selectedExport.export(caches, activity); - } - }); - - builder.create().show(); - } -}
\ No newline at end of file diff --git a/main/src/cgeo/geocaching/export/FieldnoteExport.java b/main/src/cgeo/geocaching/export/FieldnoteExport.java index 7d3e07e..f6f27c6 100644 --- a/main/src/cgeo/geocaching/export/FieldnoteExport.java +++ b/main/src/cgeo/geocaching/export/FieldnoteExport.java @@ -1,5 +1,7 @@ package cgeo.geocaching.export; +import butterknife.ButterKnife; + import cgeo.geocaching.DataStore; import cgeo.geocaching.Geocache; import cgeo.geocaching.LogEntry; @@ -16,7 +18,10 @@ import cgeo.geocaching.utils.Log; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; +import android.content.Context; import android.content.DialogInterface; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; import android.os.Environment; import android.view.ContextThemeWrapper; import android.view.View; @@ -29,11 +34,11 @@ import java.util.List; * Exports offline logs in the Groundspeak Field Note format. * */ -class FieldnoteExport extends AbstractExport { +public class FieldnoteExport extends AbstractExport { private static final File exportLocation = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/field-notes"); private static int fieldNotesCount = 0; - protected FieldnoteExport() { + public FieldnoteExport() { super(getString(R.string.export_fieldnotes)); } @@ -53,13 +58,18 @@ class FieldnoteExport extends AbstractExport { private Dialog getExportOptionsDialog(final Geocache[] caches, final Activity activity) { final AlertDialog.Builder builder = new AlertDialog.Builder(activity); - // AlertDialog has always dark style, so we have to apply it as well always - final View layout = View.inflate(new ContextThemeWrapper(activity, R.style.dark), R.layout.fieldnote_export_dialog, null); + final Context themedContext; + if (Settings.isLightSkin() && VERSION.SDK_INT < VERSION_CODES.HONEYCOMB) + themedContext = new ContextThemeWrapper(activity, R.style.dark); + else + themedContext = activity; + final View layout = View.inflate(themedContext, R.layout.fieldnote_export_dialog, null); + builder.setView(layout); - final CheckBox uploadOption = (CheckBox) layout.findViewById(R.id.upload); + final CheckBox uploadOption = ButterKnife.findById(layout, R.id.upload); uploadOption.setChecked(Settings.getFieldNoteExportUpload()); - final CheckBox onlyNewOption = (CheckBox) layout.findViewById(R.id.onlynew); + final CheckBox onlyNewOption = ButterKnife.findById(layout, R.id.onlynew); onlyNewOption.setChecked(Settings.getFieldNoteExportOnlyNew()); if (Settings.getFieldnoteExportDate() > 0) { @@ -110,7 +120,7 @@ class FieldnoteExport extends AbstractExport { @Override protected Boolean doInBackgroundInternal(final Geocache[] caches) { // export field notes separately for each connector, so the file can be uploaded to the respective site afterwards - for (IConnector connector : ConnectorFactory.getConnectors()) { + for (final IConnector connector : ConnectorFactory.getConnectors()) { if (connector instanceof FieldNotesCapability) { exportFieldNotes((FieldNotesCapability) connector, caches); } @@ -118,7 +128,7 @@ class FieldnoteExport extends AbstractExport { return true; } - private boolean exportFieldNotes(final FieldNotesCapability connector, Geocache[] caches) { + private boolean exportFieldNotes(final FieldNotesCapability connector, final Geocache[] caches) { final FieldNotes fieldNotes = new FieldNotes(); try { int i = 0; diff --git a/main/src/cgeo/geocaching/export/GpxExport.java b/main/src/cgeo/geocaching/export/GpxExport.java index 08fca0b..61d03bc 100644 --- a/main/src/cgeo/geocaching/export/GpxExport.java +++ b/main/src/cgeo/geocaching/export/GpxExport.java @@ -1,5 +1,7 @@ package cgeo.geocaching.export; +import butterknife.ButterKnife; + import cgeo.geocaching.CgeoApplication; import cgeo.geocaching.Geocache; import cgeo.geocaching.R; @@ -8,15 +10,17 @@ import cgeo.geocaching.settings.Settings; import cgeo.geocaching.utils.AsyncTaskWithProgress; import cgeo.geocaching.utils.FileUtils; import cgeo.geocaching.utils.Log; +import cgeo.geocaching.utils.ShareUtils; import org.apache.commons.lang3.CharEncoding; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; +import android.content.Context; import android.content.DialogInterface; -import android.content.Intent; -import android.net.Uri; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; import android.os.Environment; import android.view.ContextThemeWrapper; import android.view.View; @@ -35,9 +39,9 @@ import java.util.Date; import java.util.List; import java.util.Locale; -class GpxExport extends AbstractExport { +public class GpxExport extends AbstractExport { - protected GpxExport() { + public GpxExport() { super(getString(R.string.export_gpx)); } @@ -58,20 +62,25 @@ class GpxExport extends AbstractExport { private Dialog getExportDialog(final String[] geocodes, final Activity activity) { final AlertDialog.Builder builder = new AlertDialog.Builder(activity); - // AlertDialog has always dark style, so we have to apply it as well always - final View layout = View.inflate(new ContextThemeWrapper(activity, R.style.dark), R.layout.gpx_export_dialog, null); + final Context themedContext; + if (Settings.isLightSkin() && VERSION.SDK_INT < VERSION_CODES.HONEYCOMB) + themedContext = new ContextThemeWrapper(activity, R.style.dark); + else + themedContext = activity; + + final View layout = View.inflate(themedContext, R.layout.gpx_export_dialog, null); builder.setView(layout); - final TextView text = (TextView) layout.findViewById(R.id.info); + final TextView text = ButterKnife.findById(layout, R.id.info); text.setText(getString(R.string.export_gpx_info, Settings.getGpxExportDir())); - final CheckBox shareOption = (CheckBox) layout.findViewById(R.id.share); + final CheckBox shareOption = ButterKnife.findById(layout, R.id.share); shareOption.setChecked(Settings.getShareAfterExport()); shareOption.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View v) { + public void onClick(final View v) { Settings.setShareAfterExport(shareOption.isChecked()); } }); @@ -79,7 +88,7 @@ class GpxExport extends AbstractExport { builder.setPositiveButton(R.string.export, new DialogInterface.OnClickListener() { @Override - public void onClick(DialogInterface dialog, int which) { + public void onClick(final DialogInterface dialog, final int which) { dialog.dismiss(); new ExportTask(activity).execute(geocodes); } @@ -89,7 +98,7 @@ class GpxExport extends AbstractExport { } private static String[] getGeocodes(final List<Geocache> caches) { - final ArrayList<String> allGeocodes = new ArrayList<String>(caches.size()); + final ArrayList<String> allGeocodes = new ArrayList<>(caches.size()); for (final Geocache geocache : caches) { allGeocodes.add(geocache.getGeocode()); } @@ -117,13 +126,13 @@ class GpxExport extends AbstractExport { } @Override - protected File doInBackgroundInternal(String[] geocodes) { + protected File doInBackgroundInternal(final String[] geocodes) { // quick check for being able to write the GPX file if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { return null; } - final List<String> allGeocodes = new ArrayList<String>(Arrays.asList(geocodes)); + final List<String> allGeocodes = new ArrayList<>(Arrays.asList(geocodes)); setMessage(CgeoApplication.getInstance().getResources().getQuantityString(R.plurals.cache_counts, allGeocodes.size(), allGeocodes.size())); @@ -168,11 +177,7 @@ class GpxExport extends AbstractExport { if (exportFile != null) { ActivityMixin.showToast(activity, getName() + ' ' + getString(R.string.export_exportedto) + ": " + exportFile.toString()); if (Settings.getShareAfterExport()) { - final 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))); + ShareUtils.share(activity, exportFile, "application/xml", R.string.export_gpx_to); } } else { ActivityMixin.showToast(activity, getString(R.string.export_failed)); diff --git a/main/src/cgeo/geocaching/export/GpxSerializer.java b/main/src/cgeo/geocaching/export/GpxSerializer.java index b2587aa..b24eb4c 100644 --- a/main/src/cgeo/geocaching/export/GpxSerializer.java +++ b/main/src/cgeo/geocaching/export/GpxSerializer.java @@ -57,7 +57,7 @@ public final class GpxSerializer { public void writeGPX(List<String> allGeocodesIn, Writer writer, final ProgressListener progressListener) throws IOException { // create a copy of the geocode list, as we need to modify it, but it might be immutable - final ArrayList<String> allGeocodes = new ArrayList<String>(allGeocodesIn); + final ArrayList<String> allGeocodes = new ArrayList<>(allGeocodesIn); this.progressListener = progressListener; gpx.setOutput(writer); @@ -184,8 +184,8 @@ public final class GpxSerializer { private void writeWaypoints(final Geocache cache) throws IOException { final List<Waypoint> waypoints = cache.getWaypoints(); - final List<Waypoint> ownWaypoints = new ArrayList<Waypoint>(waypoints.size()); - final List<Waypoint> originWaypoints = new ArrayList<Waypoint>(waypoints.size()); + final List<Waypoint> ownWaypoints = new ArrayList<>(waypoints.size()); + final List<Waypoint> originWaypoints = new ArrayList<>(waypoints.size()); int maxPrefix = 0; for (final Waypoint wp : cache.getWaypoints()) { |
