diff options
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/cgeo/geocaching/CacheDetailActivity.java | 13 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/StaticMapsProvider.java | 28 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/connector/gc/GCBase.java | 50 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/connector/gc/Tile.java | 18 |
4 files changed, 45 insertions, 64 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index 755115a..0b99d55 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -15,7 +15,6 @@ import cgeo.geocaching.geopoint.GeopointFormatter; import cgeo.geocaching.geopoint.HumanDistance; import cgeo.geocaching.geopoint.IConversion; import cgeo.geocaching.network.HtmlImage; -import cgeo.geocaching.network.Network; import cgeo.geocaching.network.Parameters; import cgeo.geocaching.ui.DecryptTextClickListener; import cgeo.geocaching.ui.Formatter; @@ -1826,9 +1825,7 @@ public class CacheDetailActivity extends AbstractActivity { private class PreviewMapTask extends AsyncTask<Void, Void, BitmapDrawable> { @Override - protected BitmapDrawable doInBackground(Void... params) { - BitmapDrawable image = null; - + protected BitmapDrawable doInBackground(Void... parameters) { try { final String latlonMap = cache.getCoords().format(GeopointFormatter.Format.LAT_LON_DECDEGREE_COMMA); @@ -1839,15 +1836,15 @@ public class CacheDetailActivity extends AbstractActivity { final int height = (int) (110 * metrics.density); // TODO move this code to StaticMapProvider and use its constant values - final String markerUrl = Network.urlencode_rfc3986("http://cgeo.carnero.cc/_markers/my_location_mdpi.png"); + final String markerUrl = "http://cgeo.carnero.cc/_markers/my_location_mdpi.png"; final HtmlImage mapGetter = new HtmlImage(CacheDetailActivity.this, cache.getGeocode(), false, 0, false); - image = mapGetter.getDrawable("http://maps.google.com/maps/api/staticmap?zoom=15&size=" + width + "x" + height + "&maptype=roadmap&markers=icon%3A" + markerUrl + "%7Cshadow:false%7C" + latlonMap + "&sensor=false"); + final Parameters params = new Parameters("zoom", "15", "size", width + "x" + height, "maptype", "roadmap", "markers", "icon:" + markerUrl + "|shadow:false|" + latlonMap, "sensor", "false"); + return mapGetter.getDrawable("http://maps.google.com/maps/api/staticmap?" + params); } catch (Exception e) { Log.w(Settings.tag, "CacheDetailActivity.PreviewMapTask", e); + return null; } - - return image; } @Override diff --git a/main/src/cgeo/geocaching/StaticMapsProvider.java b/main/src/cgeo/geocaching/StaticMapsProvider.java index e19944b..8d055b4 100644 --- a/main/src/cgeo/geocaching/StaticMapsProvider.java +++ b/main/src/cgeo/geocaching/StaticMapsProvider.java @@ -30,7 +30,7 @@ public class StaticMapsProvider { return LocalStorage.getStorageFile(geocode, "map_" + prefix + level, false, createDirs); } - private static void downloadDifferentZooms(final cgCache cache, String markerUrl, String prefix, String latlonMap, int edge, String waypoints) { + private static void downloadDifferentZooms(final cgCache cache, String markerUrl, String prefix, String latlonMap, int edge, final Parameters waypoints) { downloadMap(cache, 20, "satellite", markerUrl, prefix, 1, latlonMap, edge, waypoints); downloadMap(cache, 18, "satellite", markerUrl, prefix, 2, latlonMap, edge, waypoints); downloadMap(cache, 16, "roadmap", markerUrl, prefix, 3, latlonMap, edge, waypoints); @@ -38,15 +38,18 @@ public class StaticMapsProvider { downloadMap(cache, 11, "roadmap", markerUrl, prefix, 5, latlonMap, edge, waypoints); } - private static void downloadMap(cgCache cache, int zoom, String mapType, String markerUrl, String prefix, int level, String latlonMap, int edge, String waypoints) { + private static void downloadMap(cgCache cache, int zoom, String mapType, String markerUrl, String prefix, int level, String latlonMap, int edge, final Parameters waypoints) { final String mapUrl = "http://maps.google.com/maps/api/staticmap"; final Parameters params = new Parameters( "center", latlonMap, "zoom", String.valueOf(zoom), "size", edge + "x" + edge, "maptype", mapType, - "markers", "icon:" + markerUrl + '|' + latlonMap + waypoints, + "markers", "icon:" + markerUrl + '|' + latlonMap, "sensor", "false"); + if (waypoints != null) { + params.addAll(waypoints); + } final HttpResponse httpResponse = Network.request(mapUrl, params); if (httpResponse != null) { @@ -102,7 +105,7 @@ public class StaticMapsProvider { String wpLatlonMap = waypoint.getCoords().format(Format.LAT_LON_DECDEGREE_COMMA); String wpMarkerUrl = getWpMarkerUrl(waypoint); // download map images in separate background thread for higher performance - downloadMaps(cache, wpMarkerUrl, "wp" + waypoint.getId() + "_", wpLatlonMap, edge, "", waitForResult); + downloadMaps(cache, wpMarkerUrl, "wp" + waypoint.getId() + "_", wpLatlonMap, edge, null, waitForResult); } public static void storeCacheStaticMap(cgCache cache, Activity activity, final boolean waitForResult) { @@ -112,22 +115,19 @@ public class StaticMapsProvider { private static void storeCacheStaticMap(cgCache cache, int edge, final boolean waitForResult) { final String latlonMap = cache.getCoords().format(Format.LAT_LON_DECDEGREE_COMMA); - final StringBuilder waypoints = new StringBuilder(); + final Parameters waypoints = new Parameters(); if (cache.hasWaypoints()) { for (cgWaypoint waypoint : cache.getWaypoints()) { if (waypoint.getCoords() == null) { continue; } - String wpMarkerUrl = getWpMarkerUrl(waypoint); - waypoints.append("&markers=icon%3A"); - waypoints.append(wpMarkerUrl); - waypoints.append("%7C"); - waypoints.append(waypoint.getCoords().format(Format.LAT_LON_DECDEGREE_COMMA)); + final String wpMarkerUrl = getWpMarkerUrl(waypoint); + waypoints.put("markers", "icon:" + wpMarkerUrl + "|" + waypoint.getCoords().format(Format.LAT_LON_DECDEGREE_COMMA)); } } // download map images in separate background thread for higher performance final String cacheMarkerUrl = getCacheMarkerUrl(cache); - downloadMaps(cache, cacheMarkerUrl, "", latlonMap, edge, waypoints.toString(), waitForResult); + downloadMaps(cache, cacheMarkerUrl, "", latlonMap, edge, waypoints, waitForResult); } private static int guessMinDisplaySide(Display display) { @@ -147,7 +147,7 @@ public class StaticMapsProvider { } private static void downloadMaps(final cgCache cache, final String markerUrl, final String prefix, final String latlonMap, final int edge, - final String waypoints, boolean waitForResult) { + final Parameters waypoints, boolean waitForResult) { if (waitForResult) { downloadDifferentZooms(cache, markerUrl, prefix, latlonMap, edge, waypoints); } @@ -174,12 +174,12 @@ public class StaticMapsProvider { type += "_disabled"; } - return Network.urlencode_rfc3986(MARKERS_URL + "marker_cache_" + type + ".png"); + return MARKERS_URL + "marker_cache_" + type + ".png"; } private static String getWpMarkerUrl(final cgWaypoint waypoint) { String type = waypoint.getWaypointType() != null ? waypoint.getWaypointType().id : null; - return Network.urlencode_rfc3986(MARKERS_URL + "marker_waypoint_" + type + ".png"); + return MARKERS_URL + "marker_waypoint_" + type + ".png"; } public static void removeWpStaticMaps(int wp_id, String geocode) { diff --git a/main/src/cgeo/geocaching/connector/gc/GCBase.java b/main/src/cgeo/geocaching/connector/gc/GCBase.java index 471aef9..e06713c 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCBase.java +++ b/main/src/cgeo/geocaching/connector/gc/GCBase.java @@ -15,6 +15,7 @@ import cgeo.geocaching.geopoint.IConversion; import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.network.Login; import cgeo.geocaching.network.Network; +import cgeo.geocaching.network.Parameters; import cgeo.geocaching.ui.Formatter; import cgeo.geocaching.utils.BaseUtils; import cgeo.geocaching.utils.LeastRecentlyUsedMap; @@ -126,36 +127,31 @@ public class GCBase { for (Tile tile : tiles) { if (!tileCache.containsKey(tile.hashCode())) { - - StringBuilder url = new StringBuilder(); - url.append("?x=").append(tile.getX()) // x tile - .append("&y=").append(tile.getY()) // y tile - .append("&z=").append(tile.getZoomlevel()); // zoom level + final Parameters params = new Parameters( + "x", String.valueOf(tile.getX()), + "y", String.valueOf(tile.getY()), + "z", String.valueOf(tile.getZoomlevel()), + "ep", "1"); if (tokens != null) { - url.append("&k=").append(tokens[0]); // user session - url.append("&st=").append(tokens[1]); // session token + params.put("k", tokens[0], "st", tokens[1]); } - url.append("&ep=1"); if (Settings.isExcludeMyCaches()) { - url.append("&hf=1").append("&hh=1"); // hide found, hide hidden + params.put("hf", "1", "hh", "1"); // hide found, hide hidden } if (Settings.getCacheType() == CacheType.TRADITIONAL) { - url.append("&ect=9,5,3,6,453,13,1304,137,11,4,8,1858"); // 2 = tradi 3 = multi 8 = mystery - } - if (Settings.getCacheType() == CacheType.MULTI) { - url.append("&ect=9,5,2,6,453,13,1304,137,11,4,8,1858"); - } - if (Settings.getCacheType() == CacheType.MYSTERY) { - url.append("&ect=9,5,3,6,453,13,1304,137,11,4,2,1858"); + params.put("ect", "9,5,3,6,453,13,1304,137,11,4,8,1858"); // 2 = tradi 3 = multi 8 = mystery + } else if (Settings.getCacheType() == CacheType.MULTI) { + params.put("ect", "9,5,2,6,453,13,1304,137,11,4,8,1858"); + } else if (Settings.getCacheType() == CacheType.MYSTERY) { + params.put("ect", "9,5,3,6,453,13,1304,137,11,4,2,1858"); } if (tile.getZoomlevel() != 14) { - url.append("&_=").append(String.valueOf(System.currentTimeMillis())); + params.put("_", String.valueOf(System.currentTimeMillis())); } - // other types t.b.d - final String urlString = url.toString(); + // TODO: other types t.b.d // The PNG must be requested first, otherwise the following request would always return with 204 - No Content - Bitmap bitmap = Tile.requestMapTile(GCConstants.URL_MAP_TILE + urlString, referer); + Bitmap bitmap = Tile.requestMapTile(GCConstants.URL_MAP_TILE, params, referer); // Check bitmap size if (bitmap.getWidth() != Tile.TILE_SIZE || @@ -164,7 +160,7 @@ public class GCBase { bitmap = null; } - String data = Tile.requestMapInfo(GCConstants.URL_MAP_INFO + urlString, referer); + String data = Tile.requestMapInfo(GCConstants.URL_MAP_INFO, params, referer); if (StringUtils.isEmpty(data)) { Log.e(Settings.tag, "GCBase.searchByViewport: No data from server for tile (" + tile.getX() + "/" + tile.getY() + ")"); } else { @@ -371,18 +367,14 @@ public class GCBase { public static SearchResult searchByGeocodes(final Set<String> geocodes) { - SearchResult result = new SearchResult(); + final SearchResult result = new SearchResult(); final String geocodeList = StringUtils.join(geocodes.toArray(), "|"); - - String referer = GCConstants.URL_LIVE_MAP_DETAILS; - - StringBuilder url = new StringBuilder(); - url.append("?i=").append(geocodeList).append("&_=").append(String.valueOf(System.currentTimeMillis())); - final String urlString = url.toString(); + final String referer = GCConstants.URL_LIVE_MAP_DETAILS; try { - String data = Tile.requestMapInfo(referer + urlString, referer); + final Parameters params = new Parameters("i", geocodeList, "_", String.valueOf(System.currentTimeMillis())); + final String data = Tile.requestMapInfo(referer, params, referer); // Example JSON information // {"status":"success", diff --git a/main/src/cgeo/geocaching/connector/gc/Tile.java b/main/src/cgeo/geocaching/connector/gc/Tile.java index 27b45de..0daa69d 100644 --- a/main/src/cgeo/geocaching/connector/gc/Tile.java +++ b/main/src/cgeo/geocaching/connector/gc/Tile.java @@ -4,10 +4,10 @@ import cgeo.geocaching.Settings; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.network.Network; +import cgeo.geocaching.network.Parameters; import cgeo.geocaching.utils.Log; import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpGet; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -208,21 +208,13 @@ public class Tile { } /** Request JSON informations for a tile */ - public static String requestMapInfo(final String url, final String referer) { - final HttpGet request = new HttpGet(url); - request.addHeader("Accept", "application/json, text/javascript, */*; q=0.01"); - request.addHeader("Referer", referer); - request.addHeader("X-Requested-With", "XMLHttpRequest"); - return Network.getResponseData(Network.request(request), false); + public static String requestMapInfo(final String url, final Parameters params, final String referer) { + return Network.getResponseData(Network.request(url, params, new Parameters("Referer", referer))); } /** Request .png image for a tile. */ - public static Bitmap requestMapTile(final String url, final String referer) { - final HttpGet request = new HttpGet(url); - request.addHeader("Accept", "image/png,image/*;q=0.8,*/*;q=0.5"); - request.addHeader("Referer", referer); - request.addHeader("X-Requested-With", "XMLHttpRequest"); - final HttpResponse response = Network.request(request); + public static Bitmap requestMapTile(final String url, final Parameters params, final String referer) { + final HttpResponse response = Network.request(url, params, new Parameters("Referer", referer)); try { return response != null ? BitmapFactory.decodeStream(response.getEntity().getContent()) : null; } catch (IOException e) { |