This commit is contained in:
Denis 2015-02-02 18:02:30 +02:00
commit 411844510d
7 changed files with 127 additions and 162 deletions

View file

@ -1,107 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="EclipseModuleManager">
<libelement value="jar://$MODULE_DIR$/libs/bsh-core-2.0b4.jar!/" />
<libelement value="jar://$MODULE_DIR$/libs/bzip2-20090327.jar!/" />
<libelement value="jar://$MODULE_DIR$/libs/commons-logging-1.1.1.jar!/" />
<libelement value="jar://$MODULE_DIR$/libs/json-20090211.jar!/" />
<libelement value="jar://$MODULE_DIR$/libs/junidecode-0.1.jar!/" />
<libelement value="jar://$MODULE_DIR$/libs/kxml2-2.3.0.jar!/" />
<libelement value="jar://$MODULE_DIR$/libs/tuprolog.jar!/" />
<libelement value="jar://$MODULE_DIR$/libs/icu4j-49_1.jar!/" />
<libelement value="jar://$MODULE_DIR$/libs/gnu-trove-osmand.jar!/" />
<src_description expected_position="0">
<src_folder value="file://$MODULE_DIR$/src" expected_position="0" />
</src_description>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/bin" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="jdk" jdkName="1.7" jdkType="JavaSDK" />
<orderEntry type="module-library">
<library name="bsh-core-2.0b4.jar">
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/bsh-core-2.0b4.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="bzip2-20090327.jar">
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/bzip2-20090327.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="commons-logging-1.1.1.jar">
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/commons-logging-1.1.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="json-20090211.jar">
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/json-20090211.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="junidecode-0.1.jar">
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/junidecode-0.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="kxml2-2.3.0.jar">
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/kxml2-2.3.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="tuprolog.jar">
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/tuprolog.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="icu4j-49_1.jar">
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/icu4j-49_1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="gnu-trove-osmand.jar">
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/gnu-trove-osmand.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

View file

@ -1,15 +1,20 @@
apply plugin: 'java'
jar {
sourceSets {
sourceSets {
main {
java {
srcDirs = ["src"]
}
srcDirs = [
"src"
]
}
}
}
// This is Android-specific
jar {
exclude "**/PlatformUtil.*"
}
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
}

View file

@ -5,6 +5,7 @@ import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@ -25,12 +26,14 @@ public class GeoPointParserUtil {
url = "geo:" + ilat + "," + ilon;
System.out.println("url: " + url);
GeoParsedPoint actual = GeoPointParserUtil.parse(url);
assertUrlEquals(url, actual.getGeoUriString());
assertGeoPoint(actual, new GeoParsedPoint(ilat, ilon));
// geo:34.99393,-106.61568
url = "geo:" + dlat + "," + dlon;
System.out.println("url: " + url);
actual = GeoPointParserUtil.parse(url);
assertUrlEquals(url, actual.getGeoUriString());
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon));
// geo:34.99393,-106.61568?z=11
@ -38,6 +41,7 @@ public class GeoPointParserUtil {
url = "geo:" + dlat + "," + dlon + "?z=" + z;
System.out.println("url: " + url);
actual = GeoPointParserUtil.parse(url);
assertUrlEquals(url, actual.getGeoUriString());
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z));
// geo:34.99393,-106.61568 (Treasure Island)
@ -60,16 +64,23 @@ public class GeoPointParserUtil {
actual = GeoPointParserUtil.parse(url);
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z, name));
// geo:34.99393,-106.61568?q=34.99393,-106.61568(Treasure+Island)
z = GeoParsedPoint.NO_ZOOM;
url = "geo:" + dlat + "," + dlon + "?q=" + dlat + "," + dlon + "(" + URLEncoder.encode(name) + ")";
System.out.println("url: " + url);
actual = GeoPointParserUtil.parse(url);
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z, name));
assertUrlEquals(url, actual.getGeoUriString());
// 0,0?q=34,-106(Treasure Island)
z = GeoParsedPoint.NO_ZOOM;
url = "geo:0,0?q=" + ilat + "," + ilon + " (" + name + ")";
System.out.println("url: " + url);
url = "geo:0,0?q=" + ilat + "," + ilon + "(" + name + ")";
actual = GeoPointParserUtil.parse(url);
assertGeoPoint(actual, new GeoParsedPoint(ilat, ilon, z, name));
// 0,0?q=34.99393,-106.61568(Treasure Island)
z = GeoParsedPoint.NO_ZOOM;
url = "geo:0,0?q=" + dlat + "," + dlon + " (" + name + ")";
url = "geo:0,0?q=" + dlat + "," + dlon + "(" + name + ")";
System.out.println("url: " + url);
actual = GeoPointParserUtil.parse(url);
assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z, name));
@ -91,11 +102,27 @@ public class GeoPointParserUtil {
// google calendar
// geo:0,0?q=760 West Genesee Street Syracuse NY 13204
String qstr = "760 West Genesee Street Syracuse NY 13204";
url = "geo:0,0?q=" + URLEncoder.encode(qstr);
System.out.println("url: " + url);
actual = GeoPointParserUtil.parse(url);
assertGeoPoint(actual, new GeoParsedPoint(qstr));
assertUrlEquals(url, actual.getGeoUriString());
// geo:0,0?q=760 West Genesee Street Syracuse NY 13204
qstr = "760 West Genesee Street Syracuse NY 13204";
url = "geo:0,0?q=" + qstr;
System.out.println("url: " + url);
actual = GeoPointParserUtil.parse(url);
assertGeoPoint(actual, new GeoParsedPoint(qstr));
// geo:0,0?z=11&q=1600+Amphitheatre+Parkway,+CA
qstr = "1600 Amphitheatre Parkway, CA";
url = "geo:0,0?q=" + URLEncoder.encode(qstr);
System.out.println("url: " + url);
actual = GeoPointParserUtil.parse(url);
assertGeoPoint(actual, new GeoParsedPoint(qstr));
assertUrlEquals(url, actual.getGeoUriString());
// geo:0,0?z=11&q=1600+Amphitheatre+Parkway,+CA
qstr = "1600 Amphitheatre Parkway, CA";
url = "geo:0,0?z=11&q=" + URLEncoder.encode(qstr);
@ -398,7 +425,6 @@ public class GeoPointParserUtil {
private static boolean areCloseEnough(double a, double b, long howClose) {
long aRounded = (long) Math.round(a * Math.pow(10, howClose));
long bRounded = (long) Math.round(b * Math.pow(10, howClose));
System.out.println("areCloseEnough: " + aRounded + ", " + bRounded);
return aRounded == bRounded;
}
@ -409,11 +435,11 @@ public class GeoPointParserUtil {
} else {
double aLat = actual.getLatitude(), eLat = expected.getLatitude(), aLon = actual.getLongitude(), eLon = expected.getLongitude();
int aZoom = actual.getZoom(), eZoom = expected.getZoom();
String aName = actual.getName(), eName = expected.getName();
if (eName != null) {
if (!aName.equals(eName)) {
throw new RuntimeException("Point name\\capture is not equal; actual=" + aName + ", expected="
+ eName);
String aLabel = actual.getLabel(), eLabel = expected.getLabel();
if (eLabel != null) {
if (!aLabel.equals(eLabel)) {
throw new RuntimeException("Point label is not equal; actual="
+ aLabel + ", expected=" + eLabel);
}
}
if (!areCloseEnough(eLat, aLat, 5)) {
@ -436,11 +462,11 @@ public class GeoPointParserUtil {
} else {
double aLat = actual.getLatitude(), eLat = expected.getLatitude(), aLon = actual.getLongitude(), eLon = expected.getLongitude();
int aZoom = actual.getZoom(), eZoom = expected.getZoom();
String aName = actual.getName(), eName = expected.getName();
if (eName != null) {
if (!aName.equals(eName)) {
throw new RuntimeException("Point name\\capture is not equal; actual=" + aName + ", expected="
+ eName);
String aLabel = actual.getLabel(), eLabel = expected.getLabel();
if (eLabel != null) {
if (!aLabel.equals(eLabel)) {
throw new RuntimeException("Point label is not equal; actual="
+ aLabel + ", expected=" + eLabel);
}
}
if (((int)eLat) != ((int)aLat)) {
@ -456,6 +482,11 @@ 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 String getQueryParameter(final String param, URI uri) {
final String query = uri.getQuery();
String value = null;
@ -474,8 +505,7 @@ public class GeoPointParserUtil {
/**
* Parses geo and map intents:
*
* @param uri
* The URI object
* @param uriString The URI as a String
* @return {@link GeoParsedPoint}
*/
public static GeoParsedPoint parse(final String uriString) {
@ -781,10 +811,10 @@ public class GeoPointParserUtil {
public static class GeoParsedPoint {
private static final int NO_ZOOM = -1;
private double lat;
private double lon;
private double lat = 0;
private double lon = 0;
private int zoom = NO_ZOOM;
private String name;
private String label;
private String query;
private boolean geoPoint;
private boolean geoAddress;
@ -796,10 +826,10 @@ public class GeoPointParserUtil {
this.geoPoint = true;
}
public GeoParsedPoint(double lat, double lon, String name) {
public GeoParsedPoint(double lat, double lon, String label) {
this(lat, lon);
if (name != null)
this.name = name.replaceAll("\\+", " ");
if (label != null)
this.label = label.replaceAll("\\+", " ");
}
public GeoParsedPoint(double lat, double lon, int zoom) {
@ -807,8 +837,8 @@ public class GeoPointParserUtil {
this.zoom = zoom;
}
public GeoParsedPoint(double lat, double lon, int zoom, String name) {
this(lat, lon, name);
public GeoParsedPoint(double lat, double lon, int zoom, String label) {
this(lat, lon, label);
this.zoom = zoom;
}
@ -840,8 +870,8 @@ public class GeoPointParserUtil {
return zoom;
}
public String getName() {
return name;
public String getLabel() {
return label;
}
public String getQuery() {
@ -852,10 +882,59 @@ public class GeoPointParserUtil {
return geoPoint;
}
private String formatDouble(double d) {
if(d == (long) d)
return String.format(Locale.ENGLISH, "%d", (long)d);
else
return String.format("%s", d);
}
public boolean isGeoAddress() {
return geoAddress;
}
/**
* Generates a URI string according to https://tools.ietf.org/html/rfc5870 and
* https://developer.android.com/guide/components/intents-common.html#Maps
*/
@Override
public String getGeoUriString() {
String uriString;
if (isGeoPoint()) {
String latlon = formatDouble(lat) + "," + formatDouble(lon);
uriString = "geo:" + latlon;
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
if (zoom != NO_ZOOM)
map.put("z", String.valueOf(zoom));
if (query != null)
map.put("q", URLEncoder.encode(query));
if (label != null)
if (query == null)
map.put("q", latlon + "(" + URLEncoder.encode(label) + ")");
if (map.size() > 0)
uriString += "?";
int i = 0;
for (String key : map.keySet()) {
if (i > 0)
uriString += "&";
uriString += key + "=" + map.get(key);
i++;
}
return uriString;
}
if (isGeoAddress()) {
uriString = "geo:0,0";
if (query != null) {
uriString += "?";
if (zoom != NO_ZOOM)
uriString += "z=" + zoom + "&";
uriString += "q=" + URLEncoder.encode(query);
}
return uriString;
}
return null;
}
@Override
public String toString() {
return isGeoPoint() ? "GeoParsedPoint [lat=" + lat + ", lon=" + lon + ", zoom=" + zoom + ", name=" + name

23
OsmAnd/build.gradle Executable file → Normal file
View file

@ -73,30 +73,18 @@ android {
jni.srcDirs = []
jniLibs.srcDirs = ["libs"]
aidl.srcDirs = ["src"]
java.srcDirs = [
"src",
fileTree(dir: "../OsmAnd-java/src", exclude: "**/PlatformUtil.java")
]
resources.srcDirs = [
"src"
]
java.srcDirs = ["src"]
resources.srcDirs = ["src"]
renderscript.srcDirs = ["src"]
res.srcDirs = [
'res'
]
assets.srcDirs = [
'assets'
]
res.srcDirs = ["res"]
assets.srcDirs = ["assets"]
}
free {
manifest.srcFile "AndroidManifest-free.xml"
}
legacy {
jniLibs.srcDirs = [
"libgnustl"
]
jniLibs.srcDirs = ["libgnustl"]
}
}
@ -311,6 +299,7 @@ repositories {
}
dependencies {
compile project(":OsmAnd-java")
compile fileTree(
dir: "libs",
include: ["*.jar"],

View file

@ -210,8 +210,8 @@ public class GeoIntentActivity extends OsmandListActivity {
private MyService extract(final Uri uri) {
GeoPointParserUtil.GeoParsedPoint p = GeoPointParserUtil.parse(uri.toString());
if (p.isGeoPoint()) {
if (p.getName() != null) {
return new GeoPointSearch(p.getLatitude(), p.getLongitude(), p.getName(), p.getZoom());
if (p.getLabel() != null) {
return new GeoPointSearch(p.getLatitude(), p.getLongitude(), p.getLabel(), p.getZoom());
}
return new GeoPointSearch(p.getLatitude(), p.getLongitude(), p.getZoom());
} else {

View file

@ -1,5 +1,3 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()

View file

@ -1 +1,2 @@
include ':OsmAnd'
include ':OsmAnd-java'