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/AbstractGeneralApp.java7
-rw-r--r--main/src/cgeo/geocaching/apps/cache/CacheBeaconApp.java5
-rw-r--r--main/src/cgeo/geocaching/apps/cache/GccApp.java4
-rw-r--r--main/src/cgeo/geocaching/apps/cache/GeneralApp.java12
-rw-r--r--main/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java48
-rw-r--r--main/src/cgeo/geocaching/apps/cache/WhereYouGoApp.java6
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/AbstractNavigationApp.java26
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/AbstractStaticMapsApp.java9
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsDirectionApp.java48
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java63
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/NavigationApp.java18
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java32
12 files changed, 105 insertions, 173 deletions
diff --git a/main/src/cgeo/geocaching/apps/cache/AbstractGeneralApp.java b/main/src/cgeo/geocaching/apps/cache/AbstractGeneralApp.java
index 61528ea..8087d6d 100644
--- a/main/src/cgeo/geocaching/apps/cache/AbstractGeneralApp.java
+++ b/main/src/cgeo/geocaching/apps/cache/AbstractGeneralApp.java
@@ -2,24 +2,23 @@ package cgeo.geocaching.apps.cache;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.apps.AbstractApp;
+import cgeo.geocaching.apps.cache.navi.CacheNavigationApp;
import android.app.Activity;
import android.content.Intent;
-abstract class AbstractGeneralApp extends AbstractApp implements GeneralApp {
+abstract class AbstractGeneralApp extends AbstractApp implements CacheNavigationApp {
protected AbstractGeneralApp(String name, String packageName) {
super(name, null, packageName);
}
@Override
- public boolean invoke(Activity activity, cgCache cache) {
+ public void navigate(Activity activity, cgCache cache) {
final Intent intent = getLaunchIntent();
if (intent != null) {
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
activity.startActivity(intent);
- return true;
}
- return false;
}
}
diff --git a/main/src/cgeo/geocaching/apps/cache/CacheBeaconApp.java b/main/src/cgeo/geocaching/apps/cache/CacheBeaconApp.java
index 6e7cdca..4ba336f 100644
--- a/main/src/cgeo/geocaching/apps/cache/CacheBeaconApp.java
+++ b/main/src/cgeo/geocaching/apps/cache/CacheBeaconApp.java
@@ -6,15 +6,12 @@ import cgeo.geocaching.enumerations.CacheAttribute;
public class CacheBeaconApp extends AbstractGeneralApp {
- protected CacheBeaconApp() {
+ public CacheBeaconApp() {
super(getString(R.string.cache_menu_cachebeacon), "de.fun2code.android.cachebeacon");
}
@Override
public boolean isEnabled(cgCache cache) {
- if (cache == null) {
- return false;
- }
return cache.hasAttribute(CacheAttribute.WIRELESS_BEACON, true);
}
diff --git a/main/src/cgeo/geocaching/apps/cache/GccApp.java b/main/src/cgeo/geocaching/apps/cache/GccApp.java
index 9000d9e..b129b45 100644
--- a/main/src/cgeo/geocaching/apps/cache/GccApp.java
+++ b/main/src/cgeo/geocaching/apps/cache/GccApp.java
@@ -2,8 +2,8 @@ package cgeo.geocaching.apps.cache;
import cgeo.geocaching.R;
-class GccApp extends AbstractGeneralApp {
- GccApp() {
+public class GccApp extends AbstractGeneralApp {
+ public GccApp() {
super(getString(R.string.cache_menu_gcc), "eisbehr.gcc");
}
}
diff --git a/main/src/cgeo/geocaching/apps/cache/GeneralApp.java b/main/src/cgeo/geocaching/apps/cache/GeneralApp.java
deleted file mode 100644
index cdbedd5..0000000
--- a/main/src/cgeo/geocaching/apps/cache/GeneralApp.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package cgeo.geocaching.apps.cache;
-
-import cgeo.geocaching.cgCache;
-import cgeo.geocaching.apps.App;
-
-import android.app.Activity;
-
-interface GeneralApp extends App {
-
- public boolean invoke(Activity activity, cgCache cache);
-
-}
diff --git a/main/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java b/main/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java
deleted file mode 100644
index 57eb957..0000000
--- a/main/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package cgeo.geocaching.apps.cache;
-
-import cgeo.geocaching.cgCache;
-import cgeo.geocaching.apps.AbstractAppFactory;
-import cgeo.geocaching.utils.Log;
-
-import org.apache.commons.lang3.ArrayUtils;
-
-import android.app.Activity;
-import android.view.Menu;
-import android.view.MenuItem;
-
-public final class GeneralAppsFactory extends AbstractAppFactory {
- private static GeneralApp[] apps = new GeneralApp[] {};
-
- private static GeneralApp[] getGeneralApps() {
- if (ArrayUtils.isEmpty(apps)) {
- apps = new GeneralApp[] {
- new CacheBeaconApp(),
- new GccApp(),
- new WhereYouGoApp()
- };
- }
- return apps;
- }
-
- public static void addMenuItems(Menu menu, cgCache cache) {
- for (GeneralApp app : getGeneralApps()) {
- if (app.isInstalled() && app.isEnabled(cache)) {
- menu.add(0, app.getId(), 0, app.getName());
- }
- }
- }
-
- public static boolean onMenuItemSelected(final MenuItem item, Activity activity, cgCache cache) {
- final GeneralApp app = (GeneralApp) getAppFromMenuItem(item, apps);
- if (app == null) {
- return false;
- }
- try {
- app.invoke(activity, cache);
- } catch (Exception e) {
- Log.e("GeneralAppsFactory.onMenuItemSelected: " + e.toString());
- }
- return true;
- }
-
-}
diff --git a/main/src/cgeo/geocaching/apps/cache/WhereYouGoApp.java b/main/src/cgeo/geocaching/apps/cache/WhereYouGoApp.java
index 8c16eaf..8c06d7a 100644
--- a/main/src/cgeo/geocaching/apps/cache/WhereYouGoApp.java
+++ b/main/src/cgeo/geocaching/apps/cache/WhereYouGoApp.java
@@ -4,13 +4,13 @@ import cgeo.geocaching.R;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.enumerations.CacheType;
-class WhereYouGoApp extends AbstractGeneralApp {
- WhereYouGoApp() {
+public class WhereYouGoApp extends AbstractGeneralApp {
+ public WhereYouGoApp() {
super(getString(R.string.cache_menu_whereyougo), "menion.android.whereyougo");
}
@Override
public boolean isEnabled(cgCache cache) {
- return cache != null && cache.getType() == CacheType.WHERIGO;
+ return cache.getType() == CacheType.WHERIGO;
}
}
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/AbstractNavigationApp.java b/main/src/cgeo/geocaching/apps/cache/navi/AbstractNavigationApp.java
deleted file mode 100644
index 27cb47c..0000000
--- a/main/src/cgeo/geocaching/apps/cache/navi/AbstractNavigationApp.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package cgeo.geocaching.apps.cache.navi;
-
-import cgeo.geocaching.cgWaypoint;
-import cgeo.geocaching.apps.AbstractApp;
-import cgeo.geocaching.geopoint.Geopoint;
-
-abstract class AbstractNavigationApp extends AbstractApp implements NavigationApp {
-
- protected AbstractNavigationApp(String name, String intent, String packageName) {
- super(name, intent, packageName);
- }
-
- protected AbstractNavigationApp(String name, String intent) {
- super(name, intent);
- }
-
- @Override
- public boolean isEnabled(cgWaypoint waypoint) {
- return waypoint != null;
- }
-
- @Override
- public boolean isEnabled(Geopoint geopoint) {
- return geopoint != null;
- }
-}
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/AbstractStaticMapsApp.java b/main/src/cgeo/geocaching/apps/cache/navi/AbstractStaticMapsApp.java
index f27b53c..85a4b93 100644
--- a/main/src/cgeo/geocaching/apps/cache/navi/AbstractStaticMapsApp.java
+++ b/main/src/cgeo/geocaching/apps/cache/navi/AbstractStaticMapsApp.java
@@ -5,8 +5,8 @@ import cgeo.geocaching.R;
import cgeo.geocaching.StaticMapsActivity;
import cgeo.geocaching.StaticMapsProvider;
import cgeo.geocaching.cgCache;
+import cgeo.geocaching.cgData;
import cgeo.geocaching.cgWaypoint;
-import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.apps.AbstractApp;
@@ -15,7 +15,7 @@ import org.apache.commons.lang3.StringUtils;
import android.app.Activity;
abstract class AbstractStaticMapsApp extends AbstractApp implements CacheNavigationApp, WaypointNavigationApp {
- public AbstractStaticMapsApp(String name) {
+ protected AbstractStaticMapsApp(String name) {
super(name, null);
}
@@ -30,11 +30,12 @@ abstract class AbstractStaticMapsApp extends AbstractApp implements CacheNavigat
}
protected static boolean hasStaticMap(cgWaypoint waypoint) {
- if (waypoint==null)
+ if (waypoint==null) {
return false;
+ }
String geocode = waypoint.getGeocode();
int id = waypoint.getId();
- if (StringUtils.isNotEmpty(geocode) && cgeoapplication.getInstance().isOffline(geocode, null)) {
+ if (StringUtils.isNotEmpty(geocode) && cgData.isOffline(geocode, null)) {
return StaticMapsProvider.hasStaticMapForWaypoint(geocode, id);
}
return false;
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..db4fc1c
--- /dev/null
+++ b/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsDirectionApp.java
@@ -0,0 +1,48 @@
+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.maps.MapProviderFactory;
+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 MapProviderFactory.isGoogleMapsInstalled();
+ }
+
+ @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..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
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/NavigationApp.java b/main/src/cgeo/geocaching/apps/cache/navi/NavigationApp.java
deleted file mode 100644
index 52d16cf..0000000
--- a/main/src/cgeo/geocaching/apps/cache/navi/NavigationApp.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package cgeo.geocaching.apps.cache.navi;
-
-import cgeo.geocaching.cgCache;
-import cgeo.geocaching.cgWaypoint;
-import cgeo.geocaching.apps.App;
-import cgeo.geocaching.geopoint.Geopoint;
-
-import android.app.Activity;
-
-public interface NavigationApp extends App {
- public boolean invoke(final Activity activity,
- final cgCache cache, final cgWaypoint waypoint,
- final Geopoint coords);
-
- boolean isEnabled(final cgWaypoint waypoint);
-
- boolean isEnabled(final Geopoint geopoint);
-}
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java
index 57a71bb..2f8ce16 100644
--- a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java
+++ b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java
@@ -8,6 +8,11 @@ import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.apps.AbstractAppFactory;
import cgeo.geocaching.apps.App;
+import cgeo.geocaching.apps.cache.CacheBeaconApp;
+import cgeo.geocaching.apps.cache.GccApp;
+import cgeo.geocaching.apps.cache.WhereYouGoApp;
+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 +45,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 +53,19 @@ 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),
+
+ CACHE_BEACON(new CacheBeaconApp(), 14),
+ GCC(new GccApp(), 15),
+ WHERE_YOU_GO(new WhereYouGoApp(), 16);
NavigationAppsEnum(App app, int id) {
this.app = app;
@@ -115,7 +132,6 @@ public final class NavigationAppFactory extends AbstractAppFactory {
final boolean showInternalMap, final boolean showDefaultNavigation) {
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(R.string.cache_menu_navigate);
- builder.setIcon(R.drawable.ic_menu_mapmode);
final List<NavigationAppsEnum> items = new ArrayList<NavigationAppFactory.NavigationAppsEnum>();
final int defaultNavigationTool = Settings.getDefaultNavigationTool();
for (NavigationAppsEnum navApp : getInstalledNavigationApps()) {
@@ -146,17 +162,15 @@ public final class NavigationAppFactory extends AbstractAppFactory {
@Override
public void onClick(DialogInterface dialog, int item) {
NavigationAppsEnum selectedItem = adapter.getItem(item);
+ App app = selectedItem.app;
if (cache != null) {
- CacheNavigationApp cacheApp = (CacheNavigationApp) selectedItem.app;
- cacheApp.navigate(activity, cache);
+ navigateCache(activity, cache, app);
}
else if (waypoint != null) {
- WaypointNavigationApp waypointApp = (WaypointNavigationApp) selectedItem.app;
- waypointApp.navigate(activity, waypoint);
+ navigateWaypoint(activity, waypoint, app);
}
else {
- GeopointNavigationApp geopointApp = (GeopointNavigationApp) selectedItem.app;
- geopointApp.navigate(activity, destination);
+ navigateGeopoint(activity, destination, app);
}
}
});