aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/res/values-de/strings.xml1
-rw-r--r--main/res/values/strings.xml1
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java18
-rw-r--r--main/src/cgeo/geocaching/StaticMapsProvider.java33
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java205
-rw-r--r--main/src/cgeo/geocaching/cgeocaches.java16
-rw-r--r--main/src/cgeo/geocaching/cgeoinit.java2
-rw-r--r--main/src/cgeo/geocaching/cgeopoint.java21
-rw-r--r--main/src/cgeo/geocaching/cgeopopup.java16
-rw-r--r--main/src/cgeo/geocaching/cgeowaypoint.java24
-rw-r--r--main/src/cgeo/geocaching/files/FileList.java35
11 files changed, 291 insertions, 81 deletions
diff --git a/main/res/values-de/strings.xml b/main/res/values-de/strings.xml
index a00d575..aef3f50 100644
--- a/main/res/values-de/strings.xml
+++ b/main/res/values-de/strings.xml
@@ -566,6 +566,7 @@
<!-- file list base -->
<string name="file_searching_in">Suche nach Dateien\nin</string>
+ <string name="file_searching_sdcard_in">Keine Dateien in Standardverzeichnissen gefunden:\n%1$s\n\nDurchsuche komplette SD-Karte:\n</string>
<string name="file_list_no_files">c:geo hat keine passenden Dateien gefunden.</string>
<string name="file_searching">Suche nach passenden Dateien</string>
<string name="file_title_searching">Suche</string>
diff --git a/main/res/values/strings.xml b/main/res/values/strings.xml
index 7a87576..3f41f2b 100644
--- a/main/res/values/strings.xml
+++ b/main/res/values/strings.xml
@@ -580,6 +580,7 @@
<!-- file list base -->
<string name="file_searching_in">Searching for files\nin</string>
+ <string name="file_searching_sdcard_in">No files found in default folders:\n%1$s\n\nSearching whole SD card for files:\n</string>
<string name="file_list_no_files">c:geo found no appropriate files.</string>
<string name="file_searching">Searching for matching files</string>
<string name="file_title_searching">Searching</string>
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/StaticMapsProvider.java b/main/src/cgeo/geocaching/StaticMapsProvider.java
index 3c4aa60..6384d59 100644
--- a/main/src/cgeo/geocaching/StaticMapsProvider.java
+++ b/main/src/cgeo/geocaching/StaticMapsProvider.java
@@ -162,4 +162,37 @@ public class StaticMapsProvider {
}
}
}
+
+ /**
+ * Check if at least one map file exists for the given geocode.
+ *
+ * @param geocode
+ * @return <code>true</code> if at least one mapfile exists; <code>false</code> otherwise
+ */
+ public static boolean doesExistStaticMapForCache(String geocode) {
+ for (int level = 1; level <= 5; level++) {
+ File mapFile = StaticMapsProvider.getMapFile(geocode, "", level, false);
+ if (mapFile != null && mapFile.exists()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Checks if at least one map file exists for the given geocode and waypoint ID.
+ *
+ * @param geocode
+ * @param waypointId
+ * @return <code>true</code> if at least one mapfile exists; <code>false</code> otherwise
+ */
+ public static boolean doesExistStaticMapForWaypoint(String geocode, int waypointId) {
+ for (int level = 1; level <= 5; level++) {
+ File mapFile = StaticMapsProvider.getMapFile(geocode, "wp" + waypointId + "_", level, false);
+ if (mapFile != null && mapFile.exists()) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java
index 13a81ff..0ec3a0a 100644
--- a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java
+++ b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java
@@ -3,18 +3,26 @@ package cgeo.geocaching.apps.cache.navi;
import cgeo.geocaching.R;
import cgeo.geocaching.SearchResult;
import cgeo.geocaching.Settings;
+import cgeo.geocaching.StaticMapsProvider;
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;
+import org.apache.commons.lang3.StringUtils;
+
import android.app.Activity;
import android.app.AlertDialog;
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 +30,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,42 +68,120 @@ 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 hasStaticMaps = hasStaticMap(cache, waypoint);
for (NavigationAppsEnum navApp : getInstalledNavigationApps(activity)) {
- if ((showInternalMap || !(navApp.app instanceof InternalMap)) &&
+ if (NavigationAppsEnum.STATIC_MAP.id == navApp.id) {
+ if (hasStaticMaps) {
+ items.add(navApp);
+ }
+ } else if ((showInternalMap || !(navApp.app instanceof InternalMap)) &&
(showDefaultNavigation || defaultNavigationTool != navApp.id)) {
- menu.add(0, MENU_ITEM_OFFSET + navApp.id, 0, navApp.app.getName());
+ 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();
alert.show();
+ }
+ private static boolean hasStaticMap(cgCache cache, cgWaypoint waypoint) {
+ if (waypoint != null) {
+ String geocode = waypoint.getGeocode();
+ int id = waypoint.getId();
+ if (StringUtils.isNotEmpty(geocode) && cgeoapplication.getInstance().isOffline(geocode, null)) {
+ return StaticMapsProvider.doesExistStaticMapForWaypoint(geocode, id);
+ }
+ }
+ if (cache != null) {
+ String geocode = cache.getGeocode();
+ if (StringUtils.isNotEmpty(geocode) && cgeoapplication.getInstance().isOffline(geocode, null)) {
+ return StaticMapsProvider.doesExistStaticMapForCache(geocode);
+ }
+ }
+ return false;
}
+ /**
+ * 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 +192,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 +269,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 +279,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 1800b72..56e5866 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);
}
}
diff --git a/main/src/cgeo/geocaching/files/FileList.java b/main/src/cgeo/geocaching/files/FileList.java
index 2f810ea..2ad05f5 100644
--- a/main/src/cgeo/geocaching/files/FileList.java
+++ b/main/src/cgeo/geocaching/files/FileList.java
@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.List;
public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractListActivity {
+ private static final int MSG_SEARCH_WHOLE_SD_CARD = 1;
private List<File> files = new ArrayList<File>();
private T adapter = null;
@@ -29,15 +30,36 @@ public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractLis
private loadFiles searchingThread = null;
private boolean endSearching = false;
private int listId = 1;
+
final private Handler changeWaitDialogHandler = new Handler() {
+ private String searchInfo;
@Override
public void handleMessage(Message msg) {
if (msg.obj != null && waitDialog != null) {
- waitDialog.setMessage(res.getString(R.string.file_searching_in) + " " + (String) msg.obj);
+ if (searchInfo == null) {
+ searchInfo = res.getString(R.string.file_searching_in) + " ";
+ }
+ if (msg.what == MSG_SEARCH_WHOLE_SD_CARD) {
+ searchInfo = String.format(res.getString(R.string.file_searching_sdcard_in), getDefaultFolders());
+ }
+ waitDialog.setMessage(searchInfo + (String) msg.obj);
+ }
+ }
+
+ private String getDefaultFolders() {
+ StringBuilder sb = new StringBuilder();
+ for (File f : getBaseFolders()) {
+ String fName = f.getPath();
+ if (sb.length() > 0) {
+ sb.append("\n");
+ }
+ sb.append(fName);
}
+ return sb.toString();
}
};
+
final private Handler loadFilesHandler = new Handler() {
@Override
@@ -162,6 +184,7 @@ public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractLis
}
}
if (!loaded) {
+ changeWaitDialogHandler.sendMessage(Message.obtain(changeWaitDialogHandler, MSG_SEARCH_WHOLE_SD_CARD, Environment.getExternalStorageDirectory().getName()));
listDir(list, Environment.getExternalStorageDirectory());
}
} else {
@@ -171,14 +194,12 @@ public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractLis
Log.e(Settings.tag, "cgFileList.loadFiles.run: " + e.toString());
}
- final Message msg = new Message();
- msg.obj = "loaded directories";
- changeWaitDialogHandler.sendMessage(msg);
+ changeWaitDialogHandler.sendMessage(Message.obtain(changeWaitDialogHandler, 0, "loaded directories"));
files.addAll(list);
list.clear();
- loadFilesHandler.sendMessage(new Message());
+ loadFilesHandler.sendMessage(Message.obtain(loadFilesHandler));
}
}
@@ -209,9 +230,7 @@ public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractLis
if (name.length() > 16) {
name = name.substring(0, 14) + "...";
}
- final Message msg = new Message();
- msg.obj = name;
- changeWaitDialogHandler.sendMessage(msg);
+ changeWaitDialogHandler.sendMessage(Message.obtain(changeWaitDialogHandler, 0, name));
listDir(result, file); // go deeper
}