diff options
author | Torsten Keil <github@torsten-keil.net> | 2012-02-03 22:41:29 +0100 |
---|---|---|
committer | Torsten Keil <github@torsten-keil.net> | 2012-02-03 22:41:29 +0100 |
commit | cc96d7528f661bc65d5de4a09a625400718fe831 (patch) | |
tree | 4922dfa03c1ab4e7ba8b3e33c94ca8f22e4078d1 /main/src | |
parent | f80652303c09c112cc1759d75a10c766eacc7568 (diff) | |
download | cgeo-cc96d7528f661bc65d5de4a09a625400718fe831.zip cgeo-cc96d7528f661bc65d5de4a09a625400718fe831.tar.gz cgeo-cc96d7528f661bc65d5de4a09a625400718fe831.tar.bz2 |
Added check for static maps.
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/cgeo/geocaching/StaticMapsProvider.java | 33 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java | 29 |
2 files changed, 59 insertions, 3 deletions
diff --git a/main/src/cgeo/geocaching/StaticMapsProvider.java b/main/src/cgeo/geocaching/StaticMapsProvider.java index 3c4aa60..6384d59 100644 --- a/main/src/cgeo/geocaching/StaticMapsProvider.java +++ b/main/src/cgeo/geocaching/StaticMapsProvider.java @@ -162,4 +162,37 @@ public class StaticMapsProvider { } } } + + /** + * Check if at least one map file exists for the given geocode. + * + * @param geocode + * @return <code>true</code> if at least one mapfile exists; <code>false</code> otherwise + */ + public static boolean doesExistStaticMapForCache(String geocode) { + for (int level = 1; level <= 5; level++) { + File mapFile = StaticMapsProvider.getMapFile(geocode, "", level, false); + if (mapFile != null && mapFile.exists()) { + return true; + } + } + return false; + } + + /** + * Checks if at least one map file exists for the given geocode and waypoint ID. + * + * @param geocode + * @param waypointId + * @return <code>true</code> if at least one mapfile exists; <code>false</code> otherwise + */ + public static boolean doesExistStaticMapForWaypoint(String geocode, int waypointId) { + for (int level = 1; level <= 5; level++) { + File mapFile = StaticMapsProvider.getMapFile(geocode, "wp" + waypointId + "_", level, false); + if (mapFile != null && mapFile.exists()) { + return true; + } + } + return false; + } } diff --git a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java index 9ac752f..0ec3a0a 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java @@ -3,12 +3,16 @@ package cgeo.geocaching.apps.cache.navi; import cgeo.geocaching.R; import cgeo.geocaching.SearchResult; import cgeo.geocaching.Settings; +import cgeo.geocaching.StaticMapsProvider; import cgeo.geocaching.cgCache; import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgWaypoint; +import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.apps.AbstractAppFactory; import cgeo.geocaching.geopoint.Geopoint; +import org.apache.commons.lang3.StringUtils; + import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; @@ -113,10 +117,13 @@ public final class NavigationAppFactory extends AbstractAppFactory { builder.setIcon(android.R.drawable.ic_menu_mapmode); final List<NavigationAppsEnum> items = new ArrayList<NavigationAppFactory.NavigationAppsEnum>(); final int defaultNavigationTool = Settings.getDefaultNavigationTool(); -// final boolean isOffline = cache != null ? cgeoapplication.getInstance().isOffline(cache.getGeocode(), null) : false; - // (isOffline && NavigationAppsEnum.STATIC_MAP.id == navApp.id) <== must be changed, isn't working for waypoints for example + final boolean hasStaticMaps = hasStaticMap(cache, waypoint); for (NavigationAppsEnum navApp : getInstalledNavigationApps(activity)) { - if ((showInternalMap || !(navApp.app instanceof InternalMap)) && + if (NavigationAppsEnum.STATIC_MAP.id == navApp.id) { + if (hasStaticMaps) { + items.add(navApp); + } + } else if ((showInternalMap || !(navApp.app instanceof InternalMap)) && (showDefaultNavigation || defaultNavigationTool != navApp.id)) { items.add(navApp); } @@ -150,7 +157,23 @@ public final class NavigationAppFactory extends AbstractAppFactory { }); final AlertDialog alert = builder.create(); alert.show(); + } + private static boolean hasStaticMap(cgCache cache, cgWaypoint waypoint) { + if (waypoint != null) { + String geocode = waypoint.getGeocode(); + int id = waypoint.getId(); + if (StringUtils.isNotEmpty(geocode) && cgeoapplication.getInstance().isOffline(geocode, null)) { + return StaticMapsProvider.doesExistStaticMapForWaypoint(geocode, id); + } + } + if (cache != null) { + String geocode = cache.getGeocode(); + if (StringUtils.isNotEmpty(geocode) && cgeoapplication.getInstance().isOffline(geocode, null)) { + return StaticMapsProvider.doesExistStaticMapForCache(geocode); + } + } + return false; } /** |