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.java165
1 files changed, 58 insertions, 107 deletions
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index 9bbf7af..bc9ba2f 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -6,6 +6,7 @@ import cgeo.geocaching.CacheListActivity;
import cgeo.geocaching.CgeoApplication;
import cgeo.geocaching.DataStore;
import cgeo.geocaching.Geocache;
+import cgeo.geocaching.Intents;
import cgeo.geocaching.R;
import cgeo.geocaching.SearchResult;
import cgeo.geocaching.Waypoint;
@@ -31,7 +32,6 @@ 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.sensors.DirectionProvider;
import cgeo.geocaching.sensors.GeoDirHandler;
import cgeo.geocaching.sensors.IGeoData;
import cgeo.geocaching.settings.Settings;
@@ -123,16 +123,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
private static final int UPDATE_PROGRESS = 0;
private static final int FINISHED_LOADING_DETAILS = 1;
- //Menu
- private static final String EXTRAS_GEOCODE = "geocode";
- private static final String EXTRAS_COORDS = "coords";
- private static final String EXTRAS_WPTTYPE = "wpttype";
- private static final String EXTRAS_MAPSTATE = "mapstate";
- private static final String EXTRAS_SEARCH = "search";
- private static final String EXTRAS_MAP_TITLE = "mapTitle";
- private static final String EXTRAS_MAP_MODE = "mapMode";
- private static final String EXTRAS_LIVE_ENABLED = "liveEnabled";
-
private static final String BUNDLE_MAP_SOURCE = "mapSource";
private static final String BUNDLE_MAP_STATE = "mapState";
private static final String BUNDLE_LIVE_ENABLED = "liveEnabled";
@@ -202,7 +192,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
private static BlockingQueue<Runnable> downloadQueue = new ArrayBlockingQueue<>(1);
private static ThreadPoolExecutor downloadExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, downloadQueue, new ThreadPoolExecutor.DiscardOldestPolicy());
private static BlockingQueue<Runnable> loadQueue = new ArrayBlockingQueue<>(1);
-
private static ThreadPoolExecutor loadExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, loadQueue, new ThreadPoolExecutor.DiscardOldestPolicy());
// handlers
/** Updates the titles */
@@ -236,7 +225,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
map.countVisibleCaches();
if (!map.caches.isEmpty() && !map.mapTitle.contains("[")) {
title.append(" [").append(map.cachesCnt);
- if (map.cachesCnt != map.caches.size()) {
+ if (map.cachesCnt != map.caches.size() && Settings.isDebug()) {
title.append('/').append(map.caches.size());
}
title.append(']');
@@ -371,21 +360,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
}
protected void countVisibleCaches() {
- final List<Geocache> protectedCaches = caches.getAsList();
-
- int count = 0;
- if (!protectedCaches.isEmpty()) {
- final Viewport viewport = mapView.getViewport();
-
- for (final Geocache cache : protectedCaches) {
- if (cache != null && cache.getCoords() != null) {
- if (viewport.contains(cache)) {
- count++;
- }
- }
- }
- }
- cachesCnt = count;
+ cachesCnt = mapView.getViewport().count(caches.getAsList());
}
@Override
@@ -415,14 +390,14 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
// Get parameters from the intent
final Bundle extras = activity.getIntent().getExtras();
if (extras != null) {
- mapMode = (MapMode) extras.get(EXTRAS_MAP_MODE);
- isLiveEnabled = extras.getBoolean(EXTRAS_LIVE_ENABLED, false);
- searchIntent = extras.getParcelable(EXTRAS_SEARCH);
- geocodeIntent = extras.getString(EXTRAS_GEOCODE);
- coordsIntent = extras.getParcelable(EXTRAS_COORDS);
- waypointTypeIntent = WaypointType.findById(extras.getString(EXTRAS_WPTTYPE));
- mapStateIntent = extras.getIntArray(EXTRAS_MAPSTATE);
- mapTitle = extras.getString(EXTRAS_MAP_TITLE);
+ mapMode = (MapMode) extras.get(Intents.EXTRA_MAP_MODE);
+ isLiveEnabled = extras.getBoolean(Intents.EXTRA_LIVE_ENABLED, false);
+ searchIntent = extras.getParcelable(Intents.EXTRA_SEARCH);
+ geocodeIntent = extras.getString(Intents.EXTRA_GEOCODE);
+ coordsIntent = extras.getParcelable(Intents.EXTRA_COORDS);
+ waypointTypeIntent = WaypointType.findById(extras.getString(Intents.EXTRA_WPTTYPE));
+ mapStateIntent = extras.getIntArray(Intents.EXTRA_MAPSTATE);
+ mapTitle = extras.getString(Intents.EXTRA_MAP_TITLE);
}
else {
mapMode = MapMode.LIVE;
@@ -482,7 +457,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
mapView.repaintRequired(null);
- setZoom(Settings.getMapZoom());
+ setZoom(Settings.getMapZoom(mapMode));
mapView.getMapController().setCenter(Settings.getMapCenter());
if (null == mapStateIntent) {
@@ -504,7 +479,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
}
prepareFilterBar();
- if (!app.isLiveMapHintShownInThisSession() && !Settings.getHideLiveMapHint() && Settings.getLiveMapHintShowCount() <= 3) {
+ if (!app.isLiveMapHintShownInThisSession() && Settings.getLiveMapHintShowCount() <= 3) {
LiveMapInfoDialogBuilder.create(activity).show();
}
}
@@ -714,7 +689,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
public void call(final Integer selectedListId) {
storeCaches(geocodes, selectedListId);
}
- }, true, StoredList.TEMPORARY_LIST_ID);
+ }, true, StoredList.TEMPORARY_LIST.id);
} else {
storeCaches(geocodes, StoredList.STANDARD_LIST_ID);
}
@@ -870,19 +845,19 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
// prepare information to restart a similar view
final Intent mapIntent = new Intent(activity, Settings.getMapProvider().getMapClass());
- mapIntent.putExtra(EXTRAS_SEARCH, searchIntent);
- mapIntent.putExtra(EXTRAS_GEOCODE, geocodeIntent);
+ mapIntent.putExtra(Intents.EXTRA_SEARCH, searchIntent);
+ mapIntent.putExtra(Intents.EXTRA_GEOCODE, geocodeIntent);
if (coordsIntent != null) {
- mapIntent.putExtra(EXTRAS_COORDS, coordsIntent);
+ mapIntent.putExtra(Intents.EXTRA_COORDS, coordsIntent);
}
- mapIntent.putExtra(EXTRAS_WPTTYPE, waypointTypeIntent != null ? waypointTypeIntent.id : null);
- mapIntent.putExtra(EXTRAS_MAP_TITLE, mapTitle);
- mapIntent.putExtra(EXTRAS_MAP_MODE, mapMode);
- mapIntent.putExtra(EXTRAS_LIVE_ENABLED, isLiveEnabled);
+ mapIntent.putExtra(Intents.EXTRA_WPTTYPE, waypointTypeIntent != null ? waypointTypeIntent.id : null);
+ mapIntent.putExtra(Intents.EXTRA_MAP_TITLE, mapTitle);
+ mapIntent.putExtra(Intents.EXTRA_MAP_MODE, mapMode);
+ mapIntent.putExtra(Intents.EXTRA_LIVE_ENABLED, isLiveEnabled);
final int[] mapState = currentMapState();
if (mapState != null) {
- mapIntent.putExtra(EXTRAS_MAPSTATE, mapState);
+ mapIntent.putExtra(Intents.EXTRA_MAPSTATE, mapState);
}
// start the new map
@@ -909,13 +884,13 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
}
private void savePrefs() {
- Settings.setMapZoom(mapView.getMapZoomLevel());
+ Settings.setMapZoom(mapMode, mapView.getMapZoomLevel());
Settings.setMapCenter(mapView.getMapViewCenter());
}
// Set center of map to my location if appropriate.
private void myLocationInMiddle(final IGeoData geo) {
- if (followMyLocation && !geo.isPseudoLocation()) {
+ if (followMyLocation) {
centerMap(geo.getCoords());
}
}
@@ -931,8 +906,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
// minimum change of location in fraction of map width/height (whatever is smaller) for position overlay update
private static final float MIN_LOCATION_DELTA = 0.01f;
- Location currentLocation = new Location("");
- boolean locationValid = false;
+ Location currentLocation = CgeoApplication.getInstance().currentGeo().getLocation();
float currentHeading;
private long timeLastPositionOverlayCalculation = 0;
@@ -947,15 +921,9 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
@Override
public void updateGeoDir(final IGeoData geo, final float dir) {
- if (geo.isPseudoLocation()) {
- locationValid = false;
- } else {
- locationValid = true;
-
- currentLocation = geo.getLocation();
- currentHeading = DirectionProvider.getDirectionNow(dir);
- repaintPositionOverlay();
- }
+ currentLocation = geo.getLocation();
+ currentHeading = AngleUtils.getDirectionNow(dir);
+ repaintPositionOverlay();
}
/**
@@ -969,23 +937,23 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
try {
final CGeoMap map = mapRef.get();
if (map != null) {
- final boolean needsRepaintForDistance = needsRepaintForDistance();
+ final boolean needsRepaintForDistanceOrAccuracy = needsRepaintForDistanceOrAccuracy();
final boolean needsRepaintForHeading = needsRepaintForHeading();
- if (needsRepaintForDistance) {
+ if (needsRepaintForDistanceOrAccuracy) {
if (map.followMyLocation) {
map.centerMap(new Geopoint(currentLocation));
}
}
- if (needsRepaintForDistance || needsRepaintForHeading) {
+ if (needsRepaintForDistanceOrAccuracy || needsRepaintForHeading) {
map.overlayPositionAndScale.setCoordinates(currentLocation);
map.overlayPositionAndScale.setHeading(currentHeading);
map.mapView.repaintRequired(map.overlayPositionAndScale);
}
}
} catch (final RuntimeException e) {
- Log.w("Failed to update location.");
+ Log.w("Failed to update location", e);
}
}
}
@@ -998,11 +966,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
return Math.abs(AngleUtils.difference(currentHeading, map.overlayPositionAndScale.getHeading())) > MIN_HEADING_DELTA;
}
- boolean needsRepaintForDistance() {
- if (!locationValid) {
- return false;
- }
-
+ boolean needsRepaintForDistanceOrAccuracy() {
final CGeoMap map = mapRef.get();
if (map == null) {
return false;
@@ -1011,6 +975,9 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
float dist = Float.MAX_VALUE;
if (lastLocation != null) {
+ if (lastLocation.getAccuracy() != currentLocation.getAccuracy()) {
+ return true;
+ }
dist = currentLocation.distanceTo(lastLocation);
}
@@ -1037,7 +1004,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
displayPoint(coordsIntent);
loadTimer = Subscriptions.empty();
} else {
- loadTimer = startLoadTimer();
+ loadTimer = Schedulers.newThread().createWorker().schedulePeriodically(new LoadTimerAction(this), 0, 250, TimeUnit.MILLISECONDS);
}
return loadTimer;
}
@@ -1094,13 +1061,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
}
/**
- * loading timer Triggers every 250ms and checks for viewport change and starts a {@link LoadRunnable}.
- */
- private Subscription startLoadTimer() {
- return Schedulers.newThread().createWorker().schedulePeriodically(new LoadTimerAction(this), 0, 250, TimeUnit.MILLISECONDS);
- }
-
- /**
* get if map is loading something
*
* @return
@@ -1250,9 +1210,6 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
//render
displayExecutor.execute(new DisplayRunnable(this));
- } catch (final ThreadDeath e) {
- Log.d("DownloadThread stopped");
- displayHandler.sendEmptyMessage(UPDATE_TITLE);
} finally {
showProgressHandler.sendEmptyMessage(HIDE_PROGRESS); // hide progress
}
@@ -1302,19 +1259,14 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
}
itemsToDisplay.add(getCacheItem(cache));
}
-
- overlayCaches.updateItems(itemsToDisplay);
- displayHandler.sendEmptyMessage(INVALIDATE_MAP);
-
- } else {
+ }
+ // don't add other waypoints to overlayCaches if just one point should be displayed
+ if (coordsIntent == null) {
overlayCaches.updateItems(itemsToDisplay);
- displayHandler.sendEmptyMessage(INVALIDATE_MAP);
}
+ displayHandler.sendEmptyMessage(INVALIDATE_MAP);
displayHandler.sendEmptyMessage(UPDATE_TITLE);
- } catch (final ThreadDeath e) {
- Log.d("DisplayThread stopped");
- displayHandler.sendEmptyMessage(UPDATE_TITLE);
} finally {
showProgressHandler.sendEmptyMessage(HIDE_PROGRESS);
}
@@ -1610,42 +1562,41 @@ public class CGeoMap extends AbstractMap implements ViewFactory {
public static void startActivitySearch(final Activity fromActivity, final SearchResult search, final String title) {
final Intent mapIntent = newIntent(fromActivity);
- mapIntent.putExtra(EXTRAS_SEARCH, search);
- mapIntent.putExtra(EXTRAS_MAP_MODE, MapMode.LIST);
- mapIntent.putExtra(EXTRAS_LIVE_ENABLED, false);
+ mapIntent.putExtra(Intents.EXTRA_SEARCH, search);
+ mapIntent.putExtra(Intents.EXTRA_MAP_MODE, MapMode.LIST);
+ mapIntent.putExtra(Intents.EXTRA_LIVE_ENABLED, false);
if (StringUtils.isNotBlank(title)) {
- mapIntent.putExtra(CGeoMap.EXTRAS_MAP_TITLE, title);
+ mapIntent.putExtra(Intents.EXTRA_MAP_TITLE, title);
}
fromActivity.startActivity(mapIntent);
}
- public static void startActivityLiveMap(final Activity fromActivity) {
- final Intent mapIntent = newIntent(fromActivity);
- mapIntent.putExtra(EXTRAS_MAP_MODE, MapMode.LIVE);
- mapIntent.putExtra(EXTRAS_LIVE_ENABLED, Settings.isLiveMap());
- fromActivity.startActivity(mapIntent);
+ public static Intent getLiveMapIntent(final Activity fromActivity) {
+ return newIntent(fromActivity)
+ .putExtra(Intents.EXTRA_MAP_MODE, MapMode.LIVE)
+ .putExtra(Intents.EXTRA_LIVE_ENABLED, Settings.isLiveMap());
}
public static void startActivityCoords(final Activity fromActivity, final Geopoint coords, final WaypointType type, final String title) {
final Intent mapIntent = newIntent(fromActivity);
- mapIntent.putExtra(EXTRAS_MAP_MODE, MapMode.COORDS);
- mapIntent.putExtra(EXTRAS_LIVE_ENABLED, false);
- mapIntent.putExtra(EXTRAS_COORDS, coords);
+ mapIntent.putExtra(Intents.EXTRA_MAP_MODE, MapMode.COORDS);
+ mapIntent.putExtra(Intents.EXTRA_LIVE_ENABLED, false);
+ mapIntent.putExtra(Intents.EXTRA_COORDS, coords);
if (type != null) {
- mapIntent.putExtra(EXTRAS_WPTTYPE, type.id);
+ mapIntent.putExtra(Intents.EXTRA_WPTTYPE, type.id);
}
if (StringUtils.isNotBlank(title)) {
- mapIntent.putExtra(EXTRAS_MAP_TITLE, title);
+ mapIntent.putExtra(Intents.EXTRA_MAP_TITLE, title);
}
fromActivity.startActivity(mapIntent);
}
public static void startActivityGeoCode(final Activity fromActivity, final String geocode) {
final Intent mapIntent = newIntent(fromActivity);
- mapIntent.putExtra(EXTRAS_MAP_MODE, MapMode.SINGLE);
- mapIntent.putExtra(EXTRAS_LIVE_ENABLED, false);
- mapIntent.putExtra(EXTRAS_GEOCODE, geocode);
- mapIntent.putExtra(EXTRAS_MAP_TITLE, geocode);
+ mapIntent.putExtra(Intents.EXTRA_MAP_MODE, MapMode.SINGLE);
+ mapIntent.putExtra(Intents.EXTRA_LIVE_ENABLED, false);
+ mapIntent.putExtra(Intents.EXTRA_GEOCODE, geocode);
+ mapIntent.putExtra(Intents.EXTRA_MAP_TITLE, geocode);
fromActivity.startActivity(mapIntent);
}