diff options
| -rw-r--r-- | src/cgeo/geocaching/cgBase.java | 8 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgCacheListAdapter.java | 6 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgDistanceView.java | 9 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgGeo.java | 6 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeo.java | 2 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeodetail.java | 4 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeonavigate.java | 2 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeopopup.java | 2 | ||||
| -rw-r--r-- | src/cgeo/geocaching/mapcommon/cgMapMyOverlay.java | 3 | ||||
| -rw-r--r-- | src/cgeo/geocaching/mapcommon/cgOverlayScale.java | 3 | ||||
| -rw-r--r-- | src/cgeo/geocaching/sorting/DistanceComparator.java | 31 |
11 files changed, 21 insertions, 55 deletions
diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java index c3625dd..7e69b89 100644 --- a/src/cgeo/geocaching/cgBase.java +++ b/src/cgeo/geocaching/cgBase.java @@ -2363,14 +2363,6 @@ public class cgBase { return text.trim(); } - public static double getDistance(final Geopoint coords1, final Geopoint coords2) { - if (coords1 == null || coords2 == null) { - return 0; - } - - return coords1.distanceTo(coords2); // TODO Check callers for null and replace them - } - public static double getHeading(final Geopoint coords1, final Geopoint coords2) { return coords1.bearingTo(coords2); // TODO Replace callers } diff --git a/src/cgeo/geocaching/cgCacheListAdapter.java b/src/cgeo/geocaching/cgCacheListAdapter.java index dec5bef..0a4faaf 100644 --- a/src/cgeo/geocaching/cgCacheListAdapter.java +++ b/src/cgeo/geocaching/cgCacheListAdapter.java @@ -50,7 +50,6 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { private LayoutInflater inflater = null; private Activity activity = null; private cgBase base = null; - private DistanceComparator dstComparator = null; private CacheComparator statComparator = null; private boolean historic = false; private Geopoint coords = null; @@ -79,7 +78,6 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { settings = settingsIn; list = listIn; base = baseIn; - dstComparator = new DistanceComparator(); DisplayMetrics metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); @@ -257,7 +255,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { return; } - dstComparator.setCoords(coordsIn); + final DistanceComparator dstComparator = new DistanceComparator(coordsIn); Collections.sort((List<cgCache>) list, dstComparator); } notifyDataSetChanged(); @@ -278,7 +276,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { if (statComparator != null) { Collections.sort((List<cgCache>) list, statComparator); } else { - dstComparator.setCoords(coordsIn); + final DistanceComparator dstComparator = new DistanceComparator(coordsIn); Collections.sort((List<cgCache>) list, dstComparator); } notifyDataSetChanged(); diff --git a/src/cgeo/geocaching/cgDistanceView.java b/src/cgeo/geocaching/cgDistanceView.java index ae9e7b7..2e17247 100644 --- a/src/cgeo/geocaching/cgDistanceView.java +++ b/src/cgeo/geocaching/cgDistanceView.java @@ -27,11 +27,10 @@ public class cgDistanceView extends TextView { } public void update(final Geopoint coords) { - if (cacheCoords == null) return; - if (coords == null) return; - if (base == null) return; - - setText(base.getHumanDistance(cgBase.getDistance(coords, cacheCoords))); + if (cacheCoords == null || coords == null || base == null) { + return; + } + setText(base.getHumanDistance(coords.distanceTo(cacheCoords))); } public void setDistance(Double distance) { diff --git a/src/cgeo/geocaching/cgGeo.java b/src/cgeo/geocaching/cgGeo.java index c908580..9903e86 100644 --- a/src/cgeo/geocaching/cgGeo.java +++ b/src/cgeo/geocaching/cgGeo.java @@ -342,9 +342,9 @@ public class cgGeo { if (gps == 1) { // save travelled distance only when location is from GPS if (coordsBefore != null && coordsNow != null) { - final double dst = cgBase.getDistance(coordsBefore, coordsNow); + final float dst = coordsBefore.distanceTo(coordsNow); - if (Double.isNaN(dst) == false && dst > 0.005) { + if (dst > 0.005) { distanceNow += dst; coordsBefore = coordsNow; @@ -375,7 +375,7 @@ public class cgGeo { return; } - if (settings.publicLoc == 1 && (lastGo4cacheCoords == null || cgBase.getDistance(coordsNow, lastGo4cacheCoords) > 0.75)) { + if (settings.publicLoc == 1 && (lastGo4cacheCoords == null || coordsNow.distanceTo(lastGo4cacheCoords) > 0.75)) { g4cRunning = true; final String host = "api.go4cache.com"; diff --git a/src/cgeo/geocaching/cgeo.java b/src/cgeo/geocaching/cgeo.java index 1c7a4c4..1f6260f 100644 --- a/src/cgeo/geocaching/cgeo.java +++ b/src/cgeo/geocaching/cgeo.java @@ -555,7 +555,7 @@ public class cgeo extends AbstractActivity { if (addCoords == null) { navLocation.setText(res.getString(R.string.loc_no_addr)); } - if (addCoords == null || (cgBase.getDistance(geo.coordsNow, addCoords) > 0.5 && addressObtaining == false)) { + if (addCoords == null || (geo.coordsNow.distanceTo(addCoords) > 0.5 && addressObtaining == false)) { (new obtainAddress()).start(); } } else { diff --git a/src/cgeo/geocaching/cgeodetail.java b/src/cgeo/geocaching/cgeodetail.java index 2b35618..340e8ee 100644 --- a/src/cgeo/geocaching/cgeodetail.java +++ b/src/cgeo/geocaching/cgeodetail.java @@ -1084,7 +1084,7 @@ public class cgeodetail extends AbstractActivity { } if (geo != null && geo.coordsNow != null && cache != null && cache.coords != null) { - cacheDistance.setText(base.getHumanDistance(cgBase.getDistance(geo.coordsNow, cache.coords))); + cacheDistance.setText(base.getHumanDistance(geo.coordsNow.distanceTo(cache.coords))); cacheDistance.bringToFront(); } } catch (Exception e) { @@ -1636,7 +1636,7 @@ public class cgeodetail extends AbstractActivity { StringBuilder dist = new StringBuilder(); if (geo.coordsNow != null && cache != null && cache.coords != null) { - dist.append(base.getHumanDistance(cgBase.getDistance(geo.coordsNow, cache.coords))); + dist.append(base.getHumanDistance(geo.coordsNow.distanceTo(cache.coords))); } if (cache != null && cache.elevation != null) { diff --git a/src/cgeo/geocaching/cgeonavigate.java b/src/cgeo/geocaching/cgeonavigate.java index 037db1c..7f9374e 100644 --- a/src/cgeo/geocaching/cgeonavigate.java +++ b/src/cgeo/geocaching/cgeonavigate.java @@ -342,7 +342,7 @@ public class cgeonavigate extends AbstractActivity { } cacheHeading = cgBase.getHeading(geo.coordsNow, dstCoords); - distanceView.setText(base.getHumanDistance(cgBase.getDistance(geo.coordsNow, dstCoords))); + distanceView.setText(base.getHumanDistance(geo.coordsNow.distanceTo(dstCoords))); headingView.setText(String.format(Locale.getDefault(), "%.0f", cacheHeading) + "°"); } diff --git a/src/cgeo/geocaching/cgeopopup.java b/src/cgeo/geocaching/cgeopopup.java index 696fc17..029e8d7 100644 --- a/src/cgeo/geocaching/cgeopopup.java +++ b/src/cgeo/geocaching/cgeopopup.java @@ -510,7 +510,7 @@ public class cgeopopup extends AbstractActivity { try { if (geo.coordsNow != null && cache != null && cache.coords != null) { - cacheDistance.setText(base.getHumanDistance(cgBase.getDistance(geo.coordsNow, cache.coords))); + cacheDistance.setText(base.getHumanDistance(geo.coordsNow.distanceTo(cache.coords))); cacheDistance.bringToFront(); } } catch (Exception e) { diff --git a/src/cgeo/geocaching/mapcommon/cgMapMyOverlay.java b/src/cgeo/geocaching/mapcommon/cgMapMyOverlay.java index ffe3e21..fa04645 100644 --- a/src/cgeo/geocaching/mapcommon/cgMapMyOverlay.java +++ b/src/cgeo/geocaching/mapcommon/cgMapMyOverlay.java @@ -14,7 +14,6 @@ import android.graphics.PaintFlagsDrawFilter; import android.graphics.Point; import android.location.Location; import cgeo.geocaching.R; -import cgeo.geocaching.cgBase; import cgeo.geocaching.cgSettings; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.mapinterfaces.GeoPointImpl; @@ -128,7 +127,7 @@ public class cgMapMyOverlay implements OverlayBase { accuracyCircle.setStyle(Style.FILL); canvas.drawCircle(center.x, center.y, radius, accuracyCircle); - if (coordinates.getAccuracy() < 50f && ((historyRecent != null && cgBase.getDistance(new Geopoint(historyRecent), new Geopoint(coordinates)) > 0.005) || historyRecent == null)) { + if (coordinates.getAccuracy() < 50f && ((historyRecent != null && historyRecent.distanceTo(coordinates) > 5.0) || historyRecent == null)) { if (historyRecent != null) history.add(historyRecent); historyRecent = coordinates; diff --git a/src/cgeo/geocaching/mapcommon/cgOverlayScale.java b/src/cgeo/geocaching/mapcommon/cgOverlayScale.java index e4db67c..f7fb969 100644 --- a/src/cgeo/geocaching/mapcommon/cgOverlayScale.java +++ b/src/cgeo/geocaching/mapcommon/cgOverlayScale.java @@ -59,8 +59,7 @@ public class cgOverlayScale implements OverlayBase { final Geopoint leftCoords = new Geopoint(center.getLatitudeE6() / 1e6, center.getLongitudeE6() / 1e6 - span /2); final Geopoint rightCoords = new Geopoint(center.getLatitudeE6() / 1e6, center.getLongitudeE6() / 1e6 + span /2); - distance = cgBase.getDistance(leftCoords, rightCoords); - distance = distance / 2; + distance = leftCoords.distanceTo(rightCoords) / 2; distanceRound = 0d; if(settings.units == cgSettings.unitsImperial) { diff --git a/src/cgeo/geocaching/sorting/DistanceComparator.java b/src/cgeo/geocaching/sorting/DistanceComparator.java index 6198753..9a5b551 100644 --- a/src/cgeo/geocaching/sorting/DistanceComparator.java +++ b/src/cgeo/geocaching/sorting/DistanceComparator.java @@ -1,6 +1,5 @@ package cgeo.geocaching.sorting; -import cgeo.geocaching.cgBase; import cgeo.geocaching.cgCache; import cgeo.geocaching.geopoint.Geopoint; @@ -9,17 +8,9 @@ import cgeo.geocaching.geopoint.Geopoint; * */ public class DistanceComparator extends AbstractCacheComparator { - private Geopoint coords = null; - - public DistanceComparator() { - // nothing - } + private final Geopoint coords; public DistanceComparator(final Geopoint coords) { - setCoords(coords); - } - - public void setCoords(final Geopoint coords) { this.coords = coords; } @@ -32,13 +23,7 @@ public class DistanceComparator extends AbstractCacheComparator { protected int compareCaches(final cgCache cache1, final cgCache cache2) { if ((cache1.coords == null || cache2.coords == null) && cache1.distance != null && cache2.distance != null) { - if (cache1.distance < cache2.distance) { - return -1; - } else if (cache1.distance > cache2.distance) { - return 1; - } else { - return 0; - } + return Double.compare(cache1.distance, cache2.distance); } else { if (cache1.coords == null) { return 1; @@ -47,15 +32,9 @@ public class DistanceComparator extends AbstractCacheComparator { return -1; } - Double distance1 = cgBase.getDistance(coords, cache1.coords); - Double distance2 = cgBase.getDistance(coords, cache2.coords); - - if (distance1 < distance2) { - return -1; - } else if (distance1 > distance2) { - return 1; - } + return Float.compare(coords.distanceTo(cache1.coords), + coords.distanceTo(cache2.coords)); } - return 0; } + } |
