diff options
10 files changed, 114 insertions, 102 deletions
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index d8cad51..fedd765 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -154,7 +154,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto private volatile boolean downloaded = false; // overlays private CachesOverlay overlayCaches = null; - private PositionAndScaleOverlay overlayPositionAndScale = 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 (overlayPositionAndScale != null) { - outState.putParcelableArrayList(BUNDLE_TRAIL_HISTORY, overlayPositionAndScale.getHistory()); + if (overlayCaches != null) { + outState.putParcelableArrayList(BUNDLE_TRAIL_HISTORY, overlayCaches.getHistory()); } } @@ -426,13 +426,9 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto mapView.clearOverlays(); if (overlayCaches == null) { - overlayCaches = mapView.createAddMapOverlay(mapView.getContext(), getResources().getDrawable(R.drawable.marker)); - } - - if (overlayPositionAndScale == null) { - overlayPositionAndScale = mapView.createAddPositionAndScaleOverlay(activity); + overlayCaches = mapView.createAddMapOverlay(mapView.getContext(), getResources().getDrawable(R.drawable.marker), activity); if (trailHistory != null) { - overlayPositionAndScale.setHistory(trailHistory); + overlayCaches.setHistory(trailHistory); } } @@ -613,7 +609,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto switch (id) { case R.id.menu_trail_mode: Settings.setMapTrail(!Settings.isMapTrail()); - mapView.repaintRequired(overlayPositionAndScale); + mapView.repaintRequired(overlayCaches); ActivityMixin.invalidateOptionsMenu(activity); return true; case R.id.menu_map_live: @@ -920,9 +916,6 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto try { if (mapView != null) { - if (overlayPositionAndScale == null) { - overlayPositionAndScale = mapView.createAddPositionAndScaleOverlay(activity); - } boolean needsRepaintForDistance = needsRepaintForDistance(); boolean needsRepaintForHeading = needsRepaintForHeading(); @@ -934,9 +927,9 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } if (needsRepaintForDistance || needsRepaintForHeading) { - overlayPositionAndScale.setCoordinates(currentLocation); - overlayPositionAndScale.setHeading(currentHeading); - mapView.repaintRequired(overlayPositionAndScale); + overlayCaches.setCoordinates(currentLocation); + overlayCaches.setHeading(currentHeading); + mapView.repaintRequired(overlayCaches); } } } catch (RuntimeException e) { @@ -946,7 +939,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } boolean needsRepaintForHeading() { - return Math.abs(AngleUtils.difference(currentHeading, overlayPositionAndScale.getHeading())) > MIN_HEADING_DELTA; + return Math.abs(AngleUtils.difference(currentHeading, overlayCaches.getHeading())) > MIN_HEADING_DELTA; } boolean needsRepaintForDistance() { @@ -955,7 +948,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto return false; } - final Location lastLocation = overlayPositionAndScale.getCoordinates(); + final Location lastLocation = overlayCaches.getCoordinates(); float dist = Float.MAX_VALUE; if (lastLocation != null) { 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 diff --git a/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java b/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java index 6b34b75..aecd1c9 100644 --- a/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java +++ b/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java @@ -8,36 +8,18 @@ import cgeo.geocaching.maps.interfaces.OverlayImpl; import android.app.Activity; import android.graphics.Canvas; import android.graphics.Point; -import android.location.Location; - -import java.util.ArrayList; public class PositionAndScaleOverlay implements GeneralOverlay { private OverlayImpl ovlImpl = null; - PositionDrawer positionDrawer = null; - ScaleDrawer scaleDrawer = null; + // PositionDrawer positionDrawer = null; + + // ScaleDrawer scaleDrawer = null; public PositionAndScaleOverlay(Activity activity, OverlayImpl ovlImpl) { this.ovlImpl = ovlImpl; - positionDrawer = new PositionDrawer(activity); - scaleDrawer = new ScaleDrawer(activity); - } - - 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(); + // positionDrawer = new PositionDrawer(activity); + //scaleDrawer = new ScaleDrawer(activity); } @Override @@ -54,8 +36,8 @@ public class PositionAndScaleOverlay implements GeneralOverlay { } private void drawInternal(Canvas canvas, MapProjectionImpl projection, MapViewImpl mapView) { - positionDrawer.drawPosition(canvas, projection); - scaleDrawer.drawScale(canvas, mapView); + // positionDrawer.drawPosition(canvas, projection); + // scaleDrawer.drawScale(canvas, mapView); } @Override @@ -63,11 +45,4 @@ public class PositionAndScaleOverlay implements GeneralOverlay { return this.ovlImpl; } - public ArrayList<Location> getHistory() { - return positionDrawer.getHistory(); - } - - public void setHistory(ArrayList<Location> history) { - positionDrawer.setHistory(history); - } } diff --git a/main/src/cgeo/geocaching/maps/google/GoogleCacheOverlay.java b/main/src/cgeo/geocaching/maps/google/GoogleCacheOverlay.java index 3339650..adfa8b5 100644 --- a/main/src/cgeo/geocaching/maps/google/GoogleCacheOverlay.java +++ b/main/src/cgeo/geocaching/maps/google/GoogleCacheOverlay.java @@ -8,6 +8,7 @@ import cgeo.geocaching.maps.interfaces.MapViewImpl; import com.google.android.maps.ItemizedOverlay; import com.google.android.maps.MapView; +import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Point; @@ -24,9 +25,9 @@ public class GoogleCacheOverlay extends ItemizedOverlay<GoogleCacheOverlayItem> private CachesOverlay base; private Lock lock = new ReentrantLock(); - public GoogleCacheOverlay(Context contextIn, Drawable markerIn) { + public GoogleCacheOverlay(Context contextIn, Drawable markerIn, Activity activity) { super(boundCenterBottom(markerIn)); - base = new CachesOverlay(this, contextIn); + base = new CachesOverlay(this, contextIn, activity); } @Override diff --git a/main/src/cgeo/geocaching/maps/google/GoogleMapView.java b/main/src/cgeo/geocaching/maps/google/GoogleMapView.java index d02e3c2..735e3ce 100644 --- a/main/src/cgeo/geocaching/maps/google/GoogleMapView.java +++ b/main/src/cgeo/geocaching/maps/google/GoogleMapView.java @@ -117,9 +117,9 @@ public class GoogleMapView extends MapView implements MapViewImpl { } @Override - public CachesOverlay createAddMapOverlay(Context context, Drawable drawable) { + public CachesOverlay createAddMapOverlay(Context context, Drawable drawable, Activity activity) { - GoogleCacheOverlay ovl = new GoogleCacheOverlay(context, drawable); + GoogleCacheOverlay ovl = new GoogleCacheOverlay(context, drawable, activity); getOverlays().add(ovl); return ovl.getBase(); } diff --git a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java index cb7ddc6..f30220a 100644 --- a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java +++ b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java @@ -44,7 +44,7 @@ public interface MapViewImpl { Context getContext(); - CachesOverlay createAddMapOverlay(Context context, Drawable drawable); + CachesOverlay createAddMapOverlay(Context context, Drawable drawable, Activity activity); PositionAndScaleOverlay createAddPositionAndScaleOverlay(Activity activity); @@ -75,7 +75,7 @@ public interface MapViewImpl { /** * Indicates if the current map view supports different themes * for map rendering - * + * * @return true - supports custom themes, false - does not support custom themes */ boolean hasMapThemes(); diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlay.java index 9e14e36..5805ba0 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlay.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlay.java @@ -8,6 +8,7 @@ import cgeo.geocaching.maps.interfaces.MapViewImpl; import org.mapsforge.android.maps.Projection; import org.mapsforge.android.maps.overlay.ItemizedOverlay; +import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Point; @@ -21,9 +22,9 @@ public class MapsforgeCacheOverlay extends ItemizedOverlay<MapsforgeCacheOverlay private CachesOverlay base; private Lock lock = new ReentrantLock(); - public MapsforgeCacheOverlay(Context contextIn, Drawable markerIn) { + public MapsforgeCacheOverlay(Context contextIn, Drawable markerIn, Activity activity) { super(boundCenterBottom(markerIn)); - base = new CachesOverlay(this, contextIn); + base = new CachesOverlay(this, contextIn, activity); } @Override diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java index 78aa47d..26e707a 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java @@ -101,9 +101,9 @@ public class MapsforgeMapView extends MapView implements MapViewImpl { } @Override - public CachesOverlay createAddMapOverlay(Context context, Drawable drawable) { + public CachesOverlay createAddMapOverlay(Context context, Drawable drawable, Activity activity) { - MapsforgeCacheOverlay ovl = new MapsforgeCacheOverlay(context, drawable); + MapsforgeCacheOverlay ovl = new MapsforgeCacheOverlay(context, drawable, activity); getOverlays().add(ovl); return ovl.getBase(); } diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlay.java index 30355fd..77848f2 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlay.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlay.java @@ -8,6 +8,7 @@ import cgeo.geocaching.maps.interfaces.MapViewImpl; import org.mapsforge.android.mapsold.ItemizedOverlay; import org.mapsforge.android.mapsold.Projection; +import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Point; @@ -21,9 +22,9 @@ public class MapsforgeCacheOverlay extends ItemizedOverlay<MapsforgeCacheOverlay private CachesOverlay base; private Lock lock = new ReentrantLock(); - public MapsforgeCacheOverlay(Context contextIn, Drawable markerIn) { + public MapsforgeCacheOverlay(Context contextIn, Drawable markerIn, Activity activity) { super(boundCenterBottom(markerIn)); - base = new CachesOverlay(this, contextIn); + base = new CachesOverlay(this, contextIn, activity); } @Override diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java index c741a31..55b3e0a 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java @@ -92,9 +92,9 @@ public class MapsforgeMapView024 extends MapView implements MapViewImpl { } @Override - public CachesOverlay createAddMapOverlay(Context context, Drawable drawable) { + public CachesOverlay createAddMapOverlay(Context context, Drawable drawable, Activity activity) { - MapsforgeCacheOverlay ovl = new MapsforgeCacheOverlay(context, drawable); + MapsforgeCacheOverlay ovl = new MapsforgeCacheOverlay(context, drawable, activity); getOverlays().add(ovl); return ovl.getBase(); } |
