aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java1
-rw-r--r--main/src/cgeo/geocaching/cgCache.java48
-rw-r--r--tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java12
3 files changed, 38 insertions, 23 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index 5a6c82b..bc60631 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -757,6 +757,7 @@ public class CacheDetailActivity extends AbstractActivity {
}
} while (cursor.moveToNext());
}
+ cursor.close();
}
final CharSequence[] items = calendars.values().toArray(new CharSequence[calendars.size()]);
diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java
index 7265ff2..92023e5 100644
--- a/main/src/cgeo/geocaching/cgCache.java
+++ b/main/src/cgeo/geocaching/cgCache.java
@@ -1050,30 +1050,34 @@ public class cgCache implements ICache {
}
public void parseWaypointsFromNote() {
- if (StringUtils.isBlank(getPersonalNote())) {
- return;
- }
- final Pattern coordPattern = Pattern.compile("\\b[nNsS]{1}\\s*\\d"); // begin of coordinates
- int count = 1;
- String note = getPersonalNote();
- Matcher matcher = coordPattern.matcher(note);
- while (matcher.find()) {
- try {
- final Geopoint point = GeopointParser.parse(note.substring(matcher.start()));
- // coords must have non zero latitude and longitude and at least one part shall have fractional degrees
- if (point != null && point.getLatitudeE6() != 0 && point.getLongitudeE6() != 0 && ((point.getLatitudeE6() % 1000) != 0 || (point.getLongitudeE6() % 1000) != 0)) {
- final String name = cgeoapplication.getInstance().getString(R.string.cache_personal_note) + " " + count;
- final cgWaypoint waypoint = new cgWaypoint(name, WaypointType.WAYPOINT);
- waypoint.setCoords(point);
- addWaypoint(waypoint);
- count++;
- }
- } catch (GeopointParser.ParseException e) {
- // ignore
+ try {
+ if (StringUtils.isBlank(getPersonalNote())) {
+ return;
}
+ final Pattern coordPattern = Pattern.compile("\\b[nNsS]{1}\\s*\\d"); // begin of coordinates
+ int count = 1;
+ String note = getPersonalNote();
+ Matcher matcher = coordPattern.matcher(note);
+ while (matcher.find()) {
+ try {
+ final Geopoint point = GeopointParser.parse(note.substring(matcher.start()));
+ // coords must have non zero latitude and longitude and at least one part shall have fractional degrees
+ if (point != null && point.getLatitudeE6() != 0 && point.getLongitudeE6() != 0 && ((point.getLatitudeE6() % 1000) != 0 || (point.getLongitudeE6() % 1000) != 0)) {
+ final String name = cgeoapplication.getInstance().getString(R.string.cache_personal_note) + " " + count;
+ final cgWaypoint waypoint = new cgWaypoint(name, WaypointType.WAYPOINT);
+ waypoint.setCoords(point);
+ addWaypoint(waypoint);
+ count++;
+ }
+ } catch (GeopointParser.ParseException e) {
+ // ignore
+ }
- note = note.substring(matcher.start() + 1);
- matcher = coordPattern.matcher(note);
+ note = note.substring(matcher.start() + 1);
+ matcher = coordPattern.matcher(note);
+ }
+ } catch (Exception e) {
+ Log.e(Settings.tag, "cgCache.parseWaypointsFromNote: " + e.toString());
}
}
diff --git a/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java b/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java
index b6d7c66..661623e 100644
--- a/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java
+++ b/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java
@@ -23,7 +23,7 @@ public class GeoPointParserTest extends AndroidTestCase {
}
public static void testCoordinateMissingPart() {
- // we are trying to parse a _point_, but have only one a latitude. Don't accept the numerical part as longitude!
+ // we are trying to parse a _point_, but have only a latitude. Don't accept the numerical part as longitude!
Geopoint point = null;
try {
point = GeopointParser.parse("N 49° 56.031");
@@ -69,4 +69,14 @@ public class GeoPointParserTest extends AndroidTestCase {
}
assertEquals(null, point);
}
+
+ public static void testComma() {
+ final Geopoint pointComma = GeopointParser.parse("N 46° 27' 55,65''\n" +
+ "E 15° 53' 41,68''");
+ final Geopoint pointDot = GeopointParser.parse("N 46° 27' 55.65''\n" +
+ "E 15° 53' 41.68''");
+ assertNotNull(pointComma);
+ assertNotNull(pointDot);
+ assertTrue(pointComma.isEqualTo(pointDot));
+ }
}