aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarsten Priegnitz <koem@petoria.de>2011-09-12 20:23:54 +0200
committerKarsten Priegnitz <koem@petoria.de>2011-09-12 20:23:54 +0200
commit1e358c97b4a01912e00883059f93d9c386232aca (patch)
tree3e42fe9a3f2caa5880ead39989bc38d0640e15db
parent1df6046cf12ab2966c8f8530a041e6e105b58ea3 (diff)
downloadcgeo-1e358c97b4a01912e00883059f93d9c386232aca.zip
cgeo-1e358c97b4a01912e00883059f93d9c386232aca.tar.gz
cgeo-1e358c97b4a01912e00883059f93d9c386232aca.tar.bz2
broke up dependency from enums to Locus-API-Constants as suggested by samualtardieu
-rw-r--r--.classpath1
-rw-r--r--src/cgeo/geocaching/apps/AbstractLocusApp.java82
-rwxr-xr-xsrc/cgeo/geocaching/apps/LocusDataStorageProvider.java4
-rwxr-xr-xsrc/cgeo/geocaching/enumerations/CacheSize.java35
-rwxr-xr-xsrc/cgeo/geocaching/enumerations/CacheType.java50
-rwxr-xr-xsrc/cgeo/geocaching/enumerations/WaypointType.java35
6 files changed, 128 insertions, 79 deletions
diff --git a/.classpath b/.classpath
index d308698..bcc6806 100644
--- a/.classpath
+++ b/.classpath
@@ -3,6 +3,7 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="lib" path="libs/locus-api-4.0.jar"/>
<classpathentry kind="lib" path="libs/mapsforge-map-0.2.4.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/src/cgeo/geocaching/apps/AbstractLocusApp.java b/src/cgeo/geocaching/apps/AbstractLocusApp.java
index 1b21b8e..3424558 100644
--- a/src/cgeo/geocaching/apps/AbstractLocusApp.java
+++ b/src/cgeo/geocaching/apps/AbstractLocusApp.java
@@ -24,6 +24,7 @@ import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.WaypointType;
/**
+ * for the Locus API:
* @see http://forum.asamm.cz/viewtopic.php?f=29&t=767
*/
public abstract class AbstractLocusApp extends AbstractApp {
@@ -108,27 +109,27 @@ public abstract class AbstractLocusApp extends AbstractApp {
pg.name = cache.name;
pg.placedBy = cache.owner;
if (cache.hidden != null) pg.hidden = ISO8601DATE.format(cache.hidden.getTime());
- CacheType ct = CacheType.findByCgeoId(cache.type);
- if (ct != null && ct.locusId != CacheType.NO_LOCUS_ID) pg.type = ct.locusId;
- CacheSize cs = CacheSize.findByCgeoId(cache.size);
- if (cs != null) pg.container = cs.locusId;
+ int locusId = toLocusId(CacheType.FIND_BY_CGEOID.get(cache.type));
+ if (locusId != NO_LOCUS_ID) pg.type = locusId;
+ locusId = toLocusId(CacheSize.FIND_BY_CGEOID.get(cache.size));
+ if (locusId != NO_LOCUS_ID) pg.container = locusId;
if (cache.difficulty != null) pg.difficulty = cache.difficulty;
if (cache.terrain != null) pg.terrain = cache.terrain;
pg.found = cache.found;
- if (withWaypoints && cache.waypoints != null) {
- pg.waypoints = new ArrayList<PointGeocachingDataWaypoint>();
- for (cgWaypoint waypoint : cache.waypoints) {
- if (waypoint == null || waypoint.coords == null) continue;
- PointGeocachingDataWaypoint wp = new PointGeocachingDataWaypoint();
- wp.code = waypoint.geocode;
- wp.name = waypoint.name;
- WaypointType wt = WaypointType.findByCgeoId(waypoint.type);
- if (wt != null) wp.type = wt.locusId;
- wp.lat = waypoint.coords.getLatitude();
- wp.lon = waypoint.coords.getLongitude();
- pg.waypoints.add(wp);
- }
+ if (withWaypoints && cache.waypoints != null) {
+ pg.waypoints = new ArrayList<PointGeocachingDataWaypoint>();
+ for (cgWaypoint waypoint : cache.waypoints) {
+ if (waypoint == null || waypoint.coords == null) continue;
+ PointGeocachingDataWaypoint wp = new PointGeocachingDataWaypoint();
+ wp.code = waypoint.geocode;
+ wp.name = waypoint.name;
+ String locusWpId = toLocusId(WaypointType.FIND_BY_CGEOID.get(waypoint.type));
+ if (locusWpId != null) wp.type = locusWpId;
+ wp.lat = waypoint.coords.getLatitude();
+ wp.lon = waypoint.coords.getLongitude();
+ pg.waypoints.add(wp);
+ }
}
// Other properties of caches, not used yet. When there are many caches to be displayed
@@ -164,4 +165,51 @@ public abstract class AbstractLocusApp extends AbstractApp {
return p;
}
+
+ private static final int NO_LOCUS_ID = -1;
+
+ private static int toLocusId(final CacheType ct) {
+ switch (ct) {
+ case TRADITIONAL: return PointGeocachingData.CACHE_TYPE_TRADITIONAL;
+ case MULTI: return PointGeocachingData.CACHE_TYPE_MULTI;
+ case MYSTERY: return PointGeocachingData.CACHE_TYPE_MYSTERY;
+ case LETTERBOX: return PointGeocachingData.CACHE_TYPE_LETTERBOX;
+ case EVENT: return PointGeocachingData.CACHE_TYPE_EVENT;
+ case MEGA_EVENT: return PointGeocachingData.CACHE_TYPE_MEGA_EVENT;
+ case EARTH: return PointGeocachingData.CACHE_TYPE_EARTH;
+ case CITO: return PointGeocachingData.CACHE_TYPE_CACHE_IN_TRASH_OUT;
+ case WEBCAM: return PointGeocachingData.CACHE_TYPE_WEBCAM;
+ case VIRTUAL: return PointGeocachingData.CACHE_TYPE_VIRTUAL;
+ case WHERIGO: return PointGeocachingData.CACHE_TYPE_WHERIGO;
+ case PROJECT_APE: return PointGeocachingData.CACHE_TYPE_PROJECT_APE;
+ case GPS_EXHIBIT: return PointGeocachingData.CACHE_TYPE_GPS_ADVENTURE;
+ default: return NO_LOCUS_ID;
+ }
+ }
+
+ private static int toLocusId(final CacheSize cs) {
+ switch (cs) {
+ case MICRO: return PointGeocachingData.CACHE_SIZE_MICRO;
+ case SMALL: return PointGeocachingData.CACHE_SIZE_SMALL;
+ case REGULAR: return PointGeocachingData.CACHE_SIZE_REGULAR;
+ case LARGE: return PointGeocachingData.CACHE_SIZE_LARGE;
+ case NOT_CHOSEN: return PointGeocachingData.CACHE_SIZE_NOT_CHOSEN;
+ case OTHER: return PointGeocachingData.CACHE_SIZE_OTHER;
+ default: return NO_LOCUS_ID;
+ }
+ }
+
+ private static String toLocusId(final WaypointType wt) {
+ switch (wt) {
+ case FLAG: return PointGeocachingData.CACHE_WAYPOINT_TYPE_FINAL;
+ case OWN: return PointGeocachingData.CACHE_WAYPOINT_TYPE_STAGES;
+ case PKG: return PointGeocachingData.CACHE_WAYPOINT_TYPE_PARKING;
+ case PUZZLE: return PointGeocachingData.CACHE_WAYPOINT_TYPE_QUESTION;
+ case STAGE: return PointGeocachingData.CACHE_WAYPOINT_TYPE_STAGES;
+ case TRAILHEAD: return PointGeocachingData.CACHE_WAYPOINT_TYPE_TRAILHEAD;
+ case WAYPOINT: return PointGeocachingData.CACHE_WAYPOINT_TYPE_STAGES;
+ default: return null;
+ }
+ }
+
}
diff --git a/src/cgeo/geocaching/apps/LocusDataStorageProvider.java b/src/cgeo/geocaching/apps/LocusDataStorageProvider.java
index 8da7160..4b6a91f 100755
--- a/src/cgeo/geocaching/apps/LocusDataStorageProvider.java
+++ b/src/cgeo/geocaching/apps/LocusDataStorageProvider.java
@@ -11,9 +11,11 @@ import android.database.Cursor;
import android.net.Uri;
import android.os.Parcel;
+/**
+ * code provided by menion - developer of Locus
+ */
public class LocusDataStorageProvider extends ContentProvider {
-// private final static String TAG = "DataStorageProvider";
@Override
public Cursor query(Uri aUri, String[] aProjection, String aSelection,
diff --git a/src/cgeo/geocaching/enumerations/CacheSize.java b/src/cgeo/geocaching/enumerations/CacheSize.java
index 1d0577d..f045c65 100755
--- a/src/cgeo/geocaching/enumerations/CacheSize.java
+++ b/src/cgeo/geocaching/enumerations/CacheSize.java
@@ -1,6 +1,8 @@
package cgeo.geocaching.enumerations;
-import menion.android.locus.addon.publiclib.geoData.PointGeocachingData;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
/**
* Enum listing cache sizes
@@ -8,29 +10,28 @@ import menion.android.locus.addon.publiclib.geoData.PointGeocachingData;
* @author koem
*/
public enum CacheSize {
- MICRO ("micro", 1, PointGeocachingData.CACHE_SIZE_MICRO),
- SMALL ("small", 2, PointGeocachingData.CACHE_SIZE_SMALL),
- REGULAR ("regular", 3, PointGeocachingData.CACHE_SIZE_REGULAR),
- LARGE ("large", 4, PointGeocachingData.CACHE_SIZE_LARGE),
- NOT_CHOSEN ("not chosen", 0, PointGeocachingData.CACHE_SIZE_NOT_CHOSEN),
- OTHER ("other", 0, PointGeocachingData.CACHE_SIZE_OTHER);
-
+ MICRO ("micro", 1),
+ SMALL ("small", 2),
+ REGULAR ("regular", 3),
+ LARGE ("large", 4),
+ NOT_CHOSEN ("not chosen", 0),
+ OTHER ("other", 0);
+
public final String cgeoId;
public final int comparable;
- public final int locusId;
- private CacheSize(String cgeoId, int comparable, int locusId) {
+ private CacheSize(String cgeoId, int comparable) {
this.cgeoId = cgeoId;
this.comparable = comparable;
- this.locusId = locusId;
}
-
- public static CacheSize findByCgeoId(String cgeoId) {
- if (cgeoId == null) return null;
- for (CacheSize cs : CacheSize.values()) {
- if (cs.cgeoId.equals(cgeoId)) return cs;
+
+ final public static Map<String, CacheSize> FIND_BY_CGEOID;
+ static {
+ final HashMap<String, CacheSize> mapping = new HashMap<String, CacheSize>();
+ for (CacheSize cs: values()) {
+ mapping.put(cs.cgeoId, cs);
}
- return null;
+ FIND_BY_CGEOID = Collections.unmodifiableMap(mapping);
}
}
diff --git a/src/cgeo/geocaching/enumerations/CacheType.java b/src/cgeo/geocaching/enumerations/CacheType.java
index 923972b..b3c0e76 100755
--- a/src/cgeo/geocaching/enumerations/CacheType.java
+++ b/src/cgeo/geocaching/enumerations/CacheType.java
@@ -1,6 +1,9 @@
package cgeo.geocaching.enumerations;
-import menion.android.locus.addon.publiclib.geoData.PointGeocachingData;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
import cgeo.geocaching.R;
/**
@@ -9,48 +12,41 @@ import cgeo.geocaching.R;
* @author koem
*/
public enum CacheType {
- TRADITIONAL ("traditional", "traditional cache", "32bc9333-5e52-4957-b0f6-5a2c8fc7b257", R.string.traditional, PointGeocachingData.CACHE_TYPE_TRADITIONAL),
- MULTI ("multi", "multi-cache", "a5f6d0ad-d2f2-4011-8c14-940a9ebf3c74", R.string.multi, PointGeocachingData.CACHE_TYPE_MULTI),
- MYSTERY ("mystery", "unknown cache", "40861821-1835-4e11-b666-8d41064d03fe", R.string.mystery, PointGeocachingData.CACHE_TYPE_MYSTERY),
- LETTERBOX ("letterbox", "letterbox hybrid", "4bdd8fb2-d7bc-453f-a9c5-968563b15d24", R.string.letterbox, PointGeocachingData.CACHE_TYPE_LETTERBOX),
- EVENT ("event", "event cache", "69eb8534-b718-4b35-ae3c-a856a55b0874", R.string.event, PointGeocachingData.CACHE_TYPE_EVENT),
- MEGA_EVENT ("mega", "mega-event cache", "69eb8535-b718-4b35-ae3c-a856a55b0874", R.string.mega, PointGeocachingData.CACHE_TYPE_MEGA_EVENT),
- EARTH ("earth", "earthcache", "c66f5cf3-9523-4549-b8dd-759cd2f18db8", R.string.earth, PointGeocachingData.CACHE_TYPE_EARTH),
- CITO ("cito", "cache in trash out event", "57150806-bc1a-42d6-9cf0-538d171a2d22", R.string.cito, PointGeocachingData.CACHE_TYPE_CACHE_IN_TRASH_OUT),
- WEBCAM ("webcam", "webcam cache", "31d2ae3c-c358-4b5f-8dcd-2185bf472d3d", R.string.webcam, PointGeocachingData.CACHE_TYPE_WEBCAM),
- VIRTUAL ("virtual", "virtual cache", "294d4360-ac86-4c83-84dd-8113ef678d7e", R.string.virtual, PointGeocachingData.CACHE_TYPE_VIRTUAL),
- WHERIGO ("wherigo", "wherigo cache", "0544fa55-772d-4e5c-96a9-36a51ebcf5c9", R.string.wherigo, PointGeocachingData.CACHE_TYPE_WHERIGO),
+ TRADITIONAL ("traditional", "traditional cache", "32bc9333-5e52-4957-b0f6-5a2c8fc7b257", R.string.traditional),
+ MULTI ("multi", "multi-cache", "a5f6d0ad-d2f2-4011-8c14-940a9ebf3c74", R.string.multi),
+ MYSTERY ("mystery", "unknown cache", "40861821-1835-4e11-b666-8d41064d03fe", R.string.mystery),
+ LETTERBOX ("letterbox", "letterbox hybrid", "4bdd8fb2-d7bc-453f-a9c5-968563b15d24", R.string.letterbox),
+ EVENT ("event", "event cache", "69eb8534-b718-4b35-ae3c-a856a55b0874", R.string.event),
+ MEGA_EVENT ("mega", "mega-event cache", "69eb8535-b718-4b35-ae3c-a856a55b0874", R.string.mega),
+ EARTH ("earth", "earthcache", "c66f5cf3-9523-4549-b8dd-759cd2f18db8", R.string.earth),
+ CITO ("cito", "cache in trash out event", "57150806-bc1a-42d6-9cf0-538d171a2d22", R.string.cito),
+ WEBCAM ("webcam", "webcam cache", "31d2ae3c-c358-4b5f-8dcd-2185bf472d3d", R.string.webcam),
+ VIRTUAL ("virtual", "virtual cache", "294d4360-ac86-4c83-84dd-8113ef678d7e", R.string.virtual),
+ WHERIGO ("wherigo", "wherigo cache", "0544fa55-772d-4e5c-96a9-36a51ebcf5c9", R.string.wherigo),
LOSTANDFOUND ("lostfound", "lost & found", "3ea6533d-bb52-42fe-b2d2-79a3424d4728", R.string.lostfound),
- PROJECT_APE ("ape", "project ape cache", "2555690d-b2bc-4b55-b5ac-0cb704c0b768", R.string.ape, PointGeocachingData.CACHE_TYPE_PROJECT_APE),
+ PROJECT_APE ("ape", "project ape cache", "2555690d-b2bc-4b55-b5ac-0cb704c0b768", R.string.ape),
GCHQ ("gchq", "groundspeak hq", "416f2494-dc17-4b6a-9bab-1a29dd292d8c", R.string.gchq),
- GPS_EXHIBIT ("gps", "gps cache exhibit", "72e69af2-7986-4990-afd9-bc16cbbb4ce3", R.string.gps, PointGeocachingData.CACHE_TYPE_GPS_ADVENTURE);
-
- public static final int NO_LOCUS_ID = -1;
+ GPS_EXHIBIT ("gps", "gps cache exhibit", "72e69af2-7986-4990-afd9-bc16cbbb4ce3", R.string.gps);
public final String cgeoId;
public final String pattern;
public final String guid;
public final int stringId;
- public final int locusId;
private CacheType(String cgeoId, String pattern, String guid, int stringId) {
- this(cgeoId, pattern, guid, stringId, NO_LOCUS_ID);
- }
-
- private CacheType(String cgeoId, String pattern, String guid, int stringId, int locusId) {
this.cgeoId = cgeoId;
this.pattern = pattern;
this.guid = guid;
this.stringId = stringId;
- this.locusId = locusId;
}
- public static CacheType findByCgeoId(String cgeoId) {
- if (cgeoId == null) return null;
- for (CacheType ct : CacheType.values()) {
- if (ct.cgeoId.equals(cgeoId)) return ct;
+ public final static Map<String, CacheType> FIND_BY_CGEOID;
+ static {
+ final HashMap<String, CacheType> mapping = new HashMap<String, CacheType>();
+ for (CacheType ct : values()) {
+ mapping.put(ct.cgeoId, ct);
}
- return null;
+ FIND_BY_CGEOID = Collections.unmodifiableMap(mapping);
}
}
diff --git a/src/cgeo/geocaching/enumerations/WaypointType.java b/src/cgeo/geocaching/enumerations/WaypointType.java
index ec442a0..41bf7b8 100755
--- a/src/cgeo/geocaching/enumerations/WaypointType.java
+++ b/src/cgeo/geocaching/enumerations/WaypointType.java
@@ -1,6 +1,8 @@
package cgeo.geocaching.enumerations;
-import menion.android.locus.addon.publiclib.geoData.PointGeocachingData;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
/**
* Enum listing waypoint types
@@ -8,28 +10,27 @@ import menion.android.locus.addon.publiclib.geoData.PointGeocachingData;
* @author koem
*/
public enum WaypointType {
- FLAG ("flag", PointGeocachingData.CACHE_WAYPOINT_TYPE_FINAL),
- OWN ("own", PointGeocachingData.CACHE_WAYPOINT_TYPE_STAGES),
- PKG ("pkg", PointGeocachingData.CACHE_WAYPOINT_TYPE_PARKING),
- PUZZLE ("puzzle", PointGeocachingData.CACHE_WAYPOINT_TYPE_QUESTION),
- STAGE ("stage", PointGeocachingData.CACHE_WAYPOINT_TYPE_STAGES),
- TRAILHEAD ("trailhead", PointGeocachingData.CACHE_WAYPOINT_TYPE_TRAILHEAD),
- WAYPOINT ("waypoint", PointGeocachingData.CACHE_WAYPOINT_TYPE_STAGES);
-
+ FLAG ("flag"),
+ OWN ("own"),
+ PKG ("pkg"),
+ PUZZLE ("puzzle"),
+ STAGE ("stage"),
+ TRAILHEAD ("trailhead"),
+ WAYPOINT ("waypoint");
+
public final String cgeoId;
- public final String locusId;
- private WaypointType(String cgeoId, String locusId) {
+ private WaypointType(String cgeoId) {
this.cgeoId = cgeoId;
- this.locusId = locusId;
}
- public static WaypointType findByCgeoId(String cgeoId) {
- if (cgeoId == null) return null;
- for (WaypointType wt : WaypointType.values()) {
- if (wt.cgeoId.equals(cgeoId)) return wt;
+ public static final Map<String, WaypointType> FIND_BY_CGEOID;
+ static {
+ final HashMap<String, WaypointType> mapping = new HashMap<String, WaypointType>();
+ for (WaypointType wt : values()) {
+ mapping.put(wt.cgeoId, wt);
}
- return null;
+ FIND_BY_CGEOID = Collections.unmodifiableMap(mapping);
}
}