aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java
blob: 47ec473b3111a81f37c71b84dc6069c4b0d3595e (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 java.util.ArrayList;

import android.app.Activity;
import android.content.res.Resources;
import android.view.Menu;
import android.view.MenuItem;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgGeo;
import cgeo.geocaching.cgWarning;
import cgeo.geocaching.cgWaypoint;
import cgeo.geocaching.apps.AbstractAppFactory;

public final class NavigationAppFactory extends AbstractAppFactory {
	private static NavigationApp[] apps = new NavigationApp[] {};

	private static NavigationApp[] getNavigationApps(Resources res) {
		if (null == apps || 0 == apps.length) {
			apps = new NavigationApp[] {
					// compass
					new RadarApp(res), new StaticMapApp(res),
					new InternalMap(res), new LocusApp(res),
					new RMapsApp(res), new GoogleMapsApp(res),
					new GoogleNavigationApp(res) };
		}
		return apps;
	}

	public static void addMenuItems(Menu menu, Activity activity,
			Resources res) {
		for (NavigationApp app : getNavigationApps(res)) {
			if (app.isInstalled(activity)) {
				menu.add(0, app.getId(), 0, app.getName());
			}
		}
	}

	public static boolean onMenuItemSelected(final MenuItem item,
			final cgGeo geo, Activity activity, Resources res,
			cgWarning warning, cgCache cache,
			Long searchId, cgWaypoint waypoint, ArrayList<Double> destination) {
		NavigationApp app = (NavigationApp) getAppFromMenuItem(item, apps);
		if (app != null) {
			Double latitude = null;
			Double longitude = null;
			if (destination != null && destination.size() >= 2) {
				latitude = destination.get(0);
				longitude = destination.get(1);
			}
			return app.invoke(geo, activity, res, warning, cache,
					searchId, waypoint, latitude, longitude);
		}
		return false;
	}

}