diff options
10 files changed, 102 insertions, 114 deletions
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index fedd765..d8cad51 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 (overlayCaches != null) { - outState.putParcelableArrayList(BUNDLE_TRAIL_HISTORY, overlayCaches.getHistory()); + if (overlayPositionAndScale != null) { + outState.putParcelableArrayList(BUNDLE_TRAIL_HISTORY, overlayPositionAndScale.getHistory()); } } @@ -426,9 +426,13 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto mapView.clearOverlays(); if (overlayCaches == null) { - overlayCaches = mapView.createAddMapOverlay(mapView.getContext(), getResources().getDrawable(R.drawable.marker), activity); + overlayCaches = mapView.createAddMapOverlay(mapView.getContext(), getResources().getDrawable(R.drawable.marker)); + } + + if (overlayPositionAndScale == null) { + overlayPositionAndScale = mapView.createAddPositionAndScaleOverlay(activity); if (trailHistory != null) { - overlayCaches.setHistory(trailHistory); + overlayPositionAndScale.setHistory(trailHistory); } } @@ -609,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(overlayCaches); + mapView.repaintRequired(overlayPositionAndScale); ActivityMixin.invalidateOptionsMenu(activity); return true; case R.id.menu_map_live: @@ -916,6 +920,9 @@ 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(); @@ -927,9 +934,9 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } if (needsRepaintForDistance || needsRepaintForHeading) { - overlayCaches.setCoordinates(currentLocation); - overlayCaches.setHeading(currentHeading); - mapView.repaintRequired(overlayCaches); + overlayPositionAndScale.setCoordinates(currentLocation); + overlayPositionAndScale.setHeading(currentHeading); + mapView.repaintRequired(overlayPositionAndScale); } } } catch (RuntimeException e) { @@ -939,7 +946,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } boolean needsRepaintForHeading() { - return Math.abs(AngleUtils.difference(currentHeading, overlayCaches.getHeading())) > MIN_HEADING_DELTA; + return Math.abs(AngleUtils.difference(currentHeading, overlayPositionAndScale.getHeading())) > MIN_HEADING_DELTA; } boolean needsRepaintForDistance() { @@ -948,7 +955,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto return false; } - final Location lastLocation = overlayCaches.getCoordinates(); + final Location lastLocation = overlayPositionAndScale.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 21692d6..cd2ff75 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,7 +23,6 @@ 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; @@ -48,10 +47,8 @@ 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, Activity activity) { + public CachesOverlay(ItemizedOverlayImpl ovlImpl, Context contextIn) { super(ovlImpl); populate(); @@ -60,8 +57,6 @@ 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) { @@ -102,95 +97,59 @@ public class CachesOverlay extends AbstractItemizedOverlay { @Override public void draw(Canvas canvas, MapViewImpl mapView, boolean shadow) { - drawInternalBefore(canvas, mapView.getMapProjection(), mapView); + + drawInternal(canvas, mapView.getMapProjection()); + super.draw(canvas, mapView, false); - drawInternalAfter(canvas, mapView.getMapProjection(), mapView); } @Override public void drawOverlayBitmap(Canvas canvas, Point drawPosition, MapProjectionImpl projection, byte drawZoomLevel) { - drawInternalBefore(canvas, projection, getOverlayImpl().getMapViewImpl()); - super.drawOverlayBitmap(canvas, drawPosition, projection, drawZoomLevel); - drawInternalAfter(canvas, projection, getOverlayImpl().getMapViewImpl()); - } - private void drawInternalBefore(Canvas canvas, MapProjectionImpl projection, MapViewImpl mapView) { - // prevent content changes - getOverlayImpl().lock(); - try { - drawCircles(canvas, projection); - } finally { - getOverlayImpl().unlock(); - } - } + drawInternal(canvas, projection); - private void drawInternalAfter(Canvas canvas, MapProjectionImpl projection, MapViewImpl mapView) { - // prevent content changes - getOverlayImpl().lock(); - try { - scaleDrawer.drawScale(canvas, mapView); - positionDrawer.drawPosition(canvas, projection); - } finally { - getOverlayImpl().unlock(); - } + super.drawOverlayBitmap(canvas, drawPosition, projection, drawZoomLevel); } - private void drawCircles(Canvas canvas, MapProjectionImpl projection) { + private void drawInternal(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); + // 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); + } finally { + getOverlayImpl().unlock(); } - 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); } /** diff --git a/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java b/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java index aecd1c9..6b34b75 100644 --- a/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java +++ b/main/src/cgeo/geocaching/maps/PositionAndScaleOverlay.java @@ -8,18 +8,36 @@ 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); + 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(); } @Override @@ -36,8 +54,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 @@ -45,4 +63,11 @@ 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 adfa8b5..3339650 100644 --- a/main/src/cgeo/geocaching/maps/google/GoogleCacheOverlay.java +++ b/main/src/cgeo/geocaching/maps/google/GoogleCacheOverlay.java @@ -8,7 +8,6 @@ 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; @@ -25,9 +24,9 @@ public class GoogleCacheOverlay extends ItemizedOverlay<GoogleCacheOverlayItem> private CachesOverlay base; private Lock lock = new ReentrantLock(); - public GoogleCacheOverlay(Context contextIn, Drawable markerIn, Activity activity) { + public GoogleCacheOverlay(Context contextIn, Drawable markerIn) { super(boundCenterBottom(markerIn)); - base = new CachesOverlay(this, contextIn, activity); + base = new CachesOverlay(this, contextIn); } @Override diff --git a/main/src/cgeo/geocaching/maps/google/GoogleMapView.java b/main/src/cgeo/geocaching/maps/google/GoogleMapView.java index 735e3ce..d02e3c2 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, Activity activity) { + public CachesOverlay createAddMapOverlay(Context context, Drawable drawable) { - GoogleCacheOverlay ovl = new GoogleCacheOverlay(context, drawable, activity); + GoogleCacheOverlay ovl = new GoogleCacheOverlay(context, drawable); 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 f30220a..cb7ddc6 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, Activity activity); + CachesOverlay createAddMapOverlay(Context context, Drawable drawable); 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 5805ba0..9e14e36 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlay.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlay.java @@ -8,7 +8,6 @@ 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; @@ -22,9 +21,9 @@ public class MapsforgeCacheOverlay extends ItemizedOverlay<MapsforgeCacheOverlay private CachesOverlay base; private Lock lock = new ReentrantLock(); - public MapsforgeCacheOverlay(Context contextIn, Drawable markerIn, Activity activity) { + public MapsforgeCacheOverlay(Context contextIn, Drawable markerIn) { super(boundCenterBottom(markerIn)); - base = new CachesOverlay(this, contextIn, activity); + base = new CachesOverlay(this, contextIn); } @Override diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java index 26e707a..78aa47d 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, Activity activity) { + public CachesOverlay createAddMapOverlay(Context context, Drawable drawable) { - MapsforgeCacheOverlay ovl = new MapsforgeCacheOverlay(context, drawable, activity); + MapsforgeCacheOverlay ovl = new MapsforgeCacheOverlay(context, drawable); 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 77848f2..30355fd 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlay.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlay.java @@ -8,7 +8,6 @@ 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; @@ -22,9 +21,9 @@ public class MapsforgeCacheOverlay extends ItemizedOverlay<MapsforgeCacheOverlay private CachesOverlay base; private Lock lock = new ReentrantLock(); - public MapsforgeCacheOverlay(Context contextIn, Drawable markerIn, Activity activity) { + public MapsforgeCacheOverlay(Context contextIn, Drawable markerIn) { super(boundCenterBottom(markerIn)); - base = new CachesOverlay(this, contextIn, activity); + base = new CachesOverlay(this, contextIn); } @Override diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java index 55b3e0a..c741a31 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, Activity activity) { + public CachesOverlay createAddMapOverlay(Context context, Drawable drawable) { - MapsforgeCacheOverlay ovl = new MapsforgeCacheOverlay(context, drawable, activity); + MapsforgeCacheOverlay ovl = new MapsforgeCacheOverlay(context, drawable); getOverlays().add(ovl); return ovl.getBase(); } |