aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/maps/MapProviderFactory.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/maps/MapProviderFactory.java')
-rw-r--r--main/src/cgeo/geocaching/maps/MapProviderFactory.java35
1 files changed, 31 insertions, 4 deletions
diff --git a/main/src/cgeo/geocaching/maps/MapProviderFactory.java b/main/src/cgeo/geocaching/maps/MapProviderFactory.java
index 95ea265..a03fc47 100644
--- a/main/src/cgeo/geocaching/maps/MapProviderFactory.java
+++ b/main/src/cgeo/geocaching/maps/MapProviderFactory.java
@@ -1,11 +1,15 @@
package cgeo.geocaching.maps;
import cgeo.geocaching.R;
-import cgeo.geocaching.settings.Settings;
+import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.maps.google.GoogleMapProvider;
import cgeo.geocaching.maps.interfaces.MapProvider;
import cgeo.geocaching.maps.interfaces.MapSource;
import cgeo.geocaching.maps.mapsforge.MapsforgeMapProvider;
+import cgeo.geocaching.settings.Settings;
+import cgeo.geocaching.utils.Log;
+
+import org.apache.commons.lang3.StringUtils;
import android.view.Menu;
import android.view.SubMenu;
@@ -26,13 +30,21 @@ public class MapProviderFactory {
}
public static boolean isGoogleMapsInstalled() {
- boolean googleMaps = true;
+ // Check if API key is available
+ if (StringUtils.isBlank(cgeoapplication.getInstance().getString(R.string.maps_api_key))) {
+ Log.w("No Google API key available.");
+ return false;
+ }
+
+ // Check if API is available
try {
Class.forName("com.google.android.maps.MapActivity");
} catch (ClassNotFoundException e) {
- googleMaps = false;
+ return false;
}
- return googleMaps;
+
+ // Assume that Google Maps is available and working
+ return true;
}
public static List<MapSource> getMapSources() {
@@ -57,6 +69,12 @@ public class MapProviderFactory {
parentMenu.setGroupCheckable(R.id.menu_group_map_sources, true, true);
}
+ /**
+ * Return a map source by id.
+ *
+ * @param id the map source id
+ * @return the map source, or <tt>null</tt> if <tt>id</tt> does not correspond to a registered map source
+ */
public static MapSource getMapSource(int id) {
for (MapSource mapSource : mapSources) {
if (mapSource.getNumericalId() == id) {
@@ -66,6 +84,15 @@ public class MapProviderFactory {
return null;
}
+ /**
+ * Return a map source if there is at least one.
+ *
+ * @return the first map source in the collection, or <tt>null</tt> if there are none registered
+ */
+ public static MapSource getAnyMapSource() {
+ return mapSources.isEmpty() ? null : mapSources.get(0);
+ }
+
public static void registerMapSource(final MapSource mapSource) {
mapSources.add(mapSource);
}