aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2011-11-07 11:35:53 +0100
committerSamuel Tardieu <sam@rfc1149.net>2011-11-07 12:53:30 +0100
commit739de1c562f4814c2883459823aa46aadf26d96c (patch)
treeaeab95f3edc7b6cbb4a5a81d4f990cdb063caf85 /main
parentc67baaf158d1102335b02defcfa445c3dda5fca0 (diff)
downloadcgeo-739de1c562f4814c2883459823aa46aadf26d96c.zip
cgeo-739de1c562f4814c2883459823aa46aadf26d96c.tar.gz
cgeo-739de1c562f4814c2883459823aa46aadf26d96c.tar.bz2
Get rid of deprecated methods related to coordinates
Diffstat (limited to 'main')
-rw-r--r--main/src/cgeo/geocaching/cgBase.java38
-rw-r--r--main/src/cgeo/geocaching/cgCache.java5
-rw-r--r--main/src/cgeo/geocaching/cgeo.java5
-rw-r--r--main/src/cgeo/geocaching/cgeoadvsearch.java13
-rw-r--r--main/src/cgeo/geocaching/cgeocaches.java5
-rw-r--r--main/src/cgeo/geocaching/cgeodetail.java3
-rw-r--r--main/src/cgeo/geocaching/cgeonavigate.java7
-rw-r--r--main/src/cgeo/geocaching/cgeopoint.java22
-rw-r--r--main/src/cgeo/geocaching/cgeowaypoint.java3
-rw-r--r--main/src/cgeo/geocaching/cgeowaypointadd.java8
-rw-r--r--main/src/cgeo/geocaching/geopoint/GeopointFormatter.java51
11 files changed, 76 insertions, 84 deletions
diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java
index 45460e5..81ae41d 100644
--- a/main/src/cgeo/geocaching/cgBase.java
+++ b/main/src/cgeo/geocaching/cgBase.java
@@ -1976,44 +1976,6 @@ public class cgBase {
}
}
- @Deprecated
- private static String formatCoordinate(final Double coordIn, final boolean degrees, final String direction, final String digitsFormat) {
- if (coordIn == null) {
- return "";
- }
- StringBuilder formatted = new StringBuilder(direction);
-
- double coordAbs = Math.abs(coordIn);
- Locale locale = Locale.getDefault();
- double floor = Math.floor(coordAbs);
-
- formatted.append(String.format(locale, digitsFormat, floor));
-
- if (degrees) {
- formatted.append("° ");
- } else {
- formatted.append(' ');
- }
- formatted.append(String.format(locale, "%06.3f", ((coordAbs - floor) * 60)));
-
- return formatted.toString();
- }
-
- @Deprecated
- public static String formatLatitude(final Double coord, final boolean degrees) {
- return formatCoordinate(coord, degrees, (coord >= 0) ? "N " : "S ", "%02.0f");
- }
-
- @Deprecated
- public static String formatLongitude(final Double coord, final boolean degrees) {
- return formatCoordinate(coord, degrees, (coord >= 0) ? "E " : "W ", "%03.0f");
- }
-
- @Deprecated
- public static String formatCoords(final Geopoint coords, final boolean degrees) {
- return formatLatitude(coords.getLatitude(), degrees) + " | " + formatLongitude(coords.getLongitude(), degrees);
- }
-
/**
* Insert the right cache type restriction in parameters
*
diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java
index 35d3681..71c9f6e 100644
--- a/main/src/cgeo/geocaching/cgCache.java
+++ b/main/src/cgeo/geocaching/cgCache.java
@@ -6,6 +6,7 @@ import cgeo.geocaching.connector.IConnector;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.geopoint.GeopointFormatter;
import cgeo.geocaching.utils.CryptUtils;
import org.apache.commons.collections.CollectionUtils;
@@ -393,12 +394,12 @@ public class cgCache implements ICache {
@Override
public String getLatitude() {
- return coords != null ? cgBase.formatLatitude(coords.getLatitude(), true) : null;
+ return coords != null ? coords.format(GeopointFormatter.Format.LAT_DECMINUTE) : null;
}
@Override
public String getLongitude() {
- return coords != null ? cgBase.formatLongitude(coords.getLongitude(), true) : null;
+ return coords != null ? coords.format(GeopointFormatter.Format.LON_DECMINUTE) : null;
}
@Override
diff --git a/main/src/cgeo/geocaching/cgeo.java b/main/src/cgeo/geocaching/cgeo.java
index 616aa9f..ec4c3ed 100644
--- a/main/src/cgeo/geocaching/cgeo.java
+++ b/main/src/cgeo/geocaching/cgeo.java
@@ -5,6 +5,7 @@ import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.geopoint.GeopointFormatter;
import cgeo.geocaching.maps.CGeoMap;
import org.apache.commons.collections.CollectionUtils;
@@ -575,9 +576,9 @@ public class cgeo extends AbstractActivity {
} else {
if (geo.altitudeNow != null) {
final String humanAlt = cgBase.getHumanDistance(geo.altitudeNow.floatValue() / 1000);
- navLocation.setText(cgBase.formatCoords(geo.coordsNow, true) + " | " + humanAlt);
+ navLocation.setText(geo.coordsNow.format(GeopointFormatter.Format.LAT_LON_DECMINUTE_PIPE) + " | " + humanAlt);
} else {
- navLocation.setText(cgBase.formatCoords(geo.coordsNow, true));
+ navLocation.setText(geo.coordsNow.format(GeopointFormatter.Format.LAT_LON_DECMINUTE_PIPE));
}
}
} else {
diff --git a/main/src/cgeo/geocaching/cgeoadvsearch.java b/main/src/cgeo/geocaching/cgeoadvsearch.java
index 882b2a7..0d00cca 100644
--- a/main/src/cgeo/geocaching/cgeoadvsearch.java
+++ b/main/src/cgeo/geocaching/cgeoadvsearch.java
@@ -2,6 +2,7 @@ package cgeo.geocaching;
import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.geopoint.GeopointFormatter;
import cgeo.geocaching.geopoint.GeopointParser;
import org.apache.commons.lang3.StringUtils;
@@ -218,10 +219,10 @@ public class cgeoadvsearch extends AbstractActivity {
if (geo.coordsNow != null) {
if (latEdit != null) {
- latEdit.setHint(cgBase.formatLatitude(geo.coordsNow.getLatitude(), false));
+ latEdit.setHint(geo.coordsNow.format(GeopointFormatter.Format.LAT_DECMINUTE_RAW));
}
if (lonEdit != null) {
- lonEdit.setHint(cgBase.formatLongitude(geo.coordsNow.getLongitude(), false));
+ lonEdit.setHint(geo.coordsNow.format(GeopointFormatter.Format.LON_DECMINUTE_RAW));
}
}
} catch (Exception e) {
@@ -239,8 +240,8 @@ public class cgeoadvsearch extends AbstractActivity {
coordsDialog.setOnCoordinateUpdate(new cgeocoords.CoordinateUpdate() {
@Override
public void update(Geopoint gp) {
- ((Button) findViewById(R.id.buttonLatitude)).setText(cgBase.formatLatitude(gp.getLatitude(), true));
- ((Button) findViewById(R.id.buttonLongitude)).setText(cgBase.formatLongitude(gp.getLongitude(), true));
+ ((Button) findViewById(R.id.buttonLatitude)).setText(gp.format(GeopointFormatter.Format.LAT_DECMINUTE));
+ ((Button) findViewById(R.id.buttonLongitude)).setText(gp.format(GeopointFormatter.Format.LON_DECMINUTE));
}
});
coordsDialog.show();
@@ -262,8 +263,8 @@ public class cgeoadvsearch extends AbstractActivity {
if (StringUtils.isEmpty(latText) || StringUtils.isEmpty(lonText)) {
if (geo.coordsNow != null) {
- latView.setText(cgBase.formatLatitude(geo.coordsNow.getLatitude(), true));
- lonView.setText(cgBase.formatLongitude(geo.coordsNow.getLongitude(), true));
+ latView.setText(geo.coordsNow.format(GeopointFormatter.Format.LAT_DECMINUTE));
+ lonView.setText(geo.coordsNow.format(GeopointFormatter.Format.LON_DECMINUTE));
}
} else {
try {
diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java
index a5a39ee..8fa7a22 100644
--- a/main/src/cgeo/geocaching/cgeocaches.java
+++ b/main/src/cgeo/geocaching/cgeocaches.java
@@ -14,6 +14,7 @@ import cgeo.geocaching.filter.cgFilterBySize;
import cgeo.geocaching.filter.cgFilterByTrackables;
import cgeo.geocaching.filter.cgFilterByType;
import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.geopoint.GeopointFormatter;
import cgeo.geocaching.maps.CGeoMap;
import cgeo.geocaching.sorting.CacheComparator;
import cgeo.geocaching.sorting.DateComparator;
@@ -611,7 +612,7 @@ public class cgeocaches extends AbstractListActivity {
break;
case COORDINATE:
action = "planning";
- title = cgBase.formatCoords(coords, true);
+ title = coords.format(GeopointFormatter.Format.LAT_LON_DECMINUTE_PIPE);
setTitle(title);
showProgress(true);
setLoadingCaches();
@@ -638,7 +639,7 @@ public class cgeocaches extends AbstractListActivity {
showProgress(true);
setLoadingCaches();
} else {
- title = cgBase.formatCoords(coords, true);
+ title = coords.format(GeopointFormatter.Format.LAT_LON_DECMINUTE_PIPE);
setTitle(title);
showProgress(true);
setLoadingCaches();
diff --git a/main/src/cgeo/geocaching/cgeodetail.java b/main/src/cgeo/geocaching/cgeodetail.java
index 02580d8..95cd8f9 100644
--- a/main/src/cgeo/geocaching/cgeodetail.java
+++ b/main/src/cgeo/geocaching/cgeodetail.java
@@ -8,6 +8,7 @@ import cgeo.geocaching.compatibility.Compatibility;
import cgeo.geocaching.connector.ConnectorFactory;
import cgeo.geocaching.connector.IConnector;
import cgeo.geocaching.enumerations.CacheType;
+import cgeo.geocaching.geopoint.GeopointFormatter;
import cgeo.geocaching.network.HtmlImage;
import cgeo.geocaching.utils.CancellableHandler;
import cgeo.geocaching.utils.CryptUtils;
@@ -1106,7 +1107,7 @@ public class cgeodetail extends AbstractActivity {
TextView nameView = (TextView) waypointView.findViewById(R.id.name);
if (StringUtils.isBlank(wpt.getName())) {
- nameView.setText(cgBase.formatCoords(wpt.getCoords(), true));
+ nameView.setText(wpt.getCoords().format(GeopointFormatter.Format.LAT_LON_DECMINUTE_PIPE));
} else {
nameView.setText(StringEscapeUtils.unescapeHtml4(wpt.getName()));
}
diff --git a/main/src/cgeo/geocaching/cgeonavigate.java b/main/src/cgeo/geocaching/cgeonavigate.java
index 47c2b0a..aee4d64 100644
--- a/main/src/cgeo/geocaching/cgeonavigate.java
+++ b/main/src/cgeo/geocaching/cgeonavigate.java
@@ -2,6 +2,7 @@ package cgeo.geocaching;
import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.geopoint.GeopointFormatter;
import cgeo.geocaching.maps.CGeoMap;
import org.apache.commons.lang3.StringUtils;
@@ -298,7 +299,7 @@ public class cgeonavigate extends AbstractActivity {
return;
}
- ((TextView) findViewById(R.id.destination)).setText(cgBase.formatCoords(dstCoords, true));
+ ((TextView) findViewById(R.id.destination)).setText(dstCoords.format(GeopointFormatter.Format.LAT_LON_DECMINUTE_PIPE));
}
public void setDest(final Geopoint coords) {
@@ -382,9 +383,9 @@ public class cgeonavigate extends AbstractActivity {
if (geo.altitudeNow != null) {
final String humanAlt = cgBase.getHumanDistance(geo.altitudeNow.floatValue() / 1000);
- navLocation.setText(cgBase.formatCoords(geo.coordsNow, true) + " | " + humanAlt);
+ navLocation.setText(geo.coordsNow.format(GeopointFormatter.Format.LAT_LON_DECMINUTE_PIPE) + " | " + humanAlt);
} else {
- navLocation.setText(cgBase.formatCoords(geo.coordsNow, true));
+ navLocation.setText(geo.coordsNow.format(GeopointFormatter.Format.LAT_LON_DECMINUTE_PIPE));
}
updateDistanceInfo();
diff --git a/main/src/cgeo/geocaching/cgeopoint.java b/main/src/cgeo/geocaching/cgeopoint.java
index cc19f4a..5096eec 100644
--- a/main/src/cgeo/geocaching/cgeopoint.java
+++ b/main/src/cgeo/geocaching/cgeopoint.java
@@ -4,6 +4,7 @@ import cgeo.geocaching.activity.AbstractActivity;
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 org.apache.commons.lang3.StringUtils;
@@ -60,8 +61,8 @@ public class cgeopoint extends AbstractActivity {
.findViewById(R.id.simple_way_point_latitude);
TextView date = (TextView) v.findViewById(R.id.date);
- String lonString = cgBase.formatLongitude(loc.getCoords().getLongitude(), true);
- String latString = cgBase.formatLatitude(loc.getCoords().getLatitude(), true);
+ String lonString = loc.getCoords().format(GeopointFormatter.Format.LON_DECMINUTE);
+ String latString = loc.getCoords().format(GeopointFormatter.Format.LAT_DECMINUTE);
longitude.setText(lonString);
latitude.setText(latString);
@@ -239,8 +240,9 @@ public class cgeopoint extends AbstractActivity {
lonButton.setOnClickListener(new coordDialogListener());
if (prefs.contains("anylatitude") && prefs.contains("anylongitude")) {
- latButton.setText(cgBase.formatLatitude(Double.valueOf(prefs.getFloat("anylatitude", 0f)), true));
- lonButton.setText(cgBase.formatLongitude(Double.valueOf(prefs.getFloat("anylongitude", 0f)), true));
+ final Geopoint coords = new Geopoint(prefs.getFloat("anylatitude", 0f), prefs.getFloat("anylongitude", 0f));
+ latButton.setText(coords.format(GeopointFormatter.Format.LAT_DECMINUTE));
+ lonButton.setText(coords.format(GeopointFormatter.Format.LON_DECMINUTE));
}
Button buttonCurrent = (Button) findViewById(R.id.current);
@@ -261,8 +263,8 @@ public class cgeopoint extends AbstractActivity {
coordsDialog.setOnCoordinateUpdate(new cgeocoords.CoordinateUpdate() {
@Override
public void update(Geopoint gp) {
- latButton.setText(cgBase.formatLatitude(gp.getLatitude(), true));
- lonButton.setText(cgBase.formatLongitude(gp.getLongitude(), true));
+ latButton.setText(gp.format(GeopointFormatter.Format.LAT_DECMINUTE));
+ lonButton.setText(gp.format(GeopointFormatter.Format.LON_DECMINUTE));
changed = true;
}
});
@@ -434,8 +436,8 @@ public class cgeopoint extends AbstractActivity {
}
try {
- latButton.setHint(cgBase.formatLatitude(geo.coordsNow.getLatitude(), false));
- lonButton.setHint(cgBase.formatLongitude(geo.coordsNow.getLongitude(), false));
+ latButton.setHint(geo.coordsNow.format(GeopointFormatter.Format.LAT_DECMINUTE_RAW));
+ lonButton.setHint(geo.coordsNow.format(GeopointFormatter.Format.LON_DECMINUTE_RAW));
} catch (Exception e) {
Log.w(Settings.tag, "Failed to update location.");
}
@@ -450,8 +452,8 @@ public class cgeopoint extends AbstractActivity {
return;
}
- latButton.setText(cgBase.formatLatitude(geo.coordsNow.getLatitude(), true));
- lonButton.setText(cgBase.formatLongitude(geo.coordsNow.getLongitude(), true));
+ latButton.setText(geo.coordsNow.format(GeopointFormatter.Format.LAT_DECMINUTE));
+ lonButton.setText(geo.coordsNow.format(GeopointFormatter.Format.LON_DECMINUTE));
changed = false;
}
diff --git a/main/src/cgeo/geocaching/cgeowaypoint.java b/main/src/cgeo/geocaching/cgeowaypoint.java
index b0d183b..483423c 100644
--- a/main/src/cgeo/geocaching/cgeowaypoint.java
+++ b/main/src/cgeo/geocaching/cgeowaypoint.java
@@ -2,6 +2,7 @@ package cgeo.geocaching;
import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
+import cgeo.geocaching.geopoint.GeopointFormatter;
import org.apache.commons.lang3.StringUtils;
@@ -75,7 +76,7 @@ public class cgeowaypoint extends AbstractActivity {
waypoint.setIcon(res, identification);
if (waypoint.getCoords() != null) {
- coords.setText(Html.fromHtml(cgBase.formatCoords(waypoint.getCoords(), true)), TextView.BufferType.SPANNABLE);
+ coords.setText(Html.fromHtml(waypoint.getCoords().format(GeopointFormatter.Format.LAT_LON_DECMINUTE_PIPE)), TextView.BufferType.SPANNABLE);
compass.setVisibility(View.VISIBLE);
separator.setVisibility(View.VISIBLE);
} else {
diff --git a/main/src/cgeo/geocaching/cgeowaypointadd.java b/main/src/cgeo/geocaching/cgeowaypointadd.java
index be90847..bce8441 100644
--- a/main/src/cgeo/geocaching/cgeowaypointadd.java
+++ b/main/src/cgeo/geocaching/cgeowaypointadd.java
@@ -61,8 +61,8 @@ public class cgeowaypointadd extends AbstractActivity {
app.setAction(geocode);
if (waypoint.getCoords() != null) {
- ((Button) findViewById(R.id.buttonLatitude)).setText(cgBase.formatLatitude(waypoint.getCoords().getLatitude(), true));
- ((Button) findViewById(R.id.buttonLongitude)).setText(cgBase.formatLongitude(waypoint.getCoords().getLongitude(), true));
+ ((Button) findViewById(R.id.buttonLatitude)).setText(waypoint.getCoords().format(GeopointFormatter.Format.LAT_DECMINUTE));
+ ((Button) findViewById(R.id.buttonLongitude)).setText(waypoint.getCoords().format(GeopointFormatter.Format.LON_DECMINUTE));
}
((EditText) findViewById(R.id.name)).setText(Html.fromHtml(StringUtils.trimToEmpty(waypoint.getName())).toString());
((EditText) findViewById(R.id.note)).setText(Html.fromHtml(StringUtils.trimToEmpty(waypoint.getNote())).toString());
@@ -197,8 +197,8 @@ public class cgeowaypointadd extends AbstractActivity {
try {
Button bLat = (Button) findViewById(R.id.buttonLatitude);
Button bLon = (Button) findViewById(R.id.buttonLongitude);
- bLat.setHint(cgBase.formatLatitude(geo.coordsNow.getLatitude(), false));
- bLon.setHint(cgBase.formatLongitude(geo.coordsNow.getLongitude(), false));
+ bLat.setHint(geo.coordsNow.format(GeopointFormatter.Format.LAT_DECMINUTE_RAW));
+ bLon.setHint(geo.coordsNow.format(GeopointFormatter.Format.LON_DECMINUTE_RAW));
} catch (Exception e) {
Log.w(Settings.tag, "Failed to update location.");
}
diff --git a/main/src/cgeo/geocaching/geopoint/GeopointFormatter.java b/main/src/cgeo/geocaching/geopoint/GeopointFormatter.java
index e37cbed..16951ad 100644
--- a/main/src/cgeo/geocaching/geopoint/GeopointFormatter.java
+++ b/main/src/cgeo/geocaching/geopoint/GeopointFormatter.java
@@ -20,12 +20,15 @@ public class GeopointFormatter
{
LAT_LON_DECDEGREE("%y6d %x6d"),
LAT_LON_DECMINUTE("%yn %yd° %y3m %xn %xd° %x3m"),
+ LAT_LON_DECMINUTE_PIPE("%yn %yd° %y3m | %xn %xd° %x3m"),
LAT_LON_DECSECOND("%yn %yd° %ym' %ys\" %xn %xd° %xm' %xs\""),
LAT_DECDEGREE("%y6d"),
LAT_DECMINUTE("%yn %yd° %y3m"),
+ LAT_DECMINUTE_RAW("%yn %yd %y3m"),
LAT_DECSECOND("%yn %yd° %ym' %ys\""),
LON_DECDEGREE("%x6d"),
LON_DECMINUTE("%xn %xd° %x3m"),
+ LON_DECMINUTE_RAW("%xn %xd %x3m"),
LON_DECSECOND("%xn %xd° %xm' %xs\"");
private final String format;
@@ -165,23 +168,41 @@ public class GeopointFormatter
{
// Don't parse often used formats
- switch (format)
- {
- case LAT_LON_DECDEGREE:
- return String.format("%.6f %.6f", gp.getLatitude(), gp.getLongitude());
+ if (format == Format.LAT_LON_DECDEGREE) {
+ return String.format("%.6f %.6f", gp.getLatitude(), gp.getLongitude());
+ }
+ final double latSigned = gp.getLatitude();
+ final double lonSigned = gp.getLongitude();
+ final double lat = Math.abs(latSigned);
+ final double lon = Math.abs(lonSigned);
+ final double latFloor = Math.floor(lat);
+ final double lonFloor = Math.floor(lon);
+ final double latMin = (lat - latFloor) * 60;
+ final double lonMin = (lon - lonFloor) * 60;
+ final char latDir = latSigned < 0 ? 'S' : 'N';
+ final char lonDir = lonSigned < 0 ? 'W' : 'E';
+
+ switch (format) {
case LAT_LON_DECMINUTE:
- final double lat = Math.abs(gp.getLatitude());
- final double lon = Math.abs(gp.getLongitude());
- final boolean latPos = (gp.getLatitude() < 0);
- final boolean lonPos = (gp.getLongitude() < 0);
-
- return String.format("%s %02.0f° %.3f %s %03.0f° %.3f", (latPos) ? "S" : "N",
- Math.floor(lat),
- (lat - Math.floor(lat)) * 60,
- (lonPos) ? "W" : "E",
- Math.floor(lon),
- (lon - Math.floor(lon)) * 60);
+ return String.format("%c %02.0f° %.3f %c %03.0f° %.3f",
+ latDir, latFloor, latMin, lonDir, lonFloor, lonMin);
+
+ case LAT_LON_DECMINUTE_PIPE:
+ return String.format("%c %02.0f° %.3f | %c %03.0f° %.3f",
+ latDir, latFloor, latMin, lonDir, lonFloor, lonMin);
+
+ case LAT_DECMINUTE:
+ return String.format("%c %02.0f° %.3f", latDir, latFloor, latMin);
+
+ case LAT_DECMINUTE_RAW:
+ return String.format("%c %02.0f %.3f", latDir, latFloor, latMin);
+
+ case LON_DECMINUTE:
+ return String.format("%c %03.0f° %.3f", lonDir, lonFloor, lonMin);
+
+ case LON_DECMINUTE_RAW:
+ return String.format("%c %03.0f %.3f", lonDir, lonFloor, lonMin);
default:
return format(format.toString(), gp);