diff options
Diffstat (limited to 'main/src/cgeo/geocaching')
-rw-r--r-- | main/src/cgeo/geocaching/GeoDataProvider.java | 7 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/IGeoData.java | 4 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/Settings.java | 21 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/maps/CGeoMap.java | 26 |
4 files changed, 51 insertions, 7 deletions
diff --git a/main/src/cgeo/geocaching/GeoDataProvider.java b/main/src/cgeo/geocaching/GeoDataProvider.java index a52420a..1b9a0f5 100644 --- a/main/src/cgeo/geocaching/GeoDataProvider.java +++ b/main/src/cgeo/geocaching/GeoDataProvider.java @@ -6,6 +6,8 @@ import cgeo.geocaching.go4cache.Go4Cache; import cgeo.geocaching.utils.Log; import cgeo.geocaching.utils.MemorySubject; +import org.apache.commons.lang3.StringUtils; + import android.content.Context; import android.location.GpsSatellite; import android.location.GpsStatus; @@ -103,6 +105,11 @@ class GeoDataProvider extends MemorySubject<IGeoData> { public int getSatellitesFixed() { return satellitesFixed; } + + @Override + public boolean isPseudoLocation() { + return StringUtils.equals(getProvider(), GeoDataProvider.LAST_LOCATION_PSEUDO_PROVIDER); + } } private class Unregisterer extends Thread { diff --git a/main/src/cgeo/geocaching/IGeoData.java b/main/src/cgeo/geocaching/IGeoData.java index 9696b27..252fd4f 100644 --- a/main/src/cgeo/geocaching/IGeoData.java +++ b/main/src/cgeo/geocaching/IGeoData.java @@ -9,6 +9,9 @@ public interface IGeoData { public Location getLocation(); public LocationProviderType getLocationProvider(); + + public boolean isPseudoLocation(); + public Geopoint getCoords(); public double getAltitude(); public float getBearing(); @@ -17,5 +20,4 @@ public interface IGeoData { public boolean getGpsEnabled(); public int getSatellitesVisible(); public int getSatellitesFixed(); - } diff --git a/main/src/cgeo/geocaching/Settings.java b/main/src/cgeo/geocaching/Settings.java index e610844..bbcb80b 100644 --- a/main/src/cgeo/geocaching/Settings.java +++ b/main/src/cgeo/geocaching/Settings.java @@ -8,6 +8,7 @@ import cgeo.geocaching.enumerations.LiveMapStrategy.Strategy; import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.maps.MapProviderFactory; +import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapProvider; import cgeo.geocaching.maps.mapsforge.MapsforgeMapProvider; import cgeo.geocaching.utils.CryptUtils; @@ -47,6 +48,8 @@ public final class Settings { private static final String KEY_SHOW_CAPTCHA = "showcaptcha"; private static final String KEY_MAP_TRAIL = "maptrail"; private static final String KEY_LAST_MAP_ZOOM = "mapzoom"; + private static final String KEY_LAST_MAP_LAT = "maplat"; + private static final String KEY_LAST_MAP_LON = "maplon"; private static final String KEY_LIVE_LIST = "livelist"; private static final String KEY_METRIC_UNITS = "units"; private static final String KEY_SKIN = "skin"; @@ -805,6 +808,23 @@ public final class Settings { }); } + public static GeoPointImpl getMapCenter() { + return getMapProvider().getMapItemFactory() + .getGeoPointBase(new Geopoint(sharedPrefs.getInt(KEY_LAST_MAP_LAT, 0) / 1e6, + sharedPrefs.getInt(KEY_LAST_MAP_LON, 0) / 1e6)); + } + + public static void setMapCenter(final GeoPointImpl mapViewCenter) { + editSharedSettings(new PrefRunnable() { + + @Override + public void edit(Editor edit) { + edit.putInt(KEY_LAST_MAP_LAT, mapViewCenter.getLatitudeE6()); + edit.putInt(KEY_LAST_MAP_LON, mapViewCenter.getLongitudeE6()); + } + }); + } + public static int getMapSource() { return sharedPrefs.getInt(KEY_MAP_SOURCE, 0); } @@ -1177,4 +1197,5 @@ public final class Settings { // there is currently no Android API to get the file name of the shared preferences return cgeoapplication.getInstance().getPackageName() + "_preferences"; } + } diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index fbbd80d..cf90430 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -450,6 +450,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto mapView.repaintRequired(null); mapView.getMapController().setZoom(Settings.getMapZoom()); + mapView.getMapController().setCenter(Settings.getMapCenter()); if (null == mapStateIntent) { followMyLocation = mapMode == MapMode.LIVE_OFFLINE || mapMode == MapMode.LIVE_ONLINE; @@ -855,11 +856,12 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } Settings.setMapZoom(mapView.getMapZoomLevel()); + Settings.setMapCenter(mapView.getMapViewCenter()); } // Set center of map to my location if appropriate. private void myLocationInMiddle(final IGeoData geo) { - if (followMyLocation) { + if (followMyLocation && !geo.isPseudoLocation()) { centerMap(geo.getCoords()); } } @@ -876,19 +878,26 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto private static final float MIN_LOCATION_DELTA = 0.01f; Location currentLocation = new Location(""); + boolean locationValid = false; float currentHeading; private long timeLastPositionOverlayCalculation = 0; @Override protected void updateGeoData(final IGeoData geo) { - currentLocation = geo.getLocation(); + if (geo.isPseudoLocation()) { + locationValid = false; + } else { + locationValid = true; - if (!Settings.isUseCompass() || geo.getSpeed() > 5) { // use GPS when speed is higher than 18 km/h - currentHeading = geo.getBearing(); - } + currentLocation = geo.getLocation(); + + if (!Settings.isUseCompass() || geo.getSpeed() > 5) { // use GPS when speed is higher than 18 km/h + currentHeading = geo.getBearing(); + } - repaintPositionOverlay(); + repaintPositionOverlay(); + } } @Override @@ -939,6 +948,11 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } boolean needsRepaintForDistance() { + + if (!locationValid) { + return false; + } + final Location lastLocation = overlayPosition.getCoordinates(); float dist = Float.MAX_VALUE; |