From 63799d93f2c0870b45b2c7c813215014198ade06 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Thu, 5 Jan 2012 07:48:03 +0100 Subject: fix #944: Navigon support --- .../apps/cache/navi/NavigationAppFactory.java | 3 +- .../geocaching/apps/cache/navi/NavigonApp.java | 64 ++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 main/src/cgeo/geocaching/apps/cache/navi/NavigonApp.java (limited to 'main/src/cgeo/geocaching/apps/cache/navi') diff --git a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java index 6e596b0..234b182 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java @@ -34,7 +34,8 @@ public final class NavigationAppFactory extends AbstractAppFactory { new GoogleMapsApp(res), new GoogleNavigationApp(res), new StreetviewApp(res), - new OruxMapsApp(res) }; + new OruxMapsApp(res), + new NavigonApp() }; } return apps; } diff --git a/main/src/cgeo/geocaching/apps/cache/navi/NavigonApp.java b/main/src/cgeo/geocaching/apps/cache/navi/NavigonApp.java new file mode 100644 index 0000000..98d95ef --- /dev/null +++ b/main/src/cgeo/geocaching/apps/cache/navi/NavigonApp.java @@ -0,0 +1,64 @@ +package cgeo.geocaching.apps.cache.navi; + +import cgeo.geocaching.SearchResult; +import cgeo.geocaching.cgCache; +import cgeo.geocaching.cgGeo; +import cgeo.geocaching.cgWaypoint; +import cgeo.geocaching.geopoint.Geopoint; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.Resources; + +public class NavigonApp extends AbstractNavigationApp { + + private static final String INTENT = "android.intent.action.navigon.START_PUBLIC"; + private static final String INTENT_EXTRA_KEY_LATITUDE = "latitude"; + private static final String INTENT_EXTRA_KEY_LONGITUDE = "longitude"; + + NavigonApp() { + super("Navigon", INTENT); + } + + @Override + public boolean invoke(cgGeo geo, Activity activity, Resources res, cgCache cache, SearchResult search, cgWaypoint waypoint, Geopoint coords) { + if (cache == null && waypoint == null && coords == null) { + return false; + } + + try { + if (isInstalled(activity)) { + Geopoint usedCoords = getCoords(cache, waypoint, coords); + + final Intent intent = new Intent(INTENT); + + /* + * Long/Lat are float values in decimal degree format (+-DDD.DDDDD). + * Example: + * intent.putExtra(INTENT_EXTRA_KEY_LATITUDE, 46.12345f); + * intent.putExtra(INTENT_EXTRA_KEY_LONGITUDE, 23.12345f); + */ + intent.putExtra(INTENT_EXTRA_KEY_LATITUDE, (float) usedCoords.getLatitude()); + intent.putExtra(INTENT_EXTRA_KEY_LONGITUDE, (float) usedCoords.getLongitude()); + + activity.startActivity(intent); + + return true; + } + } catch (Exception e) { + // nothing + } + + return false; + } + + private static Geopoint getCoords(cgCache cache, cgWaypoint waypoint, Geopoint coords) { + if (cache != null) { + return cache.getCoords(); + } + else if (waypoint != null) { + return waypoint.getCoords(); + } + return coords; + } +} \ No newline at end of file -- cgit v1.1