diff options
Diffstat (limited to 'src')
47 files changed, 555 insertions, 693 deletions
diff --git a/src/cgeo/geocaching/StaticMapsProvider.java b/src/cgeo/geocaching/StaticMapsProvider.java index 5962460..97e9bd1 100644 --- a/src/cgeo/geocaching/StaticMapsProvider.java +++ b/src/cgeo/geocaching/StaticMapsProvider.java @@ -123,12 +123,12 @@ public class StaticMapsProvider { } public static void downloadMaps(cgCache cache, cgSettings settings, Activity activity) { - if (settings.storeOfflineMaps != 1 || cache.latitude == null - || cache.longitude == null || StringUtils.isNotBlank(cache.geocode)) { + if (settings.storeOfflineMaps != 1 || cache.coords == null || StringUtils.isNotBlank(cache.geocode)) { return; } - final String latlonMap = String.format((Locale) null, "%.6f", cache.latitude) + "," + String.format((Locale) null, "%.6f", cache.longitude); + final String latlonMap = String.format((Locale) null, "%.6f", cache.coords.getLatitude()) + "," + + String.format((Locale) null, "%.6f", cache.coords.getLongitude()); final Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); final int maxWidth = display.getWidth() - 25; final int maxHeight = display.getHeight() - 25; @@ -142,7 +142,7 @@ public class StaticMapsProvider { final StringBuilder waypoints = new StringBuilder(); if (CollectionUtils.isNotEmpty(cache.waypoints)) { for (cgWaypoint waypoint : cache.waypoints) { - if (waypoint.latitude == null && waypoint.longitude == null) { + if (waypoint.coords == null) { continue; } @@ -151,9 +151,9 @@ public class StaticMapsProvider { waypoints.append("marker_waypoint_"); waypoints.append(waypoint.type); waypoints.append(".png%7C"); - waypoints.append(String.format((Locale) null, "%.6f", waypoint.latitude)); + waypoints.append(String.format((Locale) null, "%.6f", waypoint.coords.getLatitude())); waypoints.append(','); - waypoints.append(String.format((Locale) null, "%.6f", waypoint.longitude)); + waypoints.append(String.format((Locale) null, "%.6f", waypoint.coords.getLongitude())); } } diff --git a/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java b/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java index 273be5c..6307434 100644 --- a/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java +++ b/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java @@ -14,6 +14,7 @@ import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgSettings; import cgeo.geocaching.cgWaypoint; import cgeo.geocaching.activity.ActivityMixin; +import cgeo.geocaching.geopoint.Geopoint; class GoogleMapsApp extends AbstractNavigationApp implements NavigationApp { @@ -28,18 +29,16 @@ class GoogleMapsApp extends AbstractNavigationApp implements NavigationApp { public boolean invoke(cgGeo geo, Activity activity, Resources res, cgCache cache, - final UUID searchId, cgWaypoint waypoint, Double latitude, Double longitude) { - if (cache == null && waypoint == null && latitude == null && longitude == null) { + final UUID searchId, cgWaypoint waypoint, final Geopoint coords) { + if (cache == null && waypoint == null && coords == null) { return false; } try { - if (cache != null && cache.latitude != null && cache.longitude != null) { - activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("geo:" + cache.latitude + "," + cache.longitude))); - // INFO: q parameter works with Google Maps, but breaks cooperation with all other apps - } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) { - activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("geo:" + waypoint.latitude + "," + waypoint.longitude))); - // INFO: q parameter works with Google Maps, but breaks cooperation with all other apps + if (cache != null && cache.coords != null) { + startActivity(activity, cache.coords); + } else if (waypoint != null && waypoint.coords != null) { + startActivity(activity, waypoint.coords); } return true; @@ -56,4 +55,10 @@ class GoogleMapsApp extends AbstractNavigationApp implements NavigationApp { return false; } + private void startActivity(Activity activity, final Geopoint coords) { + activity.startActivity(new Intent(Intent.ACTION_VIEW, + Uri.parse("geo:" + coords.getLatitude() + "," + coords.getLongitude()))); + // INFO: q parameter works with Google Maps, but breaks cooperation with all other apps + } + } diff --git a/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java b/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java index 4a7a49e..c106988 100644 --- a/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java +++ b/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java @@ -14,6 +14,7 @@ import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgSettings; import cgeo.geocaching.cgWaypoint; import cgeo.geocaching.activity.ActivityMixin; +import cgeo.geocaching.geopoint.Geopoint; class GoogleNavigationApp extends AbstractNavigationApp implements NavigationApp { @@ -30,20 +31,20 @@ class GoogleNavigationApp extends AbstractNavigationApp implements @Override public boolean invoke(final cgGeo geo, final Activity activity, final Resources res, final cgCache cache, - final UUID searchId, final cgWaypoint waypoint, final Double latitude, final Double longitude) { + final UUID searchId, final cgWaypoint waypoint, final Geopoint coords) { if (activity == null) { return false; } boolean navigationResult = false; - if (latitude != null && longitude != null) { - navigationResult = navigateToCoordinates(geo, activity, latitude, longitude); + if (coords != null) { + navigationResult = navigateToCoordinates(geo, activity, coords); } else if (waypoint != null) { - navigationResult = navigateToCoordinates(geo, activity, waypoint.latitude, waypoint.longitude); + navigationResult = navigateToCoordinates(geo, activity, waypoint.coords); } else if (cache != null) { - navigationResult = navigateToCoordinates(geo, activity, cache.latitude, cache.longitude); + navigationResult = navigateToCoordinates(geo, activity, cache.coords); } if (!navigationResult) { @@ -56,14 +57,8 @@ class GoogleNavigationApp extends AbstractNavigationApp implements return true; } - private static boolean navigateToCoordinates(cgGeo geo, Activity activity, Double latitude, - Double longitude) { - Double latitudeNow = null; - Double longitudeNow = null; - if (geo != null) { - latitudeNow = geo.latitudeNow; - longitudeNow = geo.longitudeNow; - } + private static boolean navigateToCoordinates(cgGeo geo, Activity activity, final Geopoint coords) { + final Geopoint coordsNow = geo == null ? null : geo.coordsNow; cgSettings settings = getSettings(activity); @@ -71,8 +66,8 @@ class GoogleNavigationApp extends AbstractNavigationApp implements if (settings.useGNavigation == 1) { try { activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri - .parse("google.navigation:ll=" + latitude + "," - + longitude))); + .parse("google.navigation:ll=" + coords.getLatitude() + "," + + coords.getLongitude()))); return true; } catch (Exception e) { @@ -82,15 +77,15 @@ class GoogleNavigationApp extends AbstractNavigationApp implements // Google Maps Directions try { - if (latitudeNow != null && longitudeNow != null) { + if (coordsNow != null) { activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri .parse("http://maps.google.com/maps?f=d&saddr=" - + latitudeNow + "," + longitudeNow + "&daddr=" - + latitude + "," + longitude))); + + coordsNow.getLatitude() + "," + coordsNow.getLongitude() + "&daddr=" + + coords.getLatitude() + "," + coords.getLongitude()))); } else { activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri .parse("http://maps.google.com/maps?f=d&daddr=" - + latitude + "," + longitude))); + + coords.getLatitude() + "," + coords.getLongitude()))); } return true; diff --git a/src/cgeo/geocaching/apps/cache/navi/InternalMap.java b/src/cgeo/geocaching/apps/cache/navi/InternalMap.java index 513172c..4936842 100644 --- a/src/cgeo/geocaching/apps/cache/navi/InternalMap.java +++ b/src/cgeo/geocaching/apps/cache/navi/InternalMap.java @@ -10,6 +10,7 @@ import cgeo.geocaching.cgCache; import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgSettings; import cgeo.geocaching.cgWaypoint; +import cgeo.geocaching.geopoint.Geopoint; class InternalMap extends AbstractInternalMap implements NavigationApp { @@ -21,7 +22,7 @@ class InternalMap extends AbstractInternalMap implements @Override public boolean invoke(cgGeo geo, Activity activity, Resources res, cgCache cache, - final UUID searchId, cgWaypoint waypoint, Double latitude, Double longitude) { + final UUID searchId, cgWaypoint waypoint, final Geopoint coords) { cgSettings settings = getSettings(activity); Intent mapIntent = new Intent(activity, settings.getMapFactory().getMapClass()); if (cache != null) { @@ -33,8 +34,8 @@ class InternalMap extends AbstractInternalMap implements mapIntent.putExtra("searchid", searchId.toString()); } if (waypoint != null) { - mapIntent.putExtra("latitude", waypoint.latitude); - mapIntent.putExtra("longitude", waypoint.longitude); + mapIntent.putExtra("latitude", waypoint.coords.getLatitude()); + mapIntent.putExtra("longitude", waypoint.coords.getLongitude()); mapIntent.putExtra("wpttype", waypoint.type); } diff --git a/src/cgeo/geocaching/apps/cache/navi/LocusApp.java b/src/cgeo/geocaching/apps/cache/navi/LocusApp.java index fdba2fc..3c9928e 100644 --- a/src/cgeo/geocaching/apps/cache/navi/LocusApp.java +++ b/src/cgeo/geocaching/apps/cache/navi/LocusApp.java @@ -19,6 +19,7 @@ import cgeo.geocaching.cgCache; import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgWaypoint; import cgeo.geocaching.apps.AbstractLocusApp; +import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.utils.CollectionUtils; class LocusApp extends AbstractLocusApp implements NavigationApp { @@ -30,9 +31,8 @@ class LocusApp extends AbstractLocusApp implements NavigationApp { @Override public boolean invoke(cgGeo geo, Activity activity, Resources res, cgCache cache, - final UUID searchId, cgWaypoint waypoint, Double latitude, Double longitude) { - if (cache == null && waypoint == null && latitude == null - && longitude == null) { + final UUID searchId, cgWaypoint waypoint, final Geopoint coords) { + if (cache == null && waypoint == null && coords == null) { return false; } try { @@ -42,7 +42,7 @@ class LocusApp extends AbstractLocusApp implements NavigationApp { if (cache != null && cache.waypoints != null && cache.waypoints.isEmpty() == false) { for (cgWaypoint wp : cache.waypoints) { - if (wp.latitude != null && wp.longitude != null) { + if (wp.coords != null) { waypoints.add(wp); } } @@ -118,24 +118,21 @@ class LocusApp extends AbstractLocusApp implements NavigationApp { dos.writeUTF(""); } - if (cache != null && cache.latitude != null - && cache.longitude != null) { - dos.writeDouble(cache.latitude); // latitude - dos.writeDouble(cache.longitude); // longitude - } else if (waypoint != null && waypoint.latitude != null - && waypoint.longitude != null) { - dos.writeDouble(waypoint.latitude); // latitude - dos.writeDouble(waypoint.longitude); // longitude + if (cache != null && cache.coords != null) { + dos.writeDouble(cache.coords.getLatitude()); // latitude + dos.writeDouble(cache.coords.getLongitude()); // longitude + } else if (waypoint != null && waypoint.coords != null) { + dos.writeDouble(waypoint.coords.getLatitude()); // latitude + dos.writeDouble(waypoint.coords.getLongitude()); // longitude } else { - dos.writeDouble(latitude); // latitude - dos.writeDouble(longitude); // longitude + dos.writeDouble(coords.getLatitude()); // latitude + dos.writeDouble(coords.getLongitude()); // longitude } // cache waypoints if (CollectionUtils.isNotEmpty(waypoints)) { for (cgWaypoint wp : waypoints) { - if (wp == null || wp.latitude == null - || wp.longitude == null) { + if (wp == null || wp.coords == null) { continue; } @@ -181,8 +178,8 @@ class LocusApp extends AbstractLocusApp implements NavigationApp { dos.writeUTF(""); } - dos.writeDouble(wp.latitude); // latitude - dos.writeDouble(wp.longitude); // longitude + dos.writeDouble(wp.coords.getLatitude()); // latitude + dos.writeDouble(wp.coords.getLongitude()); // longitude } } diff --git a/src/cgeo/geocaching/apps/cache/navi/NavigationApp.java b/src/cgeo/geocaching/apps/cache/navi/NavigationApp.java index db0c1e3..8a5bd13 100644 --- a/src/cgeo/geocaching/apps/cache/navi/NavigationApp.java +++ b/src/cgeo/geocaching/apps/cache/navi/NavigationApp.java @@ -8,11 +8,12 @@ import cgeo.geocaching.cgCache; import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgWaypoint; import cgeo.geocaching.apps.App; +import cgeo.geocaching.geopoint.Geopoint; interface NavigationApp extends App { public boolean invoke(final cgGeo geo, final Activity activity, final Resources res, final cgCache cache, final UUID searchId, final cgWaypoint waypoint, - final Double latitude, final Double longitude); + final Geopoint coords); } diff --git a/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java b/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java index b8872e3..70609de 100644 --- a/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java +++ b/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java @@ -1,6 +1,5 @@ package cgeo.geocaching.apps.cache.navi; -import java.util.List; import java.util.UUID; import org.apache.commons.lang3.ArrayUtils; @@ -15,6 +14,7 @@ import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgSettings; import cgeo.geocaching.cgWaypoint; import cgeo.geocaching.apps.AbstractAppFactory; +import cgeo.geocaching.geopoint.Geopoint; public final class NavigationAppFactory extends AbstractAppFactory { private static NavigationApp[] apps = new NavigationApp[] {}; @@ -47,18 +47,12 @@ public final class NavigationAppFactory extends AbstractAppFactory { public static boolean onMenuItemSelected(final MenuItem item, final cgGeo geo, Activity activity, Resources res, cgCache cache, - final UUID searchId, cgWaypoint waypoint, List<Double> destination) { + final UUID searchId, cgWaypoint waypoint, final Geopoint destination) { NavigationApp app = (NavigationApp) getAppFromMenuItem(item, apps); if (app != null) { - Double latitude = null; - Double longitude = null; - if (destination != null && destination.size() >= 2) { - latitude = destination.get(0); - longitude = destination.get(1); - } try { return app.invoke(geo, activity, res, cache, - searchId, waypoint, latitude, longitude); + searchId, waypoint, destination); } catch (Exception e) { Log.e(cgSettings.tag, "NavigationAppFactory.onMenuItemSelected: " + e.toString()); } diff --git a/src/cgeo/geocaching/apps/cache/navi/RMapsApp.java b/src/cgeo/geocaching/apps/cache/navi/RMapsApp.java index 8e75aaa..37c727d 100644 --- a/src/cgeo/geocaching/apps/cache/navi/RMapsApp.java +++ b/src/cgeo/geocaching/apps/cache/navi/RMapsApp.java @@ -11,6 +11,7 @@ import cgeo.geocaching.R; import cgeo.geocaching.cgCache; import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgWaypoint; +import cgeo.geocaching.geopoint.Geopoint; class RMapsApp extends AbstractNavigationApp implements NavigationApp { @@ -23,32 +24,29 @@ class RMapsApp extends AbstractNavigationApp implements NavigationApp { @Override public boolean invoke(cgGeo geo, Activity activity, Resources res, cgCache cache, - final UUID searchId, cgWaypoint waypoint, Double latitude, Double longitude) { - if (cache == null && waypoint == null && latitude == null - && longitude == null) { + final UUID searchId, cgWaypoint waypoint, final Geopoint coords) { + if (cache == null && waypoint == null && coords == null) { return false; } try { if (isInstalled(activity)) { final ArrayList<String> locations = new ArrayList<String>(); - if (cache != null && cache.latitude != null - && cache.longitude != null) { + if (cache != null && cache.coords != null) { locations.add(String.format((Locale) null, "%.6f", - cache.latitude) + cache.coords.getLatitude()) + "," + String.format((Locale) null, "%.6f", - cache.longitude) + cache.coords.getLongitude()) + ";" + cache.geocode + ";" + cache.name); - } else if (waypoint != null && waypoint.latitude != null - && waypoint.longitude != null) { + } else if (waypoint != null && waypoint.coords != null) { locations.add(String.format((Locale) null, "%.6f", - waypoint.latitude) + waypoint.coords.getLatitude()) + "," + String.format((Locale) null, "%.6f", - waypoint.longitude) + waypoint.coords.getLongitude()) + ";" + waypoint.lookup + ";" + waypoint.name); diff --git a/src/cgeo/geocaching/apps/cache/navi/RadarApp.java b/src/cgeo/geocaching/apps/cache/navi/RadarApp.java index 7dc7676..1e5278f 100644 --- a/src/cgeo/geocaching/apps/cache/navi/RadarApp.java +++ b/src/cgeo/geocaching/apps/cache/navi/RadarApp.java @@ -9,6 +9,7 @@ import cgeo.geocaching.R; import cgeo.geocaching.cgCache; import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgWaypoint; +import cgeo.geocaching.geopoint.Geopoint; class RadarApp extends AbstractNavigationApp implements NavigationApp { @@ -19,31 +20,31 @@ class RadarApp extends AbstractNavigationApp implements NavigationApp { super(res.getString(R.string.cache_menu_radar), INTENT, PACKAGE_NAME); } - private static void navigateTo(Activity activity, Double latitude, Double longitude) { + private static void navigateTo(Activity activity, final Geopoint coords) { Intent radarIntent = new Intent(INTENT); - radarIntent.putExtra("latitude", Float.valueOf(latitude.floatValue())); - radarIntent.putExtra("longitude", Float.valueOf(longitude.floatValue())); + radarIntent.putExtra("latitude", (float) coords.getLatitude()); + radarIntent.putExtra("longitude", (float) coords.getLongitude()); activity.startActivity(radarIntent); } @Override public boolean invoke(cgGeo geo, Activity activity, Resources res, cgCache cache, - final UUID searchId, cgWaypoint waypoint, Double latitude, Double longitude) { + final UUID searchId, cgWaypoint waypoint, final Geopoint coords) { if (cache != null) { - if (cache.latitude != null && cache.longitude != null) { - navigateTo(activity, cache.latitude, cache.longitude); + if (cache.coords != null) { + navigateTo(activity, cache.coords); return true; } } if (waypoint != null) { - if (waypoint.latitude != null && waypoint.longitude != null) { - navigateTo(activity, waypoint.latitude, waypoint.longitude); + if (waypoint.coords != null) { + navigateTo(activity, waypoint.coords); return true; } } - if (latitude != null && longitude != null) { - navigateTo(activity, latitude, longitude); + if (coords != null) { + navigateTo(activity, coords); return true; } return false; diff --git a/src/cgeo/geocaching/apps/cache/navi/StaticMapApp.java b/src/cgeo/geocaching/apps/cache/navi/StaticMapApp.java index db6b27b..e989981 100644 --- a/src/cgeo/geocaching/apps/cache/navi/StaticMapApp.java +++ b/src/cgeo/geocaching/apps/cache/navi/StaticMapApp.java @@ -12,6 +12,7 @@ import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgWaypoint; import cgeo.geocaching.cgeosmaps; import cgeo.geocaching.activity.ActivityMixin; +import cgeo.geocaching.geopoint.Geopoint; class StaticMapApp extends AbstractNavigationApp implements NavigationApp { @@ -28,7 +29,7 @@ class StaticMapApp extends AbstractNavigationApp implements @Override public boolean invoke(cgGeo geo, Activity activity, Resources res, cgCache cache, - final UUID searchId, cgWaypoint waypoint, Double latitude, Double longitude) { + final UUID searchId, cgWaypoint waypoint, final Geopoint coords) { if (cache == null || cache.reason == 0) { ActivityMixin.showToast(activity, res.getString(R.string.err_detail_no_map_static)); diff --git a/src/cgeo/geocaching/apps/cache/navi/StreetviewApp.java b/src/cgeo/geocaching/apps/cache/navi/StreetviewApp.java index 250bc65..1b8a101 100644 --- a/src/cgeo/geocaching/apps/cache/navi/StreetviewApp.java +++ b/src/cgeo/geocaching/apps/cache/navi/StreetviewApp.java @@ -13,6 +13,7 @@ import cgeo.geocaching.cgCache; import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgWaypoint; import cgeo.geocaching.activity.ActivityMixin; +import cgeo.geocaching.geopoint.Geopoint; class StreetviewApp extends AbstractNavigationApp implements NavigationApp { @@ -27,16 +28,16 @@ class StreetviewApp extends AbstractNavigationApp implements NavigationApp { public boolean invoke(cgGeo geo, Activity activity, Resources res, cgCache cache, - final UUID searchId, cgWaypoint waypoint, Double latitude, Double longitude) { - if (cache == null && waypoint == null && latitude == null && longitude == null) { + final UUID searchId, cgWaypoint waypoint, final Geopoint coords) { + if (cache == null && waypoint == null && coords == null) { return false; } try { - if (cache != null && cache.latitude != null && cache.longitude != null) { - activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("google.streetview:cbll=" + cache.latitude + "," + cache.longitude))); - } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) { - activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("google.streetview:cbll=" + waypoint.latitude + "," + waypoint.longitude))); + if (cache != null && cache.coords != null) { + startActivity(activity, cache.coords); + } else if (waypoint != null && waypoint.coords != null) { + startActivity(activity, waypoint.coords); } return true; @@ -48,4 +49,9 @@ class StreetviewApp extends AbstractNavigationApp implements NavigationApp { return false; } + + private void startActivity(Activity activity, final Geopoint coords) { + activity.startActivity(new Intent(Intent.ACTION_VIEW, + Uri.parse("google.streetview:cbll=" + coords.getLatitude() + "," + coords.getLongitude()))); + } } diff --git a/src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java b/src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java index d72c398..41a1cdd 100644 --- a/src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java +++ b/src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java @@ -34,7 +34,7 @@ class LocusCacheListApp extends AbstractLocusApp implements CacheListApp { try { final List<cgCache> cacheListCoord = new ArrayList<cgCache>(); for (cgCache cache : cacheList) { - if (cache.latitude != null && cache.longitude != null) { + if (cache.coords != null) { cacheListCoord.add(cache); } } @@ -84,8 +84,8 @@ class LocusCacheListApp extends AbstractLocusApp implements CacheListApp { dos.writeUTF(""); } - dos.writeDouble(cache.latitude); // latitude - dos.writeDouble(cache.longitude); // longitude + dos.writeDouble(cache.coords.getLatitude()); // latitude + dos.writeDouble(cache.coords.getLongitude()); // longitude } final Intent intent = new Intent(); diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java index a0f1ac9..e0268f8 100644 --- a/src/cgeo/geocaching/cgBase.java +++ b/src/cgeo/geocaching/cgBase.java @@ -71,6 +71,7 @@ import android.util.Log; import android.widget.EditText; import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.files.LocParser; +import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.utils.CollectionUtils; public class cgBase { @@ -967,8 +968,8 @@ public class cgBase { // get direction images if (settings.getLoadDirImg()) { - for (cgCache oneCache : caches.cacheList) { - if (oneCache.latitude == null && oneCache.longitude == null && oneCache.directionImg != null) { + for (cgCache oneCache : caches.cacheList) { + if (oneCache.coords == null && oneCache.directionImg != null) { cgDirectionImg.getDrawable(oneCache.geocode, oneCache.directionImg); } } @@ -1037,8 +1038,7 @@ public class cgBase { final cgCache cacheToAdd = new cgCache(); cacheToAdd.reliableLatLon = false; cacheToAdd.geocode = oneCache.getString("gc"); - cacheToAdd.latitude = oneCache.getDouble("lat"); - cacheToAdd.longitude = oneCache.getDouble("lon"); + cacheToAdd.coords = new Geopoint(oneCache.getDouble("lat"), oneCache.getDouble("lon")); cacheToAdd.name = oneCache.getString("nn"); cacheToAdd.found = oneCache.getBoolean("f"); cacheToAdd.own = oneCache.getBoolean("o"); @@ -1333,8 +1333,7 @@ public class cgBase { Map<String, Object> tmp = cgBase.parseLatlon(cache.latlon); if (tmp.size() > 0) { - cache.latitude = (Double) tmp.get("latitude"); - cache.longitude = (Double) tmp.get("longitude"); + cache.coords = new Geopoint((Double) tmp.get("latitude"), (Double) tmp.get("longitude")); cache.latitudeString = (String) tmp.get("latitudeString"); cache.longitudeString = (String) tmp.get("longitudeString"); cache.reliableLatLon = true; @@ -1725,8 +1724,7 @@ public class cgBase { final Map<String, Object> tmp = cgBase.parseLatlon(waypoint.latlon); if (tmp.size() > 0) { - waypoint.latitude = (Double) tmp.get("latitude"); - waypoint.longitude = (Double) tmp.get("longitude"); + waypoint.coords = new Geopoint((Double) tmp.get("latitude"), (Double) tmp.get("longitude")); waypoint.latitudeString = (String) tmp.get("latitudeString"); waypoint.longitudeString = (String) tmp.get("longitudeString"); } @@ -1760,8 +1758,8 @@ public class cgBase { } } - if (cache.latitude != null && cache.longitude != null) { - cache.elevation = getElevation(cache.latitude, cache.longitude); + if (cache.coords != null) { + cache.elevation = getElevation(cache.coords); } final cgRating rating = getRating(cache.guid, cache.geocode); @@ -1813,11 +1811,8 @@ public class cgBase { if (StringUtils.isNotBlank(cache.type)) { Log.w(cgSettings.tag, "type not parsed correctly"); } - if (cache.latitude == null) { - Log.w(cgSettings.tag, "latitude not parsed correctly"); - } - if (cache.longitude == null) { - Log.w(cgSettings.tag, "longitude not parsed correctly"); + if (cache.coords == null) { + Log.w(cgSettings.tag, "coordinates not parsed correctly"); } if (StringUtils.isEmpty(cache.location)) { Log.w(cgSettings.tag, "location not parsed correctly"); @@ -2426,83 +2421,20 @@ public class cgBase { return distance; } - public static double getDistance(Double lat1, Double lon1, Double lat2, Double lon2) { - if (lat1 == null || lon1 == null || lat2 == null || lon2 == null) { - return 0d; + public static double getDistance(final Geopoint coords1, final Geopoint coords2) { + if (coords1 == null || coords2 == null) { + return 0; } - lat1 *= deg2rad; - lon1 *= deg2rad; - lat2 *= deg2rad; - lon2 *= deg2rad; - - final double d = Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(lon1 - lon2); - final double distance = erad * Math.acos(d); // distance in km - - if (Double.isNaN(distance) == false && distance > 0) { - return distance; - } else { - return 0d; - } + return coords1.distanceTo(coords2); // TODO Check callers for null and replace them } - public static Double getHeading(Double lat1, Double lon1, Double lat2, Double lon2) { - Double result = Double.valueOf(0); - - int ilat1 = (int) Math.round(0.5 + lat1 * 360000); - int ilon1 = (int) Math.round(0.5 + lon1 * 360000); - int ilat2 = (int) Math.round(0.5 + lat2 * 360000); - int ilon2 = (int) Math.round(0.5 + lon2 * 360000); - - lat1 *= deg2rad; - lon1 *= deg2rad; - lat2 *= deg2rad; - lon2 *= deg2rad; - - if (ilat1 == ilat2 && ilon1 == ilon2) { - return Double.valueOf(result); - } else if (ilat1 == ilat2) { - if (ilon1 > ilon2) { - result = Double.valueOf(270); - } else { - result = Double.valueOf(90); - } - } else if (ilon1 == ilon2) { - if (ilat1 > ilat2) { - result = Double.valueOf(180); - } - } else { - Double c = Math.acos(Math.sin(lat2) * Math.sin(lat1) + Math.cos(lat2) * Math.cos(lat1) * Math.cos(lon2 - lon1)); - Double A = Math.asin(Math.cos(lat2) * Math.sin(lon2 - lon1) / Math.sin(c)); - result = Double.valueOf(A * rad2deg); - if (ilat2 > ilat1 && ilon2 > ilon1) { - // result don't need change - } else if (ilat2 < ilat1 && ilon2 < ilon1) { - result = 180f - result; - } else if (ilat2 < ilat1 && ilon2 > ilon1) { - result = 180f - result; - } else if (ilat2 > ilat1 && ilon2 < ilon1) { - result += 360f; - } - } - - return result; + public static double getHeading(final Geopoint coords1, final Geopoint coords2) { + return coords1.bearingTo(coords2); // TODO Replace callers } - public static Map<String, Double> getRadialDistance(Double latitude, Double longitude, Double bearing, Double distance) { - final Double rlat1 = latitude * deg2rad; - final Double rlon1 = longitude * deg2rad; - final Double rbearing = bearing * deg2rad; - final Double rdistance = distance / erad; - - final Double rlat = Math.asin(Math.sin(rlat1) * Math.cos(rdistance) + Math.cos(rlat1) * Math.sin(rdistance) * Math.cos(rbearing)); - final Double rlon = rlon1 + Math.atan2(Math.sin(rbearing) * Math.sin(rdistance) * Math.cos(rlat1), Math.cos(rdistance) - Math.sin(rlat1) * Math.sin(rlat)); - - Map<String, Double> result = new HashMap<String, Double>(); - result.put("latitude", rlat * rad2deg); - result.put("longitude", rlon * rad2deg); - - return result; + public static Geopoint getRadialDistance(final Geopoint coords, double bearing, double distance) { + return coords.project(bearing, distance); // TODO Replace callers } public String getHumanDistance(Float distance) { @@ -2623,10 +2555,11 @@ public class cgBase { return formatCoordinate(coord, degrees, (coord >= 0) ? "E " : "W ", "%03.0f"); } - public static String formatCoords(final Double latitude, final Double longitude, final boolean degrees) { - return formatLatitude(latitude, degrees) + " | " + formatLongitude(longitude, degrees); + public static String formatCoords(final Geopoint coords, final boolean degrees) { + return formatLatitude(coords.getLatitude(), degrees) + " | " + formatLongitude(coords.getLongitude(), degrees); } + // TODO Use android.util.Pair<Double, String> if needed rather than a Map here. public static Map<String, Object> parseCoordinate(String coord, String latlon) { final Map<String, Object> coords = new HashMap<String, Object>(); @@ -4679,8 +4612,8 @@ public class cgBase { } } - public static boolean isCacheInViewPort(int centerLat, int centerLon, int spanLat, int spanLon, Double cacheLat, Double cacheLon) { - if (cacheLat == null || cacheLon == null) { + public static boolean isCacheInViewPort(int centerLat, int centerLon, int spanLat, int spanLon, final Geopoint cacheCoords) { + if (cacheCoords == null) { return false; } @@ -4689,8 +4622,8 @@ public class cgBase { int maxLat = centerLat + (spanLat / 2) + (spanLat / 10); int minLon = centerLon - (spanLon / 2) - (spanLon / 10); int maxLon = centerLon + (spanLon / 2) + (spanLon / 10); - int cLat = (int) Math.round(cacheLat * 1e6); - int cLon = (int) Math.round(cacheLon * 1e6); + int cLat = (int) Math.round(cacheCoords.getLatitudeE6()); + int cLon = (int) Math.round(cacheCoords.getLongitudeE6()); int mid = 0; if (maxLat < minLat) { @@ -5028,37 +4961,37 @@ public class cgBase { return usertoken; } - public static Double getElevation(Double latitude, Double longitude) { - Double elv = null; - + public static Double getElevation(final Geopoint coords) { try { final String host = "maps.googleapis.com"; final String path = "/maps/api/elevation/json"; - final String params = "sensor=false&locations=" + String.format((Locale) null, "%.6f", latitude) + "," + String.format((Locale) null, "%.6f", longitude); + final String params = "sensor=false&locations=" + + String.format((Locale) null, "%.6f", coords.getLatitude()) + "," + + String.format((Locale) null, "%.6f", coords.getLongitude()); final String data = requestJSON(host, path, params); if (StringUtils.isBlank(data)) { - return elv; + return null; } JSONObject response = new JSONObject(data); String status = response.getString("status"); if (status == null || status.equalsIgnoreCase("OK") == false) { - return elv; + return null; } if (response.has("results")) { JSONArray results = response.getJSONArray("results"); JSONObject result = results.getJSONObject(0); - elv = result.getDouble("elevation"); + return result.getDouble("elevation"); } } catch (Exception e) { Log.w(cgSettings.tag, "cgBase.getElevation: " + e.toString()); } - return elv; + return null; } /** diff --git a/src/cgeo/geocaching/cgCache.java b/src/cgeo/geocaching/cgCache.java index dfa5029..56505e6 100644 --- a/src/cgeo/geocaching/cgCache.java +++ b/src/cgeo/geocaching/cgCache.java @@ -20,6 +20,7 @@ import android.util.Log; import cgeo.geocaching.activity.IAbstractActivity; import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.connector.IConnector; +import cgeo.geocaching.geopoint.Geopoint; /** * Internal c:geo representation of a "cache" @@ -53,8 +54,7 @@ public class cgCache implements ICache { public String latitudeString = ""; public String longitudeString = ""; public String location = ""; - public Double latitude = null; - public Double longitude = null; + public Geopoint coords = null; public boolean reliableLatLon = false; public Double elevation = null; public String personalNote = null; @@ -183,11 +183,8 @@ public class cgCache implements ICache { if (StringUtils.isBlank(location)) { location = oldCache.location; } - if (latitude == null) { - latitude = oldCache.latitude; - } - if (longitude == null) { - longitude = oldCache.longitude; + if (coords == null) { + coords = oldCache.coords; } if (elevation == null) { elevation = oldCache.elevation; diff --git a/src/cgeo/geocaching/cgCacheListAdapter.java b/src/cgeo/geocaching/cgCacheListAdapter.java index 968f809..66ca5a3 100644 --- a/src/cgeo/geocaching/cgCacheListAdapter.java +++ b/src/cgeo/geocaching/cgCacheListAdapter.java @@ -35,6 +35,7 @@ import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; import cgeo.geocaching.filter.cgFilter; +import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.sorting.CacheComparator; import cgeo.geocaching.sorting.DistanceComparator; import cgeo.geocaching.sorting.VisitComparator; @@ -52,8 +53,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { private DistanceComparator dstComparator = null; private CacheComparator statComparator = null; private boolean historic = false; - private Double latitude = null; - private Double longitude = null; + private Geopoint coords = null; private Double azimuth = Double.valueOf(0); private long lastSort = 0L; private boolean sort = true; @@ -105,7 +105,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { public void setComparator(CacheComparator comparator) { statComparator = comparator; - forceSort(latitude, longitude); + forceSort(coords); } /** @@ -241,7 +241,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { notifyDataSetChanged(); } - public void forceSort(Double latitudeIn, Double longitudeIn) { + public void forceSort(final Geopoint coordsIn) { if (list == null || list.isEmpty()) { return; } @@ -253,11 +253,11 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { if (statComparator != null) { Collections.sort((List<cgCache>) list, statComparator); } else { - if (latitudeIn == null || longitudeIn == null) { + if (coordsIn == null) { return; } - dstComparator.setCoords(latitudeIn, longitudeIn); + dstComparator.setCoords(coordsIn); Collections.sort((List<cgCache>) list, dstComparator); } notifyDataSetChanged(); @@ -266,20 +266,19 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { } } - public void setActualCoordinates(Double latitudeIn, Double longitudeIn) { - if (latitudeIn == null || longitudeIn == null) { + public void setActualCoordinates(final Geopoint coordsIn) { + if (coordsIn == null) { return; } - latitude = latitudeIn; - longitude = longitudeIn; + coords = coordsIn; if (list != null && list.isEmpty() == false && (System.currentTimeMillis() - lastSort) > 1000 && sort) { try { if (statComparator != null) { Collections.sort((List<cgCache>) list, statComparator); } else { - dstComparator.setCoords(latitudeIn, longitudeIn); + dstComparator.setCoords(coordsIn); Collections.sort((List<cgCache>) list, dstComparator); } notifyDataSetChanged(); @@ -292,13 +291,13 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { if (CollectionUtils.isNotEmpty(distances)) { for (cgDistanceView distance : distances) { - distance.update(latitudeIn, longitudeIn); + distance.update(coordsIn); } } if (CollectionUtils.isNotEmpty(compasses)) { for (cgCompassMini compass : compasses) { - compass.updateCoords(latitudeIn, longitudeIn); + compass.updateCoords(coordsIn); } } } @@ -438,11 +437,11 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { if (distances.contains(holder.distance) == false) { distances.add(holder.distance); } - holder.distance.setContent(base, cache.latitude, cache.longitude); + holder.distance.setContent(base, cache.coords); if (compasses.contains(holder.direction) == false) { compasses.add(holder.direction); } - holder.direction.setContent(cache.latitude, cache.longitude); + holder.direction.setContent(cache.coords); if (cache.found && cache.logOffline) { holder.logStatusMark.setImageResource(R.drawable.mark_green_red); @@ -484,12 +483,12 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { } boolean setDiDi = false; - if (cache.latitude != null && cache.longitude != null) { + if (cache.coords != null) { holder.direction.setVisibility(View.VISIBLE); holder.direction.updateAzimuth(azimuth); - if (latitude != null && longitude != null) { - holder.distance.update(latitude, longitude); - holder.direction.updateCoords(latitude, longitude); + if (coords != null) { + holder.distance.update(coords); + holder.direction.updateCoords(coords); } setDiDi = true; } else { @@ -806,7 +805,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { } if (sort) { - forceSort(latitude, longitude); + forceSort(coords); } } diff --git a/src/cgeo/geocaching/cgCompassMini.java b/src/cgeo/geocaching/cgCompassMini.java index 17c26ce..2b9d0b6 100644 --- a/src/cgeo/geocaching/cgCompassMini.java +++ b/src/cgeo/geocaching/cgCompassMini.java @@ -9,12 +9,12 @@ import android.graphics.Paint; import android.graphics.PaintFlagsDrawFilter; import android.util.AttributeSet; import android.view.View; +import cgeo.geocaching.geopoint.Geopoint; public class cgCompassMini extends View { private int arrowSkin = R.drawable.compass_arrow_mini_white; private Context context = null; - private Double cacheLat = null; - private Double cacheLon = null; + private Geopoint cacheCoords = null; private Bitmap compassArrow = null; private Double azimuth = Double.valueOf(0); private Double heading = Double.valueOf(0); @@ -52,9 +52,8 @@ public class cgCompassMini extends View { } } - public void setContent(Double cacheLatIn, Double cacheLonIn) { - cacheLat = cacheLatIn; - cacheLon = cacheLonIn; + public void setContent(final Geopoint cacheCoordsIn) { + cacheCoords = cacheCoordsIn; } protected void updateAzimuth(Double azimuthIn) { @@ -69,12 +68,12 @@ public class cgCompassMini extends View { updateDirection(); } - protected void updateCoords(Double latitudeIn, Double longitudeIn) { - if (latitudeIn == null || longitudeIn == null || cacheLat == null || cacheLon == null) { + protected void updateCoords(final Geopoint coordsIn) { + if (coordsIn == null || cacheCoords == null) { return; } - heading = cgBase.getHeading(latitudeIn, longitudeIn, cacheLat, cacheLon); + heading = cgBase.getHeading(coordsIn, cacheCoords); updateDirection(); } diff --git a/src/cgeo/geocaching/cgCoord.java b/src/cgeo/geocaching/cgCoord.java index b699d27..d321001 100644 --- a/src/cgeo/geocaching/cgCoord.java +++ b/src/cgeo/geocaching/cgCoord.java @@ -1,5 +1,7 @@ package cgeo.geocaching;
+import cgeo.geocaching.geopoint.Geopoint;
+
public class cgCoord {
public Integer id = null;
@@ -9,8 +11,7 @@ public class cgCoord { public String name = "";
public boolean found = false;
public boolean disabled = false;
- public Double latitude = Double.valueOf(0);
- public Double longitude = Double.valueOf(0);
+ public Geopoint coords = new Geopoint(0, 0);
public Float difficulty = null;
public Float terrain = null;
public String size = null;
@@ -22,8 +23,7 @@ public class cgCoord { disabled = cache.disabled;
found = cache.found;
geocode = cache.geocode;
- latitude = cache.latitude;
- longitude = cache.longitude;
+ coords = cache.coords;
name = cache.name;
type = "cache";
typeSpec = cache.type;
@@ -37,8 +37,7 @@ public class cgCoord { disabled = false;
found = false;
geocode = "";
- latitude = waypoint.latitude;
- longitude = waypoint.longitude;
+ coords = waypoint.coords;
name = waypoint.name;
type = "waypoint";
typeSpec = waypoint.type;
diff --git a/src/cgeo/geocaching/cgData.java b/src/cgeo/geocaching/cgData.java index 5959c0c..9329ff2 100644 --- a/src/cgeo/geocaching/cgData.java +++ b/src/cgeo/geocaching/cgData.java @@ -30,6 +30,7 @@ import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteStatement; import android.os.Environment; import android.util.Log; +import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.utils.CollectionUtils; public class cgData { @@ -1197,12 +1198,12 @@ public class cgData { // save coordinates final boolean rel = isReliableLatLon(cache.geocode, cache.guid); if (cache.reliableLatLon) { // new cache has reliable coordinates, store - values.put("latitude", cache.latitude); - values.put("longitude", cache.longitude); + values.put("latitude", cache.coords.getLatitude()); + values.put("longitude", cache.coords.getLongitude()); values.put("reliable_latlon", 1); } else if (!rel) { // new cache neither stored cache is not reliable, just update - values.put("latitude", cache.latitude); - values.put("longitude", cache.longitude); + values.put("latitude", cache.coords.getLatitude()); + values.put("longitude", cache.coords.getLongitude()); values.put("reliable_latlon", 0); } values.put("elevation", cache.elevation); @@ -1347,8 +1348,8 @@ public class cgData { try { ContentValues values = new ContentValues(); values.put("date", destination.getDate()); - values.put("latitude", destination.getLatitude()); - values.put("longitude", destination.getLongitude()); + values.put("latitude", destination.getCoords().getLatitude()); + values.put("longitude", destination.getCoords().getLongitude()); long id = databaseRW.insert(dbTableSearchDestionationHistory, null, values); destination.setId(id); @@ -1396,8 +1397,8 @@ public class cgData { values.put("latlon", oneWaypoint.latlon); values.put("latitude_string", oneWaypoint.latitudeString); values.put("longitude_string", oneWaypoint.longitudeString); - values.put("latitude", oneWaypoint.latitude); - values.put("longitude", oneWaypoint.longitude); + values.put("latitude", oneWaypoint.coords.getLatitude()); + values.put("longitude", oneWaypoint.coords.getLongitude()); values.put("note", oneWaypoint.note); databaseRW.insert(dbTableWaypoints, null, values); @@ -1433,8 +1434,8 @@ public class cgData { values.put("latlon", waypoint.latlon); values.put("latitude_string", waypoint.latitudeString); values.put("longitude_string", waypoint.longitudeString); - values.put("latitude", waypoint.latitude); - values.put("longitude", waypoint.longitude); + values.put("latitude", waypoint.coords.getLatitude()); + values.put("longitude", waypoint.coords.getLongitude()); values.put("note", waypoint.note); if (id <= 0) { @@ -1885,18 +1886,15 @@ public class cgData { cache.latitudeString = (String) cursor.getString(cursor.getColumnIndex("latitude_string")); cache.longitudeString = (String) cursor.getString(cursor.getColumnIndex("longitude_string")); cache.location = (String) cursor.getString(cursor.getColumnIndex("location")); - index = cursor.getColumnIndex("latitude"); - if (cursor.isNull(index)) { - cache.latitude = null; - } else { - cache.latitude = (Double) cursor.getDouble(index); - } - index = cursor.getColumnIndex("longitude"); - if (cursor.isNull(index)) { - cache.longitude = null; + + final int indexLat = cursor.getColumnIndex("latitude"); + final int indexLon = cursor.getColumnIndex("longitude"); + if (cursor.isNull(indexLat) || cursor.isNull(indexLon)) { + cache.coords = null; } else { - cache.longitude = (Double) cursor.getDouble(index); + cache.coords = new Geopoint(cursor.getDouble(indexLat), cursor.getDouble(indexLon));; } + index = cursor.getColumnIndex("elevation"); if (cursor.isNull(index)) { cache.elevation = null; @@ -2117,17 +2115,12 @@ public class cgData { waypoint.latlon = (String) cursor.getString(cursor.getColumnIndex("latlon")); waypoint.latitudeString = (String) cursor.getString(cursor.getColumnIndex("latitude_string")); waypoint.longitudeString = (String) cursor.getString(cursor.getColumnIndex("longitude_string")); - int index = cursor.getColumnIndex("latitude"); - if (cursor.isNull(index)) { - waypoint.latitude = null; - } else { - waypoint.latitude = (Double) cursor.getDouble(index); - } - index = cursor.getColumnIndex("longitude"); - if (cursor.isNull(index)) { - waypoint.longitude = null; + final int indexLat = cursor.getColumnIndex("latitude"); + final int indexLon = cursor.getColumnIndex("longitude"); + if (cursor.isNull(indexLat) || cursor.isNull(indexLon)) { + waypoint.coords = null; } else { - waypoint.longitude = (Double) cursor.getDouble(index); + waypoint.coords = new Geopoint(cursor.getDouble(indexLat), cursor.getDouble(indexLon)); } waypoint.note = (String) cursor.getString(cursor.getColumnIndex("note")); @@ -2196,8 +2189,8 @@ public class cgData { dest.setId((long) cursor.getLong(cursor.getColumnIndex("_id"))); dest.setDate((long) cursor.getLong(cursor.getColumnIndex("date"))); - dest.setLatitude((double) cursor.getDouble(cursor.getColumnIndex("latitude"))); - dest.setLongitude((double) cursor.getDouble(cursor.getColumnIndex("longitude"))); + dest.setCoords(new Geopoint((double) cursor.getDouble(cursor.getColumnIndex("latitude")), + (double) cursor.getDouble(cursor.getColumnIndex("longitude")))); destinations.add(dest); } while (cursor.moveToNext()); diff --git a/src/cgeo/geocaching/cgDestination.java b/src/cgeo/geocaching/cgDestination.java index 0a2a493..1072a8b 100644 --- a/src/cgeo/geocaching/cgDestination.java +++ b/src/cgeo/geocaching/cgDestination.java @@ -1,24 +1,23 @@ package cgeo.geocaching; +import cgeo.geocaching.geopoint.Geopoint; + public class cgDestination { private long id; private long date; - private double latitude; - - private double longitude; + private Geopoint coords; public cgDestination() { } - public cgDestination(long id, long date, double latitude, double longitude) { + public cgDestination(long id, long date, final Geopoint coords) { super(); this.id = id; this.date = date; - this.latitude = latitude; - this.longitude = longitude; + this.coords = coords; } public long getDate() { @@ -29,20 +28,12 @@ public class cgDestination { this.date = date; } - public double getLatitude() { - return latitude; - } - - public void setLatitude(double latitude) { - this.latitude = latitude; + public Geopoint getCoords() { + return coords; } - public double getLongitude() { - return longitude; - } - - public void setLongitude(double longitude) { - this.longitude = longitude; + public void setCoords(final Geopoint coords) { + this.coords = coords; } @Override @@ -50,9 +41,9 @@ public class cgDestination { final int prime = 31; int result = 1; long temp; - temp = Double.doubleToLongBits(latitude); + temp = Double.doubleToLongBits(coords.getLatitude()); result = prime * result + (int) (temp ^ (temp >>> 32)); - temp = Double.doubleToLongBits(longitude); + temp = Double.doubleToLongBits(coords.getLongitude()); result = prime * result + (int) (temp ^ (temp >>> 32)); return result; } @@ -67,13 +58,7 @@ public class cgDestination { return false; } cgDestination other = (cgDestination) obj; - if (Double.doubleToLongBits(latitude) != Double - .doubleToLongBits(other.latitude)) - return false; - if (Double.doubleToLongBits(longitude) != Double - .doubleToLongBits(other.longitude)) - return false; - return true; + return coords.equals(other.coords); } public long getId() { diff --git a/src/cgeo/geocaching/cgDistanceView.java b/src/cgeo/geocaching/cgDistanceView.java index 9610e4f..ae9e7b7 100644 --- a/src/cgeo/geocaching/cgDistanceView.java +++ b/src/cgeo/geocaching/cgDistanceView.java @@ -3,11 +3,11 @@ package cgeo.geocaching; import android.content.Context; import android.util.AttributeSet; import android.widget.TextView; +import cgeo.geocaching.geopoint.Geopoint; public class cgDistanceView extends TextView { private cgBase base = null; - private Double cacheLat = null; - private Double cacheLon = null; + private Geopoint cacheCoords = null; public cgDistanceView(Context context) { super(context); @@ -21,18 +21,17 @@ public class cgDistanceView extends TextView { super(context, attrs, defStyle); } - public void setContent(cgBase baseIn, Double cacheLatIn, Double cacheLonIn) { + public void setContent(cgBase baseIn, final Geopoint cacheCoordsIn) { base = baseIn; - cacheLat = cacheLatIn; - cacheLon = cacheLonIn; + cacheCoords = cacheCoordsIn; } - public void update(Double latitude, Double longitude) { - if (cacheLat == null || cacheLon == null) return; - if (latitude == null || longitude == null) return; + public void update(final Geopoint coords) { + if (cacheCoords == null) return; + if (coords == null) return; if (base == null) return; - setText(base.getHumanDistance(cgBase.getDistance(latitude, longitude, cacheLat, cacheLon))); + setText(base.getHumanDistance(cgBase.getDistance(coords, cacheCoords))); } public void setDistance(Double distance) { diff --git a/src/cgeo/geocaching/cgGeo.java b/src/cgeo/geocaching/cgGeo.java index bcc0de1..c908580 100644 --- a/src/cgeo/geocaching/cgGeo.java +++ b/src/cgeo/geocaching/cgGeo.java @@ -16,6 +16,7 @@ import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.util.Log; +import cgeo.geocaching.geopoint.Geopoint; public class cgGeo { @@ -35,14 +36,11 @@ public class cgGeo { private Location locNet = null; private long locGpsLast = 0L; private boolean g4cRunning = false; - private Double lastGo4cacheLat = null; - private Double lastGo4cacheLon = null; + private Geopoint lastGo4cacheCoords = null; public Location location = null; public int gps = -1; - public Double latitudeNow = null; - public Double longitudeNow = null; - public Double latitudeBefore = null; - public Double longitudeBefore = null; + public Geopoint coordsNow = null; + public Geopoint coordsBefore = null; public Double altitudeNow = null; public Double bearingNow = null; public Float speedNow = null; @@ -87,8 +85,7 @@ public class cgGeo { public void initGeo() { location = null; gps = -1; - latitudeNow = null; - longitudeNow = null; + coordsNow = null; altitudeNow = null; bearingNow = null; speedNow = null; @@ -284,14 +281,13 @@ public class cgGeo { assign(locNet); // nothing else, using NET } - private void assign(Double lat, Double lon) { - if (lat == null || lon == null) { + private void assign(final Geopoint coords) { + if (coords == null) { return; } gps = -1; - latitudeNow = lat; - longitudeNow = lon; + coordsNow = coords; altitudeNow = null; bearingNow = Double.valueOf(0); speedNow = 0f; @@ -319,9 +315,8 @@ public class cgGeo { gps = -1; } - latitudeNow = location.getLatitude(); - longitudeNow = location.getLongitude(); - app.setLastLoc(latitudeNow, longitudeNow); + coordsNow = new Geopoint(location.getLatitude(), location.getLongitude()); + app.setLastLoc(coordsNow); if (location.hasAltitude() && gps != -1) { altitudeNow = location.getAltitude() + settings.altCorrection; @@ -346,18 +341,16 @@ public class cgGeo { if (gps == 1) { // save travelled distance only when location is from GPS - if (latitudeBefore != null && longitudeBefore != null && latitudeNow != null && longitudeNow != null) { - final double dst = cgBase.getDistance(latitudeBefore, longitudeBefore, latitudeNow, longitudeNow); + if (coordsBefore != null && coordsNow != null) { + final double dst = cgBase.getDistance(coordsBefore, coordsNow); if (Double.isNaN(dst) == false && dst > 0.005) { distanceNow += dst; - latitudeBefore = latitudeNow; - longitudeBefore = longitudeNow; + coordsBefore = coordsNow; } - } else if (latitudeBefore == null || longitudeBefore == null) { // values aren't initialized - latitudeBefore = latitudeNow; - longitudeBefore = longitudeNow; + } else if (coordsBefore == null) { // values aren't initialized + coordsBefore = coordsNow; } } @@ -382,7 +375,7 @@ public class cgGeo { return; } - if (settings.publicLoc == 1 && (lastGo4cacheLat == null || lastGo4cacheLon == null || cgBase.getDistance(latitudeNow, longitudeNow, lastGo4cacheLat, lastGo4cacheLon) > 0.75)) { + if (settings.publicLoc == 1 && (lastGo4cacheCoords == null || cgBase.getDistance(coordsNow, lastGo4cacheCoords) > 0.75)) { g4cRunning = true; final String host = "api.go4cache.com"; @@ -398,8 +391,8 @@ public class cgGeo { final String username = settings.getUsername(); if (username != null) { final Map<String, String> params = new HashMap<String, String>(); - final String latStr = String.format((Locale) null, "%.6f", latitudeNow); - final String lonStr = String.format((Locale) null, "%.6f", longitudeNow); + final String latStr = String.format((Locale) null, "%.6f", coordsNow.getLatitude()); + final String lonStr = String.format((Locale) null, "%.6f", coordsNow.getLongitude()); params.put("u", username); params.put("lt", latStr); params.put("ln", lonStr); @@ -411,8 +404,7 @@ public class cgGeo { final String res = base.request(false, host, path, method, params, false, false, false).getData(); if (StringUtils.isNotBlank(res)) { - lastGo4cacheLat = latitudeNow; - lastGo4cacheLon = longitudeNow; + lastGo4cacheCoords = coordsNow; } } } @@ -422,7 +414,7 @@ public class cgGeo { } public void lastLoc() { - assign(app.getLastLat(), app.getLastLon()); + assign(app.getLastCoords()); Location lastGps = geoManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); diff --git a/src/cgeo/geocaching/cgWaypoint.java b/src/cgeo/geocaching/cgWaypoint.java index 5876bbc..a11a2c5 100644 --- a/src/cgeo/geocaching/cgWaypoint.java +++ b/src/cgeo/geocaching/cgWaypoint.java @@ -7,6 +7,7 @@ import org.apache.commons.lang3.StringUtils; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.widget.TextView; +import cgeo.geocaching.geopoint.Geopoint; public class cgWaypoint { public Integer id = 0; @@ -18,8 +19,7 @@ public class cgWaypoint { public String latlon = ""; public String latitudeString = ""; public String longitudeString = ""; - public Double latitude = null; - public Double longitude = null; + public Geopoint coords = null; public String note = ""; public void setIcon(Resources res, cgBase base, TextView nameView) { @@ -52,11 +52,8 @@ public class cgWaypoint { if (StringUtils.isBlank(longitudeString)) { longitudeString = old.longitudeString; } - if (latitude == null) { - latitude = old.latitude; - } - if (longitude == null) { - longitude = old.longitude; + if (coords == null) { + coords = old.coords; } if (StringUtils.isBlank(note)) { note = old.note; diff --git a/src/cgeo/geocaching/cgeo.java b/src/cgeo/geocaching/cgeo.java index ceaf3b9..5fe411d 100644 --- a/src/cgeo/geocaching/cgeo.java +++ b/src/cgeo/geocaching/cgeo.java @@ -31,6 +31,7 @@ import android.widget.RelativeLayout; import android.widget.TextView; import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.activity.ActivityMixin; +import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.utils.CollectionUtils; public class cgeo extends AbstractActivity { @@ -56,8 +57,7 @@ public class cgeo extends AbstractActivity { private TextView countBubble = null; private boolean cleanupRunning = false; private int countBubbleCnt = 0; - private Double addLat = null; - private Double addLon = null; + private Geopoint addCoords = null; private List<Address> addresses = null; private boolean addressObtaining = false; private boolean initialized = false; @@ -106,8 +106,7 @@ public class cgeo extends AbstractActivity { addText.append(address.getAdminArea()); } - addLat = geo.latitudeNow; - addLon = geo.longitudeNow; + addCoords = geo.coordsNow; if (navLocation == null) { navLocation = (TextView) findViewById(R.id.nav_location); @@ -498,7 +497,7 @@ public class cgeo extends AbstractActivity { navLocation = (TextView) findViewById(R.id.nav_location); } - if (geo.latitudeNow != null && geo.longitudeNow != null) { + if (geo.coordsNow != null) { View findNearest = findViewById(R.id.nearest); findNearest.setClickable(true); findNearest.setOnClickListener(new cgeoFindNearestListener()); @@ -533,10 +532,10 @@ public class cgeo extends AbstractActivity { } if (settings.showAddress == 1) { - if (addLat == null || addLon == null) { + if (addCoords == null) { navLocation.setText(res.getString(R.string.loc_no_addr)); } - if (addLat == null || addLon == null || (cgBase.getDistance(geo.latitudeNow, geo.longitudeNow, addLat, addLon) > 0.5 && addressObtaining == false)) { + if (addCoords == null || (cgBase.getDistance(geo.coordsNow, addCoords) > 0.5 && addressObtaining == false)) { (new obtainAddress()).start(); } } else { @@ -547,9 +546,9 @@ public class cgeo extends AbstractActivity { } else { humanAlt = String.format("%.0f", geo.altitudeNow) + " m"; } - navLocation.setText(cgBase.formatCoords(geo.latitudeNow, geo.longitudeNow, true) + " | " + humanAlt); + navLocation.setText(cgBase.formatCoords(geo.coordsNow, true) + " | " + humanAlt); } else { - navLocation.setText(cgBase.formatCoords(geo.latitudeNow, geo.longitudeNow, true)); + navLocation.setText(cgBase.formatCoords(geo.coordsNow, true)); } } } else { @@ -578,8 +577,8 @@ public class cgeo extends AbstractActivity { final Intent cachesIntent = new Intent(context, cgeocaches.class); cachesIntent.putExtra("type", "nearest"); - cachesIntent.putExtra("latitude", geo.latitudeNow); - cachesIntent.putExtra("longitude", geo.longitudeNow); + cachesIntent.putExtra("latitude", geo.coordsNow.getLatitude()); + cachesIntent.putExtra("longitude", geo.coordsNow.getLongitude()); cachesIntent.putExtra("cachetype", settings.cacheType); context.startActivity(cachesIntent); } @@ -693,7 +692,7 @@ public class cgeo extends AbstractActivity { try { Geocoder geocoder = new Geocoder(context, Locale.getDefault()); - addresses = geocoder.getFromLocation(geo.latitudeNow, geo.longitudeNow, 1); + addresses = geocoder.getFromLocation(geo.coordsNow.getLatitude(), geo.coordsNow.getLongitude(), 1); } catch (Exception e) { Log.i(cgSettings.tag, "Failed to obtain address"); } diff --git a/src/cgeo/geocaching/cgeoadvsearch.java b/src/cgeo/geocaching/cgeoadvsearch.java index 56fbfb7..719bc94 100644 --- a/src/cgeo/geocaching/cgeoadvsearch.java +++ b/src/cgeo/geocaching/cgeoadvsearch.java @@ -211,9 +211,9 @@ public class cgeoadvsearch extends AbstractActivity { lonEdit = (EditText) findViewById(R.id.longitude); } - if (geo.latitudeNow != null && geo.longitudeNow != null) { - latEdit.setHint(cgBase.formatLatitude(geo.latitudeNow, false)); - lonEdit.setHint(cgBase.formatLongitude(geo.longitudeNow, false)); + if (geo.coordsNow != null) { + latEdit.setHint(cgBase.formatLatitude(geo.coordsNow.getLatitude(), false)); + lonEdit.setHint(cgBase.formatLongitude(geo.coordsNow.getLongitude(), false)); } } catch (Exception e) { Log.w(cgSettings.tag, "Failed to update location."); @@ -248,8 +248,8 @@ public class cgeoadvsearch extends AbstractActivity { final String lonText = lonView.getText().toString(); if (StringUtils.isEmpty(latText) || StringUtils.isEmpty(lonText)) { - latView.setText(cgBase.formatLatitude(geo.latitudeNow, true)); - lonView.setText(cgBase.formatLongitude(geo.longitudeNow, true)); + latView.setText(cgBase.formatLatitude(geo.coordsNow.getLatitude(), true)); + lonView.setText(cgBase.formatLongitude(geo.coordsNow.getLongitude(), true)); } else { Map<String, Object> latParsed = cgBase.parseCoordinate(latText, "lat"); Map<String, Object> lonParsed = cgBase.parseCoordinate(lonText, "lat"); diff --git a/src/cgeo/geocaching/cgeoapplication.java b/src/cgeo/geocaching/cgeoapplication.java index f580fa9..ffd94ff 100644 --- a/src/cgeo/geocaching/cgeoapplication.java +++ b/src/cgeo/geocaching/cgeoapplication.java @@ -14,14 +14,14 @@ import org.apache.commons.lang3.StringUtils; import android.app.Application; import android.content.Context; import android.util.Log; +import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.utils.CollectionUtils; public class cgeoapplication extends Application { private cgData storage = null; private String action = null; - private Double lastLatitude = null; - private Double lastLongitude = null; + private Geopoint lastCoords = null; private cgGeo geo = null; private boolean geoInUse = false; private cgDirection dir = null; @@ -789,17 +789,12 @@ public class cgeoapplication extends Application { return storage.saveLogs(geocode, list, false); } - public void setLastLoc(Double lat, Double lon) { - lastLatitude = lat; - lastLongitude = lon; + public void setLastLoc(final Geopoint coords) { + lastCoords = coords; } - public Double getLastLat() { - return lastLatitude; - } - - public Double getLastLon() { - return lastLongitude; + public Geopoint getLastCoords() { + return lastCoords; } public boolean saveLogOffline(String geocode, Date date, int logtype, String log) { diff --git a/src/cgeo/geocaching/cgeocaches.java b/src/cgeo/geocaching/cgeocaches.java index d8380bf..cf26023 100644 --- a/src/cgeo/geocaching/cgeocaches.java +++ b/src/cgeo/geocaching/cgeocaches.java @@ -53,6 +53,7 @@ import cgeo.geocaching.filter.cgFilter; import cgeo.geocaching.filter.cgFilterBySize; import cgeo.geocaching.filter.cgFilterByTrackables; import cgeo.geocaching.filter.cgFilterByType; +import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.sorting.CacheComparator; import cgeo.geocaching.sorting.DateComparator; import cgeo.geocaching.sorting.DifficultyComparator; @@ -139,8 +140,7 @@ public class cgeocaches extends AbstractListActivity { private String action = null; private String type = null; - private Double latitude = null; - private Double longitude = null; + private Geopoint coords = null; private String cachetype = null; private String keyword = null; private String address = null; @@ -241,8 +241,8 @@ public class cgeocaches extends AbstractListActivity { return; } - if (geo != null && geo.latitudeNow != null && geo.longitudeNow != null) { - adapter.setActualCoordinates(geo.latitudeNow, geo.longitudeNow); + if (geo != null && geo.coordsNow != null) { + adapter.setActualCoordinates(geo.coordsNow); adapter.setActualHeading(northHeading); } } catch (Exception e) { @@ -319,8 +319,8 @@ public class cgeocaches extends AbstractListActivity { return; } - if (geo != null && geo.latitudeNow != null && geo.longitudeNow != null) { - adapter.setActualCoordinates(geo.latitudeNow, geo.longitudeNow); + if (geo != null && geo.coordsNow != null) { + adapter.setActualCoordinates(geo.coordsNow); adapter.setActualHeading(northHeading); } } catch (Exception e) { @@ -375,8 +375,8 @@ public class cgeocaches extends AbstractListActivity { } } - if (geo != null && geo.latitudeNow != null && geo.longitudeNow != null) { - adapter.setActualCoordinates(geo.latitudeNow, geo.longitudeNow); + if (geo != null && geo.coordsNow != null) { + adapter.setActualCoordinates(geo.coordsNow); adapter.setActualHeading(northHeading); } @@ -551,8 +551,7 @@ public class cgeocaches extends AbstractListActivity { Bundle extras = getIntent().getExtras(); if (extras != null) { type = extras.getString(EXTRAS_LIST_TYPE); - latitude = extras.getDouble("latitude"); - longitude = extras.getDouble("longitude"); + coords = new Geopoint(extras.getDouble("latitude"), extras.getDouble("longitude")); cachetype = extras.getString("cachetype"); keyword = extras.getString("keyword"); address = extras.getString("address"); @@ -578,7 +577,7 @@ public class cgeocaches extends AbstractListActivity { showProgress(true); setLoadingCaches(); - threadPure = new geocachesLoadByOffline(loadCachesHandler, latitude, longitude, listId); + threadPure = new geocachesLoadByOffline(loadCachesHandler, coords, listId); threadPure.start(); } else if (type.equals("history")) { if (adapter != null) { @@ -599,17 +598,17 @@ public class cgeocaches extends AbstractListActivity { showProgress(true); setLoadingCaches(); - thread = new geocachesLoadByCoords(loadCachesHandler, latitude, longitude, cachetype); + thread = new geocachesLoadByCoords(loadCachesHandler, coords, cachetype); thread.setRecaptchaHandler(new cgSearchHandler(this, res, thread)); thread.start(); } else if (type.equals("coordinate")) { action = "planning"; - title = cgBase.formatCoords(latitude, longitude, true); + title = cgBase.formatCoords(coords, true); setTitle(title); showProgress(true); setLoadingCaches(); - thread = new geocachesLoadByCoords(loadCachesHandler, latitude, longitude, cachetype); + thread = new geocachesLoadByCoords(loadCachesHandler, coords, cachetype); thread.setRecaptchaHandler(new cgSearchHandler(this, res, thread)); thread.start(); } else if (type.equals("keyword")) { @@ -629,13 +628,13 @@ public class cgeocaches extends AbstractListActivity { showProgress(true); setLoadingCaches(); } else { - title = cgBase.formatCoords(latitude, longitude, true); + title = cgBase.formatCoords(coords, true); setTitle(title); showProgress(true); setLoadingCaches(); } - thread = new geocachesLoadByCoords(loadCachesHandler, latitude, longitude, cachetype); + thread = new geocachesLoadByCoords(loadCachesHandler, coords, cachetype); thread.setRecaptchaHandler(new cgSearchHandler(this, res, thread)); thread.start(); } else if (type.equals("username")) { @@ -677,15 +676,15 @@ public class cgeocaches extends AbstractListActivity { settings.load(); init(); - if (adapter != null && geo != null && geo.latitudeNow != null && geo.longitudeNow != null) { - adapter.setActualCoordinates(geo.latitudeNow, geo.longitudeNow); + if (adapter != null && geo != null && geo.coordsNow != null) { + adapter.setActualCoordinates(geo.coordsNow); adapter.setActualHeading(northHeading); } if (adapter != null) { adapter.setSelectMode(false, true); - if (geo != null && geo.latitudeNow != null && geo.longitudeNow != null) { - adapter.forceSort(geo.latitudeNow, geo.longitudeNow); + if (geo != null && geo.coordsNow != null) { + adapter.forceSort(geo.coordsNow); } } @@ -1100,7 +1099,7 @@ public class cgeocaches extends AbstractListActivity { menu.setHeaderTitle(cache.geocode); } - if (cache.latitude != null && cache.longitude != null) { + if (cache.coords != null) { menu.add(0, MENU_COMPASS, 0, res.getString(R.string.cache_menu_compass)); SubMenu subMenu = menu.addSubMenu(1, 0, 0, res.getString(R.string.cache_menu_navigate)).setIcon(android.R.drawable.ic_menu_more); NavigationAppFactory.addMenuItems(subMenu, this, res); @@ -1165,8 +1164,8 @@ public class cgeocaches extends AbstractListActivity { if (id == MENU_COMPASS) { Intent navigateIntent = new Intent(this, cgeonavigate.class); - navigateIntent.putExtra("latitude", cache.latitude); - navigateIntent.putExtra("longitude", cache.longitude); + navigateIntent.putExtra("latitude", cache.coords.getLatitude()); + navigateIntent.putExtra("longitude", cache.coords.getLongitude()); navigateIntent.putExtra("geocode", cache.geocode.toUpperCase()); navigateIntent.putExtra("name", cache.name); @@ -1341,7 +1340,7 @@ public class cgeocaches extends AbstractListActivity { adapter.reFilter(); if (adapter != null && geo != null) { - adapter.setActualCoordinates(geo.latitudeNow, geo.longitudeNow); + adapter.setActualCoordinates(geo.coordsNow); } if (adapter != null && dir != null) { adapter.setActualHeading(dir.directionNow); @@ -1701,8 +1700,8 @@ public class cgeocaches extends AbstractListActivity { } try { - if (cacheList != null && geo.latitudeNow != null && geo.longitudeNow != null) { - adapter.setActualCoordinates(geo.latitudeNow, geo.longitudeNow); + if (cacheList != null && geo.coordsNow != null) { + adapter.setActualCoordinates(geo.coordsNow); } if (settings.useCompass == 0 || (geo.speedNow != null && geo.speedNow > 5)) { // use GPS when speed is higher than 18 km/h @@ -1744,23 +1743,21 @@ public class cgeocaches extends AbstractListActivity { private class geocachesLoadByOffline extends Thread { private Handler handler = null; - private Double latitude = null; - private Double longitude = null; + private Geopoint coords = null; private int listId = 1; - public geocachesLoadByOffline(Handler handlerIn, Double latitudeIn, Double longitudeIn, int listIdIn) { + public geocachesLoadByOffline(Handler handlerIn, final Geopoint coordsIn, int listIdIn) { handler = handlerIn; - latitude = latitudeIn; - longitude = longitudeIn; + coords = coordsIn; listId = listIdIn; } @Override public void run() { Map<String, Object> params = new HashMap<String, Object>(); - if (latitude != null && longitude != null) { - params.put("latitude", latitude); - params.put("longitude", longitude); + if (coords != null) { + params.put("latitude", coords.getLatitude()); + params.put("longitude", coords.getLongitude()); params.put("cachetype", settings.cacheType); params.put("list", listId); } @@ -1782,7 +1779,7 @@ public class cgeocaches extends AbstractListActivity { @Override public void run() { Map<String, Object> params = new HashMap<String, Object>(); - if (latitude != null && longitude != null) { + if (coords != null) { params.put("cachetype", settings.cacheType); } @@ -1811,19 +1808,17 @@ public class cgeocaches extends AbstractListActivity { private class geocachesLoadByCoords extends cgSearchThread { private Handler handler = null; - private Double latitude = null; - private Double longitude = null; + private Geopoint coords = null; private String cachetype = null; - public geocachesLoadByCoords(Handler handlerIn, Double latitudeIn, Double longitudeIn, String cachetypeIn) { + public geocachesLoadByCoords(Handler handlerIn, final Geopoint coordsIn, String cachetypeIn) { setPriority(Thread.MIN_PRIORITY); handler = handlerIn; - latitude = latitudeIn; - longitude = longitudeIn; + coords = coordsIn; cachetype = cachetypeIn; - if (latitude == null || longitude == null) { + if (coords == null) { showToast(res.getString(R.string.warn_no_coordinates)); finish(); @@ -1834,8 +1829,8 @@ public class cgeocaches extends AbstractListActivity { @Override public void run() { Map<String, String> params = new HashMap<String, String>(); - params.put("latitude", String.format((Locale) null, "%.6f", latitude)); - params.put("longitude", String.format((Locale) null, "%.6f", longitude)); + params.put("latitude", String.format((Locale) null, "%.6f", coords.getLatitude())); + params.put("longitude", String.format((Locale) null, "%.6f", coords.getLongitude())); params.put("cachetype", cachetype); searchId = base.searchByCoords(this, params, 0, settings.showCaptcha); @@ -2423,7 +2418,7 @@ public class cgeocaches extends AbstractListActivity { private class MoveHandler extends Handler { @Override public void handleMessage(Message msg) { - Thread threadPure = new geocachesLoadByOffline(loadCachesHandler, latitude, longitude, msg.what); + Thread threadPure = new geocachesLoadByOffline(loadCachesHandler, coords, msg.what); threadPure.start(); } } @@ -2560,13 +2555,13 @@ public class cgeocaches extends AbstractListActivity { context.startActivity(cachesIntent); } - public static void startActivityCachesAround(final AbstractActivity context, final Double latitude, final Double longitude) { + public static void startActivityCachesAround(final AbstractActivity context, final Geopoint coords) { cgeocaches cachesActivity = new cgeocaches(); Intent cachesIntent = new Intent(context, cachesActivity.getClass()); cachesIntent.putExtra("type", "coordinate"); - cachesIntent.putExtra("latitude", latitude); - cachesIntent.putExtra("longitude", longitude); + cachesIntent.putExtra("latitude", coords.getLatitude()); + cachesIntent.putExtra("longitude", coords.getLongitude()); cachesIntent.putExtra("cachetype", context.getSettings().cacheType); context.startActivity(cachesIntent); diff --git a/src/cgeo/geocaching/cgeocoords.java b/src/cgeo/geocaching/cgeocoords.java index 1ee078f..afdff1c 100644 --- a/src/cgeo/geocaching/cgeocoords.java +++ b/src/cgeo/geocaching/cgeocoords.java @@ -1,7 +1,5 @@ package cgeo.geocaching; -import java.util.ArrayList; -import java.util.List; import java.util.Map; import org.apache.commons.lang3.StringUtils; @@ -22,13 +20,14 @@ import android.widget.Spinner; import android.widget.TextView; import cgeo.geocaching.cgSettings.coordInputFormatEnum; import cgeo.geocaching.activity.AbstractActivity; +import cgeo.geocaching.geopoint.Geopoint; public class cgeocoords extends Dialog { private AbstractActivity context = null; private cgSettings settings = null; private cgGeo geo = null; - private Double latitude = 0.0, longitude = 0.0; + private Geopoint coords = new Geopoint(0, 0); private EditText eLat, eLon; private Button bLat, bLon; @@ -48,11 +47,9 @@ public class cgeocoords extends Dialog { geo = geoIn; if (waypoint != null) { - latitude = waypoint.latitude; - longitude = waypoint.longitude; - } else if (geo != null && geo.latitudeNow != null && geo.longitudeNow != null) { - latitude = geo.latitudeNow; - longitude = geo.longitudeNow; + coords = waypoint.coords; + } else if (geo != null && geo.coordsNow != null) { + coords = geo.coordsNow; } } @@ -120,8 +117,12 @@ public class cgeocoords extends Dialog { } private void updateGUI() { - Double lat = 0.0; - if (latitude != null) { + double latitude = 0.0; + double longitude = 0.0; + double lat = 0.0; + double lon = 0.0; + if (coords != null) { + latitude = coords.getLatitude(); if (latitude < 0) { bLat.setText("S"); } else { @@ -129,9 +130,8 @@ public class cgeocoords extends Dialog { } lat = Math.abs(latitude); - } - Double lon = 0.0; - if (longitude != null) { + + longitude = coords.getLongitude(); if (longitude < 0) { bLon.setText("W"); } else { @@ -140,6 +140,7 @@ public class cgeocoords extends Dialog { lon = Math.abs(longitude); } + int latDeg = (int) Math.floor(lat); int latDegFrac = (int) Math.round((lat - latDeg) * 100000); @@ -163,10 +164,8 @@ public class cgeocoords extends Dialog { findViewById(R.id.coordTable).setVisibility(View.GONE); eLat.setVisibility(View.VISIBLE); eLon.setVisibility(View.VISIBLE); - if (latitude != null) { + if (coords != null) { eLat.setText(cgBase.formatLatitude(latitude, true)); - } - if (longitude != null) { eLon.setText(cgBase.formatLongitude(longitude, true)); } break; @@ -186,11 +185,9 @@ public class cgeocoords extends Dialog { tLatSep2.setText("°"); tLonSep2.setText("°"); - if (latitude != null) { + if (coords != null) { eLatDeg.setText(addZeros(latDeg, 2) + Integer.toString(latDeg)); eLatMin.setText(addZeros(latDegFrac, 5) + Integer.toString(latDegFrac)); - } - if (longitude != null) { eLonDeg.setText(addZeros(latDeg, 3) + Integer.toString(lonDeg)); eLonMin.setText(addZeros(lonDegFrac, 5) + Integer.toString(lonDegFrac)); } @@ -213,12 +210,10 @@ public class cgeocoords extends Dialog { tLatSep3.setText("'"); tLonSep3.setText("'"); - if (latitude != null) { + if (coords != null) { eLatDeg.setText(addZeros(latDeg, 2) + Integer.toString(latDeg)); eLatMin.setText(addZeros(latMin, 2) + Integer.toString(latMin)); eLatSec.setText(addZeros(latMinFrac, 3) + Integer.toString(latMinFrac)); - } - if (longitude != null) { eLonDeg.setText(addZeros(lonDeg, 3) + Integer.toString(lonDeg)); eLonMin.setText(addZeros(lonMin, 2) + Integer.toString(lonMin)); eLonSec.setText(addZeros(lonMinFrac, 3) + Integer.toString(lonMinFrac)); @@ -242,13 +237,11 @@ public class cgeocoords extends Dialog { tLatSep3.setText("."); tLonSep3.setText("."); - if (latitude != null) { + if (coords != null) { eLatDeg.setText(addZeros(latDeg, 2) + Integer.toString(latDeg)); eLatMin.setText(addZeros(latMin, 2) + Integer.toString(latMin)); eLatSec.setText(addZeros(latSec, 2) + Integer.toString(latSec)); eLatSub.setText(addZeros(latSecFrac, 3) + Integer.toString(latSecFrac)); - } - if (longitude != null) { eLonDeg.setText(addZeros(lonDeg, 3) + Integer.toString(lonDeg)); eLonMin.setText(addZeros(lonMin, 2) + Integer.toString(lonMin)); eLonSec.setText(addZeros(lonSec, 2) + Integer.toString(lonSec)); @@ -414,6 +407,8 @@ public class cgeocoords extends Dialog { } catch (NumberFormatException e) {} + double latitude = 0.0; + double longitude = 0.0; switch (currentFormat) { case Deg: latitude = latDeg + latDegFrac; @@ -430,6 +425,8 @@ public class cgeocoords extends Dialog { } latitude *= (bLat.getText().toString().equalsIgnoreCase("S") ? -1 : 1); longitude *= (bLon.getText().toString().equalsIgnoreCase("W") ? -1 : 1); + + coords = new Geopoint(latitude, longitude); } private class CoordinateFormatListener implements OnItemSelectedListener { @@ -450,13 +447,12 @@ public class cgeocoords extends Dialog { @Override public void onClick(View v) { - if (geo == null || geo.latitudeNow == null || geo.longitudeNow == null) { + if (geo == null || geo.coordsNow == null) { context.showToast(context.getResources().getString(R.string.err_point_unknown_position)); return; } - latitude = geo.latitudeNow; - longitude = geo.longitudeNow; + coords = geo.coordsNow; updateGUI(); } } @@ -481,22 +477,17 @@ public class cgeocoords extends Dialog { return; } - latitude = (Double) latParsed.get("coordinate"); - longitude = (Double) lonParsed.get("coordinate"); + coords = new Geopoint((Double) latParsed.get("coordinate"), (Double) lonParsed.get("coordinate")); } else { - if (geo == null || geo.latitudeNow == null || geo.longitudeNow == null) { + if (geo == null || geo.coordsNow == null) { context.showToast(context.getResources().getString(R.string.err_point_curr_position_unavailable)); return; } - latitude = geo.latitudeNow; - longitude = geo.longitudeNow; + coords = geo.coordsNow; } } - List<Double> co = new ArrayList<Double>(); - co.add(latitude); - co.add(longitude); - cuListener.update(co); + cuListener.update(coords); dismiss(); } } @@ -506,7 +497,7 @@ public class cgeocoords extends Dialog { } public interface CoordinateUpdate { - public void update(List<Double> coords); + public void update(final Geopoint coords); } } diff --git a/src/cgeo/geocaching/cgeodetail.java b/src/cgeo/geocaching/cgeodetail.java index 182778d..9cbecb9 100644 --- a/src/cgeo/geocaching/cgeodetail.java +++ b/src/cgeo/geocaching/cgeodetail.java @@ -493,7 +493,7 @@ public class cgeodetail extends AbstractActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { - if (cache != null && cache.latitude != null && cache.longitude != null) { + if (cache != null && cache.coords != null) { menu.add(0, 2, 0, res.getString(R.string.cache_menu_compass)).setIcon(android.R.drawable.ic_menu_compass); // compass SubMenu subMenu = menu.addSubMenu(1, 0, 0, res.getString(R.string.cache_menu_navigate)).setIcon(android.R.drawable.ic_menu_more); addNavigationMenuItems(subMenu); @@ -508,7 +508,7 @@ public class cgeodetail extends AbstractActivity { menu.add(1, 5, 0, res.getString(R.string.cache_menu_spoilers)).setIcon(android.R.drawable.ic_menu_gallery); // spoiler images } - if (cache != null && cache.latitude != null && cache.longitude != null) { + if (cache != null && cache.coords != null) { menu.add(0, 10, 0, res.getString(R.string.cache_menu_around)).setIcon(android.R.drawable.ic_menu_rotate); // caches around } @@ -812,7 +812,7 @@ public class cgeodetail extends AbstractActivity { } // cache coordinates - if (cache.latitude != null && cache.longitude != null) { + if (cache.coords != null) { itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null); itemName = (TextView) itemLayout.findViewById(R.id.name); itemValue = (TextView) itemLayout.findViewById(R.id.value); @@ -1039,7 +1039,7 @@ public class cgeodetail extends AbstractActivity { TextView nameView = (TextView) waypointView.findViewById(R.id.name); if (StringUtils.isBlank(wpt.name)) { - nameView.setText(cgBase.formatCoords(wpt.latitude, wpt.longitude, true)); + nameView.setText(cgBase.formatCoords(wpt.coords, true)); } else { // avoid HTML parsing if (wpt.name.indexOf('<') >= 0 || wpt.name.indexOf('&') >= 0) { @@ -1083,8 +1083,8 @@ public class cgeodetail extends AbstractActivity { hintView.setOnClickListener(null); } - if (geo != null && geo.latitudeNow != null && geo.longitudeNow != null && cache != null && cache.latitude != null && cache.longitude != null) { - cacheDistance.setText(base.getHumanDistance(cgBase.getDistance(geo.latitudeNow, geo.longitudeNow, cache.latitude, cache.longitude))); + if (geo != null && geo.coordsNow != null && cache != null && cache.coords != null) { + cacheDistance.setText(base.getHumanDistance(cgBase.getDistance(geo.coordsNow, cache.coords))); cacheDistance.bringToFront(); } } catch (Exception e) { @@ -1330,14 +1330,15 @@ public class cgeodetail extends AbstractActivity { @Override public void run() { - if (cache == null || cache.latitude == null || cache.longitude == null) { + if (cache == null || cache.coords == null) { return; } BitmapDrawable image = null; try { - final String latlonMap = String.format((Locale) null, "%.6f", cache.latitude) + "," + String.format((Locale) null, "%.6f", cache.longitude); + final String latlonMap = String.format((Locale) null, "%.6f", cache.coords.getLatitude()) + "," + + String.format((Locale) null, "%.6f", cache.coords.getLongitude()); final Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int width = display.getWidth(); @@ -1395,8 +1396,7 @@ public class cgeodetail extends AbstractActivity { } else { coords.name = geocode.toUpperCase(); } - coords.latitude = cache.latitude; - coords.longitude = cache.longitude; + coords.coords = cache.coords; coordinates.add(coords); } catch (Exception e) { Log.e(cgSettings.tag, "cgeodetail.getCoordinates (cache): " + e.toString()); @@ -1405,15 +1405,14 @@ public class cgeodetail extends AbstractActivity { try { // waypoints for (cgWaypoint waypoint : cache.waypoints) { - if (waypoint.latitude == null || waypoint.longitude == null) { + if (waypoint.coords == null) { continue; } coords = new cgCoord(); coords.type = "waypoint"; coords.name = waypoint.name; - coords.latitude = waypoint.latitude; - coords.longitude = waypoint.longitude; + coords.coords = waypoint.coords; coordinates.add(coords); } } catch (Exception e) { @@ -1424,7 +1423,7 @@ public class cgeodetail extends AbstractActivity { } private void cachesAround() { - cgeocaches.startActivityCachesAround(this, cache.latitude, cache.longitude); + cgeocaches.startActivityCachesAround(this, cache.coords); finish(); } @@ -1544,15 +1543,15 @@ public class cgeodetail extends AbstractActivity { } private void navigateTo() { - if (cache == null || cache.latitude == null || cache.longitude == null) { + if (cache == null || cache.coords == null) { showToast(res.getString(R.string.err_location_unknown)); } cgeonavigate navigateActivity = new cgeonavigate(); Intent navigateIntent = new Intent(this, navigateActivity.getClass()); - navigateIntent.putExtra("latitude", cache.latitude); - navigateIntent.putExtra("longitude", cache.longitude); + navigateIntent.putExtra("latitude", cache.coords.getLatitude()); + navigateIntent.putExtra("longitude", cache.coords.getLongitude()); navigateIntent.putExtra("geocode", cache.geocode.toUpperCase()); navigateIntent.putExtra("name", cache.name); @@ -1638,8 +1637,8 @@ public class cgeodetail extends AbstractActivity { try { StringBuilder dist = new StringBuilder(); - if (geo.latitudeNow != null && geo.longitudeNow != null && cache != null && cache.latitude != null && cache.longitude != null) { - dist.append(base.getHumanDistance(cgBase.getDistance(geo.latitudeNow, geo.longitudeNow, cache.latitude, cache.longitude))); + if (geo.coordsNow != null && cache != null && cache.coords != null) { + dist.append(base.getHumanDistance(cgBase.getDistance(geo.coordsNow, cache.coords))); } if (cache != null && cache.elevation != null) { @@ -1939,15 +1938,15 @@ public class cgeodetail extends AbstractActivity { } public void goCompass(View view) { - if (cache == null || cache.latitude == null || cache.longitude == null) { + if (cache == null || cache.coords == null) { showToast(res.getString(R.string.cache_coordinates_no)); return; } Intent navigateIntent = new Intent(this, cgeonavigate.class); - navigateIntent.putExtra("latitude", cache.latitude); - navigateIntent.putExtra("longitude", cache.longitude); + navigateIntent.putExtra("latitude", cache.coords.getLatitude()); + navigateIntent.putExtra("longitude", cache.coords.getLongitude()); navigateIntent.putExtra("geocode", cache.geocode.toUpperCase()); navigateIntent.putExtra("name", cache.name); diff --git a/src/cgeo/geocaching/cgeonavigate.java b/src/cgeo/geocaching/cgeonavigate.java index 6beaef7..f8b17e6 100644 --- a/src/cgeo/geocaching/cgeonavigate.java +++ b/src/cgeo/geocaching/cgeonavigate.java @@ -1,10 +1,8 @@ package cgeo.geocaching; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Locale; -import java.util.Map; import org.apache.commons.lang3.StringUtils; @@ -22,6 +20,7 @@ import android.view.SubMenu; import android.view.WindowManager; import android.widget.TextView; import cgeo.geocaching.activity.AbstractActivity; +import cgeo.geocaching.geopoint.Geopoint; public class cgeonavigate extends AbstractActivity { @@ -32,8 +31,7 @@ public class cgeonavigate extends AbstractActivity { private cgDirection dir = null; private cgUpdateLoc geoUpdate = new update(); private cgUpdateDir dirUpdate = new UpdateDirection(); - private Double dstLatitude = null; - private Double dstLongitude = null; + private Geopoint dstCoords = null; private Double cacheHeading = Double.valueOf(0); private Double northHeading = Double.valueOf(0); private String title = null; @@ -87,8 +85,7 @@ public class cgeonavigate extends AbstractActivity { if (extras != null) { title = extras.getString("geocode"); name = extras.getString("name"); - dstLatitude = extras.getDouble("latitude"); - dstLongitude = extras.getDouble("longitude"); + dstCoords = new Geopoint(extras.getDouble("latitude"), extras.getDouble("longitude")); if (StringUtils.isNotBlank(name)) { if (StringUtils.isNotBlank(title)) { @@ -249,8 +246,8 @@ public class cgeonavigate extends AbstractActivity { if (id == 0) { Intent mapIntent = new Intent(this, settings.getMapFactory().getMapClass()); mapIntent.putExtra("detail", false); - mapIntent.putExtra("latitude", dstLatitude); - mapIntent.putExtra("longitude", dstLongitude); + mapIntent.putExtra("latitude", dstCoords.getLatitude()); + mapIntent.putExtra("longitude", dstCoords.getLongitude()); startActivity(mapIntent); } else if (id == 1) { @@ -285,13 +282,14 @@ public class cgeonavigate extends AbstractActivity { cgCoord coordinate = coordinates.get(id - 4); title = coordinate.name; - dstLatitude = coordinate.latitude; - dstLongitude = coordinate.longitude; + dstCoords = coordinate.coords; setTitle(); setDestCoords(); updateDistanceInfo(); - Log.d(cgSettings.tag, "destination set: " + title + " (" + String.format(Locale.getDefault(), "%.8f", dstLatitude) + " | " + String.format(Locale.getDefault(), "%.8f", dstLongitude) + ")"); + Log.d(cgSettings.tag, "destination set: " + title + " (" + + String.format(Locale.getDefault(), "%.8f", dstCoords.getLatitude()) + " | " + + String.format(Locale.getDefault(), "%.8f", dstCoords.getLongitude()) + ")"); return true; } @@ -307,15 +305,15 @@ public class cgeonavigate extends AbstractActivity { } private void setDestCoords() { - if (dstLatitude == null || dstLatitude == null) { + if (dstCoords == null) { return; } - ((TextView) findViewById(R.id.destination)).setText(cgBase.formatCoords(dstLatitude, dstLongitude, true)); + ((TextView) findViewById(R.id.destination)).setText(cgBase.formatCoords(dstCoords, true)); } - public void setDest(Double lat, Double lon) { - if (lat == null || lon == null) { + public void setDest(final Geopoint coords) { + if (coords == null) { return; } @@ -323,22 +321,16 @@ public class cgeonavigate extends AbstractActivity { setTitle(); setDestCoords(); - dstLatitude = lat; - dstLongitude = lon; + dstCoords = coords; updateDistanceInfo(); } - public Map<String, Double> getCoordinatesNow() { - Map<String, Double> coordsNow = new HashMap<String, Double>(); - if (geo != null) { - coordsNow.put("latitude", geo.latitudeNow); - coordsNow.put("longitude", geo.longitudeNow); - } - return coordsNow; + public Geopoint getCoordinatesNow() { + return geo.coordsNow; } private void updateDistanceInfo() { - if (geo == null || geo.latitudeNow == null || geo.longitudeNow == null || dstLatitude == null || dstLongitude == null) { + if (geo == null || geo.coordsNow == null || dstCoords == null) { return; } @@ -349,8 +341,8 @@ public class cgeonavigate extends AbstractActivity { headingView = (TextView) findViewById(R.id.heading); } - cacheHeading = cgBase.getHeading(geo.latitudeNow, geo.longitudeNow, dstLatitude, dstLongitude); - distanceView.setText(base.getHumanDistance(cgBase.getDistance(geo.latitudeNow, geo.longitudeNow, dstLatitude, dstLongitude))); + cacheHeading = cgBase.getHeading(geo.coordsNow, dstCoords); + distanceView.setText(base.getHumanDistance(cgBase.getDistance(geo.coordsNow, dstCoords))); headingView.setText(String.format(Locale.getDefault(), "%.0f", cacheHeading) + "°"); } @@ -370,7 +362,7 @@ public class cgeonavigate extends AbstractActivity { navLocation = (TextView) findViewById(R.id.nav_location); } - if (geo.latitudeNow != null && geo.longitudeNow != null) { + if (geo.coordsNow != null) { String satellites = null; if (geo.satellitesVisible != null && geo.satellitesFixed != null && geo.satellitesFixed > 0) { satellites = res.getString(R.string.loc_sat) + ": " + geo.satellitesFixed + "/" + geo.satellitesVisible; @@ -406,9 +398,9 @@ public class cgeonavigate extends AbstractActivity { } else { humanAlt = String.format("%.0f", geo.altitudeNow) + " m"; } - navLocation.setText(cgBase.formatCoords(geo.latitudeNow, geo.longitudeNow, true) + " | " + humanAlt); + navLocation.setText(cgBase.formatCoords(geo.coordsNow, true) + " | " + humanAlt); } else { - navLocation.setText(cgBase.formatCoords(geo.latitudeNow, geo.longitudeNow, true)); + navLocation.setText(cgBase.formatCoords(geo.coordsNow, true)); } updateDistanceInfo(); diff --git a/src/cgeo/geocaching/cgeopoint.java b/src/cgeo/geocaching/cgeopoint.java index dba015d..6b5aa60 100644 --- a/src/cgeo/geocaching/cgeopoint.java +++ b/src/cgeo/geocaching/cgeopoint.java @@ -1,6 +1,5 @@ package cgeo.geocaching; -import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.regex.Matcher; @@ -35,6 +34,7 @@ import android.widget.ListView; import android.widget.TextView; import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.apps.cache.navi.NavigationAppFactory; +import cgeo.geocaching.geopoint.Geopoint; public class cgeopoint extends AbstractActivity { @@ -61,8 +61,8 @@ public class cgeopoint extends AbstractActivity { .findViewById(R.id.simple_way_point_latitude); TextView date = (TextView) convertView.findViewById(R.id.date); - String lonString = cgBase.formatLongitude(loc.getLongitude(), true); - String latString = cgBase.formatLatitude(loc.getLatitude(), true); + String lonString = cgBase.formatLongitude(loc.getCoords().getLongitude(), true); + String latString = cgBase.formatLatitude(loc.getCoords().getLatitude(), true); longitude.setText(lonString); latitude.setText(latString); @@ -130,11 +130,7 @@ public class cgeopoint extends AbstractActivity { long arg3) { Object selection = arg0.getItemAtPosition(arg2); if (selection instanceof cgDestination) { - List<Double> coords = new ArrayList<Double>(2); - coords.add(((cgDestination) selection).getLatitude()); - coords.add(((cgDestination) selection).getLongitude()); - - navigateTo(coords); + navigateTo(((cgDestination) selection).getCoords()); } } }); @@ -292,9 +288,9 @@ public class cgeopoint extends AbstractActivity { super.onPrepareOptionsMenu(menu); try { - List<Double> coords = getDestination(); + final Geopoint coords = getDestination(); - if (coords != null && coords.get(0) != null && coords.get(1) != null) { + if (coords != null) { menu.findItem(0).setVisible(true); menu.findItem(2).setVisible(true); menu.findItem(5).setVisible(true); @@ -316,9 +312,9 @@ public class cgeopoint extends AbstractActivity { public boolean onOptionsItemSelected(MenuItem item) { final int menuItem = item.getItemId(); - List<Double> coords = getDestination(); + final Geopoint coords = getDestination(); - if(coords != null && !coords.isEmpty()) + if(coords != null) { addToHistory(coords); } @@ -338,12 +334,10 @@ public class cgeopoint extends AbstractActivity { return NavigationAppFactory.onMenuItemSelected(item, geo, this, res, null, null, null, coords); } - private void addToHistory(List - <Double> coords) { + private void addToHistory(final Geopoint coords) { // Add locations to history cgDestination loc = new cgDestination(); - loc.setLatitude(coords.get(0)); - loc.setLongitude(coords.get(1)); + loc.setCoords(coords); if(!getHistoryOfSearchedLocations().contains(loc)) { @@ -398,8 +392,8 @@ public class cgeopoint extends AbstractActivity { navigateTo(getDestination()); } - private void navigateTo(List<Double> coords) { - if (coords == null || coords.get(0) == null || coords.get(1) == null) { + private void navigateTo(Geopoint geopoint) { + if (geopoint == null) { showToast(res.getString(R.string.err_location_unknown)); return; } @@ -407,8 +401,8 @@ public class cgeopoint extends AbstractActivity { cgeonavigate navigateActivity = new cgeonavigate(); Intent navigateIntent = new Intent(this, navigateActivity.getClass()); - navigateIntent.putExtra("latitude", coords.get(0)); - navigateIntent.putExtra("longitude", coords.get(1)); + navigateIntent.putExtra("latitude", geopoint.getLatitude()); + navigateIntent.putExtra("longitude", geopoint.getLongitude()); navigateIntent.putExtra("geocode", ""); navigateIntent.putExtra("name", "Some destination"); @@ -416,9 +410,9 @@ public class cgeopoint extends AbstractActivity { } private void cachesAround() { - List<Double> coords = getDestination(); + final Geopoint coords = getDestination(); - if (coords == null || coords.get(0) == null || coords.get(1) == null) { + if (coords == null) { showToast(res.getString(R.string.err_location_unknown)); return; } @@ -428,8 +422,8 @@ public class cgeopoint extends AbstractActivity { Intent cachesIntent = new Intent(this, cachesActivity.getClass()); cachesIntent.putExtra("type", "coordinate"); - cachesIntent.putExtra("latitude", coords.get(0)); - cachesIntent.putExtra("longitude", coords.get(1)); + cachesIntent.putExtra("latitude", coords.getLatitude()); + cachesIntent.putExtra("longitude", coords.getLongitude()); cachesIntent.putExtra("cachetype", settings.cacheType); startActivity(cachesIntent); @@ -453,8 +447,8 @@ public class cgeopoint extends AbstractActivity { lonEdit = (EditText) findViewById(R.id.longitude); } - latEdit.setHint(cgBase.formatLatitude(geo.latitudeNow, false)); - lonEdit.setHint(cgBase.formatLongitude(geo.longitudeNow, false)); + latEdit.setHint(cgBase.formatLatitude(geo.coordsNow.getLatitude(), false)); + lonEdit.setHint(cgBase.formatLongitude(geo.coordsNow.getLongitude(), false)); } catch (Exception e) { Log.w(cgSettings.tag, "Failed to update location."); } @@ -464,22 +458,21 @@ public class cgeopoint extends AbstractActivity { private class currentListener implements View.OnClickListener { public void onClick(View arg0) { - if (geo == null || geo.latitudeNow == null || geo.longitudeNow == null) { + if (geo == null || geo.coordsNow == null) { showToast(res.getString(R.string.err_point_unknown_position)); return; } - ((EditText) findViewById(R.id.latitude)).setText(cgBase.formatLatitude(geo.latitudeNow, true)); - ((EditText) findViewById(R.id.longitude)).setText(cgBase.formatLongitude(geo.longitudeNow, true)); + ((EditText) findViewById(R.id.latitude)).setText(cgBase.formatLatitude(geo.coordsNow.getLatitude(), true)); + ((EditText) findViewById(R.id.longitude)).setText(cgBase.formatLongitude(geo.coordsNow.getLongitude(), true)); changed = false; } } - private List<Double> getDestination() { - List<Double> coords = new ArrayList<Double>(); - Double latitude = null; - Double longitude = null; + private Geopoint getDestination() { + Geopoint result = null; + Geopoint coords = null; String bearingText = ((EditText) findViewById(R.id.bearing)).getText().toString(); String distanceText = ((EditText) findViewById(R.id.distance)).getText().toString(); @@ -507,16 +500,14 @@ public class cgeopoint extends AbstractActivity { return null; } - latitude = (Double) latParsed.get("coordinate"); - longitude = (Double) lonParsed.get("coordinate"); + coords = new Geopoint((Double) latParsed.get("coordinate"), (Double) lonParsed.get("coordinate")); } else { - if (geo == null || geo.latitudeNow == null || geo.longitudeNow == null) { + if (geo == null || geo.coordsNow == null) { showToast(res.getString(R.string.err_point_curr_position_unavailable)); return null; } - latitude = geo.latitudeNow; - longitude = geo.longitudeNow; + coords = geo.coordsNow; } if (StringUtils.isNotBlank(bearingText) && StringUtils.isNotBlank(distanceText)) { @@ -573,39 +564,31 @@ public class cgeopoint extends AbstractActivity { return null; } - Double latParsed = null; - Double lonParsed = null; - - Map<String, Double> coordsDst = cgBase.getRadialDistance(latitude, longitude, bearing, distance); - - latParsed = coordsDst.get("latitude"); - lonParsed = coordsDst.get("longitude"); + final Geopoint coordsDst = cgBase.getRadialDistance(coords, bearing, distance); - if (latParsed == null || lonParsed == null) { + if (coordsDst == null) { showToast(res.getString(R.string.err_point_location_error)); return null; } - coords.add(0, (Double) latParsed); - coords.add(1, (Double) lonParsed); - } else if (latitude != null && longitude != null) { - coords.add(0, latitude); - coords.add(1, longitude); + result = coordsDst; + } else if (coords != null) { + result = coords; } else { return null; } - saveCoords(coords.get(0), coords.get(1)); + saveCoords(result); - return coords; + return result; } - private void saveCoords(Double latitude, Double longitude) { - if (changed && latitude != null && longitude != null) { + private void saveCoords(final Geopoint coords) { + if (changed && coords != null) { SharedPreferences.Editor edit = prefs.edit(); - edit.putFloat("anylatitude", latitude.floatValue()); - edit.putFloat("anylongitude", longitude.floatValue()); + edit.putFloat("anylatitude", (float) coords.getLatitude()); + edit.putFloat("anylongitude", (float) coords.getLongitude()); edit.commit(); } else { diff --git a/src/cgeo/geocaching/cgeopopup.java b/src/cgeo/geocaching/cgeopopup.java index 9b1d816..696fc17 100644 --- a/src/cgeo/geocaching/cgeopopup.java +++ b/src/cgeo/geocaching/cgeopopup.java @@ -145,7 +145,7 @@ public class cgeopopup extends AbstractActivity { super.onPrepareOptionsMenu(menu); try { - if (cache != null && cache.latitude != null && cache.longitude != null) { + if (cache != null && cache.coords != null) { menu.findItem(0).setVisible(true); menu.findItem(2).setVisible(true); menu.findItem(5).setVisible(true); @@ -509,8 +509,8 @@ public class cgeopopup extends AbstractActivity { } try { - if (geo.latitudeNow != null && geo.longitudeNow != null && cache != null && cache.latitude != null && cache.longitude != null) { - cacheDistance.setText(base.getHumanDistance(cgBase.getDistance(geo.latitudeNow, geo.longitudeNow, cache.latitude, cache.longitude))); + if (geo.coordsNow != null && cache != null && cache.coords != null) { + cacheDistance.setText(base.getHumanDistance(cgBase.getDistance(geo.coordsNow, cache.coords))); cacheDistance.bringToFront(); } } catch (Exception e) { @@ -520,15 +520,15 @@ public class cgeopopup extends AbstractActivity { } private void navigateTo() { - if (cache == null || cache.latitude == null || cache.longitude == null) { + if (cache == null || cache.coords == null) { showToast(res.getString(R.string.err_location_unknown)); } cgeonavigate navigateActivity = new cgeonavigate(); Intent navigateIntent = new Intent(this, navigateActivity.getClass()); - navigateIntent.putExtra("latitude", cache.latitude); - navigateIntent.putExtra("longitude", cache.longitude); + navigateIntent.putExtra("latitude", cache.coords.getLatitude()); + navigateIntent.putExtra("longitude", cache.coords.getLongitude()); navigateIntent.putExtra("geocode", ""); navigateIntent.putExtra("name", "Some destination"); @@ -536,11 +536,11 @@ public class cgeopopup extends AbstractActivity { } private void cachesAround() { - if (cache == null || cache.latitude == null || cache.longitude == null) { + if (cache == null || cache.coords == null) { showToast(res.getString(R.string.err_location_unknown)); } - cgeocaches.startActivityCachesAround(this, cache.latitude, cache.longitude); + cgeocaches.startActivityCachesAround(this, cache.coords); finish(); } @@ -641,7 +641,7 @@ public class cgeopopup extends AbstractActivity { } public void goCompass(View view) { - if (cache == null || cache.latitude == null || cache.longitude == null) { + if (cache == null || cache.coords == null) { showToast(res.getString(R.string.cache_coordinates_no)); return; @@ -650,8 +650,8 @@ public class cgeopopup extends AbstractActivity { cgeonavigate navigateActivity = new cgeonavigate(); Intent navigateIntent = new Intent(cgeopopup.this, navigateActivity.getClass()); - navigateIntent.putExtra("latitude", cache.latitude); - navigateIntent.putExtra("longitude", cache.longitude); + navigateIntent.putExtra("latitude", cache.coords.getLatitude()); + navigateIntent.putExtra("longitude", cache.coords.getLongitude()); navigateIntent.putExtra("geocode", cache.geocode.toUpperCase()); navigateIntent.putExtra("name", cache.name); diff --git a/src/cgeo/geocaching/cgeowaypoint.java b/src/cgeo/geocaching/cgeowaypoint.java index d623bb9..c3eb684 100644 --- a/src/cgeo/geocaching/cgeowaypoint.java +++ b/src/cgeo/geocaching/cgeowaypoint.java @@ -72,8 +72,8 @@ public class cgeowaypoint extends AbstractActivity { registerNavigationMenu(identification); waypoint.setIcon(res, base, identification); - if (waypoint.latitude != null && waypoint.longitude != null) { - coords.setText(Html.fromHtml(cgBase.formatCoords(waypoint.latitude, waypoint.longitude, true)), TextView.BufferType.SPANNABLE); + if (waypoint.coords != null) { + coords.setText(Html.fromHtml(cgBase.formatCoords(waypoint.coords, true)), TextView.BufferType.SPANNABLE); compass.setVisibility(View.VISIBLE); separator.setVisibility(View.VISIBLE); } else { @@ -229,7 +229,7 @@ public class cgeowaypoint extends AbstractActivity { super.onPrepareOptionsMenu(menu); try { - boolean visible = waypoint != null && waypoint.latitude != null && waypoint.longitude != null; + boolean visible = waypoint != null && waypoint.coords != null; menu.findItem(MENU_ID_NAVIGATION).setVisible(visible); menu.findItem(MENU_ID_COMPASS).setVisible(visible); menu.findItem(MENU_ID_CACHES_AROUND).setVisible(visible); @@ -255,11 +255,11 @@ public class cgeowaypoint extends AbstractActivity { } private void cachesAround() { - if (waypoint == null || waypoint.latitude == null || waypoint.longitude == null) { + if (waypoint == null || waypoint.coords == null) { showToast(res.getString(R.string.err_location_unknown)); } - cgeocaches.startActivityCachesAround(this, waypoint.latitude, waypoint.longitude); + cgeocaches.startActivityCachesAround(this, waypoint.coords); finish(); } @@ -315,8 +315,8 @@ public class cgeowaypoint extends AbstractActivity { } Intent navigateIntent = new Intent(this, cgeonavigate.class); - navigateIntent.putExtra("latitude", waypoint.latitude); - navigateIntent.putExtra("longitude", waypoint.longitude); + navigateIntent.putExtra("latitude", waypoint.coords.getLatitude()); + navigateIntent.putExtra("longitude", waypoint.coords.getLongitude()); navigateIntent.putExtra("geocode", waypoint.prefix.trim() + "/" + waypoint.lookup.trim()); navigateIntent.putExtra("name", waypoint.name); @@ -326,7 +326,7 @@ public class cgeowaypoint extends AbstractActivity { } private boolean navigationPossible() { - if (waypoint == null || waypoint.latitude == null || waypoint.longitude == null) { + if (waypoint == null || waypoint.coords == null) { showToast(res.getString(R.string.err_location_unknown)); return false; } diff --git a/src/cgeo/geocaching/cgeowaypointadd.java b/src/cgeo/geocaching/cgeowaypointadd.java index 3c46ad0..1d641d7 100644 --- a/src/cgeo/geocaching/cgeowaypointadd.java +++ b/src/cgeo/geocaching/cgeowaypointadd.java @@ -21,6 +21,7 @@ import android.widget.Button; import android.widget.EditText; import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.activity.ActivityMixin; +import cgeo.geocaching.geopoint.Geopoint; public class cgeowaypointadd extends AbstractActivity { @@ -57,8 +58,8 @@ public class cgeowaypointadd extends AbstractActivity { app.setAction(geocode); - ((Button) findViewById(R.id.buttonLatitude)).setText(cgBase.formatLatitude(waypoint.latitude, true)); - ((Button) findViewById(R.id.buttonLongitude)).setText(cgBase.formatLongitude(waypoint.longitude, true)); + ((Button) findViewById(R.id.buttonLatitude)).setText(cgBase.formatLatitude(waypoint.coords.getLatitude(), true)); + ((Button) findViewById(R.id.buttonLongitude)).setText(cgBase.formatLongitude(waypoint.coords.getLongitude(), true)); ((EditText) findViewById(R.id.name)).setText(Html.fromHtml(waypoint.name.trim()).toString()); ((EditText) findViewById(R.id.note)).setText(Html.fromHtml(waypoint.note.trim()).toString()); @@ -187,15 +188,15 @@ public class cgeowaypointadd extends AbstractActivity { @Override public void updateLoc(cgGeo geo) { - if (geo == null || geo.latitudeNow == null || geo.longitudeNow == null) { + if (geo == null || geo.coordsNow == null) { return; } try { Button bLat = (Button) findViewById(R.id.buttonLatitude); Button bLon = (Button) findViewById(R.id.buttonLongitude); - bLat.setHint(cgBase.formatLatitude(geo.latitudeNow, false)); - bLon.setHint(cgBase.formatLongitude(geo.longitudeNow, false)); + bLat.setHint(cgBase.formatLatitude(geo.coordsNow.getLatitude(), false)); + bLon.setHint(cgBase.formatLongitude(geo.coordsNow.getLongitude(), false)); } catch (Exception e) { Log.w(cgSettings.tag, "Failed to update location."); } @@ -223,12 +224,11 @@ public class cgeowaypointadd extends AbstractActivity { coordsDialog.setCancelable(true); coordsDialog.setOnCoordinateUpdate(new cgeocoords.CoordinateUpdate() { @Override - public void update(List<Double> coords) { - ((Button) findViewById(R.id.buttonLatitude)).setText(cgBase.formatLatitude(coords.get(0), true)); - ((Button) findViewById(R.id.buttonLongitude)).setText(cgBase.formatLongitude(coords.get(1), true)); + public void update(final Geopoint coords) { + ((Button) findViewById(R.id.buttonLatitude)).setText(cgBase.formatLatitude(coords.getLatitude(), true)); + ((Button) findViewById(R.id.buttonLongitude)).setText(cgBase.formatLongitude(coords.getLongitude(), true)); if (waypoint != null) { - waypoint.latitude = coords.get(0); - waypoint.longitude = coords.get(1); + waypoint.coords = coords; } } }); @@ -272,13 +272,13 @@ public class cgeowaypointadd extends AbstractActivity { latitude = (Double) latParsed.get("coordinate"); longitude = (Double) lonParsed.get("coordinate"); } else { - if (geo == null || geo.latitudeNow == null || geo.longitudeNow == null) { + if (geo == null || geo.coordsNow == null) { showToast(res.getString(R.string.err_point_curr_position_unavailable)); return; } - latitude = geo.latitudeNow; - longitude = geo.longitudeNow; + latitude = geo.coordsNow.getLatitude(); + longitude = geo.coordsNow.getLongitude(); } if (StringUtils.isNotBlank(bearingText) && StringUtils.isNotBlank(distanceText)) { @@ -338,10 +338,10 @@ public class cgeowaypointadd extends AbstractActivity { Double latParsed = null; Double lonParsed = null; - Map<String, Double> coordsDst = cgBase.getRadialDistance(latitude, longitude, bearing, distance); + final Geopoint coordsDst = cgBase.getRadialDistance(new Geopoint(latitude, longitude), bearing, distance); - latParsed = coordsDst.get("latitude"); - lonParsed = coordsDst.get("longitude"); + latParsed = coordsDst.getLatitude(); + lonParsed = coordsDst.getLongitude(); if (latParsed == null || lonParsed == null) { showToast(res.getString(R.string.err_point_location_error)); @@ -371,8 +371,7 @@ public class cgeowaypointadd extends AbstractActivity { waypoint.prefix = prefix; waypoint.lookup = lookup; waypoint.name = name; - waypoint.latitude = coords.get(0); - waypoint.longitude = coords.get(1); + waypoint.coords = new Geopoint(coords.get(0), coords.get(1)); waypoint.latitudeString = cgBase.formatLatitude(coords.get(0), true); waypoint.longitudeString = cgBase.formatLongitude(coords.get(1), true); waypoint.note = note; diff --git a/src/cgeo/geocaching/files/FileParser.java b/src/cgeo/geocaching/files/FileParser.java index cc83cd1..2939b59 100644 --- a/src/cgeo/geocaching/files/FileParser.java +++ b/src/cgeo/geocaching/files/FileParser.java @@ -39,8 +39,8 @@ public abstract class FileParser { }
protected static void fixCache(cgCache cache) {
- cache.latitudeString = cgBase.formatLatitude(cache.latitude, true);
- cache.longitudeString = cgBase.formatLongitude(cache.longitude, true);
+ cache.latitudeString = cgBase.formatLatitude(cache.coords.getLatitude(), true);
+ cache.longitudeString = cgBase.formatLongitude(cache.coords.getLongitude(), true);
if (cache.inventory != null) {
cache.inventoryItems = cache.inventory.size();
} else {
diff --git a/src/cgeo/geocaching/files/GPXParser.java b/src/cgeo/geocaching/files/GPXParser.java index 101d68b..978079d 100644 --- a/src/cgeo/geocaching/files/GPXParser.java +++ b/src/cgeo/geocaching/files/GPXParser.java @@ -34,6 +34,7 @@ import cgeo.geocaching.cgSettings; import cgeo.geocaching.cgTrackable; import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.connector.ConnectorFactory; +import cgeo.geocaching.geopoint.Geopoint; public abstract class GPXParser extends FileParser { @@ -226,11 +227,9 @@ public abstract class GPXParser extends FileParser { @Override public void start(Attributes attrs) { try { - if (attrs.getIndex("lat") > -1) { - cache.latitude = new Double(attrs.getValue("lat")); - } - if (attrs.getIndex("lon") > -1) { - cache.longitude = new Double(attrs.getValue("lon")); + if (attrs.getIndex("lat") > -1 && attrs.getIndex("lon") > -1) { + cache.coords = new Geopoint(new Double(attrs.getValue("lat")), + new Double(attrs.getValue("lon"))); } } catch (Exception e) { Log.w(cgSettings.tag, "Failed to parse waypoint's latitude and/or longitude."); @@ -251,7 +250,7 @@ public abstract class GPXParser extends FileParser { } if (StringUtils.isNotBlank(cache.geocode) - && cache.latitude != null && cache.longitude != null + && cache.coords != null && ((type == null && sym == null) || (type != null && type.indexOf("geocache") > -1) || (sym != null && sym.indexOf("geocache") > -1))) { diff --git a/src/cgeo/geocaching/files/LocParser.java b/src/cgeo/geocaching/files/LocParser.java index 9f7f525..47d46d4 100644 --- a/src/cgeo/geocaching/files/LocParser.java +++ b/src/cgeo/geocaching/files/LocParser.java @@ -19,6 +19,7 @@ import cgeo.geocaching.cgCoord; import cgeo.geocaching.cgSearch;
import cgeo.geocaching.cgSettings;
import cgeo.geocaching.cgeoapplication;
+import cgeo.geocaching.geopoint.Geopoint;
public final class LocParser extends FileParser {
private static final Pattern patternGeocode = Pattern
@@ -51,8 +52,7 @@ public final class LocParser extends FileParser { }
private static void copyCoordToCache(final cgCoord coord, final cgCache cache) {
- cache.latitude = coord.latitude;
- cache.longitude = coord.longitude;
+ cache.coords = coord.coords;
cache.difficulty = coord.difficulty;
cache.terrain = coord.terrain;
cache.size = coord.size;
@@ -93,14 +93,12 @@ public final class LocParser extends FileParser { pointCoord.name = name;
}
final Matcher matcherLat = patternLat.matcher(pointString);
- if (matcherLat.find()) {
- tmp = cgBase.parseCoordinate(matcherLat.group(1).trim(), "lat");
- pointCoord.latitude = (Double) tmp.get("coordinate");
- }
final Matcher matcherLon = patternLon.matcher(pointString);
- if (matcherLon.find()) {
- tmp = cgBase.parseCoordinate(matcherLon.group(1).trim(), "lon");
- pointCoord.longitude = (Double) tmp.get("coordinate");
+ if (matcherLat.find() && matcherLon.find()) {
+ final Map<String, Object>tmpLat = cgBase.parseCoordinate(matcherLat.group(1).trim(), "lat");
+ final Map<String, Object> tmpLon = cgBase.parseCoordinate(matcherLon.group(1).trim(), "lon");
+ pointCoord.coords = new Geopoint((Double) tmpLat.get("coordinate"),
+ (Double) tmpLon.get("coordinate"));
}
final Matcher matcherDifficulty = patternDifficulty.matcher(pointString);
if (matcherDifficulty.find()) {
diff --git a/src/cgeo/geocaching/geopoint/Geopoint.java b/src/cgeo/geocaching/geopoint/Geopoint.java index 44aadcc..a8d7d37 100644 --- a/src/cgeo/geocaching/geopoint/Geopoint.java +++ b/src/cgeo/geocaching/geopoint/Geopoint.java @@ -1,5 +1,7 @@ package cgeo.geocaching.geopoint; +import android.location.Location; + /** * Abstraction of geographic point. */ @@ -60,6 +62,15 @@ public class Geopoint } /** + * Creates new Geopoint with given Location. + * + * @param gp the Location to clone + */ + public Geopoint(final Location loc) { + this(loc.getLatitude(), loc.getLongitude()); + } + + /** * Set latitude in degree. * * @param lat latitude diff --git a/src/cgeo/geocaching/googlemaps/googleCacheOverlayItem.java b/src/cgeo/geocaching/googlemaps/googleCacheOverlayItem.java index 5546077..5f20dd4 100644 --- a/src/cgeo/geocaching/googlemaps/googleCacheOverlayItem.java +++ b/src/cgeo/geocaching/googlemaps/googleCacheOverlayItem.java @@ -1,17 +1,17 @@ package cgeo.geocaching.googlemaps; -import com.google.android.maps.GeoPoint; -import com.google.android.maps.OverlayItem; - import cgeo.geocaching.cgCoord; import cgeo.geocaching.mapinterfaces.CacheOverlayItemImpl; +import com.google.android.maps.GeoPoint; +import com.google.android.maps.OverlayItem; + public class googleCacheOverlayItem extends OverlayItem implements CacheOverlayItemImpl { private String cacheType = null; private cgCoord coord; public googleCacheOverlayItem(cgCoord coordinate, String type) { - super(new GeoPoint((int)(coordinate.latitude * 1e6), (int)(coordinate.longitude * 1e6)), coordinate.name, ""); + super(new GeoPoint(coordinate.coords.getLatitudeE6(), coordinate.coords.getLongitudeE6()), coordinate.name, ""); this.cacheType = type; this.coord = coordinate; diff --git a/src/cgeo/geocaching/googlemaps/googleMapFactory.java b/src/cgeo/geocaching/googlemaps/googleMapFactory.java index ba62737..96f90f8 100644 --- a/src/cgeo/geocaching/googlemaps/googleMapFactory.java +++ b/src/cgeo/geocaching/googlemaps/googleMapFactory.java @@ -4,6 +4,7 @@ import android.content.Context; import cgeo.geocaching.R; import cgeo.geocaching.cgCoord; import cgeo.geocaching.cgUser; +import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.mapinterfaces.CacheOverlayItemImpl; import cgeo.geocaching.mapinterfaces.GeoPointImpl; import cgeo.geocaching.mapinterfaces.MapFactory; @@ -29,8 +30,8 @@ public class googleMapFactory implements MapFactory{ } @Override - public GeoPointImpl getGeoPointBase(int latE6, int lonE6) { - return new googleGeoPoint(latE6, lonE6); + public GeoPointImpl getGeoPointBase(final Geopoint coords) { + return new googleGeoPoint(coords.getLatitudeE6(), coords.getLongitudeE6()); } @Override diff --git a/src/cgeo/geocaching/mapcommon/cgMapMyOverlay.java b/src/cgeo/geocaching/mapcommon/cgMapMyOverlay.java index a004405..ffe3e21 100644 --- a/src/cgeo/geocaching/mapcommon/cgMapMyOverlay.java +++ b/src/cgeo/geocaching/mapcommon/cgMapMyOverlay.java @@ -16,6 +16,7 @@ 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; import cgeo.geocaching.mapinterfaces.MapFactory; import cgeo.geocaching.mapinterfaces.MapProjectionImpl; @@ -55,7 +56,7 @@ public class cgMapMyOverlay implements OverlayBase { public void setCoordinates(Location coordinatesIn) { coordinates = coordinatesIn; - location = settings.getMapFactory().getGeoPointBase((int)(coordinatesIn.getLatitude() * 1e6), (int)(coordinatesIn.getLongitude() * 1e6)); + location = settings.getMapFactory().getGeoPointBase(new Geopoint(coordinates)); } public void setHeading(Double headingIn) { @@ -113,7 +114,8 @@ public class cgMapMyOverlay implements OverlayBase { Location.distanceBetween(latitude, longitude, latitude, longitude + 1, result); float longitudeLineDistance = result[0]; - GeoPointImpl leftGeo = mapFactory.getGeoPointBase((int)(latitude * 1e6), (int)((longitude - accuracy / longitudeLineDistance) * 1e6)); + final Geopoint leftCoords = new Geopoint(latitude, longitude - accuracy / longitudeLineDistance); + GeoPointImpl leftGeo = mapFactory.getGeoPointBase(leftCoords); projection.toPixels(leftGeo, left); projection.toPixels(location, center); int radius = center.x - left.x; @@ -126,7 +128,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(historyRecent.getLatitude(), historyRecent.getLongitude(), coordinates.getLatitude(), coordinates.getLongitude()) > 0.005) || historyRecent == null)) { + if (coordinates.getAccuracy() < 50f && ((historyRecent != null && cgBase.getDistance(new Geopoint(historyRecent), new Geopoint(coordinates)) > 0.005) || historyRecent == null)) { if (historyRecent != null) history.add(historyRecent); historyRecent = coordinates; @@ -151,8 +153,8 @@ public class cgMapMyOverlay implements OverlayBase { Location now = history.get(cnt); if (prev != null && now != null) { - projection.toPixels(mapFactory.getGeoPointBase((int)(prev.getLatitude() * 1e6), (int)(prev.getLongitude() * 1e6)), historyPointP); - projection.toPixels(mapFactory.getGeoPointBase((int)(now.getLatitude() * 1e6), (int)(now.getLongitude() * 1e6)), historyPointN); + projection.toPixels(mapFactory.getGeoPointBase(new Geopoint(prev)), historyPointP); + projection.toPixels(mapFactory.getGeoPointBase(new Geopoint(now)), historyPointN); if ((alphaCnt - cnt) > 0) { alpha = 255 / (alphaCnt - cnt); @@ -175,8 +177,8 @@ public class cgMapMyOverlay implements OverlayBase { Location now = coordinates; if (prev != null && now != null) { - projection.toPixels(mapFactory.getGeoPointBase((int)(prev.getLatitude() * 1e6), (int)(prev.getLongitude() * 1e6)), historyPointP); - projection.toPixels(mapFactory.getGeoPointBase((int)(now.getLatitude() * 1e6), (int)(now.getLongitude() * 1e6)), historyPointN); + projection.toPixels(mapFactory.getGeoPointBase(new Geopoint(prev)), historyPointP); + projection.toPixels(mapFactory.getGeoPointBase(new Geopoint(now)), historyPointN); historyLineShadow.setAlpha(255); historyLine.setAlpha(255); diff --git a/src/cgeo/geocaching/mapcommon/cgMapOverlay.java b/src/cgeo/geocaching/mapcommon/cgMapOverlay.java index 475ded2..de8a6ed 100644 --- a/src/cgeo/geocaching/mapcommon/cgMapOverlay.java +++ b/src/cgeo/geocaching/mapcommon/cgMapOverlay.java @@ -26,6 +26,7 @@ import cgeo.geocaching.cgeodetail; import cgeo.geocaching.cgeonavigate; import cgeo.geocaching.cgeopopup; import cgeo.geocaching.cgeowaypoint; +import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.mapinterfaces.CacheOverlayItemImpl; import cgeo.geocaching.mapinterfaces.GeoPointImpl; import cgeo.geocaching.mapinterfaces.ItemizedOverlayImpl; @@ -137,11 +138,15 @@ public class cgMapOverlay extends ItemizedOverlayBase implements OverlayBase { final cgCoord itemCoord = item.getCoord(); float[] result = new float[1]; - Location.distanceBetween(itemCoord.latitude, itemCoord.longitude, itemCoord.latitude, itemCoord.longitude + 1, result); + Location.distanceBetween(itemCoord.coords.getLatitude(), itemCoord.coords.getLongitude(), + itemCoord.coords.getLatitude(), itemCoord.coords.getLongitude() + 1, result); final float longitudeLineDistance = result[0]; - GeoPointImpl itemGeo = mapFactory.getGeoPointBase((int)(itemCoord.latitude * 1e6), (int)(itemCoord.longitude * 1e6)); - GeoPointImpl leftGeo = mapFactory.getGeoPointBase((int)(itemCoord.latitude * 1e6), (int)((itemCoord.longitude - 161 / longitudeLineDistance) * 1e6)); + GeoPointImpl itemGeo = mapFactory.getGeoPointBase(itemCoord.coords); + + final Geopoint leftCoords = new Geopoint(itemCoord.coords.getLatitude(), + itemCoord.coords.getLongitude() - 161 / longitudeLineDistance); + GeoPointImpl leftGeo = mapFactory.getGeoPointBase(leftCoords); projection.toPixels(itemGeo, center); projection.toPixels(leftGeo, left); @@ -297,8 +302,8 @@ public class cgMapOverlay extends ItemizedOverlayBase implements OverlayBase { cgeonavigate.coordinates.add(coordinate); Intent navigateIntent = new Intent(context, navigateActivity.getClass()); - navigateIntent.putExtra("latitude", coordinate.latitude); - navigateIntent.putExtra("longitude", coordinate.longitude); + navigateIntent.putExtra("latitude", coordinate.coords.getLatitude()); + navigateIntent.putExtra("longitude", coordinate.coords.getLongitude()); navigateIntent.putExtra("geocode", coordinate.geocode.toUpperCase()); context.startActivity(navigateIntent); dialog.cancel(); @@ -325,8 +330,8 @@ public class cgMapOverlay extends ItemizedOverlayBase implements OverlayBase { cgeonavigate.coordinates.add(coordinate); Intent navigateIntent = new Intent(context, navigateActivity.getClass()); - navigateIntent.putExtra("latitude", coordinate.latitude); - navigateIntent.putExtra("longitude", coordinate.longitude); + navigateIntent.putExtra("latitude", coordinate.coords.getLatitude()); + navigateIntent.putExtra("longitude", coordinate.coords.getLongitude()); navigateIntent.putExtra("geocode", coordinate.name); context.startActivity(navigateIntent); diff --git a/src/cgeo/geocaching/mapcommon/cgOverlayScale.java b/src/cgeo/geocaching/mapcommon/cgOverlayScale.java index cb73c75..fcd5bf5 100644 --- a/src/cgeo/geocaching/mapcommon/cgOverlayScale.java +++ b/src/cgeo/geocaching/mapcommon/cgOverlayScale.java @@ -10,6 +10,7 @@ import android.util.DisplayMetrics; import cgeo.geocaching.cgBase; import cgeo.geocaching.cgSettings; import cgeo.geocaching.cgSettings.mapSourceEnum; +import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.mapinterfaces.GeoPointImpl; import cgeo.geocaching.mapinterfaces.MapProjectionImpl; import cgeo.geocaching.mapinterfaces.MapViewImpl; @@ -54,7 +55,11 @@ public class cgOverlayScale implements OverlayBase { pixels = mapView.getWidth() / 2.0; // pixels related to following latitude span bottom = mapView.getHeight() - 14; // pixels from bottom side of screen - distance = cgBase.getDistance((center.getLatitudeE6() / 1e6), ((center.getLongitudeE6() / 1e6) - (span /2)), (center.getLatitudeE6() / 1e6), ((center.getLongitudeE6() / 1e6) + (span /2))); + + 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; distanceRound = 0d; diff --git a/src/cgeo/geocaching/mapcommon/cgeomap.java b/src/cgeo/geocaching/mapcommon/cgeomap.java index 2798a61..fdffe0b 100644 --- a/src/cgeo/geocaching/mapcommon/cgeomap.java +++ b/src/cgeo/geocaching/mapcommon/cgeomap.java @@ -25,8 +25,8 @@ import android.view.Menu; import android.view.MenuItem; import android.view.SubMenu; import android.view.View; -import android.view.WindowManager; import android.view.ViewGroup.LayoutParams; +import android.view.WindowManager; import android.widget.ImageSwitcher; import android.widget.ImageView; import android.widget.ImageView.ScaleType; @@ -38,13 +38,14 @@ import cgeo.geocaching.cgCoord; import cgeo.geocaching.cgDirection; import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgSettings; +import cgeo.geocaching.cgSettings.mapSourceEnum; import cgeo.geocaching.cgUpdateDir; import cgeo.geocaching.cgUpdateLoc; import cgeo.geocaching.cgUser; import cgeo.geocaching.cgWaypoint; import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.activity.ActivityMixin; -import cgeo.geocaching.cgSettings.mapSourceEnum; +import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.mapinterfaces.ActivityImpl; import cgeo.geocaching.mapinterfaces.CacheOverlayItemImpl; import cgeo.geocaching.mapinterfaces.GeoPointImpl; @@ -85,8 +86,7 @@ public class cgeomap extends MapBase implements OnDragListener, ViewFactory { private boolean fromDetailIntent = false; private String searchIdIntent = null; private String geocodeIntent = null; - private Double latitudeIntent = null; - private Double longitudeIntent = null; + private Geopoint coordsIntent = null; private String waypointTypeIntent = null; private int[] mapStateIntent = null; // status data @@ -314,24 +314,22 @@ public class cgeomap extends MapBase implements OnDragListener, ViewFactory { fromDetailIntent = extras.getBoolean("detail"); searchIdIntent = extras.getString("searchid"); geocodeIntent = extras.getString("geocode"); - latitudeIntent = extras.getDouble("latitude"); - longitudeIntent = extras.getDouble("longitude"); + final double latitudeIntent = extras.getDouble("latitude"); + final double longitudeIntent = extras.getDouble("longitude"); + coordsIntent = new Geopoint(latitudeIntent, longitudeIntent); waypointTypeIntent = extras.getString("wpttype"); mapStateIntent = extras.getIntArray("mapstate"); if ("".equals(searchIdIntent)) { searchIdIntent = null; } - if (latitudeIntent == 0.0) { - latitudeIntent = null; - } - if (longitudeIntent == 0.0) { - longitudeIntent = null; + if (coordsIntent.getLatitude() == 0.0 || coordsIntent.getLongitude() == 0.0) { + coordsIntent = null; } } // live or death - if (searchIdIntent == null && geocodeIntent == null && (latitudeIntent == null || longitudeIntent == null)) { + if (searchIdIntent == null && geocodeIntent == null && coordsIntent == null) { live = true; } else { live = false; @@ -346,8 +344,8 @@ public class cgeomap extends MapBase implements OnDragListener, ViewFactory { } else { followMyLocation = 1 == mapStateIntent[3] ? true : false; } - if (geocodeIntent != null || searchIdIntent != null || (latitudeIntent != null && longitudeIntent != null) || mapStateIntent != null) { - centerMap(geocodeIntent, searchIdIntent, latitudeIntent, longitudeIntent, mapStateIntent); + if (geocodeIntent != null || searchIdIntent != null || coordsIntent != null || mapStateIntent != null) { + centerMap(geocodeIntent, searchIdIntent, coordsIntent, mapStateIntent); } // prepare my location button @@ -587,8 +585,8 @@ public class cgeomap extends MapBase implements OnDragListener, ViewFactory { final int mapSpanLon = mapView.getLongitudeSpan(); for (cgCache oneCache : cachesProtected) { - if (oneCache != null && oneCache.latitude != null && oneCache.longitude != null) { - if (cgBase.isCacheInViewPort(mapCenterLat, mapCenterLon, mapSpanLat, mapSpanLon, oneCache.latitude, oneCache.longitude) && app.isOffline(oneCache.geocode, null) == false) { + if (oneCache != null && oneCache.coords != null) { + if (cgBase.isCacheInViewPort(mapCenterLat, mapCenterLon, mapSpanLat, mapSpanLon, oneCache.coords) && app.isOffline(oneCache.geocode, null) == false) { geocodes.add(oneCache.geocode); } } @@ -672,8 +670,10 @@ public class cgeomap extends MapBase implements OnDragListener, ViewFactory { mapIntent.putExtra("detail", fromDetailIntent); mapIntent.putExtra("searchid", searchIdIntent); mapIntent.putExtra("geocode", geocodeIntent); - mapIntent.putExtra("latitude", latitudeIntent); - mapIntent.putExtra("longitude", longitudeIntent); + if (coordsIntent != null) { + mapIntent.putExtra("latitude", coordsIntent.getLatitude()); + mapIntent.putExtra("longitude", coordsIntent.getLongitude()); + } mapIntent.putExtra("wpttype", waypointTypeIntent); int[] mapState = new int[4]; GeoPointImpl mapCenter = mapView.getMapViewCenter(); @@ -753,7 +753,7 @@ public class cgeomap extends MapBase implements OnDragListener, ViewFactory { return; } - centerMap(geo.latitudeNow, geo.longitudeNow); + centerMap(geo.coordsNow); } // class: update location @@ -776,7 +776,7 @@ public class cgeomap extends MapBase implements OnDragListener, ViewFactory { overlayMyLoc.setCoordinates(geo.location); } - if (geo.latitudeNow != null && geo.longitudeNow != null) { + if (geo.coordsNow != null) { if (followMyLocation) { myLocationInMiddle(); } else { @@ -820,7 +820,7 @@ public class cgeomap extends MapBase implements OnDragListener, ViewFactory { } public void startTimer() { - if (latitudeIntent != null && longitudeIntent != null) { + if (coordsIntent != null) { // display just one point (new DisplayPointThread()).start(); } else { @@ -1283,7 +1283,7 @@ public class cgeomap extends MapBase implements OnDragListener, ViewFactory { return; } - if (cacheOne.latitude == null && cacheOne.longitude == null) { + if (cacheOne.coords == null) { continue; } @@ -1326,7 +1326,7 @@ public class cgeomap extends MapBase implements OnDragListener, ViewFactory { if (oneCache != null && oneCache.waypoints != null && !oneCache.waypoints.isEmpty()) { for (cgWaypoint oneWaypoint : oneCache.waypoints) { - if (oneWaypoint.latitude == null && oneWaypoint.longitude == null) { + if (oneWaypoint.coords == null) { continue; } @@ -1481,11 +1481,10 @@ public class cgeomap extends MapBase implements OnDragListener, ViewFactory { return; } - if (latitudeIntent != null && longitudeIntent != null) { + if (coordsIntent != null) { cgCoord coord = new cgCoord(); coord.type = "waypoint"; - coord.latitude = latitudeIntent; - coord.longitude = longitudeIntent; + coord.coords = coordsIntent; coord.name = "some place"; coordinates.add(coord); @@ -1632,8 +1631,8 @@ public class cgeomap extends MapBase implements OnDragListener, ViewFactory { } // center map to desired location - private void centerMap(Double latitude, Double longitude) { - if (latitude == null || longitude == null) { + private void centerMap(final Geopoint coords) { + if (coords == null) { return; } if (mapView == null) { @@ -1643,18 +1642,18 @@ public class cgeomap extends MapBase implements OnDragListener, ViewFactory { if (!alreadyCentered) { alreadyCentered = true; - mapController.setCenter(makeGeoPoint(latitude, longitude)); + mapController.setCenter(makeGeoPoint(coords)); } else { - mapController.animateTo(makeGeoPoint(latitude, longitude)); + mapController.animateTo(makeGeoPoint(coords)); } } // move map to view results of searchIdIntent - private void centerMap(String geocodeCenter, String searchIdCenter, Double latitudeCenter, Double longitudeCenter, int[] mapState) { + private void centerMap(String geocodeCenter, String searchIdCenter, final Geopoint coordsCenter, int[] mapState) { if (!centered && mapState != null) { try { - mapController.setCenter(settings.getMapFactory().getGeoPointBase(mapState[0], mapState[1])); + mapController.setCenter(settings.getMapFactory().getGeoPointBase(new Geopoint(mapState[0] / 1.0e6, mapState[1] / 1.0e6))); mapController.setZoom(mapState[2]); } catch (Exception e) { // nothing at all @@ -1712,7 +1711,7 @@ public class cgeomap extends MapBase implements OnDragListener, ViewFactory { } if (cnt != null && cnt > 0) { - mapController.setCenter(settings.getMapFactory().getGeoPointBase(centerLat, centerLon)); + mapController.setCenter(settings.getMapFactory().getGeoPointBase(new Geopoint(centerLat, centerLon))); if (Math.abs(maxLat - minLat) != 0 && Math.abs(maxLon - minLon) != 0) { mapController.zoomToSpan(Math.abs(maxLat - minLat), Math.abs(maxLon - minLon)); } @@ -1723,9 +1722,9 @@ public class cgeomap extends MapBase implements OnDragListener, ViewFactory { centered = true; alreadyCentered = true; - } else if (!centered && latitudeCenter != null && longitudeCenter != null) { + } else if (!centered && coordsCenter != null) { try { - mapController.setCenter(makeGeoPoint(latitudeCenter, longitudeCenter)); + mapController.setCenter(makeGeoPoint(coordsCenter)); } catch (Exception e) { // nothing at all } @@ -1762,8 +1761,8 @@ public class cgeomap extends MapBase implements OnDragListener, ViewFactory { } // make geopoint - private GeoPointImpl makeGeoPoint(Double latitude, Double longitude) { - return settings.getMapFactory().getGeoPointBase((int) (latitude * 1e6), (int) (longitude * 1e6)); + private GeoPointImpl makeGeoPoint(final Geopoint coords) { + return settings.getMapFactory().getGeoPointBase(coords); } // close activity and open homescreen diff --git a/src/cgeo/geocaching/mapinterfaces/MapFactory.java b/src/cgeo/geocaching/mapinterfaces/MapFactory.java index 4348c40..f43ceaf 100644 --- a/src/cgeo/geocaching/mapinterfaces/MapFactory.java +++ b/src/cgeo/geocaching/mapinterfaces/MapFactory.java @@ -4,6 +4,7 @@ import android.app.Activity; import android.content.Context; import cgeo.geocaching.cgCoord; import cgeo.geocaching.cgUser; +import cgeo.geocaching.geopoint.Geopoint; /** * Defines functions of a factory class to get implementation specific objects @@ -19,7 +20,7 @@ public interface MapFactory { public int getMapLayoutId(); - public GeoPointImpl getGeoPointBase(int latE6, int lonE6); + public GeoPointImpl getGeoPointBase(final Geopoint coords); CacheOverlayItemImpl getCacheOverlayItem(cgCoord coordinate, String type); diff --git a/src/cgeo/geocaching/mapsforge/mfCacheOverlayItem.java b/src/cgeo/geocaching/mapsforge/mfCacheOverlayItem.java index b6b7d62..b4c7c19 100644 --- a/src/cgeo/geocaching/mapsforge/mfCacheOverlayItem.java +++ b/src/cgeo/geocaching/mapsforge/mfCacheOverlayItem.java @@ -4,7 +4,6 @@ import org.mapsforge.android.maps.GeoPoint; import org.mapsforge.android.maps.OverlayItem; import android.graphics.drawable.Drawable; - import cgeo.geocaching.cgCoord; import cgeo.geocaching.mapinterfaces.CacheOverlayItemImpl; @@ -13,7 +12,7 @@ public class mfCacheOverlayItem extends OverlayItem implements CacheOverlayItemI private cgCoord coord; public mfCacheOverlayItem(cgCoord coordinate, String type) { - super(new GeoPoint((int)(coordinate.latitude * 1e6), (int)(coordinate.longitude * 1e6)), coordinate.name, ""); + super(new GeoPoint(coordinate.coords.getLatitudeE6(), coordinate.coords.getLongitudeE6()), coordinate.name, ""); this.cacheType = type; this.coord = coordinate; diff --git a/src/cgeo/geocaching/mapsforge/mfMapFactory.java b/src/cgeo/geocaching/mapsforge/mfMapFactory.java index 00204dd..5266e99 100644 --- a/src/cgeo/geocaching/mapsforge/mfMapFactory.java +++ b/src/cgeo/geocaching/mapsforge/mfMapFactory.java @@ -5,6 +5,7 @@ import android.content.Context; import cgeo.geocaching.R; import cgeo.geocaching.cgCoord; import cgeo.geocaching.cgUser; +import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.mapinterfaces.CacheOverlayItemImpl; import cgeo.geocaching.mapinterfaces.GeoPointImpl; import cgeo.geocaching.mapinterfaces.MapFactory; @@ -28,8 +29,8 @@ public class mfMapFactory implements MapFactory{ } @Override - public GeoPointImpl getGeoPointBase(int latE6, int lonE6) { - return new mfGeoPoint(latE6, lonE6); + public GeoPointImpl getGeoPointBase(final Geopoint coords) { + return new mfGeoPoint(coords.getLatitudeE6(), coords.getLongitudeE6()); } @Override diff --git a/src/cgeo/geocaching/sorting/DistanceComparator.java b/src/cgeo/geocaching/sorting/DistanceComparator.java index fc7b712..6198753 100644 --- a/src/cgeo/geocaching/sorting/DistanceComparator.java +++ b/src/cgeo/geocaching/sorting/DistanceComparator.java @@ -2,26 +2,25 @@ package cgeo.geocaching.sorting; import cgeo.geocaching.cgBase; import cgeo.geocaching.cgCache; +import cgeo.geocaching.geopoint.Geopoint; /** * sorts caches by distance to current position * */ public class DistanceComparator extends AbstractCacheComparator { - private Double latitude = null; - private Double longitude = null; + private Geopoint coords = null; public DistanceComparator() { // nothing } - public DistanceComparator(Double latitudeIn, Double longitudeIn) { - setCoords(latitudeIn, longitudeIn); + public DistanceComparator(final Geopoint coords) { + setCoords(coords); } - public void setCoords(Double latitudeIn, Double longitudeIn) { - latitude = latitudeIn; - longitude = longitudeIn; + public void setCoords(final Geopoint coords) { + this.coords = coords; } @Override @@ -31,8 +30,7 @@ public class DistanceComparator extends AbstractCacheComparator { @Override protected int compareCaches(final cgCache cache1, final cgCache cache2) { - if ((cache1.latitude == null || cache1.longitude == null - || cache2.latitude == null || cache2.longitude == null) + if ((cache1.coords == null || cache2.coords == null) && cache1.distance != null && cache2.distance != null) { if (cache1.distance < cache2.distance) { return -1; @@ -42,17 +40,15 @@ public class DistanceComparator extends AbstractCacheComparator { return 0; } } else { - if (cache1.latitude == null || cache1.longitude == null) { + if (cache1.coords == null) { return 1; } - if (cache2.latitude == null || cache2.longitude == null) { + if (cache2.coords == null) { return -1; } - Double distance1 = cgBase.getDistance(latitude, longitude, - cache1.latitude, cache1.longitude); - Double distance2 = cgBase.getDistance(latitude, longitude, - cache2.latitude, cache2.longitude); + Double distance1 = cgBase.getDistance(coords, cache1.coords); + Double distance2 = cgBase.getDistance(coords, cache2.coords); if (distance1 < distance2) { return -1; |
