aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/StaticMapsProvider.java
diff options
context:
space:
mode:
authorMarco Jacob <mjacob@union06.de>2013-03-27 20:48:27 +0100
committerMarco Jacob <mjacob@union06.de>2013-03-27 20:48:27 +0100
commitd2500fe31f90a9aedcde5676f1b02da9f58e88ef (patch)
tree98a7cc00625353ed6f9f7b8f7c37d072f62e3f6d /main/src/cgeo/geocaching/StaticMapsProvider.java
parent4e5357b0006400668e3cbbc513ae6ac2882eb369 (diff)
downloadcgeo-d2500fe31f90a9aedcde5676f1b02da9f58e88ef.zip
cgeo-d2500fe31f90a9aedcde5676f1b02da9f58e88ef.tar.gz
cgeo-d2500fe31f90a9aedcde5676f1b02da9f58e88ef.tar.bz2
more checks in static maps test
Diffstat (limited to 'main/src/cgeo/geocaching/StaticMapsProvider.java')
-rw-r--r--main/src/cgeo/geocaching/StaticMapsProvider.java25
1 files changed, 16 insertions, 9 deletions
diff --git a/main/src/cgeo/geocaching/StaticMapsProvider.java b/main/src/cgeo/geocaching/StaticMapsProvider.java
index cd88071..8f89340 100644
--- a/main/src/cgeo/geocaching/StaticMapsProvider.java
+++ b/main/src/cgeo/geocaching/StaticMapsProvider.java
@@ -49,7 +49,7 @@ public class StaticMapsProvider {
downloadMap(geocode, 11, ROADMAP, markerUrl, prefix + '5', "", latlonMap, edge, edge, waypoints);
}
- private static void downloadMap(String geocode, int zoom, String mapType, String markerUrl, String prefix, String shadow, String latlonMap, int width, int height, final Parameters waypoints) {
+ private static DownloadState downloadMap(String geocode, int zoom, String mapType, String markerUrl, String prefix, String shadow, String latlonMap, int width, int height, final Parameters waypoints) {
final Parameters params = new Parameters(
"center", latlonMap,
"zoom", String.valueOf(zoom),
@@ -64,11 +64,11 @@ public class StaticMapsProvider {
if (httpResponse == null) {
Log.e("StaticMapsProvider.downloadMap: httpResponse is null");
- return;
+ return DownloadState.REQUEST_FAILED;
}
if (httpResponse.getStatusLine().getStatusCode() != 200) {
Log.d("StaticMapsProvider.downloadMap: httpResponseCode = " + httpResponse.getStatusLine().getStatusCode());
- return;
+ return DownloadState.STATUS_CODE_NOK;
}
final File file = getMapFile(geocode, prefix, true);
if (LocalStorage.saveEntityToFile(httpResponse, file)) {
@@ -76,8 +76,11 @@ public class StaticMapsProvider {
final long fileSize = file.length();
if (fileSize < MIN_MAP_IMAGE_BYTES) {
file.delete();
+ return DownloadState.FILE_TOO_SMALL;
}
+ return DownloadState.OK;
}
+ return DownloadState.NOT_SAVED;
}
public static void downloadMaps(Geocache cache) {
@@ -166,10 +169,10 @@ public class StaticMapsProvider {
downloadMaps(cache.getGeocode(), cacheMarkerUrl, "", latlonMap, edge, waypoints, waitForResult);
}
- public static void storeCachePreviewMap(final Geocache cache) {
+ public static DownloadState storeCachePreviewMap(final Geocache cache) {
if (cache == null) {
Log.e("storeCachePreviewMap - missing input parameter cache");
- return;
+ return DownloadState.FAILED;
}
final String latlonMap = cache.getCoords().format(Format.LAT_LON_DECDEGREE_COMMA);
final Display display = ((WindowManager) cgeoapplication.getInstance().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
@@ -178,7 +181,8 @@ public class StaticMapsProvider {
final int width = metrics.widthPixels;
final int height = (int) (110 * metrics.density);
final String markerUrl = MARKERS_URL + "my_location_mdpi.png";
- downloadMap(cache.getGeocode(), 15, ROADMAP, markerUrl, PREFIX_PREVIEW, "shadow:false|", latlonMap, width, height, null);
+ DownloadState state = downloadMap(cache.getGeocode(), 15, ROADMAP, markerUrl, PREFIX_PREVIEW, "shadow:false|", latlonMap, width, height, null);
+ return state;
}
private static int guessMaxDisplaySide() {
@@ -245,7 +249,7 @@ public class StaticMapsProvider {
/**
* Check if at least one map file exists for the given cache.
- *
+ *
* @param cache
* @return <code>true</code> if at least one map file exists; <code>false</code> otherwise
*/
@@ -268,7 +272,7 @@ public class StaticMapsProvider {
/**
* Checks if at least one map file exists for the given geocode and waypoint ID.
- *
+ *
* @param geocode
* @param waypoint
* @return <code>true</code> if at least one map file exists; <code>false</code> otherwise
@@ -287,7 +291,7 @@ public class StaticMapsProvider {
/**
* Checks if all map files exist for the given geocode and waypoint ID.
- *
+ *
* @param geocode
* @param waypoint
* @return <code>true</code> if all map files exist; <code>false</code> otherwise
@@ -327,4 +331,7 @@ public class StaticMapsProvider {
return null;
}
+ public enum DownloadState {
+ OK, REQUEST_FAILED, STATUS_CODE_NOK, FILE_TOO_SMALL, NOT_SAVED, FAILED
+ }
}