diff options
Diffstat (limited to 'src')
17 files changed, 1729 insertions, 184 deletions
diff --git a/src/cgeo/geocaching/apps/AbstractLocusApp.java b/src/cgeo/geocaching/apps/AbstractLocusApp.java index 9e30200..31ae291 100644 --- a/src/cgeo/geocaching/apps/AbstractLocusApp.java +++ b/src/cgeo/geocaching/apps/AbstractLocusApp.java @@ -1,42 +1,37 @@ package cgeo.geocaching.apps; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import menion.android.locus.addon.publiclib.DisplayData; +import menion.android.locus.addon.publiclib.LocusUtils; import menion.android.locus.addon.publiclib.geoData.Point; import menion.android.locus.addon.publiclib.geoData.PointGeocachingData; +import menion.android.locus.addon.publiclib.geoData.PointGeocachingDataWaypoint; import menion.android.locus.addon.publiclib.geoData.PointsData; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.location.Location; -import android.net.Uri; import cgeo.geocaching.R; import cgeo.geocaching.cgBase; import cgeo.geocaching.cgCache; import cgeo.geocaching.cgSettings; import cgeo.geocaching.cgWaypoint; +import cgeo.geocaching.enumerations.CacheSize; +import cgeo.geocaching.enumerations.CacheType; public abstract class AbstractLocusApp extends AbstractApp { private static final String INTENT = Intent.ACTION_VIEW; - private final Resources res; protected AbstractLocusApp(final Resources res) { super(res.getString(R.string.caches_map_locus), INTENT); - this.res = res; } @Override - public boolean isInstalled(final Context context) { - final Intent intentTest = new Intent(INTENT); - intentTest.setData(Uri.parse("menion.points:x")); - return isIntentAvailable(context, intentTest); + public boolean isInstalled(Context context) { + return LocusUtils.isLocusAvailable(context); } /** @@ -49,60 +44,34 @@ public abstract class AbstractLocusApp extends AbstractApp { protected void showInLocus(List<? extends Object> objectsToShow, Activity activity) { if (objectsToShow == null || activity == null) return; - // An icon can only be set for a group of Locus-points. For grouping we use a Map. - // As a key we use an IconType object which holds all information to construct and - // distinguish between different icons. -// Map<IconType, PointsData> pointsGroups = new HashMap<IconType, PointsData>(); - -// int gc = 0; // counter for groups of points int pc = 0; // counter for points -PointsData pd = new PointsData("c:geo"); + PointsData pd = new PointsData("c:geo"); for (Object o : objectsToShow) { // get icon and Point -// IconType it = null; Point p = null; -PointGeocachingData pg = new PointGeocachingData(); if (o instanceof cgCache) { cgCache c = (cgCache) o; -// it = new IconType(true, c.type, c.own, c.found, c.disabled); - p = this.getPoint(c); -pg.name=c.name; -pg.available=!c.disabled; -pg.cacheID=c.geocode; -pg.type = (int) (Math.random() * 13); -p.setGeocachingData(pg); + p = this.getPoint(c, activity); } else if (o instanceof cgWaypoint) { cgWaypoint w = (cgWaypoint) o; -// it = new IconType(false, w.type, false, false, false); -// p = this.getPoint(w); + p = this.getPoint(w); } else { continue; // no cache, no waypoint => ignore } if (p == null) continue; -// // get / create corresponding group of points -// PointsData pd = pointsGroups.get(it); -// if (pd == null) { -// pd = new PointsData("c:geo objects " + ++gc); // every pd must have a unique name -// pd.setBitmap(getIcon(it)); -// pointsGroups.put(it, pd); -// } pd.addPoint(p); ++pc; } - if (pc < 1000) { -DisplayData.sendData(activity, pd, false); -// DisplayData.sendData(activity, new ArrayList<PointsData>(pointsGroups.values()), false); + if (pc <= 1000) { + DisplayData.sendData(activity, pd, false); } else { ArrayList<PointsData> data = new ArrayList<PointsData>(); data.add(pd); -DisplayData.sendDataCursor(activity, data, - "content://" + LocusDataStorageProvider.class.getCanonicalName().toLowerCase(), - false); -// DisplayData.sendDataCursor(activity, new ArrayList<PointsData>(pointsGroups.values()), -// "content://" + LocusDataStorageProvider.class.getCanonicalName().toLowerCase(), -// false); + DisplayData.sendDataCursor(activity, data, + "content://" + LocusDataStorageProvider.class.getCanonicalName().toLowerCase(), + false); } } @@ -113,7 +82,7 @@ DisplayData.sendDataCursor(activity, data, * @return null, when the <code>Point</code> could not be constructed * @author koem */ - private Point getPoint(cgCache cache) { + private Point getPoint(cgCache cache, Context context) { if (cache == null) return null; // create one simple point with location @@ -122,13 +91,52 @@ DisplayData.sendDataCursor(activity, data, loc.setLongitude(cache.longitude); Point p = new Point(cache.name, loc); -// p.setDescription("<a href=\"http://coord.info/" +cache.geocode + "\">" -// + cache.geocode + "</a>"); - + PointGeocachingData pg = new PointGeocachingData(); + p.setGeocachingData(pg); + + pg.cacheID = cache.geocode; + pg.available = ! cache.disabled; + pg.archived = cache.archived; + pg.premiumOnly = cache.members; + pg.name = cache.name; + pg.placedBy = cache.owner; + if (cache.hidden != null) pg.hidden = cgBase.formatFullDate(context, cache.hidden.getTime()); + for (CacheType ct : CacheType.values()) { + if (ct.cgeoId.equals(cache.type)) { + if (ct.locusId != CacheType.NO_LOCUS_ID) pg.type = ct.locusId; + break; + } + } + for (CacheSize cs : CacheSize.values()) { + if (cs.cgeoId.equals(cache.size)) { + pg.container = cs.locusId; + break; + } + } + if (cache.difficulty != null) pg.difficulty = cache.difficulty; + if (cache.terrain != null) pg.terrain = cache.terrain; + pg.shortDescription = cache.shortdesc; + pg.longDescription = cache.description; + pg.encodedHints = cache.hint; + if (cache.waypoints != null) { + pg.waypoints = new ArrayList<PointGeocachingDataWaypoint>(); + for (cgWaypoint waypoint : cache.waypoints) { + if (waypoint == null) continue; + PointGeocachingDataWaypoint w = new PointGeocachingDataWaypoint(); + w.code = waypoint.geocode; + w.name = waypoint.name; + w.type = PointGeocachingData.CACHE_WAYPOINT_TYPE_STAGES; + w.lat = waypoint.latitude; + w.lon = waypoint.longitude; + pg.waypoints.add(w); + } + } + pg.found = cache.found; + return p; } - /** + /** * This method constructs a <code>Point</code> for displaying in Locus * * @param waypoint @@ -149,55 +157,4 @@ DisplayData.sendDataCursor(activity, data, return p; } - - /** - * caching mechanism for icons - * - * @author koem - */ - private Bitmap getIcon(IconType it) { - Bitmap icon = iconCache.get(it); - if (icon != null) return icon; - - synchronized(this) { - // load icon - final int iconId = cgBase.getMarkerIcon(it.isCache, it.type, it.own, it.found, - it.disabled); - if (iconId > 0) icon = BitmapFactory.decodeResource(res, iconId); - iconCache.put(it, icon); - return icon; - } - } - - private static Map<IconType, Bitmap> iconCache = new HashMap<IconType, Bitmap>(); - - /** - * class representing a key in the iconCache - * - * @author koem - */ - private static class IconType { - private final boolean isCache; - private final String type; - private final boolean own, found, disabled; - private int hashCode = 0; - public IconType(boolean isCache, String type, boolean own, boolean found, - boolean disabled) { - this.isCache = isCache; - this.type = type; - this.own = own; - this.found = found; - this.disabled = disabled; - } - @Override - public boolean equals(Object o) { - if (! (o instanceof IconType)) return false; - return this.hashCode() == ((IconType) o).hashCode(); - } - @Override - public int hashCode() { - if (hashCode == 0) hashCode = (isCache + type + own + found + disabled).hashCode(); - return hashCode; - } - } } diff --git a/src/cgeo/geocaching/apps/cache/navi/LocusApp.java b/src/cgeo/geocaching/apps/cache/navi/LocusApp.java index 11a5ae3..365701a 100644 --- a/src/cgeo/geocaching/apps/cache/navi/LocusApp.java +++ b/src/cgeo/geocaching/apps/cache/navi/LocusApp.java @@ -1,18 +1,14 @@ package cgeo.geocaching.apps.cache.navi; import java.util.ArrayList; -import java.util.List; import java.util.UUID; -import org.apache.commons.lang3.StringUtils; - import android.app.Activity; import android.content.res.Resources; import cgeo.geocaching.cgCache; import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgWaypoint; import cgeo.geocaching.apps.AbstractLocusApp; -import cgeo.geocaching.utils.CollectionUtils; class LocusApp extends AbstractLocusApp implements NavigationApp { @@ -48,12 +44,12 @@ class LocusApp extends AbstractLocusApp implements NavigationApp { points.add(cache); } - // use only waypoints with coordinates - if (cache.waypoints != null) { - for (cgWaypoint wp : cache.waypoints) { - if (wp.latitude != null && wp.longitude != null) points.add(wp); - } - } +// // use only waypoints with coordinates +// if (cache.waypoints != null) { +// for (cgWaypoint wp : cache.waypoints) { +// if (wp.latitude != null && wp.longitude != null) points.add(wp); +// } +// } } // add waypoint if present diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java index 1287f79..3abd142 100644 --- a/src/cgeo/geocaching/cgBase.java +++ b/src/cgeo/geocaching/cgBase.java @@ -30,9 +30,9 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import java.util.UUID; +import java.util.Map.Entry; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; @@ -70,6 +70,7 @@ import android.text.style.StrikethroughSpan; import android.util.Log; import android.widget.EditText; import cgeo.geocaching.activity.ActivityMixin; +import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.files.LocParser; import cgeo.geocaching.utils.CollectionUtils; @@ -210,75 +211,20 @@ public class cgBase { context = appIn.getBaseContext(); res = appIn.getBaseContext().getResources(); - // cache types - cacheTypes.put("traditional cache", "traditional"); - cacheTypes.put("multi-cache", "multi"); - cacheTypes.put("unknown cache", "mystery"); - cacheTypes.put("letterbox hybrid", "letterbox"); - cacheTypes.put("event cache", "event"); - cacheTypes.put("mega-event cache", "mega"); - cacheTypes.put("earthcache", "earth"); - cacheTypes.put("cache in trash out event", "cito"); - cacheTypes.put("webcam cache", "webcam"); - cacheTypes.put("virtual cache", "virtual"); - cacheTypes.put("wherigo cache", "wherigo"); - cacheTypes.put("lost & found", "lostfound"); - cacheTypes.put("project ape cache", "ape"); - cacheTypes.put("groundspeak hq", "gchq"); - cacheTypes.put("gps cache exhibit", "gps"); - - // cache types inverted - cacheTypesInv.put("traditional", res.getString(R.string.traditional)); - cacheTypesInv.put("multi", res.getString(R.string.multi)); - cacheTypesInv.put("mystery", res.getString(R.string.mystery)); - cacheTypesInv.put("letterbox", res.getString(R.string.letterbox)); - cacheTypesInv.put("event", res.getString(R.string.event)); - cacheTypesInv.put("mega", res.getString(R.string.mega)); - cacheTypesInv.put("earth", res.getString(R.string.earth)); - cacheTypesInv.put("cito", res.getString(R.string.cito)); - cacheTypesInv.put("webcam", res.getString(R.string.webcam)); - cacheTypesInv.put("virtual", res.getString(R.string.virtual)); - cacheTypesInv.put("wherigo", res.getString(R.string.wherigo)); - cacheTypesInv.put("lostfound", res.getString(R.string.lostfound)); - cacheTypesInv.put("ape", res.getString(R.string.ape)); - cacheTypesInv.put("gchq", res.getString(R.string.gchq)); - cacheTypesInv.put("gps", res.getString(R.string.gps)); - - // cache ids - cacheIDs.put("all", "9a79e6ce-3344-409c-bbe9-496530baf758"); // hard-coded also in cgSettings - cacheIDs.put("traditional", "32bc9333-5e52-4957-b0f6-5a2c8fc7b257"); - cacheIDs.put("multi", "a5f6d0ad-d2f2-4011-8c14-940a9ebf3c74"); - cacheIDs.put("mystery", "40861821-1835-4e11-b666-8d41064d03fe"); - cacheIDs.put("letterbox", "4bdd8fb2-d7bc-453f-a9c5-968563b15d24"); - cacheIDs.put("event", "69eb8534-b718-4b35-ae3c-a856a55b0874"); - cacheIDs.put("mega-event", "69eb8535-b718-4b35-ae3c-a856a55b0874"); - cacheIDs.put("earth", "c66f5cf3-9523-4549-b8dd-759cd2f18db8"); - cacheIDs.put("cito", "57150806-bc1a-42d6-9cf0-538d171a2d22"); - cacheIDs.put("webcam", "31d2ae3c-c358-4b5f-8dcd-2185bf472d3d"); - cacheIDs.put("virtual", "294d4360-ac86-4c83-84dd-8113ef678d7e"); - cacheIDs.put("wherigo", "0544fa55-772d-4e5c-96a9-36a51ebcf5c9"); - cacheIDs.put("lostfound", "3ea6533d-bb52-42fe-b2d2-79a3424d4728"); - cacheIDs.put("ape", "2555690d-b2bc-4b55-b5ac-0cb704c0b768"); - cacheIDs.put("gchq", "416f2494-dc17-4b6a-9bab-1a29dd292d8c"); - cacheIDs.put("gps", "72e69af2-7986-4990-afd9-bc16cbbb4ce3"); - - // cache choices - cacheIDsChoices.put(res.getString(R.string.all), cacheIDs.get("all")); - cacheIDsChoices.put(res.getString(R.string.traditional), cacheIDs.get("traditional")); - cacheIDsChoices.put(res.getString(R.string.multi), cacheIDs.get("multi")); - cacheIDsChoices.put(res.getString(R.string.mystery), cacheIDs.get("mystery")); - cacheIDsChoices.put(res.getString(R.string.letterbox), cacheIDs.get("letterbox")); - cacheIDsChoices.put(res.getString(R.string.event), cacheIDs.get("event")); - cacheIDsChoices.put(res.getString(R.string.mega), cacheIDs.get("mega")); - cacheIDsChoices.put(res.getString(R.string.earth), cacheIDs.get("earth")); - cacheIDsChoices.put(res.getString(R.string.cito), cacheIDs.get("cito")); - cacheIDsChoices.put(res.getString(R.string.webcam), cacheIDs.get("webcam")); - cacheIDsChoices.put(res.getString(R.string.virtual), cacheIDs.get("virtual")); - cacheIDsChoices.put(res.getString(R.string.wherigo), cacheIDs.get("whereigo")); - cacheIDsChoices.put(res.getString(R.string.lostfound), cacheIDs.get("lostfound")); - cacheIDsChoices.put(res.getString(R.string.ape), cacheIDs.get("ape")); - cacheIDsChoices.put(res.getString(R.string.gchq), cacheIDs.get("gchq")); - cacheIDsChoices.put(res.getString(R.string.gps), cacheIDs.get("gps")); + // setup cache type mappings + + final String CACHETYPE_ALL_GUID = "9a79e6ce-3344-409c-bbe9-496530baf758"; + + cacheIDs.put("all", CACHETYPE_ALL_GUID); + cacheIDsChoices.put(res.getString(R.string.all), CACHETYPE_ALL_GUID); + + for (CacheType ct : CacheType.values()) { + String l10n = res.getString(ct.stringId); + cacheTypes.put(ct.pattern, ct.cgeoId); + cacheTypesInv.put(ct.cgeoId, l10n); + cacheIDs.put(ct.cgeoId, ct.guid); + cacheIDsChoices.put(l10n, ct.guid); + } // waypoint types waypointTypes.put("flag", res.getString(R.string.wp_final)); @@ -5090,12 +5036,25 @@ public class cgBase { * such as "20 December 2010". The year will always be included, making it suitable * to generate long-lived log entries. * - * @param context a context * @param date milliseconds since the epoch * @return the formatted string */ public String formatFullDate(long date) { - return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR); + return formatFullDate(context, date); + } + + /** + * Generate a date string according to system-wide settings (locale, date format) + * such as "20 December 2010". The year will always be included, making it suitable + * to generate long-lived log entries. + * + * @param context application context + * @param date milliseconds since the epoch + * @return the formatted string + */ + public static String formatFullDate(Context context, long date) { + return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE + | DateUtils.FORMAT_SHOW_YEAR); } /** @@ -5107,7 +5066,8 @@ public class cgBase { * @return the formatted string */ public String formatShortDate(long date) { - return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NUMERIC_DATE); + return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE + | DateUtils.FORMAT_NUMERIC_DATE); } /** diff --git a/src/cgeo/geocaching/enumerations/CacheSize.java b/src/cgeo/geocaching/enumerations/CacheSize.java new file mode 100755 index 0000000..b6b9d34 --- /dev/null +++ b/src/cgeo/geocaching/enumerations/CacheSize.java @@ -0,0 +1,27 @@ +package cgeo.geocaching.enumerations;
+
+import menion.android.locus.addon.publiclib.geoData.PointGeocachingData;
+
+/**
+ * Enum listing cache sizes
+ *
+ * @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);
+
+ public final String cgeoId;
+ public final int comparable;
+ public final int locusId;
+
+ private CacheSize(String cgeoId, int comparable, int locusId) {
+ this.cgeoId = cgeoId;
+ this.comparable = comparable;
+ this.locusId = locusId;
+ }
+}
diff --git a/src/cgeo/geocaching/enumerations/CacheType.java b/src/cgeo/geocaching/enumerations/CacheType.java new file mode 100755 index 0000000..a521c0e --- /dev/null +++ b/src/cgeo/geocaching/enumerations/CacheType.java @@ -0,0 +1,47 @@ +package cgeo.geocaching.enumerations;
+
+import menion.android.locus.addon.publiclib.geoData.PointGeocachingData;
+import cgeo.geocaching.R;
+
+/**
+ * Enum listing all cache types
+ *
+ * @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),
+ 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),
+ 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;
+
+ 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;
+ }
+}
diff --git a/src/menion/android/locus/addon/publiclib/DisplayData.java b/src/menion/android/locus/addon/publiclib/DisplayData.java new file mode 100644 index 0000000..e3f86db --- /dev/null +++ b/src/menion/android/locus/addon/publiclib/DisplayData.java @@ -0,0 +1,109 @@ +package menion.android.locus.addon.publiclib;
+
+import java.util.ArrayList;
+
+import menion.android.locus.addon.publiclib.geoData.PointsData;
+import menion.android.locus.addon.publiclib.utils.DataStorage;
+
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+public class DisplayData {
+
+ private static final String TAG = "TAG";
+
+ /**
+ * Simple way how to send data over intent to Locus. Count that intent in
+ * Android have some size limits so for larger data, use another method
+ * @param context actual context
+ * @param data PointsData object that should be send to Locus
+ * @param callImport wheather import with this data should be called after Locus starts
+ * @return true if success
+ */
+ public static boolean sendData(Context context, PointsData data, boolean callImport) {
+ if (data == null)
+ return false;
+ Intent intent = new Intent();
+ intent.putExtra(LocusConst.EXTRA_POINTS_DATA, data);
+ return sendData(context, intent, callImport);
+ }
+
+ /**
+ * Simple way how to send ArrayList<PointsData> object over intent to Locus. Count that
+ * intent in Android have some size limits so for larger data, use another method
+ * @param context actual context
+ * @param data ArrayList of data that should be send to Locus
+ * @return true if success
+ */
+ public static boolean sendData(Context context, ArrayList<PointsData> data, boolean callImport) {
+ if (data == null)
+ return false;
+ Intent intent = new Intent();
+ intent.putParcelableArrayListExtra(LocusConst.EXTRA_POINTS_DATA_ARRAY, data);
+ return sendData(context, intent, callImport);
+ }
+
+ /**
+ * Way how to send ArrayList<PointsData> object over intent to Locus. Data are
+ * stored in ContentProvider so don't forget to register it in manifest. More in
+ * sample application. This is recommended way how to send huge data to Locus
+ * @param context actual context
+ * @param data ArrayList of data that should be send to Locus
+ * @param callImport wheather import with this data should be called after Locus starts
+ * @return true if success
+ */
+ public static boolean sendDataCursor(Context context, PointsData data, String uri, boolean callImport) {
+ if (data == null)
+ return false;
+ // set data
+ DataStorage.setData(data);
+ Intent intent = new Intent();
+ intent.putExtra(LocusConst.EXTRA_POINTS_CURSOR_URI, uri);
+ return sendData(context, intent, callImport);
+ }
+
+ /**
+ * Way how to send ArrayList<PointsData> object over intent to Locus. Data are
+ * stored in ContentProvider so don't forget to register it in manifest. More in
+ * sample application. This is recommended way how to send huge data to Locus
+ * @param context actual context
+ * @param data ArrayList of data that should be send to Locus
+ * @return true if success
+ */
+ public static boolean sendDataCursor(Context context, ArrayList<PointsData> data,
+ String uri, boolean callImport) {
+ if (data == null)
+ return false;
+ // set data
+ DataStorage.setData(data);
+ Intent intent = new Intent();
+ intent.putExtra(LocusConst.EXTRA_POINTS_CURSOR_URI, uri);
+ return sendData(context, intent, callImport);
+ }
+
+ // private final call to Locus
+ private static boolean sendData(Context context, Intent intent, boolean callImport) {
+ // really exist locus?
+ if (!LocusUtils.isLocusAvailable(context)) {
+ Log.w(TAG, "Locus is not installed");
+ return false;
+ }
+
+ // check intent firstly
+ if (intent == null || (intent.getParcelableArrayListExtra(LocusConst.EXTRA_POINTS_DATA_ARRAY) == null &&
+ intent.getParcelableExtra(LocusConst.EXTRA_POINTS_DATA) == null &&
+ intent.getStringExtra(LocusConst.EXTRA_POINTS_CURSOR_URI) == null)) {
+ Log.w(TAG, "Intent 'null' or not contain any data");
+ return false;
+ }
+
+ intent.putExtra(LocusConst.EXTRA_CALL_IMPORT, callImport);
+
+ // create intent with right calling method
+ intent.setAction(LocusConst.INTENT_DISPLAY_DATA);
+ // finally start activity
+ context.startActivity(intent);
+ return true;
+ }
+}
diff --git a/src/menion/android/locus/addon/publiclib/LocusConst.java b/src/menion/android/locus/addon/publiclib/LocusConst.java new file mode 100644 index 0000000..e96a31f --- /dev/null +++ b/src/menion/android/locus/addon/publiclib/LocusConst.java @@ -0,0 +1,12 @@ +package menion.android.locus.addon.publiclib;
+
+public class LocusConst {
+
+ public static final String INTENT_DISPLAY_DATA = "android.intent.action.LOCUS_PUBLIC_LIB_DATA";
+
+ public static final String EXTRA_POINTS_DATA = "EXTRA_POINTS_DATA";
+ public static final String EXTRA_POINTS_DATA_ARRAY = "EXTRA_POINTS_DATA_ARRAY";
+ public static final String EXTRA_POINTS_CURSOR_URI = "EXTRA_POINTS_CURSOR_URI";
+
+ public static final String EXTRA_CALL_IMPORT = "EXTRA_CALL_IMPORT";
+}
diff --git a/src/menion/android/locus/addon/publiclib/LocusUtils.java b/src/menion/android/locus/addon/publiclib/LocusUtils.java new file mode 100644 index 0000000..45de4bd --- /dev/null +++ b/src/menion/android/locus/addon/publiclib/LocusUtils.java @@ -0,0 +1,137 @@ +package menion.android.locus.addon.publiclib;
+
+import android.content.Context;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+
+/**
+ * Locus Helper class
+ *
+ * @author Menion Asamm
+ * @author Arcao
+ *
+ */
+public class LocusUtils {
+
+ /** Locus Free package name */
+ public static final String LOCUS_FREE_PACKAGE_NAME = "menion.android.locus";
+ /** Locus Pro package name */
+ public static final String LOCUS_PRO_PACKAGE_NAME = "menion.android.locus.pro";
+ /** All Locus package names */
+ public static final String[] LOCUS_PACKAGE_NAMES = new String[] {
+ LOCUS_PRO_PACKAGE_NAME, LOCUS_FREE_PACKAGE_NAME };
+
+ /**
+ * Returns <code>true</code> if Locus Pro or Locus Free is installed.
+ *
+ * @param context
+ * actual {@link Context}
+ * @return true or false
+ */
+ public static boolean isLocusAvailable(Context context) {
+ return getLocusPackageInfo(context) != null;
+ }
+
+ /**
+ * Returns {@link PackageInfo} with information about Locus or null if Locus
+ * is not installed.
+ *
+ * @param context
+ * actual {@link Context}
+ * @return instance of PackageInfo object
+ */
+ public static PackageInfo getLocusPackageInfo(Context context) {
+ PackageInfo info = null;
+ for (String p : LOCUS_PACKAGE_NAMES) {
+ try {
+ info = context.getPackageManager().getPackageInfo(p, 0);
+ break;
+ } catch (PackageManager.NameNotFoundException e) {
+ }
+ }
+
+ return info;
+ }
+
+ /**
+ * Returns Locus version, e.g. <code>"1.9.5.1"</code>. If Locus is not
+ * installed returns <code>null</code>.
+ *
+ * @param context
+ * actual {@link Context}
+ * @return version
+ */
+ public static String getLocusVersion(Context context) {
+ PackageInfo info = getLocusPackageInfo(context);
+
+ if (info == null)
+ return null;
+
+ return info.versionName;
+ }
+
+ /**
+ * Returns Locus version code, e.g. <code>99</code>. If Locus is not
+ * installed returns <code>-1</code>.
+ *
+ * @param context
+ * actual {@link Context}
+ * @return version code
+ */
+ public static int getLocusVersionCode(Context context) {
+ PackageInfo info = getLocusPackageInfo(context);
+
+ if (info == null)
+ return -1;
+
+ return info.versionCode;
+ }
+
+ /**
+ * Returns <code>true</code> if Locus Pro is installed.
+ *
+ * @param context
+ * actual {@link Context}
+ * @return true or false
+ */
+ public static boolean isLocusProInstalled(Context context) {
+ try {
+ context.getPackageManager().getPackageInfo(LOCUS_PRO_PACKAGE_NAME,
+ 0);
+ return true;
+ } catch (PackageManager.NameNotFoundException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Returns a package name of Locus (Pro). If Locus is not installed returns
+ * null.
+ *
+ * @param context
+ * actual {@link Context}
+ * @return package name
+ */
+ public static String getLocusPackageName(Context context) {
+ PackageInfo info = getLocusPackageInfo(context);
+ if (info == null)
+ return null;
+ return info.packageName;
+ }
+
+ /**
+ * Returns a package name like {@link #getLocusPackageName(Context)} but if
+ * Locus is not installed returns a default package name constant
+ * {@link #LOCUS_FREE_PACKAGE_NAME}.
+ *
+ * @param context
+ * actual {@link Context}
+ * @return package name
+ */
+ public static String getLocusDefaultPackageName(Context context) {
+ String name = getLocusPackageName(context);
+ if (name == null)
+ return LOCUS_FREE_PACKAGE_NAME;
+ return name;
+ }
+}
diff --git a/src/menion/android/locus/addon/publiclib/geoData/Point.java b/src/menion/android/locus/addon/publiclib/geoData/Point.java new file mode 100644 index 0000000..e0f0f63 --- /dev/null +++ b/src/menion/android/locus/addon/publiclib/geoData/Point.java @@ -0,0 +1,146 @@ +package menion.android.locus.addon.publiclib.geoData;
+
+import android.location.Location;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+public class Point implements Parcelable {
+
+ private static final int VERSION = 0;
+
+ /* mName of object */
+ private String mName;
+ /* mDesc of object */
+ private String mDesc;
+ /* mLoc of this point */
+ private Location mLoc;
+ /* extra intent data */
+ private String mExtraData;
+ /* additional geoCaching data */
+ private PointGeocachingData mGeoCachingData;
+
+ public Point(String name, Location loc) {
+ this.mName = name;
+ this.mDesc = null;
+ this.mLoc = loc;
+ this.mExtraData = null;
+ this.mGeoCachingData = null;
+ }
+
+ public String getName() {
+ return mName;
+ }
+
+ public String getDescription() {
+ return mDesc;
+ }
+
+ public void setDescription(String desc) {
+ this.mDesc = desc;
+ }
+
+ public Location getLocation() {
+ return mLoc;
+ }
+
+ public String getExtra() {
+ return mExtraData;
+ }
+
+ /**
+ * Simply allow set callback value on point
+ * @param btnName Name displayed on button
+ * @param packageName this value is used for creating intent that
+ * will be called in callback (for example com.super.application)
+ * @param className the name of the class inside of com.super.application
+ * that implements the component (for example com.super.application.Main)
+ * @param returnDataName String uder which data will be stored. Can be
+ * retrieved by String data = getIntent.getStringExtra("returnData");
+ * @param returnDataValue String uder which data will be stored. Can be
+ * retrieved by String data = getIntent.getStringExtra("returnData");
+ */
+ public void setCallback(String btnName, String packageName, String className,
+ String returnDataName, String returnDataValue) {
+ StringBuffer buff = new StringBuffer();
+ buff.append("intent").append(";");
+ buff.append(btnName).append(";");
+ buff.append(packageName).append(";");
+ buff.append(className).append(";");
+ buff.append(returnDataName).append(";");
+ buff.append(returnDataValue).append(";");
+ this.mExtraData = buff.toString();
+ }
+
+ public PointGeocachingData getGeocachingData() {
+ return mGeoCachingData;
+ }
+
+ public void setGeocachingData(PointGeocachingData gcData) {
+ this.mGeoCachingData = gcData;
+ }
+
+ /****************************/
+ /* PARCELABLE PART */
+ /****************************/
+
+ public static final Parcelable.Creator<Point> CREATOR = new Parcelable.Creator<Point>() {
+ public Point createFromParcel(Parcel in) {
+ return new Point(in);
+ }
+
+ public Point[] newArray(int size) {
+ return new Point[size];
+ }
+ };
+
+ private Point(Parcel in) {
+ switch (in.readInt()) {
+ case 0:
+ // load name
+ mName = in.readString();
+ // load description
+ mDesc = in.readString();
+ // load separate location
+ mLoc = new Location(in.readString());
+ mLoc.setTime(in.readLong());
+ mLoc.setLatitude(in.readDouble());
+ mLoc.setLongitude(in.readDouble());
+ mLoc.setAltitude(in.readDouble());
+ mLoc.setAccuracy(in.readFloat());
+ mLoc.setBearing(in.readFloat());
+ mLoc.setSpeed(in.readFloat());
+ // load extra data
+ mExtraData = in.readString();
+ // load geocaching data
+ mGeoCachingData = in.readParcelable(PointGeocachingData.class.getClassLoader());//PointGeocachingData.CREATOR.createFromParcel(in);
+ break;
+ }
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(VERSION);
+ // write name
+ dest.writeString(mName);
+ // write description
+ dest.writeString(mDesc);
+ // write location as separate values (due to some problems with 'magic number'
+ dest.writeString(mLoc.getProvider());
+ dest.writeLong(mLoc.getTime());
+ dest.writeDouble(mLoc.getLatitude());
+ dest.writeDouble(mLoc.getLongitude());
+ dest.writeDouble(mLoc.getAltitude());
+ dest.writeFloat(mLoc.getAccuracy());
+ dest.writeFloat(mLoc.getBearing());
+ dest.writeFloat(mLoc.getSpeed());
+ // write extra
+ dest.writeString(mExtraData);
+ // write geocaching data
+ dest.writeParcelable(mGeoCachingData, flags);
+ }
+}
diff --git a/src/menion/android/locus/addon/publiclib/geoData/PointGeocachingAttributes.java b/src/menion/android/locus/addon/publiclib/geoData/PointGeocachingAttributes.java new file mode 100644 index 0000000..f734302 --- /dev/null +++ b/src/menion/android/locus/addon/publiclib/geoData/PointGeocachingAttributes.java @@ -0,0 +1,122 @@ +/****************************************************************************
+ *
+ * Copyright (C) 2009-2010 Menion. All rights reserved.
+ *
+ * This file is part of the LocA & SmartMaps software.
+ *
+ * Email menion@asamm.cz for more information.
+ *
+ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ ***************************************************************************/
+package menion.android.locus.addon.publiclib.geoData;
+
+import java.util.Hashtable;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ * @author menion
+ * @since 25.1.2010 2010
+ */
+public class PointGeocachingAttributes implements Parcelable {
+
+ private static final int VERSION = 0;
+
+ public int id;
+
+ public PointGeocachingAttributes() {
+ id = 0;
+ }
+
+ private static Hashtable<String, Integer> attrIds = new Hashtable<String, Integer>();
+ static {
+ attrIds.put("http://www.geocaching.com/images/attributes/dogs", 1);
+ attrIds.put("http://www.geocaching.com/images/attributes/fee", 2);
+ attrIds.put("http://www.geocaching.com/images/attributes/rappelling", 3);
+ attrIds.put("http://www.geocaching.com/images/attributes/boat", 4);
+ attrIds.put("http://www.geocaching.com/images/attributes/scuba", 5);
+ attrIds.put("http://www.geocaching.com/images/attributes/kids", 6);
+ attrIds.put("http://www.geocaching.com/images/attributes/onehour", 7);
+ attrIds.put("http://www.geocaching.com/images/attributes/scenic", 8);
+ attrIds.put("http://www.geocaching.com/images/attributes/hiking", 9);
+ attrIds.put("http://www.geocaching.com/images/attributes/climbing", 10);
+ attrIds.put("http://www.geocaching.com/images/attributes/wading", 11);
+ attrIds.put("http://www.geocaching.com/images/attributes/swimming", 12);
+ attrIds.put("http://www.geocaching.com/images/attributes/available", 13);
+ attrIds.put("http://www.geocaching.com/images/attributes/night", 14);
+ attrIds.put("http://www.geocaching.com/images/attributes/winter", 15);
+ attrIds.put("http://www.geocaching.com/images/attributes/camping", 16);
+ attrIds.put("http://www.geocaching.com/images/attributes/poisonoak", 17);
+ attrIds.put("http://www.geocaching.com/images/attributes/snakes", 18);
+ attrIds.put("http://www.geocaching.com/images/attributes/ticks", 19);
+ attrIds.put("http://www.geocaching.com/images/attributes/mine", 20);
+ attrIds.put("http://www.geocaching.com/images/attributes/cliff", 21);
+ attrIds.put("http://www.geocaching.com/images/attributes/hunting", 22);
+ attrIds.put("http://www.geocaching.com/images/attributes/danger", 23);
+ attrIds.put("http://www.geocaching.com/images/attributes/wheelchair", 24);
+ attrIds.put("http://www.geocaching.com/images/attributes/parking", 25);
+ attrIds.put("http://www.geocaching.com/images/attributes/public", 26);
+ attrIds.put("http://www.geocaching.com/images/attributes/water", 27);
+ attrIds.put("http://www.geocaching.com/images/attributes/restrooms", 28);
+ attrIds.put("http://www.geocaching.com/images/attributes/phone", 29);
+ attrIds.put("http://www.geocaching.com/images/attributes/picnic", 30);
+ attrIds.put("http://www.geocaching.com/images/attributes/camping", 31);
+ attrIds.put("http://www.geocaching.com/images/attributes/bicycles", 32);
+ attrIds.put("http://www.geocaching.com/images/attributes/motorcycles", 33);
+ attrIds.put("http://www.geocaching.com/images/attributes/quads", 34);
+ attrIds.put("http://www.geocaching.com/images/attributes/jeeps", 35);
+ attrIds.put("http://www.geocaching.com/images/attributes/snowmobiles", 36);
+ attrIds.put("http://www.geocaching.com/images/attributes/horses", 37);
+ attrIds.put("http://www.geocaching.com/images/attributes/campfires", 38);
+ attrIds.put("http://www.geocaching.com/images/attributes/thorn",39 );
+ attrIds.put("http://www.geocaching.com/images/attributes/stealth", 40);
+ attrIds.put("http://www.geocaching.com/images/attributes/stroller", 41);
+ attrIds.put("http://www.geocaching.com/images/attributes/firstaid", 42);
+ attrIds.put("http://www.geocaching.com/images/attributes/cow", 43);
+ attrIds.put("http://www.geocaching.com/images/attributes/flashlight", 44);
+ }
+
+ public void setByImgUrl(String url) {
+ if (url != null && url.length() > 0) {
+ id = attrIds.get(url.substring(0, url.lastIndexOf("-")));
+ if (url.contains("-yes."))
+ id += 100;
+ }
+ }
+
+ /****************************/
+ /* PARCELABLE PART */
+ /****************************/
+
+ public static final Parcelable.Creator<PointGeocachingAttributes> CREATOR = new Parcelable.Creator<PointGeocachingAttributes>() {
+ public PointGeocachingAttributes createFromParcel(Parcel in) {
+ return new PointGeocachingAttributes(in);
+ }
+
+ public PointGeocachingAttributes[] newArray(int size) {
+ return new PointGeocachingAttributes[size];
+ }
+ };
+
+ public PointGeocachingAttributes(Parcel in) {
+ switch (in.readInt()) {
+ case 0:
+ id = in.readInt();
+ break;
+ }
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(VERSION);
+ dest.writeInt(id);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+}
diff --git a/src/menion/android/locus/addon/publiclib/geoData/PointGeocachingData.java b/src/menion/android/locus/addon/publiclib/geoData/PointGeocachingData.java new file mode 100644 index 0000000..420da0c --- /dev/null +++ b/src/menion/android/locus/addon/publiclib/geoData/PointGeocachingData.java @@ -0,0 +1,316 @@ +package menion.android.locus.addon.publiclib.geoData;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.util.Log;
+
+public class PointGeocachingData implements Parcelable {
+
+ private static final int VERSION = 2;
+
+ public static final int CACHE_NUMBER_OF_TYPES = 14;
+
+ public static final int CACHE_TYPE_TRADITIONAL = 0;
+ public static final int CACHE_TYPE_MULTI = 1;
+ public static final int CACHE_TYPE_MYSTERY = 2;
+ public static final int CACHE_TYPE_VIRTUAL = 3;
+ public static final int CACHE_TYPE_EARTH = 4;
+ public static final int CACHE_TYPE_PROJECT_APE = 5;
+ public static final int CACHE_TYPE_LETTERBOX = 6;
+ public static final int CACHE_TYPE_WHERIGO = 7;
+ public static final int CACHE_TYPE_EVENT = 8;
+ public static final int CACHE_TYPE_MEGA_EVENT = 9;
+ public static final int CACHE_TYPE_CACHE_IN_TRASH_OUT = 10;
+ public static final int CACHE_TYPE_GPS_ADVENTURE = 11;
+ public static final int CACHE_TYPE_WEBCAM = 12;
+ public static final int CACHE_TYPE_LOCATIONLESS = 13;
+
+ public static final int CACHE_LOG_TYPE_UNKNOWN = -1;
+ public static final int CACHE_LOG_TYPE_FOUNDED = 0;
+ public static final int CACHE_LOG_TYPE_NOT_FOUNDED = 1;
+ public static final int CACHE_LOG_TYPE_WRITE_NOTE = 2;
+ public static final int CACHE_LOG_TYPE_NEEDS_MAINTENANCE = 3;
+ public static final int CACHE_LOG_TYPE_OWNER_MAINTENANCE = 4;
+ public static final int CACHE_LOG_TYPE_PUBLISH_LISTING = 5;
+ public static final int CACHE_LOG_TYPE_ENABLE_LISTING = 6;
+ public static final int CACHE_LOG_TYPE_TEMPORARILY_DISABLE_LISTING = 7;
+ public static final int CACHE_LOG_TYPE_UPDATE_COORDINATES = 8;
+ public static final int CACHE_LOG_TYPE_ANNOUNCEMENT = 9;
+ public static final int CACHE_LOG_TYPE_WILL_ATTEND = 10;
+ public static final int CACHE_LOG_TYPE_ATTENDED = 11;
+ public static final int CACHE_LOG_TYPE_POST_REVIEWER_NOTE = 12;
+ public static final int CACHE_LOG_TYPE_NEEDS_ARCHIVED = 13;
+ public static final int CACHE_LOG_TYPE_WEBCAM_PHOTO_TAKEN = 14;
+ public static final int CACHE_LOG_TYPE_RETRACT_LISTING = 15;
+
+ public static final int CACHE_SIZE_NOT_CHOSEN = 0;
+ public static final int CACHE_SIZE_MICRO = 1;
+ public static final int CACHE_SIZE_SMALL = 2;
+ public static final int CACHE_SIZE_REGULAR = 3;
+ public static final int CACHE_SIZE_LARGE = 4;
+ public static final int CACHE_SIZE_HUGE = 5;
+ public static final int CACHE_SIZE_OTHER = 6;
+
+ public static final String CACHE_WAYPOINT_TYPE_QUESTION = "Question to Answer";
+ public static final String CACHE_WAYPOINT_TYPE_FINAL = "Final Location";
+ public static final String CACHE_WAYPOINT_TYPE_PARKING = "Parking Area";
+ public static final String CACHE_WAYPOINT_TYPE_TRAILHEAD = "Trailhead";
+ public static final String CACHE_WAYPOINT_TYPE_STAGES = "Stages of a Multicache";
+ public static final String CACHE_WAYPOINT_TYPE_REFERENCE = "Reference Point";
+
+ /* id of point - not needed as I remember */
+ public int id;
+ /* whole cache ID from gc.com - so GC... - !REQUIRED! */
+ public String cacheID;
+ /* is available or disable */
+ public boolean available;
+ /* cache already archived or not */
+ public boolean archived;
+ /* available only for premium members */
+ public boolean premiumOnly;
+ /* name of cache - !REQUIRED! */
+ public String name;
+ /* String with date of last update - groundspeak:lastUpdated*/
+ public String lastUpdated;
+ /* String with date of last exported - groundspeak:exported */
+ public String exported;
+ /* name of person who placed cache - groundspeak:placed_by */
+ public String placedBy;
+ /* name of cache owner - groundspeak:owner */
+ public String owner;
+ /* String with date of hidden - value from CachePrinter */
+ public String hidden;
+ /* cache type */
+ public int type;
+ /* container size */
+ public int container;
+ /* dificulty value - 1.0 - 5.0 (by 0.5) */
+ public float difficulty;
+ /* terrain value - 1.0 - 5.0 (by 0.5) */
+ public float terrain;
+ /* country name */
+ public String country;
+ /* state name */
+ public String state;
+ /* short description of cache */
+ public String shortDescription;
+ /* full description with complete (HTML) listing */
+ public String longDescription;
+ /* encoded hints */
+ public String encodedHints;
+ /* list of attributes */
+ public ArrayList<PointGeocachingAttributes> attributes;
+ /* list of logs */
+ public ArrayList<PointGeocachingDataLog> logs;
+ /* list of travel bugs */
+ public ArrayList<PointGeocachingDataTravelBug> travelBugs;
+ /* list of waypoints */
+ public ArrayList<PointGeocachingDataWaypoint> waypoints;
+ /* user notes */
+ public String notes;
+ /* if cache is already computed - have final waypoint and is placed on it's location */
+ public boolean computed;
+ /* if cache is already found */
+ public boolean found;
+
+ public PointGeocachingData() {
+ id = 0;
+ cacheID = "";
+ available = true;
+ archived = false;
+ premiumOnly = false;
+ name = "";
+ lastUpdated = "";
+ exported = "";
+ placedBy = "";
+ owner = "";
+ hidden = "";
+ type = CACHE_TYPE_TRADITIONAL;
+ container = CACHE_SIZE_NOT_CHOSEN;
+ difficulty = -1.0f;
+ terrain = -1.0f;
+ country = "";
+ state = "";
+ shortDescription = "";
+ longDescription = "";
+ encodedHints = "";
+ attributes = new ArrayList<PointGeocachingAttributes>();
+ logs = new ArrayList<PointGeocachingDataLog>();
+ travelBugs = new ArrayList<PointGeocachingDataTravelBug>();
+ waypoints = new ArrayList<PointGeocachingDataWaypoint>();
+ notes = "";
+ computed = false;
+ found = false;
+ }
+
+ /****************************/
+ /* PARCELABLE PART */
+ /****************************/
+
+ public static final Parcelable.Creator<PointGeocachingData> CREATOR = new Parcelable.Creator<PointGeocachingData>() {
+ public PointGeocachingData createFromParcel(Parcel in) {
+ return new PointGeocachingData(in);
+ }
+
+ public PointGeocachingData[] newArray(int size) {
+ return new PointGeocachingData[size];
+ }
+ };
+
+ @SuppressWarnings("unchecked")
+ public PointGeocachingData(Parcel in) {
+ int version = in.readInt();
+ if (version == 0) {
+ id = in.readInt();
+ cacheID = in.readString();
+ available = in.readInt() == 1;
+ archived = in.readInt() == 1;
+ premiumOnly = in.readInt() == 1;
+ name = in.readString();
+ lastUpdated = in.readString();
+ exported = in.readString();
+ placedBy = in.readString();
+ owner = in.readString();
+ hidden = in.readString();
+ type = in.readInt();
+ container = in.readInt();
+ difficulty = in.readFloat();
+ terrain = in.readFloat();
+ country = in.readString();
+ state = in.readString();
+ shortDescription = in.readString();
+ longDescription = in.readString();
+ encodedHints = in.readString();
+ attributes = in.readArrayList(PointGeocachingAttributes.class.getClassLoader());
+ logs = in.readArrayList(PointGeocachingDataLog.class.getClassLoader());
+ travelBugs = in.readArrayList(PointGeocachingDataTravelBug.class.getClassLoader());
+ waypoints = in.readArrayList(PointGeocachingDataWaypoint.class.getClassLoader());
+ notes = in.readString();
+ computed = in.readInt() == 1;
+ } else if (version > 0) {
+ id = in.readInt();
+ cacheID = in.readString();
+ available = in.readInt() == 1;
+ archived = in.readInt() == 1;
+ premiumOnly = in.readInt() == 1;
+ name = in.readString();
+ lastUpdated = in.readString();
+ exported = in.readString();
+ placedBy = in.readString();
+ owner = in.readString();
+ hidden = in.readString();
+ type = in.readInt();
+ container = in.readInt();
+ difficulty = in.readFloat();
+ terrain = in.readFloat();
+ country = in.readString();
+ state = in.readString();
+ try {
+ int size = in.readInt();
+ int lengthSD = in.readInt();
+
+ byte[] data = new byte[size];
+ in.readByteArray(data);
+
+ GZIPInputStream zis = new GZIPInputStream(new ByteArrayInputStream(data), 10240);
+ StringBuffer buffer = new StringBuffer();
+
+// byte[] dataD = new byte[10240];
+// int bytesRead;
+// while ((bytesRead = zis.read(dataD)) != -1) {
+// buffer.append(new String(dataD, 0, bytesRead, "utf-8"));
+// }
+// String result = buffer.toString();
+// zis.close();
+
+ InputStreamReader isr = new InputStreamReader(zis, "UTF-8");
+ char[] dataD = new char[1024];
+ int charsRead;
+ while ((charsRead = isr.read(dataD)) != -1) {
+ buffer.append(dataD, 0, charsRead);
+ }
+ String result = buffer.toString();
+ isr.close();
+
+ // read short description
+ if (lengthSD > 0)
+ shortDescription = result.substring(0, lengthSD);
+
+ // read long description
+ longDescription = result.substring(lengthSD);
+ } catch (Exception e) {
+ Log.e("PointGeocachingData", "Problem in ZIP compression - read", e);
+ }
+ encodedHints = in.readString();
+ attributes = in.readArrayList(PointGeocachingAttributes.class.getClassLoader());
+ logs = in.readArrayList(PointGeocachingDataLog.class.getClassLoader());
+ travelBugs = in.readArrayList(PointGeocachingDataTravelBug.class.getClassLoader());
+ waypoints = in.readArrayList(PointGeocachingDataWaypoint.class.getClassLoader());
+ notes = in.readString();
+ computed = in.readInt() == 1;
+ if (version == 2) {
+ found = in.readInt() == 1;
+ }
+ }
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(VERSION);
+ dest.writeInt(id);
+ dest.writeString(cacheID);
+ dest.writeInt(available ? 1 : 0);
+ dest.writeInt(archived ? 1 : 0);
+ dest.writeInt(premiumOnly ? 1 : 0);
+ dest.writeString(name);
+ dest.writeString(lastUpdated);
+ dest.writeString(exported);
+ dest.writeString(placedBy);
+ dest.writeString(owner);
+ dest.writeString(hidden);
+ dest.writeInt(type);
+ dest.writeInt(container);
+ dest.writeFloat(difficulty);
+ dest.writeFloat(terrain);
+ dest.writeString(country);
+ dest.writeString(state);
+ try {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ GZIPOutputStream zos = new GZIPOutputStream(baos);
+
+ zos.write(shortDescription.getBytes("utf-8"));
+ zos.write(longDescription.getBytes("utf-8"));
+ zos.close();
+
+ byte[] data = baos.toByteArray();
+ baos.close();
+
+ dest.writeInt(data.length);
+ dest.writeInt(shortDescription.length());
+ dest.writeByteArray(data);
+ } catch (Exception e) {
+ Log.e("PointGeocachingData", "Problem in ZIP compression - write", e);
+ }
+
+ dest.writeString(encodedHints);
+ dest.writeList(attributes);
+ dest.writeList(logs);
+ dest.writeList(travelBugs);
+ dest.writeList(waypoints);
+ dest.writeString(notes);
+ dest.writeInt(computed ? 1 : 0);
+ dest.writeInt(found ? 1 : 0);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+}
diff --git a/src/menion/android/locus/addon/publiclib/geoData/PointGeocachingDataLog.java b/src/menion/android/locus/addon/publiclib/geoData/PointGeocachingDataLog.java new file mode 100644 index 0000000..9e7624b --- /dev/null +++ b/src/menion/android/locus/addon/publiclib/geoData/PointGeocachingDataLog.java @@ -0,0 +1,69 @@ +package menion.android.locus.addon.publiclib.geoData;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+public class PointGeocachingDataLog implements Parcelable {
+
+ private static final int VERSION = 1;
+
+ public int id;
+ public int type;
+ public String date;
+ public String finder;
+ public int finderFound;
+ public String logText;
+
+ public PointGeocachingDataLog() {
+ id = 0;
+ type = PointGeocachingData.CACHE_LOG_TYPE_UNKNOWN;
+ date = "";
+ finder = "";
+ finderFound = 0;
+ logText = "";
+ }
+
+ /****************************/
+ /* PARCELABLE PART */
+ /****************************/
+
+ public static final Parcelable.Creator<PointGeocachingDataLog> CREATOR = new Parcelable.Creator<PointGeocachingDataLog>() {
+ public PointGeocachingDataLog createFromParcel(Parcel in) {
+ return new PointGeocachingDataLog(in);
+ }
+
+ public PointGeocachingDataLog[] newArray(int size) {
+ return new PointGeocachingDataLog[size];
+ }
+ };
+
+ public PointGeocachingDataLog(Parcel in) {
+ switch (in.readInt()) {
+ case 1:
+ id = in.readInt();
+ case 0:
+ type = in.readInt();
+ date = in.readString();
+ finder = in.readString();
+ finderFound = in.readInt();
+ logText = in.readString();
+ break;
+ }
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(VERSION);
+ dest.writeInt(id);
+ dest.writeInt(type);
+ dest.writeString(date);
+ dest.writeString(finder);
+ dest.writeInt(finderFound);
+ dest.writeString(logText);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+}
\ No newline at end of file diff --git a/src/menion/android/locus/addon/publiclib/geoData/PointGeocachingDataTravelBug.java b/src/menion/android/locus/addon/publiclib/geoData/PointGeocachingDataTravelBug.java new file mode 100644 index 0000000..9ab6c85 --- /dev/null +++ b/src/menion/android/locus/addon/publiclib/geoData/PointGeocachingDataTravelBug.java @@ -0,0 +1,86 @@ +package menion.android.locus.addon.publiclib.geoData;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+public class PointGeocachingDataTravelBug implements Parcelable {
+
+ private static final int VERSION = 0;
+
+ /* name of travel bug */
+ public String name;
+ /* image url to this travel bug */
+ public String imgUrl;
+ /* original page data */
+ public String srcDetails;
+
+ /* owner of TB */
+ public String owner;
+ /* String date of release */
+ public String released;
+ /* origin place */
+ public String origin;
+ /* goal of this TB */
+ public String goal;
+ /* details */
+ public String details;
+
+ public PointGeocachingDataTravelBug() {
+ name = "";
+ imgUrl = "";
+ srcDetails = "";
+
+ owner = "";
+ released = "";
+ origin = "";
+ goal = "";
+ details = "";
+ }
+
+ /****************************/
+ /* PARCELABLE PART */
+ /****************************/
+
+ public static final Parcelable.Creator<PointGeocachingDataTravelBug> CREATOR = new Parcelable.Creator<PointGeocachingDataTravelBug>() {
+ public PointGeocachingDataTravelBug createFromParcel(Parcel in) {
+ return new PointGeocachingDataTravelBug(in);
+ }
+
+ public PointGeocachingDataTravelBug[] newArray(int size) {
+ return new PointGeocachingDataTravelBug[size];
+ }
+ };
+
+ public PointGeocachingDataTravelBug(Parcel in) {
+ switch (in.readInt()) {
+ case 0:
+ name = in.readString();
+ imgUrl = in.readString();
+ srcDetails = in.readString();
+ owner = in.readString();
+ released = in.readString();
+ origin = in.readString();
+ goal = in.readString();
+ details = in.readString();
+ break;
+ }
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(VERSION);
+ dest.writeString(name);
+ dest.writeString(imgUrl);
+ dest.writeString(srcDetails);
+ dest.writeString(owner);
+ dest.writeString(released);
+ dest.writeString(origin);
+ dest.writeString(goal);
+ dest.writeString(details);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+}
\ No newline at end of file diff --git a/src/menion/android/locus/addon/publiclib/geoData/PointGeocachingDataWaypoint.java b/src/menion/android/locus/addon/publiclib/geoData/PointGeocachingDataWaypoint.java new file mode 100644 index 0000000..e478cbb --- /dev/null +++ b/src/menion/android/locus/addon/publiclib/geoData/PointGeocachingDataWaypoint.java @@ -0,0 +1,80 @@ +package menion.android.locus.addon.publiclib.geoData;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+public class PointGeocachingDataWaypoint implements Parcelable {
+
+ private static final int VERSION = 1;
+
+ /* code of wpt */
+ public String code;
+ /* name of waypoint */
+ public String name;
+ /* description (may be HTML code) */
+ public String description;
+ /* type of waypoint (defined in PointGeocachingData) */
+ public String type;
+ /* image URL to this wpt (not needed) */
+ public String typeImagePath;
+ /* latitude of waypoint */
+ public double lat;
+ /* longitude of waypoint */
+ public double lon;
+
+ public PointGeocachingDataWaypoint() {
+ code = "";
+ name = "";
+ description = "";
+ type = "";
+ typeImagePath = "";
+ lat = 0.0;
+ lon = 0.0;
+ }
+
+ /****************************/
+ /* PARCELABLE PART */
+ /****************************/
+
+ public static final Parcelable.Creator<PointGeocachingDataWaypoint> CREATOR = new Parcelable.Creator<PointGeocachingDataWaypoint>() {
+ public PointGeocachingDataWaypoint createFromParcel(Parcel in) {
+ return new PointGeocachingDataWaypoint(in);
+ }
+
+ public PointGeocachingDataWaypoint[] newArray(int size) {
+ return new PointGeocachingDataWaypoint[size];
+ }
+ };
+
+ public PointGeocachingDataWaypoint(Parcel in) {
+ switch (in.readInt()) {
+ case 1:
+ code = in.readString();
+ case 0:
+ name = in.readString();
+ description = in.readString();
+ type = in.readString();
+ typeImagePath = in.readString();
+ lat = in.readDouble();
+ lon = in.readDouble();
+ break;
+ }
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(VERSION);
+ dest.writeString(code);
+ dest.writeString(name);
+ dest.writeString(description);
+ dest.writeString(type);
+ dest.writeString(typeImagePath);
+ dest.writeDouble(lat);
+ dest.writeDouble(lon);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+}
\ No newline at end of file diff --git a/src/menion/android/locus/addon/publiclib/geoData/PointsData.java b/src/menion/android/locus/addon/publiclib/geoData/PointsData.java new file mode 100644 index 0000000..ab8f193 --- /dev/null +++ b/src/menion/android/locus/addon/publiclib/geoData/PointsData.java @@ -0,0 +1,122 @@ +package menion.android.locus.addon.publiclib.geoData;
+
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+public class PointsData implements Parcelable {
+
+ private static final int VERSION = 0;
+
+ // Unique name. PointsData send to Locus with same name will be overwrited in Locus
+ private String mName;
+ // icon applied to whole PointsData
+ private Bitmap mBitmap;
+ // ArrayList of all points stored in this object
+ private ArrayList<Point> mPoints;
+
+ public PointsData(String uniqueName) {
+ this.mName = uniqueName;
+ this.mBitmap = null;
+ this.mPoints = new ArrayList<Point>();
+ }
+
+ public String getName() {
+ return mName;
+ }
+
+ public Bitmap getBitmap() {
+ return mBitmap;
+ }
+
+ public void setBitmap(Bitmap bitmap) {
+ this.mBitmap = bitmap;
+ }
+
+ public void addPoint(Point point) {
+ this.mPoints.add(point);
+ }
+
+ public ArrayList<Point> getPoints() {
+ return mPoints;
+ }
+
+ /****************************/
+ /* PARCELABLE PART */
+ /****************************/
+
+ public static final Parcelable.Creator<PointsData> CREATOR = new Parcelable.Creator<PointsData>() {
+ public PointsData createFromParcel(Parcel in) {
+ return new PointsData(in);
+ }
+
+ public PointsData[] newArray(int size) {
+ return new PointsData[size];
+ }
+ };
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @SuppressWarnings("unchecked")
+ private PointsData(Parcel in) {
+ switch (in.readInt()) {
+ case 0:
+ mName = in.readString();
+ int size = in.readInt();
+ if (size > 0) {
+ byte[] data = new byte[size];
+ in.readByteArray(data);
+ mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
+ } else {
+ mBitmap = null;
+ }
+
+ mPoints = in.readArrayList(Point.class.getClassLoader());
+ break;
+ }
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(VERSION);
+ dest.writeString(mName);
+ if (mBitmap == null) {
+ dest.writeInt(0);
+ } else {
+ byte[] data = getBitmapAsByte(mBitmap);
+ if (data == null || data.length == 0) {
+ dest.writeInt(0);
+ } else {
+ dest.writeInt(data.length);
+ dest.writeByteArray(data);
+ }
+ }
+ dest.writeList(mPoints);
+ }
+
+ private static byte[] getBitmapAsByte(Bitmap bitmap) {
+ ByteArrayOutputStream baos = null;
+ try {
+ baos = new ByteArrayOutputStream();
+ bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
+ return baos.toByteArray();
+ } catch (Exception e) {
+ return null;
+ } finally {
+ try {
+ if (baos != null){
+ baos.close();
+ baos = null;
+ }
+ } catch (Exception e) {}
+ }
+ }
+
+}
diff --git a/src/menion/android/locus/addon/publiclib/utils/DataCursor.java b/src/menion/android/locus/addon/publiclib/utils/DataCursor.java new file mode 100644 index 0000000..5f3912e --- /dev/null +++ b/src/menion/android/locus/addon/publiclib/utils/DataCursor.java @@ -0,0 +1,331 @@ +package menion.android.locus.addon.publiclib.utils;
+
+import java.util.ArrayList;
+
+import android.database.AbstractCursor;
+import android.database.CursorIndexOutOfBoundsException;
+import android.database.CursorWindow;
+
+/**
+ * A mutable cursor implementation backed by an array of {@code Object}s. Use
+ * {@link #newRow()} to add rows. Automatically expands internal capacity as
+ * needed.
+ */
+public class DataCursor extends AbstractCursor {
+
+ private final String[] columnNames;
+ private Object[] data;
+ private int rowCount = 0;
+ private final int columnCount;
+
+ /**
+ * Constructs a new cursor with the given initial capacity.
+ *
+ * @param columnNames
+ * names of the columns, the ordering of which determines column
+ * ordering elsewhere in this cursor
+ * @param initialCapacity
+ * in rows
+ */
+ public DataCursor(String[] columnNames, int initialCapacity) {
+ this.columnNames = columnNames;
+ this.columnCount = columnNames.length;
+
+ if (initialCapacity < 1) {
+ initialCapacity = 1;
+ }
+
+ this.data = new Object[columnCount * initialCapacity];
+ }
+
+ /**
+ * Constructs a new cursor.
+ *
+ * @param columnNames
+ * names of the columns, the ordering of which determines column
+ * ordering elsewhere in this cursor
+ */
+ public DataCursor(String[] columnNames) {
+ this(columnNames, 16);
+ }
+
+ /**
+ * Gets value at the given column for the current row.
+ */
+ private Object get(int column) {
+ if (column < 0 || column >= columnCount) {
+ throw new CursorIndexOutOfBoundsException("Requested column: "
+ + column + ", # of columns: " + columnCount);
+ }
+ if (mPos < 0) {
+ throw new CursorIndexOutOfBoundsException("Before first row.");
+ }
+ if (mPos >= rowCount) {
+ throw new CursorIndexOutOfBoundsException("After last row.");
+ }
+ return data[mPos * columnCount + column];
+ }
+
+ /**
+ * Adds a new row to the end and returns a builder for that row. Not safe
+ * for concurrent use.
+ *
+ * @return builder which can be used to set the column values for the new
+ * row
+ */
+ public RowBuilder newRow() {
+ rowCount++;
+ int endIndex = rowCount * columnCount;
+ ensureCapacity(endIndex);
+ int start = endIndex - columnCount;
+ return new RowBuilder(start, endIndex);
+ }
+
+ /**
+ * Adds a new row to the end with the given column values. Not safe for
+ * concurrent use.
+ *
+ * @throws IllegalArgumentException
+ * if {@code columnValues.length !=
+ * columnNames.length}
+ * @param columnValues
+ * in the same order as the the column names specified at cursor
+ * construction time
+ */
+ public void addRow(Object[] columnValues) {
+ if (columnValues.length != columnCount) {
+ throw new IllegalArgumentException("columnNames.length = "
+ + columnCount + ", columnValues.length = "
+ + columnValues.length);
+ }
+
+ int start = rowCount++ * columnCount;
+ ensureCapacity(start + columnCount);
+ System.arraycopy(columnValues, 0, data, start, columnCount);
+ }
+
+ /**
+ * Adds a new row to the end with the given column values. Not safe for
+ * concurrent use.
+ *
+ * @throws IllegalArgumentException
+ * if {@code columnValues.size() !=
+ * columnNames.length}
+ * @param columnValues
+ * in the same order as the the column names specified at cursor
+ * construction time
+ */
+ public void addRow(Iterable<?> columnValues) {
+ int start = rowCount * columnCount;
+ int end = start + columnCount;
+ ensureCapacity(end);
+
+ if (columnValues instanceof ArrayList<?>) {
+ addRow((ArrayList<?>) columnValues, start);
+ return;
+ }
+
+ int current = start;
+ Object[] localData = data;
+ for (Object columnValue : columnValues) {
+ if (current == end) {
+ // TODO: null out row?
+ throw new IllegalArgumentException(
+ "columnValues.size() > columnNames.length");
+ }
+ localData[current++] = columnValue;
+ }
+
+ if (current != end) {
+ // TODO: null out row?
+ throw new IllegalArgumentException(
+ "columnValues.size() < columnNames.length");
+ }
+
+ // Increase row count here in case we encounter an exception.
+ rowCount++;
+ }
+
+ /** Optimization for {@link ArrayList}. */
+ private void addRow(ArrayList<?> columnValues, int start) {
+ int size = columnValues.size();
+ if (size != columnCount) {
+ throw new IllegalArgumentException("columnNames.length = "
+ + columnCount + ", columnValues.size() = " + size);
+ }
+
+ rowCount++;
+ Object[] localData = data;
+ for (int i = 0; i < size; i++) {
+ localData[start + i] = columnValues.get(i);
+ }
+ }
+
+ /** Ensures that this cursor has enough capacity. */
+ private void ensureCapacity(int size) {
+ if (size > data.length) {
+ Object[] oldData = this.data;
+ int newSize = data.length * 2;
+ if (newSize < size) {
+ newSize = size;
+ }
+ this.data = new Object[newSize];
+ System.arraycopy(oldData, 0, this.data, 0, oldData.length);
+ }
+ }
+
+ /**
+ * Builds a row, starting from the left-most column and adding one column
+ * value at a time. Follows the same ordering as the column names specified
+ * at cursor construction time.
+ */
+ public class RowBuilder {
+
+ private int index;
+ private final int endIndex;
+
+ RowBuilder(int index, int endIndex) {
+ this.index = index;
+ this.endIndex = endIndex;
+ }
+
+ /**
+ * Sets the next column value in this row.
+ *
+ * @throws CursorIndexOutOfBoundsException
+ * if you try to add too many values
+ * @return this builder to support chaining
+ */
+ public RowBuilder add(Object columnValue) {
+ if (index == endIndex) {
+ throw new CursorIndexOutOfBoundsException(
+ "No more columns left.");
+ }
+
+ data[index++] = columnValue;
+ return this;
+ }
+ }
+
+ // AbstractCursor implementation.
+
+ @Override
+ public int getCount() {
+ return rowCount;
+ }
+
+ @Override
+ public String[] getColumnNames() {
+ return columnNames;
+ }
+
+ @Override
+ public String getString(int column) {
+ Object value = get(column);
+ if (value == null)
+ return null;
+ return value.toString();
+ }
+
+ @Override
+ public short getShort(int column) {
+ Object value = get(column);
+ if (value == null)
+ return 0;
+ if (value instanceof Number)
+ return ((Number) value).shortValue();
+ return Short.parseShort(value.toString());
+ }
+
+ @Override
+ public int getInt(int column) {
+ Object value = get(column);
+ if (value == null)
+ return 0;
+ if (value instanceof Number)
+ return ((Number) value).intValue();
+ return Integer.parseInt(value.toString());
+ }
+
+ @Override
+ public long getLong(int column) {
+ Object value = get(column);
+ if (value == null)
+ return 0;
+ if (value instanceof Number)
+ return ((Number) value).longValue();
+ return Long.parseLong(value.toString());
+ }
+
+ @Override
+ public float getFloat(int column) {
+ Object value = get(column);
+ if (value == null)
+ return 0.0f;
+ if (value instanceof Number)
+ return ((Number) value).floatValue();
+ return Float.parseFloat(value.toString());
+ }
+
+ @Override
+ public double getDouble(int column) {
+ Object value = get(column);
+ if (value == null)
+ return 0.0d;
+ if (value instanceof Number)
+ return ((Number) value).doubleValue();
+ return Double.parseDouble(value.toString());
+ }
+
+ @Override
+ public byte[] getBlob(int column) {
+ Object value = get(column);
+ if (value == null)
+ return new byte[0];
+ if (value instanceof byte[])
+ return ((byte[]) value);
+ return new byte[0];
+ }
+
+ @Override
+ public boolean isNull(int column) {
+ return get(column) == null;
+ }
+
+ public void fillWindow(int position, CursorWindow window) {
+ if (position < 0 || position >= getCount()) {
+ return;
+ }
+ window.acquireReference();
+ try {
+ int oldpos = mPos;
+ mPos = position - 1;
+ window.clear();
+ window.setStartPosition(position);
+ int columnNum = getColumnCount();
+ window.setNumColumns(columnNum);
+ while (moveToNext() && window.allocRow()) {
+ for (int i = 0; i < columnNum; i++) {
+ byte[] field = getBlob(i);
+ if (field != null) {
+ if (!window.putBlob(field, mPos, i)) {
+ window.freeLastRow();
+ break;
+ }
+ } else {
+ if (!window.putNull(mPos, i)) {
+ window.freeLastRow();
+ break;
+ }
+ }
+ }
+ }
+
+ mPos = oldpos;
+ } catch (IllegalStateException e) {
+ // simply ignore it
+ } finally {
+ window.releaseReference();
+ }
+ }
+}
diff --git a/src/menion/android/locus/addon/publiclib/utils/DataStorage.java b/src/menion/android/locus/addon/publiclib/utils/DataStorage.java new file mode 100644 index 0000000..8705b04 --- /dev/null +++ b/src/menion/android/locus/addon/publiclib/utils/DataStorage.java @@ -0,0 +1,28 @@ +package menion.android.locus.addon.publiclib.utils;
+
+import java.util.ArrayList;
+
+import menion.android.locus.addon.publiclib.geoData.PointsData;
+
+public class DataStorage {
+
+ private static ArrayList<PointsData> mData;
+
+ public static ArrayList<PointsData> getData() {
+ return mData;
+ }
+
+ public static void setData(ArrayList<PointsData> data) {
+ DataStorage.mData = data;
+ }
+
+ public static void setData(PointsData data) {
+ DataStorage.mData = new ArrayList<PointsData>();
+ DataStorage.mData.add(data);
+ }
+
+ public static void clearData() {
+ DataStorage.mData.clear();
+ DataStorage.mData = null;
+ }
+}
|
