aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/cgCache.java7
-rw-r--r--main/src/cgeo/geocaching/cgeoadvsearch.java5
-rw-r--r--main/src/cgeo/geocaching/cgeocoords.java3
-rw-r--r--main/src/cgeo/geocaching/cgeopoint.java5
-rw-r--r--main/src/cgeo/geocaching/cgeowaypointadd.java25
-rw-r--r--main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java5
-rw-r--r--main/src/cgeo/geocaching/files/LocParser.java3
-rw-r--r--main/src/cgeo/geocaching/geopoint/Geopoint.java22
-rw-r--r--main/src/cgeo/geocaching/geopoint/GeopointParser.java32
9 files changed, 46 insertions, 61 deletions
diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java
index 9dfaa24..cbc67e7 100644
--- a/main/src/cgeo/geocaching/cgCache.java
+++ b/main/src/cgeo/geocaching/cgCache.java
@@ -15,7 +15,6 @@ import cgeo.geocaching.enumerations.LoadFlags.SaveFlag;
import cgeo.geocaching.enumerations.LogType;
import cgeo.geocaching.enumerations.WaypointType;
import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.geopoint.GeopointParser;
import cgeo.geocaching.network.HtmlImage;
import cgeo.geocaching.utils.CancellableHandler;
import cgeo.geocaching.utils.Log;
@@ -1320,16 +1319,16 @@ public class cgCache implements ICache, IWaypoint {
Matcher matcher = coordPattern.matcher(note);
while (matcher.find()) {
try {
- final Geopoint point = GeopointParser.parse(note.substring(matcher.start()));
+ final Geopoint point = new Geopoint(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)) {
+ if (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, false);
waypoint.setCoords(point);
addWaypoint(waypoint, false);
count++;
}
- } catch (GeopointParser.ParseException e) {
+ } catch (Geopoint.ParseException e) {
// ignore
}
diff --git a/main/src/cgeo/geocaching/cgeoadvsearch.java b/main/src/cgeo/geocaching/cgeoadvsearch.java
index 2c1d5f8..319ac96 100644
--- a/main/src/cgeo/geocaching/cgeoadvsearch.java
+++ b/main/src/cgeo/geocaching/cgeoadvsearch.java
@@ -4,7 +4,6 @@ import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.connector.gc.GCConstants;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.GeopointFormatter;
-import cgeo.geocaching.geopoint.GeopointParser;
import cgeo.geocaching.utils.BaseUtils;
import cgeo.geocaching.utils.EditUtils;
import cgeo.geocaching.utils.Log;
@@ -306,8 +305,8 @@ public class cgeoadvsearch extends AbstractActivity {
}
} else {
try {
- cgeocaches.startActivityCoordinates(this, GeopointParser.parse(latText, lonText));
- } catch (GeopointParser.ParseException e) {
+ cgeocaches.startActivityCoordinates(this, new Geopoint(latText, lonText));
+ } catch (Geopoint.ParseException e) {
showToast(res.getString(e.resource));
}
}
diff --git a/main/src/cgeo/geocaching/cgeocoords.java b/main/src/cgeo/geocaching/cgeocoords.java
index 060260a..e6262b1 100644
--- a/main/src/cgeo/geocaching/cgeocoords.java
+++ b/main/src/cgeo/geocaching/cgeocoords.java
@@ -6,7 +6,6 @@ import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.compatibility.Compatibility;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.GeopointFormatter;
-import cgeo.geocaching.geopoint.GeopointParser.ParseException;
import cgeo.geocaching.geopoint.direction.DDD;
import cgeo.geocaching.geopoint.direction.DMM;
import cgeo.geocaching.geopoint.direction.DMS;
@@ -352,7 +351,7 @@ public class cgeocoords extends Dialog {
if (currentFormat == coordInputFormatEnum.Plain) {
try {
gp = new Geopoint(eLat.getText().toString(), eLon.getText().toString());
- } catch (ParseException e) {
+ } catch (Geopoint.ParseException e) {
if (signalError) {
context.showToast(context.getResources().getString(R.string.err_parse_lat_lon));
}
diff --git a/main/src/cgeo/geocaching/cgeopoint.java b/main/src/cgeo/geocaching/cgeopoint.java
index 0335453..f78d970 100644
--- a/main/src/cgeo/geocaching/cgeopoint.java
+++ b/main/src/cgeo/geocaching/cgeopoint.java
@@ -5,7 +5,6 @@ import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
import cgeo.geocaching.geopoint.DistanceParser;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.GeopointFormatter;
-import cgeo.geocaching.geopoint.GeopointParser;
import cgeo.geocaching.ui.Formatter;
import cgeo.geocaching.utils.Log;
@@ -535,8 +534,8 @@ public class cgeopoint extends AbstractActivity {
if (StringUtils.isNotBlank(latText) && StringUtils.isNotBlank(lonText)) {
try {
- coords = GeopointParser.parse(latText, lonText);
- } catch (GeopointParser.ParseException e) {
+ coords = new Geopoint(latText, lonText);
+ } catch (Geopoint.ParseException e) {
showToast(res.getString(e.resource));
return null;
}
diff --git a/main/src/cgeo/geocaching/cgeowaypointadd.java b/main/src/cgeo/geocaching/cgeowaypointadd.java
index 47cd64a..3d4c4c1 100644
--- a/main/src/cgeo/geocaching/cgeowaypointadd.java
+++ b/main/src/cgeo/geocaching/cgeowaypointadd.java
@@ -8,7 +8,6 @@ import cgeo.geocaching.enumerations.WaypointType;
import cgeo.geocaching.geopoint.DistanceParser;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.GeopointFormatter;
-import cgeo.geocaching.geopoint.GeopointParser;
import cgeo.geocaching.utils.BaseUtils;
import cgeo.geocaching.utils.Log;
@@ -370,28 +369,22 @@ public class cgeowaypointadd extends AbstractActivity {
return;
}
- double latitude;
- double longitude;
+ Geopoint coords;
if (StringUtils.isNotBlank(latText) && StringUtils.isNotBlank(lonText)) {
try {
- latitude = GeopointParser.parseLatitude(latText);
- longitude = GeopointParser.parseLongitude(lonText);
- } catch (GeopointParser.ParseException e) {
+ coords = new Geopoint(latText, lonText);
+ } catch (Geopoint.ParseException e) {
showToast(res.getString(e.resource));
return;
}
+ } else if (geo == null || geo.coordsNow == null) {
+ showToast(res.getString(R.string.err_point_curr_position_unavailable));
+ return;
} else {
- if (geo == null || geo.coordsNow == null) {
- showToast(res.getString(R.string.err_point_curr_position_unavailable));
- return;
- }
-
- latitude = geo.coordsNow.getLatitude();
- longitude = geo.coordsNow.getLongitude();
+ coords = geo.coordsNow;
}
- Geopoint coords = null;
if (StringUtils.isNotBlank(bearingText) && StringUtils.isNotBlank(distanceText)) {
// bearing & distance
double bearing = 0;
@@ -410,9 +403,7 @@ public class cgeowaypointadd extends AbstractActivity {
return;
}
- coords = new Geopoint(latitude, longitude).project(bearing, distance);
- } else {
- coords = new Geopoint(latitude, longitude);
+ coords = coords.project(bearing, distance);
}
String name = ((EditText) findViewById(R.id.name)).getText().toString().trim();
diff --git a/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java b/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java
index 4e4d9f7..80ad58e 100644
--- a/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java
+++ b/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java
@@ -1,8 +1,8 @@
package cgeo.geocaching.connector.opencaching;
+import cgeo.geocaching.LogEntry;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgImage;
-import cgeo.geocaching.LogEntry;
import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.connector.ConnectorFactory;
import cgeo.geocaching.connector.IConnector;
@@ -12,7 +12,6 @@ import cgeo.geocaching.enumerations.LoadFlags.SaveFlag;
import cgeo.geocaching.enumerations.LogType;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.GeopointFormatter;
-import cgeo.geocaching.geopoint.GeopointParser;
import cgeo.geocaching.network.Network;
import cgeo.geocaching.network.Parameters;
import cgeo.geocaching.utils.Log;
@@ -248,7 +247,7 @@ final public class OkapiClient {
final String latitude = StringUtils.substringBefore(location, "|");
final String longitude = StringUtils.substringAfter(location, "|");
// FIXME: the next line should be a setter at cgCache
- cache.setCoords(GeopointParser.parse(latitude, longitude));
+ cache.setCoords(new Geopoint(latitude, longitude));
}
private static CacheSize getCacheSize(final JSONObject response) {
diff --git a/main/src/cgeo/geocaching/files/LocParser.java b/main/src/cgeo/geocaching/files/LocParser.java
index ad44dc4..b17b203 100644
--- a/main/src/cgeo/geocaching/files/LocParser.java
+++ b/main/src/cgeo/geocaching/files/LocParser.java
@@ -7,7 +7,6 @@ import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.geopoint.GeopointParser;
import cgeo.geocaching.utils.CancellableHandler;
import cgeo.geocaching.utils.Log;
@@ -114,7 +113,7 @@ public final class LocParser extends FileParser {
Log.e("LOC format has changed");
}
// fall back to parser, just in case the format changes
- return GeopointParser.parse(latitude, longitude);
+ return new Geopoint(latitude, longitude);
}
public LocParser(int listId) {
diff --git a/main/src/cgeo/geocaching/geopoint/Geopoint.java b/main/src/cgeo/geocaching/geopoint/Geopoint.java
index 106e8a9..2fe7bd2 100644
--- a/main/src/cgeo/geocaching/geopoint/Geopoint.java
+++ b/main/src/cgeo/geocaching/geopoint/Geopoint.java
@@ -1,6 +1,7 @@
package cgeo.geocaching.geopoint;
import cgeo.geocaching.ICoordinates;
+import cgeo.geocaching.R;
import cgeo.geocaching.geopoint.GeopointFormatter.Format;
import cgeo.geocaching.geopoint.direction.DDD;
import cgeo.geocaching.geopoint.direction.DMM;
@@ -53,12 +54,14 @@ public final class Geopoint implements ICoordinates, Parcelable {
*
* @param text
* string to parse
- * @throws GeopointParser.ParseException
+ * @throws Geopoint.ParseException
* if the string cannot be parsed
* @see GeopointParser.parse()
*/
public Geopoint(final String text) {
- this(GeopointParser.parseLatitude(text), GeopointParser.parseLongitude(text));
+ final Geopoint parsed = GeopointParser.parse(text);
+ this.latitude = parsed.latitude;
+ this.longitude = parsed.longitude;
}
/**
@@ -68,7 +71,7 @@ public final class Geopoint implements ICoordinates, Parcelable {
* latitude string to parse
* @param lonText
* longitude string to parse
- * @throws GeopointParser.ParseException
+ * @throws Geopoint.ParseException
* if any argument string cannot be parsed
* @see GeopointParser.parse()
*/
@@ -315,6 +318,19 @@ public final class Geopoint implements ICoordinates, Parcelable {
}
}
+ public static class ParseException
+ extends GeopointException
+ {
+ private static final long serialVersionUID = 1L;
+ public final int resource;
+
+ public ParseException(final String msg, final GeopointParser.LatLon faulty)
+ {
+ super(msg);
+ resource = faulty == GeopointParser.LatLon.LAT ? R.string.err_parse_lat : R.string.err_parse_lon;
+ }
+ }
+
public Double getElevation() {
try {
final String uri = "http://maps.googleapis.com/maps/api/elevation/json";
diff --git a/main/src/cgeo/geocaching/geopoint/GeopointParser.java b/main/src/cgeo/geocaching/geopoint/GeopointParser.java
index 3c72f1e..68263f6 100644
--- a/main/src/cgeo/geocaching/geopoint/GeopointParser.java
+++ b/main/src/cgeo/geocaching/geopoint/GeopointParser.java
@@ -1,7 +1,5 @@
package cgeo.geocaching.geopoint;
-import cgeo.geocaching.R;
-import cgeo.geocaching.geopoint.Geopoint.GeopointException;
import org.apache.commons.lang3.StringUtils;
@@ -11,8 +9,7 @@ import java.util.regex.Pattern;
/**
* Parse coordinates.
*/
-public class GeopointParser
-{
+class GeopointParser {
private static class ResultWrapper {
final double result;
final int matcherPos;
@@ -29,7 +26,7 @@ public class GeopointParser
private static final Pattern patternLat = Pattern.compile("\\b([NS])\\s*(\\d+)°?(?:\\s*(\\d+)(?:[.,](\\d+)|'?\\s*(\\d+(?:[.,]\\d+)?)(?:''|\")?)?)?", Pattern.CASE_INSENSITIVE);
private static final Pattern patternLon = Pattern.compile("\\b([WE])\\s*(\\d+)°?(?:\\s*(\\d+)(?:[.,](\\d+)|'?\\s*(\\d+(?:[.,]\\d+)?)(?:''|\")?)?)?", Pattern.CASE_INSENSITIVE);
- private enum LatLon
+ enum LatLon
{
LAT,
LON
@@ -52,7 +49,7 @@ public class GeopointParser
* @param text
* the string to parse
* @return an Geopoint with parsed latitude and longitude
- * @throws ParseException
+ * @throws Geopoint.ParseException
* if lat or lon could not be parsed
*/
public static Geopoint parse(final String text)
@@ -63,7 +60,7 @@ public class GeopointParser
final ResultWrapper longitudeWrapper = parseHelper(text.substring(latitudeWrapper.matcherPos + latitudeWrapper.matcherLength), LatLon.LON);
if (longitudeWrapper.matcherPos - (latitudeWrapper.matcherPos + latitudeWrapper.matcherLength) >= 10) {
- throw new ParseException("Distance between latitude and longitude text is to large.", LatLon.LON);
+ throw new Geopoint.ParseException("Distance between latitude and longitude text is to large.", LatLon.LON);
}
final double lon = longitudeWrapper.result;
@@ -89,7 +86,7 @@ public class GeopointParser
* @param longitude
* the longitude string to parse
* @return an Geopoint with parsed latitude and longitude
- * @throws ParseException
+ * @throws Geopoint.ParseException
* if lat or lon could not be parsed
*/
public static Geopoint parse(final String latitude, final String longitude)
@@ -143,7 +140,7 @@ public class GeopointParser
// The right exception will be raised below.
}
- throw new ParseException("Could not parse coordinates as " + latlon + ": \"" + text + "\"", latlon);
+ throw new Geopoint.ParseException("Could not parse coordinates as " + latlon + ": \"" + text + "\"", latlon);
}
/**
@@ -153,7 +150,7 @@ public class GeopointParser
* @param text
* the string to be parsed
* @return the latitude as decimal degree
- * @throws ParseException
+ * @throws Geopoint.ParseException
* if latitude could not be parsed
*/
public static double parseLatitude(final String text)
@@ -168,24 +165,11 @@ public class GeopointParser
* @param text
* the string to be parsed
* @return the longitude as decimal degree
- * @throws ParseException
+ * @throws Geopoint.ParseException
* if longitude could not be parsed
*/
public static double parseLongitude(final String text)
{
return parseHelper(text, LatLon.LON).result;
}
-
- public static class ParseException
- extends GeopointException
- {
- private static final long serialVersionUID = 1L;
- public final int resource;
-
- public ParseException(final String msg, final LatLon faulty)
- {
- super(msg);
- resource = faulty == LatLon.LAT ? R.string.err_parse_lat : R.string.err_parse_lon;
- }
- }
}