diff options
author | Torsten Keil <github@torsten-keil.net> | 2012-02-03 00:47:51 +0100 |
---|---|---|
committer | Torsten Keil <github@torsten-keil.net> | 2012-02-03 00:47:51 +0100 |
commit | 4711a02fa036fd23c604937ac4a60a7be48c2d4b (patch) | |
tree | cb5000bef860cf5bc3a8175d698a8f4de759f002 /main/src | |
parent | 7fba2c26fd9203eb9cde0997bca231b63f11c2c4 (diff) | |
download | cgeo-4711a02fa036fd23c604937ac4a60a7be48c2d4b.zip cgeo-4711a02fa036fd23c604937ac4a60a7be48c2d4b.tar.gz cgeo-4711a02fa036fd23c604937ac4a60a7be48c2d4b.tar.bz2 |
Refactoring navigation apps submenus to use AlertDialog.Builder where
possible.
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/cgeo/geocaching/CacheDetailActivity.java | 18 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java | 183 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeocaches.java | 16 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeoinit.java | 2 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeopoint.java | 21 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeopopup.java | 16 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeowaypoint.java | 24 |
7 files changed, 207 insertions, 73 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index 2740b05..37970b9 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -388,8 +388,7 @@ public class CacheDetailActivity extends AbstractActivity { } if (waypoint.getCoords() != null) { menu.add(CONTEXT_MENU_WAYPOINT_DEFAULT_NAVIGATION, index, 0, NavigationAppFactory.getDefaultNavigationApplication(this).getName()); - SubMenu subMenu = menu.addSubMenu(CONTEXT_MENU_WAYPOINT_NAVIGATE, index, 0, R.string.cache_menu_navigate).setIcon(android.R.drawable.ic_menu_mapmode); - NavigationAppFactory.addMenuItems(subMenu, this); + menu.add(CONTEXT_MENU_WAYPOINT_NAVIGATE, index, 0, R.string.cache_menu_navigate).setIcon(android.R.drawable.ic_menu_mapmode); menu.add(CONTEXT_MENU_WAYPOINT_CACHES_AROUND, index, 0, R.string.cache_menu_around); } break; @@ -454,7 +453,12 @@ public class CacheDetailActivity extends AbstractActivity { } break; case CONTEXT_MENU_WAYPOINT_NAVIGATE: - // No processing necessary, sub-menu gets displayed; + { + final cgWaypoint waypoint = cache.getWaypoint(contextMenuWPIndex); + if (waypoint != null) { + NavigationAppFactory.showNavigationMenu(geolocation, this, null, null, waypoint, null); + } + } break; case CONTEXT_MENU_WAYPOINT_CACHES_AROUND: { @@ -465,12 +469,6 @@ public class CacheDetailActivity extends AbstractActivity { } break; default: - // First check the navigation menu, then the option items - final cgWaypoint waypoint = cache.getWaypoint(contextMenuWPIndex); - if (waypoint != null && NavigationAppFactory.onMenuItemSelected(item, geolocation, this, - null, null, waypoint, null)) { - return true; - } return onOptionsItemSelected(item); } return false; @@ -951,7 +949,7 @@ public class CacheDetailActivity extends AbstractActivity { } private void showNavigationMenu() { - NavigationAppFactory.showNavigationMenu(geolocation, this, cache, search); + NavigationAppFactory.showNavigationMenu(geolocation, this, cache, search, null, null); } /** diff --git a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java index 13a81ff..6053948 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java @@ -6,6 +6,7 @@ import cgeo.geocaching.Settings; import cgeo.geocaching.cgCache; import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgWaypoint; +import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.apps.AbstractAppFactory; import cgeo.geocaching.geopoint.Geopoint; @@ -15,6 +16,10 @@ import android.content.DialogInterface; import android.util.Log; import android.view.Menu; import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; import java.util.ArrayList; import java.util.List; @@ -22,16 +27,27 @@ import java.util.List; public final class NavigationAppFactory extends AbstractAppFactory { public enum NavigationAppsEnum { + /** The internal compass activity */ COMPASS(new CompassApp(), 0), + /** The external radar app */ RADAR(new RadarApp(), 1), + /** The selected map */ INTERNAL_MAP(new InternalMap(), 2), + /** The internal static map activity */ STATIC_MAP(new StaticMapApp(), 3), + /** The external Locus app */ LOCUS(new LocusApp(), 4), + /** The external RMaps app */ RMAPS(new RMapsApp(), 5), + /** Google Maps */ GOOGLE_MAPS(new GoogleMapsApp(), 6), + /** Google Navigation */ GOOGLE_NAVIGATION(new GoogleNavigationApp(), 7), + /** Google Streetview */ GOOGLE_STREETVIEW(new StreetviewApp(), 8), + /** The external OruxMaps app */ ORUX_MAPS(new OruxMapsApp(), 9), + /** The external navigon app */ NAVIGON(new NavigonApp(), 10); NavigationAppsEnum(NavigationApp app, int id) { @@ -49,35 +65,88 @@ public final class NavigationAppFactory extends AbstractAppFactory { public final int id; } - private static final int MENU_ITEM_OFFSET = 12345; - - public static void addMenuItems(final Menu menu, final Activity activity) { - addMenuItems(menu, activity, true, false); + /** + * Default way to handle selection of navigation tool.<br /> + * A dialog is created for tool selection and the selected tool is started afterwards. + * <p /> + * Delegates to + * {@link #showNavigationMenu(cgGeo, Activity, cgCache, SearchResult, cgWaypoint, Geopoint, boolean, boolean)} with + * <code>showInternalMap = true</code> and <code>showDefaultNavigation = false</code> + * + * @param geo + * @param activity + * @param cache + * @param search + * @param waypoint + * @param destination + */ + public static void showNavigationMenu(final cgGeo geo, final Activity activity, + final cgCache cache, final SearchResult search, final cgWaypoint waypoint, final Geopoint destination) { + showNavigationMenu(geo, activity, cache, search, waypoint, destination, true, false); } - public static void addMenuItems(final Menu menu, final Activity activity, + /** + * Specialized way to handle selection of navigation tool.<br /> + * A dialog is created for tool selection and the selected tool is started afterwards. + * + * @param geo + * @param activity + * @param cache + * may be <code>null</code> + * @param search + * may be <code>null</code> + * @param waypoint + * may be <code>null</code> + * @param destination + * may be <code>null</code> + * @param showInternalMap + * should be <code>false</code> only when called from within the internal map + * @param showDefaultNavigation + * should be <code>false</code> by default + * + * @see #showNavigationMenu(cgGeo, Activity, cgCache, SearchResult, cgWaypoint, Geopoint) + */ + public static void showNavigationMenu(final cgGeo geo, final Activity activity, + final cgCache cache, final SearchResult search, final cgWaypoint waypoint, final Geopoint destination, final boolean showInternalMap, final boolean showDefaultNavigation) { + final AlertDialog.Builder builder = new AlertDialog.Builder(activity); + builder.setTitle(R.string.cache_menu_navigate); + builder.setIcon(android.R.drawable.ic_menu_mapmode); + final List<NavigationAppsEnum> items = new ArrayList<NavigationAppFactory.NavigationAppsEnum>(); final int defaultNavigationTool = Settings.getDefaultNavigationTool(); + final boolean isOffline = cache != null ? cgeoapplication.getInstance().isOffline(cache.getGeocode(), null) : false; for (NavigationAppsEnum navApp : getInstalledNavigationApps(activity)) { if ((showInternalMap || !(navApp.app instanceof InternalMap)) && - (showDefaultNavigation || defaultNavigationTool != navApp.id)) { - menu.add(0, MENU_ITEM_OFFSET + navApp.id, 0, navApp.app.getName()); + (showDefaultNavigation || defaultNavigationTool != navApp.id) && + (isOffline && NavigationAppsEnum.STATIC_MAP.id == navApp.id)) { + items.add(navApp); } } - } + /* + * Using an ArrayAdapter with list of NavigationAppsEnum items avoids + * handling between mapping list positions allows us to do dynamic filtering of the list based on usecase. + */ + final ArrayAdapter<NavigationAppsEnum> adapter = new ArrayAdapter<NavigationAppsEnum>(activity, android.R.layout.select_dialog_item, items) { + @Override + public View getView(int position, View convertView, ViewGroup parent) { + TextView textView = (TextView) super.getView(position, convertView, parent); + textView.setText(getItem(position).app.getName()); + return textView; + } - public static void showNavigationMenu(final cgGeo geo, final Activity activity, final cgCache cache, final SearchResult search) { - final AlertDialog.Builder builder = new AlertDialog.Builder(activity); - builder.setTitle(R.string.cache_menu_navigate); - builder.setIcon(android.R.drawable.ic_menu_mapmode); - final List<NavigationAppsEnum> installed = getInstalledNavigationApps(activity); - final String[] items = new String[installed.size()]; - for (int i = 0; i < installed.size(); i++) { - items[i] = installed.get(i).app.getName(); - } - builder.setItems(items, new DialogInterface.OnClickListener() { + @Override + public View getDropDownView(int position, View convertView, ViewGroup parent) { + TextView textView = (TextView) super.getDropDownView(position, convertView, parent); + textView.setText(getItem(position).app.getName()); + return textView; + } + }; + adapter.setDropDownViewResource(android.R.layout.select_dialog_item); + + builder.setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { - installed.get(item).app.invoke(geo, activity, cache, search, null, null); + NavigationAppsEnum selectedItem = adapter.getItem(item); + selectedItem.app.invoke(geo, activity, cache, search, waypoint, destination); } }); final AlertDialog alert = builder.create(); @@ -85,6 +154,12 @@ public final class NavigationAppFactory extends AbstractAppFactory { } + /** + * Returns all installed navigation apps. + * + * @param activity + * @return + */ public static List<NavigationAppsEnum> getInstalledNavigationApps(final Activity activity) { final List<NavigationAppsEnum> installedNavigationApps = new ArrayList<NavigationAppsEnum>(); for (NavigationAppsEnum appEnum : NavigationAppsEnum.values()) { @@ -95,6 +170,64 @@ public final class NavigationAppFactory extends AbstractAppFactory { return installedNavigationApps; } + /** + * This offset is used to build unique menu ids to avoid collisions of ids in menus + */ + private static final int MENU_ITEM_OFFSET = 12345; + + /** + * Adds the installed navigation tools to the given menu. + * Use {@link #onMenuItemSelected(MenuItem, cgGeo, Activity, cgCache, SearchResult, cgWaypoint, Geopoint)} on + * selection event to start the selected navigation tool. + * + * <b>Only use this way if {@link #showNavigationMenu(cgGeo, Activity, cgCache, SearchResult, cgWaypoint, Geopoint)} + * is not suitable for the given usecase.</b> + * + * @param menu + * @param activity + */ + public static void addMenuItems(final Menu menu, final Activity activity) { + addMenuItems(menu, activity, true, false); + } + + /** + * Adds the installed navigation tools to the given menu. + * Use {@link #onMenuItemSelected(MenuItem, cgGeo, Activity, cgCache, SearchResult, cgWaypoint, Geopoint)} on + * selection event to start the selected navigation tool. + * + * <b>Only use this way if + * {@link #showNavigationMenu(cgGeo, Activity, cgCache, SearchResult, cgWaypoint, Geopoint, boolean, boolean)} is + * not suitable for the given usecase.</b> + * + * @param menu + * @param activity + * @param showInternalMap + * @param showDefaultNavigation + */ + public static void addMenuItems(final Menu menu, final Activity activity, + final boolean showInternalMap, final boolean showDefaultNavigation) { + final int defaultNavigationTool = Settings.getDefaultNavigationTool(); + for (NavigationAppsEnum navApp : getInstalledNavigationApps(activity)) { + if ((showInternalMap || !(navApp.app instanceof InternalMap)) && + (showDefaultNavigation || defaultNavigationTool != navApp.id)) { + menu.add(0, MENU_ITEM_OFFSET + navApp.id, 0, navApp.app.getName()); + } + } + } + + /** + * Handles menu selections for menu entries created with {@link #addMenuItems(Menu, Activity)} or + * {@link #addMenuItems(Menu, Activity, boolean, boolean)}. + * + * @param item + * @param geo + * @param activity + * @param cache + * @param search + * @param waypoint + * @param destination + * @return + */ public static boolean onMenuItemSelected(final MenuItem item, final cgGeo geo, Activity activity, cgCache cache, final SearchResult search, cgWaypoint waypoint, final Geopoint destination) { @@ -114,7 +247,7 @@ public final class NavigationAppFactory extends AbstractAppFactory { return false; } - public static NavigationApp getAppFromMenuItem(MenuItem item) { + private static NavigationApp getAppFromMenuItem(MenuItem item) { final int id = item.getItemId(); for (NavigationAppsEnum navApp : NavigationAppsEnum.values()) { if (MENU_ITEM_OFFSET + navApp.id == id) { @@ -124,6 +257,16 @@ public final class NavigationAppFactory extends AbstractAppFactory { return null; } + /** + * Starts the default navigation tool if correctly set and installed or the compass app as default fallback. + * + * @param geo + * @param activity + * @param cache + * @param search + * @param waypoint + * @param destination + */ public static void startDefaultNavigationApplication(final cgGeo geo, Activity activity, cgCache cache, final SearchResult search, cgWaypoint waypoint, final Geopoint destination) { final NavigationApp app = getDefaultNavigationApplication(activity); diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java index dcf1585..b2e5489 100644 --- a/main/src/cgeo/geocaching/cgeocaches.java +++ b/main/src/cgeo/geocaching/cgeocaches.java @@ -130,6 +130,7 @@ public class cgeocaches extends AbstractListActivity { private static final int MENU_DEFAULT_NAVIGATION = 66; private static final int SUBMENU_FILTER_ATTRIBUTES = 67; private static final int SUBMENU_FILTER_STATE = 68; + private static final int MENU_NAVIGATION = 69; private String action = null; private CacheListType type = null; @@ -1138,8 +1139,7 @@ public class cgeocaches extends AbstractListActivity { if (cache.getCoords() != null) { menu.add(0, MENU_DEFAULT_NAVIGATION, 0, NavigationAppFactory.getDefaultNavigationApplication(this).getName()); - final SubMenu subMenu = menu.addSubMenu(1, 0, 0, res.getString(R.string.cache_menu_navigate)).setIcon(android.R.drawable.ic_menu_mapmode); - NavigationAppFactory.addMenuItems(subMenu, this); + menu.add(1, MENU_NAVIGATION, 0, res.getString(R.string.cache_menu_navigate)).setIcon(android.R.drawable.ic_menu_mapmode); addVisitMenu(menu, cache); menu.add(0, MENU_CACHE_DETAILS, 0, res.getString(R.string.cache_menu_details)); } @@ -1207,6 +1207,12 @@ public class cgeocaches extends AbstractListActivity { final SearchResult singleSearch = cgBase.searchByGeocode(cache.getGeocode(), null, 0, false, null); NavigationAppFactory.startDefaultNavigationApplication(geo, this, cache, singleSearch, null, null); return true; + } else if (id == MENU_NAVIGATION) { + // create a search for a single cache (as if in details view) + final cgCache cache = getCacheFromAdapter(adapterInfo); + final SearchResult singleSearch = cgBase.searchByGeocode(cache.getGeocode(), null, 0, false, null); + NavigationAppFactory.showNavigationMenu(geo, this, cache, singleSearch, null, null); + return true; } else if (id == MENU_LOG_VISIT) { return getCacheFromAdapter(adapterInfo).logVisit(this); } else if (id == MENU_CACHE_DETAILS) { @@ -1255,12 +1261,6 @@ public class cgeocaches extends AbstractListActivity { if (adapterInfo != null) { // create a search for a single cache (as if in details view) final cgCache cache = getCacheFromAdapter(adapterInfo); - final SearchResult singleSearch = cgBase.searchByGeocode(cache.getGeocode(), null, 0, false, null); - - if (NavigationAppFactory.onMenuItemSelected(item, geo, this, - cache, singleSearch, null, null)) { - return true; - } int logType = id - MENU_LOG_VISIT_OFFLINE; cache.logOffline(this, LogType.getById(logType)); diff --git a/main/src/cgeo/geocaching/cgeoinit.java b/main/src/cgeo/geocaching/cgeoinit.java index 58db9bd..be315ce 100644 --- a/main/src/cgeo/geocaching/cgeoinit.java +++ b/main/src/cgeo/geocaching/cgeoinit.java @@ -589,7 +589,7 @@ public class cgeoinit extends AbstractActivity { // Default navigation tool settings Spinner defaultNavigationToolSelector = (Spinner) findViewById(R.id.default_navigation_tool); final List<NavigationAppsEnum> apps = NavigationAppFactory.getInstalledNavigationApps(this); - ArrayAdapter<NavigationAppsEnum> naviAdapter = new ArrayAdapter<NavigationAppsEnum>(this, android.R.layout.simple_spinner_item, apps.toArray(new NavigationAppsEnum[apps.size()])) { + ArrayAdapter<NavigationAppsEnum> naviAdapter = new ArrayAdapter<NavigationAppsEnum>(this, android.R.layout.simple_spinner_item, apps) { @Override public View getView(int position, View convertView, ViewGroup parent) { TextView textView = (TextView) super.getView(position, convertView, parent); diff --git a/main/src/cgeo/geocaching/cgeopoint.java b/main/src/cgeo/geocaching/cgeopoint.java index 5d109c4..a976b20 100644 --- a/main/src/cgeo/geocaching/cgeopoint.java +++ b/main/src/cgeo/geocaching/cgeopoint.java @@ -19,7 +19,6 @@ import android.view.ContextMenu.ContextMenuInfo; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; -import android.view.SubMenu; import android.view.View; import android.view.View.OnCreateContextMenuListener; import android.view.ViewGroup; @@ -144,9 +143,7 @@ public class cgeopoint extends AbstractActivity { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { - final SubMenu subMenu = menu.addSubMenu(Menu.NONE, CONTEXT_MENU_NAVIGATE, Menu.NONE, res.getString(R.string.cache_menu_navigate)); - NavigationAppFactory.addMenuItems(subMenu, cgeopoint.this); - + menu.add(Menu.NONE, CONTEXT_MENU_NAVIGATE, Menu.NONE, res.getString(R.string.cache_menu_navigate)); menu.add(Menu.NONE, CONTEXT_MENU_EDIT_WAYPOINT, Menu.NONE, R.string.waypoint_edit); menu.add(Menu.NONE, CONTEXT_MENU_DELETE_WAYPOINT, Menu.NONE, R.string.waypoint_delete); } @@ -162,6 +159,10 @@ public class cgeopoint extends AbstractActivity { switch (item.getItemId()) { case CONTEXT_MENU_NAVIGATE: contextMenuItemPosition = position; + if (destination instanceof cgDestination) { + NavigationAppFactory.showNavigationMenu(geo, this, null, null, null, ((cgDestination) destination).getCoords()); + return true; + } break; case CONTEXT_MENU_DELETE_WAYPOINT: @@ -177,11 +178,7 @@ public class cgeopoint extends AbstractActivity { lonButton.setText(gp.format(GeopointFormatter.Format.LON_DECMINUTE)); } return true; - default: - if (destination instanceof cgDestination) { - return NavigationAppFactory.onMenuItemSelected(item, geo, this, null, null, null, ((cgDestination) destination).getCoords()); - } } return super.onContextItemSelected(item); @@ -303,8 +300,7 @@ public class cgeopoint extends AbstractActivity { public boolean onCreateOptionsMenu(Menu menu) { menu.add(0, MENU_DEFAULT_NAVIGATION, 0, NavigationAppFactory.getDefaultNavigationApplication(this).getName()).setIcon(android.R.drawable.ic_menu_compass); // default navigation tool - SubMenu subMenu = menu.addSubMenu(1, MENU_NAVIGATE, 0, res.getString(R.string.cache_menu_navigate)).setIcon(android.R.drawable.ic_menu_more); - NavigationAppFactory.addMenuItems(subMenu, this); + menu.add(0, MENU_NAVIGATE, 0, res.getString(R.string.cache_menu_navigate)).setIcon(android.R.drawable.ic_menu_more); menu.add(0, MENU_CACHES_AROUND, 0, res.getString(R.string.cache_menu_around)).setIcon(android.R.drawable.ic_menu_rotate); // caches around @@ -362,8 +358,11 @@ public class cgeopoint extends AbstractActivity { clearHistory(); return true; + case MENU_NAVIGATE: + NavigationAppFactory.showNavigationMenu(geo, this, null, null, null, coords); + return true; default: - return NavigationAppFactory.onMenuItemSelected(item, geo, this, null, null, null, coords); + return false; } } diff --git a/main/src/cgeo/geocaching/cgeopopup.java b/main/src/cgeo/geocaching/cgeopopup.java index b089dde..1210efc 100644 --- a/main/src/cgeo/geocaching/cgeopopup.java +++ b/main/src/cgeo/geocaching/cgeopopup.java @@ -22,7 +22,6 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; -import android.view.SubMenu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; @@ -134,9 +133,7 @@ public class cgeopopup extends AbstractActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { menu.add(0, 2, 0, NavigationAppFactory.getDefaultNavigationApplication(this).getName()).setIcon(android.R.drawable.ic_menu_compass); // default navigation tool - - SubMenu subMenu = menu.addSubMenu(1, 0, 0, res.getString(R.string.cache_menu_navigate)).setIcon(android.R.drawable.ic_menu_mapmode); - NavigationAppFactory.addMenuItems(subMenu, this); + menu.add(0, 3, 0, res.getString(R.string.cache_menu_navigate)).setIcon(android.R.drawable.ic_menu_mapmode); addVisitMenu(menu, cache); menu.add(0, 5, 0, res.getString(R.string.cache_menu_around)).setIcon(android.R.drawable.ic_menu_rotate); // caches around menu.add(0, 7, 0, res.getString(R.string.cache_menu_browser)).setIcon(android.R.drawable.ic_menu_info_details); // browser @@ -150,12 +147,12 @@ public class cgeopopup extends AbstractActivity { try { if (cache != null && cache.getCoords() != null) { - menu.findItem(0).setVisible(true); menu.findItem(2).setVisible(true); + menu.findItem(3).setVisible(true); menu.findItem(5).setVisible(true); } else { - menu.findItem(0).setVisible(false); menu.findItem(2).setVisible(false); + menu.findItem(3).setVisible(false); menu.findItem(5).setVisible(false); } @@ -175,6 +172,9 @@ public class cgeopopup extends AbstractActivity { if (menuItem == 2) { navigateTo(); return true; + } else if (menuItem == 3) { + NavigationAppFactory.showNavigationMenu(geo, this, cache, null, null, null); + return true; } else if (menuItem == 5) { cachesAround(); return true; @@ -187,10 +187,6 @@ public class cgeopopup extends AbstractActivity { return true; } - if (NavigationAppFactory.onMenuItemSelected(item, geo, this, cache, null, null, null)) { - return true; - } - int logType = menuItem - MENU_LOG_VISIT_OFFLINE; cache.logOffline(this, LogType.getById(logType)); return true; diff --git a/main/src/cgeo/geocaching/cgeowaypoint.java b/main/src/cgeo/geocaching/cgeowaypoint.java index a96e1ab..a46a969 100644 --- a/main/src/cgeo/geocaching/cgeowaypoint.java +++ b/main/src/cgeo/geocaching/cgeowaypoint.java @@ -16,7 +16,6 @@ import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.Menu; import android.view.MenuItem; -import android.view.SubMenu; import android.view.View; import android.widget.Button; import android.widget.ImageView; @@ -210,20 +209,13 @@ public class cgeowaypoint extends AbstractActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { menu.add(0, MENU_ID_DEFAULT_NAVIGATION, 0, NavigationAppFactory.getDefaultNavigationApplication(this).getName()).setIcon(android.R.drawable.ic_menu_compass); // default navigation tool - - SubMenu subMenu = menu.addSubMenu(1, MENU_ID_NAVIGATION, 0, res.getString(R.string.cache_menu_navigate)).setIcon(android.R.drawable.ic_menu_mapmode); - addNavigationMenuItems(subMenu); - + menu.add(0, MENU_ID_NAVIGATION, 0, res.getString(R.string.cache_menu_navigate)).setIcon(android.R.drawable.ic_menu_mapmode); menu.add(0, MENU_ID_CACHES_AROUND, 0, res.getString(R.string.cache_menu_around)).setIcon(android.R.drawable.ic_menu_rotate); // caches around menu.add(0, MENU_ID_OPEN_GEOCACHE, 0, res.getString(R.string.waypoint_menu_open_cache)).setIcon(android.R.drawable.ic_menu_mylocation); // open geocache return true; } - private void addNavigationMenuItems(Menu menu) { - NavigationAppFactory.addMenuItems(menu, this); - } - @Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); @@ -255,9 +247,11 @@ public class cgeowaypoint extends AbstractActivity { } else if (menuItem == MENU_ID_OPEN_GEOCACHE) { goToGeocache(); return true; + } else if (menuItem == MENU_ID_NAVIGATION) { + NavigationAppFactory.showNavigationMenu(geo, this, null, null, waypoint, null); + return true; } - - return NavigationAppFactory.onMenuItemSelected(item, geo, this, null, null, waypoint, null); + return false; } private void cachesAround() { @@ -351,12 +345,16 @@ public class cgeowaypoint extends AbstractActivity { ContextMenuInfo menuInfo) { if (navigationPossible()) { menu.setHeaderTitle(res.getString(R.string.cache_menu_navigate)); - addNavigationMenuItems(menu); + NavigationAppFactory.addMenuItems(menu, this); } } @Override public boolean onContextItemSelected(MenuItem item) { - return onOptionsItemSelected(item); + boolean handled = onOptionsItemSelected(item); + if (handled) { + return true; + } + return NavigationAppFactory.onMenuItemSelected(item, geo, this, null, null, waypoint, null); } } |