diff --git a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java index d81d1194e2..4ed8540dda 100644 --- a/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java +++ b/OsmAnd-java/src/net/osmand/util/GeoPointParserUtil.java @@ -22,12 +22,12 @@ public class GeoPointParserUtil { String url; String noQueryParameters[] = { - "geo:0,0", - "geo:0,0?", - "http://download.osmand.net/go", - "http://download.osmand.net/go?", + "geo:0,0", + "geo:0,0?", + "http://download.osmand.net/go", + "http://download.osmand.net/go?", }; - for (String s: noQueryParameters) { + for (String s : noQueryParameters) { URI uri = URI.create(s); Map map = getQueryParameters(uri); System.out.print(s + " map: " + map.size() + "..."); @@ -39,14 +39,15 @@ public class GeoPointParserUtil { } String oneQueryParameter[] = { - "geo:0,0?m", - "geo:0,0?m=", - "geo:0,0?m=foo", - "http://download.osmand.net/go?lat", - "http://download.osmand.net/go?lat=", - "http://download.osmand.net/go?lat=34.99393", + "geo:0,0?m", + "geo:0,0?m=", + "geo:0,0?m=foo", + "geo:0,0?q=%D0%9D%D0", + "http://download.osmand.net/go?lat", + "http://download.osmand.net/go?lat=", + "http://download.osmand.net/go?lat=34.99393", }; - for (String s: oneQueryParameter) { + for (String s : oneQueryParameter) { URI uri = URI.create(s); Map map = getQueryParameters(uri); System.out.print(s + " map: " + map.size() + "..."); @@ -58,13 +59,13 @@ public class GeoPointParserUtil { } String twoQueryParameters[] = { - "geo:0,0?z=11&q=Lots+Of+Stuff", - "http://osmand.net/go?lat=34.99393&lon=-110.12345", - "http://www.osmand.net/go.html?lat=34.99393&lon=-110.12345", - "http://download.osmand.net/go?lat=34.99393&lon=-110.12345", - "http://download.osmand.net/go?lat=34.99393&lon=-110.12345#this+should+be+ignored", + "geo:0,0?z=11&q=Lots+Of+Stuff", + "http://osmand.net/go?lat=34.99393&lon=-110.12345", + "http://www.osmand.net/go.html?lat=34.99393&lon=-110.12345", + "http://download.osmand.net/go?lat=34.99393&lon=-110.12345", + "http://download.osmand.net/go?lat=34.99393&lon=-110.12345#this+should+be+ignored", }; - for (String s: twoQueryParameters) { + for (String s : twoQueryParameters) { URI uri = URI.create(s); Map map = getQueryParameters(uri); System.out.print(s + " map: " + map.size() + "..."); @@ -88,7 +89,7 @@ public class GeoPointParserUtil { actual = GeoPointParserUtil.parse(url); assertUrlEquals(url, actual.getGeoUriString()); assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon)); - + // geo:34.99393,-106.61568?z=11 z = 11; url = "geo:" + dlat + "," + dlon + "?z=" + z; @@ -211,7 +212,7 @@ public class GeoPointParserUtil { System.out.println("url: " + url); actual = GeoPointParserUtil.parse(url); assertGeoPoint(actual, new GeoParsedPoint(ilat, ilon, z)); - + // http://maps.google.com/maps?q=N34.939,E-106 url = "http://maps.google.com/maps?q=N" + dlat + ",E" + Math.abs(dlon); System.out.println("url: " + url); @@ -223,7 +224,7 @@ public class GeoPointParserUtil { System.out.println("url: " + url); actual = GeoPointParserUtil.parse(url); assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); - + // http://osmand.net/go?lat=34&lon=-106&z=11 url = "http://osmand.net/go?lat=" + ilat + "&lon=" + ilon + "&z=" + z; System.out.println("url: " + url); @@ -256,7 +257,7 @@ public class GeoPointParserUtil { actual = GeoPointParserUtil.parse(url); assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); - // https://www.openstreetmap.org/#map=11/49.563/17.291 + // https://www.openstreetmap.org/#map=11/49.563/17.291 url = "https://www.openstreetmap.org/#map=" + z + "/" + dlat + "/" + dlon; System.out.println("url: " + url); actual = GeoPointParserUtil.parse(url); @@ -264,7 +265,7 @@ public class GeoPointParserUtil { // https://www.openstreetmap.org/?mlat=34.993933029174805&mlon=-106.61568069458008#map=11/34.99393/-106.61568 url = "https://www.openstreetmap.org/?mlat=" + longLat + "&mlon=" + longLon - + "#map=" + z + "/" + dlat + "/" + dlon; + + "#map=" + z + "/" + dlat + "/" + dlon; System.out.println("url: " + url); actual = GeoPointParserUtil.parse(url); assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); @@ -465,9 +466,9 @@ public class GeoPointParserUtil { assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); // http://maps.google.com/maps?lci=com.google.latitudepublicupdates&ll=34.99393%2C-106.61568&q=34.99393%2C-106.61568 - z = GeoParsedPoint.NO_ZOOM; + z = GeoParsedPoint.NO_ZOOM; url = "http://maps.google.com/maps?lci=com.google.latitudepublicupdates&ll=" + dlat - +"%2C" + dlon + "&q=" + dlat + "%2C" + dlon + "((" + dlat + "%2C%20" + dlon + "))"; + + "%2C" + dlon + "&q=" + dlat + "%2C" + dlon + "((" + dlat + "%2C%20" + dlon + "))"; System.out.println("url: " + url); actual = GeoPointParserUtil.parse(url); assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); @@ -523,14 +524,14 @@ public class GeoPointParserUtil { // http://map.baidu.com/?l=13&tn=B_NORMAL_MAP&c=13748138,4889173&s=gibberish z = 7; - int latint = ((int)(dlat * 100000)); - int lonint = ((int)(dlon * 100000)); + int latint = ((int) (dlat * 100000)); + int lonint = ((int) (dlon * 100000)); url = "http://map.baidu.com/?l=" + z + "&tn=B_NORMAL_MAP&c=" + latint + "," + lonint + "&s=gibberish"; System.out.println("url: " + url); actual = GeoPointParserUtil.parse(url); assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); - // http://www.amap.com/#!poi!!q=38.174596,114.995033|2|%E5%AE%BE%E9%A6%86&radius=1000 + // http://www.amap.com/#!poi!!q=38.174596,114.995033|2|%E5%AE%BE%E9%A6%86&radius=1000 z = 13; // amap uses radius, so 1000m is roughly zoom level 13 url = "http://www.amap.com/#!poi!!q=" + dlat + "," + dlon + "|2|%E5%AE%BE%E9%A6%86&radius=1000"; System.out.println("\nurl: " + url); @@ -587,44 +588,44 @@ public class GeoPointParserUtil { assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); /* URLs straight from various services, instead of generated here */ - - String urls[] = { - "https://openstreetmap.org/go/0LQ127-?m", - "http://osm.org/go/0LQ127-?m", - "http://osm.org/go/0EEQjE==", - "http://osm.org/go/0EEQjEEb", - "http://osm.org/go/0EE~jEEb", - "http://osm.org/go/0EE@jEEb", - "http://osm.org/go/~~~~", - "http://osm.org/go/@@@@", - "https://www.openstreetmap.org/#map=0/0/0", - "https://www.openstreetmap.org/#map=0/180/180", - "https://www.openstreetmap.org/#map=0/-180/-180", - "https://www.openstreetmap.org/#map=0/180.0/180.0", - "https://www.openstreetmap.org/#map=6/33.907/34.662", - "https://www.openstreetmap.org/?mlat=49.56275939941406&mlon=17.291107177734375#map=8/49.563/17.291", - "https://www.google.at/maps/place/Bargou,+Tunesien/@36.0922506,9.5676327,15z/data=!3m1!4b1!4m2!3m1!1s0x12fc5d0b4dc5e66f:0xbd3618c6193d14cd", - "http://www.amap.com/#!poi!!q=38.174596,114.995033,%E6%B2%B3%E5%8C%97%E7%9C%81%E7%9F%B3%E5%AE%B6%E5%BA%84%E5%B8%82%E6%97%A0%E6%9E%81%E5%8E%BF", - "http://wb.amap.com/?p=B013706PJN,38.179456,114.98577,%E6%96%B0%E4%B8%9C%E6%96%B9%E5%A4%A7%E9%85%92%E5%BA%97(%E4%BF%9D%E9%99%A9%E8%8A%B1...,%E5%BB%BA%E8%AE%BE%E8%B7%AF67%E5%8F%B7", - "http://www.amap.com/#!poi!!q=38.179456,114.98577|3|B013706PJN", - "http://www.amap.com/#!poi!!q=38.174596,114.995033|2|%E5%AE%BE%E9%A6%86&radius=1000", - "http://www.amap.com/?p=B013704EJT,38.17914,114.976337,%E6%97%A0%E6%9E%81%E5%8E%BF%E4%BA%BA%E6%B0%91%E6%94%BF%E5%BA%9C,%E5%BB%BA%E8%AE%BE%E4%B8%9C%E8%B7%AF12%E5%8F%B7", - "http://share.here.com/l/52.5134272,13.3778416,Hannah-Arendt-Stra%C3%9Fe?z=16.0&t=normal", - "https://www.here.com/location?map=52.5134272,13.3778416,16,normal&msg=Hannah-Arendt-Stra%C3%9Fe", - "https://www.here.com/?map=48.23145,16.38454,15,normal", - "http://map.wap.qq.com/loc/detail.jsp?sid=AU8f3ck87L6XDmytunBm4iWg&g_ut=2&city=%E5%8C%97%E4%BA%AC&key=NOBU%20Beijing&x=116.48177&y=39.91082&md=10461366113386140862", - "http://map.wap.qq.com/loc/d.jsp?c=113.275020,39.188380&m=113.275020,39.188380&n=%E9%BC%93%E6%A5%BC&a=%E5%B1%B1%E8%A5%BF%E7%9C%81%E5%BF%BB%E5%B7%9E%E5%B8%82%E7%B9%81%E5%B3%99%E5%8E%BF+&p=+&i=16959367104973338386&z=0", - "http://map.wap.qq.com/loc/d.jsp?c=113.275020,39.188380&m=113.275020,39.188380&n=%E9%BC%93%E6%A5%BC&a=%E5%B1%B1%E8%A5%BF%E7%9C%81%E5%BF%BB%E5%B7%9E%E5%B8%82%E7%B9%81%E5%B3%99%E5%8E%BF+&p=+&i=16959367104973338386&z=0&m", - "http://map.qq.com/AppBox/print/?t=&c=%7B%22base%22%3A%7B%22l%22%3A11%2C%22lat%22%3A39.90403%2C%22lng%22%3A116.407526%7D%7D", - "http://maps.yandex.com/?text=Australia%2C%20Victoria%2C%20Christmas%20Hills&sll=145.319026%2C-37.650344&ll=145.319026%2C-37.650344&spn=0.352249%2C0.151501&z=12&l=map", - "http://maps.apple.com/?q=Bargou,+Tunisien", - "http://maps.apple.com/?daddr=Bargou,+Tunisien", - "http://maps.apple.com/?lsp=7618&q=40.738065,-73.988898&sll=40.738065,-73.988898", - "http://maps.apple.com/?lsp=9902&auid=13787349062281695774&sll=40.694576,-73.982992&q=Garden%20Nail%20%26%20Spa&hnear=325%20Gold%20St%2C%20Brooklyn%2C%20NY%20%2011201-3054%2C%20United%20States", - "https://www.google.com/maps/place/Wild+Herb+Market/@33.32787,-105.66291,14z/data=!4m5!1m2!2m1!1sfood!3m1!1s0x86e1ce2079e1f94b:0x1d7460465dcaf3ed", - "http://www.google.com/maps/search/food/@34,-106,14z", - "http://www.google.com/maps/search/food/@34.99393,-106.61568,14z", - }; + + String urls[] = { + "https://openstreetmap.org/go/0LQ127-?m", + "http://osm.org/go/0LQ127-?m", + "http://osm.org/go/0EEQjE==", + "http://osm.org/go/0EEQjEEb", + "http://osm.org/go/0EE~jEEb", + "http://osm.org/go/0EE@jEEb", + "http://osm.org/go/~~~~", + "http://osm.org/go/@@@@", + "https://www.openstreetmap.org/#map=0/0/0", + "https://www.openstreetmap.org/#map=0/180/180", + "https://www.openstreetmap.org/#map=0/-180/-180", + "https://www.openstreetmap.org/#map=0/180.0/180.0", + "https://www.openstreetmap.org/#map=6/33.907/34.662", + "https://www.openstreetmap.org/?mlat=49.56275939941406&mlon=17.291107177734375#map=8/49.563/17.291", + "https://www.google.at/maps/place/Bargou,+Tunesien/@36.0922506,9.5676327,15z/data=!3m1!4b1!4m2!3m1!1s0x12fc5d0b4dc5e66f:0xbd3618c6193d14cd", + "http://www.amap.com/#!poi!!q=38.174596,114.995033,%E6%B2%B3%E5%8C%97%E7%9C%81%E7%9F%B3%E5%AE%B6%E5%BA%84%E5%B8%82%E6%97%A0%E6%9E%81%E5%8E%BF", + "http://wb.amap.com/?p=B013706PJN,38.179456,114.98577,%E6%96%B0%E4%B8%9C%E6%96%B9%E5%A4%A7%E9%85%92%E5%BA%97(%E4%BF%9D%E9%99%A9%E8%8A%B1...,%E5%BB%BA%E8%AE%BE%E8%B7%AF67%E5%8F%B7", + "http://www.amap.com/#!poi!!q=38.179456,114.98577|3|B013706PJN", + "http://www.amap.com/#!poi!!q=38.174596,114.995033|2|%E5%AE%BE%E9%A6%86&radius=1000", + "http://www.amap.com/?p=B013704EJT,38.17914,114.976337,%E6%97%A0%E6%9E%81%E5%8E%BF%E4%BA%BA%E6%B0%91%E6%94%BF%E5%BA%9C,%E5%BB%BA%E8%AE%BE%E4%B8%9C%E8%B7%AF12%E5%8F%B7", + "http://share.here.com/l/52.5134272,13.3778416,Hannah-Arendt-Stra%C3%9Fe?z=16.0&t=normal", + "https://www.here.com/location?map=52.5134272,13.3778416,16,normal&msg=Hannah-Arendt-Stra%C3%9Fe", + "https://www.here.com/?map=48.23145,16.38454,15,normal", + "http://map.wap.qq.com/loc/detail.jsp?sid=AU8f3ck87L6XDmytunBm4iWg&g_ut=2&city=%E5%8C%97%E4%BA%AC&key=NOBU%20Beijing&x=116.48177&y=39.91082&md=10461366113386140862", + "http://map.wap.qq.com/loc/d.jsp?c=113.275020,39.188380&m=113.275020,39.188380&n=%E9%BC%93%E6%A5%BC&a=%E5%B1%B1%E8%A5%BF%E7%9C%81%E5%BF%BB%E5%B7%9E%E5%B8%82%E7%B9%81%E5%B3%99%E5%8E%BF+&p=+&i=16959367104973338386&z=0", + "http://map.wap.qq.com/loc/d.jsp?c=113.275020,39.188380&m=113.275020,39.188380&n=%E9%BC%93%E6%A5%BC&a=%E5%B1%B1%E8%A5%BF%E7%9C%81%E5%BF%BB%E5%B7%9E%E5%B8%82%E7%B9%81%E5%B3%99%E5%8E%BF+&p=+&i=16959367104973338386&z=0&m", + "http://map.qq.com/AppBox/print/?t=&c=%7B%22base%22%3A%7B%22l%22%3A11%2C%22lat%22%3A39.90403%2C%22lng%22%3A116.407526%7D%7D", + "http://maps.yandex.com/?text=Australia%2C%20Victoria%2C%20Christmas%20Hills&sll=145.319026%2C-37.650344&ll=145.319026%2C-37.650344&spn=0.352249%2C0.151501&z=12&l=map", + "http://maps.apple.com/?q=Bargou,+Tunisien", + "http://maps.apple.com/?daddr=Bargou,+Tunisien", + "http://maps.apple.com/?lsp=7618&q=40.738065,-73.988898&sll=40.738065,-73.988898", + "http://maps.apple.com/?lsp=9902&auid=13787349062281695774&sll=40.694576,-73.982992&q=Garden%20Nail%20%26%20Spa&hnear=325%20Gold%20St%2C%20Brooklyn%2C%20NY%20%2011201-3054%2C%20United%20States", + "https://www.google.com/maps/place/Wild+Herb+Market/@33.32787,-105.66291,14z/data=!4m5!1m2!2m1!1sfood!3m1!1s0x86e1ce2079e1f94b:0x1d7460465dcaf3ed", + "http://www.google.com/maps/search/food/@34,-106,14z", + "http://www.google.com/maps/search/food/@34.99393,-106.61568,14z", + }; for (String u : urls) { System.out.println("url: " + u); @@ -636,14 +637,14 @@ public class GeoPointParserUtil { // these URLs are not parsable, but should not crash or cause problems String[] unparsableUrls = { - "http://maps.yandex.ru/-/CVCw6M9g", - "http://maps.yandex.com/-/CVCXEKYW", - "http://goo.gl/maps/Cji0V", - "http://amap.com/0F0i02", - "http://j.map.baidu.com/oXrVz", - "http://l.map.qq.com/9741483212?m", - "http://map.qq.com/?l=261496722", - "http://her.is/vLCEXE", + "http://maps.yandex.ru/-/CVCw6M9g", + "http://maps.yandex.com/-/CVCXEKYW", + "http://goo.gl/maps/Cji0V", + "http://amap.com/0F0i02", + "http://j.map.baidu.com/oXrVz", + "http://l.map.qq.com/9741483212?m", + "http://map.qq.com/?l=261496722", + "http://her.is/vLCEXE", }; for (String u : unparsableUrls) { @@ -653,8 +654,8 @@ public class GeoPointParserUtil { throw new RuntimeException(u + " not parsable, but parse did not return null!"); System.out.println("Handled URL"); } - - + + } private static boolean areCloseEnough(double a, double b, long howClose) { @@ -667,7 +668,7 @@ public class GeoPointParserUtil { if (expected.getQuery() != null) { if (!expected.getQuery().equals(actual.getQuery())) throw new RuntimeException("Query param not equal:\n'" + - actual.getQuery() + "' != '" + expected.getQuery()); + actual.getQuery() + "' != '" + expected.getQuery()); } else { double aLat = actual.getLatitude(), eLat = expected.getLatitude(), aLon = actual.getLongitude(), eLon = expected.getLongitude(); int aZoom = actual.getZoom(), eZoom = expected.getZoom(); @@ -705,10 +706,10 @@ public class GeoPointParserUtil { + aLabel + ", expected=" + eLabel); } } - if (((int)eLat) != ((int)aLat)) { + if (((int) eLat) != ((int) aLat)) { throw new RuntimeException("Latitude is not equal; actual=" + aLat + ", expected=" + eLat); } - if (((int)eLon) != ((int)aLon)) { + if (((int) eLon) != ((int) aLon)) { throw new RuntimeException("Longitude is not equal; actual=" + aLon + ", expected=" + eLon); } if (eZoom != aZoom) { @@ -718,10 +719,10 @@ public class GeoPointParserUtil { System.out.println("Passed!"); } - private static void assertUrlEquals(String actual, String expected) { - if (actual == null || !actual.equals(expected)) - throw new RuntimeException("URLs not equal; actual=" + actual + ", expected=" + expected); - } + private static void assertUrlEquals(String actual, String expected) { + if (actual == null || !actual.equals(expected)) + throw new RuntimeException("URLs not equal; actual=" + actual + ", expected=" + expected); + } private static String getQueryParameter(final String param, URI uri) { final String query = uri.getQuery(); @@ -738,43 +739,43 @@ public class GeoPointParserUtil { return value; } - /** - * This parses out all of the parameters in the query string for both - * http: and geo: URIs. This will only work on URIs with valid syntax, so - * it will not work on URIs that do odd things like have a query string in - * the fragment, like this one: - * http://www.amap.com/#!poi!!q=38.174596,114.995033|2|%E5%AE%BE%E9%A6%86&radius=1000 - * + /** + * This parses out all of the parameters in the query string for both + * http: and geo: URIs. This will only work on URIs with valid syntax, so + * it will not work on URIs that do odd things like have a query string in + * the fragment, like this one: + * http://www.amap.com/#!poi!!q=38.174596,114.995033|2|%E5%AE%BE%E9%A6%86&radius=1000 + * * @param uri * @return {@link Map} a Map of the query parameters - */ + */ private static Map getQueryParameters(URI uri) { - String query = null; - if (uri.isOpaque()) { - String schemeSpecificPart = uri.getSchemeSpecificPart(); - int pos = schemeSpecificPart.indexOf("?"); - if (pos == schemeSpecificPart.length()) { - query = ""; - } else if (pos > -1) { - query = schemeSpecificPart.substring(pos + 1); - } - } else { - query = uri.getRawQuery(); - } - return getQueryParameters(query); - } + String query = null; + if (uri.isOpaque()) { + String schemeSpecificPart = uri.getSchemeSpecificPart(); + int pos = schemeSpecificPart.indexOf("?"); + if (pos == schemeSpecificPart.length()) { + query = ""; + } else if (pos > -1) { + query = schemeSpecificPart.substring(pos + 1); + } + } else { + query = uri.getRawQuery(); + } + return getQueryParameters(query); + } private static Map getQueryParameters(String query) { - final LinkedHashMap map = new LinkedHashMap(); - if (query != null && !query.equals("")) { - String[] params = query.split("&"); - for (String p : params) { - String[] keyValue = p.split("="); - if (keyValue.length == 1) - map.put(keyValue[0], ""); - else if (keyValue.length > 1) - map.put(keyValue[0], URLDecoder.decode(keyValue[1])); - } + final LinkedHashMap map = new LinkedHashMap(); + if (query != null && !query.equals("")) { + String[] params = query.split("&"); + for (String p : params) { + String[] keyValue = p.split("="); + if (keyValue.length == 1) + map.put(keyValue[0], ""); + else if (keyValue.length > 1) + map.put(keyValue[0], URLDecoder.decode(keyValue[1])); + } } return map; } @@ -786,67 +787,68 @@ public class GeoPointParserUtil { * @return {@link GeoParsedPoint} */ public static GeoParsedPoint parse(final String uriString) { - URI uri; - try { - // amap.com uses | in their URLs, which is an illegal character for a URL - uri = URI.create(uriString.replaceAll("\\s+", "+") - .replaceAll("%20", "+") - .replaceAll("%2C", ",") - .replaceAll("\\|", ";") - .replaceAll("\\(\\(\\S+\\)\\)", "")); - } catch (IllegalArgumentException e) { - return null; - } + System.out.println("parse(" + "uriString=" + uriString + ")"); + URI uri; + try { + // amap.com uses | in their URLs, which is an illegal character for a URL + uri = URI.create(uriString.replaceAll("\\s+", "+") + .replaceAll("%20", "+") + .replaceAll("%2C", ",") + .replaceAll("\\|", ";") + .replaceAll("\\(\\(\\S+\\)\\)", "")); + } catch (IllegalArgumentException e) { + return null; + } - String scheme = uri.getScheme(); - if (scheme == null) - return null; - else - scheme = scheme.toLowerCase(Locale.US); + String scheme = uri.getScheme(); + if (scheme == null) + return null; + else + scheme = scheme.toLowerCase(Locale.US); if ("http".equals(scheme) || "https".equals(scheme)) { - String host = uri.getHost(); - if (host == null) - return null; - else - host = host.toLowerCase(Locale.US); - String path = uri.getPath(); + String host = uri.getHost(); + if (host == null) + return null; + else + host = host.toLowerCase(Locale.US); + String path = uri.getPath(); if (path == null) { path = ""; } - String fragment = uri.getFragment(); + String fragment = uri.getFragment(); - // lat-double, lon - double, zoom or z - int - Set simpleDomains = new HashSet(); - simpleDomains.add("osmand.net"); - simpleDomains.add("www.osmand.net"); - simpleDomains.add("download.osmand.net"); - simpleDomains.add("openstreetmap.de"); - simpleDomains.add("www.openstreetmap.de"); + // lat-double, lon - double, zoom or z - int + Set simpleDomains = new HashSet(); + simpleDomains.add("osmand.net"); + simpleDomains.add("www.osmand.net"); + simpleDomains.add("download.osmand.net"); + simpleDomains.add("openstreetmap.de"); + simpleDomains.add("www.openstreetmap.de"); final Pattern commaSeparatedPairPattern = Pattern.compile("(?:loc:)?([N|S]?[+-]?\\d+(?:\\.\\d+)?),([E|W]?[+-]?\\d+(?:\\.\\d+)?)"); - try { - if (host.equals("osm.org") || host.endsWith("openstreetmap.org")) { - Pattern p; - Matcher matcher; - if (path.startsWith("/go/")) { // short URL form - p = Pattern.compile("^/go/([A-Za-z0-9_@~]+-*)(?:.*)"); - matcher = p.matcher(path); - if (matcher.matches()) { - return MapUtils.decodeShortLinkString(matcher.group(1)); - } + try { + if (host.equals("osm.org") || host.endsWith("openstreetmap.org")) { + Pattern p; + Matcher matcher; + if (path.startsWith("/go/")) { // short URL form + p = Pattern.compile("^/go/([A-Za-z0-9_@~]+-*)(?:.*)"); + matcher = p.matcher(path); + if (matcher.matches()) { + return MapUtils.decodeShortLinkString(matcher.group(1)); + } } else { // data in the query and/or feature strings double lat = 0; double lon = 0; int zoom = GeoParsedPoint.NO_ZOOM; if (fragment != null) { - if(fragment.startsWith("map=")) { + if (fragment.startsWith("map=")) { fragment = fragment.substring("map=".length()); } String[] vls = fragment.split("/"); - if(vls.length >= 3) { + if (vls.length >= 3) { zoom = parseZoom(vls[0]); lat = parseSilentDouble(vls[1]); lon = parseSilentDouble(vls[2]); @@ -854,30 +856,30 @@ public class GeoPointParserUtil { } // the query string sometimes has higher resolution values String mlat = getQueryParameter("mlat", uri); - if(mlat != null) { + if (mlat != null) { lat = parseSilentDouble(mlat); } String mlon = getQueryParameter("mlon", uri); - if(mlon != null) { + if (mlon != null) { lon = parseSilentDouble(mlon); } return new GeoParsedPoint(lat, lon, zoom); } - } else if (host.startsWith("map.baidu.")) { // .com and .cn both work - /* Baidu Map uses a custom format for lat/lon., it is basically standard lat/lon + } else if (host.startsWith("map.baidu.")) { // .com and .cn both work + /* Baidu Map uses a custom format for lat/lon., it is basically standard lat/lon * multiplied by 100,000, then rounded to an integer */ Map params = getQueryParameters(uri); - String zm = params.get("l"); - String[] vls = silentSplit(params.get("c"),","); - if ( vls != null && vls.length >= 2) { - double lat = parseSilentInt(vls[0]) / 100000.; - double lon = parseSilentInt(vls[1]) / 100000.; - int zoom = parseZoom(zm); - return new GeoParsedPoint(lat, lon, zoom); - } + String zm = params.get("l"); + String[] vls = silentSplit(params.get("c"), ","); + if (vls != null && vls.length >= 2) { + double lat = parseSilentInt(vls[0]) / 100000.; + double lon = parseSilentInt(vls[1]) / 100000.; + int zoom = parseZoom(zm); + return new GeoParsedPoint(lat, lon, zoom); + } } else if (simpleDomains.contains(host)) { Map params = getQueryParameters(uri); - if(uri.getQuery() == null && params.size() == 0) { + if (uri.getQuery() == null && params.size() == 0) { // DOUBLE check this may be wrong test of openstreetmap.de (looks very weird url and server doesn't respond) params = getQueryParameters(path.substring(1)); } @@ -907,13 +909,13 @@ public class GeoPointParserUtil { String lonString = null; String z = String.valueOf(GeoParsedPoint.NO_ZOOM); Map params = getQueryParameters(uri); - if(params.containsKey("q")){ + if (params.containsKey("q")) { Matcher matcher = commaSeparatedPairPattern.matcher(params.get("q")); if (matcher.matches()) { latString = matcher.group(1); lonString = matcher.group(2); } - } else if(params.containsKey("ll")){ + } else if (params.containsKey("ll")) { Matcher matcher = commaSeparatedPairPattern.matcher(params.get("ll")); if (matcher.matches()) { latString = matcher.group(1); @@ -926,11 +928,11 @@ public class GeoPointParserUtil { } return new GeoParsedPoint(latString, lonString, z); } - if(params.containsKey("daddr")){ + if (params.containsKey("daddr")) { return parseGoogleMapsPath(params.get("daddr"), params); - } else if(params.containsKey("saddr")){ + } else if (params.containsKey("saddr")) { return parseGoogleMapsPath(params.get("saddr"), params); - } else if(params.containsKey("q")){ + } else if (params.containsKey("q")) { return parseGoogleMapsPath(params.get("q"), params); } if (fragment != null) { @@ -940,9 +942,9 @@ public class GeoPointParserUtil { return new GeoParsedPoint(m.group(1)); } } - - String[] pathPrefixes = new String[] { "/@", "/ll=", - "loc:", "/" }; + + String[] pathPrefixes = new String[]{"/@", "/ll=", + "loc:", "/"}; for (String pref : pathPrefixes) { if (path.contains(pref)) { path = path.substring(path.lastIndexOf(pref) @@ -959,9 +961,9 @@ public class GeoPointParserUtil { Matcher matcher; final String[] patterns = { /* though this looks like Query String, it is also used as part of the Fragment */ - ".*q=([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?).*&radius=(\\d+).*", - ".*q=([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?).*", - ".*p=(?:[A-Z0-9]+),([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?).*", }; + ".*q=([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?).*&radius=(\\d+).*", + ".*q=([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?).*", + ".*p=(?:[A-Z0-9]+),([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?).*",}; for (int i = 0; i < patterns.length; i++) { p = Pattern.compile(patterns[i]); matcher = p.matcher(subString); @@ -969,7 +971,7 @@ public class GeoPointParserUtil { if (matcher.groupCount() == 3) { // amap uses radius in meters, so do rough conversion into zoom level float radius = Float.valueOf(matcher.group(3)); - long zoom = Math.round(23. - Math.log(radius)/Math.log(2.0)); + long zoom = Math.round(23. - Math.log(radius) / Math.log(2.0)); return new GeoParsedPoint(matcher.group(1), matcher.group(2), String.valueOf(zoom)); } else if (matcher.groupCount() == 2) { return new GeoParsedPoint(matcher.group(1), matcher.group(2)); @@ -1096,9 +1098,9 @@ public class GeoPointParserUtil { } } - } catch (RuntimeException e) { - e.printStackTrace(); - } + } catch (RuntimeException e) { + e.printStackTrace(); + } return null; } else if ("geo".equals(scheme) || "osmand.geo".equals(scheme)) { String schemeSpecific = uri.getSchemeSpecificPart(); @@ -1182,14 +1184,14 @@ public class GeoPointParserUtil { String zmPart = ""; String descr = ""; String path = opath; - if(path.contains("&")){ + if (path.contains("&")) { String[] vls = path.split("&"); path = vls[0]; - for(int i = 1; i < vls.length; i++) { + for (int i = 1; i < vls.length; i++) { int ik = vls[i].indexOf('='); - if(ik > 0) { - params.put(vls[i].substring(0, ik), vls[i].substring(ik + 1)); - } + if (ik > 0) { + params.put(vls[i].substring(0, ik), vls[i].substring(ik + 1)); + } } } if (path.contains("+")) { @@ -1200,36 +1202,36 @@ public class GeoPointParserUtil { } } - if(params.containsKey("z")) { + if (params.containsKey("z")) { zmPart = params.get("z"); } String[] vls = silentSplit(path, ","); - - if(vls.length >= 2) { + + if (vls.length >= 2) { double lat = parseSilentDouble(vls[0]); - double lon = parseSilentDouble(vls[1]) ; - int zoom = GeoParsedPoint.NO_ZOOM; - if(vls.length >= 3 || zmPart.length() > 0) { - if(zmPart.length() == 0){ - zmPart = vls[2]; - } - if(zmPart.startsWith("z=")) { - zmPart = zmPart.substring(2); - } else if(zmPart.contains("z")) { - zmPart = zmPart.substring(0, zmPart.indexOf('z')); - } - zoom = parseZoom(zmPart); - } - return new GeoParsedPoint(lat, lon, zoom); + double lon = parseSilentDouble(vls[1]); + int zoom = GeoParsedPoint.NO_ZOOM; + if (vls.length >= 3 || zmPart.length() > 0) { + if (zmPart.length() == 0) { + zmPart = vls[2]; + } + if (zmPart.startsWith("z=")) { + zmPart = zmPart.substring(2); + } else if (zmPart.contains("z")) { + zmPart = zmPart.substring(0, zmPart.indexOf('z')); + } + zoom = parseZoom(zmPart); + } + return new GeoParsedPoint(lat, lon, zoom); } return new GeoParsedPoint(URLDecoder.decode(opath)); } - private static String[] silentSplit(String vl, String split) { - if(vl == null) { - return null; - } - return vl.split(split); + private static String[] silentSplit(String vl, String split) { + if (vl == null) { + return null; + } + return vl.split(split); } private static int parseZoom(String zoom) { @@ -1241,7 +1243,7 @@ public class GeoPointParserUtil { } return GeoParsedPoint.NO_ZOOM; } - + private static double parseSilentDouble(String zoom) { try { if (zoom != null) { @@ -1251,7 +1253,7 @@ public class GeoPointParserUtil { } return 0; } - + private static int parseSilentInt(String zoom) { try { if (zoom != null) { @@ -1307,20 +1309,20 @@ public class GeoPointParserUtil { } private static double parseLon(String lonString) { - if(lonString.startsWith("E")) { + if (lonString.startsWith("E")) { return -Double.valueOf(lonString.substring(1)); - } else if(lonString.startsWith("W")) { + } else if (lonString.startsWith("W")) { return Double.valueOf(lonString.substring(1)); - } + } return Double.valueOf(lonString); } private static double parseLat(String latString) { - if(latString.startsWith("S")) { + if (latString.startsWith("S")) { return -Double.valueOf(latString.substring(1)); - } else if(latString.startsWith("N")) { + } else if (latString.startsWith("N")) { return Double.valueOf(latString.substring(1)); - } + } return Double.valueOf(latString); } @@ -1363,8 +1365,8 @@ public class GeoPointParserUtil { } private String formatDouble(double d) { - if(d == (long) d) - return String.format(Locale.ENGLISH, "%d", (long)d); + if (d == (long) d) + return String.format(Locale.ENGLISH, "%d", (long) d); else return String.format("%s", d); } diff --git a/OsmAnd/res/drawable-hdpi/widget_monitoring_rec_inactive_day.png b/OsmAnd/res/drawable-hdpi/widget_monitoring_rec_inactive_day.png old mode 100644 new mode 100755 index 1fcda1060b..c39f19c695 Binary files a/OsmAnd/res/drawable-hdpi/widget_monitoring_rec_inactive_day.png and b/OsmAnd/res/drawable-hdpi/widget_monitoring_rec_inactive_day.png differ diff --git a/OsmAnd/res/drawable-hdpi/widget_monitoring_rec_inactive_night.png b/OsmAnd/res/drawable-hdpi/widget_monitoring_rec_inactive_night.png old mode 100644 new mode 100755 index 5a3045ed6f..8880e901c5 Binary files a/OsmAnd/res/drawable-hdpi/widget_monitoring_rec_inactive_night.png and b/OsmAnd/res/drawable-hdpi/widget_monitoring_rec_inactive_night.png differ diff --git a/OsmAnd/res/drawable-mdpi/widget_monitoring_rec_inactive_day.png b/OsmAnd/res/drawable-mdpi/widget_monitoring_rec_inactive_day.png old mode 100644 new mode 100755 index ddd99345a9..e95da2d603 Binary files a/OsmAnd/res/drawable-mdpi/widget_monitoring_rec_inactive_day.png and b/OsmAnd/res/drawable-mdpi/widget_monitoring_rec_inactive_day.png differ diff --git a/OsmAnd/res/drawable-mdpi/widget_monitoring_rec_inactive_night.png b/OsmAnd/res/drawable-mdpi/widget_monitoring_rec_inactive_night.png old mode 100644 new mode 100755 index fb19e8ec4b..d8e3e7b77b Binary files a/OsmAnd/res/drawable-mdpi/widget_monitoring_rec_inactive_night.png and b/OsmAnd/res/drawable-mdpi/widget_monitoring_rec_inactive_night.png differ diff --git a/OsmAnd/res/drawable-xhdpi/widget_monitoring_rec_inactive_day.png b/OsmAnd/res/drawable-xhdpi/widget_monitoring_rec_inactive_day.png old mode 100644 new mode 100755 index 1dea15d87e..d1b700e940 Binary files a/OsmAnd/res/drawable-xhdpi/widget_monitoring_rec_inactive_day.png and b/OsmAnd/res/drawable-xhdpi/widget_monitoring_rec_inactive_day.png differ diff --git a/OsmAnd/res/drawable-xhdpi/widget_monitoring_rec_inactive_night.png b/OsmAnd/res/drawable-xhdpi/widget_monitoring_rec_inactive_night.png old mode 100644 new mode 100755 index 34a1e314bc..0d0c4e6873 Binary files a/OsmAnd/res/drawable-xhdpi/widget_monitoring_rec_inactive_night.png and b/OsmAnd/res/drawable-xhdpi/widget_monitoring_rec_inactive_night.png differ diff --git a/OsmAnd/res/drawable-xxhdpi/widget_monitoring_rec_inactive_day.png b/OsmAnd/res/drawable-xxhdpi/widget_monitoring_rec_inactive_day.png old mode 100644 new mode 100755 index 3aca714733..8d23795788 Binary files a/OsmAnd/res/drawable-xxhdpi/widget_monitoring_rec_inactive_day.png and b/OsmAnd/res/drawable-xxhdpi/widget_monitoring_rec_inactive_day.png differ diff --git a/OsmAnd/res/drawable-xxhdpi/widget_monitoring_rec_inactive_night.png b/OsmAnd/res/drawable-xxhdpi/widget_monitoring_rec_inactive_night.png old mode 100644 new mode 100755 index 559c2d62bd..46b073416e Binary files a/OsmAnd/res/drawable-xxhdpi/widget_monitoring_rec_inactive_night.png and b/OsmAnd/res/drawable-xxhdpi/widget_monitoring_rec_inactive_night.png differ diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesListFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesListFragment.java index 450211f447..93518e91a0 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesListFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesListFragment.java @@ -51,6 +51,13 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA public void onAttach(Activity activity) { super.onAttach(activity); Intent intent = activity.getIntent(); + settings = getApplication().getSettings(); + OsmandApplication app = getApplication(); + favouritesAdapter = new FavouritesAdapter(activity, app.getFavorites().getFavouritePoints(), + !selectFavoriteMode); + setListAdapter(favouritesAdapter); + setHasOptionsMenu(true); + if (intent != null) { selectFavoriteMode = intent.hasExtra(SELECT_FAVORITE_POINT_INTENT_KEY); if (intent.hasExtra(SearchActivity.SEARCH_LAT) && intent.hasExtra(SearchActivity.SEARCH_LON)) { @@ -61,12 +68,6 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA } } } - settings = ((OsmandApplication) getApplication()).getSettings(); - OsmandApplication app = (OsmandApplication) getApplication(); - favouritesAdapter = new FavouritesAdapter(activity, app.getFavorites().getFavouritePoints(), - !selectFavoriteMode); - setListAdapter(favouritesAdapter); - setHasOptionsMenu(true); } private OsmandApplication getApplication() {