aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorrsudev <rasch@munin-soft.de>2012-04-29 13:57:07 +0200
committerrsudev <rasch@munin-soft.de>2012-04-30 22:14:39 +0200
commitcc434abf47358f5abc62dc9ce4d01dfd56044acd (patch)
treed6758538ea6e55bc556a8e0267a679824f532ee5 /main
parent3a137b06bdfdd382dbe785baf7490dfc50c201dc (diff)
downloadcgeo-cc434abf47358f5abc62dc9ce4d01dfd56044acd.zip
cgeo-cc434abf47358f5abc62dc9ce4d01dfd56044acd.tar.gz
cgeo-cc434abf47358f5abc62dc9ce4d01dfd56044acd.tar.bz2
Compatibility for mapsforge 0.2.4 offline maps
Diffstat (limited to 'main')
-rw-r--r--main/.classpath1
-rw-r--r--main/AndroidManifest.xml5
-rw-r--r--main/libs/mapsforge-map-0.2.4.jarbin0 -> 392417 bytes
-rw-r--r--main/res/layout/map_mapsforge_old.xml48
-rw-r--r--main/res/values/strings.xml1
-rw-r--r--main/src/cgeo/geocaching/Settings.java2
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java22
-rw-r--r--main/src/cgeo/geocaching/maps/CachesOverlay.java9
-rw-r--r--main/src/cgeo/geocaching/maps/MapProviderFactory.java4
-rw-r--r--main/src/cgeo/geocaching/maps/PositionOverlay.java17
-rw-r--r--main/src/cgeo/geocaching/maps/google/GoogleMapItemFactory.java32
-rw-r--r--main/src/cgeo/geocaching/maps/google/GoogleMapProvider.java26
-rw-r--r--main/src/cgeo/geocaching/maps/interfaces/MapItemFactory.java18
-rw-r--r--main/src/cgeo/geocaching/maps/interfaces/MapProvider.java16
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapItemFactory.java33
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java65
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlay.java118
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlayItem.java36
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeGeoPoint.java18
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapActivity024.java122
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapController.java48
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java33
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapProjection.java29
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java239
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOtherCachersOverlay.java120
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOtherCachersOverlayItem.java31
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java63
27 files changed, 1082 insertions, 74 deletions
diff --git a/main/.classpath b/main/.classpath
index 8b36cb6..44706dc 100644
--- a/main/.classpath
+++ b/main/.classpath
@@ -8,6 +8,7 @@
<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 kind="lib" path="libs/mapsforge-map-0.2.4.jar"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
diff --git a/main/AndroidManifest.xml b/main/AndroidManifest.xml
index 9be66db..686c5ee 100644
--- a/main/AndroidManifest.xml
+++ b/main/AndroidManifest.xml
@@ -138,6 +138,11 @@
android:configChanges="keyboardHidden|orientation" >
</activity>
<activity
+ android:name=".maps.mapsforge.v024.MapsforgeMapActivity024"
+ android:label="@string/app_name"
+ android:configChanges="keyboardHidden|orientation" >
+ </activity>
+ <activity
android:name=".StaticMapsActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation" >
diff --git a/main/libs/mapsforge-map-0.2.4.jar b/main/libs/mapsforge-map-0.2.4.jar
new file mode 100644
index 0000000..ec9aa4c
--- /dev/null
+++ b/main/libs/mapsforge-map-0.2.4.jar
Binary files differ
diff --git a/main/res/layout/map_mapsforge_old.xml b/main/res/layout/map_mapsforge_old.xml
new file mode 100644
index 0000000..00ee46d
--- /dev/null
+++ b/main/res/layout/map_mapsforge_old.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical"
+ android:background="?background_color" >
+ <LinearLayout style="@style/action_bar">
+ <ImageView style="@style/action_bar_action"
+ android:onClick="goHome" />
+ <View style="@style/action_bar_separator" />
+ <TextView style="@style/action_bar_title" />
+ <ProgressBar style="@style/action_bar_progress"
+ android:visibility="gone" />
+ <View style="@style/action_bar_separator" />
+ <ImageSwitcher style="@style/action_bar_action"
+ android:id="@+id/my_position" />
+ <View style="@style/action_bar_separator" />
+ <ImageView style="@style/action_bar_action"
+ android:src="@drawable/actionbar_manual"
+ android:onClick="goManual" />
+ </LinearLayout>
+ <include layout="@layout/filter_bar"/>
+ <RelativeLayout
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" >
+ <TextView android:id="@+id/number"
+ android:visibility="gone"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_margin="5dip"
+ android:gravity="center_horizontal"
+ android:paddingLeft="5dip"
+ android:paddingRight="5dip"
+ android:lines="1"
+ android:singleLine="true"
+ android:scrollHorizontally="true"
+ android:ellipsize="marquee"
+ android:textSize="12dip"
+ android:textColor="@color/text_icon"
+ android:background="@drawable/icon_bcg" />
+ <view class="cgeo.geocaching.maps.mapsforge.v024.MapsforgeMapView024" android:id="@+id/mfmap_old"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:keepScreenOn="true"
+ android:enabled="true"
+ android:clickable="true" />
+ </RelativeLayout>
+</LinearLayout> \ No newline at end of file
diff --git a/main/res/values/strings.xml b/main/res/values/strings.xml
index 625e90a..98f7c90 100644
--- a/main/res/values/strings.xml
+++ b/main/res/values/strings.xml
@@ -219,6 +219,7 @@
<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.3.0 map file.\nOffline maps are not available.</string>
+ <string name="warn_deprecated_mapfile">You are using a deprecated version 0.2.4 map file.\nConsider switching to a version 0.3.0 map.\nWe will drop support for version 0.2.4 in the next release.</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 08a9415..e46516f 100644
--- a/main/src/cgeo/geocaching/Settings.java
+++ b/main/src/cgeo/geocaching/Settings.java
@@ -808,7 +808,7 @@ public final class Settings {
}
public static void setMapSource(final int newMapSource) {
- if (!MapProviderFactory.isSameProvider(getMapSource(), newMapSource)) {
+ if (!MapProviderFactory.isSameActivity(getMapSource(), newMapSource)) {
mapProvider = null;
}
editSharedSettings(new PrefRunnable() {
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index 1b6be1e..3e4cca3 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -9,11 +9,11 @@ import cgeo.geocaching.R;
import cgeo.geocaching.SearchResult;
import cgeo.geocaching.Settings;
import cgeo.geocaching.StoredList;
-import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgWaypoint;
import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.cgeocaches;
+import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.connector.ConnectorFactory;
import cgeo.geocaching.connector.gc.GCBase;
import cgeo.geocaching.connector.gc.Login;
@@ -30,6 +30,7 @@ import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl;
import cgeo.geocaching.maps.interfaces.GeoPointImpl;
import cgeo.geocaching.maps.interfaces.MapActivityImpl;
import cgeo.geocaching.maps.interfaces.MapControllerImpl;
+import cgeo.geocaching.maps.interfaces.MapItemFactory;
import cgeo.geocaching.maps.interfaces.MapProvider;
import cgeo.geocaching.maps.interfaces.MapViewImpl;
import cgeo.geocaching.maps.interfaces.OnMapDragListener;
@@ -117,6 +118,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
private Resources res = null;
private MapProvider mapProvider = null;
+ private MapItemFactory mapItemFactory = null;
private Activity activity = null;
private MapViewImpl mapView = null;
private MapControllerImpl mapController = null;
@@ -355,6 +357,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
activity = this.getActivity();
app = (cgeoapplication) activity.getApplication();
mapProvider = Settings.getMapProvider();
+ mapItemFactory = mapProvider.getMapItemFactory();
// Get parameters from the intent
@@ -738,7 +741,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
* @return true if a restart is needed, false otherwise
*/
private boolean changeMapSource(final int mapSource) {
- final boolean restartRequired = !MapProviderFactory.isSameProvider(currentSourceId, mapSource);
+ final boolean restartRequired = !MapProviderFactory.isSameActivity(currentSourceId, mapSource);
Settings.setMapSource(mapSource);
currentSourceId = mapSource;
@@ -1270,7 +1273,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
continue;
}
- item = mapProvider.getOtherCachersOverlayItemBase(activity, userOne);
+ item = mapItemFactory.getOtherCachersOverlayItemBase(activity, userOne);
items.add(item);
counter++;
@@ -1441,7 +1444,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
if (!centered && mapState != null) {
try {
- mapController.setCenter(mapProvider.getGeoPointBase(new Geopoint(mapState[0] / 1.0e6, mapState[1] / 1.0e6)));
+ mapController.setCenter(mapItemFactory.getGeoPointBase(new Geopoint(mapState[0] / 1.0e6, mapState[1] / 1.0e6)));
mapController.setZoom(mapState[2]);
} catch (Exception e) {
// nothing at all
@@ -1463,7 +1466,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
return;
}
- mapController.setCenter(mapProvider.getGeoPointBase(viewport.center));
+ mapController.setCenter(mapItemFactory.getGeoPointBase(viewport.center));
if (viewport.getLatitudeSpan() != 0 && viewport.getLongitudeSpan() != 0) {
mapController.zoomToSpan((int) (viewport.getLatitudeSpan() * 1e6), (int) (viewport.getLongitudeSpan() * 1e6));
}
@@ -1513,7 +1516,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
// make geopoint
private GeoPointImpl makeGeoPoint(final Geopoint coords) {
- return mapProvider.getGeoPointBase(coords);
+ return mapItemFactory.getGeoPointBase(coords);
}
// close activity and open homescreen
@@ -1592,7 +1595,9 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
*/
private CachesOverlayItemImpl getItem(final IWaypoint coord, final cgCache cache, final cgWaypoint waypoint) {
if (cache != null) {
- final CachesOverlayItemImpl item = mapProvider.getCachesOverlayItem(coord, cache.getType());
+ final CachesOverlayItemImpl item = mapItemFactory.getCachesOverlayItem(coord, cache.getType());
+
+
final int hashcode = new HashCodeBuilder()
.append(cache.isReliableLatLon())
.append(cache.getType().id)
@@ -1670,7 +1675,8 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
if (waypoint != null) {
- final CachesOverlayItemImpl item = mapProvider.getCachesOverlayItem(coord, null);
+
+ final CachesOverlayItemImpl item = mapItemFactory.getCachesOverlayItem(coord, null);
Drawable[] layers = new Drawable[2];
layers[0] = getResources().getDrawable(R.drawable.marker);
layers[1] = getResources().getDrawable(waypoint.getWaypointType().markerId);
diff --git a/main/src/cgeo/geocaching/maps/CachesOverlay.java b/main/src/cgeo/geocaching/maps/CachesOverlay.java
index d3a7865..923c5e4 100644
--- a/main/src/cgeo/geocaching/maps/CachesOverlay.java
+++ b/main/src/cgeo/geocaching/maps/CachesOverlay.java
@@ -9,6 +9,7 @@ import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl;
import cgeo.geocaching.maps.interfaces.GeoPointImpl;
import cgeo.geocaching.maps.interfaces.ItemizedOverlayImpl;
+import cgeo.geocaching.maps.interfaces.MapItemFactory;
import cgeo.geocaching.maps.interfaces.MapProjectionImpl;
import cgeo.geocaching.maps.interfaces.MapProvider;
import cgeo.geocaching.maps.interfaces.MapViewImpl;
@@ -39,6 +40,7 @@ public class CachesOverlay extends AbstractItemizedOverlay {
private PaintFlagsDrawFilter setFilter = null;
private PaintFlagsDrawFilter removeFilter = null;
private MapProvider mapProvider = null;
+ private MapItemFactory mapItemFactory = null;
public CachesOverlay(ItemizedOverlayImpl ovlImpl, Context contextIn) {
super(ovlImpl);
@@ -48,6 +50,7 @@ public class CachesOverlay extends AbstractItemizedOverlay {
context = contextIn;
mapProvider = Settings.getMapProvider();
+ mapItemFactory = mapProvider.getMapItemFactory();
}
public void updateItems(CachesOverlayItemImpl item) {
@@ -119,7 +122,7 @@ public class CachesOverlay extends AbstractItemizedOverlay {
for (CachesOverlayItemImpl item : items) {
final Geopoint itemCoord = item.getCoord().getCoords();
- final GeoPointImpl itemGeo = mapProvider.getGeoPointBase(itemCoord);
+ final GeoPointImpl itemGeo = mapItemFactory.getGeoPointBase(itemCoord);
projection.toPixels(itemGeo, center);
final CacheType type = item.getType();
@@ -159,11 +162,11 @@ public class CachesOverlay extends AbstractItemizedOverlay {
itemCoord.getLatitude(), itemCoord.getLongitude() + 1, distanceArray);
final float longitudeLineDistance = distanceArray[0];
- final GeoPointImpl itemGeo = mapProvider.getGeoPointBase(itemCoord);
+ final GeoPointImpl itemGeo = mapItemFactory.getGeoPointBase(itemCoord);
final Geopoint leftCoords = new Geopoint(itemCoord.getLatitude(),
itemCoord.getLongitude() - 161 / longitudeLineDistance);
- final GeoPointImpl leftGeo = mapProvider.getGeoPointBase(leftCoords);
+ final GeoPointImpl leftGeo = mapItemFactory.getGeoPointBase(leftCoords);
final Point center = new Point();
projection.toPixels(itemGeo, center);
diff --git a/main/src/cgeo/geocaching/maps/MapProviderFactory.java b/main/src/cgeo/geocaching/maps/MapProviderFactory.java
index 3509209..10ca12a 100644
--- a/main/src/cgeo/geocaching/maps/MapProviderFactory.java
+++ b/main/src/cgeo/geocaching/maps/MapProviderFactory.java
@@ -61,10 +61,10 @@ public class MapProviderFactory {
return getInstance().mapSources.containsKey(sourceId);
}
- public static boolean isSameProvider(int sourceId1, int sourceId2) {
+ public static boolean isSameActivity(int sourceId1, int sourceId2) {
for (MapProvider mp : getInstance().mapProviders) {
if (mp.isMySource(sourceId1) && mp.isMySource(sourceId2)) {
- return true;
+ return mp.isSameActivity(sourceId1, sourceId2);
}
}
return false;
diff --git a/main/src/cgeo/geocaching/maps/PositionOverlay.java b/main/src/cgeo/geocaching/maps/PositionOverlay.java
index 9099498..5c88f08 100644
--- a/main/src/cgeo/geocaching/maps/PositionOverlay.java
+++ b/main/src/cgeo/geocaching/maps/PositionOverlay.java
@@ -5,6 +5,7 @@ import cgeo.geocaching.Settings;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.maps.interfaces.GeneralOverlay;
import cgeo.geocaching.maps.interfaces.GeoPointImpl;
+import cgeo.geocaching.maps.interfaces.MapItemFactory;
import cgeo.geocaching.maps.interfaces.MapProjectionImpl;
import cgeo.geocaching.maps.interfaces.MapProvider;
import cgeo.geocaching.maps.interfaces.MapViewImpl;
@@ -44,17 +45,19 @@ public class PositionOverlay implements GeneralOverlay {
private Point historyPointP = new Point();
private Activity activity;
private MapProvider mapProvider = null;
+ private MapItemFactory mapItemFactory = null;
private OverlayImpl ovlImpl = null;
public PositionOverlay(Activity activity, OverlayImpl ovlImpl) {
this.activity = activity;
this.mapProvider = Settings.getMapProvider();
+ this.mapItemFactory = this.mapProvider.getMapItemFactory();
this.ovlImpl = ovlImpl;
}
public void setCoordinates(Location coordinatesIn) {
coordinates = coordinatesIn;
- location = mapProvider.getGeoPointBase(new Geopoint(coordinates));
+ location = mapItemFactory.getGeoPointBase(new Geopoint(coordinates));
}
public void setHeading(Float bearingNow) {
@@ -119,7 +122,7 @@ public class PositionOverlay implements GeneralOverlay {
float longitudeLineDistance = result[0];
final Geopoint leftCoords = new Geopoint(latitude, longitude - accuracy / longitudeLineDistance);
- GeoPointImpl leftGeo = mapProvider.getGeoPointBase(leftCoords);
+ GeoPointImpl leftGeo = mapItemFactory.getGeoPointBase(leftCoords);
projection.toPixels(leftGeo, left);
projection.toPixels(location, center);
int radius = center.x - left.x;
@@ -161,8 +164,8 @@ public class PositionOverlay implements GeneralOverlay {
Location now = history.get(cnt);
if (prev != null && now != null) {
- projection.toPixels(mapProvider.getGeoPointBase(new Geopoint(prev)), historyPointP);
- projection.toPixels(mapProvider.getGeoPointBase(new Geopoint(now)), historyPointN);
+ projection.toPixels(mapItemFactory.getGeoPointBase(new Geopoint(prev)), historyPointP);
+ projection.toPixels(mapItemFactory.getGeoPointBase(new Geopoint(now)), historyPointN);
if ((alphaCnt - cnt) > 0) {
alpha = 255 / (alphaCnt - cnt);
@@ -185,8 +188,8 @@ public class PositionOverlay implements GeneralOverlay {
Location now = coordinates;
if (prev != null && now != null) {
- projection.toPixels(mapProvider.getGeoPointBase(new Geopoint(prev)), historyPointP);
- projection.toPixels(mapProvider.getGeoPointBase(new Geopoint(now)), historyPointN);
+ projection.toPixels(mapItemFactory.getGeoPointBase(new Geopoint(prev)), historyPointP);
+ projection.toPixels(mapItemFactory.getGeoPointBase(new Geopoint(now)), historyPointN);
historyLineShadow.setAlpha(255);
historyLine.setAlpha(255);
@@ -224,4 +227,4 @@ public class PositionOverlay implements GeneralOverlay {
public OverlayImpl getOverlayImpl() {
return this.ovlImpl;
}
-} \ No newline at end of file
+}
diff --git a/main/src/cgeo/geocaching/maps/google/GoogleMapItemFactory.java b/main/src/cgeo/geocaching/maps/google/GoogleMapItemFactory.java
new file mode 100644
index 0000000..0e18dce
--- /dev/null
+++ b/main/src/cgeo/geocaching/maps/google/GoogleMapItemFactory.java
@@ -0,0 +1,32 @@
+package cgeo.geocaching.maps.google;
+
+import cgeo.geocaching.IWaypoint;
+import cgeo.geocaching.enumerations.CacheType;
+import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.go4cache.Go4CacheUser;
+import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl;
+import cgeo.geocaching.maps.interfaces.GeoPointImpl;
+import cgeo.geocaching.maps.interfaces.MapItemFactory;
+import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl;
+
+import android.content.Context;
+
+public class GoogleMapItemFactory implements MapItemFactory {
+
+ @Override
+ public GeoPointImpl getGeoPointBase(final Geopoint coords) {
+ return new GoogleGeoPoint(coords.getLatitudeE6(), coords.getLongitudeE6());
+ }
+
+ @Override
+ public CachesOverlayItemImpl getCachesOverlayItem(final IWaypoint coordinate, final CacheType type) {
+ GoogleCacheOverlayItem baseItem = new GoogleCacheOverlayItem(coordinate, type);
+ return baseItem;
+ }
+
+ @Override
+ public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context, Go4CacheUser userOne) {
+ GoogleOtherCachersOverlayItem baseItem = new GoogleOtherCachersOverlayItem(context, userOne);
+ return baseItem;
+ }
+}
diff --git a/main/src/cgeo/geocaching/maps/google/GoogleMapProvider.java b/main/src/cgeo/geocaching/maps/google/GoogleMapProvider.java
index b659042..1cccbe3 100644
--- a/main/src/cgeo/geocaching/maps/google/GoogleMapProvider.java
+++ b/main/src/cgeo/geocaching/maps/google/GoogleMapProvider.java
@@ -1,20 +1,13 @@
package cgeo.geocaching.maps.google;
-import cgeo.geocaching.IWaypoint;
import cgeo.geocaching.R;
import cgeo.geocaching.cgeoapplication;
-import cgeo.geocaching.enumerations.CacheType;
-import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.go4cache.Go4CacheUser;
import cgeo.geocaching.maps.MapProviderFactory;
-import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl;
-import cgeo.geocaching.maps.interfaces.GeoPointImpl;
+import cgeo.geocaching.maps.interfaces.MapItemFactory;
import cgeo.geocaching.maps.interfaces.MapProvider;
-import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl;
import com.google.android.maps.MapActivity;
-import android.content.Context;
import android.content.res.Resources;
import java.util.HashMap;
@@ -28,6 +21,7 @@ public class GoogleMapProvider implements MapProvider {
private final Map<Integer, String> mapSources;
private int baseId;
+ private final MapItemFactory mapItemFactory;
public GoogleMapProvider(int _baseId) {
baseId = _baseId;
@@ -36,6 +30,8 @@ public class GoogleMapProvider implements MapProvider {
mapSources = new HashMap<Integer, String>();
mapSources.put(baseId + MAP, resources.getString(R.string.map_source_google_map));
mapSources.put(baseId + SATELLITE, resources.getString(R.string.map_source_google_satellite));
+
+ mapItemFactory = new GoogleMapItemFactory();
}
@Override
@@ -76,18 +72,12 @@ public class GoogleMapProvider implements MapProvider {
}
@Override
- public GeoPointImpl getGeoPointBase(final Geopoint coords) {
- return new GoogleGeoPoint(coords.getLatitudeE6(), coords.getLongitudeE6());
+ public MapItemFactory getMapItemFactory() {
+ return mapItemFactory;
}
@Override
- public CachesOverlayItemImpl getCachesOverlayItem(final IWaypoint coordinate, final CacheType type) {
- return new GoogleCacheOverlayItem(coordinate, type);
+ public boolean isSameActivity(int sourceId1, int sourceId2) {
+ return true;
}
-
- @Override
- public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context, Go4CacheUser userOne) {
- return new GoogleOtherCachersOverlayItem(context, userOne);
- }
-
}
diff --git a/main/src/cgeo/geocaching/maps/interfaces/MapItemFactory.java b/main/src/cgeo/geocaching/maps/interfaces/MapItemFactory.java
new file mode 100644
index 0000000..c38739d
--- /dev/null
+++ b/main/src/cgeo/geocaching/maps/interfaces/MapItemFactory.java
@@ -0,0 +1,18 @@
+package cgeo.geocaching.maps.interfaces;
+
+import cgeo.geocaching.IWaypoint;
+import cgeo.geocaching.enumerations.CacheType;
+import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.go4cache.Go4CacheUser;
+
+import android.content.Context;
+
+public interface MapItemFactory {
+
+ public GeoPointImpl getGeoPointBase(final Geopoint coords);
+
+ public CachesOverlayItemImpl getCachesOverlayItem(final IWaypoint iWaypoint, final CacheType type);
+
+ public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context,
+ Go4CacheUser userOne);
+}
diff --git a/main/src/cgeo/geocaching/maps/interfaces/MapProvider.java b/main/src/cgeo/geocaching/maps/interfaces/MapProvider.java
index dd935c4..626a410 100644
--- a/main/src/cgeo/geocaching/maps/interfaces/MapProvider.java
+++ b/main/src/cgeo/geocaching/maps/interfaces/MapProvider.java
@@ -1,12 +1,6 @@
package cgeo.geocaching.maps.interfaces;
-import cgeo.geocaching.IWaypoint;
-import cgeo.geocaching.enumerations.CacheType;
-import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.go4cache.Go4CacheUser;
-
import android.app.Activity;
-import android.content.Context;
import java.util.Map;
@@ -23,17 +17,13 @@ public interface MapProvider {
public boolean isMySource(int sourceId);
+ public boolean isSameActivity(int sourceId1, int sourceId2);
+
public Class<? extends Activity> getMapClass();
public int getMapViewId();
public int getMapLayoutId();
- public GeoPointImpl getGeoPointBase(final Geopoint coords);
-
- public CachesOverlayItemImpl getCachesOverlayItem(final IWaypoint iWaypoint, final CacheType type);
-
- public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context,
- Go4CacheUser userOne);
-
+ public MapItemFactory getMapItemFactory();
}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapItemFactory.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapItemFactory.java
new file mode 100644
index 0000000..5e86f81
--- /dev/null
+++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapItemFactory.java
@@ -0,0 +1,33 @@
+package cgeo.geocaching.maps.mapsforge;
+
+import cgeo.geocaching.IWaypoint;
+import cgeo.geocaching.enumerations.CacheType;
+import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.go4cache.Go4CacheUser;
+import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl;
+import cgeo.geocaching.maps.interfaces.GeoPointImpl;
+import cgeo.geocaching.maps.interfaces.MapItemFactory;
+import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl;
+
+import android.content.Context;
+
+public class MapsforgeMapItemFactory implements MapItemFactory {
+
+ @Override
+ public GeoPointImpl getGeoPointBase(final Geopoint coords) {
+ return new MapsforgeGeoPoint(coords.getLatitudeE6(), coords.getLongitudeE6());
+ }
+
+ @Override
+ public CachesOverlayItemImpl getCachesOverlayItem(final IWaypoint coordinate, final CacheType type) {
+ MapsforgeCacheOverlayItem baseItem = new MapsforgeCacheOverlayItem(coordinate, type);
+ return baseItem;
+ }
+
+ @Override
+ public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context, Go4CacheUser userOne) {
+ MapsforgeOtherCachersOverlayItem baseItem = new MapsforgeOtherCachersOverlayItem(context, userOne);
+ return baseItem;
+ }
+
+}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java
index f9882e0..026dd50 100644
--- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java
+++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java
@@ -1,23 +1,19 @@
package cgeo.geocaching.maps.mapsforge;
-import cgeo.geocaching.IWaypoint;
import cgeo.geocaching.R;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.cgeoapplication;
-import cgeo.geocaching.enumerations.CacheType;
-import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.go4cache.Go4CacheUser;
import cgeo.geocaching.maps.MapProviderFactory;
-import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl;
-import cgeo.geocaching.maps.interfaces.GeoPointImpl;
+import cgeo.geocaching.maps.interfaces.MapItemFactory;
import cgeo.geocaching.maps.interfaces.MapProvider;
-import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl;
+import cgeo.geocaching.maps.mapsforge.v024.MapsforgeMapActivity024;
+import cgeo.geocaching.maps.mapsforge.v024.MapsforgeMapItemFactory024;
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;
@@ -33,6 +29,8 @@ public class MapsforgeMapProvider implements MapProvider {
private final Map<Integer, String> mapSources;
private final int baseId;
+ private boolean oldMap = false;
+ private MapItemFactory mapItemFactory = new MapsforgeMapItemFactory();
public MapsforgeMapProvider(int _baseId) {
baseId = _baseId;
@@ -74,36 +72,59 @@ public class MapsforgeMapProvider implements MapProvider {
FileOpenResult result = mapDB.openFile(new File(mapFileIn));
mapDB.closeFile();
- return result.isSuccess();
+ boolean isValid = result.isSuccess();
+
+ if (!isValid) {
+ isValid = isMapfile024(mapFileIn);
+ }
+
+ return isValid;
+ }
+
+ private static boolean isMapfile024(String mapFileIn) {
+ return org.mapsforge.android.mapsold.MapDatabase.isValidMapFile(mapFileIn);
+ }
+
+ @Override
+ public boolean isSameActivity(int sourceId1, int sourceId2) {
+ final int mfSourceId1 = getMapsforgeSource(sourceId1);
+ final int mfSourceId2 = getMapsforgeSource(sourceId2);
+ return mfSourceId1 == mfSourceId2 ||
+ !isMapfile024(Settings.getMapFile()) ||
+ mfSourceId1 != OFFLINE && mfSourceId2 != OFFLINE;
}
@Override
public Class<? extends Activity> getMapClass() {
+ int sourceId = getMapsforgeSource(Settings.getMapSource());
+
+ if (sourceId == OFFLINE && isMapfile024(Settings.getMapFile())) {
+ oldMap = true;
+ mapItemFactory = new MapsforgeMapItemFactory024();
+ return MapsforgeMapActivity024.class;
+ }
+ oldMap = false;
+ mapItemFactory = new MapsforgeMapItemFactory();
return MapsforgeMapActivity.class;
}
@Override
public int getMapViewId() {
+ if (oldMap) {
+ return R.id.mfmap_old;
+ }
return R.id.mfmap;
}
@Override
public int getMapLayoutId() {
+ if (oldMap) {
+ return R.layout.map_mapsforge_old;
+ }
return R.layout.map_mapsforge;
}
-
- @Override
- public GeoPointImpl getGeoPointBase(final Geopoint coords) {
- return new MapsforgeGeoPoint(coords.getLatitudeE6(), coords.getLongitudeE6());
- }
-
- @Override
- public CachesOverlayItemImpl getCachesOverlayItem(final IWaypoint coordinate, final CacheType type) {
- return new MapsforgeCacheOverlayItem(coordinate, type);
- }
-
@Override
- public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context, Go4CacheUser userOne) {
- return new MapsforgeOtherCachersOverlayItem(context, userOne);
+ public MapItemFactory getMapItemFactory() {
+ return mapItemFactory;
}
}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlay.java
new file mode 100644
index 0000000..581548f
--- /dev/null
+++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlay.java
@@ -0,0 +1,118 @@
+package cgeo.geocaching.maps.mapsforge.v024;
+
+import cgeo.geocaching.maps.CachesOverlay;
+import cgeo.geocaching.maps.interfaces.ItemizedOverlayImpl;
+import cgeo.geocaching.maps.interfaces.MapProjectionImpl;
+import cgeo.geocaching.maps.interfaces.MapViewImpl;
+
+import org.mapsforge.android.mapsold.ItemizedOverlay;
+import org.mapsforge.android.mapsold.Projection;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Point;
+import android.graphics.drawable.Drawable;
+
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+public class MapsforgeCacheOverlay extends ItemizedOverlay<MapsforgeCacheOverlayItem> implements ItemizedOverlayImpl {
+
+ private CachesOverlay base;
+ private Lock lock = new ReentrantLock();
+
+ public MapsforgeCacheOverlay(Context contextIn, Drawable markerIn) {
+ super(boundCenterBottom(markerIn));
+ base = new CachesOverlay(this, contextIn);
+ }
+
+ @Override
+ public CachesOverlay getBase() {
+ return base;
+ }
+
+ @Override
+ protected MapsforgeCacheOverlayItem createItem(int i) {
+ if (base == null) {
+ return null;
+ }
+
+ return (MapsforgeCacheOverlayItem) base.createItem(i);
+ }
+
+ @Override
+ public int size() {
+ if (base == null) {
+ return 0;
+ }
+
+ return base.size();
+ }
+
+ @Override
+ protected boolean onTap(int arg0) {
+ if (base == null) {
+ return false;
+ }
+
+ return base.onTap(arg0);
+ }
+
+ @Override
+ protected void drawOverlayBitmap(Canvas canvas, Point drawPosition,
+ Projection projection, byte drawZoomLevel) {
+ base.drawOverlayBitmap(canvas, drawPosition, new MapsforgeMapProjection(projection), drawZoomLevel);
+ }
+
+ @Override
+ public void superPopulate() {
+ populate();
+ }
+
+ @Override
+ public Drawable superBoundCenter(Drawable markerIn) {
+ return super.boundCenter(markerIn);
+ }
+
+ @Override
+ public Drawable superBoundCenterBottom(Drawable marker) {
+ return super.boundCenterBottom(marker);
+ }
+
+ @Override
+ public void superSetLastFocusedItemIndex(int i) {
+ // nothing to do
+ }
+
+ @Override
+ public boolean superOnTap(int index) {
+ return super.onTap(index);
+ }
+
+ @Override
+ public void superDraw(Canvas canvas, MapViewImpl mapView, boolean shadow) {
+ // nothing to do here...
+ }
+
+ @Override
+ public void superDrawOverlayBitmap(Canvas canvas, Point drawPosition,
+ MapProjectionImpl projection, byte drawZoomLevel) {
+ super.drawOverlayBitmap(canvas, drawPosition, (Projection) projection.getImpl(), drawZoomLevel);
+ }
+
+ @Override
+ public void lock() {
+ lock.lock();
+ }
+
+ @Override
+ public void unlock() {
+ lock.unlock();
+ }
+
+ @Override
+ public MapViewImpl getMapViewImpl() {
+ return (MapViewImpl) internalMapView;
+ }
+
+}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlayItem.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlayItem.java
new file mode 100644
index 0000000..3052e65
--- /dev/null
+++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeCacheOverlayItem.java
@@ -0,0 +1,36 @@
+package cgeo.geocaching.maps.mapsforge.v024;
+
+import cgeo.geocaching.IWaypoint;
+import cgeo.geocaching.enumerations.CacheType;
+import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl;
+
+import org.mapsforge.android.mapsold.GeoPoint;
+import org.mapsforge.android.mapsold.OverlayItem;
+
+import android.graphics.drawable.Drawable;
+
+public class MapsforgeCacheOverlayItem extends OverlayItem implements CachesOverlayItemImpl {
+ final private CacheType cacheType;
+ final private IWaypoint coord;
+
+ public MapsforgeCacheOverlayItem(IWaypoint coordinate, final CacheType type) {
+ super(new GeoPoint(coordinate.getCoords().getLatitudeE6(), coordinate.getCoords().getLongitudeE6()), coordinate.getName(), "");
+
+ this.cacheType = type;
+ this.coord = coordinate;
+ }
+
+ public IWaypoint getCoord() {
+ return coord;
+ }
+
+ public CacheType getType() {
+ return cacheType;
+ }
+
+ @Override
+ public Drawable getMarker(int index) {
+ return getMarker();
+ }
+
+}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeGeoPoint.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeGeoPoint.java
new file mode 100644
index 0000000..c801e3f
--- /dev/null
+++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeGeoPoint.java
@@ -0,0 +1,18 @@
+package cgeo.geocaching.maps.mapsforge.v024;
+
+import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.maps.interfaces.GeoPointImpl;
+
+import org.mapsforge.android.mapsold.GeoPoint;
+
+public class MapsforgeGeoPoint extends GeoPoint implements GeoPointImpl {
+
+ public MapsforgeGeoPoint(int latitudeE6, int longitudeE6) {
+ super(latitudeE6, longitudeE6);
+ }
+
+ @Override
+ public Geopoint getCoords() {
+ return new Geopoint(getLatitudeE6() / 1e6, getLongitudeE6() / 1e6);
+ }
+}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapActivity024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapActivity024.java
new file mode 100644
index 0000000..52cfbb9
--- /dev/null
+++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapActivity024.java
@@ -0,0 +1,122 @@
+package cgeo.geocaching.maps.mapsforge.v024;
+
+import cgeo.geocaching.maps.AbstractMap;
+import cgeo.geocaching.maps.CGeoMap;
+import cgeo.geocaching.maps.interfaces.MapActivityImpl;
+
+import org.mapsforge.android.mapsold.MapActivity;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+
+public class MapsforgeMapActivity024 extends MapActivity implements MapActivityImpl {
+
+ private AbstractMap mapBase;
+
+ public MapsforgeMapActivity024() {
+ mapBase = new CGeoMap(this);
+ }
+
+ @Override
+ public Activity getActivity() {
+ return this;
+ }
+
+ @Override
+ protected void onCreate(Bundle icicle) {
+ mapBase.onCreate(icicle);
+ }
+
+ @Override
+ protected void onSaveInstanceState(final Bundle outState) {
+ mapBase.onSaveInstanceState(outState);
+ }
+
+ @Override
+ protected void onDestroy() {
+ mapBase.onDestroy();
+ }
+
+ @Override
+ protected void onPause() {
+ mapBase.onPause();
+ }
+
+ @Override
+ protected void onResume() {
+ mapBase.onResume();
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ return mapBase.onCreateOptionsMenu(menu);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ return mapBase.onOptionsItemSelected(item);
+ }
+
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ return mapBase.onPrepareOptionsMenu(menu);
+ }
+
+ @Override
+ protected void onStop() {
+ mapBase.onStop();
+ }
+
+ @Override
+ public void superOnCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ public boolean superOnCreateOptionsMenu(Menu menu) {
+ return super.onCreateOptionsMenu(menu);
+ }
+
+ @Override
+ public void superOnDestroy() {
+ super.onDestroy();
+ }
+
+ @Override
+ public boolean superOnOptionsItemSelected(MenuItem item) {
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
+ public void superOnResume() {
+ super.onResume();
+ }
+
+ @Override
+ public void superOnStop() {
+ super.onStop();
+ }
+
+ @Override
+ public void superOnPause() {
+ super.onPause();
+ }
+
+ @Override
+ public boolean superOnPrepareOptionsMenu(Menu menu) {
+ return super.onPrepareOptionsMenu(menu);
+ }
+
+ // close activity and open homescreen
+ public void goHome(View view) {
+ mapBase.goHome(view);
+ }
+
+ // open manual entry
+ public void goManual(View view) {
+ mapBase.goManual(view);
+ }
+}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapController.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapController.java
new file mode 100644
index 0000000..2160d21
--- /dev/null
+++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapController.java
@@ -0,0 +1,48 @@
+package cgeo.geocaching.maps.mapsforge.v024;
+
+import cgeo.geocaching.maps.interfaces.GeoPointImpl;
+import cgeo.geocaching.maps.interfaces.MapControllerImpl;
+
+import org.mapsforge.android.mapsold.GeoPoint;
+import org.mapsforge.android.mapsold.MapController;
+
+public class MapsforgeMapController implements MapControllerImpl {
+
+ private MapController mapController;
+ private int maxZoomLevel;
+
+ public MapsforgeMapController(MapController mapControllerIn, int maxZoomLevelIn) {
+ mapController = mapControllerIn;
+ maxZoomLevel = maxZoomLevelIn;
+ }
+
+ @Override
+ public void animateTo(GeoPointImpl geoPoint) {
+ mapController.setCenter((GeoPoint) geoPoint);
+ }
+
+ @Override
+ public void setCenter(GeoPointImpl geoPoint) {
+ mapController.setCenter((GeoPoint) geoPoint);
+ }
+
+ @Override
+ public void setZoom(int mapzoom) {
+ int mfzoom = mapzoom - 1;
+ if (mfzoom > maxZoomLevel) {
+ mfzoom = maxZoomLevel;
+ }
+ mapController.setZoom(mfzoom);
+ }
+
+ @Override
+ public void zoomToSpan(int latSpanE6, int lonSpanE6) {
+
+ if (latSpanE6 != 0 && lonSpanE6 != 0) {
+ // calculate zoomlevel
+ int distDegree = Math.max(latSpanE6, lonSpanE6);
+ int zoomLevel = (int) Math.floor(Math.log(360.0 * 1e6 / distDegree) / Math.log(2));
+ mapController.setZoom(zoomLevel + 1);
+ }
+ }
+}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java
new file mode 100644
index 0000000..27cadd8
--- /dev/null
+++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapItemFactory024.java
@@ -0,0 +1,33 @@
+package cgeo.geocaching.maps.mapsforge.v024;
+
+import cgeo.geocaching.IWaypoint;
+import cgeo.geocaching.enumerations.CacheType;
+import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.go4cache.Go4CacheUser;
+import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl;
+import cgeo.geocaching.maps.interfaces.GeoPointImpl;
+import cgeo.geocaching.maps.interfaces.MapItemFactory;
+import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl;
+
+import android.content.Context;
+
+public class MapsforgeMapItemFactory024 implements MapItemFactory {
+
+ @Override
+ public GeoPointImpl getGeoPointBase(final Geopoint coords) {
+ return new MapsforgeGeoPoint(coords.getLatitudeE6(), coords.getLongitudeE6());
+ }
+
+ @Override
+ public CachesOverlayItemImpl getCachesOverlayItem(final IWaypoint coordinate, final CacheType type) {
+ MapsforgeCacheOverlayItem baseItem = new MapsforgeCacheOverlayItem(coordinate, type);
+ return baseItem;
+ }
+
+ @Override
+ public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context, Go4CacheUser userOne) {
+ MapsforgeOtherCachersOverlayItem baseItem = new MapsforgeOtherCachersOverlayItem(context, userOne);
+ return baseItem;
+ }
+
+}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapProjection.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapProjection.java
new file mode 100644
index 0000000..9d36b7d
--- /dev/null
+++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapProjection.java
@@ -0,0 +1,29 @@
+package cgeo.geocaching.maps.mapsforge.v024;
+
+import cgeo.geocaching.maps.interfaces.GeoPointImpl;
+import cgeo.geocaching.maps.interfaces.MapProjectionImpl;
+
+import org.mapsforge.android.mapsold.GeoPoint;
+import org.mapsforge.android.mapsold.Projection;
+
+import android.graphics.Point;
+
+public class MapsforgeMapProjection implements MapProjectionImpl {
+
+ private Projection projection;
+
+ public MapsforgeMapProjection(Projection projectionIn) {
+ projection = projectionIn;
+ }
+
+ @Override
+ public void toPixels(GeoPointImpl leftGeo, Point left) {
+ projection.toPixels((GeoPoint) leftGeo, left);
+ }
+
+ @Override
+ public Object getImpl() {
+ return projection;
+ }
+
+}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java
new file mode 100644
index 0000000..5963d32
--- /dev/null
+++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeMapView024.java
@@ -0,0 +1,239 @@
+package cgeo.geocaching.maps.mapsforge.v024;
+
+import cgeo.geocaching.R;
+import cgeo.geocaching.Settings;
+import cgeo.geocaching.geopoint.Viewport;
+import cgeo.geocaching.maps.CachesOverlay;
+import cgeo.geocaching.maps.OtherCachersOverlay;
+import cgeo.geocaching.maps.PositionOverlay;
+import cgeo.geocaching.maps.ScaleOverlay;
+import cgeo.geocaching.maps.interfaces.GeneralOverlay;
+import cgeo.geocaching.maps.interfaces.GeoPointImpl;
+import cgeo.geocaching.maps.interfaces.MapControllerImpl;
+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.utils.Log;
+
+import org.mapsforge.android.mapsold.GeoPoint;
+import org.mapsforge.android.mapsold.MapDatabase;
+import org.mapsforge.android.mapsold.MapView;
+import org.mapsforge.android.mapsold.MapViewMode;
+import org.mapsforge.android.mapsold.Overlay;
+import org.mapsforge.android.mapsold.Projection;
+
+import android.app.Activity;
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+import android.view.GestureDetector;
+import android.view.GestureDetector.SimpleOnGestureListener;
+import android.view.MotionEvent;
+import android.widget.Toast;
+public class MapsforgeMapView024 extends MapView implements MapViewImpl {
+ private GestureDetector gestureDetector;
+ private OnMapDragListener onDragListener;
+
+ public MapsforgeMapView024(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ gestureDetector = new GestureDetector(context, new GestureListener());
+ }
+
+ @Override
+ public void draw(Canvas canvas) {
+ try {
+ if (getMapZoomLevel() >= 22) { // to avoid too close zoom level (mostly on Samsung Galaxy S series)
+ getController().setZoom(22);
+ }
+
+ super.draw(canvas);
+ } catch (Exception e) {
+ Log.e("MapsforgeMapView.draw: " + e.toString());
+ }
+ }
+
+ @Override
+ public void displayZoomControls(boolean takeFocus) {
+ // nothing to do here
+ }
+
+ @Override
+ public MapControllerImpl getMapController() {
+ return new MapsforgeMapController(getController(), getMaxZoomLevel());
+ }
+
+ @Override
+ public GeoPointImpl getMapViewCenter() {
+ GeoPoint point = getMapCenter();
+ return new MapsforgeGeoPoint(point.getLatitudeE6(), point.getLongitudeE6());
+ }
+
+ @Override
+ public Viewport getViewport() {
+ return new Viewport(getMapViewCenter(), getLatitudeSpan() / 1e6, getLongitudeSpan() / 1e6);
+ }
+
+ @Override
+ public void addOverlay(OverlayImpl ovl) {
+ getOverlays().add((Overlay) ovl);
+ }
+
+ @Override
+ public void clearOverlays() {
+ getOverlays().clear();
+ }
+
+ @Override
+ public MapProjectionImpl getMapProjection() {
+ return new MapsforgeMapProjection(getProjection());
+ }
+
+ @Override
+ public CachesOverlay createAddMapOverlay(Context context, Drawable drawable) {
+
+ MapsforgeCacheOverlay ovl = new MapsforgeCacheOverlay(context, drawable);
+ getOverlays().add(ovl);
+ return ovl.getBase();
+ }
+
+ @Override
+ public OtherCachersOverlay createAddUsersOverlay(Context context, Drawable markerIn) {
+ MapsforgeOtherCachersOverlay ovl = new MapsforgeOtherCachersOverlay(context, markerIn);
+ getOverlays().add(ovl);
+ return ovl.getBase();
+ }
+
+ @Override
+ public PositionOverlay createAddPositionOverlay(Activity activity) {
+ 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);
+ getOverlays().add(ovl);
+ return (ScaleOverlay) ovl.getBase();
+ }
+
+ @Override
+ public int getLatitudeSpan() {
+
+ int span = 0;
+
+ Projection projection = getProjection();
+
+ if (projection != null && getHeight() > 0) {
+
+ GeoPoint low = projection.fromPixels(0, 0);
+ GeoPoint high = projection.fromPixels(0, getHeight());
+
+ if (low != null && high != null) {
+ span = Math.abs(high.getLatitudeE6() - low.getLatitudeE6());
+ }
+ }
+
+ return span;
+ }
+
+ @Override
+ public int getLongitudeSpan() {
+
+ int span = 0;
+
+ Projection projection = getProjection();
+
+ if (projection != null && getWidth() > 0) {
+ GeoPoint low = projection.fromPixels(0, 0);
+ GeoPoint high = projection.fromPixels(getWidth(), 0);
+
+ if (low != null && high != null) {
+ span = Math.abs(high.getLongitudeE6() - low.getLongitudeE6());
+ }
+ }
+
+ return span;
+ }
+
+ @Override
+ public void preLoad() {
+ // Nothing to do here
+ }
+
+ @Override
+ public int getMapZoomLevel() {
+ return getZoomLevel() + 1;
+ }
+
+ @Override
+ public void setMapSource() {
+ setMapViewMode(MapViewMode.CANVAS_RENDERER);
+ setMapFile(Settings.getMapFile());
+ if (!MapDatabase.isValidMapFile(Settings.getMapFile())) {
+ Log.e("MapsforgeMapView024: Invalid map file");
+ }
+ Toast.makeText(
+ getContext(),
+ getContext().getResources().getString(R.string.warn_deprecated_mapfile),
+ Toast.LENGTH_LONG)
+ .show();
+ }
+
+ @Override
+ public void repaintRequired(GeneralOverlay overlay) {
+
+ if (null == overlay) {
+ invalidate();
+ } else {
+ try {
+ Overlay ovl = (Overlay) overlay.getOverlayImpl();
+
+ if (ovl != null) {
+ ovl.requestRedraw();
+ }
+
+ } catch (Exception e) {
+ Log.e("MapsforgeMapView.repaintRequired: " + e.toString());
+ }
+ }
+ }
+
+ @Override
+ public void setOnDragListener(OnMapDragListener onDragListener) {
+ this.onDragListener = onDragListener;
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent ev) {
+ gestureDetector.onTouchEvent(ev);
+ return super.onTouchEvent(ev);
+ }
+
+ private class GestureListener extends SimpleOnGestureListener {
+ @Override
+ public boolean onDoubleTap(MotionEvent e) {
+ if (onDragListener != null) {
+ onDragListener.onDrag();
+ }
+ return true;
+ }
+
+ @Override
+ public boolean onScroll(MotionEvent e1, MotionEvent e2,
+ float distanceX, float distanceY) {
+ if (onDragListener != null) {
+ onDragListener.onDrag();
+ }
+ return super.onScroll(e1, e2, distanceX, distanceY);
+ }
+ }
+
+ @Override
+ public boolean needsInvertedColors() {
+ return false;
+ }
+}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOtherCachersOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOtherCachersOverlay.java
new file mode 100644
index 0000000..64ce8b0
--- /dev/null
+++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOtherCachersOverlay.java
@@ -0,0 +1,120 @@
+package cgeo.geocaching.maps.mapsforge.v024;
+
+import cgeo.geocaching.maps.OtherCachersOverlay;
+import cgeo.geocaching.maps.interfaces.ItemizedOverlayImpl;
+import cgeo.geocaching.maps.interfaces.MapProjectionImpl;
+import cgeo.geocaching.maps.interfaces.MapViewImpl;
+
+import org.mapsforge.android.mapsold.ItemizedOverlay;
+import org.mapsforge.android.mapsold.Projection;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Point;
+import android.graphics.drawable.Drawable;
+
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+public class MapsforgeOtherCachersOverlay extends ItemizedOverlay<MapsforgeOtherCachersOverlayItem> implements ItemizedOverlayImpl {
+
+ private OtherCachersOverlay base;
+ private Lock lock = new ReentrantLock();
+
+ public MapsforgeOtherCachersOverlay(Context contextIn, Drawable markerIn) {
+ super(boundCenter(markerIn));
+ base = new OtherCachersOverlay(this, contextIn);
+ }
+
+ @Override
+ public OtherCachersOverlay getBase() {
+ return base;
+ }
+
+ @Override
+ protected MapsforgeOtherCachersOverlayItem createItem(int i) {
+ if (base == null) {
+ return null;
+ }
+
+ return (MapsforgeOtherCachersOverlayItem) base.createItem(i);
+ }
+
+ @Override
+ public int size() {
+ if (base == null) {
+ return 0;
+ }
+
+ return base.size();
+ }
+
+ @Override
+ protected boolean onTap(int arg0) {
+ if (base == null) {
+ return false;
+ }
+
+ return base.onTap(arg0);
+ }
+
+ @Override
+ protected void drawOverlayBitmap(Canvas canvas, Point drawPosition,
+ Projection projection, byte drawZoomLevel) {
+
+ base.drawOverlayBitmap(canvas, drawPosition, new MapsforgeMapProjection(projection), drawZoomLevel);
+ }
+
+ @Override
+ public void superPopulate() {
+ populate();
+ }
+
+ @Override
+ public Drawable superBoundCenter(Drawable markerIn) {
+ return super.boundCenter(markerIn);
+ }
+
+ @Override
+ public Drawable superBoundCenterBottom(Drawable marker) {
+ return super.boundCenterBottom(marker);
+ }
+
+ @Override
+ public void superSetLastFocusedItemIndex(int i) {
+ // Nothing to do here
+ }
+
+ @Override
+ public boolean superOnTap(int index) {
+ return super.onTap(index);
+ }
+
+ @Override
+ public void superDraw(Canvas canvas, MapViewImpl mapView, boolean shadow) {
+ // Nothing to do here
+ }
+
+ @Override
+ public void superDrawOverlayBitmap(Canvas canvas, Point drawPosition,
+ MapProjectionImpl projection, byte drawZoomLevel) {
+
+ super.drawOverlayBitmap(canvas, drawPosition, (Projection) projection.getImpl(), drawZoomLevel);
+ }
+
+ @Override
+ public void lock() {
+ lock.lock();
+ }
+
+ @Override
+ public void unlock() {
+ lock.unlock();
+ }
+
+ @Override
+ public MapViewImpl getMapViewImpl() {
+ return (MapViewImpl) internalMapView;
+ }
+
+} \ No newline at end of file
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOtherCachersOverlayItem.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOtherCachersOverlayItem.java
new file mode 100644
index 0000000..29a2b62
--- /dev/null
+++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOtherCachersOverlayItem.java
@@ -0,0 +1,31 @@
+package cgeo.geocaching.maps.mapsforge.v024;
+
+import cgeo.geocaching.go4cache.Go4CacheUser;
+import cgeo.geocaching.maps.OtherCachersOverlayItem;
+import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl;
+
+import org.mapsforge.android.mapsold.GeoPoint;
+import org.mapsforge.android.mapsold.OverlayItem;
+
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+
+public class MapsforgeOtherCachersOverlayItem extends OverlayItem implements OtherCachersOverlayItemImpl {
+ private final OtherCachersOverlayItem item;
+
+ public MapsforgeOtherCachersOverlayItem(Context context, Go4CacheUser user) {
+ super(new GeoPoint(user.getCoords().getLatitudeE6(), user.getCoords().getLongitudeE6()), user.getUsername(), "");
+ item = new OtherCachersOverlayItem(context, user);
+ }
+
+ @Override
+ public Drawable getMarker(int state) {
+ Drawable marker = item.getMarker();
+ setMarker(marker);
+ return marker;
+ }
+
+ public Go4CacheUser getUser() {
+ return item.getUser();
+ }
+}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java
new file mode 100644
index 0000000..d40b539
--- /dev/null
+++ b/main/src/cgeo/geocaching/maps/mapsforge/v024/MapsforgeOverlay.java
@@ -0,0 +1,63 @@
+package cgeo.geocaching.maps.mapsforge.v024;
+
+import cgeo.geocaching.maps.PositionOverlay;
+import cgeo.geocaching.maps.ScaleOverlay;
+import cgeo.geocaching.maps.interfaces.GeneralOverlay;
+import cgeo.geocaching.maps.interfaces.MapViewImpl;
+import cgeo.geocaching.maps.interfaces.OverlayImpl;
+
+import org.mapsforge.android.mapsold.Overlay;
+import org.mapsforge.android.mapsold.Projection;
+
+import android.app.Activity;
+import android.graphics.Canvas;
+import android.graphics.Point;
+
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+public class MapsforgeOverlay extends Overlay implements OverlayImpl {
+
+ private GeneralOverlay overlayBase = null;
+ private Lock lock = new ReentrantLock();
+
+ public MapsforgeOverlay(Activity activityIn, OverlayImpl.overlayType ovlType) {
+
+ switch (ovlType) {
+ case PositionOverlay:
+ overlayBase = new PositionOverlay(activityIn, this);
+ break;
+ case ScaleOverlay:
+ overlayBase = new ScaleOverlay(activityIn, this);
+ }
+ }
+
+ @Override
+ protected void drawOverlayBitmap(Canvas canvas, Point drawPosition,
+ Projection projection, byte drawZoomLevel) {
+
+ if (overlayBase != null) {
+ overlayBase.drawOverlayBitmap(canvas, drawPosition, new MapsforgeMapProjection(projection), drawZoomLevel);
+ }
+ }
+
+ public GeneralOverlay getBase() {
+ return overlayBase;
+ }
+
+ @Override
+ public void lock() {
+ lock.lock();
+ }
+
+ @Override
+ public void unlock() {
+ lock.unlock();
+ }
+
+ @Override
+ public MapViewImpl getMapViewImpl() {
+ return (MapViewImpl) internalMapView;
+ }
+
+}