diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/project.properties | 1 | ||||
-rw-r--r-- | main/res/values/ids.xml | 3 | ||||
-rw-r--r-- | main/res/values/preference_keys.xml | 1 | ||||
-rw-r--r-- | main/res/values/strings.xml | 2 | ||||
-rw-r--r-- | main/res/xml/preferences.xml | 5 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/CacheDetailActivity.java | 7 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/apps/cache/navi/MapsWithMeApp.java | 43 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java | 3 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java | 3 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/apps/cachelist/MapsWithMeCacheListApp.java | 65 |
10 files changed, 130 insertions, 3 deletions
diff --git a/main/project.properties b/main/project.properties index 6d3329d..a761287 100644 --- a/main/project.properties +++ b/main/project.properties @@ -12,3 +12,4 @@ proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project. # Project target. target=Google Inc.:Google APIs:19 +android.library.reference.1=../mapswithme-api diff --git a/main/res/values/ids.xml b/main/res/values/ids.xml index 8539275..e8cb74b 100644 --- a/main/res/values/ids.xml +++ b/main/res/values/ids.xml @@ -24,5 +24,6 @@ <item name="cache_app_show_static_maps" type="id"/> <item name="cache_app_locus" type="id"/> <item name="cache_app_pebble" type="id"/> - + <item name="cache_app_mapswithme" type="id"/> + </resources>
\ No newline at end of file diff --git a/main/res/values/preference_keys.xml b/main/res/values/preference_keys.xml index 91b2c67..6036be3 100644 --- a/main/res/values/preference_keys.xml +++ b/main/res/values/preference_keys.xml @@ -137,6 +137,7 @@ <string name="pref_navigation_menu_gcc">navigationGcc</string> <string name="pref_navigation_menu_where_you_go">navigationWhereYouGo</string> <string name="pref_navigation_menu_pebble">navigationPebble</string> + <string name="pref_navigation_menu_mapswithme">navigationMapsWithMe</string> <string name="pref_ocpl_tokensecret">ocpl_tokensecret</string> <string name="pref_ocpl_tokenpublic">ocpl_tokenpublic</string> <string name="pref_temp_ocpl_token_secret">ocpl-temp-token-secret</string> diff --git a/main/res/values/strings.xml b/main/res/values/strings.xml index 62c3bbf..55d44b8 100644 --- a/main/res/values/strings.xml +++ b/main/res/values/strings.xml @@ -320,6 +320,7 @@ <string name="caches_move_all">Move all</string> <string name="caches_map_locus">Locus</string> <string name="caches_map_locus_export">Export to Locus</string> + <string name="caches_map_mapswithme">MapsWithMe</string> <string name="caches_recaptcha_title">reCAPTCHA</string> <string name="caches_recaptcha_explanation">Please enter the text you see in the image. This enables downloading of cache coordinates, which can be disabled in Settings.</string> <string name="caches_recaptcha_hint">Text from image</string> @@ -709,6 +710,7 @@ <string name="cache_menu_cachebeacon">Cache Beacon</string> <string name="cache_menu_navigon">Navigon</string> <string name="cache_menu_pebble">Pebble</string> + <string name="cache_menu_mapswithme">MapsWithMe</string> <string name="cache_status">Status</string> <string name="cache_status_offline_log">Saved Log</string> <string name="cache_status_found">Found</string> diff --git a/main/res/xml/preferences.xml b/main/res/xml/preferences.xml index fb17fb8..d550dc8 100644 --- a/main/res/xml/preferences.xml +++ b/main/res/xml/preferences.xml @@ -666,6 +666,11 @@ android:enabled="false" android:key="@string/pref_navigation_menu_pebble" android:title="@string/cache_menu_pebble" /> + <CheckBoxPreference + android:defaultValue="true" + android:enabled="false" + android:key="@string/pref_navigation_menu_mapswithme" + android:title="@string/cache_menu_mapswithme" /> </PreferenceScreen> </PreferenceCategory> </PreferenceScreen> 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); + } + +} |