aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/export/AbstractExport.java20
-rw-r--r--main/src/cgeo/geocaching/export/Export.java6
-rw-r--r--main/src/cgeo/geocaching/export/ExportFactory.java52
-rw-r--r--main/src/cgeo/geocaching/export/FieldnoteExport.java4
-rw-r--r--main/src/cgeo/geocaching/export/GpxExport.java2
5 files changed, 42 insertions, 42 deletions
diff --git a/main/src/cgeo/geocaching/export/AbstractExport.java b/main/src/cgeo/geocaching/export/AbstractExport.java
index c5bf3c0..85b060b 100644
--- a/main/src/cgeo/geocaching/export/AbstractExport.java
+++ b/main/src/cgeo/geocaching/export/AbstractExport.java
@@ -2,8 +2,8 @@ package cgeo.geocaching.export;
import cgeo.geocaching.cgeoapplication;
-public abstract class AbstractExport implements Export {
- private String name;
+abstract class AbstractExport implements Export {
+ private final String name;
protected AbstractExport(final String name) {
this.name = name;
@@ -14,13 +14,19 @@ public abstract class AbstractExport implements Export {
}
/**
- * Generates a localized string from a ressource id.
+ * Generates a localized string from a resource id.
*
- * @param ressourceId
- * the ressource id of the string
+ * @param resourceId
+ * the resource id of the string
* @return localized string
*/
- protected static String getString(int ressourceId) {
- return cgeoapplication.getInstance().getString(ressourceId);
+ protected static String getString(int resourceId) {
+ return cgeoapplication.getInstance().getString(resourceId);
+ }
+
+ @Override
+ public String toString() {
+ // used in the array adapter of the dialog showing the exports
+ return getName();
}
}
diff --git a/main/src/cgeo/geocaching/export/Export.java b/main/src/cgeo/geocaching/export/Export.java
index 700c752..7a2b075 100644
--- a/main/src/cgeo/geocaching/export/Export.java
+++ b/main/src/cgeo/geocaching/export/Export.java
@@ -7,12 +7,12 @@ import android.app.Activity;
import java.util.List;
/**
- * Represent an exporter to export a {@link List} of {@link cgCache} to various formats.
+ * Represents an exporter to export a {@link List} of {@link cgCache} to various formats.
*/
-public interface Export {
+interface Export {
/**
* Export a {@link List} of {@link cgCache} to various formats.
- *
+ *
* @param caches
* The {@link List} of {@link cgCache} to be exported
* @param activity
diff --git a/main/src/cgeo/geocaching/export/ExportFactory.java b/main/src/cgeo/geocaching/export/ExportFactory.java
index dd3a6f4..c4fdf36 100644
--- a/main/src/cgeo/geocaching/export/ExportFactory.java
+++ b/main/src/cgeo/geocaching/export/ExportFactory.java
@@ -2,33 +2,32 @@ package cgeo.geocaching.export;
import cgeo.geocaching.R;
import cgeo.geocaching.cgCache;
+import cgeo.geocaching.utils.Log;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
-import android.view.View;
-import android.view.ViewGroup;
import android.widget.ArrayAdapter;
-import android.widget.TextView;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
/**
* Factory to create a dialog with all available exporters.
*/
-public class ExportFactory {
+public abstract class ExportFactory {
+
/**
- * Contains instances of all available exporters.
+ * Contains instances of all available exporter classes.
*/
- public enum Exporters {
- FIELDNOTES(new FieldnoteExport()),
- GPX(new GpxExport());
-
- Exporters(Export exporter) {
- this.exporter = exporter;
- }
+ private static final List<Class<? extends Export>> exporterClasses;
- public final Export exporter;
+ static {
+ final ArrayList<Class<? extends Export>> temp = new ArrayList<Class<? extends Export>>();
+ temp.add(FieldnoteExport.class);
+ temp.add(GpxExport.class);
+ exporterClasses = Collections.unmodifiableList(temp);
}
/**
@@ -43,30 +42,25 @@ public class ExportFactory {
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(R.string.export).setIcon(android.R.drawable.ic_menu_share);
- final ArrayAdapter<Exporters> adapter = new ArrayAdapter<Exporters>(activity, android.R.layout.select_dialog_item, Exporters.values()) {
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- TextView textView = (TextView) super.getView(position, convertView, parent);
- textView.setText(getItem(position).exporter.getName());
- return textView;
+ 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);
}
+ }
- @Override
- public View getDropDownView(int position, View convertView, ViewGroup parent) {
- TextView textView = (TextView) super.getDropDownView(position, convertView, parent);
- textView.setText(getItem(position).exporter.getName());
- return textView;
- }
- };
+ final ArrayAdapter<Export> adapter = new ArrayAdapter<Export>(activity, android.R.layout.select_dialog_item, export);
adapter.setDropDownViewResource(android.R.layout.select_dialog_item);
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
- Exporters selectedItem = adapter.getItem(item);
- selectedItem.exporter.export(caches, activity);
+ 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 9e6ae1e..f9f13e3 100644
--- a/main/src/cgeo/geocaching/export/FieldnoteExport.java
+++ b/main/src/cgeo/geocaching/export/FieldnoteExport.java
@@ -39,11 +39,11 @@ import java.util.Map;
* Field Notes are simple plain text files, but poorly documented. Syntax:<br>
* <code>GCxxxxx,yyyy-mm-ddThh:mm:ssZ,Found it,"logtext"</code>
*/
-public class FieldnoteExport extends AbstractExport {
+class FieldnoteExport extends AbstractExport {
private static final File exportLocation = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/field-notes");
private static final SimpleDateFormat fieldNoteDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
- public FieldnoteExport() {
+ protected FieldnoteExport() {
super(getString(R.string.export_fieldnotes));
}
diff --git a/main/src/cgeo/geocaching/export/GpxExport.java b/main/src/cgeo/geocaching/export/GpxExport.java
index da46ab4..bebbed8 100644
--- a/main/src/cgeo/geocaching/export/GpxExport.java
+++ b/main/src/cgeo/geocaching/export/GpxExport.java
@@ -28,7 +28,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
-public class GpxExport extends AbstractExport {
+class GpxExport extends AbstractExport {
private static final File exportLocation = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/gpx-export");
private static final SimpleDateFormat dateFormatZ = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");