diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2012-11-19 21:06:55 +0100 |
---|---|---|
committer | Bananeweizen <bananeweizen@gmx.de> | 2012-11-19 21:06:55 +0100 |
commit | 32a3cab0f7ffe941fa8a4a4515fd444ca3052d28 (patch) | |
tree | bd183a02ddd40df56105aeff47dc03989dd406e6 /main/src/cgeo/geocaching/apps/cache | |
parent | 8b7cad1b798f20f00dfb7667eead71d456fb49fc (diff) | |
download | cgeo-32a3cab0f7ffe941fa8a4a4515fd444ca3052d28.zip cgeo-32a3cab0f7ffe941fa8a4a4515fd444ca3052d28.tar.gz cgeo-32a3cab0f7ffe941fa8a4a4515fd444ca3052d28.tar.bz2 |
fix #2175: Navigation for walking
* split navigation into two different apps (driving and walking)
* also split the maps directions into separate app and removed option
from the settings screen
Diffstat (limited to 'main/src/cgeo/geocaching/apps/cache')
3 files changed, 79 insertions, 45 deletions
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsDirectionApp.java b/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsDirectionApp.java new file mode 100644 index 0000000..38ddae6 --- /dev/null +++ b/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsDirectionApp.java @@ -0,0 +1,47 @@ +package cgeo.geocaching.apps.cache.navi; + +import cgeo.geocaching.IGeoData; +import cgeo.geocaching.R; +import cgeo.geocaching.cgeoapplication; +import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.utils.Log; + +import android.app.Activity; +import android.content.Intent; +import android.net.Uri; + +public class GoogleMapsDirectionApp extends AbstractPointNavigationApp { + + protected GoogleMapsDirectionApp() { + super(getString(R.string.cache_menu_maps_directions), null); + } + + @Override + public boolean isInstalled() { + return true; + } + + @Override + public void navigate(Activity activity, Geopoint coords) { + try { + IGeoData geo = cgeoapplication.getInstance().currentGeo(); + final Geopoint coordsNow = geo == null ? null : geo.getCoords(); + + if (coordsNow != null) { + activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri + .parse("http://maps.google.com/maps?f=d&saddr=" + + coordsNow.getLatitude() + "," + coordsNow.getLongitude() + "&daddr=" + + coords.getLatitude() + "," + coords.getLongitude()))); + } else { + activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri + .parse("http://maps.google.com/maps?f=d&daddr=" + + coords.getLatitude() + "," + coords.getLongitude()))); + } + + } catch (Exception e) { + Log.i("GoogleMapsDirection: application not available."); + } + + } + +} diff --git a/main/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java b/main/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java index 7258e11..e74eb89 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java @@ -1,10 +1,6 @@ package cgeo.geocaching.apps.cache.navi; -import cgeo.geocaching.IGeoData; import cgeo.geocaching.R; -import cgeo.geocaching.Settings; -import cgeo.geocaching.cgeoapplication; -import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.utils.Log; @@ -12,10 +8,13 @@ import android.app.Activity; import android.content.Intent; import android.net.Uri; -class GoogleNavigationApp extends AbstractPointNavigationApp { +abstract class GoogleNavigationApp extends AbstractPointNavigationApp { - GoogleNavigationApp() { - super(getString(R.string.cache_menu_tbt), null); + private final String mode; + + GoogleNavigationApp(final int nameResourceId, final String mode) { + super(getString(nameResourceId), null); + this.mode = mode; } @Override @@ -23,49 +22,27 @@ class GoogleNavigationApp extends AbstractPointNavigationApp { return true; } - private static boolean navigateToCoordinates(Activity activity, final Geopoint coords) { - IGeoData geo = cgeoapplication.getInstance().currentGeo(); - final Geopoint coordsNow = geo == null ? null : geo.getCoords(); - - // Google Navigation - if (Settings.isUseGoogleNavigation()) { - try { - activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri - .parse("google.navigation:ll=" + coords.getLatitude() + "," - + coords.getLongitude()))); - - return true; - } catch (Exception e) { - // nothing - } - } - - // Google Maps Directions + @Override + public void navigate(Activity activity, Geopoint coords) { try { - if (coordsNow != null) { - activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri - .parse("http://maps.google.com/maps?f=d&saddr=" - + coordsNow.getLatitude() + "," + coordsNow.getLongitude() + "&daddr=" - + coords.getLatitude() + "," + coords.getLongitude()))); - } else { - activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri - .parse("http://maps.google.com/maps?f=d&daddr=" - + coords.getLatitude() + "," + coords.getLongitude()))); - } + activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri + .parse("google.navigation:ll=" + coords.getLatitude() + "," + + coords.getLongitude() + mode))); - return true; } catch (Exception e) { - // nothing + Log.i("cgBase.runNavigation: No navigation application available."); } + } - Log.i("cgBase.runNavigation: No navigation application available."); - return false; + static class GoogleNavigationWalkingApp extends GoogleNavigationApp { + GoogleNavigationWalkingApp() { + super(R.string.cache_menu_navigation_walk, "&mode=w"); + } } - @Override - public void navigate(Activity activity, Geopoint coords) { - if (!navigateToCoordinates(activity, coords)) { - ActivityMixin.showToast(activity, getString(R.string.err_navigation_no)); + static class GoogleNavigationDrivingApp extends GoogleNavigationApp { + GoogleNavigationDrivingApp() { + super(R.string.cache_menu_navigation_drive, "&mode=d"); } } }
\ No newline at end of file diff --git a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java index 57a71bb..0ff4af2 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java @@ -8,6 +8,8 @@ import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.apps.AbstractAppFactory; import cgeo.geocaching.apps.App; +import cgeo.geocaching.apps.cache.navi.GoogleNavigationApp.GoogleNavigationDrivingApp; +import cgeo.geocaching.apps.cache.navi.GoogleNavigationApp.GoogleNavigationWalkingApp; import cgeo.geocaching.geopoint.Geopoint; import android.app.Activity; @@ -40,7 +42,7 @@ public final class NavigationAppFactory extends AbstractAppFactory { /** Google Maps */ GOOGLE_MAPS(new GoogleMapsApp(), 6), /** Google Navigation */ - GOOGLE_NAVIGATION(new GoogleNavigationApp(), 7), + GOOGLE_NAVIGATION(new GoogleNavigationDrivingApp(), 7), /** Google Streetview */ GOOGLE_STREETVIEW(new StreetviewApp(), 8), /** The external OruxMaps app */ @@ -48,7 +50,15 @@ public final class NavigationAppFactory extends AbstractAppFactory { /** The external navigon app */ NAVIGON(new NavigonApp(), 10), /** The external Sygic app */ - SYGIC(new SygicNavigationApp(), 11); + SYGIC(new SygicNavigationApp(), 11), + /** + * Google Navigation in walking mode + */ + GOOGLE_NAVIGATION_WALK(new GoogleNavigationWalkingApp(), 12), + /** + * Google Maps Directions + */ + GOOGLE_MAPS_DIRECTIONS(new GoogleMapsDirectionApp(), 13); NavigationAppsEnum(App app, int id) { this.app = app; |