aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/apps/cache
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/apps/cache')
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/AbstractPointNavigationApp.java14
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/AbstractRadarApp.java45
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java22
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/PebbleApp.java28
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/RadarApp.java12
5 files changed, 88 insertions, 33 deletions
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/AbstractPointNavigationApp.java b/main/src/cgeo/geocaching/apps/cache/navi/AbstractPointNavigationApp.java
index a1c752c..ec9705c 100644
--- a/main/src/cgeo/geocaching/apps/cache/navi/AbstractPointNavigationApp.java
+++ b/main/src/cgeo/geocaching/apps/cache/navi/AbstractPointNavigationApp.java
@@ -8,6 +8,7 @@ import cgeo.geocaching.apps.AbstractApp;
import cgeo.geocaching.geopoint.Geopoint;
import android.app.Activity;
+import android.content.Intent;
/**
* navigation app for simple point navigation (no differentiation between cache/waypoint/point)
@@ -49,4 +50,17 @@ abstract class AbstractPointNavigationApp extends AbstractApp implements CacheNa
public boolean isEnabled(Waypoint waypoint) {
return waypoint.getCoords() != null;
}
+
+ protected static void addIntentExtras(final Intent intent, final Waypoint waypoint) {
+ intent.putExtra("name", waypoint.getName());
+ intent.putExtra("code", waypoint.getGeocode());
+ }
+
+ protected static void addIntentExtras(final Intent intent, final Geocache cache) {
+ intent.putExtra("difficulty", cache.getDifficulty());
+ intent.putExtra("terrain", cache.getTerrain());
+ intent.putExtra("name", cache.getName());
+ intent.putExtra("code", cache.getGeocode());
+ intent.putExtra("size", cache.getSize().getL10n());
+ }
}
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/AbstractRadarApp.java b/main/src/cgeo/geocaching/apps/cache/navi/AbstractRadarApp.java
new file mode 100644
index 0000000..6c6ffda
--- /dev/null
+++ b/main/src/cgeo/geocaching/apps/cache/navi/AbstractRadarApp.java
@@ -0,0 +1,45 @@
+package cgeo.geocaching.apps.cache.navi;
+
+import cgeo.geocaching.Geocache;
+import cgeo.geocaching.Waypoint;
+import cgeo.geocaching.geopoint.Geopoint;
+
+import android.app.Activity;
+import android.content.Intent;
+
+public abstract class AbstractRadarApp extends AbstractPointNavigationApp {
+
+ private final String intentAction;
+
+ protected AbstractRadarApp(final String name, final int id, final String intent, final String packageName) {
+ super(name, id, intent, packageName);
+ this.intentAction = intent;
+ }
+
+ private Intent createIntent(final Geopoint point) {
+ final Intent intent = new Intent(intentAction);
+ addCoordinates(intent, point);
+ return intent;
+ }
+
+ @Override
+ public void navigate(final Activity activity, final Geopoint point) {
+ activity.startActivity(createIntent(point));
+ }
+
+ @Override
+ public void navigate(final Activity activity, final Geocache cache) {
+ final Intent intent = createIntent(cache.getCoords());
+ addIntentExtras(intent, cache);
+ activity.startActivity(intent);
+ }
+
+ @Override
+ public void navigate(final Activity activity, final Waypoint waypoint) {
+ final Intent intent = createIntent(waypoint.getCoords());
+ addIntentExtras(intent, waypoint);
+ activity.startActivity(intent);
+ }
+
+ protected abstract void addCoordinates(final Intent intent, final Geopoint point);
+}
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java b/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java
index 60d6e31..819638c 100644
--- a/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java
+++ b/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java
@@ -1,6 +1,8 @@
package cgeo.geocaching.apps.cache.navi;
+import cgeo.geocaching.Geocache;
import cgeo.geocaching.R;
+import cgeo.geocaching.Waypoint;
import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.utils.Log;
@@ -22,10 +24,15 @@ class GoogleMapsApp extends AbstractPointNavigationApp {
@Override
public void navigate(Activity activity, Geopoint point) {
- // INFO: q parameter works with Google Maps, but breaks cooperation with all other apps
+ navigate(activity, point, activity.getString(R.string.waypoint));
+ }
+
+ private static void navigate(Activity activity, Geopoint point, String label) {
try {
- activity.startActivity(new Intent(Intent.ACTION_VIEW,
- Uri.parse("geo:" + point.getLatitude() + "," + point.getLongitude())));
+ final String geoLocation = "geo:" + point.getLatitude() + "," + point.getLongitude();
+ final String query = point.getLatitude() + "," + point.getLongitude() + "(" + label + ")";
+ final String uriString = geoLocation + "?q=" + Uri.encode(query);
+ activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(uriString)));
return;
} catch (RuntimeException e) {
// nothing
@@ -35,4 +42,13 @@ class GoogleMapsApp extends AbstractPointNavigationApp {
ActivityMixin.showToast(activity, getString(R.string.err_application_no));
}
+ @Override
+ public void navigate(Activity activity, Geocache cache) {
+ navigate(activity, cache.getCoords(), cache.getName());
+ }
+
+ @Override
+ public void navigate(Activity activity, Waypoint waypoint) {
+ navigate(activity, waypoint.getCoords(), waypoint.getName());
+ }
}
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/PebbleApp.java b/main/src/cgeo/geocaching/apps/cache/navi/PebbleApp.java
index 8ba3bef..ac83085 100644
--- a/main/src/cgeo/geocaching/apps/cache/navi/PebbleApp.java
+++ b/main/src/cgeo/geocaching/apps/cache/navi/PebbleApp.java
@@ -1,17 +1,15 @@
package cgeo.geocaching.apps.cache.navi;
-import cgeo.geocaching.Geocache;
import cgeo.geocaching.R;
import cgeo.geocaching.geopoint.Geopoint;
-import android.app.Activity;
import android.content.Intent;
/**
* Application for communication with the Pebble watch.
- *
+ *
*/
-class PebbleApp extends AbstractPointNavigationApp {
+class PebbleApp extends AbstractRadarApp {
private static final String INTENT = "com.webmajstr.pebble_gc.NAVIGATE_TO";
private static final String PACKAGE_NAME = "com.webmajstr.pebble_gc";
@@ -21,24 +19,8 @@ class PebbleApp extends AbstractPointNavigationApp {
}
@Override
- public void navigate(Activity activity, Geopoint point) {
- final Intent pebbleIntent = new Intent(INTENT);
- pebbleIntent.putExtra("latitude", point.getLatitude());
- pebbleIntent.putExtra("longitude", point.getLongitude());
- activity.startActivity(pebbleIntent);
+ protected void addCoordinates(final Intent intent, final Geopoint coords) {
+ intent.putExtra("latitude", coords.getLatitude());
+ intent.putExtra("longitude", coords.getLongitude());
}
-
- @Override
- public void navigate(Activity activity, Geocache cache) {
- final Intent pebbleIntent = new Intent(INTENT);
- pebbleIntent.putExtra("latitude", cache.getCoords().getLatitude());
- pebbleIntent.putExtra("longitude", cache.getCoords().getLongitude());
- pebbleIntent.putExtra("difficulty", cache.getDifficulty());
- pebbleIntent.putExtra("terrain", cache.getTerrain());
- pebbleIntent.putExtra("name", cache.getName());
- pebbleIntent.putExtra("code", cache.getGeocode());
- pebbleIntent.putExtra("size", cache.getSize().getL10n());
- activity.startActivity(pebbleIntent);
- }
-
} \ No newline at end of file
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/RadarApp.java b/main/src/cgeo/geocaching/apps/cache/navi/RadarApp.java
index ffa6650..41cf2d8 100644
--- a/main/src/cgeo/geocaching/apps/cache/navi/RadarApp.java
+++ b/main/src/cgeo/geocaching/apps/cache/navi/RadarApp.java
@@ -3,10 +3,9 @@ package cgeo.geocaching.apps.cache.navi;
import cgeo.geocaching.R;
import cgeo.geocaching.geopoint.Geopoint;
-import android.app.Activity;
import android.content.Intent;
-class RadarApp extends AbstractPointNavigationApp {
+class RadarApp extends AbstractRadarApp {
private static final String INTENT = "com.google.android.radar.SHOW_RADAR";
private static final String PACKAGE_NAME = "com.eclipsim.gpsstatus2";
@@ -16,10 +15,9 @@ class RadarApp extends AbstractPointNavigationApp {
}
@Override
- public void navigate(Activity activity, Geopoint point) {
- final Intent radarIntent = new Intent(INTENT);
- radarIntent.putExtra("latitude", (float) point.getLatitude());
- radarIntent.putExtra("longitude", (float) point.getLongitude());
- activity.startActivity(radarIntent);
+ protected void addCoordinates(final Intent intent, final Geopoint coords) {
+ intent.putExtra("latitude", (float) coords.getLatitude());
+ intent.putExtra("longitude", (float) coords.getLongitude());
}
+
} \ No newline at end of file