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.java74
1 files changed, 33 insertions, 41 deletions
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index 28e1b71..927ff28 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -11,7 +11,8 @@ import cgeo.geocaching.SearchResult;
import cgeo.geocaching.Waypoint;
import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.connector.ConnectorFactory;
-import cgeo.geocaching.connector.gc.Login;
+import cgeo.geocaching.connector.gc.GCLogin;
+import cgeo.geocaching.connector.gc.MapTokens;
import cgeo.geocaching.connector.gc.Tile;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LiveMapStrategy.Strategy;
@@ -138,7 +139,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
// status data
/** Last search result used for displaying header */
private SearchResult lastSearchResult = null;
- private String[] tokens = null;
+ private MapTokens tokens = null;
private boolean noMapTokenShowed = false;
// map status data
private boolean followMyLocation = false;
@@ -153,8 +154,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
private volatile boolean downloaded = false;
// overlays
private CachesOverlay overlayCaches = null;
- private ScaleOverlay overlayScale = null;
- private PositionOverlay overlayPosition = null;
+ private PositionAndScaleOverlay overlayPositionAndScale = null;
// data for overlays
private static final int[][] INSET_RELIABLE = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }; // center, 33x40 / 45x51 / 60x68
private static final int[][] INSET_TYPE = { { 5, 8, 6, 10 }, { 4, 4, 5, 11 }, { 4, 4, 5, 11 } }; // center, 22x22 / 36x36
@@ -347,8 +347,8 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
outState.putInt(BUNDLE_MAP_SOURCE, currentSourceId);
outState.putIntArray(BUNDLE_MAP_STATE, currentMapState());
outState.putBoolean(BUNDLE_LIVE_ENABLED, isLiveEnabled);
- if (overlayPosition != null) {
- outState.putParcelableArrayList(BUNDLE_TRAIL_HISTORY, overlayPosition.getHistory());
+ if (overlayPositionAndScale != null) {
+ outState.putParcelableArrayList(BUNDLE_TRAIL_HISTORY, overlayPositionAndScale.getHistory());
}
}
@@ -429,17 +429,13 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
overlayCaches = mapView.createAddMapOverlay(mapView.getContext(), getResources().getDrawable(R.drawable.marker));
}
- if (overlayPosition == null) {
- overlayPosition = mapView.createAddPositionOverlay(activity);
+ if (overlayPositionAndScale == null) {
+ overlayPositionAndScale = mapView.createAddPositionAndScaleOverlay(activity);
if (trailHistory != null) {
- overlayPosition.setHistory(trailHistory);
+ overlayPositionAndScale.setHistory(trailHistory);
}
}
- if (overlayScale == null) {
- overlayScale = mapView.createAddScaleOverlay(activity);
- }
-
mapView.repaintRequired(null);
mapView.getMapController().setZoom(Settings.getMapZoom());
@@ -517,13 +513,8 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
@Override
public void onPause() {
- if (loadTimer != null) {
- loadTimer.stopIt();
- loadTimer = null;
- }
-
+ stopTimer();
deleteGeoDirObservers();
-
savePrefs();
if (mapView != null) {
@@ -622,7 +613,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
switch (id) {
case R.id.menu_trail_mode:
Settings.setMapTrail(!Settings.isMapTrail());
- mapView.repaintRequired(overlayPosition);
+ mapView.repaintRequired(overlayPositionAndScale);
ActivityMixin.invalidateOptionsMenu(activity);
return true;
case R.id.menu_map_live:
@@ -929,8 +920,8 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
try {
if (mapView != null) {
- if (overlayPosition == null) {
- overlayPosition = mapView.createAddPositionOverlay(activity);
+ if (overlayPositionAndScale == null) {
+ overlayPositionAndScale = mapView.createAddPositionAndScaleOverlay(activity);
}
boolean needsRepaintForDistance = needsRepaintForDistance();
@@ -943,9 +934,9 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
if (needsRepaintForDistance || needsRepaintForHeading) {
- overlayPosition.setCoordinates(currentLocation);
- overlayPosition.setHeading(currentHeading);
- mapView.repaintRequired(overlayPosition);
+ overlayPositionAndScale.setCoordinates(currentLocation);
+ overlayPositionAndScale.setHeading(currentHeading);
+ mapView.repaintRequired(overlayPositionAndScale);
}
}
} catch (RuntimeException e) {
@@ -955,7 +946,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
boolean needsRepaintForHeading() {
- return Math.abs(AngleUtils.difference(currentHeading, overlayPosition.getHeading())) > MIN_HEADING_DELTA;
+ return Math.abs(AngleUtils.difference(currentHeading, overlayPositionAndScale.getHeading())) > MIN_HEADING_DELTA;
}
boolean needsRepaintForDistance() {
@@ -964,7 +955,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
return false;
}
- final Location lastLocation = overlayPosition.getCoordinates();
+ final Location lastLocation = overlayPositionAndScale.getCoordinates();
float dist = Float.MAX_VALUE;
if (lastLocation != null) {
@@ -994,15 +985,19 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
(new DisplayPointThread()).start();
} else {
// start timer
- if (loadTimer != null) {
- loadTimer.stopIt();
- loadTimer = null;
- }
+ stopTimer();
loadTimer = new LoadTimer();
loadTimer.start();
}
}
+ private synchronized void stopTimer() {
+ if (loadTimer != null) {
+ loadTimer.stopIt();
+ loadTimer = null;
+ }
+ }
+
/**
* loading timer Triggers every 250ms and checks for viewport change and starts a {@link LoadRunnable}.
*/
@@ -1172,8 +1167,8 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
do {
if (tokens == null) {
- tokens = Login.getMapTokens();
- if (noMapTokenHandler != null && tokens == null) {
+ tokens = GCLogin.getMapTokens();
+ if (noMapTokenHandler != null && (StringUtils.isEmpty(tokens.getUserSession()) || StringUtils.isEmpty(tokens.getSessionToken()))) {
noMapTokenHandler.sendEmptyMessage(0);
}
}
@@ -1181,7 +1176,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
searchResult = ConnectorFactory.searchByViewport(viewport.resize(0.8), tokens);
downloaded = true;
if (searchResult.getError() == StatusCode.NOT_LOGGED_IN && Settings.isGCConnectorActive()) {
- Login.login();
+ GCLogin.getInstance().login();
tokens = null;
} else {
break;
@@ -1311,9 +1306,6 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
protected DoRunnable(final Viewport viewport) {
this.viewport = viewport;
}
-
- @Override
- public abstract void run();
}
/**
@@ -1429,7 +1421,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
}
- private static void filter(Collection<Geocache> caches) {
+ private static synchronized void filter(Collection<Geocache> caches) {
boolean excludeMine = Settings.isExcludeMyCaches();
boolean excludeDisabled = Settings.isExcludeDisabledCaches();
@@ -1480,7 +1472,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
mapController.setCenter(mapItemFactory.getGeoPointBase(new Geopoint(mapState[0] / 1.0e6, mapState[1] / 1.0e6)));
mapController.setZoom(mapState[2]);
} catch (RuntimeException e) {
- // nothing at all
+ Log.e("centermap", e);
}
centered = true;
@@ -1504,7 +1496,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
mapController.zoomToSpan((int) (viewport.getLatitudeSpan() * 1e6), (int) (viewport.getLongitudeSpan() * 1e6));
}
} catch (RuntimeException e) {
- // nothing at all
+ Log.e("centermap", e);
}
centered = true;
@@ -1513,7 +1505,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
try {
mapController.setCenter(makeGeoPoint(coordsCenter));
} catch (Exception e) {
- // nothing at all
+ Log.e("centermap", e);
}
centered = true;