aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2011-09-14 23:54:46 +0200
committerSamuel Tardieu <sam@rfc1149.net>2011-09-14 23:54:46 +0200
commitccaab5d0b312b28ab15833ab8f11dd809ec93aab (patch)
tree4f80418eeb724a0c15ec6c80621e647b63a1a826 /src/cgeo
parent4f7c67407019de18fd53b640edb9682a346fbfef (diff)
downloadcgeo-ccaab5d0b312b28ab15833ab8f11dd809ec93aab.zip
cgeo-ccaab5d0b312b28ab15833ab8f11dd809ec93aab.tar.gz
cgeo-ccaab5d0b312b28ab15833ab8f11dd809ec93aab.tar.bz2
Convert to Unix end-of-line format
Diffstat (limited to 'src/cgeo')
-rw-r--r--src/cgeo/geocaching/ICache.java198
-rw-r--r--src/cgeo/geocaching/LogTemplateProvider.java310
-rw-r--r--src/cgeo/geocaching/apps/LocusDataStorageProvider.java140
-rw-r--r--src/cgeo/geocaching/cgCoord.java90
-rw-r--r--src/cgeo/geocaching/cgDirection.java150
-rw-r--r--src/cgeo/geocaching/enumerations/CacheSize.java74
-rw-r--r--src/cgeo/geocaching/enumerations/CacheType.java104
-rw-r--r--src/cgeo/geocaching/enumerations/WaypointType.java72
-rw-r--r--src/cgeo/geocaching/files/FileParser.java106
-rw-r--r--src/cgeo/geocaching/files/GPX10Parser.java40
-rw-r--r--src/cgeo/geocaching/files/GPX11Parser.java40
-rw-r--r--src/cgeo/geocaching/files/LocParser.java358
-rw-r--r--src/cgeo/geocaching/utils/CollectionUtils.java48
13 files changed, 865 insertions, 865 deletions
diff --git a/src/cgeo/geocaching/ICache.java b/src/cgeo/geocaching/ICache.java
index 1560700..9126268 100644
--- a/src/cgeo/geocaching/ICache.java
+++ b/src/cgeo/geocaching/ICache.java
@@ -1,99 +1,99 @@
-/**
- *
- */
-package cgeo.geocaching;
-
-/**
- * Basic interface for caches
- *
- * @author blafoo
- *
- */
-public interface ICache {
-
- /**
- * @return Geocode like GCxxxx
- */
- public String getGeocode();
-
- /**
- * @return Tradi, multi etc.
- */
- public String getType();
-
- /**
- * @return Displayed owner, might differ from the real owner
- */
- public String getOwner();
-
- /**
- * @return GC username of the owner
- */
- public String getOwnerReal();
-
- /**
- * @return Micro, small etc.
- */
- public String getSize();
-
- /**
- * @return Difficulty assessment
- */
- public Float getDifficulty();
-
- /**
- * @return Terrain assessment
- */
- public Float getTerrain();
-
- /**
- * @return Latitude, e.g. N 52° 12.345
- */
- public String getLatitude();
-
- /**
- * @return Longitude, e.g. E 9° 34.567
- */
- public String getLongitude();
-
- /**
- * @return true if the cache is disabled, false else
- */
- public boolean isDisabled();
-
- /**
- * @return true if the user is the owner of the cache, false else
- */
- public boolean isOwn();
-
- /**
- * @return true is the cache is archived, false else
- */
- public boolean isArchived();
-
- /**
- * @return true is the cache is a Premium Member cache only, false else
- */
- public boolean isMembersOnly();
-
- /**
- * @return Decrypted hint
- */
- public String getHint();
-
- /**
- * @return Description
- */
- public String getDescription();
-
- /**
- * @return Short Description
- */
- public String getShortDescription();
-
- /**
- * @return Name
- */
- public String getName();
-
-}
+/**
+ *
+ */
+package cgeo.geocaching;
+
+/**
+ * Basic interface for caches
+ *
+ * @author blafoo
+ *
+ */
+public interface ICache {
+
+ /**
+ * @return Geocode like GCxxxx
+ */
+ public String getGeocode();
+
+ /**
+ * @return Tradi, multi etc.
+ */
+ public String getType();
+
+ /**
+ * @return Displayed owner, might differ from the real owner
+ */
+ public String getOwner();
+
+ /**
+ * @return GC username of the owner
+ */
+ public String getOwnerReal();
+
+ /**
+ * @return Micro, small etc.
+ */
+ public String getSize();
+
+ /**
+ * @return Difficulty assessment
+ */
+ public Float getDifficulty();
+
+ /**
+ * @return Terrain assessment
+ */
+ public Float getTerrain();
+
+ /**
+ * @return Latitude, e.g. N 52° 12.345
+ */
+ public String getLatitude();
+
+ /**
+ * @return Longitude, e.g. E 9° 34.567
+ */
+ public String getLongitude();
+
+ /**
+ * @return true if the cache is disabled, false else
+ */
+ public boolean isDisabled();
+
+ /**
+ * @return true if the user is the owner of the cache, false else
+ */
+ public boolean isOwn();
+
+ /**
+ * @return true is the cache is archived, false else
+ */
+ public boolean isArchived();
+
+ /**
+ * @return true is the cache is a Premium Member cache only, false else
+ */
+ public boolean isMembersOnly();
+
+ /**
+ * @return Decrypted hint
+ */
+ public String getHint();
+
+ /**
+ * @return Description
+ */
+ public String getDescription();
+
+ /**
+ * @return Short Description
+ */
+ public String getShortDescription();
+
+ /**
+ * @return Name
+ */
+ public String getName();
+
+}
diff --git a/src/cgeo/geocaching/LogTemplateProvider.java b/src/cgeo/geocaching/LogTemplateProvider.java
index a02f585..bcb5d5c 100644
--- a/src/cgeo/geocaching/LogTemplateProvider.java
+++ b/src/cgeo/geocaching/LogTemplateProvider.java
@@ -1,155 +1,155 @@
-package cgeo.geocaching;
-
-import org.apache.commons.lang3.StringUtils;
-
-import android.util.Log;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * provides all the available templates for logging
- *
- */
-public class LogTemplateProvider {
- public static abstract class LogTemplate {
- private String template;
- private int resourceId;
-
- protected LogTemplate(String template, int resourceId) {
- this.template = template;
- this.resourceId = resourceId;
- }
-
- abstract String getValue(cgBase base, boolean offline);
-
- public int getResourceId() {
- return resourceId;
- }
-
- public int getItemId() {
- return template.hashCode();
- }
-
- public String getTemplateString() {
- return template;
- }
-
- protected String apply(String input, cgBase base, boolean offline) {
- if (input.contains("[" + template + "]")) {
- return input.replaceAll("\\[" + template + "\\]", getValue(base, offline));
- }
- return input;
- }
- }
-
- private static LogTemplate[] templates;
-
- public static LogTemplate[] getTemplates() {
- if (templates == null) {
- templates = new LogTemplate[] {
- new LogTemplate("DATE", R.string.init_signature_template_date) {
-
- @Override
- String getValue(final cgBase base, final boolean offline) {
- return base.formatFullDate(System.currentTimeMillis());
- }
- },
- new LogTemplate("TIME", R.string.init_signature_template_time) {
-
- @Override
- String getValue(final cgBase base, final boolean offline) {
- return base.formatTime(System.currentTimeMillis());
- }
- },
- new LogTemplate("DATETIME", R.string.init_signature_template_datetime) {
-
- @Override
- String getValue(final cgBase base, final boolean offline) {
- final long currentTime = System.currentTimeMillis();
- return base.formatFullDate(currentTime) + " " + base.formatTime(currentTime);
- }
- },
- new LogTemplate("USER", R.string.init_signature_template_user) {
-
- @Override
- String getValue(final cgBase base, final boolean offline) {
- return base.getUserName();
- }
- },
- new LogTemplate("NUMBER", R.string.init_signature_template_number) {
-
- @Override
- String getValue(final cgBase base, final boolean offline) {
- if (offline) {
- return "";
- }
- String findCount = "";
- final Map<String, String> params = new HashMap<String, String>();
- final String page = base.request(false, "www.geocaching.com", "/email/", "GET", params, false, false, false).getData();
- int current = parseFindCount(page);
-
- if (current >= 0) {
- findCount = String.valueOf(current + 1);
- }
- return findCount;
- }
- }
- };
- }
- return templates;
- }
-
- public static LogTemplate getTemplate(int itemId) {
- for (LogTemplate template : getTemplates()) {
- if (template.getItemId() == itemId) {
- return template;
- }
- }
- return null;
- }
-
- public static String applyTemplates(String signature, cgBase base, boolean offline) {
- if (signature == null) {
- return "";
- }
- String result = signature;
- for (LogTemplate template : getTemplates()) {
- result = template.apply(result, base, offline);
- }
- return result;
- }
-
- private static int parseFindCount(String page) {
- if (StringUtils.isBlank(page)) {
- return -1;
- }
-
- int findCount = -1;
-
- try {
- final Pattern findPattern = Pattern.compile("<strong><img.+?icon_smile.+?title=\"Caches Found\" /> ([,\\d]+)", Pattern.CASE_INSENSITIVE);
- final Matcher findMatcher = findPattern.matcher(page);
- if (findMatcher.find()) {
- if (findMatcher.groupCount() > 0) {
- String count = findMatcher.group(1);
-
- if (count != null) {
- if (count.length() == 0) {
- findCount = 0;
- } else {
- findCount = Integer.parseInt(count.replaceAll(",", ""));
- }
- }
- }
- }
- } catch (Exception e) {
- Log.w(cgSettings.tag, "cgBase.parseFindCount: " + e.toString());
- }
-
- return findCount;
- }
-
-}
+package cgeo.geocaching;
+
+import org.apache.commons.lang3.StringUtils;
+
+import android.util.Log;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * provides all the available templates for logging
+ *
+ */
+public class LogTemplateProvider {
+ public static abstract class LogTemplate {
+ private String template;
+ private int resourceId;
+
+ protected LogTemplate(String template, int resourceId) {
+ this.template = template;
+ this.resourceId = resourceId;
+ }
+
+ abstract String getValue(cgBase base, boolean offline);
+
+ public int getResourceId() {
+ return resourceId;
+ }
+
+ public int getItemId() {
+ return template.hashCode();
+ }
+
+ public String getTemplateString() {
+ return template;
+ }
+
+ protected String apply(String input, cgBase base, boolean offline) {
+ if (input.contains("[" + template + "]")) {
+ return input.replaceAll("\\[" + template + "\\]", getValue(base, offline));
+ }
+ return input;
+ }
+ }
+
+ private static LogTemplate[] templates;
+
+ public static LogTemplate[] getTemplates() {
+ if (templates == null) {
+ templates = new LogTemplate[] {
+ new LogTemplate("DATE", R.string.init_signature_template_date) {
+
+ @Override
+ String getValue(final cgBase base, final boolean offline) {
+ return base.formatFullDate(System.currentTimeMillis());
+ }
+ },
+ new LogTemplate("TIME", R.string.init_signature_template_time) {
+
+ @Override
+ String getValue(final cgBase base, final boolean offline) {
+ return base.formatTime(System.currentTimeMillis());
+ }
+ },
+ new LogTemplate("DATETIME", R.string.init_signature_template_datetime) {
+
+ @Override
+ String getValue(final cgBase base, final boolean offline) {
+ final long currentTime = System.currentTimeMillis();
+ return base.formatFullDate(currentTime) + " " + base.formatTime(currentTime);
+ }
+ },
+ new LogTemplate("USER", R.string.init_signature_template_user) {
+
+ @Override
+ String getValue(final cgBase base, final boolean offline) {
+ return base.getUserName();
+ }
+ },
+ new LogTemplate("NUMBER", R.string.init_signature_template_number) {
+
+ @Override
+ String getValue(final cgBase base, final boolean offline) {
+ if (offline) {
+ return "";
+ }
+ String findCount = "";
+ final Map<String, String> params = new HashMap<String, String>();
+ final String page = base.request(false, "www.geocaching.com", "/email/", "GET", params, false, false, false).getData();
+ int current = parseFindCount(page);
+
+ if (current >= 0) {
+ findCount = String.valueOf(current + 1);
+ }
+ return findCount;
+ }
+ }
+ };
+ }
+ return templates;
+ }
+
+ public static LogTemplate getTemplate(int itemId) {
+ for (LogTemplate template : getTemplates()) {
+ if (template.getItemId() == itemId) {
+ return template;
+ }
+ }
+ return null;
+ }
+
+ public static String applyTemplates(String signature, cgBase base, boolean offline) {
+ if (signature == null) {
+ return "";
+ }
+ String result = signature;
+ for (LogTemplate template : getTemplates()) {
+ result = template.apply(result, base, offline);
+ }
+ return result;
+ }
+
+ private static int parseFindCount(String page) {
+ if (StringUtils.isBlank(page)) {
+ return -1;
+ }
+
+ int findCount = -1;
+
+ try {
+ final Pattern findPattern = Pattern.compile("<strong><img.+?icon_smile.+?title=\"Caches Found\" /> ([,\\d]+)", Pattern.CASE_INSENSITIVE);
+ final Matcher findMatcher = findPattern.matcher(page);
+ if (findMatcher.find()) {
+ if (findMatcher.groupCount() > 0) {
+ String count = findMatcher.group(1);
+
+ if (count != null) {
+ if (count.length() == 0) {
+ findCount = 0;
+ } else {
+ findCount = Integer.parseInt(count.replaceAll(",", ""));
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ Log.w(cgSettings.tag, "cgBase.parseFindCount: " + e.toString());
+ }
+
+ return findCount;
+ }
+
+}
diff --git a/src/cgeo/geocaching/apps/LocusDataStorageProvider.java b/src/cgeo/geocaching/apps/LocusDataStorageProvider.java
index 9fc794f..fcc4ba2 100644
--- a/src/cgeo/geocaching/apps/LocusDataStorageProvider.java
+++ b/src/cgeo/geocaching/apps/LocusDataStorageProvider.java
@@ -1,70 +1,70 @@
-package cgeo.geocaching.apps;
-
-import menion.android.locus.addon.publiclib.geoData.PointsData;
-import menion.android.locus.addon.publiclib.utils.DataCursor;
-import menion.android.locus.addon.publiclib.utils.DataStorage;
-
-import android.content.ContentProvider;
-import android.content.ContentValues;
-import android.database.Cursor;
-import android.net.Uri;
-import android.os.Parcel;
-
-import java.util.ArrayList;
-
-/**
- * code provided by menion - developer of Locus
- */
-public class LocusDataStorageProvider extends ContentProvider {
-
- @Override
- public Cursor query(Uri aUri, String[] aProjection, String aSelection,
- String[] aSelectionArgs, String aSortOrder) {
-
- DataCursor cursor = new DataCursor(new String[] { "data" });
-
- ArrayList<PointsData> data = DataStorage.getData();
- if (data == null || data.size() == 0)
- return cursor;
-
- for (int i = 0; i < data.size(); i++) {
- // get byte array
- Parcel par = Parcel.obtain();
- data.get(i).writeToParcel(par, 0);
- byte[] byteData = par.marshall();
- // add to row
- cursor.addRow(new Object[] { byteData });
- }
- // data filled to cursor, clear reference to prevent some memory issue
- DataStorage.clearData();
- // now finally return filled cursor
- return cursor;
- }
-
- @Override
- public int delete(Uri uri, String selection, String[] selectionArgs) {
- return 0;
- }
-
- @Override
- public String getType(Uri uri) {
- return null;
- }
-
- @Override
- public Uri insert(Uri uri, ContentValues values) {
- return null;
- }
-
- @Override
- public boolean onCreate() {
- return false;
- }
-
- @Override
- public int update(Uri uri, ContentValues values, String selection,
- String[] selectionArgs) {
- return 0;
- }
-
-}
+package cgeo.geocaching.apps;
+
+import menion.android.locus.addon.publiclib.geoData.PointsData;
+import menion.android.locus.addon.publiclib.utils.DataCursor;
+import menion.android.locus.addon.publiclib.utils.DataStorage;
+
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.Parcel;
+
+import java.util.ArrayList;
+
+/**
+ * code provided by menion - developer of Locus
+ */
+public class LocusDataStorageProvider extends ContentProvider {
+
+ @Override
+ public Cursor query(Uri aUri, String[] aProjection, String aSelection,
+ String[] aSelectionArgs, String aSortOrder) {
+
+ DataCursor cursor = new DataCursor(new String[] { "data" });
+
+ ArrayList<PointsData> data = DataStorage.getData();
+ if (data == null || data.size() == 0)
+ return cursor;
+
+ for (int i = 0; i < data.size(); i++) {
+ // get byte array
+ Parcel par = Parcel.obtain();
+ data.get(i).writeToParcel(par, 0);
+ byte[] byteData = par.marshall();
+ // add to row
+ cursor.addRow(new Object[] { byteData });
+ }
+ // data filled to cursor, clear reference to prevent some memory issue
+ DataStorage.clearData();
+ // now finally return filled cursor
+ return cursor;
+ }
+
+ @Override
+ public int delete(Uri uri, String selection, String[] selectionArgs) {
+ return 0;
+ }
+
+ @Override
+ public String getType(Uri uri) {
+ return null;
+ }
+
+ @Override
+ public Uri insert(Uri uri, ContentValues values) {
+ return null;
+ }
+
+ @Override
+ public boolean onCreate() {
+ return false;
+ }
+
+ @Override
+ public int update(Uri uri, ContentValues values, String selection,
+ String[] selectionArgs) {
+ return 0;
+ }
+
+}
diff --git a/src/cgeo/geocaching/cgCoord.java b/src/cgeo/geocaching/cgCoord.java
index 09c9d91..17520ca 100644
--- a/src/cgeo/geocaching/cgCoord.java
+++ b/src/cgeo/geocaching/cgCoord.java
@@ -1,45 +1,45 @@
-package cgeo.geocaching;
-
-import cgeo.geocaching.geopoint.Geopoint;
-
-public class cgCoord {
-
- public Integer id = null;
- public String geocode = "";
- public String type = "cache";
- public String typeSpec = "traditional";
- public String name = "";
- public boolean found = false;
- public boolean disabled = false;
- public Geopoint coords = new Geopoint(0, 0);
- public Float difficulty = null;
- public Float terrain = null;
- public String size = null;
-
- public cgCoord() {
- }
-
- public cgCoord(cgCache cache) {
- disabled = cache.disabled;
- found = cache.found;
- geocode = cache.geocode;
- coords = cache.coords;
- name = cache.name;
- type = "cache";
- typeSpec = cache.type;
- difficulty = cache.difficulty;
- terrain = cache.terrain;
- size = cache.size;
- }
-
- public cgCoord(cgWaypoint waypoint) {
- id = waypoint.id;
- disabled = false;
- found = false;
- geocode = "";
- coords = waypoint.coords;
- name = waypoint.name;
- type = "waypoint";
- typeSpec = waypoint.type;
- }
-}
+package cgeo.geocaching;
+
+import cgeo.geocaching.geopoint.Geopoint;
+
+public class cgCoord {
+
+ public Integer id = null;
+ public String geocode = "";
+ public String type = "cache";
+ public String typeSpec = "traditional";
+ public String name = "";
+ public boolean found = false;
+ public boolean disabled = false;
+ public Geopoint coords = new Geopoint(0, 0);
+ public Float difficulty = null;
+ public Float terrain = null;
+ public String size = null;
+
+ public cgCoord() {
+ }
+
+ public cgCoord(cgCache cache) {
+ disabled = cache.disabled;
+ found = cache.found;
+ geocode = cache.geocode;
+ coords = cache.coords;
+ name = cache.name;
+ type = "cache";
+ typeSpec = cache.type;
+ difficulty = cache.difficulty;
+ terrain = cache.terrain;
+ size = cache.size;
+ }
+
+ public cgCoord(cgWaypoint waypoint) {
+ id = waypoint.id;
+ disabled = false;
+ found = false;
+ geocode = "";
+ coords = waypoint.coords;
+ name = waypoint.name;
+ type = "waypoint";
+ typeSpec = waypoint.type;
+ }
+}
diff --git a/src/cgeo/geocaching/cgDirection.java b/src/cgeo/geocaching/cgDirection.java
index c1c1f68..21ea883 100644
--- a/src/cgeo/geocaching/cgDirection.java
+++ b/src/cgeo/geocaching/cgDirection.java
@@ -1,75 +1,75 @@
-package cgeo.geocaching;
-
-import cgeo.geocaching.compatibility.Compatibility;
-
-import android.app.Activity;
-import android.content.Context;
-import android.hardware.Sensor;
-import android.hardware.SensorEvent;
-import android.hardware.SensorEventListener;
-import android.hardware.SensorManager;
-
-public class cgDirection {
- private cgDirection dir = null;
- private Context context = null;
- private SensorManager sensorManager = null;
- private cgeoSensorListener sensorListener = null;
- private cgUpdateDir dirUpdate = null;
-
- public Float directionNow = null;
-
- public cgDirection(Context contextIn, cgUpdateDir dirUpdateIn) {
- context = contextIn;
- dirUpdate = dirUpdateIn;
- sensorListener = new cgeoSensorListener();
- }
-
- public void initDir() {
- dir = this;
-
- if (sensorManager == null) {
- sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
- }
- sensorManager.registerListener(sensorListener, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_NORMAL);
- }
-
- public void closeDir() {
- if (sensorManager != null && sensorListener != null) {
- sensorManager.unregisterListener(sensorListener);
- }
- }
-
- public void replaceUpdate(cgUpdateDir dirUpdateIn) {
- dirUpdate = dirUpdateIn;
-
- if (dirUpdate != null && directionNow != null) {
- dirUpdate.updateDir(dir);
- }
- }
-
- private class cgeoSensorListener implements SensorEventListener {
- @Override
- public void onAccuracyChanged(Sensor sensor, int accuracy) {
- /*
- * There is a bug in Android, which appearently causes this method to be called every
- * time the sensor _value_ changed, even if the _accuracy_ did not change. So logging
- * this event leads to the log being flooded with multiple entries _per second_,
- * which I experienced when running cgeo in a building (with GPS and network being
- * unreliable).
- *
- * See for example https://code.google.com/p/android/issues/detail?id=14792
- */
-
- //Log.i(cgSettings.tag, "Compass' accuracy is low (" + accuracy + ")");
- }
-
- @Override
- public void onSensorChanged(SensorEvent event) {
- directionNow = Compatibility.getDirectionNow(event.values[0], (Activity) context);
-
- if (dirUpdate != null && directionNow != null) {
- dirUpdate.updateDir(dir);
- }
- }
- }
-}
+package cgeo.geocaching;
+
+import cgeo.geocaching.compatibility.Compatibility;
+
+import android.app.Activity;
+import android.content.Context;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+
+public class cgDirection {
+ private cgDirection dir = null;
+ private Context context = null;
+ private SensorManager sensorManager = null;
+ private cgeoSensorListener sensorListener = null;
+ private cgUpdateDir dirUpdate = null;
+
+ public Float directionNow = null;
+
+ public cgDirection(Context contextIn, cgUpdateDir dirUpdateIn) {
+ context = contextIn;
+ dirUpdate = dirUpdateIn;
+ sensorListener = new cgeoSensorListener();
+ }
+
+ public void initDir() {
+ dir = this;
+
+ if (sensorManager == null) {
+ sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
+ }
+ sensorManager.registerListener(sensorListener, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_NORMAL);
+ }
+
+ public void closeDir() {
+ if (sensorManager != null && sensorListener != null) {
+ sensorManager.unregisterListener(sensorListener);
+ }
+ }
+
+ public void replaceUpdate(cgUpdateDir dirUpdateIn) {
+ dirUpdate = dirUpdateIn;
+
+ if (dirUpdate != null && directionNow != null) {
+ dirUpdate.updateDir(dir);
+ }
+ }
+
+ private class cgeoSensorListener implements SensorEventListener {
+ @Override
+ public void onAccuracyChanged(Sensor sensor, int accuracy) {
+ /*
+ * There is a bug in Android, which appearently causes this method to be called every
+ * time the sensor _value_ changed, even if the _accuracy_ did not change. So logging
+ * this event leads to the log being flooded with multiple entries _per second_,
+ * which I experienced when running cgeo in a building (with GPS and network being
+ * unreliable).
+ *
+ * See for example https://code.google.com/p/android/issues/detail?id=14792
+ */
+
+ //Log.i(cgSettings.tag, "Compass' accuracy is low (" + accuracy + ")");
+ }
+
+ @Override
+ public void onSensorChanged(SensorEvent event) {
+ directionNow = Compatibility.getDirectionNow(event.values[0], (Activity) context);
+
+ if (dirUpdate != null && directionNow != null) {
+ dirUpdate.updateDir(dir);
+ }
+ }
+ }
+}
diff --git a/src/cgeo/geocaching/enumerations/CacheSize.java b/src/cgeo/geocaching/enumerations/CacheSize.java
index 901be9e..9ea82bb 100644
--- a/src/cgeo/geocaching/enumerations/CacheSize.java
+++ b/src/cgeo/geocaching/enumerations/CacheSize.java
@@ -1,37 +1,37 @@
-package cgeo.geocaching.enumerations;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Enum listing cache sizes
- *
- * @author koem
- */
-public enum CacheSize {
- 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;
-
- private CacheSize(String cgeoId, int comparable) {
- this.cgeoId = cgeoId;
- this.comparable = comparable;
- }
-
- 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);
- }
- FIND_BY_CGEOID = Collections.unmodifiableMap(mapping);
- }
-
-}
+package cgeo.geocaching.enumerations;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Enum listing cache sizes
+ *
+ * @author koem
+ */
+public enum CacheSize {
+ 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;
+
+ private CacheSize(String cgeoId, int comparable) {
+ this.cgeoId = cgeoId;
+ this.comparable = comparable;
+ }
+
+ 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);
+ }
+ FIND_BY_CGEOID = Collections.unmodifiableMap(mapping);
+ }
+
+}
diff --git a/src/cgeo/geocaching/enumerations/CacheType.java b/src/cgeo/geocaching/enumerations/CacheType.java
index f30afc9..6acc3a4 100644
--- a/src/cgeo/geocaching/enumerations/CacheType.java
+++ b/src/cgeo/geocaching/enumerations/CacheType.java
@@ -1,52 +1,52 @@
-package cgeo.geocaching.enumerations;
-
-import cgeo.geocaching.R;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Enum listing all cache types
- *
- * @author koem
- */
-public enum CacheType {
- 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),
- 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);
-
- public final String cgeoId;
- public final String pattern;
- public final String guid;
- public final int stringId;
-
- private CacheType(String cgeoId, String pattern, String guid, int stringId) {
- this.cgeoId = cgeoId;
- this.pattern = pattern;
- this.guid = guid;
- this.stringId = stringId;
- }
-
- 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);
- }
- FIND_BY_CGEOID = Collections.unmodifiableMap(mapping);
- }
-
-}
+package cgeo.geocaching.enumerations;
+
+import cgeo.geocaching.R;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Enum listing all cache types
+ *
+ * @author koem
+ */
+public enum CacheType {
+ 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),
+ 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);
+
+ public final String cgeoId;
+ public final String pattern;
+ public final String guid;
+ public final int stringId;
+
+ private CacheType(String cgeoId, String pattern, String guid, int stringId) {
+ this.cgeoId = cgeoId;
+ this.pattern = pattern;
+ this.guid = guid;
+ this.stringId = stringId;
+ }
+
+ 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);
+ }
+ FIND_BY_CGEOID = Collections.unmodifiableMap(mapping);
+ }
+
+}
diff --git a/src/cgeo/geocaching/enumerations/WaypointType.java b/src/cgeo/geocaching/enumerations/WaypointType.java
index cd4b31c..84ef59a 100644
--- a/src/cgeo/geocaching/enumerations/WaypointType.java
+++ b/src/cgeo/geocaching/enumerations/WaypointType.java
@@ -1,36 +1,36 @@
-package cgeo.geocaching.enumerations;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Enum listing waypoint types
- *
- * @author koem
- */
-public enum WaypointType {
- FLAG ("flag"),
- OWN ("own"),
- PKG ("pkg"),
- PUZZLE ("puzzle"),
- STAGE ("stage"),
- TRAILHEAD ("trailhead"),
- WAYPOINT ("waypoint");
-
- public final String cgeoId;
-
- private WaypointType(String cgeoId) {
- this.cgeoId = cgeoId;
- }
-
- 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);
- }
- FIND_BY_CGEOID = Collections.unmodifiableMap(mapping);
- }
-
-}
+package cgeo.geocaching.enumerations;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Enum listing waypoint types
+ *
+ * @author koem
+ */
+public enum WaypointType {
+ FLAG ("flag"),
+ OWN ("own"),
+ PKG ("pkg"),
+ PUZZLE ("puzzle"),
+ STAGE ("stage"),
+ TRAILHEAD ("trailhead"),
+ WAYPOINT ("waypoint");
+
+ public final String cgeoId;
+
+ private WaypointType(String cgeoId) {
+ this.cgeoId = cgeoId;
+ }
+
+ 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);
+ }
+ FIND_BY_CGEOID = Collections.unmodifiableMap(mapping);
+ }
+
+}
diff --git a/src/cgeo/geocaching/files/FileParser.java b/src/cgeo/geocaching/files/FileParser.java
index c7f16c8..158d390 100644
--- a/src/cgeo/geocaching/files/FileParser.java
+++ b/src/cgeo/geocaching/files/FileParser.java
@@ -1,53 +1,53 @@
-package cgeo.geocaching.files;
-
-import cgeo.geocaching.cgBase;
-import cgeo.geocaching.cgCache;
-import cgeo.geocaching.cgSearch;
-
-import android.os.Handler;
-import android.os.Message;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.Date;
-
-public abstract class FileParser {
- protected static StringBuilder readFile(File file)
- throws FileNotFoundException, IOException {
- StringBuilder buffer = new StringBuilder();
- BufferedReader input = new BufferedReader(new FileReader(file));
- try {
- String line = null;
- while ((line = input.readLine()) != null) {
- buffer.append(line);
- }
- } finally {
- input.close();
- }
- return buffer;
- }
-
- static void showFinishedMessage(Handler handler, cgSearch search) {
- if (handler != null) {
- final Message msg = new Message();
- msg.obj = search.getCount();
- handler.sendMessage(msg);
- }
- }
-
- protected static void fixCache(cgCache cache) {
- cache.latitudeString = cgBase.formatLatitude(cache.coords.getLatitude(), true);
- cache.longitudeString = cgBase.formatLongitude(cache.coords.getLongitude(), true);
- if (cache.inventory != null) {
- cache.inventoryItems = cache.inventory.size();
- } else {
- cache.inventoryItems = 0;
- }
- cache.updated = new Date().getTime();
- cache.detailedUpdate = new Date().getTime();
- }
-
-}
+package cgeo.geocaching.files;
+
+import cgeo.geocaching.cgBase;
+import cgeo.geocaching.cgCache;
+import cgeo.geocaching.cgSearch;
+
+import android.os.Handler;
+import android.os.Message;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Date;
+
+public abstract class FileParser {
+ protected static StringBuilder readFile(File file)
+ throws FileNotFoundException, IOException {
+ StringBuilder buffer = new StringBuilder();
+ BufferedReader input = new BufferedReader(new FileReader(file));
+ try {
+ String line = null;
+ while ((line = input.readLine()) != null) {
+ buffer.append(line);
+ }
+ } finally {
+ input.close();
+ }
+ return buffer;
+ }
+
+ static void showFinishedMessage(Handler handler, cgSearch search) {
+ if (handler != null) {
+ final Message msg = new Message();
+ msg.obj = search.getCount();
+ handler.sendMessage(msg);
+ }
+ }
+
+ protected static void fixCache(cgCache cache) {
+ cache.latitudeString = cgBase.formatLatitude(cache.coords.getLatitude(), true);
+ cache.longitudeString = cgBase.formatLongitude(cache.coords.getLongitude(), true);
+ if (cache.inventory != null) {
+ cache.inventoryItems = cache.inventory.size();
+ } else {
+ cache.inventoryItems = 0;
+ }
+ cache.updated = new Date().getTime();
+ cache.detailedUpdate = new Date().getTime();
+ }
+
+}
diff --git a/src/cgeo/geocaching/files/GPX10Parser.java b/src/cgeo/geocaching/files/GPX10Parser.java
index be3c857..c3b95b2 100644
--- a/src/cgeo/geocaching/files/GPX10Parser.java
+++ b/src/cgeo/geocaching/files/GPX10Parser.java
@@ -1,20 +1,20 @@
-package cgeo.geocaching.files;
-
-import cgeo.geocaching.cgSearch;
-import cgeo.geocaching.cgeoapplication;
-
-import android.sax.Element;
-
-public final class GPX10Parser extends GPXParser {
-
- public GPX10Parser(cgeoapplication appIn, int listIdIn,
- cgSearch searchIn) {
- super(appIn, listIdIn, searchIn, "http://www.topografix.com/GPX/1/0", "1.0");
- }
-
- @Override
- protected Element getCacheParent(Element waypoint) {
- return waypoint;
- }
-
-}
+package cgeo.geocaching.files;
+
+import cgeo.geocaching.cgSearch;
+import cgeo.geocaching.cgeoapplication;
+
+import android.sax.Element;
+
+public final class GPX10Parser extends GPXParser {
+
+ public GPX10Parser(cgeoapplication appIn, int listIdIn,
+ cgSearch searchIn) {
+ super(appIn, listIdIn, searchIn, "http://www.topografix.com/GPX/1/0", "1.0");
+ }
+
+ @Override
+ protected Element getCacheParent(Element waypoint) {
+ return waypoint;
+ }
+
+}
diff --git a/src/cgeo/geocaching/files/GPX11Parser.java b/src/cgeo/geocaching/files/GPX11Parser.java
index 9370450..4c8960b 100644
--- a/src/cgeo/geocaching/files/GPX11Parser.java
+++ b/src/cgeo/geocaching/files/GPX11Parser.java
@@ -1,20 +1,20 @@
-package cgeo.geocaching.files;
-
-import cgeo.geocaching.cgSearch;
-import cgeo.geocaching.cgeoapplication;
-
-import android.sax.Element;
-
-public final class GPX11Parser extends GPXParser {
-
- public GPX11Parser(cgeoapplication appIn, int listIdIn,
- cgSearch searchIn) {
- super(appIn, listIdIn, searchIn, "http://www.topografix.com/GPX/1/1", "1.1");
- }
-
- @Override
- protected Element getCacheParent(Element waypoint) {
- return waypoint.getChild(namespace, "extensions");
- }
-
-}
+package cgeo.geocaching.files;
+
+import cgeo.geocaching.cgSearch;
+import cgeo.geocaching.cgeoapplication;
+
+import android.sax.Element;
+
+public final class GPX11Parser extends GPXParser {
+
+ public GPX11Parser(cgeoapplication appIn, int listIdIn,
+ cgSearch searchIn) {
+ super(appIn, listIdIn, searchIn, "http://www.topografix.com/GPX/1/1", "1.1");
+ }
+
+ @Override
+ protected Element getCacheParent(Element waypoint) {
+ return waypoint.getChild(namespace, "extensions");
+ }
+
+}
diff --git a/src/cgeo/geocaching/files/LocParser.java b/src/cgeo/geocaching/files/LocParser.java
index f631e10..0cbb297 100644
--- a/src/cgeo/geocaching/files/LocParser.java
+++ b/src/cgeo/geocaching/files/LocParser.java
@@ -1,179 +1,179 @@
-package cgeo.geocaching.files;
-
-import cgeo.geocaching.cgBase;
-import cgeo.geocaching.cgCache;
-import cgeo.geocaching.cgCacheWrap;
-import cgeo.geocaching.cgCoord;
-import cgeo.geocaching.cgSearch;
-import cgeo.geocaching.cgSettings;
-import cgeo.geocaching.cgeoapplication;
-import cgeo.geocaching.geopoint.Geopoint;
-
-import org.apache.commons.lang3.StringUtils;
-
-import android.os.Handler;
-import android.util.Log;
-
-import java.io.File;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.UUID;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public final class LocParser extends FileParser {
- private static final Pattern patternGeocode = Pattern
- .compile("name id=\"([^\"]+)\"");
- private static final Pattern patternLat = Pattern
- .compile("lat=\"([^\"]+)\"");
- private static final Pattern patternLon = Pattern
- .compile("lon=\"([^\"]+)\"");
- // premium only >>
- private static final Pattern patternDifficulty = Pattern
- .compile("<difficulty>([^<]+)</difficulty>");
- private static final Pattern patternTerrain = Pattern
- .compile("<terrain>([^<]+)</terrain>");
- private static final Pattern patternContainer = Pattern
- .compile("<container>([^<]+)</container>");
- private static final Pattern patternName = Pattern.compile("CDATA\\[([^\\]]+)\\]");
-
- public static void parseLoc(final cgCacheWrap caches,
- final String fileContent) {
- final Map<String, cgCoord> cidCoords = parseCoordinates(fileContent);
-
- // save found cache coordinates
- for (cgCache cache : caches.cacheList) {
- if (cidCoords.containsKey(cache.geocode)) {
- cgCoord coord = cidCoords.get(cache.geocode);
-
- copyCoordToCache(coord, cache);
- }
- }
- }
-
- private static void copyCoordToCache(final cgCoord coord, final cgCache cache) {
- cache.coords = coord.coords;
- cache.difficulty = coord.difficulty;
- cache.terrain = coord.terrain;
- cache.size = coord.size;
- cache.geocode = coord.geocode.toUpperCase();
- if (StringUtils.isBlank(cache.name)) {
- cache.name = coord.name;
- }
- }
-
- private static Map<String, cgCoord> parseCoordinates(
- final String fileContent) {
- final Map<String, cgCoord> coords = new HashMap<String, cgCoord>();
- if (StringUtils.isBlank(fileContent)) {
- return coords;
- }
- // >> premium only
-
- final String[] points = fileContent.split("<waypoint>");
-
- // parse coordinates
- for (String pointString : points) {
- final cgCoord pointCoord = new cgCoord();
-
- final Matcher matcherGeocode = patternGeocode.matcher(pointString);
- if (matcherGeocode.find()) {
- String geocode = matcherGeocode.group(1).trim().toUpperCase();
- pointCoord.name = geocode;
- pointCoord.geocode = geocode;
- }
- final Matcher matcherName = patternName.matcher(pointString);
- if (matcherName.find()) {
- String name = matcherName.group(1).trim();
- int pos = name.indexOf(" by ");
- if (pos > 0) {
- name = name.substring(0, pos).trim();
- }
- pointCoord.name = name;
- }
- final Matcher matcherLat = patternLat.matcher(pointString);
- final Matcher matcherLon = patternLon.matcher(pointString);
- if (matcherLat.find() && matcherLon.find()) {
- final Map<String, Object> tmpLat = cgBase.parseCoordinate(matcherLat.group(1).trim(), "lat");
- final Map<String, Object> tmpLon = cgBase.parseCoordinate(matcherLon.group(1).trim(), "lon");
- pointCoord.coords = new Geopoint((Double) tmpLat.get("coordinate"),
- (Double) tmpLon.get("coordinate"));
- }
- final Matcher matcherDifficulty = patternDifficulty.matcher(pointString);
- if (matcherDifficulty.find()) {
- pointCoord.difficulty = new Float(matcherDifficulty.group(1)
- .trim());
- }
- final Matcher matcherTerrain = patternTerrain.matcher(pointString);
- if (matcherTerrain.find()) {
- pointCoord.terrain = new Float(matcherTerrain.group(1).trim());
- }
- final Matcher matcherContainer = patternContainer.matcher(pointString);
- if (matcherContainer.find()) {
- final int size = Integer.parseInt(matcherContainer.group(1)
- .trim());
-
- if (size == 1) {
- pointCoord.size = "not chosen";
- } else if (size == 2) {
- pointCoord.size = "micro";
- } else if (size == 3) {
- pointCoord.size = "regular";
- } else if (size == 4) {
- pointCoord.size = "large";
- } else if (size == 5) {
- pointCoord.size = "virtual";
- } else if (size == 6) {
- pointCoord.size = "other";
- } else if (size == 8) {
- pointCoord.size = "small";
- } else {
- pointCoord.size = "unknown";
- }
- }
-
- if (StringUtils.isNotBlank(pointCoord.geocode)) {
- coords.put(pointCoord.geocode, pointCoord);
- }
- }
-
- Log.i(cgSettings.tag,
- "Coordinates found in .loc file: " + coords.size());
- return coords;
- }
-
- public static UUID parseLoc(cgeoapplication app, File file, int listId,
- Handler handler) {
- cgSearch search = new cgSearch();
- UUID searchId = null;
-
- try {
- Map<String, cgCoord> coords = parseCoordinates(readFile(file).toString());
- final cgCacheWrap caches = new cgCacheWrap();
- for (Entry<String, cgCoord> entry : coords.entrySet()) {
- cgCoord coord = entry.getValue();
- if (StringUtils.isBlank(coord.geocode) || StringUtils.isBlank(coord.name)) {
- continue;
- }
- cgCache cache = new cgCache();
- copyCoordToCache(coord, cache);
- caches.cacheList.add(cache);
-
- fixCache(cache);
- cache.reason = listId;
- cache.detailed = false;
-
- app.addCacheToSearch(search, cache);
- }
- caches.totalCnt = caches.cacheList.size();
- showFinishedMessage(handler, search);
- } catch (Exception e) {
- Log.e(cgSettings.tag, "cgBase.parseGPX: " + e.toString());
- }
-
- Log.i(cgSettings.tag, "Caches found in .gpx file: " + app.getCount(searchId));
-
- return search.getCurrentId();
- }
-}
+package cgeo.geocaching.files;
+
+import cgeo.geocaching.cgBase;
+import cgeo.geocaching.cgCache;
+import cgeo.geocaching.cgCacheWrap;
+import cgeo.geocaching.cgCoord;
+import cgeo.geocaching.cgSearch;
+import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.cgeoapplication;
+import cgeo.geocaching.geopoint.Geopoint;
+
+import org.apache.commons.lang3.StringUtils;
+
+import android.os.Handler;
+import android.util.Log;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.UUID;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public final class LocParser extends FileParser {
+ private static final Pattern patternGeocode = Pattern
+ .compile("name id=\"([^\"]+)\"");
+ private static final Pattern patternLat = Pattern
+ .compile("lat=\"([^\"]+)\"");
+ private static final Pattern patternLon = Pattern
+ .compile("lon=\"([^\"]+)\"");
+ // premium only >>
+ private static final Pattern patternDifficulty = Pattern
+ .compile("<difficulty>([^<]+)</difficulty>");
+ private static final Pattern patternTerrain = Pattern
+ .compile("<terrain>([^<]+)</terrain>");
+ private static final Pattern patternContainer = Pattern
+ .compile("<container>([^<]+)</container>");
+ private static final Pattern patternName = Pattern.compile("CDATA\\[([^\\]]+)\\]");
+
+ public static void parseLoc(final cgCacheWrap caches,
+ final String fileContent) {
+ final Map<String, cgCoord> cidCoords = parseCoordinates(fileContent);
+
+ // save found cache coordinates
+ for (cgCache cache : caches.cacheList) {
+ if (cidCoords.containsKey(cache.geocode)) {
+ cgCoord coord = cidCoords.get(cache.geocode);
+
+ copyCoordToCache(coord, cache);
+ }
+ }
+ }
+
+ private static void copyCoordToCache(final cgCoord coord, final cgCache cache) {
+ cache.coords = coord.coords;
+ cache.difficulty = coord.difficulty;
+ cache.terrain = coord.terrain;
+ cache.size = coord.size;
+ cache.geocode = coord.geocode.toUpperCase();
+ if (StringUtils.isBlank(cache.name)) {
+ cache.name = coord.name;
+ }
+ }
+
+ private static Map<String, cgCoord> parseCoordinates(
+ final String fileContent) {
+ final Map<String, cgCoord> coords = new HashMap<String, cgCoord>();
+ if (StringUtils.isBlank(fileContent)) {
+ return coords;
+ }
+ // >> premium only
+
+ final String[] points = fileContent.split("<waypoint>");
+
+ // parse coordinates
+ for (String pointString : points) {
+ final cgCoord pointCoord = new cgCoord();
+
+ final Matcher matcherGeocode = patternGeocode.matcher(pointString);
+ if (matcherGeocode.find()) {
+ String geocode = matcherGeocode.group(1).trim().toUpperCase();
+ pointCoord.name = geocode;
+ pointCoord.geocode = geocode;
+ }
+ final Matcher matcherName = patternName.matcher(pointString);
+ if (matcherName.find()) {
+ String name = matcherName.group(1).trim();
+ int pos = name.indexOf(" by ");
+ if (pos > 0) {
+ name = name.substring(0, pos).trim();
+ }
+ pointCoord.name = name;
+ }
+ final Matcher matcherLat = patternLat.matcher(pointString);
+ final Matcher matcherLon = patternLon.matcher(pointString);
+ if (matcherLat.find() && matcherLon.find()) {
+ final Map<String, Object> tmpLat = cgBase.parseCoordinate(matcherLat.group(1).trim(), "lat");
+ final Map<String, Object> tmpLon = cgBase.parseCoordinate(matcherLon.group(1).trim(), "lon");
+ pointCoord.coords = new Geopoint((Double) tmpLat.get("coordinate"),
+ (Double) tmpLon.get("coordinate"));
+ }
+ final Matcher matcherDifficulty = patternDifficulty.matcher(pointString);
+ if (matcherDifficulty.find()) {
+ pointCoord.difficulty = new Float(matcherDifficulty.group(1)
+ .trim());
+ }
+ final Matcher matcherTerrain = patternTerrain.matcher(pointString);
+ if (matcherTerrain.find()) {
+ pointCoord.terrain = new Float(matcherTerrain.group(1).trim());
+ }
+ final Matcher matcherContainer = patternContainer.matcher(pointString);
+ if (matcherContainer.find()) {
+ final int size = Integer.parseInt(matcherContainer.group(1)
+ .trim());
+
+ if (size == 1) {
+ pointCoord.size = "not chosen";
+ } else if (size == 2) {
+ pointCoord.size = "micro";
+ } else if (size == 3) {
+ pointCoord.size = "regular";
+ } else if (size == 4) {
+ pointCoord.size = "large";
+ } else if (size == 5) {
+ pointCoord.size = "virtual";
+ } else if (size == 6) {
+ pointCoord.size = "other";
+ } else if (size == 8) {
+ pointCoord.size = "small";
+ } else {
+ pointCoord.size = "unknown";
+ }
+ }
+
+ if (StringUtils.isNotBlank(pointCoord.geocode)) {
+ coords.put(pointCoord.geocode, pointCoord);
+ }
+ }
+
+ Log.i(cgSettings.tag,
+ "Coordinates found in .loc file: " + coords.size());
+ return coords;
+ }
+
+ public static UUID parseLoc(cgeoapplication app, File file, int listId,
+ Handler handler) {
+ cgSearch search = new cgSearch();
+ UUID searchId = null;
+
+ try {
+ Map<String, cgCoord> coords = parseCoordinates(readFile(file).toString());
+ final cgCacheWrap caches = new cgCacheWrap();
+ for (Entry<String, cgCoord> entry : coords.entrySet()) {
+ cgCoord coord = entry.getValue();
+ if (StringUtils.isBlank(coord.geocode) || StringUtils.isBlank(coord.name)) {
+ continue;
+ }
+ cgCache cache = new cgCache();
+ copyCoordToCache(coord, cache);
+ caches.cacheList.add(cache);
+
+ fixCache(cache);
+ cache.reason = listId;
+ cache.detailed = false;
+
+ app.addCacheToSearch(search, cache);
+ }
+ caches.totalCnt = caches.cacheList.size();
+ showFinishedMessage(handler, search);
+ } catch (Exception e) {
+ Log.e(cgSettings.tag, "cgBase.parseGPX: " + e.toString());
+ }
+
+ Log.i(cgSettings.tag, "Caches found in .gpx file: " + app.getCount(searchId));
+
+ return search.getCurrentId();
+ }
+}
diff --git a/src/cgeo/geocaching/utils/CollectionUtils.java b/src/cgeo/geocaching/utils/CollectionUtils.java
index b7c6f3f..06e2419 100644
--- a/src/cgeo/geocaching/utils/CollectionUtils.java
+++ b/src/cgeo/geocaching/utils/CollectionUtils.java
@@ -1,24 +1,24 @@
-package cgeo.geocaching.utils;
-
-import java.util.List;
-import java.util.Map;
-
-public class CollectionUtils {
-
- public static <T> boolean isEmpty(List<T> list) {
- return (list != null && list.size() == 0);
- }
-
- public static <T, T2> boolean isEmpty(Map<T, T2> map) {
- return (map != null && map.size() == 0);
- }
-
- public static <T> boolean isNotEmpty(List<T> list) {
- return (list != null && list.size() != 0);
- }
-
- public static <T, T2> boolean isNotEmpty(Map<T, T2> map) {
- return (map != null && map.size() != 0);
- }
-
-}
+package cgeo.geocaching.utils;
+
+import java.util.List;
+import java.util.Map;
+
+public class CollectionUtils {
+
+ public static <T> boolean isEmpty(List<T> list) {
+ return (list != null && list.size() == 0);
+ }
+
+ public static <T, T2> boolean isEmpty(Map<T, T2> map) {
+ return (map != null && map.size() == 0);
+ }
+
+ public static <T> boolean isNotEmpty(List<T> list) {
+ return (list != null && list.size() != 0);
+ }
+
+ public static <T, T2> boolean isNotEmpty(Map<T, T2> map) {
+ return (map != null && map.size() != 0);
+ }
+
+}