aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/maps/CachesOverlay.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/maps/CachesOverlay.java')
-rw-r--r--main/src/cgeo/geocaching/maps/CachesOverlay.java117
1 files changed, 79 insertions, 38 deletions
diff --git a/main/src/cgeo/geocaching/maps/CachesOverlay.java b/main/src/cgeo/geocaching/maps/CachesOverlay.java
index cd2ff75..21692d6 100644
--- a/main/src/cgeo/geocaching/maps/CachesOverlay.java
+++ b/main/src/cgeo/geocaching/maps/CachesOverlay.java
@@ -1,11 +1,11 @@
package cgeo.geocaching.maps;
import cgeo.geocaching.CachePopup;
+import cgeo.geocaching.DataStore;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.IWaypoint;
import cgeo.geocaching.R;
import cgeo.geocaching.WaypointPopup;
-import cgeo.geocaching.DataStore;
import cgeo.geocaching.activity.Progress;
import cgeo.geocaching.connector.gc.GCMap;
import cgeo.geocaching.enumerations.CacheType;
@@ -23,6 +23,7 @@ import cgeo.geocaching.utils.Log;
import org.apache.commons.lang3.StringUtils;
+import android.app.Activity;
import android.content.Context;
import android.content.res.Resources.NotFoundException;
import android.graphics.Canvas;
@@ -47,8 +48,10 @@ public class CachesOverlay extends AbstractItemizedOverlay {
private PaintFlagsDrawFilter setFilter = null;
private PaintFlagsDrawFilter removeFilter = null;
private MapItemFactory mapItemFactory = null;
+ private ScaleDrawer scaleDrawer = null;
+ private PositionDrawer positionDrawer;
- public CachesOverlay(ItemizedOverlayImpl ovlImpl, Context contextIn) {
+ public CachesOverlay(ItemizedOverlayImpl ovlImpl, Context contextIn, Activity activity) {
super(ovlImpl);
populate();
@@ -57,6 +60,8 @@ public class CachesOverlay extends AbstractItemizedOverlay {
final MapProvider mapProvider = Settings.getMapProvider();
mapItemFactory = mapProvider.getMapItemFactory();
+ positionDrawer = new PositionDrawer(activity);
+ scaleDrawer = new ScaleDrawer(activity);
}
void updateItems(CachesOverlayItemImpl item) {
@@ -97,61 +102,97 @@ public class CachesOverlay extends AbstractItemizedOverlay {
@Override
public void draw(Canvas canvas, MapViewImpl mapView, boolean shadow) {
-
- drawInternal(canvas, mapView.getMapProjection());
-
+ drawInternalBefore(canvas, mapView.getMapProjection(), mapView);
super.draw(canvas, mapView, false);
+ drawInternalAfter(canvas, mapView.getMapProjection(), mapView);
}
@Override
public void drawOverlayBitmap(Canvas canvas, Point drawPosition,
MapProjectionImpl projection, byte drawZoomLevel) {
-
- drawInternal(canvas, projection);
-
+ drawInternalBefore(canvas, projection, getOverlayImpl().getMapViewImpl());
super.drawOverlayBitmap(canvas, drawPosition, projection, drawZoomLevel);
+ drawInternalAfter(canvas, projection, getOverlayImpl().getMapViewImpl());
}
- private void drawInternal(Canvas canvas, MapProjectionImpl projection) {
- if (!displayCircles || items.isEmpty()) {
- return;
+ private void drawInternalBefore(Canvas canvas, MapProjectionImpl projection, MapViewImpl mapView) {
+ // prevent content changes
+ getOverlayImpl().lock();
+ try {
+ drawCircles(canvas, projection);
+ } finally {
+ getOverlayImpl().unlock();
}
+ }
+ private void drawInternalAfter(Canvas canvas, MapProjectionImpl projection, MapViewImpl mapView) {
// prevent content changes
getOverlayImpl().lock();
try {
- lazyInitializeDrawingObjects();
- canvas.setDrawFilter(setFilter);
- final int height = canvas.getHeight();
- final int width = canvas.getWidth();
-
- final int radius = calculateDrawingRadius(projection);
- final Point center = new Point();
-
- for (CachesOverlayItemImpl item : items) {
- if (item.applyDistanceRule()) {
- final Geopoint itemCoord = item.getCoord().getCoords();
- final GeoPointImpl itemGeo = mapItemFactory.getGeoPointBase(itemCoord);
- projection.toPixels(itemGeo, center);
- if (center.x > -radius && center.y > -radius && center.x < width + radius && center.y < height + radius) {
- // dashed circle around the waypoint
- blockedCircle.setColor(0x66BB0000);
- blockedCircle.setStyle(Style.STROKE);
- canvas.drawCircle(center.x, center.y, radius, blockedCircle);
-
- // filling the circle area with a transparent color
- blockedCircle.setColor(0x44BB0000);
- blockedCircle.setStyle(Style.FILL);
- canvas.drawCircle(center.x, center.y, radius, blockedCircle);
- }
- }
- }
- canvas.setDrawFilter(removeFilter);
+ scaleDrawer.drawScale(canvas, mapView);
+ positionDrawer.drawPosition(canvas, projection);
} finally {
getOverlayImpl().unlock();
}
}
+ private void drawCircles(Canvas canvas, MapProjectionImpl projection) {
+ if (!displayCircles || items.isEmpty()) {
+ return;
+ }
+ lazyInitializeDrawingObjects();
+ canvas.setDrawFilter(setFilter);
+ final int height = canvas.getHeight();
+ final int width = canvas.getWidth();
+
+ final int radius = calculateDrawingRadius(projection);
+ final Point center = new Point();
+
+ for (CachesOverlayItemImpl item : items) {
+ if (item.applyDistanceRule()) {
+ final Geopoint itemCoord = item.getCoord().getCoords();
+ final GeoPointImpl itemGeo = mapItemFactory.getGeoPointBase(itemCoord);
+ projection.toPixels(itemGeo, center);
+ if (center.x > -radius && center.y > -radius && center.x < width + radius && center.y < height + radius) {
+ // dashed circle around the waypoint
+ blockedCircle.setColor(0x66BB0000);
+ blockedCircle.setStyle(Style.STROKE);
+ canvas.drawCircle(center.x, center.y, radius, blockedCircle);
+
+ // filling the circle area with a transparent color
+ blockedCircle.setColor(0x44BB0000);
+ blockedCircle.setStyle(Style.FILL);
+ canvas.drawCircle(center.x, center.y, radius, blockedCircle);
+ }
+ }
+ }
+ canvas.setDrawFilter(removeFilter);
+ }
+
+ public void setCoordinates(Location coordinatesIn) {
+ positionDrawer.setCoordinates(coordinatesIn);
+ }
+
+ public Location getCoordinates() {
+ return positionDrawer.getCoordinates();
+ }
+
+ public void setHeading(float bearingNow) {
+ positionDrawer.setHeading(bearingNow);
+ }
+
+ public float getHeading() {
+ return positionDrawer.getHeading();
+ }
+
+ public ArrayList<Location> getHistory() {
+ return positionDrawer.getHistory();
+ }
+
+ public void setHistory(ArrayList<Location> history) {
+ positionDrawer.setHistory(history);
+ }
+
/**
* calculate the radius of the circle to be drawn for the first item only. Those circles are only 161 meters in
* reality and therefore the minor changes due to the projection will not make any visible difference at the zoom