diff options
| author | Michael Keppler <michael.keppler@gmx.de> | 2014-04-21 18:33:07 +0200 |
|---|---|---|
| committer | Michael Keppler <michael.keppler@gmx.de> | 2014-04-21 18:33:07 +0200 |
| commit | 7955c23b643ba127d002b07fac57790ca430ad88 (patch) | |
| tree | 4f61c7f0c81bf8d85cb44034f097ff9b7c63e44b /main/src/cgeo/geocaching | |
| parent | bcced1c4bfafcd0984f7c94abf53bc966359799e (diff) | |
| download | cgeo-7955c23b643ba127d002b07fac57790ca430ad88.zip cgeo-7955c23b643ba127d002b07fac57790ca430ad88.tar.gz cgeo-7955c23b643ba127d002b07fac57790ca430ad88.tar.bz2 | |
new: integrate mapswithme
Diffstat (limited to 'main/src/cgeo/geocaching')
5 files changed, 119 insertions, 2 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index b8f4703..e76a773 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -8,6 +8,7 @@ import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.activity.AbstractViewPagerActivity; import cgeo.geocaching.activity.Progress; import cgeo.geocaching.apps.cache.navi.NavigationAppFactory; +import cgeo.geocaching.apps.cachelist.MapsWithMeCacheListApp; import cgeo.geocaching.compatibility.Compatibility; import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.connector.IConnector; @@ -55,6 +56,7 @@ import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; + import rx.Observable; import rx.Observable.OnSubscribe; import rx.Observer; @@ -197,6 +199,11 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc guid = extras.getString(Intents.EXTRA_GUID); } + // integration with MapsWithMe + if (StringUtils.isEmpty(geocode)) { + geocode = MapsWithMeCacheListApp.getCacheFromMapsWithMe(this, getIntent()); + } + // try to get data from URI if (geocode == null && guid == null && uri != null) { final String uriHost = uri.getHost().toLowerCase(Locale.US); diff --git a/main/src/cgeo/geocaching/apps/cache/navi/MapsWithMeApp.java b/main/src/cgeo/geocaching/apps/cache/navi/MapsWithMeApp.java new file mode 100644 index 0000000..ea5aebb --- /dev/null +++ b/main/src/cgeo/geocaching/apps/cache/navi/MapsWithMeApp.java @@ -0,0 +1,43 @@ +package cgeo.geocaching.apps.cache.navi; + +import cgeo.geocaching.Geocache; +import cgeo.geocaching.R; +import cgeo.geocaching.Waypoint; +import cgeo.geocaching.geopoint.Geopoint; + +import com.mapswithme.maps.api.MapsWithMeApi; + +import android.app.Activity; + +public class MapsWithMeApp extends AbstractPointNavigationApp { + + protected MapsWithMeApp() { + super(getString(R.string.cache_menu_mapswithme), R.id.cache_app_mapswithme, null); + } + + @Override + public void navigate(Activity activity, Geopoint coords) { + navigate(activity, coords, getString(R.string.unknown)); + } + + @Override + public void navigate(Activity activity, Geocache cache) { + navigate(activity, cache.getCoords(), cache.getName()); + } + + private static void navigate(Activity activity, Geopoint coords, String label) { + MapsWithMeApi.showPointOnMap(activity, coords.getLatitude(), coords.getLongitude(), label); + } + + @Override + public void navigate(Activity activity, Waypoint waypoint) { + navigate(activity, waypoint.getCoords(), waypoint.getName()); + } + + @Override + public boolean isInstalled() { + // the library can handle the app not being installed + return true; + } + +} diff --git a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java index bf0e776..3177a29 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java @@ -72,7 +72,8 @@ public final class NavigationAppFactory extends AbstractAppFactory { CACHE_BEACON(new CacheBeaconApp(), 14, R.string.pref_navigation_menu_cache_beacon), GCC(new GccApp(), 15, R.string.pref_navigation_menu_gcc), WHERE_YOU_GO(new WhereYouGoApp(), 16, R.string.pref_navigation_menu_where_you_go), - PEBBLE(new PebbleApp(), 17, R.string.pref_navigation_menu_pebble); + PEBBLE(new PebbleApp(), 17, R.string.pref_navigation_menu_pebble), + MAPSWITHME(new MapsWithMeApp(), 22, R.string.pref_navigation_menu_mapswithme); NavigationAppsEnum(final App app, final int id, final int preferenceKey) { this.app = app; diff --git a/main/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java b/main/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java index 4df9d26..8212111 100644 --- a/main/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java +++ b/main/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java @@ -21,7 +21,8 @@ public final class CacheListAppFactory extends AbstractAppFactory { public static final CacheListApp[] apps = { new InternalCacheListMap(), new LocusShowCacheListApp(), - new LocusExportCacheListApp() + new LocusExportCacheListApp(), + new MapsWithMeCacheListApp() }; } diff --git a/main/src/cgeo/geocaching/apps/cachelist/MapsWithMeCacheListApp.java b/main/src/cgeo/geocaching/apps/cachelist/MapsWithMeCacheListApp.java new file mode 100644 index 0000000..e22d358 --- /dev/null +++ b/main/src/cgeo/geocaching/apps/cachelist/MapsWithMeCacheListApp.java @@ -0,0 +1,65 @@ +package cgeo.geocaching.apps.cachelist; + +import cgeo.geocaching.CacheDetailActivity; +import cgeo.geocaching.Geocache; +import cgeo.geocaching.R; +import cgeo.geocaching.SearchResult; +import cgeo.geocaching.apps.AbstractApp; + +import com.mapswithme.maps.api.MWMPoint; +import com.mapswithme.maps.api.MWMResponse; +import com.mapswithme.maps.api.MapsWithMeApi; + +import org.eclipse.jdt.annotation.Nullable; + +import android.app.Activity; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; + +import java.util.List; + +public class MapsWithMeCacheListApp extends AbstractApp implements CacheListApp { + + protected MapsWithMeCacheListApp() { + super(getString(R.string.caches_map_mapswithme), R.id.cache_app_mapswithme, Intent.ACTION_VIEW); + } + + @Override + public boolean invoke(List<Geocache> caches, Activity activity, SearchResult search) { + final MWMPoint[] points = new MWMPoint[caches.size()]; + for (int i = 0; i < points.length; i++) { + Geocache geocache = caches.get(i); + points[i] = new MWMPoint(geocache.getCoords().getLatitude(), geocache.getCoords().getLongitude(), geocache.getName(), geocache.getGeocode()); + } + MapsWithMeApi.showPointsOnMap(activity, null, getPendingIntent(activity), points); + return true; + } + + @Override + public boolean isInstalled() { + // API can handle installing on the fly + return true; + } + + /** + * get cache code from an invocation of MapsWithMe + * + * @return + */ + @Nullable + public static String getCacheFromMapsWithMe(final Context context, final Intent intent) { + final MWMResponse mwmResponse = MWMResponse.extractFromIntent(context, intent); + if (mwmResponse != null) { + final MWMPoint point = mwmResponse.getPoint(); + return point.getId(); + } + return null; + } + + private static PendingIntent getPendingIntent(Context context) { + final Intent intent = new Intent(context, CacheDetailActivity.class); + return PendingIntent.getActivity(context, 0, intent, 0); + } + +} |
