aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/maps/MapProviderFactory.java
diff options
context:
space:
mode:
authorrsudev <rasch@munin-soft.de>2011-11-15 22:04:20 +0100
committerrsudev <rasch@munin-soft.de>2011-11-15 22:04:20 +0100
commitafb9a89209cf2e64eca726549f0da93a1da5ff80 (patch)
treeddd96b3e03722e3e32861a3e7944a8c7cbf4265f /main/src/cgeo/geocaching/maps/MapProviderFactory.java
parent2d9773fa90cba4bafff3bd71b9b7d3baaaff4766 (diff)
downloadcgeo-afb9a89209cf2e64eca726549f0da93a1da5ff80.zip
cgeo-afb9a89209cf2e64eca726549f0da93a1da5ff80.tar.gz
cgeo-afb9a89209cf2e64eca726549f0da93a1da5ff80.tar.bz2
Implementing #179, refactor maps to single source, last part
Diffstat (limited to 'main/src/cgeo/geocaching/maps/MapProviderFactory.java')
-rw-r--r--main/src/cgeo/geocaching/maps/MapProviderFactory.java104
1 files changed, 104 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/maps/MapProviderFactory.java b/main/src/cgeo/geocaching/maps/MapProviderFactory.java
new file mode 100644
index 0000000..707eb64
--- /dev/null
+++ b/main/src/cgeo/geocaching/maps/MapProviderFactory.java
@@ -0,0 +1,104 @@
+package cgeo.geocaching.maps;
+
+import cgeo.geocaching.maps.google.GoogleMapProvider;
+import cgeo.geocaching.maps.interfaces.MapProvider;
+import cgeo.geocaching.maps.mapsforge.MapsforgeMapProvider;
+
+import android.view.Menu;
+
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+public class MapProviderFactory {
+
+ private final static int GOOGLEMAP_BASEID = 30;
+ private final static int MFMAP_BASEID = 40;
+
+ private static MapProviderFactory instance = null;
+
+ private MapProvider[] mapProviders;
+ private SortedMap<Integer, String> mapSources;
+
+ private MapProviderFactory() {
+ mapProviders = new MapProvider[] { new GoogleMapProvider(GOOGLEMAP_BASEID), new MapsforgeMapProvider(MFMAP_BASEID) };
+ mapSources = new TreeMap<Integer, String>();
+ for (MapProvider mp : mapProviders) {
+ mapSources.putAll(mp.getMapSources());
+ }
+ }
+
+ private static synchronized void initInstance() {
+ if (null == instance) {
+ instance = new MapProviderFactory();
+ }
+ }
+
+ private static MapProviderFactory getFactory() {
+ if (null == instance) {
+ initInstance();
+ }
+ return instance;
+ }
+
+ public static SortedMap<Integer, String> getMapSources() {
+ return getFactory().mapSources;
+ }
+
+ public static boolean IsValidSourceId(int sourceId) {
+ return getFactory().mapSources.containsKey(sourceId);
+ }
+
+ public static boolean IsSameProvider(int sourceId1, int sourceId2) {
+ for (MapProvider mp : getFactory().mapProviders) {
+ if (mp.IsMySource(sourceId1) && mp.IsMySource(sourceId2)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static MapProvider getMapProvider(int sourceId) {
+ for (MapProvider mp : getFactory().mapProviders) {
+ if (mp.IsMySource(sourceId)) {
+ return mp;
+ }
+ }
+ return getFactory().mapProviders[0];
+ }
+
+ public static int getSourceOrdinalFromId(int sourceId) {
+
+ int sourceOrdinal = 1;
+ for (int key : getFactory().mapSources.keySet()) {
+ if (sourceId == key) {
+ return sourceOrdinal;
+ }
+ sourceOrdinal++;
+ }
+ return 0;
+ }
+
+ public static int getSourceIdFromOrdinal(int sourceOrdinal) {
+ int count = 1;
+ for (int key : getFactory().mapSources.keySet()) {
+ if (sourceOrdinal == count) {
+ return key;
+ }
+ count++;
+ }
+ return getFactory().mapSources.firstKey();
+ }
+
+ public static void addMapviewMenuItems(Menu parentMenu, int groupId, int currentSource) {
+
+ SortedMap<Integer, String> mapSources = getFactory().mapSources;
+
+ for (int key : mapSources.keySet()) {
+ parentMenu.add(groupId, key, 0, mapSources.get(key)).setCheckable(true).setChecked(key == currentSource);
+ }
+ }
+
+ public static int getMapSourceFromMenuId(int menuId) {
+ return menuId;
+ }
+}