aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/apps/cachelist/ListNavigationSelectionActionProvider.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/apps/cachelist/ListNavigationSelectionActionProvider.java')
-rw-r--r--main/src/cgeo/geocaching/apps/cachelist/ListNavigationSelectionActionProvider.java60
1 files changed, 60 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/apps/cachelist/ListNavigationSelectionActionProvider.java b/main/src/cgeo/geocaching/apps/cachelist/ListNavigationSelectionActionProvider.java
new file mode 100644
index 0000000..6a49995
--- /dev/null
+++ b/main/src/cgeo/geocaching/apps/cachelist/ListNavigationSelectionActionProvider.java
@@ -0,0 +1,60 @@
+package cgeo.geocaching.apps.cachelist;
+
+import cgeo.geocaching.ui.AbstractMenuActionProvider;
+
+import android.content.Context;
+import android.support.v4.view.ActionProvider;
+import android.support.v4.view.MenuItemCompat;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.MenuItem.OnMenuItemClickListener;
+import android.view.SubMenu;
+
+import java.util.List;
+
+public class ListNavigationSelectionActionProvider extends AbstractMenuActionProvider {
+
+ public static interface Callback {
+ void onListNavigationSelected(final CacheListApp app);
+ }
+
+ private Callback callback;
+
+ public ListNavigationSelectionActionProvider(final Context context) {
+ super(context);
+ }
+
+ public void setCallback(final Callback callback) {
+ this.callback = callback;
+ }
+
+ @Override
+ public void onPrepareSubMenu(final SubMenu subMenu) {
+ subMenu.clear();
+ if (callback == null) {
+ return;
+ }
+ final List<CacheListApp> activeApps = CacheListApps.getActiveApps();
+ for (int i = 0; i < activeApps.size(); i++) {
+ final CacheListApp app = activeApps.get(i);
+ subMenu.add(Menu.NONE, i, Menu.NONE, app.getName()).setOnMenuItemClickListener(new OnMenuItemClickListener() {
+
+ @Override
+ public boolean onMenuItemClick(final MenuItem item) {
+ final CacheListApp app = activeApps.get(item.getItemId());
+ callback.onListNavigationSelected(app);
+ return true;
+ }
+ });
+ }
+ }
+
+ public static void initialize(final MenuItem menuItem, final Callback callback) {
+ final ActionProvider actionProvider = MenuItemCompat.getActionProvider(menuItem);
+ if (actionProvider instanceof ListNavigationSelectionActionProvider) {
+ final ListNavigationSelectionActionProvider navigateAction = (ListNavigationSelectionActionProvider) actionProvider;
+ navigateAction.setCallback(callback);
+ }
+ }
+
+}