diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2012-01-08 10:51:10 +0100 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2012-01-08 10:51:10 +0100 |
| commit | cdd9939761c09dc0b00c825cfbab80aa198348f2 (patch) | |
| tree | c5edecedd56901860a274739e2a90418284fced2 /main/src/cgeo/geocaching/apps/cache/navi/AbstractPointNavigationApp.java | |
| parent | e9ddb7e7abd1406e77637c15831aa4f8b52ce772 (diff) | |
| download | cgeo-cdd9939761c09dc0b00c825cfbab80aa198348f2.zip cgeo-cdd9939761c09dc0b00c825cfbab80aa198348f2.tar.gz cgeo-cdd9939761c09dc0b00c825cfbab80aa198348f2.tar.bz2 | |
refactoring: cleanup for #945
* remove duplicated code
* remove all access to resources via method parameters
Diffstat (limited to 'main/src/cgeo/geocaching/apps/cache/navi/AbstractPointNavigationApp.java')
| -rw-r--r-- | main/src/cgeo/geocaching/apps/cache/navi/AbstractPointNavigationApp.java | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/AbstractPointNavigationApp.java b/main/src/cgeo/geocaching/apps/cache/navi/AbstractPointNavigationApp.java new file mode 100644 index 0000000..dc51a15 --- /dev/null +++ b/main/src/cgeo/geocaching/apps/cache/navi/AbstractPointNavigationApp.java @@ -0,0 +1,59 @@ +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; + +/** + * navigation app for simple point navigation (no differentiation between cache/waypoint/point) + * + * @author bananeweizen + * + */ +abstract class AbstractPointNavigationApp extends AbstractNavigationApp { + + protected AbstractPointNavigationApp(String name, String intent) { + super(name, intent); + } + + protected AbstractPointNavigationApp(String name, String intent, String packageName) { + super(name, intent, packageName); + } + + @Override + public final boolean invoke(cgGeo geo, Activity activity, cgCache cache, SearchResult search, cgWaypoint waypoint, Geopoint coords) { + if (cache == null && waypoint == null && coords == null) { + return false; + } + + try { + if (isInstalled(activity)) { + final Geopoint point = getCoordinates(cache, waypoint, coords); + if (point != null) { + navigate(activity, point); + return true; + } + } + } catch (Exception e) { + // nothing + } + + return false; + } + + protected abstract void navigate(Activity activity, Geopoint point); + + private static Geopoint getCoordinates(cgCache cache, cgWaypoint waypoint, Geopoint coords) { + if (cache != null && cache.getCoords() != null) { + return cache.getCoords(); + } + else if (waypoint != null && waypoint.getCoords() != null) { + return waypoint.getCoords(); + } + return coords; + } +}
\ No newline at end of file |
