aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/maps/CGeoMap.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/maps/CGeoMap.java')
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java444
1 files changed, 221 insertions, 223 deletions
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index e48ca70..4b8d1a0 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -1,15 +1,14 @@
package cgeo.geocaching.maps;
import cgeo.geocaching.DirectionProvider;
+import cgeo.geocaching.Geocache;
import cgeo.geocaching.IGeoData;
-import cgeo.geocaching.IWaypoint;
-import cgeo.geocaching.LiveMapInfo;
import cgeo.geocaching.R;
import cgeo.geocaching.SearchResult;
import cgeo.geocaching.Settings;
import cgeo.geocaching.StoredList;
-import cgeo.geocaching.cgCache;
-import cgeo.geocaching.cgWaypoint;
+import cgeo.geocaching.Waypoint;
+import cgeo.geocaching.cgData;
import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.cgeocaches;
import cgeo.geocaching.activity.ActivityMixin;
@@ -31,11 +30,13 @@ import cgeo.geocaching.maps.interfaces.MapProvider;
import cgeo.geocaching.maps.interfaces.MapSource;
import cgeo.geocaching.maps.interfaces.MapViewImpl;
import cgeo.geocaching.maps.interfaces.OnMapDragListener;
+import cgeo.geocaching.ui.dialog.LiveMapInfoDialogBuilder;
import cgeo.geocaching.utils.AngleUtils;
import cgeo.geocaching.utils.CancellableHandler;
import cgeo.geocaching.utils.GeoDirHandler;
import cgeo.geocaching.utils.LeastRecentlyUsedSet;
import cgeo.geocaching.utils.Log;
+import cgeo.geocaching.utils.RunnableWithArgument;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@@ -84,7 +85,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
/** max. number of caches displayed in the Live Map */
public static final int MAX_CACHES = 500;
- /**Controls the behaviour of the map*/
+ /** Controls the behaviour of the map */
public enum MapMode {
/** Live Map */
LIVE,
@@ -95,6 +96,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
/** Map with a list of caches (no reload on move) */
LIST
}
+
/** Handler Messages */
private static final int HIDE_PROGRESS = 0;
private static final int SHOW_PROGRESS = 1;
@@ -177,9 +179,9 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
/** Count of caches currently visible */
private int cachesCnt = 0;
/** List of caches in the viewport */
- private LeastRecentlyUsedSet<cgCache> caches = null;
+ private LeastRecentlyUsedSet<Geocache> caches = null;
/** List of waypoints in the viewport */
- private final LeastRecentlyUsedSet<cgWaypoint> waypoints = new LeastRecentlyUsedSet<cgWaypoint>(MAX_CACHES);
+ private final LeastRecentlyUsedSet<Waypoint> waypoints = new LeastRecentlyUsedSet<Waypoint>(MAX_CACHES);
// storing for offline
private ProgressDialog waitDialog = null;
private int detailTotal = 0;
@@ -188,7 +190,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
// views
private ImageSwitcher myLocSwitch = null;
- /**Controls the map behaviour*/
+ /** Controls the map behaviour */
private MapMode mapMode = null;
/** Live mode enabled for map. **/
private boolean isLiveEnabled;
@@ -226,7 +228,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
countVisibleCaches();
- if (caches != null && caches.size() > 0 && !mapTitle.contains("[")) {
+ if (caches != null && !caches.isEmpty() && !mapTitle.contains("[")) {
title.append(" [").append(cachesCnt);
if (cachesCnt != caches.size()) {
title.append('/').append(caches.size());
@@ -288,7 +290,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
waitDialog.setMessage(res.getString(R.string.caches_downloading) + " " + res.getString(R.string.caches_eta_ltm));
} else {
int minsRemaining = secondsRemaining / 60;
- waitDialog.setMessage(res.getString(R.string.caches_downloading) + " " + minsRemaining + " " + res.getQuantityString(R.plurals.caches_eta_mins,minsRemaining));
+ waitDialog.setMessage(res.getString(R.string.caches_downloading) + " " + minsRemaining + " " + res.getQuantityString(R.plurals.caches_eta_mins, minsRemaining));
}
}
} else if (msg.what == FINISHED_LOADING_DETAILS) {
@@ -335,13 +337,13 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
protected void countVisibleCaches() {
- final List<cgCache> protectedCaches = caches.getAsList();
+ final List<Geocache> protectedCaches = caches.getAsList();
int count = 0;
- if (protectedCaches.size() > 0) {
+ if (!protectedCaches.isEmpty()) {
final Viewport viewport = mapView.getViewport();
- for (final cgCache cache : protectedCaches) {
+ for (final Geocache cache : protectedCaches) {
if (cache != null && cache.getCoords() != null) {
if (viewport.contains(cache)) {
count++;
@@ -368,8 +370,8 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
activity = this.getActivity();
app = (cgeoapplication) activity.getApplication();
- int countBubbleCnt = app.getAllStoredCachesCount(true, CacheType.ALL);
- caches = new LeastRecentlyUsedSet<cgCache>(MAX_CACHES + countBubbleCnt);
+ int countBubbleCnt = cgData.getAllCachesCount();
+ caches = new LeastRecentlyUsedSet<Geocache>(MAX_CACHES + countBubbleCnt);
final MapProvider mapProvider = Settings.getMapProvider();
mapItemFactory = mapProvider.getMapItemFactory();
@@ -469,9 +471,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
prepareFilterBar();
if (!app.isLiveMapHintShown() && !Settings.getHideLiveMapHint()) {
- Intent hintIntent = new Intent(activity, LiveMapInfo.class);
- activity.startActivity(hintIntent);
- app.setLiveMapHintShown();
+ LiveMapInfoDialogBuilder.create(activity).show();
}
}
@@ -494,10 +494,11 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
if (!CollectionUtils.isEmpty(dirtyCaches)) {
for (String geocode : dirtyCaches) {
- cgCache cache = app.loadCache(geocode, LoadFlags.LOAD_WAYPOINTS);
+ Geocache cache = cgData.loadCache(geocode, LoadFlags.LOAD_WAYPOINTS);
if (cache != null) {
- // remove to update the cache
+ // new collection type needs to remove first
caches.remove(cache);
+ // re-add to update the freshness
caches.add(cache);
}
}
@@ -579,9 +580,8 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
}
- MenuItem item;
try {
- item = menu.findItem(MENU_TRAIL_MODE); // show trail
+ MenuItem item = menu.findItem(MENU_TRAIL_MODE);
if (Settings.isMapTrail()) {
item.setTitle(res.getString(R.string.map_trail_hide));
} else {
@@ -596,7 +596,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
final Set<String> geocodesInViewport = getGeocodesForCachesInViewport();
- menu.findItem(MENU_STORE_CACHES).setEnabled(!isLoading() && CollectionUtils.isNotEmpty(geocodesInViewport) && app.hasUnsavedCaches(new SearchResult(geocodesInViewport)));
+ menu.findItem(MENU_STORE_CACHES).setEnabled(!isLoading() && CollectionUtils.isNotEmpty(geocodesInViewport) && new SearchResult(geocodesInViewport).hasUnsavedCaches());
item = menu.findItem(MENU_CIRCLE_MODE); // show circles
if (overlayCaches != null && overlayCaches.getCircles()) {
@@ -612,7 +612,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
menu.findItem(SUBMENU_STRATEGY).setEnabled(isLiveEnabled);
} catch (Exception e) {
- Log.e("cgeomap.onPrepareOptionsMenu: " + e);
+ Log.e("cgeomap.onPrepareOptionsMenu", e);
}
return true;
@@ -642,7 +642,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
final List<String> geocodes = new ArrayList<String>();
for (final String geocode : geocodesInViewport) {
- if (!app.isOffline(geocode, null)) {
+ if (!cgData.isOffline(geocode, null)) {
geocodes.add(geocode);
}
}
@@ -656,42 +656,18 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
return true;
}
- final LoadDetailsHandler loadDetailsHandler = new LoadDetailsHandler();
-
- waitDialog = new ProgressDialog(activity);
- waitDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
- waitDialog.setCancelable(true);
- waitDialog.setCancelMessage(loadDetailsHandler.cancelMessage());
- waitDialog.setMax(detailTotal);
- waitDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
-
- @Override
- public void onCancel(DialogInterface arg0) {
- try {
- if (loadDetailsThread != null) {
- loadDetailsThread.stopIt();
- }
-
- geoDirUpdate.startDir();
- } catch (Exception e) {
- Log.e("cgeocaches.onPrepareOptionsMenu.onCancel: " + e.toString());
- }
- }
- });
-
- float etaTime = detailTotal * 7.0f / 60.0f;
- int roundedEta = Math.round(etaTime);
- if (etaTime < 0.4) {
- waitDialog.setMessage(res.getString(R.string.caches_downloading) + " " + res.getString(R.string.caches_eta_ltm));
- } else {
- waitDialog.setMessage(res.getString(R.string.caches_downloading) + " " + roundedEta + " " + res.getQuantityString(R.plurals.caches_eta_mins, roundedEta));
+ if (Settings.getChooseList()) {
+ // let user select list to store cache in
+ new StoredList.UserInterface(activity).promptForListSelection(R.string.list_title,
+ new RunnableWithArgument<Integer>() {
+ @Override
+ public void run(final Integer selectedListId) {
+ storeCaches(geocodes, selectedListId);
+ }
+ }, true, StoredList.TEMPORARY_LIST_ID);
+ } else {
+ storeCaches(geocodes, StoredList.STANDARD_LIST_ID);
}
- waitDialog.show();
-
- detailProgressTime = System.currentTimeMillis();
-
- loadDetailsThread = new LoadDetails(loadDetailsHandler, geocodes);
- loadDetailsThread.start();
}
return true;
case MENU_CIRCLE_MODE:
@@ -752,9 +728,9 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
currentTheme = currentThemeFile.getName();
}
- int currentItem = 0;
List<String> names = new ArrayList<String>();
names.add(res.getString(R.string.map_theme_builtin));
+ int currentItem = 0;
for (File file : themeFiles) {
if (currentTheme.equalsIgnoreCase(file.getName())) {
currentItem = names.size();
@@ -768,7 +744,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
builder.setTitle(R.string.map_theme_select);
- builder.setSingleChoiceItems(names.toArray(new String[] {}), selectedItem,
+ builder.setSingleChoiceItems(names.toArray(new String[names.size()]), selectedItem,
new DialogInterface.OnClickListener() {
@Override
@@ -792,15 +768,15 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
/**
- * @return a Set of geocodes corresponding to the caches that are shown on screen.
+ * @return a non-null Set of geocodes corresponding to the caches that are shown on screen.
*/
private Set<String> getGeocodesForCachesInViewport() {
final Set<String> geocodes = new HashSet<String>();
- final List<cgCache> cachesProtected = caches.getAsList();
+ final List<Geocache> cachesProtected = caches.getAsList();
final Viewport viewport = mapView.getViewport();
- for (final cgCache cache : cachesProtected) {
+ for (final Geocache cache : cachesProtected) {
if (viewport.contains(cache)) {
geocodes.add(cache.getGeocode());
}
@@ -1053,22 +1029,11 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
// check if map moved or zoomed
//TODO Portree Use Rectangle inside with bigger search window. That will stop reloading on every move
- boolean moved = false;
-
- if (liveChanged) {
- moved = true;
- } else if (isLiveEnabled && !downloaded) {
- moved = true;
- } else if (viewport == null) {
- moved = true;
- } else if (zoomNow != zoom) {
- moved = true;
- } else if (mapMoved(viewport, viewportNow) && (cachesCnt <= 0 || CollectionUtils.isEmpty(caches) || !viewport.includes(viewportNow))) {
- moved = true;
- }
+ final boolean moved = liveChanged || (isLiveEnabled && !downloaded) || (viewport == null) || zoomNow != zoom ||
+ (mapMoved(viewport, viewportNow) && (cachesCnt <= 0 || CollectionUtils.isEmpty(caches) || !viewport.includes(viewportNow)));
// update title on any change
- if (moved || zoomNow != zoom || !viewportNow.equals(viewport)) {
+ if (moved || !viewportNow.equals(viewport)) {
displayHandler.sendEmptyMessage(UPDATE_TITLE);
}
zoom = zoomNow;
@@ -1088,7 +1053,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
yield();
} catch (Exception e) {
- Log.w("cgeomap.LoadTimer.run: " + e.toString());
+ Log.w("cgeomap.LoadTimer.run", e);
}
}
}
@@ -1120,59 +1085,60 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
SearchResult searchResult;
if (mapMode == MapMode.LIVE) {
- if (isLiveEnabled) {
- searchResult = new SearchResult();
- } else {
- searchResult = new SearchResult(app.getStoredInViewport(viewport, Settings.getCacheType()));
- }
+ searchResult = isLiveEnabled ? new SearchResult() : new SearchResult(cgData.loadStoredInViewport(viewport, Settings.getCacheType()));
} else {
// map started from another activity
- searchResult = new SearchResult(searchIntent);
+ searchResult = searchIntent != null ? new SearchResult(searchIntent) : new SearchResult();
if (geocodeIntent != null) {
searchResult.addGeocode(geocodeIntent);
}
}
// live mode search result
if (isLiveEnabled) {
- SearchResult liveResult = new SearchResult(app.getCachedInViewport(viewport, Settings.getCacheType()));
+ SearchResult liveResult = new SearchResult(cgData.loadCachedInViewport(viewport, Settings.getCacheType()));
searchResult.addGeocodes(liveResult.getGeocodes());
}
downloaded = true;
- Set<cgCache> cachesFromSearchResult = searchResult.getCachesFromSearchResult(LoadFlags.LOAD_WAYPOINTS);
- // to update the caches they have to be removed first
+ Set<Geocache> cachesFromSearchResult = searchResult.getCachesFromSearchResult(LoadFlags.LOAD_WAYPOINTS);
+ // update the caches
+ // new collection type needs to remove first
caches.removeAll(cachesFromSearchResult);
caches.addAll(cachesFromSearchResult);
+ final boolean excludeMine = Settings.isExcludeMyCaches();
+ final boolean excludeDisabled = Settings.isExcludeDisabledCaches();
if (mapMode == MapMode.LIVE) {
- final boolean excludeMine = Settings.isExcludeMyCaches();
- final boolean excludeDisabled = Settings.isExcludeDisabledCaches();
-
- final List<cgCache> tempList = caches.getAsList();
+ final List<Geocache> tempList = caches.getAsList();
- for (cgCache cache : tempList) {
- if ((cache.isFound() && excludeMine) || (cache.isOwn() && excludeMine) || (cache.isDisabled() && excludeDisabled)) {
+ for (Geocache cache : tempList) {
+ if ((cache.isFound() && excludeMine) || (cache.isOwner() && excludeMine) || (cache.isDisabled() && excludeDisabled)) {
caches.remove(cache);
}
}
}
countVisibleCaches();
if (cachesCnt < Settings.getWayPointsThreshold() || geocodeIntent != null) {
+ // we don't want to see any stale waypoints
waypoints.clear();
- if (isLiveEnabled || mapMode == MapMode.COORDS) {
+ if (isLiveEnabled || mapMode == MapMode.LIVE
+ || mapMode == MapMode.COORDS) {
//All visible waypoints
CacheType type = Settings.getCacheType();
- Set<cgWaypoint> waypointsInViewport = app.getWaypointsInViewport(viewport, Settings.isExcludeMyCaches(), Settings.isExcludeDisabledCaches(), type);
+ Set<Waypoint> waypointsInViewport = cgData.loadWaypoints(viewport, excludeMine, excludeDisabled, type);
waypoints.addAll(waypointsInViewport);
}
- else
- {
+ else {
//All waypoints from the viewed caches
- for (cgCache c : caches.getAsList()) {
+ for (Geocache c : caches.getAsList()) {
waypoints.addAll(c.getWaypoints());
}
}
}
+ else {
+ // we don't want to see any stale waypoints when above threshold
+ waypoints.clear();
+ }
//render
displayExecutor.execute(new DisplayRunnable(viewport));
@@ -1229,8 +1195,9 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
} while (count < 2);
if (searchResult != null) {
- Set<cgCache> result = searchResult.getCachesFromSearchResult(LoadFlags.LOAD_CACHE_OR_DB);
- // to update the caches they have to be removed first
+ Set<Geocache> result = searchResult.getCachesFromSearchResult(LoadFlags.LOAD_CACHE_OR_DB);
+ // update the caches
+ // new collection type needs to remove first
caches.removeAll(result);
caches.addAll(result);
lastSearchResult = searchResult;
@@ -1266,29 +1233,29 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
// display caches
- final List<cgCache> cachesToDisplay = caches.getAsList();
- final List<cgWaypoint> waypointsToDisplay = new ArrayList<cgWaypoint>(waypoints);
+ final List<Geocache> cachesToDisplay = caches.getAsList();
+ final List<Waypoint> waypointsToDisplay = new ArrayList<Waypoint>(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 (mapMode == MapMode.SINGLE || (cachesCnt < Settings.getWayPointsThreshold())) {
- for (cgWaypoint waypoint : waypointsToDisplay) {
+ for (Waypoint waypoint : waypointsToDisplay) {
if (waypoint == null || waypoint.getCoords() == null) {
continue;
}
- itemsToDisplay.add(getItem(waypoint, null, waypoint));
+ itemsToDisplay.add(getWaypointItem(waypoint));
}
}
- for (cgCache cache : cachesToDisplay) {
+ for (Geocache cache : cachesToDisplay) {
if (cache == null || cache.getCoords() == null) {
continue;
}
- itemsToDisplay.add(getItem(cache, cache, null));
+ itemsToDisplay.add(getCacheItem(cache));
}
overlayCaches.updateItems(itemsToDisplay);
@@ -1309,7 +1276,6 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
}
-
/**
* Thread to display one point. Started on opening if in single mode.
*/
@@ -1322,10 +1288,10 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
if (coordsIntent != null) {
- final cgWaypoint waypoint = new cgWaypoint("some place", waypointTypeIntent != null ? waypointTypeIntent : WaypointType.WAYPOINT, false);
+ final Waypoint waypoint = new Waypoint("some place", waypointTypeIntent != null ? waypointTypeIntent : WaypointType.WAYPOINT, false);
waypoint.setCoords(coordsIntent);
- final CachesOverlayItemImpl item = getItem(waypoint, null, waypoint);
+ final CachesOverlayItemImpl item = getWaypointItem(waypoint);
overlayCaches.updateItems(item);
displayHandler.sendEmptyMessage(INVALIDATE_MAP);
@@ -1342,7 +1308,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
final protected Viewport viewport;
- public DoRunnable(final Viewport viewport) {
+ protected DoRunnable(final Viewport viewport) {
this.viewport = viewport;
}
@@ -1364,6 +1330,51 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
/**
+ * store caches, invoked by "store offline" menu item
+ *
+ * @param listId
+ * the list to store the caches in
+ */
+ private void storeCaches(List<String> geocodes, int listId) {
+ final LoadDetailsHandler loadDetailsHandler = new LoadDetailsHandler();
+
+ waitDialog = new ProgressDialog(activity);
+ waitDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
+ waitDialog.setCancelable(true);
+ waitDialog.setCancelMessage(loadDetailsHandler.cancelMessage());
+ waitDialog.setMax(detailTotal);
+ waitDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
+
+ @Override
+ public void onCancel(DialogInterface arg0) {
+ try {
+ if (loadDetailsThread != null) {
+ loadDetailsThread.stopIt();
+ }
+
+ geoDirUpdate.startDir();
+ } catch (Exception e) {
+ Log.e("cgeocaches.onPrepareOptionsMenu.onCancel", e);
+ }
+ }
+ });
+
+ float etaTime = detailTotal * 7.0f / 60.0f;
+ int roundedEta = Math.round(etaTime);
+ if (etaTime < 0.4) {
+ waitDialog.setMessage(res.getString(R.string.caches_downloading) + " " + res.getString(R.string.caches_eta_ltm));
+ } else {
+ waitDialog.setMessage(res.getString(R.string.caches_downloading) + " " + roundedEta + " " + res.getQuantityString(R.plurals.caches_eta_mins, roundedEta));
+ }
+ waitDialog.show();
+
+ detailProgressTime = System.currentTimeMillis();
+
+ loadDetailsThread = new LoadDetails(loadDetailsHandler, geocodes, listId);
+ loadDetailsThread.start();
+ }
+
+ /**
* Thread to store the caches in the viewport. Started by Activity.
*/
@@ -1371,11 +1382,13 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
final private CancellableHandler handler;
final private List<String> geocodes;
+ final private int listId;
private long last = 0L;
- public LoadDetails(final CancellableHandler handler, final List<String> geocodes) {
+ public LoadDetails(final CancellableHandler handler, final List<String> geocodes, final int listId) {
this.handler = handler;
this.geocodes = geocodes;
+ this.listId = listId;
}
public void stopIt() {
@@ -1396,7 +1409,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
break;
}
- if (!app.isOffline(geocode, null)) {
+ if (!cgData.isOffline(geocode, null)) {
if ((System.currentTimeMillis() - last) < 1500) {
try {
int delay = 1000 + (int) (Math.random() * 1000.0) - (int) (System.currentTimeMillis() - last);
@@ -1416,10 +1429,10 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
break;
}
- cgCache.storeCache(null, geocode, StoredList.STANDARD_LIST_ID, false, handler);
+ Geocache.storeCache(null, geocode, listId, false, handler);
}
} catch (Exception e) {
- Log.e("cgeocaches.LoadDetails.run: " + e.toString());
+ Log.e("cgeocaches.LoadDetails.run", e);
} finally {
// one more cache over
detailProgress++;
@@ -1486,9 +1499,9 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
Viewport viewport = null;
if (geocodeCenter != null) {
- viewport = app.getBounds(geocodeCenter);
+ viewport = cgData.getBounds(geocodeCenter);
} else if (searchCenter != null) {
- viewport = app.getBounds(searchCenter.getGeocodes());
+ viewport = cgData.getBounds(searchCenter.getGeocodes());
}
if (viewport == null) {
@@ -1621,116 +1634,101 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
dirtyCaches.add(geocode);
}
- /**
- * Returns a OverlayItem represented by an icon
- *
- * @param coord
- * The coords
- * @param cache
- * Cache
- * @param waypoint
- * Waypoint. Mutally exclusive with cache
- * @return
- */
- private CachesOverlayItemImpl getItem(final IWaypoint coord, final cgCache cache, final cgWaypoint waypoint) {
- if (cache != null) {
- final CachesOverlayItemImpl item = mapItemFactory.getCachesOverlayItem(coord, cache.getType());
-
- final int hashcode = new HashCodeBuilder()
- .append(cache.isReliableLatLon())
- .append(cache.getType().id)
- .append(cache.isDisabled() || cache.isArchived())
- .append(cache.isOwn())
- .append(cache.isFound())
- .append(cache.hasUserModifiedCoords())
- .append(cache.getPersonalNote())
- .append(cache.isLogOffline())
- .append(cache.getListId() > 0)
- .toHashCode();
-
- final LayerDrawable ldFromCache = overlaysCache.get(hashcode);
- if (ldFromCache != null) {
- item.setMarker(ldFromCache);
- return item;
- }
-
- // Set initial capacities to the maximum of layers and insets to avoid dynamic reallocation
- final ArrayList<Drawable> layers = new ArrayList<Drawable>(9);
- final ArrayList<int[]> insets = new ArrayList<int[]>(8);
-
- // background: disabled or not
- final Drawable marker = getResources().getDrawable(cache.isDisabled() || cache.isArchived() ? R.drawable.marker_disabled : R.drawable.marker);
- layers.add(marker);
- final int resolution = marker.getIntrinsicWidth() > 40 ? 1 : 0;
- // reliable or not
- if (!cache.isReliableLatLon()) {
- insets.add(INSET_RELIABLE[resolution]);
- layers.add(getResources().getDrawable(R.drawable.marker_notreliable));
- }
- // cache type
- layers.add(getResources().getDrawable(cache.getType().markerId));
- insets.add(INSET_TYPE[resolution]);
- // own
- if (cache.isOwn()) {
- layers.add(getResources().getDrawable(R.drawable.marker_own));
- insets.add(INSET_OWN[resolution]);
- // if not, checked if stored
- } else if (cache.getListId() > 0) {
- layers.add(getResources().getDrawable(R.drawable.marker_stored));
- insets.add(INSET_OWN[resolution]);
- }
- // found
- if (cache.isFound()) {
- layers.add(getResources().getDrawable(R.drawable.marker_found));
- insets.add(INSET_FOUND[resolution]);
- // if not, perhaps logged offline
- } else if (cache.isLogOffline()) {
- layers.add(getResources().getDrawable(R.drawable.marker_found_offline));
- insets.add(INSET_FOUND[resolution]);
- }
- // user modified coords
- if (cache.hasUserModifiedCoords()) {
- layers.add(getResources().getDrawable(R.drawable.marker_usermodifiedcoords));
- insets.add(INSET_USERMODIFIEDCOORDS[resolution]);
- }
- // personal note
- if (cache.getPersonalNote() != null) {
- layers.add(getResources().getDrawable(R.drawable.marker_personalnote));
- insets.add(INSET_PERSONALNOTE[resolution]);
- }
-
- final LayerDrawable ld = new LayerDrawable(layers.toArray(new Drawable[layers.size()]));
-
- int index = 1;
- for (final int[] inset : insets) {
- ld.setLayerInset(index++, inset[0], inset[1], inset[2], inset[3]);
- }
-
- overlaysCache.put(hashcode, ld);
-
- item.setMarker(ld);
+ private CachesOverlayItemImpl getCacheItem(final Geocache cache) {
+ final CachesOverlayItemImpl item = mapItemFactory.getCachesOverlayItem(cache, cache.getType());
+
+ final int hashcode = new HashCodeBuilder()
+ .append(cache.isReliableLatLon())
+ .append(cache.getType().id)
+ .append(cache.isDisabled() || cache.isArchived())
+ .append(cache.getCacheRealm().id)
+ .append(cache.isOwner())
+ .append(cache.isFound())
+ .append(cache.hasUserModifiedCoords())
+ .append(cache.getPersonalNote())
+ .append(cache.isLogOffline())
+ .append(cache.getListId() > 0)
+ .toHashCode();
+
+ final LayerDrawable ldFromCache = overlaysCache.get(hashcode);
+ if (ldFromCache != null) {
+ item.setMarker(ldFromCache);
return item;
}
- if (waypoint != null) {
-
- final CachesOverlayItemImpl item = mapItemFactory.getCachesOverlayItem(coord, null);
- Drawable[] layers = new Drawable[2];
- layers[0] = getResources().getDrawable(R.drawable.marker);
- layers[1] = getResources().getDrawable(waypoint.getWaypointType().markerId);
+ // Set initial capacities to the maximum of layers and insets to avoid dynamic reallocation
+ final ArrayList<Drawable> layers = new ArrayList<Drawable>(9);
+ final ArrayList<int[]> insets = new ArrayList<int[]>(8);
+
+ // background: disabled or not
+ final Drawable marker = getResources().getDrawable(cache.isDisabled() || cache.isArchived() ? cache.getCacheRealm().markerDisabledId : cache.getCacheRealm().markerId);
+ layers.add(marker);
+ final int resolution = marker.getIntrinsicWidth() > 40 ? 1 : 0;
+ // reliable or not
+ if (!cache.isReliableLatLon()) {
+ insets.add(INSET_RELIABLE[resolution]);
+ layers.add(getResources().getDrawable(R.drawable.marker_notreliable));
+ }
+ // cache type
+ layers.add(getResources().getDrawable(cache.getType().markerId));
+ insets.add(INSET_TYPE[resolution]);
+ // own
+ if (cache.isOwner()) {
+ layers.add(getResources().getDrawable(R.drawable.marker_own));
+ insets.add(INSET_OWN[resolution]);
+ // if not, checked if stored
+ } else if (cache.getListId() > 0) {
+ layers.add(getResources().getDrawable(R.drawable.marker_stored));
+ insets.add(INSET_OWN[resolution]);
+ }
+ // found
+ if (cache.isFound()) {
+ layers.add(getResources().getDrawable(R.drawable.marker_found));
+ insets.add(INSET_FOUND[resolution]);
+ // if not, perhaps logged offline
+ } else if (cache.isLogOffline()) {
+ layers.add(getResources().getDrawable(R.drawable.marker_found_offline));
+ insets.add(INSET_FOUND[resolution]);
+ }
+ // user modified coords
+ if (cache.hasUserModifiedCoords()) {
+ layers.add(getResources().getDrawable(R.drawable.marker_usermodifiedcoords));
+ insets.add(INSET_USERMODIFIEDCOORDS[resolution]);
+ }
+ // personal note
+ if (cache.getPersonalNote() != null) {
+ layers.add(getResources().getDrawable(R.drawable.marker_personalnote));
+ insets.add(INSET_PERSONALNOTE[resolution]);
+ }
+
+ final LayerDrawable ld = new LayerDrawable(layers.toArray(new Drawable[layers.size()]));
+
+ int index = 1;
+ for (final int[] inset : insets) {
+ ld.setLayerInset(index++, inset[0], inset[1], inset[2], inset[3]);
+ }
+
+ overlaysCache.put(hashcode, ld);
+
+ item.setMarker(ld);
+ return item;
+ }
- LayerDrawable ld = new LayerDrawable(layers);
- if (layers[0].getIntrinsicWidth() > 40) {
- ld.setLayerInset(1, 9, 12, 10, 13);
- } else {
- ld.setLayerInset(1, 9, 12, 8, 12);
- }
- item.setMarker(ld);
- return item;
+ private CachesOverlayItemImpl getWaypointItem(final Waypoint waypoint) {
+ final CachesOverlayItemImpl item = mapItemFactory.getCachesOverlayItem(waypoint, null);
+ Drawable marker = getResources().getDrawable(!waypoint.isVisited() ? R.drawable.marker : R.drawable.marker_transparent);
+ final Drawable[] layers = new Drawable[] {
+ marker,
+ getResources().getDrawable(waypoint.getWaypointType().markerId)
+ };
+ final LayerDrawable ld = new LayerDrawable(layers);
+ if (layers[0].getIntrinsicWidth() > 40) {
+ ld.setLayerInset(1, 9, 12, 10, 13);
+ } else {
+ ld.setLayerInset(1, 9, 12, 8, 12);
}
-
- return null;
-
+ item.setMarker(ld);
+ return item;
}
}