aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java
blob: 6b05426d72294d9230600d6c4fa864958e808cd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package cgeo.geocaching.apps.cache.navi;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.util.Log;
import cgeo.geocaching.R;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgGeo;
import cgeo.geocaching.cgSettings;
import cgeo.geocaching.cgWaypoint;
import cgeo.geocaching.activity.ActivityMixin;

class GoogleMapsApp extends AbstractNavigationApp implements NavigationApp {

	GoogleMapsApp(final Resources res) {
		super(res.getString(R.string.cache_menu_map_ext), null);
	}

	@Override
	public boolean isInstalled(Context context) {
		return true;
	}

	public boolean invoke(cgGeo geo, Activity activity, Resources res,
			cgCache cache,
			Long searchId, cgWaypoint waypoint, Double latitude, Double longitude) {
		if (cache == null && waypoint == null && latitude == null && longitude == null) {
			return false;
		}

		try {
			if (cache != null && cache.latitude != null && cache.longitude != null) {
				activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("geo:" + cache.latitude + "," + cache.longitude)));
				// INFO: q parameter works with Google Maps, but breaks cooperation with all other apps
			} else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) {
				activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("geo:" + waypoint.latitude + "," + waypoint.longitude)));
				// INFO: q parameter works with Google Maps, but breaks cooperation with all other apps
			}

			return true;
		} catch (Exception e) {
			// nothing
		}

		Log.i(cgSettings.tag, "cgBase.runExternalMap: No maps application available.");

		if (res != null) {
			ActivityMixin.showToast(activity, res.getString(R.string.err_application_no));
		}

		return false;
	}

}