aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2014-05-17 22:07:57 +0200
committerBananeweizen <bananeweizen@gmx.de>2014-05-17 22:07:57 +0200
commitd08ad2a31c3d5292a7276f9b74e84ee3ffefeae0 (patch)
tree8e3305c15af2940e3169016f45699e0eda16cbc0 /main/src
parent9c8375c9d23fded750ec52b8347366fd20e8e6cb (diff)
downloadcgeo-d08ad2a31c3d5292a7276f9b74e84ee3ffefeae0.zip
cgeo-d08ad2a31c3d5292a7276f9b74e84ee3ffefeae0.tar.gz
cgeo-d08ad2a31c3d5292a7276f9b74e84ee3ffefeae0.tar.bz2
#3818: remove further GC blocking references
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java5
-rw-r--r--main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java7
-rw-r--r--main/src/cgeo/geocaching/maps/PositionDrawer.java8
-rw-r--r--main/src/cgeo/geocaching/maps/ScaleDrawer.java9
-rw-r--r--main/src/cgeo/geocaching/maps/google/GoogleMapView.java5
-rw-r--r--main/src/cgeo/geocaching/maps/google/GoogleOverlay.java5
-rw-r--r--main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java3
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java5
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java5
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java5
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java5
-rw-r--r--main/src/cgeo/geocaching/ui/CompassView.java45
12 files changed, 60 insertions, 47 deletions
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index b5d0b0e..857dfbb 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.Subscription;
import rx.functions.Action0;
import rx.functions.Action1;
@@ -438,7 +439,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
if (overlayPositionAndScale == null) {
- overlayPositionAndScale = mapView.createAddPositionAndScaleOverlay(activity);
+ overlayPositionAndScale = mapView.createAddPositionAndScaleOverlay();
if (trailHistory != null) {
overlayPositionAndScale.setHistory(trailHistory);
}
@@ -925,7 +926,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
if (cgeoMapRef != null) {
if (cgeoMapRef.mapView != null) {
if (cgeoMapRef.overlayPositionAndScale == null) {
- cgeoMapRef.overlayPositionAndScale = cgeoMapRef.mapView.createAddPositionAndScaleOverlay(cgeoMapRef.activity);
+ cgeoMapRef.overlayPositionAndScale = cgeoMapRef.mapView.createAddPositionAndScaleOverlay();
}
boolean needsRepaintForDistance = needsRepaintForDistance();
diff --git a/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java b/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java
index 6b34b75..63fcd73 100644
--- a/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java
+++ b/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java
@@ -5,7 +5,6 @@ import cgeo.geocaching.maps.interfaces.MapProjectionImpl;
import cgeo.geocaching.maps.interfaces.MapViewImpl;
import cgeo.geocaching.maps.interfaces.OverlayImpl;
-import android.app.Activity;
import android.graphics.Canvas;
import android.graphics.Point;
import android.location.Location;
@@ -18,10 +17,10 @@ public class PositionAndScaleOverlay implements GeneralOverlay {
PositionDrawer positionDrawer = null;
ScaleDrawer scaleDrawer = null;
- public PositionAndScaleOverlay(Activity activity, OverlayImpl ovlImpl) {
+ public PositionAndScaleOverlay(OverlayImpl ovlImpl) {
this.ovlImpl = ovlImpl;
- positionDrawer = new PositionDrawer(activity);
- scaleDrawer = new ScaleDrawer(activity);
+ positionDrawer = new PositionDrawer();
+ scaleDrawer = new ScaleDrawer();
}
public void setCoordinates(Location coordinatesIn) {
diff --git a/main/src/cgeo/geocaching/maps/PositionDrawer.java b/main/src/cgeo/geocaching/maps/PositionDrawer.java
index 1a5dcaf..0e20e7c 100644
--- a/main/src/cgeo/geocaching/maps/PositionDrawer.java
+++ b/main/src/cgeo/geocaching/maps/PositionDrawer.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.maps;
+import cgeo.geocaching.CgeoApplication;
import cgeo.geocaching.R;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.maps.interfaces.GeoPointImpl;
@@ -7,7 +8,6 @@ import cgeo.geocaching.maps.interfaces.MapItemFactory;
import cgeo.geocaching.maps.interfaces.MapProjectionImpl;
import cgeo.geocaching.settings.Settings;
-import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
@@ -36,11 +36,9 @@ public class PositionDrawer {
private PaintFlagsDrawFilter setfil = null;
private PaintFlagsDrawFilter remfil = null;
private PositionHistory positionHistory = new PositionHistory();
- private Activity activity;
private MapItemFactory mapItemFactory;
- public PositionDrawer(Activity activity) {
- this.activity = activity;
+ public PositionDrawer() {
this.mapItemFactory = Settings.getMapProvider().getMapItemFactory();
}
@@ -144,7 +142,7 @@ public class PositionDrawer {
}
if (arrow == null) {
- arrow = BitmapFactory.decodeResource(activity.getResources(), R.drawable.my_location_chevron);
+ arrow = BitmapFactory.decodeResource(CgeoApplication.getInstance().getResources(), R.drawable.my_location_chevron);
widthArrowHalf = arrow.getWidth() / 2;
heightArrowHalf = arrow.getHeight() / 2;
}
diff --git a/main/src/cgeo/geocaching/maps/ScaleDrawer.java b/main/src/cgeo/geocaching/maps/ScaleDrawer.java
index fb46408..95c987d 100644
--- a/main/src/cgeo/geocaching/maps/ScaleDrawer.java
+++ b/main/src/cgeo/geocaching/maps/ScaleDrawer.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.maps;
+import cgeo.geocaching.CgeoApplication;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.Units;
import cgeo.geocaching.maps.interfaces.GeoPointImpl;
@@ -7,12 +8,13 @@ import cgeo.geocaching.maps.interfaces.MapViewImpl;
import org.apache.commons.lang3.tuple.ImmutablePair;
-import android.app.Activity;
+import android.content.Context;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.util.DisplayMetrics;
+import android.view.WindowManager;
public class ScaleDrawer {
private static final double SCALE_WIDTH_FACTOR = 1.0 / 2.5;
@@ -22,9 +24,10 @@ public class ScaleDrawer {
private BlurMaskFilter blur = null;
private float pixelDensity = 0;
- public ScaleDrawer(Activity activity) {
+ public ScaleDrawer() {
DisplayMetrics metrics = new DisplayMetrics();
- activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
+ WindowManager windowManager = (WindowManager) CgeoApplication.getInstance().getSystemService(Context.WINDOW_SERVICE);
+ windowManager.getDefaultDisplay().getMetrics(metrics);
pixelDensity = metrics.density;
}
diff --git a/main/src/cgeo/geocaching/maps/google/GoogleMapView.java b/main/src/cgeo/geocaching/maps/google/GoogleMapView.java
index 610dbe1..094c456 100644
--- a/main/src/cgeo/geocaching/maps/google/GoogleMapView.java
+++ b/main/src/cgeo/geocaching/maps/google/GoogleMapView.java
@@ -20,7 +20,6 @@ import com.google.android.maps.MapView;
import org.apache.commons.lang3.reflect.MethodUtils;
import org.eclipse.jdt.annotation.NonNull;
-import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
@@ -120,9 +119,9 @@ public class GoogleMapView extends MapView implements MapViewImpl {
}
@Override
- public PositionAndScaleOverlay createAddPositionAndScaleOverlay(Activity activity) {
+ public PositionAndScaleOverlay createAddPositionAndScaleOverlay() {
- GoogleOverlay ovl = new GoogleOverlay(activity);
+ GoogleOverlay ovl = new GoogleOverlay();
getOverlays().add(ovl);
return (PositionAndScaleOverlay) ovl.getBase();
}
diff --git a/main/src/cgeo/geocaching/maps/google/GoogleOverlay.java b/main/src/cgeo/geocaching/maps/google/GoogleOverlay.java
index 0a5cf69..c684b9a 100644
--- a/main/src/cgeo/geocaching/maps/google/GoogleOverlay.java
+++ b/main/src/cgeo/geocaching/maps/google/GoogleOverlay.java
@@ -8,7 +8,6 @@ import cgeo.geocaching.maps.interfaces.OverlayImpl;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
-import android.app.Activity;
import android.graphics.Canvas;
import java.util.concurrent.locks.Lock;
@@ -19,8 +18,8 @@ public class GoogleOverlay extends Overlay implements OverlayImpl {
private PositionAndScaleOverlay overlayBase = null;
private Lock lock = new ReentrantLock();
- public GoogleOverlay(Activity activityIn) {
- overlayBase = new PositionAndScaleOverlay(activityIn, this);
+ public GoogleOverlay() {
+ overlayBase = new PositionAndScaleOverlay(this);
}
@Override
diff --git a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java
index 5ae8e15..4a6d733 100644
--- a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java
+++ b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java
@@ -6,7 +6,6 @@ import cgeo.geocaching.maps.PositionAndScaleOverlay;
import org.eclipse.jdt.annotation.NonNull;
-import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
@@ -47,7 +46,7 @@ public interface MapViewImpl {
CachesOverlay createAddMapOverlay(Context context, Drawable drawable);
- PositionAndScaleOverlay createAddPositionAndScaleOverlay(Activity activity);
+ PositionAndScaleOverlay createAddPositionAndScaleOverlay();
void setMapSource();
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java
index 7a5aab2..fb057a4 100644
--- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java
+++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java
@@ -24,7 +24,6 @@ import org.mapsforge.android.maps.mapgenerator.MapGeneratorInternal;
import org.mapsforge.android.maps.overlay.Overlay;
import org.mapsforge.core.GeoPoint;
-import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
@@ -105,8 +104,8 @@ public class MapsforgeMapView extends MapView implements MapViewImpl {
}
@Override
- public PositionAndScaleOverlay createAddPositionAndScaleOverlay(Activity activity) {
- MapsforgeOverlay ovl = new MapsforgeOverlay(activity);
+ public PositionAndScaleOverlay createAddPositionAndScaleOverlay() {
+ MapsforgeOverlay ovl = new MapsforgeOverlay();
getOverlays().add(ovl);
return (PositionAndScaleOverlay) ovl.getBase();
}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java
index 74a8601..3df4ab0 100644
--- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java
+++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java
@@ -8,7 +8,6 @@ import cgeo.geocaching.maps.interfaces.OverlayImpl;
import org.mapsforge.android.maps.Projection;
import org.mapsforge.android.maps.overlay.Overlay;
-import android.app.Activity;
import android.graphics.Canvas;
import android.graphics.Point;
@@ -20,8 +19,8 @@ public class MapsforgeOverlay extends Overlay implements OverlayImpl {
private PositionAndScaleOverlay overlayBase = null;
private Lock lock = new ReentrantLock();
- public MapsforgeOverlay(Activity activityIn) {
- overlayBase = new PositionAndScaleOverlay(activityIn, this);
+ public MapsforgeOverlay() {
+ overlayBase = new PositionAndScaleOverlay(this);
}
@Override
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java
index 4fa4e02..68a03b7 100644
--- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java
+++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java
@@ -21,7 +21,6 @@ import org.mapsforge.android.mapsold.MapViewMode;
import org.mapsforge.android.mapsold.Overlay;
import org.mapsforge.android.mapsold.Projection;
-import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
@@ -96,8 +95,8 @@ public class MapsforgeMapView024 extends MapView implements MapViewImpl {
}
@Override
- public PositionAndScaleOverlay createAddPositionAndScaleOverlay(Activity activity) {
- MapsforgeOverlay ovl = new MapsforgeOverlay(activity);
+ public PositionAndScaleOverlay createAddPositionAndScaleOverlay() {
+ MapsforgeOverlay ovl = new MapsforgeOverlay();
getOverlays().add(ovl);
return (PositionAndScaleOverlay) ovl.getBase();
}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java
index 655e0b9..bfb3548 100644
--- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java
+++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java
@@ -8,7 +8,6 @@ import cgeo.geocaching.maps.interfaces.OverlayImpl;
import org.mapsforge.android.mapsold.Overlay;
import org.mapsforge.android.mapsold.Projection;
-import android.app.Activity;
import android.graphics.Canvas;
import android.graphics.Point;
@@ -20,8 +19,8 @@ public class MapsforgeOverlay extends Overlay implements OverlayImpl {
private PositionAndScaleOverlay overlayBase = null;
private Lock lock = new ReentrantLock();
- public MapsforgeOverlay(Activity activityIn) {
- overlayBase = new PositionAndScaleOverlay(activityIn, this);
+ public MapsforgeOverlay() {
+ overlayBase = new PositionAndScaleOverlay(this);
}
@Override
diff --git a/main/src/cgeo/geocaching/ui/CompassView.java b/main/src/cgeo/geocaching/ui/CompassView.java
index 915303b..60982a9 100644
--- a/main/src/cgeo/geocaching/ui/CompassView.java
+++ b/main/src/cgeo/geocaching/ui/CompassView.java
@@ -17,6 +17,7 @@ import android.graphics.PaintFlagsDrawFilter;
import android.util.AttributeSet;
import android.view.View;
+import java.lang.ref.WeakReference;
import java.util.concurrent.TimeUnit;
public class CompassView extends View {
@@ -55,11 +56,40 @@ public class CompassView extends View {
private boolean initialDisplay;
private Subscription periodicUpdate;
+ private static final class UpdateAction implements Action0 {
+
+ private final WeakReference<CompassView> compassViewRef;
+
+ private UpdateAction(CompassView view) {
+ this.compassViewRef = new WeakReference<CompassView>(view);
+ }
+
+ @Override
+ public void call() {
+ final CompassView compassView = compassViewRef.get();
+ if (compassView == null) {
+ return;
+ }
+ compassView.updateGraphics();
+ }
+ }
+
public CompassView(Context contextIn) {
super(contextIn);
context = contextIn;
}
+ public void updateGraphics() {
+ final float newAzimuthShown = smoothUpdate(northMeasured, azimuthShown);
+ final float newCacheHeadingShown = smoothUpdate(cacheHeadingMeasured, cacheHeadingShown);
+ if (Math.abs(AngleUtils.difference(azimuthShown, newAzimuthShown)) >= 2 ||
+ Math.abs(AngleUtils.difference(cacheHeadingShown, newCacheHeadingShown)) >= 2) {
+ azimuthShown = newAzimuthShown;
+ cacheHeadingShown = newCacheHeadingShown;
+ invalidate();
+ }
+ }
+
public CompassView(Context contextIn, AttributeSet attrs) {
super(contextIn, attrs);
context = contextIn;
@@ -87,24 +117,13 @@ public class CompassView extends View {
initialDisplay = true;
- periodicUpdate = AndroidSchedulers.mainThread().createWorker().schedulePeriodically(new Action0() {
- @Override
- public void call() {
- final float newAzimuthShown = smoothUpdate(northMeasured, azimuthShown);
- final float newCacheHeadingShown = smoothUpdate(cacheHeadingMeasured, cacheHeadingShown);
- if (Math.abs(AngleUtils.difference(azimuthShown, newAzimuthShown)) >= 2 ||
- Math.abs(AngleUtils.difference(cacheHeadingShown, newCacheHeadingShown)) >= 2) {
- azimuthShown = newAzimuthShown;
- cacheHeadingShown = newCacheHeadingShown;
- invalidate();
- }
- }
- }, 0, 40, TimeUnit.MILLISECONDS);
+ periodicUpdate = AndroidSchedulers.mainThread().createWorker().schedulePeriodically(new UpdateAction(this), 0, 40, TimeUnit.MILLISECONDS);
}
@Override
public void onDetachedFromWindow() {
periodicUpdate.unsubscribe();
+
super.onDetachedFromWindow();
if (compassUnderlay != null) {