diff options
Diffstat (limited to 'main/src/cgeo/geocaching/maps')
10 files changed, 127 insertions, 98 deletions
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index f892622..0817170 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -156,12 +156,12 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto private ScaleOverlay overlayScale = null; private PositionOverlay overlayPosition = null; // data for overlays - private static final int[][] INSET_RELIABLE = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }; // center, 33x40 / 45x51 - private static final int[][] INSET_TYPE = { { 5, 8, 6, 10 }, { 4, 4, 5, 11 } }; // center, 22x22 / 36x36 - private static final int[][] INSET_OWN = { { 21, 0, 0, 26 }, { 25, 0, 0, 35 } }; // top right, 12x12 / 16x16 - private static final int[][] INSET_FOUND = { { 0, 0, 21, 28 }, { 0, 0, 25, 35 } }; // top left, 12x12 / 16x16 - private static final int[][] INSET_USERMODIFIEDCOORDS = { { 21, 28, 0, 0 }, { 19, 25, 0, 0 } }; // bottom right, 12x12 / 26x26 - private static final int[][] INSET_PERSONALNOTE = { { 0, 28, 21, 0 }, { 0, 25, 19, 0 } }; // bottom left, 12x12 / 26x26 + 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 + private static final int[][] INSET_OWN = { { 21, 0, 0, 26 }, { 25, 0, 0, 35 }, { 40, 0, 0, 48 } }; // top right, 12x12 / 16x16 / 20x20 + private static final int[][] INSET_FOUND = { { 0, 0, 21, 28 }, { 0, 0, 25, 35 }, { 0, 0, 40, 48 } }; // top left, 12x12 / 16x16 / 20x20 + private static final int[][] INSET_USERMODIFIEDCOORDS = { { 21, 28, 0, 0 }, { 19, 25, 0, 0 }, { 25, 33, 0, 0 } }; // bottom right, 12x12 / 26x26 / 35x35 + private static final int[][] INSET_PERSONALNOTE = { { 0, 28, 21, 0 }, { 0, 25, 19, 0 }, { 0, 33, 25, 0 } }; // bottom left, 12x12 / 26x26 / 35x35 private SparseArray<LayerDrawable> overlaysCache = new SparseArray<LayerDrawable>(); /** Count of caches currently visible */ @@ -1179,33 +1179,29 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } searchResult = ConnectorFactory.searchByViewport(viewport.resize(0.8), tokens); - if (searchResult != null) { - downloaded = true; - if (searchResult.getError() == StatusCode.NOT_LOGGED_IN && Settings.isGCConnectorActive()) { - Login.login(); - tokens = null; - } else { - break; - } + downloaded = true; + if (searchResult.getError() == StatusCode.NOT_LOGGED_IN && Settings.isGCConnectorActive()) { + Login.login(); + tokens = null; + } else { + break; } count++; } while (count < 2); - if (searchResult != null) { - Set<Geocache> result = searchResult.getCachesFromSearchResult(LoadFlags.LOAD_CACHE_OR_DB); - CGeoMap.filter(result); - // update the caches - // first remove filtered out - final Set<String> filteredCodes = searchResult.getFilteredGeocodes(); - Log.d("Filtering out " + filteredCodes.size() + " caches: " + filteredCodes.toString()); - caches.removeAll(cgData.loadCaches(filteredCodes, LoadFlags.LOAD_CACHE_ONLY)); - cgData.removeCaches(filteredCodes, EnumSet.of(RemoveFlag.REMOVE_CACHE)); - // new collection type needs to remove first to refresh - caches.removeAll(result); - caches.addAll(result); - lastSearchResult = searchResult; - } + Set<Geocache> result = searchResult.getCachesFromSearchResult(LoadFlags.LOAD_CACHE_OR_DB); + CGeoMap.filter(result); + // update the caches + // first remove filtered out + final Set<String> filteredCodes = searchResult.getFilteredGeocodes(); + Log.d("Filtering out " + filteredCodes.size() + " caches: " + filteredCodes.toString()); + caches.removeAll(cgData.loadCaches(filteredCodes, LoadFlags.LOAD_CACHE_ONLY)); + cgData.removeCaches(filteredCodes, EnumSet.of(RemoveFlag.REMOVE_CACHE)); + // new collection type needs to remove first to refresh + caches.removeAll(result); + caches.addAll(result); + lastSearchResult = searchResult; //render displayExecutor.execute(new DisplayRunnable(viewport)); @@ -1677,7 +1673,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto // background: disabled or not final Drawable marker = getResources().getDrawable(cache.getMapMarkerId()); layers.add(marker); - final int resolution = marker.getIntrinsicWidth() > 40 ? 1 : 0; + final int resolution = marker.getIntrinsicWidth() > 40 ? (marker.getIntrinsicWidth() > 50 ? 2 : 1) : 0; // reliable or not if (!cache.isReliableLatLon()) { insets.add(INSET_RELIABLE[resolution]); diff --git a/main/src/cgeo/geocaching/maps/PositionHistory.java b/main/src/cgeo/geocaching/maps/PositionHistory.java new file mode 100644 index 0000000..9b090fc --- /dev/null +++ b/main/src/cgeo/geocaching/maps/PositionHistory.java @@ -0,0 +1,63 @@ +package cgeo.geocaching.maps; + +import android.location.Location; + +import java.util.ArrayList; + +/** + * Map trail history + */ +public class PositionHistory { + + /** + * minimum distance between two recorded points of the trail + */ + private static final double MINIMUM_DISTANCE_METERS = 10.0; + + /** + * maximum number of positions to remember + */ + private static final int MAX_POSITIONS = 700; + + private ArrayList<Location> history = new ArrayList<Location>(); + + /** + * Adds the current position to the trail history to be able to show the trail on the map. + */ + void rememberTrailPosition(Location coordinates) { + if (coordinates.getAccuracy() >= 50f) { + return; + } + if (coordinates.getLatitude() == 0.0 && coordinates.getLatitude() == 0.0) { + return; + } + if (history.isEmpty()) { + history.add(coordinates); + return; + } + + Location historyRecent = history.get(history.size() - 1); + if (historyRecent.distanceTo(coordinates) <= MINIMUM_DISTANCE_METERS) { + return; + } + + history.add(coordinates); + + // avoid running out of memory + final int itemsToRemove = getHistory().size() - MAX_POSITIONS; + if (itemsToRemove > 0) { + for (int i = 0; i < itemsToRemove; i++) { + getHistory().remove(0); + } + } + } + + public ArrayList<Location> getHistory() { + return history; + } + + public void setHistory(ArrayList<Location> history) { + this.history = history; + } + +}
\ No newline at end of file diff --git a/main/src/cgeo/geocaching/maps/PositionOverlay.java b/main/src/cgeo/geocaching/maps/PositionOverlay.java index c3a0834..39f4987 100644 --- a/main/src/cgeo/geocaching/maps/PositionOverlay.java +++ b/main/src/cgeo/geocaching/maps/PositionOverlay.java @@ -1,7 +1,6 @@ package cgeo.geocaching.maps; import cgeo.geocaching.R; -import cgeo.geocaching.settings.Settings; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.maps.interfaces.GeneralOverlay; import cgeo.geocaching.maps.interfaces.GeoPointImpl; @@ -9,6 +8,7 @@ import cgeo.geocaching.maps.interfaces.MapItemFactory; import cgeo.geocaching.maps.interfaces.MapProjectionImpl; import cgeo.geocaching.maps.interfaces.MapViewImpl; import cgeo.geocaching.maps.interfaces.OverlayImpl; +import cgeo.geocaching.settings.Settings; import android.app.Activity; import android.graphics.Bitmap; @@ -37,10 +37,7 @@ public class PositionOverlay implements GeneralOverlay { private int heightArrowHalf = 0; private PaintFlagsDrawFilter setfil = null; private PaintFlagsDrawFilter remfil = null; - private Location historyRecent = null; - private ArrayList<Location> history = new ArrayList<Location>(); - private Point historyPointN = new Point(); - private Point historyPointP = new Point(); + private PositionHistory positionHistory = new PositionHistory(); private Activity activity; private MapItemFactory mapItemFactory = null; private OverlayImpl ovlImpl = null; @@ -139,67 +136,40 @@ public class PositionOverlay implements GeneralOverlay { accuracyCircle.setStyle(Style.FILL); canvas.drawCircle(center.x, center.y, radius, accuracyCircle); - if (coordinates.getAccuracy() < 50f && ((historyRecent != null && historyRecent.distanceTo(coordinates) > 5.0) || historyRecent == null)) { - if (historyRecent != null) { - history.add(historyRecent); - } - historyRecent = coordinates; - - int toRemove = history.size() - 700; - - if (toRemove > 0) { - for (int cnt = 0; cnt < toRemove; cnt++) { - history.remove(cnt); - } - } - } + positionHistory.rememberTrailPosition(coordinates); if (Settings.isMapTrail()) { - int size = history.size(); + int size = positionHistory.getHistory().size(); if (size > 1) { int alphaCnt = size - 201; if (alphaCnt < 1) { alphaCnt = 1; } + Point pointNow = new Point(); + Point pointPrevious = new Point(); + Location prev = positionHistory.getHistory().get(0); + projection.toPixels(mapItemFactory.getGeoPointBase(new Geopoint(prev)), pointPrevious); + for (int cnt = 1; cnt < size; cnt++) { - Location prev = history.get(cnt - 1); - Location now = history.get(cnt); - - if (prev != null && now != null) { - projection.toPixels(mapItemFactory.getGeoPointBase(new Geopoint(prev)), historyPointP); - projection.toPixels(mapItemFactory.getGeoPointBase(new Geopoint(now)), historyPointN); - - int alpha; - if ((alphaCnt - cnt) > 0) { - alpha = 255 / (alphaCnt - cnt); - } - else { - alpha = 255; - } - - historyLineShadow.setAlpha(alpha); - historyLine.setAlpha(alpha); - - canvas.drawLine(historyPointP.x, historyPointP.y, historyPointN.x, historyPointN.y, historyLineShadow); - canvas.drawLine(historyPointP.x, historyPointP.y, historyPointN.x, historyPointN.y, historyLine); - } - } - } + Location now = positionHistory.getHistory().get(cnt); + projection.toPixels(mapItemFactory.getGeoPointBase(new Geopoint(now)), pointNow); - if (size > 0) { - Location prev = history.get(size - 1); - Location now = coordinates; + int alpha; + if ((alphaCnt - cnt) > 0) { + alpha = 255 / (alphaCnt - cnt); + } + else { + alpha = 255; + } - if (prev != null && now != null) { - projection.toPixels(mapItemFactory.getGeoPointBase(new Geopoint(prev)), historyPointP); - projection.toPixels(mapItemFactory.getGeoPointBase(new Geopoint(now)), historyPointN); + historyLineShadow.setAlpha(alpha); + historyLine.setAlpha(alpha); - historyLineShadow.setAlpha(255); - historyLine.setAlpha(255); + canvas.drawLine(pointPrevious.x, pointPrevious.y, pointNow.x, pointNow.y, historyLineShadow); + canvas.drawLine(pointPrevious.x, pointPrevious.y, pointNow.x, pointNow.y, historyLine); - canvas.drawLine(historyPointP.x, historyPointP.y, historyPointN.x, historyPointN.y, historyLineShadow); - canvas.drawLine(historyPointP.x, historyPointP.y, historyPointN.x, historyPointN.y, historyLine); + pointPrevious.set(pointNow.x, pointNow.y); } } } @@ -230,10 +200,10 @@ public class PositionOverlay implements GeneralOverlay { } public ArrayList<Location> getHistory() { - return history; + return positionHistory.getHistory(); } - public void setHistory(ArrayList<Location> inHistory) { - history = inHistory; + public void setHistory(ArrayList<Location> history) { + positionHistory.setHistory(history); } } diff --git a/main/src/cgeo/geocaching/maps/google/GoogleMapView.java b/main/src/cgeo/geocaching/maps/google/GoogleMapView.java index 6e5406e..3cf258e 100644 --- a/main/src/cgeo/geocaching/maps/google/GoogleMapView.java +++ b/main/src/cgeo/geocaching/maps/google/GoogleMapView.java @@ -14,7 +14,7 @@ import cgeo.geocaching.maps.interfaces.MapProjectionImpl; import cgeo.geocaching.maps.interfaces.MapViewImpl; import cgeo.geocaching.maps.interfaces.OnMapDragListener; import cgeo.geocaching.maps.interfaces.OverlayImpl; -import cgeo.geocaching.maps.interfaces.OverlayImpl.overlayType; +import cgeo.geocaching.maps.interfaces.OverlayImpl.OverlayType; import cgeo.geocaching.utils.Log; import com.google.android.maps.GeoPoint; @@ -121,7 +121,7 @@ public class GoogleMapView extends MapView implements MapViewImpl { @Override public PositionOverlay createAddPositionOverlay(Activity activity) { - GoogleOverlay ovl = new GoogleOverlay(activity, overlayType.PositionOverlay); + GoogleOverlay ovl = new GoogleOverlay(activity, OverlayType.PositionOverlay); getOverlays().add(ovl); return (PositionOverlay) ovl.getBase(); } @@ -129,7 +129,7 @@ public class GoogleMapView extends MapView implements MapViewImpl { @Override public ScaleOverlay createAddScaleOverlay(Activity activity) { - GoogleOverlay ovl = new GoogleOverlay(activity, overlayType.ScaleOverlay); + GoogleOverlay ovl = new GoogleOverlay(activity, OverlayType.ScaleOverlay); getOverlays().add(ovl); return (ScaleOverlay) ovl.getBase(); } diff --git a/main/src/cgeo/geocaching/maps/google/GoogleOverlay.java b/main/src/cgeo/geocaching/maps/google/GoogleOverlay.java index 773f9ff..bf4f606 100644 --- a/main/src/cgeo/geocaching/maps/google/GoogleOverlay.java +++ b/main/src/cgeo/geocaching/maps/google/GoogleOverlay.java @@ -20,7 +20,7 @@ public class GoogleOverlay extends Overlay implements OverlayImpl { private GeneralOverlay overlayBase = null; private Lock lock = new ReentrantLock(); - public GoogleOverlay(Activity activityIn, overlayType ovlType) { + public GoogleOverlay(Activity activityIn, OverlayType ovlType) { switch (ovlType) { case PositionOverlay: overlayBase = new PositionOverlay(activityIn, this); diff --git a/main/src/cgeo/geocaching/maps/interfaces/OverlayImpl.java b/main/src/cgeo/geocaching/maps/interfaces/OverlayImpl.java index 115b692..a17b5fb 100644 --- a/main/src/cgeo/geocaching/maps/interfaces/OverlayImpl.java +++ b/main/src/cgeo/geocaching/maps/interfaces/OverlayImpl.java @@ -6,7 +6,7 @@ package cgeo.geocaching.maps.interfaces; */ public interface OverlayImpl { - public enum overlayType { + public enum OverlayType { PositionOverlay, ScaleOverlay } diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java index 2b0c1f7..aa11405 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java @@ -14,7 +14,7 @@ import cgeo.geocaching.maps.interfaces.MapSource; import cgeo.geocaching.maps.interfaces.MapViewImpl; import cgeo.geocaching.maps.interfaces.OnMapDragListener; import cgeo.geocaching.maps.interfaces.OverlayImpl; -import cgeo.geocaching.maps.interfaces.OverlayImpl.overlayType; +import cgeo.geocaching.maps.interfaces.OverlayImpl.OverlayType; import cgeo.geocaching.utils.Log; import org.apache.commons.lang3.StringUtils; @@ -109,14 +109,14 @@ public class MapsforgeMapView extends MapView implements MapViewImpl { @Override public PositionOverlay createAddPositionOverlay(Activity activity) { - MapsforgeOverlay ovl = new MapsforgeOverlay(activity, overlayType.PositionOverlay); + MapsforgeOverlay ovl = new MapsforgeOverlay(activity, OverlayType.PositionOverlay); getOverlays().add(ovl); return (PositionOverlay) ovl.getBase(); } @Override public ScaleOverlay createAddScaleOverlay(Activity activity) { - MapsforgeOverlay ovl = new MapsforgeOverlay(activity, overlayType.ScaleOverlay); + MapsforgeOverlay ovl = new MapsforgeOverlay(activity, OverlayType.ScaleOverlay); getOverlays().add(ovl); return (ScaleOverlay) ovl.getBase(); } diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java index dd7fb75..a94b988 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java @@ -21,7 +21,7 @@ public class MapsforgeOverlay extends Overlay implements OverlayImpl { private GeneralOverlay overlayBase = null; private Lock lock = new ReentrantLock(); - public MapsforgeOverlay(Activity activityIn, OverlayImpl.overlayType ovlType) { + public MapsforgeOverlay(Activity activityIn, OverlayImpl.OverlayType ovlType) { switch (ovlType) { case PositionOverlay: diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java index 8e3a4d8..a074e70 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java @@ -13,7 +13,7 @@ import cgeo.geocaching.maps.interfaces.MapProjectionImpl; import cgeo.geocaching.maps.interfaces.MapViewImpl; import cgeo.geocaching.maps.interfaces.OnMapDragListener; import cgeo.geocaching.maps.interfaces.OverlayImpl; -import cgeo.geocaching.maps.interfaces.OverlayImpl.overlayType; +import cgeo.geocaching.maps.interfaces.OverlayImpl.OverlayType; import cgeo.geocaching.utils.Log; import org.mapsforge.android.mapsold.GeoPoint; @@ -103,14 +103,14 @@ public class MapsforgeMapView024 extends MapView implements MapViewImpl { @Override public PositionOverlay createAddPositionOverlay(Activity activity) { - MapsforgeOverlay ovl = new MapsforgeOverlay(activity, overlayType.PositionOverlay); + MapsforgeOverlay ovl = new MapsforgeOverlay(activity, OverlayType.PositionOverlay); getOverlays().add(ovl); return (PositionOverlay) ovl.getBase(); } @Override public ScaleOverlay createAddScaleOverlay(Activity activity) { - MapsforgeOverlay ovl = new MapsforgeOverlay(activity, overlayType.ScaleOverlay); + MapsforgeOverlay ovl = new MapsforgeOverlay(activity, OverlayType.ScaleOverlay); getOverlays().add(ovl); return (ScaleOverlay) 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 d40b539..bdaac98 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java @@ -21,7 +21,7 @@ public class MapsforgeOverlay extends Overlay implements OverlayImpl { private GeneralOverlay overlayBase = null; private Lock lock = new ReentrantLock(); - public MapsforgeOverlay(Activity activityIn, OverlayImpl.overlayType ovlType) { + public MapsforgeOverlay(Activity activityIn, OverlayImpl.OverlayType ovlType) { switch (ovlType) { case PositionOverlay: |
