aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cgeo/geocaching/FileList.java (renamed from src/cgeo/geocaching/cgFileList.java)69
-rw-r--r--src/cgeo/geocaching/FileParser.java52
-rw-r--r--src/cgeo/geocaching/GPX10Parser.java17
-rw-r--r--src/cgeo/geocaching/GPX11Parser.java17
-rw-r--r--src/cgeo/geocaching/GPXParser.java (renamed from src/cgeo/geocaching/cgGPXParser.java)81
-rw-r--r--src/cgeo/geocaching/LocParser.java170
-rw-r--r--src/cgeo/geocaching/cgBase.java102
-rw-r--r--src/cgeo/geocaching/cgData.java2
-rw-r--r--src/cgeo/geocaching/cgSelectMapfile.java11
-rw-r--r--src/cgeo/geocaching/cgWaypoint.java4
-rw-r--r--src/cgeo/geocaching/cgeodetail.java8
-rw-r--r--src/cgeo/geocaching/cgeogpxes.java23
-rw-r--r--src/cgeo/geocaching/cgeovisit.java10
-rw-r--r--src/cgeo/geocaching/cgeowaypoint.java18
14 files changed, 372 insertions, 212 deletions
diff --git a/src/cgeo/geocaching/cgFileList.java b/src/cgeo/geocaching/FileList.java
index 3536ba6..545ad52 100644
--- a/src/cgeo/geocaching/cgFileList.java
+++ b/src/cgeo/geocaching/FileList.java
@@ -13,7 +13,7 @@ import android.util.Log;
import android.widget.ArrayAdapter;
import cgeo.geocaching.activity.AbstractListActivity;
-public abstract class cgFileList<T extends ArrayAdapter<File>> extends AbstractListActivity {
+public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractListActivity {
private ArrayList<File> files = new ArrayList<File>();
private T adapter = null;
@@ -61,6 +61,7 @@ public abstract class cgFileList<T extends ArrayAdapter<File>> extends AbstractL
}
}
};
+ private String[] extensions;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -175,58 +176,64 @@ public abstract class cgFileList<T extends ArrayAdapter<File>> extends AbstractL
}
}
- /**
- * Get the file extension to search for
- * @return The file extension
- */
- protected abstract String getFileExtension();
-
- private void listDir(ArrayList<File> list, File directory) {
- if (directory == null || directory.isDirectory() == false || directory.canRead() == false) {
+ private void listDir(ArrayList<File> result, File directory) {
+ if (directory == null || !directory.isDirectory() || !directory.canRead()) {
return;
}
- final File[] listPre = directory.listFiles();
- String fileExt = getFileExtension();
+ final File[] files = directory.listFiles();
- if (listPre != null && listPre.length > 0) {
- final int listCnt = listPre.length;
-
- for (int i = 0; i < listCnt; i++) {
+ if (files != null && files.length > 0) {
+ for (File file : files) {
if (endSearching) {
return;
}
-
- if (listPre[i].canRead() && listPre[i].isFile()) {
- final String[] nameParts = listPre[i].getName().split("\\.");
- if (nameParts.length > 1) {
- final String extension = nameParts[(nameParts.length - 1)].toLowerCase();
-
- if (extension.equals(fileExt) == false) {
- continue;
+ if (!file.canRead()) {
+ continue;
+ }
+ String name = file.getName();
+ if (file.isFile()) {
+ for (String ext : extensions) {
+ int extLength = ext.length();
+ if (name.length() > extLength && name.substring(name.length() - extLength, name.length()).equalsIgnoreCase(ext)) {
+ result.add(file); // add file to list
+ break;
}
- } else {
- continue; // file has no extension
}
- list.add(listPre[i]); // add file to list
- } else if (listPre[i].canRead() && listPre[i].isDirectory()) {
- final Message msg = new Message();
- String name = listPre[i].getName();
- if (name.substring(0, 1).equals(".")) {
+ } else if (file.isDirectory()) {
+ if (name.charAt(0) == '.') {
continue; // skip hidden directories
}
if (name.length() > 16) {
name = name.substring(0, 14) + "...";
}
+ final Message msg = new Message();
msg.obj = name;
changeWaitDialogHandler.sendMessage(msg);
- listDir(list, listPre[i]); // go deeper
+ listDir(result, file); // go deeper
}
}
}
return;
}
+
+ public FileList(final String extension) {
+ setExtensions(new String[] {extension});
+ }
+
+ public FileList(final String[] extensions) {
+ setExtensions(extensions);
+ }
+
+ private void setExtensions(String[] extensionsIn) {
+ for (String extension : extensionsIn) {
+ if (!extension.startsWith(".")) {
+ extension = "." + extension;
+ }
+ }
+ extensions = extensionsIn;
+ }
}
diff --git a/src/cgeo/geocaching/FileParser.java b/src/cgeo/geocaching/FileParser.java
new file mode 100644
index 0000000..d67c888
--- /dev/null
+++ b/src/cgeo/geocaching/FileParser.java
@@ -0,0 +1,52 @@
+package cgeo.geocaching;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Date;
+
+import android.os.Handler;
+import android.os.Message;
+
+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.formatCoordinate(cache.latitude, "lat", true);
+ cache.longitudeString = cgBase.formatCoordinate(cache.longitude, "lon", 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/GPX10Parser.java b/src/cgeo/geocaching/GPX10Parser.java
new file mode 100644
index 0000000..a1bcef4
--- /dev/null
+++ b/src/cgeo/geocaching/GPX10Parser.java
@@ -0,0 +1,17 @@
+package cgeo.geocaching;
+
+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/GPX11Parser.java b/src/cgeo/geocaching/GPX11Parser.java
new file mode 100644
index 0000000..0f946b3
--- /dev/null
+++ b/src/cgeo/geocaching/GPX11Parser.java
@@ -0,0 +1,17 @@
+package cgeo.geocaching;
+
+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/cgGPXParser.java b/src/cgeo/geocaching/GPXParser.java
index 2e9b671..000c745 100644
--- a/src/cgeo/geocaching/cgGPXParser.java
+++ b/src/cgeo/geocaching/GPXParser.java
@@ -5,7 +5,6 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -13,7 +12,6 @@ import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import android.os.Handler;
-import android.os.Message;
import android.sax.Element;
import android.sax.EndElementListener;
import android.sax.EndTextElementListener;
@@ -23,12 +21,12 @@ import android.text.Html;
import android.util.Log;
import android.util.Xml;
-public class cgGPXParser {
+public abstract class GPXParser extends FileParser {
- private cgeoapplication app = null;
- private int listId = 1;
private cgSearch search = null;
private Handler handler = null;
+ private cgeoapplication app = null;
+ private int listId = 1;
private cgCache cache = new cgCache();
private cgTrackable trackable = new cgTrackable();
private cgLog log = new cgLog();
@@ -36,14 +34,15 @@ public class cgGPXParser {
private boolean htmlLong = true;
private String type = null;
private String sym = null;
- private String ns = null;
+ protected String namespace = null;
private ArrayList<String> nsGCList = new ArrayList<String>();
- private final Pattern patternGeocode = Pattern.compile("(GC[0-9A-Z]+)", Pattern.CASE_INSENSITIVE);
+ private static final Pattern patternGeocode = Pattern.compile("(GC[0-9A-Z]+)", Pattern.CASE_INSENSITIVE);
private String name = null;
private String cmt = null;
private String desc = null;
+ private String version;
- public cgGPXParser(cgeoapplication appIn, int listIdIn, cgSearch searchIn) {
+ public GPXParser(cgeoapplication appIn, int listIdIn, cgSearch searchIn, String namespaceIn, String versionIn) {
app = appIn;
listId = listIdIn;
search = searchIn;
@@ -51,21 +50,19 @@ public class cgGPXParser {
nsGCList.add("http://www.groundspeak.com/cache/1/1"); // PQ 1.1
nsGCList.add("http://www.groundspeak.com/cache/1/0/1"); // PQ 1.0.1
nsGCList.add("http://www.groundspeak.com/cache/1/0"); // PQ 1.0
+
+ namespace = namespaceIn;
+ version = versionIn;
}
- public long parse(File file, int version, Handler handlerIn) {
+ public long parse(File file, Handler handlerIn) {
handler = handlerIn;
if (file == null) {
return 0l;
}
- if (version == 11) {
- ns = "http://www.topografix.com/GPX/1/1"; // GPX 1.1
- } else {
- ns = "http://www.topografix.com/GPX/1/0"; // GPX 1.0
- }
- final RootElement root = new RootElement(ns, "gpx");
- final Element waypoint = root.getChild(ns, "wpt");
+ final RootElement root = new RootElement(namespace, "gpx");
+ final Element waypoint = root.getChild(namespace, "wpt");
// waypoint - attributes
waypoint.setStartElementListener(new StartElementListener() {
@@ -133,26 +130,14 @@ public class cgGPXParser {
&& ((type == null && sym == null)
|| (type != null && type.indexOf("geocache") > -1)
|| (sym != null && sym.indexOf("geocache") > -1))) {
- cache.latitudeString = cgBase.formatCoordinate(cache.latitude, "lat", true);
- cache.longitudeString = cgBase.formatCoordinate(cache.longitude, "lon", true);
- if (cache.inventory != null) {
- cache.inventoryItems = cache.inventory.size();
- } else {
- cache.inventoryItems = 0;
- }
+ fixCache(cache);
cache.reason = listId;
- cache.updated = new Date().getTime();
- cache.detailedUpdate = new Date().getTime();
cache.detailed = true;
app.addCacheToSearch(search, cache);
}
- if (handler != null) {
- final Message msg = new Message();
- msg.obj = search.getCount();
- handler.sendMessage(msg);
- }
+ showFinishedMessage(handler, search);
htmlShort = true;
htmlLong = true;
@@ -168,7 +153,7 @@ public class cgGPXParser {
});
// waypoint.time
- waypoint.getChild(ns, "time").setEndTextElementListener(new EndTextElementListener() {
+ waypoint.getChild(namespace, "time").setEndTextElementListener(new EndTextElementListener() {
public void end(String body) {
try {
@@ -180,7 +165,7 @@ public class cgGPXParser {
});
// waypoint.name
- waypoint.getChild(ns, "name").setEndTextElementListener(new EndTextElementListener() {
+ waypoint.getChild(namespace, "name").setEndTextElementListener(new EndTextElementListener() {
public void end(String body) {
name = body;
@@ -194,7 +179,7 @@ public class cgGPXParser {
});
// waypoint.desc
- waypoint.getChild(ns, "desc").setEndTextElementListener(new EndTextElementListener() {
+ waypoint.getChild(namespace, "desc").setEndTextElementListener(new EndTextElementListener() {
public void end(String body) {
desc = body;
@@ -205,7 +190,7 @@ public class cgGPXParser {
});
// waypoint.cmt
- waypoint.getChild(ns, "cmt").setEndTextElementListener(new EndTextElementListener() {
+ waypoint.getChild(namespace, "cmt").setEndTextElementListener(new EndTextElementListener() {
public void end(String body) {
cmt = body;
@@ -216,7 +201,7 @@ public class cgGPXParser {
});
// waypoint.type
- waypoint.getChild(ns, "type").setEndTextElementListener(new EndTextElementListener() {
+ waypoint.getChild(namespace, "type").setEndTextElementListener(new EndTextElementListener() {
public void end(String body) {
final String[] content = body.split("\\|");
@@ -227,7 +212,7 @@ public class cgGPXParser {
});
// waypoint.sym
- waypoint.getChild(ns, "sym").setEndTextElementListener(new EndTextElementListener() {
+ waypoint.getChild(namespace, "sym").setEndTextElementListener(new EndTextElementListener() {
public void end(String body) {
body = body.toLowerCase();
@@ -240,7 +225,7 @@ public class cgGPXParser {
// for GPX 1.0, cache info comes from waypoint node (so called private children,
// for GPX 1.1 from extensions node
- final Element cacheParent = version == 11 ? waypoint.getChild(ns, "extensions") : waypoint;
+ final Element cacheParent = getCacheParent(waypoint);
for (String nsGC : nsGCList) {
// waypoints.cache
@@ -552,6 +537,8 @@ public class cgGPXParser {
return parsed ? search.getCurrentId() : 0l;
}
+ protected abstract Element getCacheParent(Element waypoint);
+
protected String validate(String input) {
if ("nil".equalsIgnoreCase(input)) {
return "";
@@ -570,4 +557,24 @@ public class cgGPXParser {
}
}
}
+
+ public static Long parseGPX(cgeoapplication app, File file, int listId, Handler handler) {
+ cgSearch search = new cgSearch();
+ long searchId = 0l;
+
+ try {
+ GPXParser parser = new GPX10Parser(app, listId, search);
+ searchId = parser.parse(file, handler);
+ if (searchId == 0l) {
+ parser = new GPX11Parser(app, listId, search);
+ searchId = parser.parse(file, handler);
+ }
+ } 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/LocParser.java b/src/cgeo/geocaching/LocParser.java
new file mode 100644
index 0000000..21e9e02
--- /dev/null
+++ b/src/cgeo/geocaching/LocParser.java
@@ -0,0 +1,170 @@
+package cgeo.geocaching;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map.Entry;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import android.os.Handler;
+import android.util.Log;
+
+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 HashMap<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.latitude = coord.latitude;
+ cache.longitude = coord.longitude;
+ cache.difficulty = coord.difficulty;
+ cache.terrain = coord.terrain;
+ cache.size = coord.size;
+ cache.geocode = coord.geocode.toUpperCase();
+ if (cache.name == null || cache.name.length() == 0) {
+ cache.name = coord.name;
+ }
+ }
+
+ private static HashMap<String, cgCoord> parseCoordinates(
+ final String fileContent) {
+ final HashMap<String, cgCoord> coords = new HashMap<String, cgCoord>();
+ if (fileContent == null || fileContent.length() <= 0) {
+ return coords;
+ }
+ // >> premium only
+
+ final String[] points = fileContent.split("<waypoint>");
+
+ // parse coordinates
+ for (String pointString : points) {
+ final cgCoord pointCoord = new cgCoord();
+ HashMap<String, Object> tmp = null;
+
+ 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);
+ if (matcherLat.find()) {
+ tmp = cgBase.parseCoordinate(matcherLat.group(1).trim(), "lat");
+ pointCoord.latitude = (Double) tmp.get("coordinate");
+ }
+ final Matcher matcherLon = patternLon.matcher(pointString);
+ if (matcherLon.find()) {
+ tmp = cgBase.parseCoordinate(matcherLon.group(1).trim(), "lon");
+ pointCoord.longitude = (Double) tmp.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 (pointCoord.name != null && pointCoord.name.length() > 0) {
+ coords.put(pointCoord.name, pointCoord);
+ }
+ }
+
+ Log.i(cgSettings.tag,
+ "Coordinates found in .loc file: " + coords.size());
+ return coords;
+ }
+
+ public static long parseLoc(cgeoapplication app, File file, int listId,
+ Handler handler) {
+ cgSearch search = new cgSearch();
+ long searchId = 0l;
+
+ try {
+ HashMap<String, cgCoord> coords = parseCoordinates(readFile(file).toString());
+ final cgCacheWrap caches = new cgCacheWrap();
+ for (Entry<String, cgCoord> entry : coords.entrySet()) {
+ cgCoord coord = entry.getValue();
+ if (coord.geocode == null || coord.geocode.length() == 0 || coord.name == null || coord.name.length() == 0) {
+ 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/cgBase.java b/src/cgeo/geocaching/cgBase.java
index 38e2d9e..aeb253d 100644
--- a/src/cgeo/geocaching/cgBase.java
+++ b/src/cgeo/geocaching/cgBase.java
@@ -935,87 +935,7 @@ public class cgBase {
}
}
- if (coordinates != null && coordinates.length() > 0) {
- final HashMap<String, cgCoord> cidCoords = new HashMap<String, cgCoord>();
- final Pattern patternCidCode = Pattern.compile("name id=\"([^\"]+)\"");
- final Pattern patternCidLat = Pattern.compile("lat=\"([^\"]+)\"");
- final Pattern patternCidLon = Pattern.compile("lon=\"([^\"]+)\"");
- // premium only >>
- final Pattern patternCidDif = Pattern.compile("<difficulty>([^<]+)</difficulty>");
- final Pattern patternCidTer = Pattern.compile("<terrain>([^<]+)</terrain>");
- final Pattern patternCidCon = Pattern.compile("<container>([^<]+)</container>");
- // >> premium only
-
- final String[] points = coordinates.split("<waypoint>");
-
- // parse coordinates
- for (String point : points) {
- final cgCoord pointCoord = new cgCoord();
- final Matcher matcherCidCode = patternCidCode.matcher(point);
- final Matcher matcherLatCode = patternCidLat.matcher(point);
- final Matcher matcherLonCode = patternCidLon.matcher(point);
- final Matcher matcherDifCode = patternCidDif.matcher(point);
- final Matcher matcherTerCode = patternCidTer.matcher(point);
- final Matcher matcherConCode = patternCidCon.matcher(point);
- HashMap<String, Object> tmp = null;
-
- if (matcherCidCode.find()) {
- pointCoord.name = matcherCidCode.group(1).trim().toUpperCase();
- }
- if (matcherLatCode.find()) {
- tmp = parseCoordinate(matcherLatCode.group(1), "lat");
- pointCoord.latitude = (Double) tmp.get("coordinate");
- }
- if (matcherLonCode.find()) {
- tmp = parseCoordinate(matcherLonCode.group(1), "lon");
- pointCoord.longitude = (Double) tmp.get("coordinate");
- }
- if (matcherDifCode.find()) {
- pointCoord.difficulty = new Float(matcherDifCode.group(1));
- }
- if (matcherTerCode.find()) {
- pointCoord.terrain = new Float(matcherTerCode.group(1));
- }
- if (matcherConCode.find()) {
- final int size = Integer.parseInt(matcherConCode.group(1));
-
- 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";
- }
- }
-
- cidCoords.put(pointCoord.name, pointCoord);
- }
-
- Log.i(cgSettings.tag, "Coordinates found in .loc file: " + cidCoords.size());
-
- // save found cache coordinates
- for (cgCache oneCache : caches.cacheList) {
- if (cidCoords.containsKey(oneCache.geocode)) {
- cgCoord thisCoords = cidCoords.get(oneCache.geocode);
-
- oneCache.latitude = thisCoords.latitude;
- oneCache.longitude = thisCoords.longitude;
- oneCache.difficulty = thisCoords.difficulty;
- oneCache.terrain = thisCoords.terrain;
- oneCache.size = thisCoords.size;
- }
- }
- }
+ LocParser.parseLoc(caches, coordinates);
} catch (Exception e) {
Log.e(cgSettings.tag, "cgBase.parseSearch.CIDs: " + e.toString());
}
@@ -2117,26 +2037,6 @@ public class cgBase {
return ratings;
}
- public static Long parseGPX(cgeoapplication app, File file, int listId, Handler handler) {
- cgSearch search = new cgSearch();
- long searchId = 0l;
-
- try {
- cgGPXParser GPXparser = new cgGPXParser(app, listId, search);
-
- searchId = GPXparser.parse(file, 10, handler);
- if (searchId == 0l) {
- searchId = GPXparser.parse(file, 11, handler);
- }
- } 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();
- }
-
public cgTrackable parseTrackable(String page) {
if (page == null || page.length() == 0) {
Log.e(cgSettings.tag, "cgeoBase.parseTrackable: No page given");
diff --git a/src/cgeo/geocaching/cgData.java b/src/cgeo/geocaching/cgData.java
index 78a3442..deb8ea1 100644
--- a/src/cgeo/geocaching/cgData.java
+++ b/src/cgeo/geocaching/cgData.java
@@ -1354,7 +1354,7 @@ public class cgData {
if (!waypoints.isEmpty()) {
ContentValues values = new ContentValues();
for (cgWaypoint oneWaypoint : waypoints) {
- if (oneWaypoint.type.equalsIgnoreCase("own")) {
+ if (oneWaypoint.isUserDefined()) {
continue;
}
diff --git a/src/cgeo/geocaching/cgSelectMapfile.java b/src/cgeo/geocaching/cgSelectMapfile.java
index 0d9e57c..d119f26 100644
--- a/src/cgeo/geocaching/cgSelectMapfile.java
+++ b/src/cgeo/geocaching/cgSelectMapfile.java
@@ -7,7 +7,11 @@ import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
-public class cgSelectMapfile extends cgFileList<cgMapfileListAdapter> {
+public class cgSelectMapfile extends FileList<cgMapfileListAdapter> {
+
+ public cgSelectMapfile() {
+ super("map");
+ }
String mapFile;
@@ -40,11 +44,6 @@ public class cgSelectMapfile extends cgFileList<cgMapfileListAdapter> {
}
@Override
- protected String getFileExtension() {
- return "map";
- }
-
- @Override
protected void setTitle() {
setTitle(res.getString(R.string.map_file_select_title));
}
diff --git a/src/cgeo/geocaching/cgWaypoint.java b/src/cgeo/geocaching/cgWaypoint.java
index 5703dfa..7746c2c 100644
--- a/src/cgeo/geocaching/cgWaypoint.java
+++ b/src/cgeo/geocaching/cgWaypoint.java
@@ -90,4 +90,8 @@ public class cgWaypoint {
}
}
}
+
+ public boolean isUserDefined() {
+ return type != null && type.equalsIgnoreCase("own");
+ }
} \ No newline at end of file
diff --git a/src/cgeo/geocaching/cgeodetail.java b/src/cgeo/geocaching/cgeodetail.java
index b6f4cd4..ff6d702 100644
--- a/src/cgeo/geocaching/cgeodetail.java
+++ b/src/cgeo/geocaching/cgeodetail.java
@@ -343,7 +343,7 @@ public class cgeodetail extends AbstractActivity {
// nothing, we lost the window
}
- threadCache = new loadCache(loadCacheHandler, geocode, guid);
+ threadCache = new loadCache(loadCacheHandler);
threadCache.start();
}
@@ -1253,13 +1253,9 @@ public class cgeodetail extends AbstractActivity {
private class loadCache extends Thread {
private Handler handler = null;
- private String geocode = null;
- private String guid = null;
- public loadCache(Handler handlerIn, String geocodeIn, String guidIn) {
+ public loadCache(Handler handlerIn) {
handler = handlerIn;
- geocode = geocodeIn;
- guid = guidIn;
if (geocode == null && guid == null) {
showToast(res.getString(R.string.err_detail_cache_forgot));
diff --git a/src/cgeo/geocaching/cgeogpxes.java b/src/cgeo/geocaching/cgeogpxes.java
index 772f268..380f0f7 100644
--- a/src/cgeo/geocaching/cgeogpxes.java
+++ b/src/cgeo/geocaching/cgeogpxes.java
@@ -9,7 +9,13 @@ import android.os.Environment;
import android.os.Handler;
import android.os.Message;
-public class cgeogpxes extends cgFileList<cgGPXListAdapter> {
+public class cgeogpxes extends FileList<cgGPXListAdapter> {
+
+ public cgeogpxes() {
+ super(new String[] {"gpx"
+ // TODO , "loc"
+ });
+ }
private ProgressDialog parseDialog = null;
private int listId = 1;
@@ -55,11 +61,6 @@ public class cgeogpxes extends cgFileList<cgGPXListAdapter> {
}
@Override
- protected String getFileExtension() {
- return "gpx";
- }
-
- @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -100,8 +101,14 @@ public class cgeogpxes extends cgFileList<cgGPXListAdapter> {
@Override
public void run() {
- final long searchId = cgBase.parseGPX(app, file, listId, changeParseDialogHandler);
-
+ final long searchId;
+ String name = file.getName().toLowerCase();
+ if (name.endsWith("gpx")) {
+ searchId = GPXParser.parseGPX(app, file, listId, changeParseDialogHandler);
+ }
+ else {
+ searchId = LocParser.parseLoc(app, file, listId, changeParseDialogHandler);
+ }
imported = app.getCount(searchId);
loadCachesHandler.sendMessage(new Message());
diff --git a/src/cgeo/geocaching/cgeovisit.java b/src/cgeo/geocaching/cgeovisit.java
index 43a97aa..767363d 100644
--- a/src/cgeo/geocaching/cgeovisit.java
+++ b/src/cgeo/geocaching/cgeovisit.java
@@ -83,7 +83,7 @@ public class cgeovisit extends cgLogForm {
showToast(res.getString(R.string.err_log_load_data_again));
loadData thread;
- thread = new loadData(cacheid);
+ thread = new loadData();
thread.start();
return;
@@ -551,7 +551,7 @@ public class cgeovisit extends cgLogForm {
post.setOnClickListener(null);
loadData thread;
- thread = new loadData(cacheid);
+ thread = new loadData();
thread.start();
} else {
post.setEnabled(true);
@@ -687,11 +687,7 @@ public class cgeovisit extends cgLogForm {
private class loadData extends Thread {
- private String cacheid = null;
-
- public loadData(String cacheidIn) {
- cacheid = cacheidIn;
-
+ public loadData() {
if (cacheid == null) {
showToast(res.getString(R.string.err_detail_cache_forgot_visit));
diff --git a/src/cgeo/geocaching/cgeowaypoint.java b/src/cgeo/geocaching/cgeowaypoint.java
index 672e7f5..e4ec379 100644
--- a/src/cgeo/geocaching/cgeowaypoint.java
+++ b/src/cgeo/geocaching/cgeowaypoint.java
@@ -88,11 +88,11 @@ public class cgeowaypoint extends AbstractActivity {
}
Button buttonEdit = (Button) findViewById(R.id.edit);
- buttonEdit.setOnClickListener(new editWaypointListener(waypoint.id));
+ buttonEdit.setOnClickListener(new editWaypointListener());
Button buttonDelete = (Button) findViewById(R.id.delete);
- if (waypoint.type != null && waypoint.type.equalsIgnoreCase("own")) {
- buttonDelete.setOnClickListener(new deleteWaypointListener(waypoint.id));
+ if (waypoint.isUserDefined()) {
+ buttonDelete.setOnClickListener(new deleteWaypointListener());
buttonDelete.setVisibility(View.VISIBLE);
}
@@ -294,12 +294,6 @@ public class cgeowaypoint extends AbstractActivity {
private class editWaypointListener implements View.OnClickListener {
- private int id = -1;
-
- public editWaypointListener(int idIn) {
- id = idIn;
- }
-
public void onClick(View arg0) {
Intent editIntent = new Intent(cgeowaypoint.this, cgeowaypointadd.class);
editIntent.putExtra("waypoint", id);
@@ -309,12 +303,6 @@ public class cgeowaypoint extends AbstractActivity {
private class deleteWaypointListener implements View.OnClickListener {
- private Integer id = null;
-
- public deleteWaypointListener(int idIn) {
- id = idIn;
- }
-
public void onClick(View arg0) {
if (app.deleteWaypoint(id) == false) {
showToast(res.getString(R.string.err_waypoint_delete_failed));