aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java')
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java63
1 files changed, 20 insertions, 43 deletions
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java b/main/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java
index 7258e11..f1616ad 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;
+
+ protected 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