diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2012-05-06 07:55:09 +0200 |
---|---|---|
committer | Bananeweizen <bananeweizen@gmx.de> | 2012-05-06 07:55:09 +0200 |
commit | 6dfaab43fc05406313db3d092e90307dea0e6b90 (patch) | |
tree | 77497565cc99b2c3b6b4475167070f9b10ff1f51 /main/src/cgeo/geocaching/ui | |
parent | a662a4c20d6797cf0e39324e12ceb0ad53b5ddce (diff) | |
download | cgeo-6dfaab43fc05406313db3d092e90307dea0e6b90.zip cgeo-6dfaab43fc05406313db3d092e90307dea0e6b90.tar.gz cgeo-6dfaab43fc05406313db3d092e90307dea0e6b90.tar.bz2 |
refactoring: addition to #1509 to unify distance code
Diffstat (limited to 'main/src/cgeo/geocaching/ui')
-rw-r--r-- | main/src/cgeo/geocaching/ui/CacheDetailsCreator.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java index e4a0fe5..70fc2bb 100644 --- a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java +++ b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java @@ -2,6 +2,9 @@ package cgeo.geocaching.ui; import cgeo.geocaching.R; import cgeo.geocaching.cgCache; +import cgeo.geocaching.cgeoapplication; +import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.geopoint.HumanDistance; import org.apache.commons.lang3.StringUtils; @@ -129,4 +132,29 @@ public final class CacheDetailsCreator { addStars(R.string.cache_terrain, cache.getTerrain()); } } + + public void addDistance(final cgCache cache, final TextView cacheDistanceView) { + Float distance = null; + if (cache.getCoords() != null) { + final Geopoint currentCoords = cgeoapplication.getInstance().currentGeo().getCoords(); + if (currentCoords != null) { + distance = currentCoords.distanceTo(cache); + } + } + if (distance == null) { + if (cache.getDistance() != null) { + distance = cache.getDistance(); + } + } + String text = "--"; + if (distance != null) { + text = HumanDistance.getHumanDistance(distance); + } + else if (cacheDistanceView != null) { + // if there is already a distance in cacheDistance, use it instead of resetting to default. + // this prevents displaying "--" while waiting for a new position update (See bug #1468) + text = cacheDistanceView.getText().toString(); + } + add(R.string.cache_distance, text); + } } |