aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorMichael Keppler <michael.keppler@gmx.de>2014-04-26 10:33:00 +0200
committerMichael Keppler <michael.keppler@gmx.de>2014-04-26 10:33:00 +0200
commit1e70b946fb1746118082a7a11d5e534284dc1507 (patch)
tree5f4266002dc7c138ca605b127f295a916fcdae60 /main/src
parent087a8a0c4a8be25f8b10a2d2fceb6fb595740acf (diff)
parentb0435b4eb828be8f38853427eb000d7feafde1ff (diff)
downloadcgeo-1e70b946fb1746118082a7a11d5e534284dc1507.zip
cgeo-1e70b946fb1746118082a7a11d5e534284dc1507.tar.gz
cgeo-1e70b946fb1746118082a7a11d5e534284dc1507.tar.bz2
Merge remote-tracking branch 'origin/release'
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java65
1 files changed, 43 insertions, 22 deletions
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index 9f2f89e..00aee36 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -43,6 +43,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.eclipse.jdt.annotation.NonNull;
+
import rx.Scheduler;
import rx.Subscription;
import rx.functions.Action1;
@@ -76,6 +77,7 @@ import android.widget.TextView;
import android.widget.ViewSwitcher.ViewFactory;
import java.io.File;
+import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
@@ -136,7 +138,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
private Activity activity = null;
private MapViewImpl mapView = null;
private CgeoApplication app = null;
- final private GeoDirHandler geoDirUpdate = new UpdateLoc();
+ final private GeoDirHandler geoDirUpdate;
private SearchResult searchIntent = null;
private String geocodeIntent = null;
private Geopoint coordsIntent = null;
@@ -328,6 +330,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
public CGeoMap(MapActivityImpl activity) {
super(activity);
+ geoDirUpdate = new UpdateLoc(this);
}
protected void countVisibleCaches() {
@@ -873,7 +876,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
// class: update location
- private class UpdateLoc extends GeoDirHandler {
+ private static class UpdateLoc extends GeoDirHandler {
// use the following constants for fine tuning - find good compromise between smooth updates and as less updates as possible
// minimum time in milliseconds between position overlay updates
@@ -888,6 +891,14 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
float currentHeading;
private long timeLastPositionOverlayCalculation = 0;
+ /**
+ * weak reference to the outer class
+ */
+ private final WeakReference<CGeoMap> map;
+
+ public UpdateLoc(CGeoMap map) {
+ this.map = new WeakReference<CGeoMap>(map);
+ }
@Override
public void updateGeoDir(final IGeoData geo, final float dir) {
@@ -911,24 +922,27 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
timeLastPositionOverlayCalculation = currentTimeMillis;
try {
- if (mapView != null) {
- if (overlayPositionAndScale == null) {
- overlayPositionAndScale = mapView.createAddPositionAndScaleOverlay(activity);
- }
+ CGeoMap cgeoMapRef = map.get();
+ if (cgeoMapRef != null) {
+ if (cgeoMapRef.mapView != null) {
+ if (cgeoMapRef.overlayPositionAndScale == null) {
+ cgeoMapRef.overlayPositionAndScale = cgeoMapRef.mapView.createAddPositionAndScaleOverlay(cgeoMapRef.activity);
+ }
- boolean needsRepaintForDistance = needsRepaintForDistance();
- boolean needsRepaintForHeading = needsRepaintForHeading();
+ boolean needsRepaintForDistance = needsRepaintForDistance();
+ boolean needsRepaintForHeading = needsRepaintForHeading();
- if (needsRepaintForDistance) {
- if (followMyLocation) {
- centerMap(new Geopoint(currentLocation));
+ if (needsRepaintForDistance) {
+ if (cgeoMapRef.followMyLocation) {
+ cgeoMapRef.centerMap(new Geopoint(currentLocation));
+ }
}
- }
- if (needsRepaintForDistance || needsRepaintForHeading) {
- overlayPositionAndScale.setCoordinates(currentLocation);
- overlayPositionAndScale.setHeading(currentHeading);
- mapView.repaintRequired(overlayPositionAndScale);
+ if (needsRepaintForDistance || needsRepaintForHeading) {
+ cgeoMapRef.overlayPositionAndScale.setCoordinates(currentLocation);
+ cgeoMapRef.overlayPositionAndScale.setHeading(currentHeading);
+ cgeoMapRef.mapView.repaintRequired(cgeoMapRef.overlayPositionAndScale);
+ }
}
}
} catch (RuntimeException e) {
@@ -938,16 +952,23 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
boolean needsRepaintForHeading() {
- return Math.abs(AngleUtils.difference(currentHeading, overlayPositionAndScale.getHeading())) > MIN_HEADING_DELTA;
+ final CGeoMap cgeoMapRef = map.get();
+ if (cgeoMapRef == null) {
+ return false;
+ }
+ return Math.abs(AngleUtils.difference(currentHeading, cgeoMapRef.overlayPositionAndScale.getHeading())) > MIN_HEADING_DELTA;
}
boolean needsRepaintForDistance() {
-
if (!locationValid) {
return false;
}
- final Location lastLocation = overlayPositionAndScale.getCoordinates();
+ final CGeoMap cgeoMapRef = map.get();
+ if (cgeoMapRef == null) {
+ return false;
+ }
+ final Location lastLocation = cgeoMapRef.overlayPositionAndScale.getCoordinates();
float dist = Float.MAX_VALUE;
if (lastLocation != null) {
@@ -955,11 +976,11 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
final float[] mapDimension = new float[1];
- if (mapView.getWidth() < mapView.getHeight()) {
- final double span = mapView.getLongitudeSpan() / 1e6;
+ if (cgeoMapRef.mapView.getWidth() < cgeoMapRef.mapView.getHeight()) {
+ final double span = cgeoMapRef.mapView.getLongitudeSpan() / 1e6;
Location.distanceBetween(currentLocation.getLatitude(), currentLocation.getLongitude(), currentLocation.getLatitude(), currentLocation.getLongitude() + span, mapDimension);
} else {
- final double span = mapView.getLatitudeSpan() / 1e6;
+ final double span = cgeoMapRef.mapView.getLatitudeSpan() / 1e6;
Location.distanceBetween(currentLocation.getLatitude(), currentLocation.getLongitude(), currentLocation.getLatitude() + span, currentLocation.getLongitude(), mapDimension);
}