aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/res/values/strings.xml1
-rw-r--r--main/src/cgeo/geocaching/cgData.java149
-rw-r--r--main/src/cgeo/geocaching/cgeoapplication.java5
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java32
4 files changed, 116 insertions, 71 deletions
diff --git a/main/res/values/strings.xml b/main/res/values/strings.xml
index 13de995..ead1b80 100644
--- a/main/res/values/strings.xml
+++ b/main/res/values/strings.xml
@@ -996,6 +996,7 @@
· Pascal (localization NL)\n
· Pavol Babinčák (code, loc. SK)\n
· Peter (localization HU)\n
+ · <a href="https://github.com/Portree-Kid">Portree Kid</a> (code)\n
· Rainer S. (code)\n
· Ray (code, loc. JA)\n
· <a href="http://seromenho.com/">Ricardo Seromenho</a> (localization PT)\n
diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java
index 24151da..281d098 100644
--- a/main/src/cgeo/geocaching/cgData.java
+++ b/main/src/cgeo/geocaching/cgData.java
@@ -28,6 +28,7 @@ import android.database.sqlite.SQLiteStatement;
import java.io.File;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.EnumSet;
@@ -1883,39 +1884,15 @@ public class cgData {
Cursor cursor = null;
try {
- StringBuilder where = cgData.whereGeocodeIn(geocodes);
+ StringBuilder where = null;
// viewport limitation
if (centerLat != null && centerLon != null && spanLat != null && spanLon != null) {
- double latMin = (centerLat / 1e6) - ((spanLat / 1e6) / 2) - ((spanLat / 1e6) / 4);
- double latMax = (centerLat / 1e6) + ((spanLat / 1e6) / 2) + ((spanLat / 1e6) / 4);
- double lonMin = (centerLon / 1e6) - ((spanLon / 1e6) / 2) - ((spanLon / 1e6) / 4);
- double lonMax = (centerLon / 1e6) + ((spanLon / 1e6) / 2) + ((spanLon / 1e6) / 4);
- double llCache;
-
- if (latMin > latMax) {
- llCache = latMax;
- latMax = latMin;
- latMin = llCache;
- }
- if (lonMin > lonMax) {
- llCache = lonMax;
- lonMax = lonMin;
- lonMin = llCache;
- }
-
- if (where.length() > 0) {
- where.append(" and ");
- }
- where.append("(latitude >= ");
- where.append(String.format((Locale) null, "%.6f", latMin));
- where.append(" and latitude <= ");
- where.append(String.format((Locale) null, "%.6f", latMax));
- where.append(" and longitude >= ");
- where.append(String.format((Locale) null, "%.6f", lonMin));
- where.append(" and longitude <= ");
- where.append(String.format((Locale) null, "%.6f", lonMax));
- where.append(')');
+ where = buildCoordinateWhere(centerLat, centerLon, spanLat, spanLon);
+ }
+ else
+ {
+ where = cgData.whereGeocodeIn(geocodes);
}
cursor = databaseRO.query(
dbTableCaches,
@@ -2001,6 +1978,47 @@ public class cgData {
}
/**
+ * Builds a where for coordinates
+ *
+ * @param centerLat
+ * @param centerLon
+ * @param spanLat
+ * @param spanLon
+ * @return
+ */
+
+ private static StringBuilder buildCoordinateWhere(final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon) {
+ StringBuilder where = new StringBuilder();
+ double latMin = (centerLat / 1e6) - ((spanLat / 1e6) / 2) - ((spanLat / 1e6) / 4);
+ double latMax = (centerLat / 1e6) + ((spanLat / 1e6) / 2) + ((spanLat / 1e6) / 4);
+ double lonMin = (centerLon / 1e6) - ((spanLon / 1e6) / 2) - ((spanLon / 1e6) / 4);
+ double lonMax = (centerLon / 1e6) + ((spanLon / 1e6) / 2) + ((spanLon / 1e6) / 4);
+ double llCache;
+
+ if (latMin > latMax) {
+ llCache = latMax;
+ latMax = latMin;
+ latMin = llCache;
+ }
+ if (lonMin > lonMax) {
+ llCache = lonMax;
+ lonMax = lonMin;
+ lonMin = llCache;
+ }
+
+ where.append("(latitude >= ");
+ where.append(String.format((Locale) null, "%.6f", latMin));
+ where.append(" and latitude <= ");
+ where.append(String.format((Locale) null, "%.6f", latMax));
+ where.append(" and longitude >= ");
+ where.append(String.format((Locale) null, "%.6f", lonMin));
+ where.append(" and longitude <= ");
+ where.append(String.format((Locale) null, "%.6f", lonMax));
+ where.append(')');
+ return where;
+ }
+
+ /**
* creates a Cache from the cursor. Doesn't next.
*
* @param cursor
@@ -2736,32 +2754,7 @@ public class cgData {
}
// viewport limitation
- double latMin = (centerLat / 1e6) - ((spanLat / 1e6) / 2) - ((spanLat / 1e6) / 4);
- double latMax = (centerLat / 1e6) + ((spanLat / 1e6) / 2) + ((spanLat / 1e6) / 4);
- double lonMin = (centerLon / 1e6) - ((spanLon / 1e6) / 2) - ((spanLon / 1e6) / 4);
- double lonMax = (centerLon / 1e6) + ((spanLon / 1e6) / 2) + ((spanLon / 1e6) / 4);
- double llCache;
-
- if (latMin > latMax) {
- llCache = latMax;
- latMax = latMin;
- latMin = llCache;
- }
- if (lonMin > lonMax) {
- llCache = lonMax;
- lonMax = lonMin;
- lonMin = llCache;
- }
-
- final StringBuilder where = new StringBuilder();
- where.append("latitude >= ");
- where.append(String.format((Locale) null, "%.6f", latMin));
- where.append(" and latitude <= ");
- where.append(String.format((Locale) null, "%.6f", latMax));
- where.append(" and longitude >= ");
- where.append(String.format((Locale) null, "%.6f", lonMin));
- where.append(" and longitude <= ");
- where.append(String.format((Locale) null, "%.6f", lonMax));
+ StringBuilder where = buildCoordinateWhere(centerLat, centerLon, spanLat, spanLon);
// cacheType limitation
if (cacheType != CacheType.ALL) {
@@ -3412,4 +3405,48 @@ public class cgData {
return where;
}
+ /**
+ * Loads all Waypoints in the coordinate rectangle.
+ *
+ * @param centerLat
+ * @param centerLon
+ * @param spanLat
+ * @param spanLon
+ * @return
+ */
+
+ public Collection<? extends cgWaypoint> loadWaypoints(long centerLat, long centerLon, long spanLat, long spanLon) {
+ StringBuilder where = buildCoordinateWhere(centerLat, centerLon, spanLat, spanLon);
+ init();
+
+ List<cgWaypoint> waypoints = new ArrayList<cgWaypoint>();
+
+ Cursor cursor = databaseRO.query(
+ dbTableWaypoints,
+ new String[] { "_id", "geocode", "updated", "type", "prefix", "lookup", "name", "latlon", "latitude", "longitude", "note", "own" },
+ where.toString(),
+ null,
+ null,
+ null,
+ "_id",
+ "100");
+
+ if (cursor != null && cursor.getCount() > 0) {
+ cursor.moveToFirst();
+
+ do {
+
+ cgWaypoint waypoint = createWaypointFromDatabaseContent(cursor);
+
+ waypoints.add(waypoint);
+ } while (cursor.moveToNext());
+ }
+
+ if (cursor != null) {
+ cursor.close();
+ }
+
+ return waypoints;
+ }
+
}
diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java
index bdad7f0..b43cf05 100644
--- a/main/src/cgeo/geocaching/cgeoapplication.java
+++ b/main/src/cgeo/geocaching/cgeoapplication.java
@@ -21,6 +21,7 @@ import android.os.Message;
import java.io.File;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Date;
import java.util.EnumSet;
import java.util.HashSet;
@@ -525,4 +526,8 @@ public class cgeoapplication extends Application {
storage.removeCaches(geocodes, removeFlags);
}
+ public Collection<? extends cgWaypoint> getWaypointsInViewport(long centerLat, long centerLon, long spanLat, long spanLon) {
+ return storage.loadWaypoints(centerLat, centerLon, spanLat, spanLon);
+ }
+
}
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index 57bc4bd..09aeabd 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -172,6 +172,8 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
private int cachesCnt = 0;
/** List of caches in the viewport */
private final LeastRecentlyUsedSet<cgCache> caches = new LeastRecentlyUsedSet<cgCache>(MAX_CACHES);
+ /** List of waypoints in the viewport */
+ private final LeastRecentlyUsedSet<cgWaypoint> waypoints = new LeastRecentlyUsedSet<cgWaypoint>(MAX_CACHES);
// storing for offline
private ProgressDialog waitDialog = null;
private int detailTotal = 0;
@@ -1148,7 +1150,8 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
if (search != null) {
downloaded = true;
- caches.addAll(search.getCachesFromSearchResult(LoadFlags.LOAD_WAYPOINTS));
+ caches.addAll(search.getCachesFromSearchResult(LoadFlags.LOAD_CACHE_ONLY));
+ waypoints.addAll(app.getWaypointsInViewport(centerLat, centerLon, spanLat, spanLon));
}
if (live) {
@@ -1254,28 +1257,27 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
// display caches
final List<cgCache> cachesToDisplay = new ArrayList<cgCache>(caches);
+ final List<cgWaypoint> waypointsToDisplay = new ArrayList<cgWaypoint>(waypoints);
final List<CachesOverlayItemImpl> itemsToDisplay = new ArrayList<CachesOverlayItemImpl>();
if (!cachesToDisplay.isEmpty()) {
+ // Only show waypoints for single view or setting
+ // when less than showWaypointsthreshold Caches shown
+ if (cachesToDisplay.size() == 1 || (cachesCnt < Settings.getWayPointsThreshold())) {
+ for (cgWaypoint waypoint : waypointsToDisplay) {
+
+ if (waypoint.getCoords() == null) {
+ continue;
+ }
+
+ itemsToDisplay.add(getItem(waypoint, null, waypoint));
+ }
+ }
for (cgCache cache : cachesToDisplay) {
if (cache.getCoords() == null) {
continue;
}
-
- // display cache waypoints
- if (cache.hasWaypoints()
- // Only show waypoints for single view or setting
- // when less than showWaypointsthreshold Caches shown
- && (cachesToDisplay.size() == 1 || (cachesToDisplay.size() < Settings.getWayPointsThreshold()))) {
- for (cgWaypoint waypoint : cache.getWaypoints()) {
- if (waypoint.getCoords() == null) {
- continue;
- }
-
- itemsToDisplay.add(getItem(waypoint, null, waypoint));
- }
- }
itemsToDisplay.add(getItem(cache, cache, null));
}