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

import org.apache.commons.lang3.ArrayUtils;

import android.app.Activity;
import android.content.res.Resources;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgSettings;
import cgeo.geocaching.apps.AbstractAppFactory;

public final class GeneralAppsFactory extends AbstractAppFactory {
	private static GeneralApp[] apps = new GeneralApp[] {};

	private static GeneralApp[] getGeneralApps(Resources res) {
		if (ArrayUtils.isEmpty(apps)) {
			apps = new GeneralApp[] { new GccApp(res),
					new WhereYouGoApp(res) };
		}
		return apps;
	}

	public static void addMenuItems(Menu menu, Activity activity,
			Resources res, cgCache cache) {
		for (GeneralApp app : getGeneralApps(res)) {
			if (app.isInstalled(activity) && app.isEnabled(cache)) {
				menu.add(0, app.getId(), 0, app.getName());
			}
		}
	}

	public static boolean onMenuItemSelected(final MenuItem item,
			Activity activity, cgCache cache) {
		GeneralApp app = (GeneralApp) getAppFromMenuItem(item, apps);
		if (app != null) {
			try {
				return app.invoke(activity, cache);
			} catch (Exception e) {
				Log.e(cgSettings.tag, "GeneralAppsFactory.onMenuItemSelected: " + e.toString());
			}
		}
		return false;
	}

}