diff options
| -rw-r--r-- | src/cgeo/geocaching/apps/cache/navi/LocusApp.java | 8 | ||||
| -rw-r--r-- | src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java | 2 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgBase.java | 128 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgCacheListAdapter.java | 27 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeocaches.java | 102 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeodetail.java | 51 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeopopup.java | 36 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeotrackable.java | 18 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeowaypoint.java | 10 | ||||
| -rw-r--r-- | src/cgeo/geocaching/files/GPXParser.java | 142 | ||||
| -rw-r--r-- | src/cgeo/geocaching/mapcommon/cgeomap.java | 6 |
11 files changed, 220 insertions, 310 deletions
diff --git a/src/cgeo/geocaching/apps/cache/navi/LocusApp.java b/src/cgeo/geocaching/apps/cache/navi/LocusApp.java index 2b4baf4..41b9896 100644 --- a/src/cgeo/geocaching/apps/cache/navi/LocusApp.java +++ b/src/cgeo/geocaching/apps/cache/navi/LocusApp.java @@ -60,12 +60,12 @@ class LocusApp extends AbstractLocusApp implements NavigationApp { int icon = -1; if (cache != null) { - icon = cgBase.getIcon(true, cache.type, cache.own, cache.found, + icon = cgBase.getMarkerIcon(true, cache.type, cache.own, cache.found, cache.disabled || cache.archived); } else if (waypoint != null) { - icon = cgBase.getIcon(false, waypoint.type, false, false, false); + icon = cgBase.getMarkerIcon(false, waypoint.type, false, false, false); } else { - icon = cgBase.getIcon(false, "waypoint", false, false, false); + icon = cgBase.getMarkerIcon(false, "waypoint", false, false, false); } if (icon > 0) { @@ -139,7 +139,7 @@ class LocusApp extends AbstractLocusApp implements NavigationApp { continue; } - final int wpIcon = cgBase.getIcon(false, wp.type, false, + final int wpIcon = cgBase.getMarkerIcon(false, wp.type, false, false, false); if (wpIcon > 0) { diff --git a/src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java b/src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java index 0e03821..a9c438b 100644 --- a/src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java +++ b/src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java @@ -44,7 +44,7 @@ class LocusCacheListApp extends AbstractLocusApp implements CacheListApp { // cache waypoints for (cgCache cache : cacheListCoord) { - final int wpIcon = cgBase.getIcon(true, cache.type, cache.own, cache.found, cache.disabled); + final int wpIcon = cgBase.getMarkerIcon(true, cache.type, cache.own, cache.found, cache.disabled); if (wpIcon > 0) { // load icon diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java index 2483438..79e67b5 100644 --- a/src/cgeo/geocaching/cgBase.java +++ b/src/cgeo/geocaching/cgBase.java @@ -2107,7 +2107,7 @@ public class cgBase { final Pattern patternIcon = Pattern.compile("<img id=\"ctl00_ContentBody_BugTypeImage\" class=\"TravelBugHeaderIcon\" src=\"([^\"]+)\"[^>]*>", Pattern.CASE_INSENSITIVE); final Pattern patternType = Pattern.compile("<img id=\"ctl00_ContentBody_BugTypeImage\" class=\"TravelBugHeaderIcon\" src=\"[^\"]+\" alt=\"([^\"]+)\"[^>]*>", Pattern.CASE_INSENSITIVE); final Pattern patternDistance = Pattern.compile("<h4[^>]*\\W*Tracking History \\(([0-9\\.,]+(km|mi))[^\\)]*\\)", Pattern.CASE_INSENSITIVE); - final Pattern patternLog = Pattern.compile("<tr class=\"Data.+?src=\"/images/icons/([^\\.]+).gif[^>]+> ([^<]+)</td>.+?guid.+?>([^<]+)</a>.+?guid=([^\"]+)\">([^<]+)</a>.+?<td colspan=\"4\">(.+?)(?:<ul.+?ul>)?\\s*</td>\\s*</tr>", Pattern.CASE_INSENSITIVE); + final Pattern patternLog = Pattern.compile("<tr class=\"Data.+?src=\"/images/icons/([^\\.]+)\\.gif[^>]+> ([^<]+)</td>.+?guid.+?>([^<]+)</a>.+?(?:guid=([^\"]+)\">([^<]+)</a>.+?)?<td colspan=\"4\">(.+?)(?:<ul.+?ul>)?\\s*</td>\\s*</tr>", Pattern.CASE_INSENSITIVE); final cgTrackable trackable = new cgTrackable(); @@ -5022,9 +5022,85 @@ public class cgBase { } return out; } + + public static int getCacheIcon(final String type) { + fillIconsMap(); + Integer iconId = gcIcons.get("type_" + type); + if (iconId != null) { + return iconId; + } + // fallback to traditional if some icon type is not correct + return gcIcons.get("type_traditional"); + } + + public static int getMarkerIcon(final boolean cache, final String type, final boolean own, final boolean found, final boolean disabled) { + fillIconsMap(); + + if (wpIcons.isEmpty()) { + wpIcons.put("waypoint", R.drawable.marker_waypoint_waypoint); + wpIcons.put("flag", R.drawable.marker_waypoint_flag); + wpIcons.put("pkg", R.drawable.marker_waypoint_pkg); + wpIcons.put("puzzle", R.drawable.marker_waypoint_puzzle); + wpIcons.put("stage", R.drawable.marker_waypoint_stage); + wpIcons.put("trailhead", R.drawable.marker_waypoint_trailhead); + } + + int icon = -1; + String iconTxt = null; + + if (cache) { + if (type != null && type.length() > 0) { + if (own) { + iconTxt = type + "-own"; + } else if (found) { + iconTxt = type + "-found"; + } else if (disabled) { + iconTxt = type + "-disabled"; + } else { + iconTxt = type; + } + } else { + iconTxt = "traditional"; + } + + if (gcIcons.containsKey(iconTxt)) { + icon = gcIcons.get(iconTxt); + } else { + icon = gcIcons.get("traditional"); + } + } else { + if (type != null && type.length() > 0) { + iconTxt = type; + } else { + iconTxt = "waypoint"; + } + + if (wpIcons.containsKey(iconTxt)) { + icon = wpIcons.get(iconTxt); + } else { + icon = wpIcons.get("waypoint"); + } + } + + return icon; + } - public static int getIcon(boolean cache, String type, boolean own, boolean found, boolean disabled) { + private static void fillIconsMap() { if (gcIcons.isEmpty()) { + gcIcons.put("type_ape", R.drawable.type_ape); + gcIcons.put("type_cito", R.drawable.type_cito); + gcIcons.put("type_earth", R.drawable.type_earth); + gcIcons.put("type_event", R.drawable.type_event); + gcIcons.put("type_letterbox", R.drawable.type_letterbox); + gcIcons.put("type_locationless", R.drawable.type_locationless); + gcIcons.put("type_mega", R.drawable.type_mega); + gcIcons.put("type_multi", R.drawable.type_multi); + gcIcons.put("type_traditional", R.drawable.type_traditional); + gcIcons.put("type_virtual", R.drawable.type_virtual); + gcIcons.put("type_webcam", R.drawable.type_webcam); + gcIcons.put("type_wherigo", R.drawable.type_wherigo); + gcIcons.put("type_mystery", R.drawable.type_mystery); + gcIcons.put("type_gchq", R.drawable.type_hq); // default markers gcIcons.put("ape", R.drawable.marker_cache_ape); gcIcons.put("cito", R.drawable.marker_cache_cito); @@ -5086,54 +5162,6 @@ public class cgBase { gcIcons.put("mystery-disabled", R.drawable.marker_cache_mystery_disabled); gcIcons.put("gchq-disabled", R.drawable.marker_cache_gchq_disabled); } - - if (wpIcons.isEmpty()) { - wpIcons.put("waypoint", R.drawable.marker_waypoint_waypoint); - wpIcons.put("flag", R.drawable.marker_waypoint_flag); - wpIcons.put("pkg", R.drawable.marker_waypoint_pkg); - wpIcons.put("puzzle", R.drawable.marker_waypoint_puzzle); - wpIcons.put("stage", R.drawable.marker_waypoint_stage); - wpIcons.put("trailhead", R.drawable.marker_waypoint_trailhead); - } - - int icon = -1; - String iconTxt = null; - - if (cache) { - if (type != null && type.length() > 0) { - if (own) { - iconTxt = type + "-own"; - } else if (found) { - iconTxt = type + "-found"; - } else if (disabled) { - iconTxt = type + "-disabled"; - } else { - iconTxt = type; - } - } else { - iconTxt = "traditional"; - } - - if (gcIcons.containsKey(iconTxt)) { - icon = gcIcons.get(iconTxt); - } else { - icon = gcIcons.get("traditional"); - } - } else { - if (type != null && type.length() > 0) { - iconTxt = type; - } else { - iconTxt = "waypoint"; - } - - if (wpIcons.containsKey(iconTxt)) { - icon = wpIcons.get(iconTxt); - } else { - icon = wpIcons.get("waypoint"); - } - } - - return icon; } public static boolean runNavigation(Activity activity, Resources res, cgSettings settings, Double latitude, Double longitude) { diff --git a/src/cgeo/geocaching/cgCacheListAdapter.java b/src/cgeo/geocaching/cgCacheListAdapter.java index 64bf3ea..57c6e5f 100644 --- a/src/cgeo/geocaching/cgCacheListAdapter.java +++ b/src/cgeo/geocaching/cgCacheListAdapter.java @@ -55,7 +55,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { private boolean sort = true; private int checked = 0; private boolean selectMode = false; - private HashMap<String, Drawable> gcIcons = new HashMap<String, Drawable>(); + private static HashMap<String, Drawable> gcIconDrawables = new HashMap<String, Drawable>(); private ArrayList<cgCompassMini> compasses = new ArrayList<cgCompassMini>(); private ArrayList<cgDistanceView> distances = new ArrayList<cgDistanceView>(); private int[] ratingBcgs = new int[3]; @@ -81,21 +81,10 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); pixelDensity = metrics.density; - if (gcIcons == null || gcIcons.isEmpty()) { - gcIcons.put("ape", (Drawable) activity.getResources().getDrawable(R.drawable.type_ape)); - gcIcons.put("cito", (Drawable) activity.getResources().getDrawable(R.drawable.type_cito)); - gcIcons.put("earth", (Drawable) activity.getResources().getDrawable(R.drawable.type_earth)); - gcIcons.put("event", (Drawable) activity.getResources().getDrawable(R.drawable.type_event)); - gcIcons.put("letterbox", (Drawable) activity.getResources().getDrawable(R.drawable.type_letterbox)); - gcIcons.put("locationless", (Drawable) activity.getResources().getDrawable(R.drawable.type_locationless)); - gcIcons.put("mega", (Drawable) activity.getResources().getDrawable(R.drawable.type_mega)); - gcIcons.put("multi", (Drawable) activity.getResources().getDrawable(R.drawable.type_multi)); - gcIcons.put("traditional", (Drawable) activity.getResources().getDrawable(R.drawable.type_traditional)); - gcIcons.put("virtual", (Drawable) activity.getResources().getDrawable(R.drawable.type_virtual)); - gcIcons.put("webcam", (Drawable) activity.getResources().getDrawable(R.drawable.type_webcam)); - gcIcons.put("wherigo", (Drawable) activity.getResources().getDrawable(R.drawable.type_wherigo)); - gcIcons.put("mystery", (Drawable) activity.getResources().getDrawable(R.drawable.type_mystery)); - gcIcons.put("gchq", (Drawable) activity.getResources().getDrawable(R.drawable.type_hq)); + if (gcIconDrawables == null || gcIconDrawables.isEmpty()) { + for (String cacheType : cgBase.cacheTypesInv.keySet()) { + gcIconDrawables.put(cacheType, (Drawable) activity.getResources().getDrawable(cgBase.getCacheIcon(cacheType))); + } } if (settings.skin == 0) { @@ -471,10 +460,10 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { } holder.text.setText(cache.nameSp, TextView.BufferType.SPANNABLE); - if (gcIcons.containsKey(cache.type)) { // cache icon - holder.text.setCompoundDrawablesWithIntrinsicBounds(gcIcons.get(cache.type), null, null, null); + if (gcIconDrawables.containsKey(cache.type)) { // cache icon + holder.text.setCompoundDrawablesWithIntrinsicBounds(gcIconDrawables.get(cache.type), null, null, null); } else { // unknown cache type, "mystery" icon - holder.text.setCompoundDrawablesWithIntrinsicBounds(gcIcons.get("mystery"), null, null, null); + holder.text.setCompoundDrawablesWithIntrinsicBounds(gcIconDrawables.get("mystery"), null, null, null); } if (holder.inventory.getChildCount() > 0) { diff --git a/src/cgeo/geocaching/cgeocaches.java b/src/cgeo/geocaching/cgeocaches.java index 4d07740..c01ae72 100644 --- a/src/cgeo/geocaching/cgeocaches.java +++ b/src/cgeo/geocaching/cgeocaches.java @@ -40,6 +40,7 @@ import android.widget.EditText; import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.TextView; +import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.activity.AbstractListActivity; import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.apps.cache.navi.NavigationAppFactory; @@ -438,31 +439,25 @@ public class cgeocaches extends AbstractListActivity { @Override public void handleMessage(Message msg) { - setAdapter(); - - if (msg.what > -1) { - cacheList.get(msg.what).statusChecked = false; - } else { - if (adapter != null) { - adapter.setSelectMode(false, true); - } + if (adapter != null) { + adapter.setSelectMode(false, true); + } - refreshCurrentList(); + refreshCurrentList(); - cacheList.clear(); + cacheList.clear(); - final ArrayList<cgCache> cacheListTmp = app.getCaches(searchId); - if (cacheListTmp != null && cacheListTmp.isEmpty() == false) { - cacheList.addAll(cacheListTmp); - cacheListTmp.clear(); + final ArrayList<cgCache> cacheListTmp = app.getCaches(searchId); + if (cacheListTmp != null && cacheListTmp.isEmpty() == false) { + cacheList.addAll(cacheListTmp); + cacheListTmp.clear(); - Collections.sort((List<cgCache>)cacheList, gcComparator); - } + Collections.sort((List<cgCache>)cacheList, gcComparator); + } - if (waitDialog != null) { - waitDialog.dismiss(); - waitDialog.setOnCancelListener(null); - } + if (waitDialog != null) { + waitDialog.dismiss(); + waitDialog.setOnCancelListener(null); } } }; @@ -2145,9 +2140,6 @@ public class cgeocaches extends AbstractListActivity { final ArrayList<cgCache> cacheListTemp = new ArrayList<cgCache>(cacheList); for (cgCache cache : cacheListTemp) { if (checked > 0 && cache.statusChecked == false) { - handler.sendEmptyMessage(0); - - yield(); continue; } @@ -2158,10 +2150,6 @@ public class cgeocaches extends AbstractListActivity { } app.markDropped(cache.geocode); - - handler.sendEmptyMessage(cacheList.indexOf(cache)); - - yield(); } catch (Exception e) { Log.e(cgSettings.tag, "cgeocaches.geocachesDropDetails: " + e.toString()); } @@ -2488,21 +2476,33 @@ public class cgeocaches extends AbstractListActivity { alert.show(); } + private void removeListInternal() { + boolean status = app.removeList(listId); + + if (status) { + showToast(res.getString(R.string.list_dialog_remove_ok)); + switchListById(1); + } else { + showToast(res.getString(R.string.list_dialog_remove_err)); + } + } + private void removeList() { + // if there are no caches on this list, don't bother the user with questions. + // there is no harm in deleting the list, he could recreate it easily + if (cacheList != null && cacheList.isEmpty()) { + removeListInternal(); + return; + } + + // ask him, if there are caches on the list final AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle(R.string.list_dialog_remove_title); alert.setMessage(R.string.list_dialog_remove_description); alert.setPositiveButton(R.string.list_dialog_remove, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { - boolean status = app.removeList(listId); - - if (status) { - showToast(res.getString(R.string.list_dialog_remove_ok)); - switchListById(1); - } else { - showToast(res.getString(R.string.list_dialog_remove_err)); - } + removeListInternal(); } }); alert.setNegativeButton(res.getString(R.string.list_dialog_cancel), new DialogInterface.OnClickListener() { @@ -2547,4 +2547,36 @@ public class cgeocaches extends AbstractListActivity { cachesIntent.putExtra(EXTRAS_LIST_TYPE, "offline"); context.startActivity(cachesIntent); } + + public static void startActivityCachesAround(final AbstractActivity context, final Double latitude, final Double longitude) { + cgeocaches cachesActivity = new cgeocaches(); + + Intent cachesIntent = new Intent(context, cachesActivity.getClass()); + cachesIntent.putExtra("type", "coordinate"); + cachesIntent.putExtra("latitude", latitude); + cachesIntent.putExtra("longitude", longitude); + cachesIntent.putExtra("cachetype", context.getSettings().cacheType); + + context.startActivity(cachesIntent); + } + + public static void startActivityCacheOwner(final AbstractActivity context, final String userName) { + final Intent cachesIntent = new Intent(context, cgeocaches.class); + + cachesIntent.putExtra("type", "owner"); + cachesIntent.putExtra("username", userName); + cachesIntent.putExtra("cachetype", context.getSettings().cacheType); + + context.startActivity(cachesIntent); + } + + public static void startActivityCacheUser(final AbstractActivity context, final String userName) { + final Intent cachesIntent = new Intent(context, cgeocaches.class); + + cachesIntent.putExtra("type", "username"); + cachesIntent.putExtra("username", userName); + cachesIntent.putExtra("cachetype", context.getSettings().cacheType); + + context.startActivity(cachesIntent); + } }
\ No newline at end of file diff --git a/src/cgeo/geocaching/cgeodetail.java b/src/cgeo/geocaching/cgeodetail.java index 17d9e17..48b6430 100644 --- a/src/cgeo/geocaching/cgeodetail.java +++ b/src/cgeo/geocaching/cgeodetail.java @@ -80,7 +80,6 @@ public class cgeodetail extends AbstractActivity { private loadLongDesc threadLongDesc = null; private Thread storeThread = null; private Thread refreshThread = null; - private HashMap<String, Integer> gcIcons = new HashMap<String, Integer>(); private ProgressDialog storeDialog = null; private ProgressDialog refreshDialog = null; private ProgressDialog dropDialog = null; @@ -455,24 +454,10 @@ public class cgeodetail extends AbstractActivity { final int id = item.getItemId(); if (id == 1) { - final Intent cachesIntent = new Intent(this, cgeocaches.class); - - cachesIntent.putExtra("type", "owner"); - cachesIntent.putExtra("username", contextMenuUser); - cachesIntent.putExtra("cachetype", settings.cacheType); - - startActivity(cachesIntent); - + cgeocaches.startActivityCacheOwner(this, contextMenuUser); return true; } else if (id == 2) { - final Intent cachesIntent = new Intent(this, cgeocaches.class); - - cachesIntent.putExtra("type", "username"); - cachesIntent.putExtra("username", contextMenuUser); - cachesIntent.putExtra("cachetype", settings.cacheType); - - startActivity(cachesIntent); - + cgeocaches.startActivityCacheUser(this, contextMenuUser); return true; } else if (id == 3) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/profile/?u=" + URLEncoder.encode(contextMenuUser)))); @@ -607,22 +592,6 @@ public class cgeodetail extends AbstractActivity { } try { - if (gcIcons == null || gcIcons.isEmpty()) { - gcIcons.put("ape", R.drawable.type_ape); - gcIcons.put("cito", R.drawable.type_cito); - gcIcons.put("earth", R.drawable.type_earth); - gcIcons.put("event", R.drawable.type_event); - gcIcons.put("letterbox", R.drawable.type_letterbox); - gcIcons.put("locationless", R.drawable.type_locationless); - gcIcons.put("mega", R.drawable.type_mega); - gcIcons.put("multi", R.drawable.type_multi); - gcIcons.put("traditional", R.drawable.type_traditional); - gcIcons.put("virtual", R.drawable.type_virtual); - gcIcons.put("webcam", R.drawable.type_webcam); - gcIcons.put("wherigo", R.drawable.type_wherigo); - gcIcons.put("gchq", R.drawable.type_hq); - gcIcons.put("mystery", R.drawable.type_mystery); - } if (null == geocode && cache.geocode.length() > 0) { @@ -645,11 +614,7 @@ public class cgeodetail extends AbstractActivity { detailsList.removeAllViews(); // actionbar icon, default myster< - String typeId = "mystery"; - if (cache.type != null && gcIcons.containsKey(cache.type)) { // cache icon - typeId = cache.type; - } - ((TextView) findViewById(R.id.actionbar_title)).setCompoundDrawablesWithIntrinsicBounds((Drawable) getResources().getDrawable(gcIcons.get(typeId)), null, null, null); + ((TextView) findViewById(R.id.actionbar_title)).setCompoundDrawablesWithIntrinsicBounds((Drawable) getResources().getDrawable(cgBase.getCacheIcon(cache.type)), null, null, null); // cache name (full name) itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null); @@ -1441,15 +1406,7 @@ public class cgeodetail extends AbstractActivity { } private void cachesAround() { - cgeocaches cachesActivity = new cgeocaches(); - - Intent cachesIntent = new Intent(this, cachesActivity.getClass()); - cachesIntent.putExtra("type", "coordinate"); - cachesIntent.putExtra("latitude", cache.latitude); - cachesIntent.putExtra("longitude", cache.longitude); - cachesIntent.putExtra("cachetype", settings.cacheType); - - startActivity(cachesIntent); + cgeocaches.startActivityCachesAround(this, cache.latitude, cache.longitude); finish(); } diff --git a/src/cgeo/geocaching/cgeopopup.java b/src/cgeo/geocaching/cgeopopup.java index 54be58c..8531338 100644 --- a/src/cgeo/geocaching/cgeopopup.java +++ b/src/cgeo/geocaching/cgeopopup.java @@ -1,6 +1,5 @@ package cgeo.geocaching; -import java.util.HashMap; import java.util.Locale; import android.app.ProgressDialog; @@ -38,7 +37,6 @@ public class cgeopopup extends AbstractActivity { private ProgressDialog storeDialog = null; private ProgressDialog dropDialog = null; private TextView cacheDistance = null; - private HashMap<String, Integer> gcIcons = new HashMap<String, Integer>(); private Handler ratingHandler = new Handler() { @Override @@ -214,23 +212,6 @@ public class cgeopopup extends AbstractActivity { TextView itemValue; LinearLayout itemStars; - if (gcIcons == null || gcIcons.isEmpty()) { - gcIcons.put("ape", R.drawable.type_ape); - gcIcons.put("cito", R.drawable.type_cito); - gcIcons.put("earth", R.drawable.type_earth); - gcIcons.put("event", R.drawable.type_event); - gcIcons.put("letterbox", R.drawable.type_letterbox); - gcIcons.put("locationless", R.drawable.type_locationless); - gcIcons.put("mega", R.drawable.type_mega); - gcIcons.put("multi", R.drawable.type_multi); - gcIcons.put("traditional", R.drawable.type_traditional); - gcIcons.put("virtual", R.drawable.type_virtual); - gcIcons.put("webcam", R.drawable.type_webcam); - gcIcons.put("wherigo", R.drawable.type_wherigo); - gcIcons.put("mystery", R.drawable.type_mystery); - gcIcons.put("gchq", R.drawable.type_hq); - } - if (cache.name != null && cache.name.length() > 0) { setTitle(cache.name); } else { @@ -245,11 +226,7 @@ public class cgeopopup extends AbstractActivity { detailsList.removeAllViews(); // actionbar icon - if (cache.type != null && gcIcons.containsKey(cache.type)) { // cache icon - ((TextView) findViewById(R.id.actionbar_title)).setCompoundDrawablesWithIntrinsicBounds((Drawable) getResources().getDrawable(gcIcons.get(cache.type)), null, null, null); - } else { // unknown cache type, "mystery" icon - ((TextView) findViewById(R.id.actionbar_title)).setCompoundDrawablesWithIntrinsicBounds((Drawable) getResources().getDrawable(gcIcons.get("mystery")), null, null, null); - } + ((TextView) findViewById(R.id.actionbar_title)).setCompoundDrawablesWithIntrinsicBounds((Drawable) getResources().getDrawable(cgBase.getCacheIcon(cache.type)), null, null, null); // cache type itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null); @@ -561,16 +538,7 @@ public class cgeopopup extends AbstractActivity { showToast(res.getString(R.string.err_location_unknown)); } - cgeocaches cachesActivity = new cgeocaches(); - - Intent cachesIntent = new Intent(this, cachesActivity.getClass()); - - cachesIntent.putExtra("type", "coordinate"); - cachesIntent.putExtra("latitude", cache.latitude); - cachesIntent.putExtra("longitude", cache.longitude); - cachesIntent.putExtra("cachetype", settings.cacheType); - - startActivity(cachesIntent); + cgeocaches.startActivityCachesAround(this, cache.latitude, cache.longitude); finish(); } diff --git a/src/cgeo/geocaching/cgeotrackable.java b/src/cgeo/geocaching/cgeotrackable.java index d0f82be..d41324e 100644 --- a/src/cgeo/geocaching/cgeotrackable.java +++ b/src/cgeo/geocaching/cgeotrackable.java @@ -420,24 +420,10 @@ public class cgeotrackable extends AbstractActivity { final int id = item.getItemId(); if (id == 1) { - final Intent cachesIntent = new Intent(this, cgeocaches.class); - - cachesIntent.putExtra("type", "owner"); - cachesIntent.putExtra("username", contextMenuUser); - cachesIntent.putExtra("cachetype", settings.cacheType); - - startActivity(cachesIntent); - + cgeocaches.startActivityCacheOwner(this, contextMenuUser); return true; } else if (id == 2) { - final Intent cachesIntent = new Intent(this, cgeocaches.class); - - cachesIntent.putExtra("type", "username"); - cachesIntent.putExtra("username", contextMenuUser); - cachesIntent.putExtra("cachetype", settings.cacheType); - - startActivity(cachesIntent); - + cgeocaches.startActivityCacheUser(this, contextMenuUser); return true; } else if (id == 3) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/profile/?u=" + URLEncoder.encode(contextMenuUser)))); diff --git a/src/cgeo/geocaching/cgeowaypoint.java b/src/cgeo/geocaching/cgeowaypoint.java index e4ec379..b964df7 100644 --- a/src/cgeo/geocaching/cgeowaypoint.java +++ b/src/cgeo/geocaching/cgeowaypoint.java @@ -257,15 +257,7 @@ public class cgeowaypoint extends AbstractActivity { showToast(res.getString(R.string.err_location_unknown)); } - cgeocaches cachesActivity = new cgeocaches(); - - Intent cachesIntent = new Intent(this, cachesActivity.getClass()); - cachesIntent.putExtra("type", "coordinate"); - cachesIntent.putExtra("latitude", waypoint.latitude); - cachesIntent.putExtra("longitude", waypoint.longitude); - cachesIntent.putExtra("cachetype", settings.cacheType); - - startActivity(cachesIntent); + cgeocaches.startActivityCachesAround(this, waypoint.latitude, waypoint.longitude); finish(); } diff --git a/src/cgeo/geocaching/files/GPXParser.java b/src/cgeo/geocaching/files/GPXParser.java index 7d59862..14607bf 100644 --- a/src/cgeo/geocaching/files/GPXParser.java +++ b/src/cgeo/geocaching/files/GPXParser.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -20,7 +21,6 @@ import android.sax.EndElementListener; import android.sax.EndTextElementListener; import android.sax.RootElement; import android.sax.StartElementListener; -import android.text.Html; import android.util.Log; import android.util.Xml; import cgeo.geocaching.R; @@ -57,8 +57,6 @@ public abstract class GPXParser extends FileParser { private cgLog log = new cgLog(); private CacheAttribute cacheAttribute = null; - private boolean shortDescIsHtml = true; - private boolean longDescIsHtml = true; private String type = null; private String sym = null; private String name = null; @@ -198,11 +196,8 @@ public abstract class GPXParser extends FileParser { return formatSimple.parse(input); } - public long parse(File file, Handler handlerIn) { + public long parse(final InputStream stream, Handler handlerIn) { handler = handlerIn; - if (file == null) { - return 0l; - } final RootElement root = new RootElement(namespace, "gpx"); final Element waypoint = root.getChild(namespace, "wpt"); @@ -251,8 +246,6 @@ public abstract class GPXParser extends FileParser { showFinishedMessage(handler, search); - shortDescIsHtml = true; - longDescIsHtml = true; type = null; sym = null; name = null; @@ -284,7 +277,7 @@ public abstract class GPXParser extends FileParser { public void end(String body) { name = body; - final String content = Html.fromHtml(body).toString().trim(); + final String content = body.trim(); cache.name = content; findGeoCode(cache.name); @@ -299,8 +292,7 @@ public abstract class GPXParser extends FileParser { public void end(String body) { desc = body; - final String content = Html.fromHtml(body).toString().trim(); - cache.shortdesc = content; + cache.shortdesc = validate(body); } }); @@ -311,8 +303,7 @@ public abstract class GPXParser extends FileParser { public void end(String body) { cmt = body; - final String content = Html.fromHtml(body).toString().trim(); - cache.description = content; + cache.description = validate(body); } }); @@ -373,8 +364,8 @@ public abstract class GPXParser extends FileParser { gcCache.getChild(nsGC, "name").setEndTextElementListener(new EndTextElementListener() { @Override - public void end(String body) { - cache.name = validate(Html.fromHtml(body).toString().trim()); + public void end(String cacheName) { + cache.name = validate(cacheName); } }); @@ -382,8 +373,8 @@ public abstract class GPXParser extends FileParser { gcCache.getChild(nsGC, "owner").setEndTextElementListener(new EndTextElementListener() { @Override - public void end(String body) { - cache.owner = validate(Html.fromHtml(body).toString().trim()); + public void end(String cacheOwner) { + cache.owner = validate(cacheOwner); } }); @@ -479,11 +470,11 @@ public abstract class GPXParser extends FileParser { gcCache.getChild(nsGC, "country").setEndTextElementListener(new EndTextElementListener() { @Override - public void end(String body) { + public void end(String country) { if (cache.location == null || cache.location.length() == 0) { - cache.location = validate(body.trim()); + cache.location = validate(country); } else { - cache.location = cache.location + ", " + body.trim(); + cache.location = cache.location + ", " + country.trim(); } } }); @@ -492,11 +483,11 @@ public abstract class GPXParser extends FileParser { gcCache.getChild(nsGC, "state").setEndTextElementListener(new EndTextElementListener() { @Override - public void end(String body) { + public void end(String state) { if (cache.location == null || cache.location.length() == 0) { - cache.location = validate(body.trim()); + cache.location = validate(state); } else { - cache.location = body.trim() + ", " + cache.location; + cache.location = state.trim() + ", " + cache.location; } } }); @@ -505,67 +496,24 @@ public abstract class GPXParser extends FileParser { gcCache.getChild(nsGC, "encoded_hints").setEndTextElementListener(new EndTextElementListener() { @Override - public void end(String body) { - cache.hint = validate(body.trim()); - } - }); - - // waypoint.cache.short_description - gcCache.getChild(nsGC, "short_description").setStartElementListener(new StartElementListener() { - - @Override - public void start(Attributes attrs) { - try { - if (attrs.getIndex("html") > -1) { - final String at = attrs.getValue("html"); - if (at.equalsIgnoreCase("false")) { - shortDescIsHtml = false; - } - } - } catch (Exception e) { - // nothing - } + public void end(String encoded) { + cache.hint = validate(encoded); } }); gcCache.getChild(nsGC, "short_description").setEndTextElementListener(new EndTextElementListener() { @Override - public void end(String body) { - if (shortDescIsHtml) { - cache.shortdesc = body.trim(); - } else { - cache.shortdesc = Html.fromHtml(body).toString(); - } - } - }); - - // waypoint.cache.long_description - gcCache.getChild(nsGC, "long_description").setStartElementListener(new StartElementListener() { - - @Override - public void start(Attributes attrs) { - try { - if (attrs.getIndex("html") > -1) { - if (attrs.getValue("html").equalsIgnoreCase("false")) { - longDescIsHtml = false; - } - } - } catch (Exception e) { - // nothing - } + public void end(String shortDesc) { + cache.shortdesc = validate(shortDesc); } }); gcCache.getChild(nsGC, "long_description").setEndTextElementListener(new EndTextElementListener() { @Override - public void end(String body) { - if (longDescIsHtml) { - cache.description = body.trim(); - } else { - cache.description = Html.fromHtml(body).toString().trim(); - } + public void end(String desc) { + cache.description = validate(desc); } }); @@ -609,8 +557,8 @@ public abstract class GPXParser extends FileParser { gcTB.getChild(nsGC, "name").setEndTextElementListener(new EndTextElementListener() { @Override - public void end(String body) { - trackable.name = Html.fromHtml(body).toString(); + public void end(String tbName) { + trackable.name = validate(tbName); } }); @@ -667,7 +615,7 @@ public abstract class GPXParser extends FileParser { @Override public void end(String body) { - final String logType = body.trim().toLowerCase(); + final String logType = validate(body).toLowerCase(); if (cgBase.logTypes0.containsKey(logType)) { log.type = cgBase.logTypes0.get(logType); } else { @@ -680,34 +628,44 @@ public abstract class GPXParser extends FileParser { gcLog.getChild(nsGC, "finder").setEndTextElementListener(new EndTextElementListener() { @Override - public void end(String body) { - log.author = Html.fromHtml(body).toString(); + public void end(String finderName) { + log.author = validate(finderName); } }); - // waypoint.cache.logs.log.finder + // waypoint.cache.logs.log.text gcLog.getChild(nsGC, "text").setEndTextElementListener(new EndTextElementListener() { @Override - public void end(String body) { - log.log = Html.fromHtml(body).toString(); + public void end(String logText) { + log.log = validate(logText); } }); } - FileInputStream fis = null; boolean parsed = false; try { - fis = new FileInputStream(file); - } catch (FileNotFoundException e) { - Log.e(cgSettings.tag, "Cannot parse .gpx file " + file.getAbsolutePath() + " as GPX " + version + ": file not found!"); - } - try { - Xml.parse(fis, Xml.Encoding.UTF_8, root.getContentHandler()); + Xml.parse(stream, Xml.Encoding.UTF_8, root.getContentHandler()); parsed = true; } catch (IOException e) { - Log.e(cgSettings.tag, "Cannot parse .gpx file " + file.getAbsolutePath() + " as GPX " + version + ": could not read file!"); + Log.e(cgSettings.tag, "Cannot parse .gpx file as GPX " + version + ": could not read file!"); } catch (SAXException e) { - Log.e(cgSettings.tag, "Cannot parse .gpx file " + file.getAbsolutePath() + " as GPX " + version + ": could not parse XML - " + e.toString()); + Log.e(cgSettings.tag, "Cannot parse .gpx file as GPX " + version + ": could not parse XML - " + e.toString()); + } + return parsed ? search.getCurrentId() : 0l; + } + + private long parse(final File file, final Handler handlerIn) { + if (file == null) { + return 0l; + } + + FileInputStream fis = null; + long result = 0l; + try { + fis = new FileInputStream(file); + result = parse(fis, handlerIn); + } catch (FileNotFoundException e) { + Log.e(cgSettings.tag, "Cannot parse .gpx file " + file.getAbsolutePath() + " as GPX " + version + ": file not found!"); } try { if (fis != null) { @@ -716,7 +674,7 @@ public abstract class GPXParser extends FileParser { } catch (IOException e) { Log.e(cgSettings.tag, "Error after parsing .gpx file " + file.getAbsolutePath() + " as GPX " + version + ": could not close file!"); } - return parsed ? search.getCurrentId() : 0l; + return result; } protected abstract Element getCacheParent(Element waypoint); @@ -725,7 +683,7 @@ public abstract class GPXParser extends FileParser { if ("nil".equalsIgnoreCase(input)) { return ""; } - return input; + return input.trim(); } private void setType(String parsedString) { diff --git a/src/cgeo/geocaching/mapcommon/cgeomap.java b/src/cgeo/geocaching/mapcommon/cgeomap.java index 8500e1c..9360899 100644 --- a/src/cgeo/geocaching/mapcommon/cgeomap.java +++ b/src/cgeo/geocaching/mapcommon/cgeomap.java @@ -1280,7 +1280,7 @@ public class cgeomap extends MapBase { coordinates.add(coord); item = settings.getMapFactory().getCacheOverlayItem(coord, cacheOne.type); - icon = cgBase.getIcon(true, cacheOne.type, cacheOne.own, cacheOne.found, cacheOne.disabled || cacheOne.archived); + icon = cgBase.getMarkerIcon(true, cacheOne.type, cacheOne.own, cacheOne.found, cacheOne.disabled || cacheOne.archived); pin = null; if (iconsCache.containsKey(icon)) { @@ -1324,7 +1324,7 @@ public class cgeomap extends MapBase { coordinates.add(coord); item = settings.getMapFactory().getCacheOverlayItem(coord, null); - icon = cgBase.getIcon(false, oneWaypoint.type, false, false, false); + icon = cgBase.getMarkerIcon(false, oneWaypoint.type, false, false, false); if (iconsCache.containsKey(icon)) { pin = iconsCache.get(icon); } else { @@ -1480,7 +1480,7 @@ public class cgeomap extends MapBase { coordinates.add(coord); CacheOverlayItemImpl item = settings.getMapFactory().getCacheOverlayItem(coord, null); - final int icon = cgBase.getIcon(false, waypointTypeIntent, false, false, false); + final int icon = cgBase.getMarkerIcon(false, waypointTypeIntent, false, false, false); Drawable pin = null; if (iconsCache.containsKey(icon)) { pin = iconsCache.get(icon); |
