Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-08-21 17:33:53 +02:00
commit f1ac728c3d
10 changed files with 231 additions and 228 deletions

View file

@ -22,12 +22,12 @@ public class GeoPointParserUtil {
String url; String url;
String noQueryParameters[] = { String noQueryParameters[] = {
"geo:0,0", "geo:0,0",
"geo:0,0?", "geo:0,0?",
"http://download.osmand.net/go", "http://download.osmand.net/go",
"http://download.osmand.net/go?", "http://download.osmand.net/go?",
}; };
for (String s: noQueryParameters) { for (String s : noQueryParameters) {
URI uri = URI.create(s); URI uri = URI.create(s);
Map<String, String> map = getQueryParameters(uri); Map<String, String> map = getQueryParameters(uri);
System.out.print(s + " map: " + map.size() + "..."); System.out.print(s + " map: " + map.size() + "...");
@ -39,14 +39,15 @@ public class GeoPointParserUtil {
} }
String oneQueryParameter[] = { String oneQueryParameter[] = {
"geo:0,0?m", "geo:0,0?m",
"geo:0,0?m=", "geo:0,0?m=",
"geo:0,0?m=foo", "geo:0,0?m=foo",
"http://download.osmand.net/go?lat", "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", "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); URI uri = URI.create(s);
Map<String, String> map = getQueryParameters(uri); Map<String, String> map = getQueryParameters(uri);
System.out.print(s + " map: " + map.size() + "..."); System.out.print(s + " map: " + map.size() + "...");
@ -58,13 +59,13 @@ public class GeoPointParserUtil {
} }
String twoQueryParameters[] = { String twoQueryParameters[] = {
"geo:0,0?z=11&q=Lots+Of+Stuff", "geo:0,0?z=11&q=Lots+Of+Stuff",
"http://osmand.net/go?lat=34.99393&lon=-110.12345", "http://osmand.net/go?lat=34.99393&lon=-110.12345",
"http://www.osmand.net/go.html?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",
"http://download.osmand.net/go?lat=34.99393&lon=-110.12345#this+should+be+ignored", "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); URI uri = URI.create(s);
Map<String, String> map = getQueryParameters(uri); Map<String, String> map = getQueryParameters(uri);
System.out.print(s + " map: " + map.size() + "..."); System.out.print(s + " map: " + map.size() + "...");
@ -88,7 +89,7 @@ public class GeoPointParserUtil {
actual = GeoPointParserUtil.parse(url); actual = GeoPointParserUtil.parse(url);
assertUrlEquals(url, actual.getGeoUriString()); assertUrlEquals(url, actual.getGeoUriString());
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon)); assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon));
// geo:34.99393,-106.61568?z=11 // geo:34.99393,-106.61568?z=11
z = 11; z = 11;
url = "geo:" + dlat + "," + dlon + "?z=" + z; url = "geo:" + dlat + "," + dlon + "?z=" + z;
@ -211,7 +212,7 @@ public class GeoPointParserUtil {
System.out.println("url: " + url); System.out.println("url: " + url);
actual = GeoPointParserUtil.parse(url); actual = GeoPointParserUtil.parse(url);
assertGeoPoint(actual, new GeoParsedPoint(ilat, ilon, z)); assertGeoPoint(actual, new GeoParsedPoint(ilat, ilon, z));
// http://maps.google.com/maps?q=N34.939,E-106 // http://maps.google.com/maps?q=N34.939,E-106
url = "http://maps.google.com/maps?q=N" + dlat + ",E" + Math.abs(dlon); url = "http://maps.google.com/maps?q=N" + dlat + ",E" + Math.abs(dlon);
System.out.println("url: " + url); System.out.println("url: " + url);
@ -223,7 +224,7 @@ public class GeoPointParserUtil {
System.out.println("url: " + url); System.out.println("url: " + url);
actual = GeoPointParserUtil.parse(url); actual = GeoPointParserUtil.parse(url);
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z));
// http://osmand.net/go?lat=34&lon=-106&z=11 // http://osmand.net/go?lat=34&lon=-106&z=11
url = "http://osmand.net/go?lat=" + ilat + "&lon=" + ilon + "&z=" + z; url = "http://osmand.net/go?lat=" + ilat + "&lon=" + ilon + "&z=" + z;
System.out.println("url: " + url); System.out.println("url: " + url);
@ -256,7 +257,7 @@ public class GeoPointParserUtil {
actual = GeoPointParserUtil.parse(url); actual = GeoPointParserUtil.parse(url);
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); 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; url = "https://www.openstreetmap.org/#map=" + z + "/" + dlat + "/" + dlon;
System.out.println("url: " + url); System.out.println("url: " + url);
actual = GeoPointParserUtil.parse(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 // 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 url = "https://www.openstreetmap.org/?mlat=" + longLat + "&mlon=" + longLon
+ "#map=" + z + "/" + dlat + "/" + dlon; + "#map=" + z + "/" + dlat + "/" + dlon;
System.out.println("url: " + url); System.out.println("url: " + url);
actual = GeoPointParserUtil.parse(url); actual = GeoPointParserUtil.parse(url);
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z));
@ -465,9 +466,9 @@ public class GeoPointParserUtil {
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); 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 // 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 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); System.out.println("url: " + url);
actual = GeoPointParserUtil.parse(url); actual = GeoPointParserUtil.parse(url);
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); 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 // http://map.baidu.com/?l=13&tn=B_NORMAL_MAP&c=13748138,4889173&s=gibberish
z = 7; z = 7;
int latint = ((int)(dlat * 100000)); int latint = ((int) (dlat * 100000));
int lonint = ((int)(dlon * 100000)); int lonint = ((int) (dlon * 100000));
url = "http://map.baidu.com/?l=" + z + "&tn=B_NORMAL_MAP&c=" + latint + "," + lonint + "&s=gibberish"; url = "http://map.baidu.com/?l=" + z + "&tn=B_NORMAL_MAP&c=" + latint + "," + lonint + "&s=gibberish";
System.out.println("url: " + url); System.out.println("url: " + url);
actual = GeoPointParserUtil.parse(url); actual = GeoPointParserUtil.parse(url);
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); 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 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"; url = "http://www.amap.com/#!poi!!q=" + dlat + "," + dlon + "|2|%E5%AE%BE%E9%A6%86&radius=1000";
System.out.println("\nurl: " + url); System.out.println("\nurl: " + url);
@ -587,44 +588,44 @@ public class GeoPointParserUtil {
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z));
/* URLs straight from various services, instead of generated here */ /* URLs straight from various services, instead of generated here */
String urls[] = { String urls[] = {
"https://openstreetmap.org/go/0LQ127-?m", "https://openstreetmap.org/go/0LQ127-?m",
"http://osm.org/go/0LQ127-?m", "http://osm.org/go/0LQ127-?m",
"http://osm.org/go/0EEQjE==", "http://osm.org/go/0EEQjE==",
"http://osm.org/go/0EEQjEEb", "http://osm.org/go/0EEQjEEb",
"http://osm.org/go/0EE~jEEb", "http://osm.org/go/0EE~jEEb",
"http://osm.org/go/0EE@jEEb", "http://osm.org/go/0EE@jEEb",
"http://osm.org/go/~~~~", "http://osm.org/go/~~~~",
"http://osm.org/go/@@@@", "http://osm.org/go/@@@@",
"https://www.openstreetmap.org/#map=0/0/0", "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/-180", "https://www.openstreetmap.org/#map=0/-180/-180",
"https://www.openstreetmap.org/#map=0/180.0/180.0", "https://www.openstreetmap.org/#map=0/180.0/180.0",
"https://www.openstreetmap.org/#map=6/33.907/34.662", "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.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", "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://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://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.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/#!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://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", "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/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", "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/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",
"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.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://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.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/?q=Bargou,+Tunisien",
"http://maps.apple.com/?daddr=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=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", "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", "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,-106,14z",
"http://www.google.com/maps/search/food/@34.99393,-106.61568,14z", "http://www.google.com/maps/search/food/@34.99393,-106.61568,14z",
}; };
for (String u : urls) { for (String u : urls) {
System.out.println("url: " + u); System.out.println("url: " + u);
@ -636,14 +637,14 @@ public class GeoPointParserUtil {
// these URLs are not parsable, but should not crash or cause problems // these URLs are not parsable, but should not crash or cause problems
String[] unparsableUrls = { String[] unparsableUrls = {
"http://maps.yandex.ru/-/CVCw6M9g", "http://maps.yandex.ru/-/CVCw6M9g",
"http://maps.yandex.com/-/CVCXEKYW", "http://maps.yandex.com/-/CVCXEKYW",
"http://goo.gl/maps/Cji0V", "http://goo.gl/maps/Cji0V",
"http://amap.com/0F0i02", "http://amap.com/0F0i02",
"http://j.map.baidu.com/oXrVz", "http://j.map.baidu.com/oXrVz",
"http://l.map.qq.com/9741483212?m", "http://l.map.qq.com/9741483212?m",
"http://map.qq.com/?l=261496722", "http://map.qq.com/?l=261496722",
"http://her.is/vLCEXE", "http://her.is/vLCEXE",
}; };
for (String u : unparsableUrls) { for (String u : unparsableUrls) {
@ -653,8 +654,8 @@ public class GeoPointParserUtil {
throw new RuntimeException(u + " not parsable, but parse did not return null!"); throw new RuntimeException(u + " not parsable, but parse did not return null!");
System.out.println("Handled URL"); System.out.println("Handled URL");
} }
} }
private static boolean areCloseEnough(double a, double b, long howClose) { private static boolean areCloseEnough(double a, double b, long howClose) {
@ -667,7 +668,7 @@ public class GeoPointParserUtil {
if (expected.getQuery() != null) { if (expected.getQuery() != null) {
if (!expected.getQuery().equals(actual.getQuery())) if (!expected.getQuery().equals(actual.getQuery()))
throw new RuntimeException("Query param not equal:\n'" + throw new RuntimeException("Query param not equal:\n'" +
actual.getQuery() + "' != '" + expected.getQuery()); actual.getQuery() + "' != '" + expected.getQuery());
} else { } else {
double aLat = actual.getLatitude(), eLat = expected.getLatitude(), aLon = actual.getLongitude(), eLon = expected.getLongitude(); double aLat = actual.getLatitude(), eLat = expected.getLatitude(), aLon = actual.getLongitude(), eLon = expected.getLongitude();
int aZoom = actual.getZoom(), eZoom = expected.getZoom(); int aZoom = actual.getZoom(), eZoom = expected.getZoom();
@ -705,10 +706,10 @@ public class GeoPointParserUtil {
+ aLabel + ", expected=" + eLabel); + aLabel + ", expected=" + eLabel);
} }
} }
if (((int)eLat) != ((int)aLat)) { if (((int) eLat) != ((int) aLat)) {
throw new RuntimeException("Latitude is not equal; actual=" + aLat + ", expected=" + eLat); 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); throw new RuntimeException("Longitude is not equal; actual=" + aLon + ", expected=" + eLon);
} }
if (eZoom != aZoom) { if (eZoom != aZoom) {
@ -718,10 +719,10 @@ public class GeoPointParserUtil {
System.out.println("Passed!"); System.out.println("Passed!");
} }
private static void assertUrlEquals(String actual, String expected) { private static void assertUrlEquals(String actual, String expected) {
if (actual == null || !actual.equals(expected)) if (actual == null || !actual.equals(expected))
throw new RuntimeException("URLs not equal; actual=" + actual + ", expected=" + expected); throw new RuntimeException("URLs not equal; actual=" + actual + ", expected=" + expected);
} }
private static String getQueryParameter(final String param, URI uri) { private static String getQueryParameter(final String param, URI uri) {
final String query = uri.getQuery(); final String query = uri.getQuery();
@ -738,43 +739,43 @@ public class GeoPointParserUtil {
return value; return value;
} }
/** /**
* This parses out all of the parameters in the query string for both * 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 * 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 * it will not work on URIs that do odd things like have a query string in
* the fragment, like this one: * the fragment, like this one:
* 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
* *
* @param uri * @param uri
* @return {@link Map<String, String>} a Map of the query parameters * @return {@link Map<String, String>} a Map of the query parameters
*/ */
private static Map<String, String> getQueryParameters(URI uri) { private static Map<String, String> getQueryParameters(URI uri) {
String query = null; String query = null;
if (uri.isOpaque()) { if (uri.isOpaque()) {
String schemeSpecificPart = uri.getSchemeSpecificPart(); String schemeSpecificPart = uri.getSchemeSpecificPart();
int pos = schemeSpecificPart.indexOf("?"); int pos = schemeSpecificPart.indexOf("?");
if (pos == schemeSpecificPart.length()) { if (pos == schemeSpecificPart.length()) {
query = ""; query = "";
} else if (pos > -1) { } else if (pos > -1) {
query = schemeSpecificPart.substring(pos + 1); query = schemeSpecificPart.substring(pos + 1);
} }
} else { } else {
query = uri.getRawQuery(); query = uri.getRawQuery();
} }
return getQueryParameters(query); return getQueryParameters(query);
} }
private static Map<String, String> getQueryParameters(String query) { private static Map<String, String> getQueryParameters(String query) {
final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>(); final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
if (query != null && !query.equals("")) { if (query != null && !query.equals("")) {
String[] params = query.split("&"); String[] params = query.split("&");
for (String p : params) { for (String p : params) {
String[] keyValue = p.split("="); String[] keyValue = p.split("=");
if (keyValue.length == 1) if (keyValue.length == 1)
map.put(keyValue[0], ""); map.put(keyValue[0], "");
else if (keyValue.length > 1) else if (keyValue.length > 1)
map.put(keyValue[0], URLDecoder.decode(keyValue[1])); map.put(keyValue[0], URLDecoder.decode(keyValue[1]));
} }
} }
return map; return map;
} }
@ -786,67 +787,68 @@ public class GeoPointParserUtil {
* @return {@link GeoParsedPoint} * @return {@link GeoParsedPoint}
*/ */
public static GeoParsedPoint parse(final String uriString) { public static GeoParsedPoint parse(final String uriString) {
URI uri; System.out.println("parse(" + "uriString=" + uriString + ")");
try { URI uri;
// amap.com uses | in their URLs, which is an illegal character for a URL try {
uri = URI.create(uriString.replaceAll("\\s+", "+") // amap.com uses | in their URLs, which is an illegal character for a URL
.replaceAll("%20", "+") uri = URI.create(uriString.replaceAll("\\s+", "+")
.replaceAll("%2C", ",") .replaceAll("%20", "+")
.replaceAll("\\|", ";") .replaceAll("%2C", ",")
.replaceAll("\\(\\(\\S+\\)\\)", "")); .replaceAll("\\|", ";")
} catch (IllegalArgumentException e) { .replaceAll("\\(\\(\\S+\\)\\)", ""));
return null; } catch (IllegalArgumentException e) {
} return null;
}
String scheme = uri.getScheme(); String scheme = uri.getScheme();
if (scheme == null) if (scheme == null)
return null; return null;
else else
scheme = scheme.toLowerCase(Locale.US); scheme = scheme.toLowerCase(Locale.US);
if ("http".equals(scheme) || "https".equals(scheme)) { if ("http".equals(scheme) || "https".equals(scheme)) {
String host = uri.getHost(); String host = uri.getHost();
if (host == null) if (host == null)
return null; return null;
else else
host = host.toLowerCase(Locale.US); host = host.toLowerCase(Locale.US);
String path = uri.getPath(); String path = uri.getPath();
if (path == null) { if (path == null) {
path = ""; path = "";
} }
String fragment = uri.getFragment(); String fragment = uri.getFragment();
// lat-double, lon - double, zoom or z - int // lat-double, lon - double, zoom or z - int
Set<String> simpleDomains = new HashSet<String>(); Set<String> simpleDomains = new HashSet<String>();
simpleDomains.add("osmand.net"); simpleDomains.add("osmand.net");
simpleDomains.add("www.osmand.net"); simpleDomains.add("www.osmand.net");
simpleDomains.add("download.osmand.net"); simpleDomains.add("download.osmand.net");
simpleDomains.add("openstreetmap.de"); simpleDomains.add("openstreetmap.de");
simpleDomains.add("www.openstreetmap.de"); simpleDomains.add("www.openstreetmap.de");
final Pattern commaSeparatedPairPattern = Pattern.compile("(?:loc:)?([N|S]?[+-]?\\d+(?:\\.\\d+)?),([E|W]?[+-]?\\d+(?:\\.\\d+)?)"); final Pattern commaSeparatedPairPattern = Pattern.compile("(?:loc:)?([N|S]?[+-]?\\d+(?:\\.\\d+)?),([E|W]?[+-]?\\d+(?:\\.\\d+)?)");
try { try {
if (host.equals("osm.org") || host.endsWith("openstreetmap.org")) { if (host.equals("osm.org") || host.endsWith("openstreetmap.org")) {
Pattern p; Pattern p;
Matcher matcher; Matcher matcher;
if (path.startsWith("/go/")) { // short URL form if (path.startsWith("/go/")) { // short URL form
p = Pattern.compile("^/go/([A-Za-z0-9_@~]+-*)(?:.*)"); p = Pattern.compile("^/go/([A-Za-z0-9_@~]+-*)(?:.*)");
matcher = p.matcher(path); matcher = p.matcher(path);
if (matcher.matches()) { if (matcher.matches()) {
return MapUtils.decodeShortLinkString(matcher.group(1)); return MapUtils.decodeShortLinkString(matcher.group(1));
} }
} else { // data in the query and/or feature strings } else { // data in the query and/or feature strings
double lat = 0; double lat = 0;
double lon = 0; double lon = 0;
int zoom = GeoParsedPoint.NO_ZOOM; int zoom = GeoParsedPoint.NO_ZOOM;
if (fragment != null) { if (fragment != null) {
if(fragment.startsWith("map=")) { if (fragment.startsWith("map=")) {
fragment = fragment.substring("map=".length()); fragment = fragment.substring("map=".length());
} }
String[] vls = fragment.split("/"); String[] vls = fragment.split("/");
if(vls.length >= 3) { if (vls.length >= 3) {
zoom = parseZoom(vls[0]); zoom = parseZoom(vls[0]);
lat = parseSilentDouble(vls[1]); lat = parseSilentDouble(vls[1]);
lon = parseSilentDouble(vls[2]); lon = parseSilentDouble(vls[2]);
@ -854,30 +856,30 @@ public class GeoPointParserUtil {
} }
// the query string sometimes has higher resolution values // the query string sometimes has higher resolution values
String mlat = getQueryParameter("mlat", uri); String mlat = getQueryParameter("mlat", uri);
if(mlat != null) { if (mlat != null) {
lat = parseSilentDouble(mlat); lat = parseSilentDouble(mlat);
} }
String mlon = getQueryParameter("mlon", uri); String mlon = getQueryParameter("mlon", uri);
if(mlon != null) { if (mlon != null) {
lon = parseSilentDouble(mlon); lon = parseSilentDouble(mlon);
} }
return new GeoParsedPoint(lat, lon, zoom); return new GeoParsedPoint(lat, lon, zoom);
} }
} else if (host.startsWith("map.baidu.")) { // .com and .cn both work } 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 /* Baidu Map uses a custom format for lat/lon., it is basically standard lat/lon
* multiplied by 100,000, then rounded to an integer */ * multiplied by 100,000, then rounded to an integer */
Map<String, String> params = getQueryParameters(uri); Map<String, String> params = getQueryParameters(uri);
String zm = params.get("l"); String zm = params.get("l");
String[] vls = silentSplit(params.get("c"),","); String[] vls = silentSplit(params.get("c"), ",");
if ( vls != null && vls.length >= 2) { if (vls != null && vls.length >= 2) {
double lat = parseSilentInt(vls[0]) / 100000.; double lat = parseSilentInt(vls[0]) / 100000.;
double lon = parseSilentInt(vls[1]) / 100000.; double lon = parseSilentInt(vls[1]) / 100000.;
int zoom = parseZoom(zm); int zoom = parseZoom(zm);
return new GeoParsedPoint(lat, lon, zoom); return new GeoParsedPoint(lat, lon, zoom);
} }
} else if (simpleDomains.contains(host)) { } else if (simpleDomains.contains(host)) {
Map<String, String> params = getQueryParameters(uri); Map<String, String> 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) // DOUBLE check this may be wrong test of openstreetmap.de (looks very weird url and server doesn't respond)
params = getQueryParameters(path.substring(1)); params = getQueryParameters(path.substring(1));
} }
@ -907,13 +909,13 @@ public class GeoPointParserUtil {
String lonString = null; String lonString = null;
String z = String.valueOf(GeoParsedPoint.NO_ZOOM); String z = String.valueOf(GeoParsedPoint.NO_ZOOM);
Map<String, String> params = getQueryParameters(uri); Map<String, String> params = getQueryParameters(uri);
if(params.containsKey("q")){ if (params.containsKey("q")) {
Matcher matcher = commaSeparatedPairPattern.matcher(params.get("q")); Matcher matcher = commaSeparatedPairPattern.matcher(params.get("q"));
if (matcher.matches()) { if (matcher.matches()) {
latString = matcher.group(1); latString = matcher.group(1);
lonString = matcher.group(2); lonString = matcher.group(2);
} }
} else if(params.containsKey("ll")){ } else if (params.containsKey("ll")) {
Matcher matcher = commaSeparatedPairPattern.matcher(params.get("ll")); Matcher matcher = commaSeparatedPairPattern.matcher(params.get("ll"));
if (matcher.matches()) { if (matcher.matches()) {
latString = matcher.group(1); latString = matcher.group(1);
@ -926,11 +928,11 @@ public class GeoPointParserUtil {
} }
return new GeoParsedPoint(latString, lonString, z); return new GeoParsedPoint(latString, lonString, z);
} }
if(params.containsKey("daddr")){ if (params.containsKey("daddr")) {
return parseGoogleMapsPath(params.get("daddr"), params); return parseGoogleMapsPath(params.get("daddr"), params);
} else if(params.containsKey("saddr")){ } else if (params.containsKey("saddr")) {
return parseGoogleMapsPath(params.get("saddr"), params); return parseGoogleMapsPath(params.get("saddr"), params);
} else if(params.containsKey("q")){ } else if (params.containsKey("q")) {
return parseGoogleMapsPath(params.get("q"), params); return parseGoogleMapsPath(params.get("q"), params);
} }
if (fragment != null) { if (fragment != null) {
@ -940,9 +942,9 @@ public class GeoPointParserUtil {
return new GeoParsedPoint(m.group(1)); return new GeoParsedPoint(m.group(1));
} }
} }
String[] pathPrefixes = new String[] { "/@", "/ll=", String[] pathPrefixes = new String[]{"/@", "/ll=",
"loc:", "/" }; "loc:", "/"};
for (String pref : pathPrefixes) { for (String pref : pathPrefixes) {
if (path.contains(pref)) { if (path.contains(pref)) {
path = path.substring(path.lastIndexOf(pref) path = path.substring(path.lastIndexOf(pref)
@ -959,9 +961,9 @@ public class GeoPointParserUtil {
Matcher matcher; Matcher matcher;
final String[] patterns = { final String[] patterns = {
/* though this looks like Query String, it is also used as part of the Fragment */ /* 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+)?).*&radius=(\\d+).*",
".*q=([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?).*", ".*q=([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?).*",
".*p=(?:[A-Z0-9]+),([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?).*", }; ".*p=(?:[A-Z0-9]+),([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?).*",};
for (int i = 0; i < patterns.length; i++) { for (int i = 0; i < patterns.length; i++) {
p = Pattern.compile(patterns[i]); p = Pattern.compile(patterns[i]);
matcher = p.matcher(subString); matcher = p.matcher(subString);
@ -969,7 +971,7 @@ public class GeoPointParserUtil {
if (matcher.groupCount() == 3) { if (matcher.groupCount() == 3) {
// amap uses radius in meters, so do rough conversion into zoom level // amap uses radius in meters, so do rough conversion into zoom level
float radius = Float.valueOf(matcher.group(3)); 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)); return new GeoParsedPoint(matcher.group(1), matcher.group(2), String.valueOf(zoom));
} else if (matcher.groupCount() == 2) { } else if (matcher.groupCount() == 2) {
return new GeoParsedPoint(matcher.group(1), matcher.group(2)); return new GeoParsedPoint(matcher.group(1), matcher.group(2));
@ -1096,9 +1098,9 @@ public class GeoPointParserUtil {
} }
} }
} catch (RuntimeException e) { } catch (RuntimeException e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
} else if ("geo".equals(scheme) || "osmand.geo".equals(scheme)) { } else if ("geo".equals(scheme) || "osmand.geo".equals(scheme)) {
String schemeSpecific = uri.getSchemeSpecificPart(); String schemeSpecific = uri.getSchemeSpecificPart();
@ -1182,14 +1184,14 @@ public class GeoPointParserUtil {
String zmPart = ""; String zmPart = "";
String descr = ""; String descr = "";
String path = opath; String path = opath;
if(path.contains("&")){ if (path.contains("&")) {
String[] vls = path.split("&"); String[] vls = path.split("&");
path = vls[0]; path = vls[0];
for(int i = 1; i < vls.length; i++) { for (int i = 1; i < vls.length; i++) {
int ik = vls[i].indexOf('='); int ik = vls[i].indexOf('=');
if(ik > 0) { if (ik > 0) {
params.put(vls[i].substring(0, ik), vls[i].substring(ik + 1)); params.put(vls[i].substring(0, ik), vls[i].substring(ik + 1));
} }
} }
} }
if (path.contains("+")) { if (path.contains("+")) {
@ -1200,36 +1202,36 @@ public class GeoPointParserUtil {
} }
} }
if(params.containsKey("z")) { if (params.containsKey("z")) {
zmPart = params.get("z"); zmPart = params.get("z");
} }
String[] vls = silentSplit(path, ","); String[] vls = silentSplit(path, ",");
if(vls.length >= 2) { if (vls.length >= 2) {
double lat = parseSilentDouble(vls[0]); double lat = parseSilentDouble(vls[0]);
double lon = parseSilentDouble(vls[1]) ; double lon = parseSilentDouble(vls[1]);
int zoom = GeoParsedPoint.NO_ZOOM; int zoom = GeoParsedPoint.NO_ZOOM;
if(vls.length >= 3 || zmPart.length() > 0) { if (vls.length >= 3 || zmPart.length() > 0) {
if(zmPart.length() == 0){ if (zmPart.length() == 0) {
zmPart = vls[2]; zmPart = vls[2];
} }
if(zmPart.startsWith("z=")) { if (zmPart.startsWith("z=")) {
zmPart = zmPart.substring(2); zmPart = zmPart.substring(2);
} else if(zmPart.contains("z")) { } else if (zmPart.contains("z")) {
zmPart = zmPart.substring(0, zmPart.indexOf('z')); zmPart = zmPart.substring(0, zmPart.indexOf('z'));
} }
zoom = parseZoom(zmPart); zoom = parseZoom(zmPart);
} }
return new GeoParsedPoint(lat, lon, zoom); return new GeoParsedPoint(lat, lon, zoom);
} }
return new GeoParsedPoint(URLDecoder.decode(opath)); return new GeoParsedPoint(URLDecoder.decode(opath));
} }
private static String[] silentSplit(String vl, String split) { private static String[] silentSplit(String vl, String split) {
if(vl == null) { if (vl == null) {
return null; return null;
} }
return vl.split(split); return vl.split(split);
} }
private static int parseZoom(String zoom) { private static int parseZoom(String zoom) {
@ -1241,7 +1243,7 @@ public class GeoPointParserUtil {
} }
return GeoParsedPoint.NO_ZOOM; return GeoParsedPoint.NO_ZOOM;
} }
private static double parseSilentDouble(String zoom) { private static double parseSilentDouble(String zoom) {
try { try {
if (zoom != null) { if (zoom != null) {
@ -1251,7 +1253,7 @@ public class GeoPointParserUtil {
} }
return 0; return 0;
} }
private static int parseSilentInt(String zoom) { private static int parseSilentInt(String zoom) {
try { try {
if (zoom != null) { if (zoom != null) {
@ -1307,20 +1309,20 @@ public class GeoPointParserUtil {
} }
private static double parseLon(String lonString) { private static double parseLon(String lonString) {
if(lonString.startsWith("E")) { if (lonString.startsWith("E")) {
return -Double.valueOf(lonString.substring(1)); 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.substring(1));
} }
return Double.valueOf(lonString); return Double.valueOf(lonString);
} }
private static double parseLat(String latString) { private static double parseLat(String latString) {
if(latString.startsWith("S")) { if (latString.startsWith("S")) {
return -Double.valueOf(latString.substring(1)); 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.substring(1));
} }
return Double.valueOf(latString); return Double.valueOf(latString);
} }
@ -1363,8 +1365,8 @@ public class GeoPointParserUtil {
} }
private String formatDouble(double d) { private String formatDouble(double d) {
if(d == (long) d) if (d == (long) d)
return String.format(Locale.ENGLISH, "%d", (long)d); return String.format(Locale.ENGLISH, "%d", (long) d);
else else
return String.format("%s", d); return String.format("%s", d);
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4 KiB

View file

@ -51,6 +51,13 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
super.onAttach(activity); super.onAttach(activity);
Intent intent = activity.getIntent(); 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) { if (intent != null) {
selectFavoriteMode = intent.hasExtra(SELECT_FAVORITE_POINT_INTENT_KEY); selectFavoriteMode = intent.hasExtra(SELECT_FAVORITE_POINT_INTENT_KEY);
if (intent.hasExtra(SearchActivity.SEARCH_LAT) && intent.hasExtra(SearchActivity.SEARCH_LON)) { 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() { private OsmandApplication getApplication() {