Add google maps intent

This commit is contained in:
Victor Shcherb 2013-02-17 21:51:26 +01:00
parent 5acc6b3495
commit 218a67574f
2 changed files with 71 additions and 31 deletions

View file

@ -76,16 +76,23 @@
<activity android:name="net.osmand.plus.activities.search.SearchStreet2ByNameActivity"></activity>
<activity android:name="net.osmand.plus.activities.search.SearchBuildingByNameActivity"></activity>
<activity android:name="net.osmand.plus.activities.EditPOIFilterActivity"></activity>
<activity android:name="net.osmand.plus.activities.search.GeoIntentActivity"><intent-filter><action android:name="android.intent.action.VIEW"></action>
<activity android:name="net.osmand.plus.activities.search.GeoIntentActivity">
<intent-filter><action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<data android:scheme="geo"></data>
</intent-filter>
<intent-filter>
<data android:scheme="http" android:host="maps.google.com" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
<!-- requires read permission -->
<!--
<intent-filter android:label="OsmAnd">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/postal-address_v2" />
<data android:mimeType="vnd.android.cursor.item/postal-address_v2" />
</intent-filter>
-->
</activity>

View file

@ -184,12 +184,43 @@ public class GeoIntentActivity extends OsmandListActivity {
* @return
*/
private MyService extract(Uri data) {
// it is 0,0? that means a search
if (data.getSchemeSpecificPart().indexOf("0,0?") != -1) {
if ("http".equalsIgnoreCase(data.getScheme()) && "maps.google.com".equals(data.getHost()) && "/go".equals(data.getPath())) {
String q = data.getQueryParameter("q");
if (q.indexOf(',') != -1) {
int i = q.indexOf(',');
String lat = q.substring(0, i);
String lon = q.substring(i + 1);
try {
double llat = Double.parseDouble(lat.trim());
double llon = Double.parseDouble(lon.trim());
return new GeoPointSearch(llat, llon);
} catch (NumberFormatException e) {
showErrorMessage(q);
}
} else {
showErrorMessage(q);
}
} else if (data.getSchemeSpecificPart().indexOf("0,0?") != -1) {
// it is 0,0? that means a search
return new GeoAddressSearch(data.getQuery());
} else {
return new GeoPointSearch(data.getSchemeSpecificPart());
String geo = data.getSchemeSpecificPart();
int latIndex = geo.indexOf(',');
int lonIndex = geo.indexOf('?');
lonIndex = lonIndex > 0 ? lonIndex : geo.length();
if (latIndex > 0) {
try {
double lat = Double.parseDouble(geo.substring(0, latIndex).trim());
double lon = Double.parseDouble(geo.substring(latIndex + 1, lonIndex).trim());
return new GeoPointSearch(lat, lon);
} catch (NumberFormatException e) {
showErrorMessage(geo);
}
} else {
showErrorMessage(geo);
}
}
return new Empty();
}
private final class GeoAddressSearch implements MyService {
@ -276,39 +307,41 @@ public class GeoIntentActivity extends OsmandListActivity {
return getMyApplication().getResourceManager();
}
private void showErrorMessage(final String geo) {
runOnUiThread(new Runnable() {
@Override
public void run() {
AccessibleToast.makeText(GeoIntentActivity.this,
getString(R.string.search_offline_geo_error, geo),
Toast.LENGTH_LONG);
}
});
}
private class Empty implements MyService {
@Override
public Collection<MapObject> execute() {
return Collections.emptyList();
}
}
private class GeoPointSearch implements MyService {
private MapObject point;
/**
* geo:latitude,longitude geo:latitude,longitude?z=zoom
*/
public GeoPointSearch(final String geo) {
int latIndex = geo.indexOf(',');
int lonIndex = geo.indexOf('?');
lonIndex = lonIndex > 0 ? lonIndex : geo.length();
if (latIndex > 0) {
try {
double latitude = Double.parseDouble(geo.substring(0, latIndex).trim());
double longitude = Double.parseDouble(geo.substring(latIndex + 1, lonIndex).trim());
// TODO zoom is omited for now
point = new MapObject(new Node(latitude, longitude, -1)) {
private static final long serialVersionUID = -7028586132795853725L;
};
point.setName("Lat: " + latitude + ",Lon:" + longitude);
} catch (NumberFormatException e) {
runOnUiThread(new Runnable() {
@Override
public void run() {
AccessibleToast.makeText(GeoIntentActivity.this,
getString(R.string.search_offline_geo_error, geo),
Toast.LENGTH_LONG);
}
});
}
}
public GeoPointSearch(double lat , double lon ) {
// TODO zoom is omited for now
point = new MapObject(new Node(lat, lon, -1)) {
private static final long serialVersionUID = -7028586132795853725L;
};
point.setName("Lat: " + lat + ",Lon:" + lon);
}
@Override
public Collection<MapObject> execute() {
if (point != null) {