diff options
17 files changed, 81 insertions, 44 deletions
diff --git a/main/.classpath b/main/.classpath index f3ebe20..8b36cb6 100644 --- a/main/.classpath +++ b/main/.classpath @@ -5,9 +5,9 @@ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry exported="true" kind="lib" path="libs/commons-lang3-3.1.jar"/> <classpathentry kind="lib" path="libs/locus-api-4.0.jar"/> - <classpathentry kind="lib" path="libs/mapsforge-map-0.2.4.jar"/> <classpathentry kind="lib" path="libs/commons-collections-3.2.1.jar"/> <classpathentry kind="lib" path="libs/android-support-v4.jar"/> + <classpathentry kind="lib" path="libs/mapsforge-map-0.3.0-jar-with-dependencies.jar"/> <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> <classpathentry kind="output" path="bin/classes"/> </classpath> diff --git a/main/libs/mapsforge-map-0.2.4.jar b/main/libs/mapsforge-map-0.2.4.jar Binary files differdeleted file mode 100644 index 858ef3e..0000000 --- a/main/libs/mapsforge-map-0.2.4.jar +++ /dev/null diff --git a/main/libs/mapsforge-map-0.3.0-jar-with-dependencies.jar b/main/libs/mapsforge-map-0.3.0-jar-with-dependencies.jar Binary files differnew file mode 100644 index 0000000..e8cdd62 --- /dev/null +++ b/main/libs/mapsforge-map-0.3.0-jar-with-dependencies.jar diff --git a/main/res/values/strings.xml b/main/res/values/strings.xml index ca15692..625e90a 100644 --- a/main/res/values/strings.xml +++ b/main/res/values/strings.xml @@ -218,7 +218,7 @@ <string name="warn_search_help_tb">Enter the code for a trackable. For example \"TB29QMZ\".</string> <string name="warn_log_text_fill">Please fill in text for your log.</string> <string name="warn_load_images">c:geo failed to load images.</string> - <string name="warn_invalid_mapfile">The selected map file is not a valid mapsforge version 0.2.4 map file.\nOffline maps are not available.</string> + <string name="warn_invalid_mapfile">The selected map file is not a valid mapsforge version 0.3.0 map file.\nOffline maps are not available.</string> <string name="info_log_posted">c:geo successfully submitted the log.</string> <string name="info_log_saved">c:geo successfully saved the log.</string> diff --git a/main/src/cgeo/geocaching/Settings.java b/main/src/cgeo/geocaching/Settings.java index 3b36b23..08a9415 100644 --- a/main/src/cgeo/geocaching/Settings.java +++ b/main/src/cgeo/geocaching/Settings.java @@ -430,6 +430,15 @@ public final class Settings { }); } + public static boolean isValidMapFile() { + return checkMapfile(getMapFile()); + } + + private static boolean checkMapfile(final String mapFileIn) { + + return MapsforgeMapProvider.isValidMapFile(mapFileIn); + } + public static boolean isValidMapFile(final String mapFileIn) { return MapsforgeMapProvider.isValidMapFile(mapFileIn); } diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index d64b6a0..1b6be1e 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -469,10 +469,6 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto public void onResume() { super.onResume(); - if (changeMapSource(Settings.getMapSource())) { - return; - } - app.setAction(StringUtils.defaultIfBlank(geocodeIntent, null)); addGeoDirObservers(); diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlay.java index 6ea4478..0bd2484 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlay.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlay.java @@ -5,8 +5,8 @@ import cgeo.geocaching.maps.interfaces.ItemizedOverlayImpl; import cgeo.geocaching.maps.interfaces.MapProjectionImpl; import cgeo.geocaching.maps.interfaces.MapViewImpl; -import org.mapsforge.android.maps.ItemizedOverlay; import org.mapsforge.android.maps.Projection; +import org.mapsforge.android.maps.overlay.ItemizedOverlay; import android.content.Context; import android.graphics.Canvas; diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlayItem.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlayItem.java index f2ffae7..b56a2c4 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlayItem.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlayItem.java @@ -4,8 +4,8 @@ import cgeo.geocaching.IWaypoint; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; -import org.mapsforge.android.maps.GeoPoint; -import org.mapsforge.android.maps.OverlayItem; +import org.mapsforge.android.maps.overlay.OverlayItem; +import org.mapsforge.core.GeoPoint; import android.graphics.drawable.Drawable; diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeGeoPoint.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeGeoPoint.java index 490822b..197bd76 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeGeoPoint.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeGeoPoint.java @@ -3,10 +3,12 @@ package cgeo.geocaching.maps.mapsforge; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.maps.interfaces.GeoPointImpl; -import org.mapsforge.android.maps.GeoPoint; +import org.mapsforge.core.GeoPoint; public class MapsforgeGeoPoint extends GeoPoint implements GeoPointImpl { + private static final long serialVersionUID = 1L; + public MapsforgeGeoPoint(int latitudeE6, int longitudeE6) { super(latitudeE6, longitudeE6); } @@ -15,4 +17,14 @@ public class MapsforgeGeoPoint extends GeoPoint implements GeoPointImpl { public Geopoint getCoords() { return new Geopoint(getLatitudeE6() / 1e6, getLongitudeE6() / 1e6); } + + @Override + public int getLatitudeE6() { + return latitudeE6; + } + + @Override + public int getLongitudeE6() { + return longitudeE6; + } } diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapController.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapController.java index 9cdb80f..db81609 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapController.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapController.java @@ -3,8 +3,8 @@ package cgeo.geocaching.maps.mapsforge; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapControllerImpl; -import org.mapsforge.android.maps.GeoPoint; import org.mapsforge.android.maps.MapController; +import org.mapsforge.core.GeoPoint; public class MapsforgeMapController implements MapControllerImpl { diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProjection.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProjection.java index 268825d..68d7123 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProjection.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProjection.java @@ -3,8 +3,8 @@ package cgeo.geocaching.maps.mapsforge; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapProjectionImpl; -import org.mapsforge.android.maps.GeoPoint; import org.mapsforge.android.maps.Projection; +import org.mapsforge.core.GeoPoint; import android.graphics.Point; diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java index c119fd0..f9882e0 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java @@ -12,12 +12,15 @@ import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapProvider; import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl; -import org.mapsforge.android.maps.MapDatabase; +import org.apache.commons.lang3.StringUtils; +import org.mapsforge.map.reader.MapDatabase; +import org.mapsforge.map.reader.header.FileOpenResult; import android.app.Activity; import android.content.Context; import android.content.res.Resources; +import java.io.File; import java.util.HashMap; import java.util.Map; @@ -61,6 +64,19 @@ public class MapsforgeMapProvider implements MapProvider { return 0; } + public static boolean isValidMapFile(String mapFileIn) { + + if (StringUtils.isEmpty(mapFileIn)) { + return false; + } + + MapDatabase mapDB = new MapDatabase(); + FileOpenResult result = mapDB.openFile(new File(mapFileIn)); + mapDB.closeFile(); + + return result.isSuccess(); + } + @Override public Class<? extends Activity> getMapClass() { return MapsforgeMapActivity.class; @@ -90,9 +106,4 @@ public class MapsforgeMapProvider implements MapProvider { public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context, Go4CacheUser userOne) { return new MapsforgeOtherCachersOverlayItem(context, userOne); } - - public static boolean isValidMapFile(String mapFileIn) { - return MapDatabase.isValidMapFile(mapFileIn); - } - } diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java index aaede4d..1e37087 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java @@ -17,11 +17,13 @@ import cgeo.geocaching.maps.interfaces.OverlayImpl; import cgeo.geocaching.maps.interfaces.OverlayImpl.overlayType; import cgeo.geocaching.utils.Log; -import org.mapsforge.android.maps.GeoPoint; import org.mapsforge.android.maps.MapView; -import org.mapsforge.android.maps.MapViewMode; -import org.mapsforge.android.maps.Overlay; import org.mapsforge.android.maps.Projection; +import org.mapsforge.android.maps.mapgenerator.MapGenerator; +import org.mapsforge.android.maps.mapgenerator.MapGeneratorFactory; +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; @@ -33,6 +35,7 @@ import android.view.GestureDetector.SimpleOnGestureListener; import android.view.MotionEvent; import android.widget.Toast; +import java.io.File; public class MapsforgeMapView extends MapView implements MapViewImpl { private GestureDetector gestureDetector; private OnMapDragListener onDragListener; @@ -62,13 +65,13 @@ public class MapsforgeMapView extends MapView implements MapViewImpl { @Override public MapControllerImpl getMapController() { - return new MapsforgeMapController(getController(), getMaxZoomLevel()); + return new MapsforgeMapController(getController(), getMapGenerator().getZoomLevelMax()); } @Override public GeoPointImpl getMapViewCenter() { - GeoPoint point = getMapCenter(); - return new MapsforgeGeoPoint(point.getLatitudeE6(), point.getLongitudeE6()); + GeoPoint point = getMapPosition().getMapCenter(); + return new MapsforgeGeoPoint(point.latitudeE6, point.longitudeE6); } @Override @@ -133,7 +136,7 @@ public class MapsforgeMapView extends MapView implements MapViewImpl { GeoPoint high = projection.fromPixels(0, getHeight()); if (low != null && high != null) { - span = Math.abs(high.getLatitudeE6() - low.getLatitudeE6()); + span = Math.abs(high.latitudeE6 - low.latitudeE6); } } @@ -152,7 +155,7 @@ public class MapsforgeMapView extends MapView implements MapViewImpl { GeoPoint high = projection.fromPixels(getWidth(), 0); if (low != null && high != null) { - span = Math.abs(high.getLongitudeE6() - low.getLongitudeE6()); + span = Math.abs(high.longitudeE6 - low.longitudeE6); } } @@ -166,29 +169,35 @@ public class MapsforgeMapView extends MapView implements MapViewImpl { @Override public int getMapZoomLevel() { - return getZoomLevel() + 1; + return getMapPosition().getZoomLevel() + 1; } @Override public void setMapSource() { + MapGeneratorInternal newMapType = MapGeneratorInternal.MAPNIK; switch (MapsforgeMapProvider.getMapsforgeSource(Settings.getMapSource())) { case MapsforgeMapProvider.CYCLEMAP: - setMapViewMode(MapViewMode.OPENCYCLEMAP_TILE_DOWNLOAD); + newMapType = MapGeneratorInternal.OPENCYCLEMAP; break; case MapsforgeMapProvider.OFFLINE: - setMapViewMode(MapViewMode.CANVAS_RENDERER); - super.setMapFile(Settings.getMapFile()); - if (!Settings.isValidMapFile(Settings.getMapFile())) { - Toast.makeText( - getContext(), - getContext().getResources().getString(R.string.warn_invalid_mapfile), - Toast.LENGTH_LONG) - .show(); - } + newMapType = MapGeneratorInternal.DATABASE_RENDERER; break; default: - setMapViewMode(MapViewMode.MAPNIK_TILE_DOWNLOAD); + newMapType = MapGeneratorInternal.MAPNIK; + } + + MapGenerator mapGenerator = MapGeneratorFactory.createMapGenerator(newMapType); + setMapGenerator(mapGenerator); + if (!mapGenerator.requiresInternetConnection()) { + setMapFile(new File(Settings.getMapFile())); + if (!Settings.isValidMapFile(Settings.getMapFile())) { + Toast.makeText( + getContext(), + getContext().getResources().getString(R.string.warn_invalid_mapfile), + Toast.LENGTH_LONG) + .show(); + } } } diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlay.java index 277f2d9..66aa13e 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlay.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlay.java @@ -5,8 +5,8 @@ import cgeo.geocaching.maps.interfaces.ItemizedOverlayImpl; import cgeo.geocaching.maps.interfaces.MapProjectionImpl; import cgeo.geocaching.maps.interfaces.MapViewImpl; -import org.mapsforge.android.maps.ItemizedOverlay; import org.mapsforge.android.maps.Projection; +import org.mapsforge.android.maps.overlay.ItemizedOverlay; import android.content.Context; import android.graphics.Canvas; diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlayItem.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlayItem.java index 7795968..6a8c181 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlayItem.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlayItem.java @@ -4,8 +4,8 @@ import cgeo.geocaching.go4cache.Go4CacheUser; import cgeo.geocaching.maps.OtherCachersOverlayItem; import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl; -import org.mapsforge.android.maps.GeoPoint; -import org.mapsforge.android.maps.OverlayItem; +import org.mapsforge.android.maps.overlay.OverlayItem; +import org.mapsforge.core.GeoPoint; import android.content.Context; import android.graphics.drawable.Drawable; diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java index c32d39d..b6e31a2 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java @@ -6,8 +6,8 @@ import cgeo.geocaching.maps.interfaces.GeneralOverlay; import cgeo.geocaching.maps.interfaces.MapViewImpl; import cgeo.geocaching.maps.interfaces.OverlayImpl; -import org.mapsforge.android.maps.Overlay; import org.mapsforge.android.maps.Projection; +import org.mapsforge.android.maps.overlay.Overlay; import android.app.Activity; import android.graphics.Canvas; diff --git a/tests/src/cgeo/geocaching/SettingsTest.java b/tests/src/cgeo/geocaching/SettingsTest.java index 27395ec..5c03396 100644 --- a/tests/src/cgeo/geocaching/SettingsTest.java +++ b/tests/src/cgeo/geocaching/SettingsTest.java @@ -1,6 +1,6 @@ package cgeo.geocaching; -import org.mapsforge.android.maps.MapDatabase; +import cgeo.geocaching.maps.mapsforge.MapsforgeMapProvider; import android.test.ActivityInstrumentationTestCase2; @@ -23,6 +23,6 @@ public class SettingsTest extends ActivityInstrumentationTestCase2<cgeo> { final String mapFile = Settings.getMapFile(); assertNotNull(mapFile); // We just want to ensure that it does not throw any exception but we do not know anything about the result - MapDatabase.isValidMapFile(mapFile); + MapsforgeMapProvider.isValidMapFile(mapFile); } } |