aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo/geocaching/apps/cache/navi/RadarApp.java
blob: 5bb1e6cf639674754e7250ac00a5e03e17445a9b (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
package cgeo.geocaching.apps.cache.navi;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import cgeo.geocaching.R;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgGeo;
import cgeo.geocaching.cgWarning;
import cgeo.geocaching.cgWaypoint;

class RadarApp extends AbstractNavigationApp implements NavigationApp {

	private static final String INTENT = "com.google.android.radar.SHOW_RADAR";
	private static final String PACKAGE_NAME = "com.eclipsim.gpsstatus2";

	RadarApp(final Resources res) {
		super(res.getString(R.string.cache_menu_radar), INTENT, PACKAGE_NAME);
	}

	@Override
	public boolean isInstalled(Context context) {
		return true; // seems like Radar is assumed to be available always
	}

	private static void navigateTo(Activity activity, Double latitude, Double longitude) {
		Intent radarIntent = new Intent(INTENT);
		radarIntent.putExtra("latitude", Float.valueOf(latitude.floatValue()));
		radarIntent.putExtra("longitude", Float.valueOf(longitude.floatValue()));
		activity.startActivity(radarIntent);
	}

	@Override
	public boolean invoke(cgGeo geo, Activity activity, Resources res,
			cgWarning warning, cgCache cache,
			Long searchId, cgWaypoint waypoint, Double latitude, Double longitude) {
		if (cache != null) {
			if (cache.latitude != null && cache.longitude != null) {
				navigateTo(activity, cache.latitude, cache.longitude);
				return true;
			}
		}
		if (waypoint != null) {
			if (waypoint.latitude != null && waypoint.longitude != null) {
				navigateTo(activity, waypoint.latitude, waypoint.longitude);
				return true;
			}
		}
		if (latitude != null && longitude != null) {
			navigateTo(activity, latitude, longitude);
			return true;
		}
		return false;
	}
}