aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo
diff options
context:
space:
mode:
Diffstat (limited to 'src/cgeo')
-rw-r--r--src/cgeo/geocaching/LogTemplateProvider.java7
-rw-r--r--src/cgeo/geocaching/StaticMapsProvider.java6
-rw-r--r--src/cgeo/geocaching/activity/ActivityMixin.java16
-rw-r--r--src/cgeo/geocaching/apps/AbstractApp.java3
-rw-r--r--src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java4
-rw-r--r--src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java4
-rw-r--r--src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java4
-rw-r--r--src/cgeo/geocaching/apps/cache/navi/InternalMap.java6
-rw-r--r--src/cgeo/geocaching/apps/cache/navi/LocusApp.java8
-rw-r--r--src/cgeo/geocaching/apps/cache/navi/NavigationApp.java4
-rw-r--r--src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java9
-rw-r--r--src/cgeo/geocaching/apps/cache/navi/RMapsApp.java3
-rw-r--r--src/cgeo/geocaching/apps/cache/navi/RadarApp.java4
-rw-r--r--src/cgeo/geocaching/apps/cache/navi/StaticMapApp.java4
-rw-r--r--src/cgeo/geocaching/apps/cache/navi/StreetviewApp.java4
-rw-r--r--src/cgeo/geocaching/apps/cachelist/CacheListApp.java3
-rw-r--r--src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java9
-rw-r--r--src/cgeo/geocaching/apps/cachelist/InternalCacheListMap.java5
-rw-r--r--src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java5
-rw-r--r--src/cgeo/geocaching/cgBase.java562
-rw-r--r--src/cgeo/geocaching/cgCache.java63
-rw-r--r--src/cgeo/geocaching/cgCacheListAdapter.java38
-rw-r--r--src/cgeo/geocaching/cgCacheView.java3
-rw-r--r--src/cgeo/geocaching/cgCacheWrap.java3
-rw-r--r--src/cgeo/geocaching/cgData.java218
-rw-r--r--src/cgeo/geocaching/cgDirectionImg.java5
-rw-r--r--src/cgeo/geocaching/cgGeo.java7
-rw-r--r--src/cgeo/geocaching/cgHtmlImg.java5
-rw-r--r--src/cgeo/geocaching/cgLog.java4
-rw-r--r--src/cgeo/geocaching/cgOAuth.java7
-rw-r--r--src/cgeo/geocaching/cgSearch.java13
-rw-r--r--src/cgeo/geocaching/cgSelectMapfile.java7
-rw-r--r--src/cgeo/geocaching/cgSettings.java24
-rw-r--r--src/cgeo/geocaching/cgTrackable.java6
-rw-r--r--src/cgeo/geocaching/cgWaypoint.java22
-rw-r--r--src/cgeo/geocaching/cgeo.java14
-rw-r--r--src/cgeo/geocaching/cgeoaddresses.java2
-rw-r--r--src/cgeo/geocaching/cgeoadvsearch.java22
-rw-r--r--src/cgeo/geocaching/cgeoapplication.java112
-rw-r--r--src/cgeo/geocaching/cgeoauth.java15
-rw-r--r--src/cgeo/geocaching/cgeocaches.java102
-rw-r--r--src/cgeo/geocaching/cgeocoords.java15
-rw-r--r--src/cgeo/geocaching/cgeodetail.java109
-rw-r--r--src/cgeo/geocaching/cgeogpxes.java7
-rw-r--r--src/cgeo/geocaching/cgeoimages.java7
-rw-r--r--src/cgeo/geocaching/cgeoinit.java12
-rw-r--r--src/cgeo/geocaching/cgeonavigate.java26
-rw-r--r--src/cgeo/geocaching/cgeopoint.java31
-rw-r--r--src/cgeo/geocaching/cgeopopup.java12
-rw-r--r--src/cgeo/geocaching/cgeosmaps.java6
-rw-r--r--src/cgeo/geocaching/cgeotouch.java23
-rw-r--r--src/cgeo/geocaching/cgeotrackable.java61
-rw-r--r--src/cgeo/geocaching/cgeotrackables.java17
-rw-r--r--src/cgeo/geocaching/cgeovisit.java55
-rw-r--r--src/cgeo/geocaching/cgeowaypoint.java8
-rw-r--r--src/cgeo/geocaching/cgeowaypointadd.java29
-rw-r--r--src/cgeo/geocaching/connector/GCConnector.java4
-rw-r--r--src/cgeo/geocaching/connector/OCConnector.java4
-rw-r--r--src/cgeo/geocaching/connector/OXConnector.java4
-rw-r--r--src/cgeo/geocaching/files/FileList.java13
-rw-r--r--src/cgeo/geocaching/files/GPXParser.java36
-rw-r--r--src/cgeo/geocaching/files/LocParser.java26
-rw-r--r--src/cgeo/geocaching/googlemaps/googleMapView.java21
-rw-r--r--src/cgeo/geocaching/mapcommon/cgMapMyOverlay.java5
-rw-r--r--src/cgeo/geocaching/mapcommon/cgMapOverlay.java13
-rw-r--r--src/cgeo/geocaching/mapcommon/cgUsersOverlay.java11
-rw-r--r--src/cgeo/geocaching/mapcommon/cgeomap.java59
-rw-r--r--src/cgeo/geocaching/mapinterfaces/MapViewImpl.java1
-rw-r--r--src/cgeo/geocaching/mapinterfaces/OnDragListener.java12
-rw-r--r--src/cgeo/geocaching/mapsforge/mfMapView.java36
-rw-r--r--src/cgeo/geocaching/sorting/GeocodeComparator.java6
-rw-r--r--src/cgeo/geocaching/sorting/NameComparator.java4
-rw-r--r--src/cgeo/geocaching/sorting/SizeComparator.java4
-rw-r--r--src/cgeo/geocaching/utils/CollectionUtils.java25
74 files changed, 1124 insertions, 940 deletions
diff --git a/src/cgeo/geocaching/LogTemplateProvider.java b/src/cgeo/geocaching/LogTemplateProvider.java
index 08931a7..4cc97fc 100644
--- a/src/cgeo/geocaching/LogTemplateProvider.java
+++ b/src/cgeo/geocaching/LogTemplateProvider.java
@@ -1,9 +1,12 @@
package cgeo.geocaching;
import java.util.HashMap;
+import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.lang3.StringUtils;
+
import android.util.Log;
@@ -82,7 +85,7 @@ public class LogTemplateProvider {
@Override
String getValue(final cgBase base) {
String findCount = "";
- final HashMap<String, String> params = new HashMap<String, String>();
+ final Map<String, String> params = new HashMap<String, String>();
final String page = base.request(false, "www.geocaching.com", "/email/", "GET", params, false, false, false).getData();
int current = parseFindCount(page);
@@ -118,7 +121,7 @@ public class LogTemplateProvider {
}
private static int parseFindCount(String page) {
- if (page == null || page.length() == 0) {
+ if (StringUtils.isBlank(page)) {
return -1;
}
diff --git a/src/cgeo/geocaching/StaticMapsProvider.java b/src/cgeo/geocaching/StaticMapsProvider.java
index 927a99c..5962460 100644
--- a/src/cgeo/geocaching/StaticMapsProvider.java
+++ b/src/cgeo/geocaching/StaticMapsProvider.java
@@ -6,6 +6,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
+import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
@@ -18,6 +19,7 @@ import android.content.Context;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
+import cgeo.geocaching.utils.CollectionUtils;
public class StaticMapsProvider {
private static final String MARKERS_URL = "http://cgeo.carnero.cc/_markers/";
@@ -122,7 +124,7 @@ public class StaticMapsProvider {
public static void downloadMaps(cgCache cache, cgSettings settings, Activity activity) {
if (settings.storeOfflineMaps != 1 || cache.latitude == null
- || cache.longitude == null || cache.geocode == null || cache.geocode.length() == 0) {
+ || cache.longitude == null || StringUtils.isNotBlank(cache.geocode)) {
return;
}
@@ -138,7 +140,7 @@ public class StaticMapsProvider {
}
final StringBuilder waypoints = new StringBuilder();
- if (cache.waypoints != null && cache.waypoints.size() > 0) {
+ if (CollectionUtils.isNotEmpty(cache.waypoints)) {
for (cgWaypoint waypoint : cache.waypoints) {
if (waypoint.latitude == null && waypoint.longitude == null) {
continue;
diff --git a/src/cgeo/geocaching/activity/ActivityMixin.java b/src/cgeo/geocaching/activity/ActivityMixin.java
index 9a50662..53efd4b 100644
--- a/src/cgeo/geocaching/activity/ActivityMixin.java
+++ b/src/cgeo/geocaching/activity/ActivityMixin.java
@@ -2,7 +2,9 @@ package cgeo.geocaching.activity;
import gnu.android.app.appmanualclient.AppManualReaderClient;
-import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
import android.app.Activity;
import android.app.AlertDialog;
@@ -35,7 +37,7 @@ public final class ActivityMixin {
}
public final static void goManual(final Context context, final String helpTopic) {
- if (helpTopic == null || helpTopic.length() == 0) {
+ if (StringUtils.isBlank(helpTopic)) {
return;
}
try {
@@ -50,7 +52,7 @@ public final class ActivityMixin {
}
public final static void setTitle(final Activity activity, final String text) {
- if (text == null) {
+ if (StringUtils.isBlank(text)) {
return;
}
@@ -83,7 +85,7 @@ public final class ActivityMixin {
}
public final static void showToast(final Activity activity, final String text) {
- if (text.length() > 0) {
+ if (StringUtils.isNotBlank(text)) {
Toast toast = Toast.makeText(activity, text, Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM, 0, 100);
@@ -92,7 +94,7 @@ public final class ActivityMixin {
}
public final static void showShortToast(final Activity activity, final String text) {
- if (text.length() > 0) {
+ if (StringUtils.isNotBlank(text)) {
Toast toast = Toast.makeText(activity, text, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM, 0, 100);
@@ -101,7 +103,7 @@ public final class ActivityMixin {
}
public static final void helpDialog(final Activity activity, final String title, final String message) {
- if (message == null || message.length() == 0) {
+ if (StringUtils.isBlank(message)) {
return;
}
@@ -131,7 +133,7 @@ public final class ActivityMixin {
if (settings.isLogin()) {
if (settings.getLogOffline()) {
SubMenu logMenu = menu.addSubMenu(1, IAbstractActivity.MENU_LOG_VISIT_OFFLINE, 0, res.getString(R.string.cache_menu_visit_offline)).setIcon(MENU_ICON_LOG_VISIT);
- ArrayList<Integer> logTypes = cache.getPossibleLogTypes(settings);
+ List<Integer> logTypes = cache.getPossibleLogTypes(settings);
for (Integer logType : logTypes) {
String label = cgBase.logTypes2.get(logType);
logMenu.add(1, IAbstractActivity.MENU_LOG_VISIT_OFFLINE + logType, 0, label);
diff --git a/src/cgeo/geocaching/apps/AbstractApp.java b/src/cgeo/geocaching/apps/AbstractApp.java
index 42ce677..190bf5e 100644
--- a/src/cgeo/geocaching/apps/AbstractApp.java
+++ b/src/cgeo/geocaching/apps/AbstractApp.java
@@ -8,6 +8,7 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.utils.CollectionUtils;
public abstract class AbstractApp implements App {
@@ -60,7 +61,7 @@ public abstract class AbstractApp implements App {
final List<ResolveInfo> list = packageManager.queryIntentActivities(
intent, PackageManager.MATCH_DEFAULT_ONLY);
- return list.size() > 0;
+ return (CollectionUtils.isNotEmpty(list));
}
@Override
diff --git a/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java b/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java
index 8291365..c184bd0 100644
--- a/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java
+++ b/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.apps.cache;
+import org.apache.commons.lang3.ArrayUtils;
+
import android.app.Activity;
import android.content.res.Resources;
import android.util.Log;
@@ -13,7 +15,7 @@ public final class GeneralAppsFactory extends AbstractAppFactory {
private static GeneralApp[] apps = new GeneralApp[] {};
private static GeneralApp[] getGeneralApps(Resources res) {
- if (null == apps || 0 == apps.length) {
+ if (ArrayUtils.isEmpty(apps)) {
apps = new GeneralApp[] { new GccApp(res),
new WhereYouGoApp(res) };
}
diff --git a/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java b/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java
index 6b05426..273be5c 100644
--- a/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java
+++ b/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.apps.cache.navi;
+import java.util.UUID;
+
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
@@ -26,7 +28,7 @@ class GoogleMapsApp extends AbstractNavigationApp implements NavigationApp {
public boolean invoke(cgGeo geo, Activity activity, Resources res,
cgCache cache,
- Long searchId, cgWaypoint waypoint, Double latitude, Double longitude) {
+ final UUID searchId, cgWaypoint waypoint, Double latitude, Double longitude) {
if (cache == null && waypoint == null && latitude == null && longitude == null) {
return false;
}
diff --git a/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java b/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java
index b8afb54..4a7a49e 100644
--- a/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java
+++ b/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.apps.cache.navi;
+import java.util.UUID;
+
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
@@ -28,7 +30,7 @@ class GoogleNavigationApp extends AbstractNavigationApp implements
@Override
public boolean invoke(final cgGeo geo, final Activity activity, final Resources res,
final cgCache cache,
- final Long searchId, final cgWaypoint waypoint, final Double latitude, final Double longitude) {
+ final UUID searchId, final cgWaypoint waypoint, final Double latitude, final Double longitude) {
if (activity == null) {
return false;
}
diff --git a/src/cgeo/geocaching/apps/cache/navi/InternalMap.java b/src/cgeo/geocaching/apps/cache/navi/InternalMap.java
index 4c3d815..513172c 100644
--- a/src/cgeo/geocaching/apps/cache/navi/InternalMap.java
+++ b/src/cgeo/geocaching/apps/cache/navi/InternalMap.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.apps.cache.navi;
+import java.util.UUID;
+
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
@@ -19,7 +21,7 @@ class InternalMap extends AbstractInternalMap implements
@Override
public boolean invoke(cgGeo geo, Activity activity, Resources res,
cgCache cache,
- Long searchId, cgWaypoint waypoint, Double latitude, Double longitude) {
+ final UUID searchId, cgWaypoint waypoint, Double latitude, Double longitude) {
cgSettings settings = getSettings(activity);
Intent mapIntent = new Intent(activity, settings.getMapFactory().getMapClass());
if (cache != null) {
@@ -28,7 +30,7 @@ class InternalMap extends AbstractInternalMap implements
}
if (searchId != null) {
mapIntent.putExtra("detail", true);
- mapIntent.putExtra("searchid", searchId);
+ mapIntent.putExtra("searchid", searchId.toString());
}
if (waypoint != null) {
mapIntent.putExtra("latitude", waypoint.latitude);
diff --git a/src/cgeo/geocaching/apps/cache/navi/LocusApp.java b/src/cgeo/geocaching/apps/cache/navi/LocusApp.java
index c74e855..11a5ae3 100644
--- a/src/cgeo/geocaching/apps/cache/navi/LocusApp.java
+++ b/src/cgeo/geocaching/apps/cache/navi/LocusApp.java
@@ -1,6 +1,10 @@
package cgeo.geocaching.apps.cache.navi;
import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.commons.lang3.StringUtils;
import android.app.Activity;
import android.content.res.Resources;
@@ -8,6 +12,7 @@ import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgGeo;
import cgeo.geocaching.cgWaypoint;
import cgeo.geocaching.apps.AbstractLocusApp;
+import cgeo.geocaching.utils.CollectionUtils;
class LocusApp extends AbstractLocusApp implements NavigationApp {
@@ -24,7 +29,7 @@ class LocusApp extends AbstractLocusApp implements NavigationApp {
*/
@Override
public boolean invoke(cgGeo geo, Activity activity, Resources res, cgCache cache,
- Long searchId, cgWaypoint waypoint, Double latitude, Double longitude) {
+ final UUID searchId, cgWaypoint waypoint, Double latitude, Double longitude) {
if (cache == null && waypoint == null && latitude == null && longitude == null) {
return false;
@@ -42,6 +47,7 @@ class LocusApp extends AbstractLocusApp implements NavigationApp {
if (cache.longitude != null && cache.latitude != null) {
points.add(cache);
}
+
// use only waypoints with coordinates
if (cache.waypoints != null) {
for (cgWaypoint wp : cache.waypoints) {
diff --git a/src/cgeo/geocaching/apps/cache/navi/NavigationApp.java b/src/cgeo/geocaching/apps/cache/navi/NavigationApp.java
index 2f52111..db0c1e3 100644
--- a/src/cgeo/geocaching/apps/cache/navi/NavigationApp.java
+++ b/src/cgeo/geocaching/apps/cache/navi/NavigationApp.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.apps.cache.navi;
+import java.util.UUID;
+
import android.app.Activity;
import android.content.res.Resources;
import cgeo.geocaching.cgCache;
@@ -11,6 +13,6 @@ interface NavigationApp extends App {
public boolean invoke(final cgGeo geo, final Activity activity,
final Resources res,
final cgCache cache,
- final Long searchId, final cgWaypoint waypoint,
+ final UUID searchId, final cgWaypoint waypoint,
final Double latitude, final Double longitude);
}
diff --git a/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java b/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java
index e496e33..b8872e3 100644
--- a/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java
+++ b/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java
@@ -1,6 +1,9 @@
package cgeo.geocaching.apps.cache.navi;
-import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.commons.lang3.ArrayUtils;
import android.app.Activity;
import android.content.res.Resources;
@@ -17,7 +20,7 @@ public final class NavigationAppFactory extends AbstractAppFactory {
private static NavigationApp[] apps = new NavigationApp[] {};
private static NavigationApp[] getNavigationApps(Resources res) {
- if (null == apps || 0 == apps.length) {
+ if (ArrayUtils.isEmpty(apps)) {
apps = new NavigationApp[] {
// compass
new RadarApp(res),
@@ -44,7 +47,7 @@ public final class NavigationAppFactory extends AbstractAppFactory {
public static boolean onMenuItemSelected(final MenuItem item,
final cgGeo geo, Activity activity, Resources res,
cgCache cache,
- Long searchId, cgWaypoint waypoint, ArrayList<Double> destination) {
+ final UUID searchId, cgWaypoint waypoint, List<Double> destination) {
NavigationApp app = (NavigationApp) getAppFromMenuItem(item, apps);
if (app != null) {
Double latitude = null;
diff --git a/src/cgeo/geocaching/apps/cache/navi/RMapsApp.java b/src/cgeo/geocaching/apps/cache/navi/RMapsApp.java
index 80802ac..8e75aaa 100644
--- a/src/cgeo/geocaching/apps/cache/navi/RMapsApp.java
+++ b/src/cgeo/geocaching/apps/cache/navi/RMapsApp.java
@@ -2,6 +2,7 @@ package cgeo.geocaching.apps.cache.navi;
import java.util.ArrayList;
import java.util.Locale;
+import java.util.UUID;
import android.app.Activity;
import android.content.Intent;
@@ -22,7 +23,7 @@ class RMapsApp extends AbstractNavigationApp implements NavigationApp {
@Override
public boolean invoke(cgGeo geo, Activity activity, Resources res,
cgCache cache,
- Long searchId, cgWaypoint waypoint, Double latitude, Double longitude) {
+ final UUID searchId, cgWaypoint waypoint, Double latitude, Double longitude) {
if (cache == null && waypoint == null && latitude == null
&& longitude == null) {
return false;
diff --git a/src/cgeo/geocaching/apps/cache/navi/RadarApp.java b/src/cgeo/geocaching/apps/cache/navi/RadarApp.java
index a4aec8c..7dc7676 100644
--- a/src/cgeo/geocaching/apps/cache/navi/RadarApp.java
+++ b/src/cgeo/geocaching/apps/cache/navi/RadarApp.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.apps.cache.navi;
+import java.util.UUID;
+
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
@@ -27,7 +29,7 @@ class RadarApp extends AbstractNavigationApp implements NavigationApp {
@Override
public boolean invoke(cgGeo geo, Activity activity, Resources res,
cgCache cache,
- Long searchId, cgWaypoint waypoint, Double latitude, Double longitude) {
+ final UUID searchId, cgWaypoint waypoint, Double latitude, Double longitude) {
if (cache != null) {
if (cache.latitude != null && cache.longitude != null) {
navigateTo(activity, cache.latitude, cache.longitude);
diff --git a/src/cgeo/geocaching/apps/cache/navi/StaticMapApp.java b/src/cgeo/geocaching/apps/cache/navi/StaticMapApp.java
index b6ae8c1..db6b27b 100644
--- a/src/cgeo/geocaching/apps/cache/navi/StaticMapApp.java
+++ b/src/cgeo/geocaching/apps/cache/navi/StaticMapApp.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.apps.cache.navi;
+import java.util.UUID;
+
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
@@ -26,7 +28,7 @@ class StaticMapApp extends AbstractNavigationApp implements
@Override
public boolean invoke(cgGeo geo, Activity activity, Resources res,
cgCache cache,
- Long searchId, cgWaypoint waypoint, Double latitude, Double longitude) {
+ final UUID searchId, cgWaypoint waypoint, Double latitude, Double longitude) {
if (cache == null || cache.reason == 0) {
ActivityMixin.showToast(activity, res.getString(R.string.err_detail_no_map_static));
diff --git a/src/cgeo/geocaching/apps/cache/navi/StreetviewApp.java b/src/cgeo/geocaching/apps/cache/navi/StreetviewApp.java
index 24d6606..250bc65 100644
--- a/src/cgeo/geocaching/apps/cache/navi/StreetviewApp.java
+++ b/src/cgeo/geocaching/apps/cache/navi/StreetviewApp.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.apps.cache.navi;
+import java.util.UUID;
+
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
@@ -25,7 +27,7 @@ class StreetviewApp extends AbstractNavigationApp implements NavigationApp {
public boolean invoke(cgGeo geo, Activity activity, Resources res,
cgCache cache,
- Long searchId, cgWaypoint waypoint, Double latitude, Double longitude) {
+ final UUID searchId, cgWaypoint waypoint, Double latitude, Double longitude) {
if (cache == null && waypoint == null && latitude == null && longitude == null) {
return false;
}
diff --git a/src/cgeo/geocaching/apps/cachelist/CacheListApp.java b/src/cgeo/geocaching/apps/cachelist/CacheListApp.java
index b58358c..74fba64 100644
--- a/src/cgeo/geocaching/apps/cachelist/CacheListApp.java
+++ b/src/cgeo/geocaching/apps/cachelist/CacheListApp.java
@@ -1,6 +1,7 @@
package cgeo.geocaching.apps.cachelist;
import java.util.List;
+import java.util.UUID;
import android.app.Activity;
import android.content.res.Resources;
@@ -12,6 +13,6 @@ interface CacheListApp extends App {
boolean invoke(final cgGeo geo, final List<cgCache> caches,
final Activity activity, final Resources res,
- final Long searchId);
+ final UUID searchId);
}
diff --git a/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java b/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java
index 416388d..cb69e17 100644
--- a/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java
+++ b/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java
@@ -2,6 +2,9 @@ package cgeo.geocaching.apps.cachelist;
import java.util.ArrayList;
import java.util.List;
+import java.util.UUID;
+
+import org.apache.commons.lang3.ArrayUtils;
import android.app.Activity;
import android.content.res.Resources;
@@ -20,7 +23,7 @@ public final class CacheListAppFactory extends AbstractAppFactory {
private static CacheListApp[] getMultiPointNavigationApps(
Resources res) {
- if (null == apps || 0 == apps.length) {
+ if (ArrayUtils.isEmpty(apps)) {
apps = new CacheListApp[] {
new InternalCacheListMap(res),
new LocusCacheListApp(res) };
@@ -36,7 +39,7 @@ public final class CacheListAppFactory extends AbstractAppFactory {
*/
public static MenuItem addMenuItems(Menu menu,
Activity activity, Resources res) {
- ArrayList<CacheListApp> activeApps = new ArrayList<CacheListApp>();
+ List<CacheListApp> activeApps = new ArrayList<CacheListApp>();
for (CacheListApp app : getMultiPointNavigationApps(res)) {
if (app.isInstalled(activity)) {
activeApps.add(app);
@@ -60,7 +63,7 @@ public final class CacheListAppFactory extends AbstractAppFactory {
public static boolean onMenuItemSelected(final MenuItem item,
final cgGeo geo, final List<cgCache> caches, final Activity activity, final Resources res,
- final Long searchId) {
+ final UUID searchId) {
CacheListApp app = (CacheListApp) getAppFromMenuItem(
item, apps);
if (app != null) {
diff --git a/src/cgeo/geocaching/apps/cachelist/InternalCacheListMap.java b/src/cgeo/geocaching/apps/cachelist/InternalCacheListMap.java
index 8576aab..2fd418e 100644
--- a/src/cgeo/geocaching/apps/cachelist/InternalCacheListMap.java
+++ b/src/cgeo/geocaching/apps/cachelist/InternalCacheListMap.java
@@ -1,6 +1,7 @@
package cgeo.geocaching.apps.cachelist;
import java.util.List;
+import java.util.UUID;
import android.app.Activity;
import android.content.Context;
@@ -23,11 +24,11 @@ class InternalCacheListMap extends AbstractApp implements CacheListApp {
}
@Override
- public boolean invoke(cgGeo geo, List<cgCache> caches, Activity activity, Resources res, Long searchId) {
+ public boolean invoke(cgGeo geo, List<cgCache> caches, Activity activity, Resources res, final UUID searchId) {
Intent mapIntent = new Intent(activity, getSettings(activity).getMapFactory()
.getMapClass());
mapIntent.putExtra("detail", false); // this is the main difference to the activity for a single point
- mapIntent.putExtra("searchid", searchId);
+ mapIntent.putExtra("searchid", searchId.toString());
activity.startActivity(mapIntent);
return true;
diff --git a/src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java b/src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java
index 9c14d48..3ca3653 100644
--- a/src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java
+++ b/src/cgeo/geocaching/apps/cachelist/LocusCacheListApp.java
@@ -1,6 +1,9 @@
package cgeo.geocaching.apps.cachelist;
import java.util.List;
+import java.util.UUID;
+
+import org.apache.commons.lang3.StringUtils;
import android.app.Activity;
import android.content.res.Resources;
@@ -22,7 +25,7 @@ class LocusCacheListApp extends AbstractLocusApp implements CacheListApp {
*/
@Override
public boolean invoke(cgGeo geo, List<cgCache> cacheList, Activity activity, Resources res,
- final Long searchId) {
+ final UUID searchId) {
if (cacheList == null || cacheList.isEmpty()) return false;
this.showInLocus((List<? extends Object>) cacheList, activity);
diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java
index 7e52d00..1287f79 100644
--- a/src/cgeo/geocaching/cgBase.java
+++ b/src/cgeo/geocaching/cgBase.java
@@ -27,10 +27,12 @@ import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
@@ -46,6 +48,8 @@ import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
@@ -67,6 +71,7 @@ import android.util.Log;
import android.widget.EditText;
import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.files.LocParser;
+import cgeo.geocaching.utils.CollectionUtils;
public class cgBase {
@@ -122,18 +127,18 @@ public class cgBase {
private final static Pattern PATTERN_TRACKABLE_Distance = Pattern.compile("<h4[^>]*\\W*Tracking History \\(([0-9\\.,]+(km|mi))[^\\)]*\\)", Pattern.CASE_INSENSITIVE);
private final static Pattern PATTERN_TRACKABLE_Log = Pattern.compile("<tr class=\"Data.+?src=\"/images/icons/([^\\.]+)\\.gif[^>]+>&nbsp;([^<]+)</td>.+?guid.+?>([^<]+)</a>.+?(?:guid=([^\"]+)\">([^<]+)</a>.+?)?<td colspan=\"4\">(.+?)(?:<ul.+?ul>)?\\s*</td>\\s*</tr>", Pattern.CASE_INSENSITIVE);
- public static HashMap<String, String> cacheTypes = new HashMap<String, String>();
- public static HashMap<String, String> cacheTypesInv = new HashMap<String, String>();
- public static HashMap<String, String> cacheIDs = new HashMap<String, String>();
- public static HashMap<String, String> cacheIDsChoices = new HashMap<String, String>();
- public static HashMap<String, String> waypointTypes = new HashMap<String, String>();
- public static HashMap<String, Integer> logTypes = new HashMap<String, Integer>();
- public static HashMap<String, Integer> logTypes0 = new HashMap<String, Integer>();
- public static HashMap<Integer, String> logTypes1 = new HashMap<Integer, String>();
- public static HashMap<Integer, String> logTypes2 = new HashMap<Integer, String>();
- public static HashMap<Integer, String> logTypesTrackable = new HashMap<Integer, String>();
- public static HashMap<Integer, String> logTypesTrackableAction = new HashMap<Integer, String>();
- public static HashMap<Integer, String> errorRetrieve = new HashMap<Integer, String>();
+ public static Map<String, String> cacheTypes = new HashMap<String, String>();
+ public static Map<String, String> cacheTypesInv = new HashMap<String, String>();
+ public static Map<String, String> cacheIDs = new HashMap<String, String>();
+ public static Map<String, String> cacheIDsChoices = new HashMap<String, String>();
+ public static Map<String, String> waypointTypes = new HashMap<String, String>();
+ public static Map<String, Integer> logTypes = new HashMap<String, Integer>();
+ public static Map<String, Integer> logTypes0 = new HashMap<String, Integer>();
+ public static Map<Integer, String> logTypes1 = new HashMap<Integer, String>();
+ public static Map<Integer, String> logTypes2 = new HashMap<Integer, String>();
+ public static Map<Integer, String> logTypesTrackable = new HashMap<Integer, String>();
+ public static Map<Integer, String> logTypesTrackableAction = new HashMap<Integer, String>();
+ public static Map<Integer, String> errorRetrieve = new HashMap<Integer, String>();
public static final Map<String, SimpleDateFormat> gcCustomDateFormats;
static {
final String[] formats = new String[] {
@@ -146,7 +151,7 @@ public class cgBase {
"dd/MM/yyyy"
};
- HashMap<String, SimpleDateFormat> map = new HashMap<String, SimpleDateFormat>();
+ Map<String, SimpleDateFormat> map = new HashMap<String, SimpleDateFormat>();
for (String format : formats)
{
@@ -159,7 +164,7 @@ public class cgBase {
public final static SimpleDateFormat dateTbIn2 = new SimpleDateFormat("EEEEE, MMMMM dd, yyyy", Locale.ENGLISH); // Saturday, March 28, 2009
public final static SimpleDateFormat dateSqlIn = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 2010-07-25 14:44:01
private Resources res = null;
- private HashMap<String, String> cookies = new HashMap<String, String>();
+ private Map<String, String> cookies = new HashMap<String, String>();
private static final String passMatch = "[/\\?&]*[Pp]ass(word)?=[^&^#^$]+";
private static final Pattern patternLoggedIn = Pattern.compile("<span class=\"Success\">You are logged in as[^<]*<strong[^>]*>([^<]+)</strong>[^<]*</span>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
private static final Pattern patternLogged2In = Pattern.compile("<strong>\\W*Hello,[^<]*<a[^>]+>([^<]+)</a>[^<]*</strong>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
@@ -176,8 +181,8 @@ public class cgBase {
public String version = null;
private String idBrowser = "Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.86 Safari/533.4";
Context context = null;
- final private static HashMap<String, Integer> gcIcons = new HashMap<String, Integer>();
- final private static HashMap<String, Integer> wpIcons = new HashMap<String, Integer>();
+ final private static Map<String, Integer> gcIcons = new HashMap<String, Integer>();
+ final private static Map<String, Integer> wpIcons = new HashMap<String, Integer>();
public static final int LOG_FOUND_IT = 2;
public static final int LOG_DIDNT_FIND_IT = 3;
@@ -460,8 +465,8 @@ public class cgBase {
/**
* put viewstates into request parameters
*/
- private static void setViewstates(String[] viewstates, HashMap<String, String> params) {
- if (viewstates == null || viewstates.length == 0)
+ private static void setViewstates(String[] viewstates, Map<String, String> params) {
+ if (ArrayUtils.isEmpty(viewstates))
return;
params.put("__VIEWSTATE", viewstates[0]);
if (viewstates.length > 1) {
@@ -475,25 +480,10 @@ public class cgBase {
* transfers the viewstates variables from a page (response) to parameters
* (next request)
*/
- public static void transferViewstates(String page, HashMap<String, String> params) {
+ public static void transferViewstates(String page, Map<String, String> params) {
setViewstates(getViewstates(page), params);
}
- /**
- * checks if an Array of Strings is empty or not. Empty means:
- * - Array is null
- * - or all elements are null or empty strings
- */
- public static boolean isEmpty(String[] a) {
- if (a == null)
- return true;
-
- for (String s: a)
- if (s != null && s.length() > 0)
- return false;
-
- return true;
- }
public class loginThread extends Thread {
@@ -511,7 +501,7 @@ public class cgBase {
String[] viewstates = null;
- final HashMap<String, String> loginStart = settings.getLogin();
+ final Map<String, String> loginStart = settings.getLogin();
if (loginStart == null) {
return -3; // no login information stored
@@ -519,7 +509,7 @@ public class cgBase {
loginResponse = request(true, host, path, "GET", new HashMap<String, String>(), false, false, false);
loginData = loginResponse.getData();
- if (loginData != null && loginData.length() > 0) {
+ if (StringUtils.isNotBlank(loginData)) {
if (checkLogin(loginData)) {
Log.i(cgSettings.tag, "Already logged in Geocaching.com as " + loginStart.get("username"));
@@ -530,7 +520,7 @@ public class cgBase {
viewstates = getViewstates(loginData);
- if (isEmpty(viewstates)) {
+ if (ArrayUtils.isEmpty(viewstates)) {
Log.e(cgSettings.tag, "cgeoBase.login: Failed to find viewstates");
return -1; // no viewstates
}
@@ -539,10 +529,10 @@ public class cgBase {
return -2; // no loginpage
}
- final HashMap<String, String> login = settings.getLogin();
- final HashMap<String, String> params = new HashMap<String, String>();
+ final Map<String, String> login = settings.getLogin();
+ final Map<String, String> params = new HashMap<String, String>();
- if (login == null || login.get("username") == null || login.get("username").length() == 0 || login.get("password") == null || login.get("password").length() == 0) {
+ if (login == null || StringUtils.isEmpty(login.get("username")) || StringUtils.isEmpty(login.get("password"))) {
Log.e(cgSettings.tag, "cgeoBase.login: No login information stored");
return -3;
}
@@ -560,7 +550,7 @@ public class cgBase {
loginResponse = request(true, host, path, "POST", params, false, false, false);
loginData = loginResponse.getData();
- if (loginData != null && loginData.length() > 0) {
+ if (StringUtils.isNotBlank(loginData)) {
if (checkLogin(loginData)) {
Log.i(cgSettings.tag, "Successfully logged in Geocaching.com as " + login.get("username"));
@@ -595,7 +585,7 @@ public class cgBase {
}
public static Boolean checkLogin(String page) {
- if (page == null || page.length() == 0) {
+ if (StringUtils.isBlank(page)) {
Log.e(cgSettings.tag, "cgeoBase.checkLogin: No page given");
return false;
}
@@ -618,7 +608,7 @@ public class cgBase {
public String switchToEnglish(String[] viewstates) {
final String host = "www.geocaching.com";
final String path = "/default.aspx";
- final HashMap<String, String> params = new HashMap<String, String>();
+ final Map<String, String> params = new HashMap<String, String>();
setViewstates(viewstates, params);
params.put("__EVENTTARGET", "ctl00$uxLocaleList$uxLocaleList$ctl00$uxLocaleItem"); // switch to english
@@ -628,14 +618,14 @@ public class cgBase {
}
public cgCacheWrap parseSearch(cgSearchThread thread, String url, String page, boolean showCaptcha) {
- if (page == null || page.length() == 0) {
+ if (StringUtils.isBlank(page)) {
Log.e(cgSettings.tag, "cgeoBase.parseSearch: No page given");
return null;
}
final cgCacheWrap caches = new cgCacheWrap();
- final ArrayList<String> cids = new ArrayList<String>();
- final ArrayList<String> guids = new ArrayList<String>();
+ final List<String> cids = new ArrayList<String>();
+ final List<String> guids = new ArrayList<String>();
String recaptchaChallenge = null;
String recaptchaText = null;
@@ -669,7 +659,7 @@ public class cgBase {
if (recaptchaJsParam != null) {
final String recaptchaJs = request(false, "www.google.com", "/recaptcha/api/challenge", "GET", "k=" + urlencode_rfc3986(recaptchaJsParam.trim()), 0, true).getData();
- if (recaptchaJs != null && recaptchaJs.length() > 0) {
+ if (StringUtils.isNotBlank(recaptchaJs)) {
final Matcher matcherRecaptchaChallenge = patternRecaptchaChallenge.matcher(recaptchaJs);
while (matcherRecaptchaChallenge.find()) {
if (matcherRecaptchaChallenge.groupCount() > 0) {
@@ -683,7 +673,7 @@ public class cgBase {
Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse recaptcha challenge");
}
- if (thread != null && recaptchaChallenge != null && recaptchaChallenge.length() > 0) {
+ if (thread != null && StringUtils.isNotBlank(recaptchaChallenge)) {
thread.setChallenge(recaptchaChallenge);
thread.notifyNeed();
}
@@ -821,7 +811,7 @@ public class cgBase {
Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse cache inventory (1)");
}
- if (inventoryPre != null && inventoryPre.trim().length() > 0) {
+ if (StringUtils.isNotBlank(inventoryPre)) {
try {
final Matcher matcherTbsInside = patternTbsInside.matcher(inventoryPre);
while (matcherTbsInside.find()) {
@@ -923,7 +913,7 @@ public class cgBase {
recaptchaText = thread.getText();
}
- if (cids.size() > 0 && (recaptchaChallenge == null || (recaptchaChallenge != null && recaptchaText != null && recaptchaText.length() > 0))) {
+ if (cids.size() > 0 && (recaptchaChallenge == null || (recaptchaChallenge != null && StringUtils.isNotBlank(recaptchaText)))) {
Log.i(cgSettings.tag, "Trying to get .loc for " + cids.size() + " caches");
try {
@@ -932,7 +922,7 @@ public class cgBase {
final String path = "/seek/nearest.aspx";
final StringBuilder params = new StringBuilder();
params.append("__EVENTTARGET=&__EVENTARGUMENT=");
- if (caches.viewstates != null && caches.viewstates.length > 0) {
+ if (ArrayUtils.isNotEmpty(caches.viewstates)) {
params.append("&__VIEWSTATE=");
params.append(urlencode_rfc3986(caches.viewstates[0]));
if (caches.viewstates.length > 1) {
@@ -948,7 +938,7 @@ public class cgBase {
params.append(urlencode_rfc3986(cid));
}
- if (recaptchaChallenge != null && recaptchaText != null && recaptchaText.length() > 0) {
+ if (recaptchaChallenge != null && StringUtils.isNotBlank(recaptchaText)) {
params.append("&recaptcha_challenge_field=");
params.append(urlencode_rfc3986(recaptchaChallenge));
params.append("&recaptcha_response_field=");
@@ -958,7 +948,7 @@ public class cgBase {
final String coordinates = request(false, host, path, "POST", params.toString(), 0, true).getData();
- if (coordinates != null && coordinates.length() > 0) {
+ if ( StringUtils.isNotBlank(coordinates)) {
if (coordinates.indexOf("You have not agreed to the license agreement. The license agreement is required before you can start downloading GPX or LOC files from Geocaching.com") > -1) {
Log.i(cgSettings.tag, "User has not agreed to the license agreement. Can\'t download .loc file.");
@@ -989,9 +979,9 @@ public class cgBase {
Log.i(cgSettings.tag, "Trying to get ratings for " + cids.size() + " caches");
try {
- final HashMap<String, cgRating> ratings = getRating(guids, null);
+ final Map<String, cgRating> ratings = getRating(guids, null);
- if (ratings != null) {
+ if (CollectionUtils.isNotEmpty(ratings)) {
// save found cache coordinates
for (cgCache oneCache : caches.cacheList) {
if (ratings.containsKey(oneCache.guid)) {
@@ -1012,7 +1002,7 @@ public class cgBase {
}
public static cgCacheWrap parseMapJSON(String url, String data) {
- if (data == null || data.length() == 0) {
+ if (StringUtils.isEmpty(data)) {
Log.e(cgSettings.tag, "cgeoBase.parseMapJSON: No page given");
return null;
}
@@ -1024,14 +1014,14 @@ public class cgBase {
final JSONObject yoDawg = new JSONObject(data);
final String json = yoDawg.getString("d");
- if (json == null || json.length() == 0) {
+ if (StringUtils.isBlank(json)) {
Log.e(cgSettings.tag, "cgeoBase.parseMapJSON: No JSON inside JSON");
return null;
}
final JSONObject dataJSON = new JSONObject(json);
final JSONObject extra = dataJSON.getJSONObject("cs");
- if (extra != null && extra.length() > 0) {
+ if ( StringUtils.isNotBlank(data)) {
int count = extra.getInt("count");
if (count > 0 && extra.has("cc")) {
@@ -1096,7 +1086,7 @@ public class cgBase {
}
public cgCacheWrap parseCache(String page, int reason) {
- if (page == null || page.length() == 0) {
+ if (StringUtils.isBlank(page)) {
Log.e(cgSettings.tag, "cgeoBase.parseCache: No page given");
return null;
}
@@ -1218,7 +1208,7 @@ public class cgBase {
tableInside = tableInside.substring(0, pos);
- if (tableInside != null && tableInside.length() > 0) {
+ if (StringUtils.isNotBlank(tableInside)) {
// cache terrain
try {
final Matcher matcherTerrain = patternTerrain.matcher(tableInside);
@@ -1341,7 +1331,7 @@ public class cgBase {
if (matcherLatLon.find() && matcherLatLon.groupCount() > 0) {
cache.latlon = getMatch(matcherLatLon.group(2)); // first is <b>
- HashMap<String, Object> tmp = cgBase.parseLatlon(cache.latlon);
+ Map<String, Object> tmp = cgBase.parseLatlon(cache.latlon);
if (tmp.size() > 0) {
cache.latitude = (Double) tmp.get("latitude");
cache.longitude = (Double) tmp.get("longitude");
@@ -1518,7 +1508,7 @@ public class cgBase {
if (matcherInventory.groupCount() > 1) {
final String inventoryPre = matcherInventory.group(2);
- if (inventoryPre != null && inventoryPre.length() > 0) {
+ if (StringUtils.isNotBlank(inventoryPre)) {
final Matcher matcherInventoryInside = patternInventoryInside.matcher(inventoryPre);
while (matcherInventoryInside.find()) {
@@ -1553,11 +1543,9 @@ public class cgBase {
String typeStr = matcherLog.group(1);
String countStr = matcherLog.group(2);
- if (typeStr != null
- && typeStr.length() > 0
+ if (StringUtils.isNotBlank(typeStr)
&& logTypes.containsKey(typeStr.toLowerCase())
- && countStr != null
- && countStr.length() > 0)
+ && StringUtils.isNotBlank(countStr))
{
cache.logCounts.put(logTypes.get(typeStr.toLowerCase()), Integer.parseInt(countStr));
}
@@ -1713,8 +1701,16 @@ public class cgBase {
// waypoint name
try {
final Matcher matcherWpName = patternWpName.matcher(wp[6]);
+ while (matcherWpName.find()) {
+ if (matcherWpName.groupCount() > 0) {
+ waypoint.name = matcherWpName.group(1);
+ if (StringUtils.isNotBlank(waypoint.name)) {
+ waypoint.name = waypoint.name.trim();
+ }
+ }
if (matcherWpName.find() && matcherWpName.groupCount() > 0) {
waypoint.name = matcherWpName.group(1).trim();
+ }
}
} catch (Exception e) {
// failed to parse name
@@ -1727,7 +1723,7 @@ public class cgBase {
if (matcherWpLatLon.find() && matcherWpLatLon.groupCount() > 1) {
waypoint.latlon = Html.fromHtml(matcherWpLatLon.group(2)).toString();
- final HashMap<String, Object> tmp = cgBase.parseLatlon(waypoint.latlon);
+ final Map<String, Object> tmp = cgBase.parseLatlon(waypoint.latlon);
if (tmp.size() > 0) {
waypoint.latitude = (Double) tmp.get("latitude");
waypoint.longitude = (Double) tmp.get("longitude");
@@ -1784,13 +1780,13 @@ public class cgBase {
}
private static void checkFields(cgCache cache) {
- if (cache.geocode == null || cache.geocode.length() == 0) {
+ if (StringUtils.isEmpty(cache.geocode)) {
Log.w(cgSettings.tag, "geo code not parsed correctly");
}
- if (cache.name == null || cache.name.length() == 0) {
+ if (StringUtils.isEmpty(cache.name)) {
Log.w(cgSettings.tag, "name not parsed correctly");
}
- if (cache.guid == null || cache.guid.length() == 0) {
+ if (StringUtils.isEmpty(cache.guid)) {
Log.w(cgSettings.tag, "guid not parsed correctly");
}
if (cache.terrain == null || cache.terrain == 0.0) {
@@ -1799,10 +1795,10 @@ public class cgBase {
if (cache.difficulty == null || cache.difficulty == 0.0) {
Log.w(cgSettings.tag, "difficulty not parsed correctly");
}
- if (cache.owner == null || cache.owner.length() == 0) {
+ if (StringUtils.isEmpty(cache.owner)) {
Log.w(cgSettings.tag, "owner not parsed correctly");
}
- if (cache.ownerReal == null || cache.ownerReal.length() == 0) {
+ if (StringUtils.isEmpty(cache.ownerReal)) {
Log.w(cgSettings.tag, "owner real not parsed correctly");
}
if (cache.hidden == null) {
@@ -1811,10 +1807,10 @@ public class cgBase {
if (cache.favouriteCnt == null) {
Log.w(cgSettings.tag, "favoriteCount not parsed correctly");
}
- if (cache.size == null || cache.size.length() == 0) {
+ if (StringUtils.isEmpty(cache.size)) {
Log.w(cgSettings.tag, "size not parsed correctly");
}
- if (cache.type == null || cache.type.length() == 0) {
+ if (StringUtils.isNotBlank(cache.type)) {
Log.w(cgSettings.tag, "type not parsed correctly");
}
if (cache.latitude == null) {
@@ -1823,7 +1819,7 @@ public class cgBase {
if (cache.longitude == null) {
Log.w(cgSettings.tag, "longitude not parsed correctly");
}
- if (cache.location == null || cache.location.length() == 0) {
+ if (StringUtils.isEmpty(cache.location)) {
Log.w(cgSettings.tag, "location not parsed correctly");
}
}
@@ -1841,7 +1837,7 @@ public class cgBase {
public Date parseGcCustomDate(String input)
throws ParseException
{
- if (input == null)
+ if (StringUtils.isBlank(input))
{
throw new ParseException("Input is null", 0);
}
@@ -1888,20 +1884,20 @@ public class cgBase {
}
public cgRating getRating(String guid, String geocode) {
- ArrayList<String> guids = null;
- ArrayList<String> geocodes = null;
+ List<String> guids = null;
+ List<String> geocodes = null;
- if (guid != null && guid.length() > 0) {
+ if (StringUtils.isNotBlank(guid)) {
guids = new ArrayList<String>();
guids.add(guid);
- } else if (geocode != null && geocode.length() > 0) {
+ } else if (StringUtils.isNotBlank(geocode)) {
geocodes = new ArrayList<String>();
geocodes.add(geocode);
} else {
return null;
}
- final HashMap<String, cgRating> ratings = getRating(guids, geocodes);
+ final Map<String, cgRating> ratings = getRating(guids, geocodes);
if(ratings != null){
for (Entry<String, cgRating> entry : ratings.entrySet()) {
return entry.getValue();
@@ -1911,23 +1907,23 @@ public class cgBase {
return null;
}
- public HashMap<String, cgRating> getRating(ArrayList<String> guids, ArrayList<String> geocodes) {
+ public Map<String, cgRating> getRating(List<String> guids, List<String> geocodes) {
if (guids == null && geocodes == null) {
return null;
}
- final HashMap<String, cgRating> ratings = new HashMap<String, cgRating>();
+ final Map<String, cgRating> ratings = new HashMap<String, cgRating>();
try {
- final HashMap<String, String> params = new HashMap<String, String>();
+ final Map<String, String> params = new HashMap<String, String>();
if (settings.isLogin()) {
- final HashMap<String, String> login = settings.getGCvoteLogin();
+ final Map<String, String> login = settings.getGCvoteLogin();
if (login != null) {
params.put("userName", login.get("username"));
params.put("password", login.get("password"));
}
}
- if (guids != null && guids.size() > 0) {
+ if (CollectionUtils.isNotEmpty(guids)) {
params.put("cacheIds", implode(",", guids.toArray()));
} else {
params.put("waypoints", implode(",", geocodes.toArray()));
@@ -2019,7 +2015,7 @@ public class cgBase {
}
}
- if (guid != null) {
+ if (StringUtils.isNotBlank(guid)) {
ratings.put(guid, rating);
}
}
@@ -2031,7 +2027,7 @@ public class cgBase {
}
public cgTrackable parseTrackable(String page) {
- if (page == null || page.length() == 0) {
+ if (StringUtils.isBlank(page)) {
Log.e(cgSettings.tag, "cgeoBase.parseTrackable: No page given");
return null;
}
@@ -2083,7 +2079,7 @@ public class cgBase {
}
// trackable type
- if (trackable.name != null && trackable.name.length() > 0) {
+ if (StringUtils.isNotBlank(trackable.name)) {
try {
final Matcher matcherType = PATTERN_TRACKABLE_Type.matcher(page);
if (matcherType.find() && matcherType.groupCount() > 0) {
@@ -2267,12 +2263,12 @@ public class cgBase {
return trackable;
}
- public static ArrayList<Integer> parseTypes(String page) {
- if (page == null || page.length() == 0) {
+ public static List<Integer> parseTypes(String page) {
+ if (StringUtils.isEmpty(page)) {
return null;
}
- final ArrayList<Integer> types = new ArrayList<Integer>();
+ final List<Integer> types = new ArrayList<Integer>();
final Pattern typeBoxPattern = Pattern.compile("<select name=\"ctl00\\$ContentBody\\$LogBookPanel1\\$ddLogType\" id=\"ctl00_ContentBody_LogBookPanel1_ddLogType\"[^>]*>"
+ "(([^<]*<option[^>]*>[^<]+</option>)+)[^<]*</select>", Pattern.CASE_INSENSITIVE);
@@ -2301,12 +2297,12 @@ public class cgBase {
return types;
}
- public static ArrayList<cgTrackableLog> parseTrackableLog(String page) {
- if (page == null || page.length() == 0) {
+ public static List<cgTrackableLog> parseTrackableLog(String page) {
+ if (StringUtils.isEmpty(page)) {
return null;
}
- final ArrayList<cgTrackableLog> trackables = new ArrayList<cgTrackableLog>();
+ final List<cgTrackableLog> trackables = new ArrayList<cgTrackableLog>();
int startPos = -1;
int endPos = -1;
@@ -2384,7 +2380,7 @@ public class cgBase {
}
public static String stripParagraphs(String text) {
- if (text == null) {
+ if (StringUtils.isBlank(text)) {
return "";
}
@@ -2400,7 +2396,7 @@ public class cgBase {
}
public static String stripTags(String text) {
- if (text == null) {
+ if (StringUtils.isBlank(text)) {
return "";
}
@@ -2412,28 +2408,6 @@ public class cgBase {
return text.trim();
}
- public static String capitalizeSentence(String sentence) {
- if (sentence == null) {
- return "";
- }
-
- final String[] word = sentence.split(" ");
-
- for (int i = 0; i < word.length; i++) {
- word[i] = capitalizeWord(word[i]);
- }
-
- return implode(" ", word);
- }
-
- public static String capitalizeWord(String word) {
- if (word.length() == 0) {
- return word;
- }
-
- return (word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase());
- }
-
public static Double parseDistance(String dst) {
Double distance = null;
@@ -2515,7 +2489,7 @@ public class cgBase {
return result;
}
- public static HashMap<String, Double> getRadialDistance(Double latitude, Double longitude, Double bearing, Double distance) {
+ public static Map<String, Double> getRadialDistance(Double latitude, Double longitude, Double bearing, Double distance) {
final Double rlat1 = latitude * deg2rad;
final Double rlon1 = longitude * deg2rad;
final Double rbearing = bearing * deg2rad;
@@ -2524,7 +2498,7 @@ public class cgBase {
final Double rlat = Math.asin(Math.sin(rlat1) * Math.cos(rdistance) + Math.cos(rlat1) * Math.sin(rdistance) * Math.cos(rbearing));
final Double rlon = rlon1 + Math.atan2(Math.sin(rbearing) * Math.sin(rdistance) * Math.cos(rlat1), Math.cos(rdistance) - Math.sin(rlat1) * Math.sin(rlat));
- HashMap<String, Double> result = new HashMap<String, Double>();
+ Map<String, Double> result = new HashMap<String, Double>();
result.put("latitude", rlat * rad2deg);
result.put("longitude", rlon * rad2deg);
@@ -2592,8 +2566,8 @@ public class cgBase {
}
}
- public static HashMap<String, Object> parseLatlon(String latlon) {
- final HashMap<String, Object> result = new HashMap<String, Object>();
+ public static Map<String, Object> parseLatlon(String latlon) {
+ final Map<String, Object> result = new HashMap<String, Object>();
final Pattern patternLatlon = Pattern.compile("([NS])[^\\d]*(\\d+)[^°]*° (\\d+)\\.(\\d+) ([WE])[^\\d]*(\\d+)[^°]*° (\\d+)\\.(\\d+)", Pattern.CASE_INSENSITIVE);
final Matcher matcherLatlon = patternLatlon.matcher(latlon);
@@ -2653,8 +2627,8 @@ public class cgBase {
return formatLatitude(latitude, degrees) + " | " + formatLongitude(longitude, degrees);
}
- public static HashMap<String, Object> parseCoordinate(String coord, String latlon) {
- final HashMap<String, Object> coords = new HashMap<String, Object>();
+ public static Map<String, Object> parseCoordinate(String coord, String latlon) {
+ final Map<String, Object> coords = new HashMap<String, Object>();
final Pattern patternA = Pattern.compile("^([NSWE])[^\\d]*(\\d+)°? +(\\d+)([\\.|,](\\d+))?$", Pattern.CASE_INSENSITIVE);
final Pattern patternB = Pattern.compile("^([NSWE])[^\\d]*(\\d+)([\\.|,](\\d+))?$", Pattern.CASE_INSENSITIVE);
@@ -2764,17 +2738,17 @@ public class cgBase {
}
}
- public Long searchByNextPage(cgSearchThread thread, Long searchId, int reason, boolean showCaptcha) {
+ public UUID searchByNextPage(cgSearchThread thread, final UUID searchId, int reason, boolean showCaptcha) {
final String[] viewstates = app.getViewstates(searchId);
cgCacheWrap caches = new cgCacheWrap();
String url = app.getUrl(searchId);
- if (url == null || url.length() == 0) {
+ if (StringUtils.isBlank(url)) {
Log.e(cgSettings.tag, "cgeoBase.searchByNextPage: No url found");
return searchId;
}
- if (isEmpty(viewstates)) {
+ if (ArrayUtils.isEmpty(viewstates)) {
Log.e(cgSettings.tag, "cgeoBase.searchByNextPage: No viewstate given");
return searchId;
}
@@ -2804,7 +2778,7 @@ public class cgBase {
path = url;
}
- final HashMap<String, String> params = new HashMap<String, String>();
+ final Map<String, String> params = new HashMap<String, String>();
setViewstates(viewstates, params);
params.put("__EVENTTARGET", "ctl00$ContentBody$pgrBottom$ctl08");
params.put("__EVENTARGUMENT", "");
@@ -2823,7 +2797,7 @@ public class cgBase {
}
}
- if (page == null || page.length() == 0) {
+ if (StringUtils.isBlank(page)) {
Log.e(cgSettings.tag, "cgeoBase.searchByNextPage: No data from server");
return searchId;
}
@@ -2838,7 +2812,7 @@ public class cgBase {
app.setError(searchId, caches.error);
app.setViewstates(searchId, caches.viewstates);
- final ArrayList<cgCache> cacheList = new ArrayList<cgCache>();
+ final List<cgCache> cacheList = new ArrayList<cgCache>();
for (cgCache cache : caches.cacheList) {
app.addGeocode(searchId, cache.geocode);
cacheList.add(cache);
@@ -2849,22 +2823,22 @@ public class cgBase {
return searchId;
}
- public Long searchByGeocode(HashMap<String, String> parameters, int reason, boolean forceReload) {
+ public UUID searchByGeocode(Map<String, String> parameters, int reason, boolean forceReload) {
final cgSearch search = new cgSearch();
String geocode = parameters.get("geocode");
String guid = parameters.get("guid");
- if ((geocode == null || geocode.length() == 0) && ((guid == null || guid.length() == 0))) {
+ if (StringUtils.isBlank(geocode) && StringUtils.isBlank(guid)) {
Log.e(cgSettings.tag, "cgeoBase.searchByGeocode: No geocode nor guid given");
return null;
}
if (forceReload == false && reason == 0 && (app.isOffline(geocode, guid) || app.isThere(geocode, guid, true, true))) {
- if ((geocode == null || geocode.length() == 0) && guid != null && guid.length() > 0) {
+ if (StringUtils.isBlank(geocode) && StringUtils.isBlank(guid)) {
geocode = app.getGeocode(guid);
}
- ArrayList<cgCache> cacheList = new ArrayList<cgCache>();
+ List<cgCache> cacheList = new ArrayList<cgCache>();
cacheList.add(app.getCacheByGeocode(geocode, true, true, true, true, true, true));
search.addGeocode(geocode);
@@ -2879,10 +2853,10 @@ public class cgBase {
final String host = "www.geocaching.com";
final String path = "/seek/cache_details.aspx";
final String method = "GET";
- final HashMap<String, String> params = new HashMap<String, String>();
- if (geocode != null && geocode.length() > 0) {
+ final Map<String, String> params = new HashMap<String, String>();
+ if (StringUtils.isNotBlank(geocode)) {
params.put("wp", geocode);
- } else if (guid != null && guid.length() > 0) {
+ } else if (StringUtils.isNotBlank(guid)) {
params.put("guid", guid);
}
params.put("decrypt", "y");
@@ -2891,19 +2865,18 @@ public class cgBase {
String page = requestLogged(false, host, path, method, params, false, false, false);
- if (page == null || page.length() == 0) {
+ if (StringUtils.isEmpty(page)) {
if (app.isThere(geocode, guid, true, false)) {
- if ((geocode == null || geocode.length() == 0) && guid != null && guid.length() > 0) {
+ if (StringUtils.isBlank(geocode) && StringUtils.isBlank(guid)) {
Log.i(cgSettings.tag, "Loading old cache from cache.");
geocode = app.getGeocode(guid);
}
- final ArrayList<cgCache> cacheList = new ArrayList<cgCache>();
+ final List<cgCache> cacheList = new ArrayList<cgCache>();
cacheList.add(app.getCacheByGeocode(geocode));
search.addGeocode(geocode);
search.error = null;
- search.errorRetrieve = 0; // reset errors from previous failed request
app.addSearch(search, cacheList, false, reason);
@@ -2918,10 +2891,10 @@ public class cgBase {
final cgCacheWrap caches = parseCache(page, reason);
if (caches == null || caches.cacheList == null || caches.cacheList.isEmpty()) {
- if (caches != null && caches.error != null && caches.error.length() > 0) {
+ if (caches != null && StringUtils.isNotBlank(caches.error)) {
search.error = caches.error;
}
- if (caches != null && caches.url != null && caches.url.length() > 0) {
+ if (caches != null && StringUtils.isNotBlank(caches.url)) {
search.url = caches.url;
}
@@ -2936,22 +2909,7 @@ public class cgBase {
return null;
}
- final ArrayList<cgCache> cacheList = new ArrayList<cgCache>();
- if (caches != null) {
- if (caches.error != null && caches.error.length() > 0) {
- search.error = caches.error;
- }
- if (caches.url != null && caches.url.length() > 0) {
- search.url = caches.url;
- }
- search.viewstates = caches.viewstates;
- search.totalCnt = caches.totalCnt;
-
- for (cgCache cache : caches.cacheList) {
- search.addGeocode(cache.geocode);
- cacheList.add(cache);
- }
- }
+ List<cgCache> cacheList = processSearchResults(search, caches, 0, 0, null);
app.addSearch(search, cacheList, true, reason);
@@ -2961,7 +2919,7 @@ public class cgBase {
return search.getCurrentId();
}
- public Long searchByOffline(HashMap<String, Object> parameters) {
+ public UUID searchByOffline(Map<String, Object> parameters) {
if (app == null) {
Log.e(cgSettings.tag, "cgeoBase.searchByOffline: No application found");
return null;
@@ -2991,7 +2949,7 @@ public class cgBase {
return search.getCurrentId();
}
- public Long searchByHistory(HashMap<String, Object> parameters) {
+ public UUID searchByHistory(Map<String, Object> parameters) {
if (app == null) {
Log.e(cgSettings.tag, "cgeoBase.searchByHistory: No application found");
return null;
@@ -3009,31 +2967,31 @@ public class cgBase {
return search.getCurrentId();
}
- public Long searchByCoords(cgSearchThread thread, HashMap<String, String> parameters, int reason, boolean showCaptcha) {
+ public UUID searchByCoords(cgSearchThread thread, Map<String, String> parameters, int reason, boolean showCaptcha) {
final cgSearch search = new cgSearch();
final String latitude = parameters.get("latitude");
final String longitude = parameters.get("longitude");
cgCacheWrap caches = new cgCacheWrap();
String cacheType = parameters.get("cachetype");
- if (latitude == null || latitude.length() == 0) {
+ if (StringUtils.isBlank(latitude)) {
Log.e(cgSettings.tag, "cgeoBase.searchByCoords: No latitude given");
return null;
}
- if (longitude == null || longitude.length() == 0) {
+ if (StringUtils.isBlank(longitude)) {
Log.e(cgSettings.tag, "cgeoBase.searchByCoords: No longitude given");
return null;
}
- if (cacheType != null && cacheType.length() == 0) {
+ if (StringUtils.isBlank(latitude)) {
cacheType = null;
}
final String host = "www.geocaching.com";
final String path = "/seek/nearest.aspx";
final String method = "GET";
- final HashMap<String, String> params = new HashMap<String, String>();
+ final Map<String, String> params = new HashMap<String, String>();
if (cacheType != null && cacheIDs.containsKey(cacheType)) {
params.put("tx", cacheIDs.get(cacheType));
} else {
@@ -3045,7 +3003,7 @@ public class cgBase {
final String url = "http://" + host + path + "?" + prepareParameters(params, false, true);
String page = requestLogged(false, host, path, method, params, false, false, true);
- if (page == null || page.length() == 0) {
+ if (StringUtils.isBlank(page)) {
Log.e(cgSettings.tag, "cgeoBase.searchByCoords: No data from server");
return null;
}
@@ -3060,49 +3018,32 @@ public class cgBase {
return null;
}
- final ArrayList<cgCache> cacheList = new ArrayList<cgCache>();
- if (caches != null) {
- if (caches.error != null && caches.error.length() > 0) {
- search.error = caches.error;
- }
- if (caches.url != null && caches.url.length() > 0) {
- search.url = caches.url;
- }
- search.viewstates = caches.viewstates;
- search.totalCnt = caches.totalCnt;
-
- for (cgCache cache : caches.cacheList) {
- if (settings.excludeDisabled == 0 || (settings.excludeDisabled == 1 && cache.disabled == false)) {
- search.addGeocode(cache.geocode);
- cacheList.add(cache);
- }
- }
- }
+ List<cgCache> cacheList = processSearchResults(search, caches, settings.excludeDisabled, 0, null);
app.addSearch(search, cacheList, true, reason);
return search.getCurrentId();
}
- public Long searchByKeyword(cgSearchThread thread, HashMap<String, String> parameters, int reason, boolean showCaptcha) {
+ public UUID searchByKeyword(cgSearchThread thread, Map<String, String> parameters, int reason, boolean showCaptcha) {
final cgSearch search = new cgSearch();
final String keyword = parameters.get("keyword");
cgCacheWrap caches = new cgCacheWrap();
String cacheType = parameters.get("cachetype");
- if (keyword == null || keyword.length() == 0) {
+ if (StringUtils.isBlank(keyword)) {
Log.e(cgSettings.tag, "cgeoBase.searchByKeyword: No keyword given");
return null;
}
- if (cacheType != null && cacheType.length() == 0) {
+ if (StringUtils.isBlank(cacheType)) {
cacheType = null;
}
final String host = "www.geocaching.com";
final String path = "/seek/nearest.aspx";
final String method = "GET";
- final HashMap<String, String> params = new HashMap<String, String>();
+ final Map<String, String> params = new HashMap<String, String>();
if (cacheType != null && cacheIDs.containsKey(cacheType)) {
params.put("tx", cacheIDs.get(cacheType));
} else {
@@ -3113,7 +3054,7 @@ public class cgBase {
final String url = "http://" + host + path + "?" + prepareParameters(params, false, true);
String page = requestLogged(false, host, path, method, params, false, false, true);
- if (page == null || page.length() == 0) {
+ if (StringUtils.isBlank(page)) {
Log.e(cgSettings.tag, "cgeoBase.searchByKeyword: No data from server");
return null;
}
@@ -3128,49 +3069,32 @@ public class cgBase {
return null;
}
- final ArrayList<cgCache> cacheList = new ArrayList<cgCache>();
- if (caches != null) {
- if (caches.error != null && caches.error.length() > 0) {
- search.error = caches.error;
- }
- if (caches.url != null && caches.url.length() > 0) {
- search.url = caches.url;
- }
- search.viewstates = caches.viewstates;
- search.totalCnt = caches.totalCnt;
-
- for (cgCache cache : caches.cacheList) {
- if (settings.excludeDisabled == 0 || (settings.excludeDisabled == 1 && cache.disabled == false)) {
- search.addGeocode(cache.geocode);
- cacheList.add(cache);
- }
- }
- }
+ List<cgCache> cacheList = processSearchResults(search, caches, settings.excludeDisabled, 0, null);
app.addSearch(search, cacheList, true, reason);
return search.getCurrentId();
}
- public Long searchByUsername(cgSearchThread thread, HashMap<String, String> parameters, int reason, boolean showCaptcha) {
+ public UUID searchByUsername(cgSearchThread thread, Map<String, String> parameters, int reason, boolean showCaptcha) {
final cgSearch search = new cgSearch();
final String userName = parameters.get("username");
cgCacheWrap caches = new cgCacheWrap();
String cacheType = parameters.get("cachetype");
- if (userName == null || userName.length() == 0) {
+ if (StringUtils.isBlank(userName)) {
Log.e(cgSettings.tag, "cgeoBase.searchByUsername: No user name given");
return null;
}
- if (cacheType != null && cacheType.length() == 0) {
+ if (StringUtils.isBlank(cacheType)) {
cacheType = null;
}
final String host = "www.geocaching.com";
final String path = "/seek/nearest.aspx";
final String method = "GET";
- final HashMap<String, String> params = new HashMap<String, String>();
+ final Map<String, String> params = new HashMap<String, String>();
if (cacheType != null && cacheIDs.containsKey(cacheType)) {
params.put("tx", cacheIDs.get(cacheType));
} else {
@@ -3187,7 +3111,7 @@ public class cgBase {
final String url = "http://" + host + path + "?" + prepareParameters(params, my, true);
String page = requestLogged(false, host, path, method, params, false, my, true);
- if (page == null || page.length() == 0) {
+ if (StringUtils.isBlank(page)) {
Log.e(cgSettings.tag, "cgeoBase.searchByUsername: No data from server");
return null;
}
@@ -3198,53 +3122,36 @@ public class cgBase {
}
if (app == null) {
- Log.e(cgSettings.tag, "cgeoBase.searchByCoords: No application found");
+ Log.e(cgSettings.tag, "cgeoBase.searchByUsername: No application found");
return null;
}
- final ArrayList<cgCache> cacheList = new ArrayList<cgCache>();
- if (caches != null) {
- if (caches.error != null && caches.error.length() > 0) {
- search.error = caches.error;
- }
- if (caches.url != null && caches.url.length() > 0) {
- search.url = caches.url;
- }
- search.viewstates = caches.viewstates;
- search.totalCnt = caches.totalCnt;
-
- for (cgCache cache : caches.cacheList) {
- if (settings.excludeDisabled == 0 || (settings.excludeDisabled == 1 && cache.disabled == false)) {
- search.addGeocode(cache.geocode);
- cacheList.add(cache);
- }
- }
- }
+ List<cgCache> cacheList = processSearchResults(search, caches, settings.excludeDisabled, 0, null);
app.addSearch(search, cacheList, true, reason);
return search.getCurrentId();
}
- public Long searchByOwner(cgSearchThread thread, HashMap<String, String> parameters, int reason, boolean showCaptcha) {
+ public UUID searchByOwner(cgSearchThread thread, Map<String, String> parameters, int reason, boolean showCaptcha) {
final cgSearch search = new cgSearch();
final String userName = parameters.get("username");
cgCacheWrap caches = new cgCacheWrap();
String cacheType = parameters.get("cachetype");
- if (userName == null || userName.length() == 0) {
+ if (StringUtils.isBlank(userName)) {
Log.e(cgSettings.tag, "cgeoBase.searchByOwner: No user name given");
return null;
}
- if (cacheType != null && cacheType.length() == 0) {
+ if (StringUtils.isBlank(cacheType)) {
cacheType = null;
}
final String host = "www.geocaching.com";
final String path = "/seek/nearest.aspx";
final String method = "GET";
- final HashMap<String, String> params = new HashMap<String, String>();
+ final Map<String, String> params = new HashMap<String, String>();
if (cacheType != null && cacheIDs.containsKey(cacheType)) {
params.put("tx", cacheIDs.get(cacheType));
} else {
@@ -3255,7 +3162,7 @@ public class cgBase {
final String url = "http://" + host + path + "?" + prepareParameters(params, false, true);
String page = requestLogged(false, host, path, method, params, false, false, true);
- if (page == null || page.length() == 0) {
+ if (StringUtils.isBlank(page)) {
Log.e(cgSettings.tag, "cgeoBase.searchByOwner: No data from server");
return null;
}
@@ -3270,31 +3177,14 @@ public class cgBase {
return null;
}
- final ArrayList<cgCache> cacheList = new ArrayList<cgCache>();
- if (caches != null) {
- if (caches.error != null && caches.error.length() > 0) {
- search.error = caches.error;
- }
- if (caches.url != null && caches.url.length() > 0) {
- search.url = caches.url;
- }
- search.viewstates = caches.viewstates;
- search.totalCnt = caches.totalCnt;
-
- for (cgCache cache : caches.cacheList) {
- if (settings.excludeDisabled == 0 || (settings.excludeDisabled == 1 && cache.disabled == false)) {
- search.addGeocode(cache.geocode);
- cacheList.add(cache);
- }
- }
- }
+ List<cgCache> cacheList = processSearchResults(search, caches, settings.excludeDisabled, 0, null);
app.addSearch(search, cacheList, true, reason);
return search.getCurrentId();
}
- public Long searchByViewport(HashMap<String, String> parameters, int reason) {
+ public UUID searchByViewport(Map<String, String> parameters, int reason) {
final cgSearch search = new cgSearch();
final String latMin = parameters.get("latitude-min");
final String latMax = parameters.get("latitude-max");
@@ -3311,7 +3201,7 @@ public class cgBase {
String page = null;
- if (latMin == null || latMin.length() == 0 || latMax == null || latMax.length() == 0 || lonMin == null || lonMin.length() == 0 || lonMax == null || lonMax.length() == 0) {
+ if (StringUtils.isBlank(latMin) || StringUtils.isBlank(latMax) || StringUtils.isBlank(lonMin) || StringUtils.isBlank(lonMax)) {
Log.e(cgSettings.tag, "cgeoBase.searchByViewport: Not enough parameters to recognize viewport");
return null;
}
@@ -3324,7 +3214,7 @@ public class cgBase {
final String url = "http://" + host + path + "?" + params;
page = requestJSONgc(host, path, params);
- if (page == null || page.length() == 0) {
+ if (StringUtils.isBlank(page)) {
Log.e(cgSettings.tag, "cgeoBase.searchByViewport: No data from server");
return null;
}
@@ -3339,37 +3229,15 @@ public class cgBase {
return null;
}
- final ArrayList<cgCache> cacheList = new ArrayList<cgCache>();
- if (caches != null) {
- if (caches.error != null && caches.error.length() > 0) {
- search.error = caches.error;
- }
- if (caches.url != null && caches.url.length() > 0) {
- search.url = caches.url;
- }
- search.viewstates = caches.viewstates;
- search.totalCnt = caches.totalCnt;
-
- if (caches.cacheList != null && caches.cacheList.size() > 0) {
- for (cgCache cache : caches.cacheList) {
- if ((settings.excludeDisabled == 0 || (settings.excludeDisabled == 1 && cache.disabled == false))
- && (settings.excludeMine == 0 || (settings.excludeMine == 1 && cache.own == false))
- && (settings.excludeMine == 0 || (settings.excludeMine == 1 && cache.found == false))
- && (settings.cacheType == null || (settings.cacheType.equals(cache.type)))) {
- search.addGeocode(cache.geocode);
- cacheList.add(cache);
- }
- }
- }
- }
+ List<cgCache> cacheList = processSearchResults(search, caches, settings.excludeDisabled, settings.excludeMine, settings.cacheType);
app.addSearch(search, cacheList, true, reason);
return search.getCurrentId();
}
- public ArrayList<cgUser> getGeocachersInViewport(String username, Double latMin, Double latMax, Double lonMin, Double lonMax) {
- final ArrayList<cgUser> users = new ArrayList<cgUser>();
+ public List<cgUser> getGeocachersInViewport(String username, Double latMin, Double latMax, Double lonMin, Double lonMax) {
+ final List<cgUser> users = new ArrayList<cgUser>();
if (username == null) {
return users;
@@ -3381,7 +3249,7 @@ public class cgBase {
final String host = "api.go4cache.com";
final String path = "/get.php";
final String method = "POST";
- final HashMap<String, String> params = new HashMap<String, String>();
+ final Map<String, String> params = new HashMap<String, String>();
params.put("u", username);
params.put("ltm", String.format((Locale) null, "%.6f", latMin));
@@ -3391,7 +3259,7 @@ public class cgBase {
final String data = request(false, host, path, method, params, false, false, false).getData();
- if (data == null || data.length() == 0) {
+ if (StringUtils.isBlank(data)) {
Log.e(cgSettings.tag, "cgeoBase.getGeocachersInViewport: No data from server");
return null;
}
@@ -3432,13 +3300,40 @@ public class cgBase {
return users;
}
- public cgTrackable searchTrackable(HashMap<String, String> parameters) {
+ public List<cgCache> processSearchResults(cgSearch search, cgCacheWrap caches, int excludeDisabled, int excludeMine, String cacheType) {
+ List<cgCache> cacheList = new ArrayList<cgCache>();
+ if (caches != null) {
+ if (StringUtils.isNotBlank(caches.error)) {
+ search.error = caches.error;
+ }
+ if (StringUtils.isNotBlank(caches.url)) {
+ search.url = caches.url;
+ }
+ search.viewstates = caches.viewstates;
+ search.totalCnt = caches.totalCnt;
+
+ if (CollectionUtils.isNotEmpty(caches.cacheList)) {
+ for (cgCache cache : caches.cacheList) {
+ if ((excludeDisabled == 0 || (excludeDisabled == 1 && cache.disabled == false))
+ && (excludeMine == 0 || (excludeMine == 1 && cache.own == false))
+ && (excludeMine == 0 || (excludeMine == 1 && cache.found == false))
+ && (cacheType == null || (cacheType.equals(cache.type)))) {
+ search.addGeocode(cache.geocode);
+ cacheList.add(cache);
+ }
+ }
+ }
+ }
+ return cacheList;
+ }
+
+ public cgTrackable searchTrackable(Map<String, String> parameters) {
final String geocode = parameters.get("geocode");
final String guid = parameters.get("guid");
final String id = parameters.get("id");
cgTrackable trackable = new cgTrackable();
- if ((geocode == null || geocode.length() == 0) && (guid == null || guid.length() == 0) && (id == null || id.length() == 0)) {
+ if (StringUtils.isBlank(geocode) && StringUtils.isBlank(guid) && StringUtils.isBlank(id)) {
Log.e(cgSettings.tag, "cgeoBase.searchTrackable: No geocode nor guid nor id given");
return null;
}
@@ -3446,18 +3341,18 @@ public class cgBase {
final String host = "www.geocaching.com";
final String path = "/track/details.aspx";
final String method = "GET";
- final HashMap<String, String> params = new HashMap<String, String>();
- if (geocode != null && geocode.length() > 0) {
+ final Map<String, String> params = new HashMap<String, String>();
+ if (StringUtils.isNotBlank(geocode)) {
params.put("tracker", geocode);
- } else if (guid != null && guid.length() > 0) {
+ } else if (StringUtils.isNotBlank(guid)) {
params.put("guid", guid);
- } else if (id != null && id.length() > 0) {
+ } else if (StringUtils.isNotBlank(id)) {
params.put("id", id);
}
String page = requestLogged(false, host, path, method, params, false, false, false);
- if (page == null || page.length() == 0) {
+ if (StringUtils.isBlank(page)) {
Log.e(cgSettings.tag, "cgeoBase.searchTrackable: No data from server");
return trackable;
}
@@ -3472,8 +3367,8 @@ public class cgBase {
}
public int postLog(cgeoapplication app, String geocode, String cacheid, String[] viewstates,
- int logType, int year, int month, int day, String log, ArrayList<cgTrackableLog> trackables) {
- if (isEmpty(viewstates)) {
+ int logType, int year, int month, int day, String log, List<cgTrackableLog> trackables) {
+ if (ArrayUtils.isEmpty(viewstates)) {
Log.e(cgSettings.tag, "cgeoBase.postLog: No viewstate given");
return 1000;
}
@@ -3483,7 +3378,7 @@ public class cgBase {
return 1000;
}
- if (log == null || log.length() == 0) {
+ if (StringUtils.isBlank(log)) {
Log.e(cgSettings.tag, "cgeoBase.postLog: No log text given");
return 1001;
}
@@ -3516,7 +3411,7 @@ public class cgBase {
final String host = "www.geocaching.com";
final String path = "/seek/log.aspx?ID=" + cacheid;
final String method = "POST";
- final HashMap<String, String> params = new HashMap<String, String>();
+ final Map<String, String> params = new HashMap<String, String>();
setViewstates(viewstates, params);
params.put("__EVENTTARGET", "");
@@ -3557,7 +3452,7 @@ public class cgBase {
}
}
- if (page == null || page.length() == 0) {
+ if (StringUtils.isBlank(page)) {
Log.e(cgSettings.tag, "cgeoBase.postLog: No data from server");
return 1002;
}
@@ -3570,7 +3465,7 @@ public class cgBase {
if (matcher.find() && matcher.groupCount() > 0) {
final String[] viewstatesConfirm = getViewstates(page);
- if (isEmpty(viewstatesConfirm)) {
+ if (ArrayUtils.isEmpty(viewstatesConfirm)) {
Log.e(cgSettings.tag, "cgeoBase.postLog: No viewstate for confirm log");
return 1000;
}
@@ -3635,7 +3530,7 @@ public class cgBase {
public int postLogTrackable(String tbid, String trackingCode, String[] viewstates,
int logType, int year, int month, int day, String log) {
- if (isEmpty(viewstates)) {
+ if (ArrayUtils.isEmpty(viewstates)) {
Log.e(cgSettings.tag, "cgeoBase.postLogTrackable: No viewstate given");
return 1000;
}
@@ -3645,7 +3540,7 @@ public class cgBase {
return 1000;
}
- if (log == null || log.length() == 0) {
+ if (StringUtils.isBlank(log)) {
Log.e(cgSettings.tag, "cgeoBase.postLogTrackable: No log text given");
return 1001;
}
@@ -3658,7 +3553,7 @@ public class cgBase {
final String host = "www.geocaching.com";
final String path = "/track/log.aspx?wid=" + tbid;
final String method = "POST";
- final HashMap<String, String> params = new HashMap<String, String>();
+ final Map<String, String> params = new HashMap<String, String>();
setViewstates(viewstates, params);
params.put("__EVENTTARGET", "");
@@ -3689,7 +3584,7 @@ public class cgBase {
}
}
- if (page == null || page.length() == 0) {
+ if (StringUtils.isBlank(page)) {
Log.e(cgSettings.tag, "cgeoBase.postLogTrackable: No data from server");
return 1002;
}
@@ -3719,7 +3614,7 @@ public class cgBase {
String page = requestLogged(false, "www.geocaching.com", "/my/watchlist.aspx?w=" + cache.cacheid,
"POST", null, false, false, false);
- if (page == null || page.length() == 0) {
+ if (StringUtils.isBlank(page)) {
Log.e(cgSettings.tag, "cgBase.addToWatchlist: No data from server");
return -1; // error
}
@@ -3747,13 +3642,13 @@ public class cgBase {
String page = requestLogged(false, host, path, method, null, false, false, false);
- if (page == null || page.length() == 0) {
+ if (StringUtils.isBlank(page)) {
Log.e(cgSettings.tag, "cgBase.removeFromWatchlist: No data from server");
return -1; // error
}
// removing cache from list needs approval by hitting "Yes" button
- final HashMap<String, String> params = new HashMap<String, String>();
+ final Map<String, String> params = new HashMap<String, String>();
transferViewstates(page, params);
params.put("__EVENTTARGET", "");
params.put("__EVENTARGUMENT", "");
@@ -3828,12 +3723,12 @@ public class cgBase {
if (app == null) {
return;
}
- if (settings == null || settings.tokenPublic == null || settings.tokenPublic.length() == 0 || settings.tokenSecret == null || settings.tokenSecret.length() == 0) {
+ if (settings == null || StringUtils.isBlank(settings.tokenPublic) || StringUtils.isNotBlank(settings.tokenSecret)) {
return;
}
try {
- HashMap<String, String> parameters = new HashMap<String, String>();
+ Map<String, String> parameters = new HashMap<String, String>();
parameters.put("status", status);
if (latitude != null && longitude != null) {
@@ -3964,7 +3859,7 @@ public class cgBase {
return encoded;
}
- public String prepareParameters(HashMap<String, String> params, boolean my, boolean addF) {
+ public String prepareParameters(Map<String, String> params, boolean my, boolean addF) {
String paramsDone = null;
if (my != true && settings.excludeMine > 0) {
@@ -3980,7 +3875,7 @@ public class cgBase {
if (params != null) {
Set<Map.Entry<String, String>> entrySet = params.entrySet();
- ArrayList<String> paramsEncoded = new ArrayList<String>();
+ List<String> paramsEncoded = new ArrayList<String>();
for(Map.Entry<String, String> entry : entrySet)
{
@@ -4005,13 +3900,13 @@ public class cgBase {
return paramsDone;
}
- public String[] requestViewstates(boolean secure, String host, String path, String method, HashMap<String, String> params, boolean xContentType, boolean my) {
+ public String[] requestViewstates(boolean secure, String host, String path, String method, Map<String, String> params, boolean xContentType, boolean my) {
final cgResponse response = request(secure, host, path, method, params, xContentType, my, false);
return getViewstates(response.getData());
}
- public String requestLogged(boolean secure, String host, String path, String method, HashMap<String, String> params, boolean xContentType, boolean my, boolean addF) {
+ public String requestLogged(boolean secure, String host, String path, String method, Map<String, String> params, boolean xContentType, boolean my, boolean addF) {
cgResponse response = request(secure, host, path, method, params, xContentType, my, addF);
String data = response.getData();
@@ -4028,14 +3923,14 @@ public class cgBase {
return data;
}
- public cgResponse request(boolean secure, String host, String path, String method, HashMap<String, String> params, boolean xContentType, boolean my, boolean addF) {
+ public cgResponse request(boolean secure, String host, String path, String method, Map<String, String> params, boolean xContentType, boolean my, boolean addF) {
// prepare parameters
final String paramsDone = prepareParameters(params, my, addF);
return request(secure, host, path, method, paramsDone, 0, xContentType);
}
- public cgResponse request(boolean secure, String host, String path, String method, HashMap<String, String> params, int requestId, boolean xContentType, boolean my, boolean addF) {
+ public cgResponse request(boolean secure, String host, String path, String method, Map<String, String> params, int requestId, boolean xContentType, boolean my, boolean addF) {
// prepare parameters
final String paramsDone = prepareParameters(params, my, addF);
@@ -4213,7 +4108,7 @@ public class cgBase {
response = request(secureRedir, newLocation.getHost(), newLocation.getPath(), "GET", new HashMap<String, String>(), requestId, false, false, false);
}
} else {
- if (buffer != null && buffer.length() > 0) {
+ if (StringUtils.isNotBlank(buffer)) {
replaceWhitespace(buffer);
String data = buffer.toString();
buffer = null;
@@ -4259,7 +4154,7 @@ public class cgBase {
if (cookies != null) {
final Set<Map.Entry<String, String>> entrySet = cookies.entrySet();
- final ArrayList<String> cookiesEncoded = new ArrayList<String>();
+ final List<String> cookiesEncoded = new ArrayList<String>();
for(Map.Entry<String, String> entry : entrySet){
cookiesEncoded.add(entry.getKey() + "=" + entry.getValue());
@@ -4273,9 +4168,9 @@ public class cgBase {
if (cookiesDone == null) {
Map<String, ?> prefsValues = prefs.getAll();
- if (prefsValues != null && prefsValues.size() > 0) {
+ if (CollectionUtils.isNotEmpty(prefsValues)) {
final Set<? extends Map.Entry<String, ?>> entrySet = prefsValues.entrySet();
- final ArrayList<String> cookiesEncoded = new ArrayList<String>();
+ final List<String> cookiesEncoded = new ArrayList<String>();
for(Map.Entry<String, ?> entry : entrySet){
String key = entry.getKey();
@@ -4561,7 +4456,7 @@ public class cgBase {
Log.e(cgSettings.tag, "cgeoBase.requestJSON: " + e.toString());
}
- if (buffer != null && buffer.length() > 0) {
+ if (StringUtils.isNotBlank(buffer)) {
break;
}
@@ -4680,16 +4575,16 @@ public class cgBase {
// get cache details, they may not yet be complete
if (cache != null) {
// only reload the cache, if it was already stored or has not all details (by checking the description)
- if (cache.reason > 0 || cache.description == null || cache.description.length() == 0) {
- final HashMap<String, String> params = new HashMap<String, String>();
+ if (cache.reason > 0 || StringUtils.isBlank(cache.description)) {
+ final Map<String, String> params = new HashMap<String, String>();
params.put("geocode", cache.geocode);
- final Long searchId = searchByGeocode(params, listId, false);
+ final UUID searchId = searchByGeocode(params, listId, false);
cache = app.getCache(searchId);
}
- } else if (geocode != null) {
- final HashMap<String, String> params = new HashMap<String, String>();
+ } else if (StringUtils.isNotBlank(geocode)) {
+ final Map<String, String> params = new HashMap<String, String>();
params.put("geocode", geocode);
- final Long searchId = searchByGeocode(params, listId, false);
+ final UUID searchId = searchByGeocode(params, listId, false);
cache = app.getCache(searchId);
}
@@ -4704,12 +4599,12 @@ public class cgBase {
final cgHtmlImg imgGetter = new cgHtmlImg(activity, cache.geocode, false, listId, true);
// store images from description
- if (cache.description != null) {
+ if (StringUtils.isNotBlank(cache.description)) {
Html.fromHtml(cache.description, imgGetter, null);
}
// store spoilers
- if (cache.spoilers != null && cache.spoilers.isEmpty() == false) {
+ if (CollectionUtils.isNotEmpty(cache.spoilers)) {
for (cgImage oneSpoiler : cache.spoilers) {
imgGetter.getDrawable(oneSpoiler.url);
}
@@ -4718,7 +4613,7 @@ public class cgBase {
// store images from logs
if (settings.storelogimages) {
for (cgLog log : cache.logs) {
- if (log.logImages != null && log.logImages.isEmpty() == false) {
+ if (CollectionUtils.isNotEmpty(log.logImages)) {
for (cgImage oneLogImg : log.logImages) {
imgGetter.getDrawable(oneLogImg.url);
}
@@ -4949,7 +4844,7 @@ public class cgBase {
String iconTxt = null;
if (cache) {
- if (type != null && type.length() > 0) {
+ if (StringUtils.isNotBlank(type)) {
if (own) {
iconTxt = type + "-own";
} else if (found) {
@@ -4969,7 +4864,7 @@ public class cgBase {
icon = gcIcons.get("traditional");
}
} else {
- if (type != null && type.length() > 0) {
+ if (StringUtils.isNotBlank(type)) {
iconTxt = type;
} else {
iconTxt = "waypoint";
@@ -5062,6 +4957,7 @@ public class cgBase {
gcIcons.put("mystery-disabled", R.drawable.marker_cache_mystery_disabled);
gcIcons.put("gchq-disabled", R.drawable.marker_cache_gchq_disabled);
}
+
}
public static boolean runNavigation(Activity activity, Resources res, cgSettings settings, Double latitude, Double longitude) {
@@ -5114,7 +5010,7 @@ public class cgBase {
final String data = response.getData();
String usertoken = null;
- if (data != null && data.length() > 0) {
+ if (StringUtils.isNotBlank(data)) {
final Pattern pattern = Pattern.compile("var userToken[^=]*=[^']*'([^']+)';", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(data);
@@ -5125,7 +5021,7 @@ public class cgBase {
}
}
- if (noTokenHandler != null && (usertoken == null || usertoken.length() == 0)) {
+ if (noTokenHandler != null && StringUtils.isBlank(usertoken)) {
noTokenHandler.sendEmptyMessage(0);
}
@@ -5142,7 +5038,7 @@ public class cgBase {
final String data = requestJSON(host, path, params);
- if (data == null || data.length() == 0) {
+ if (StringUtils.isBlank(data)) {
return elv;
}
diff --git a/src/cgeo/geocaching/cgCache.java b/src/cgeo/geocaching/cgCache.java
index 5ffa991..e9c37ef 100644
--- a/src/cgeo/geocaching/cgCache.java
+++ b/src/cgeo/geocaching/cgCache.java
@@ -4,9 +4,13 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.lang3.StringUtils;
+
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
@@ -68,12 +72,12 @@ public class cgCache implements ICache {
public Float myVote = null;
public int inventoryItems = 0;
public boolean onWatchlist = false;
- public ArrayList<String> attributes = null;
- public ArrayList<cgWaypoint> waypoints = null;
- public ArrayList<cgImage> spoilers = null;
- public ArrayList<cgLog> logs = null;
- public ArrayList<cgTrackable> inventory = null;
- public HashMap<Integer, Integer> logCounts = new HashMap<Integer, Integer>();
+ public List<String> attributes = null;
+ public List<cgWaypoint> waypoints = null;
+ public List<cgImage> spoilers = null;
+ public List<cgLog> logs = null;
+ public List<cgTrackable> inventory = null;
+ public Map<Integer, Integer> logCounts = new HashMap<Integer, Integer>();
public boolean logOffline = false;
// temporary values
public boolean statusChecked = false;
@@ -122,37 +126,37 @@ public class cgCache implements ICache {
if (reason == null || reason == 0) {
reason = oldCache.reason;
}
- if (geocode == null || geocode.length() == 0) {
+ if (StringUtils.isBlank(geocode)) {
geocode = oldCache.geocode;
}
- if (cacheid == null || cacheid.length() == 0) {
+ if (StringUtils.isBlank(cacheid)) {
cacheid = oldCache.cacheid;
}
- if (guid == null || guid.length() == 0) {
+ if (StringUtils.isBlank(guid)) {
guid = oldCache.guid;
}
- if (type == null || type.length() == 0) {
+ if (StringUtils.isBlank(type)) {
type = oldCache.type;
}
- if (name == null || name.length() == 0) {
+ if (StringUtils.isBlank(name)) {
name = oldCache.name;
}
- if (nameSp == null || nameSp.length() == 0) {
+ if (StringUtils.isBlank(nameSp)) {
nameSp = oldCache.nameSp;
}
- if (owner == null || owner.length() == 0) {
+ if (StringUtils.isBlank(owner)) {
owner = oldCache.owner;
}
- if (ownerReal == null || ownerReal.length() == 0) {
+ if (StringUtils.isBlank(ownerReal)) {
ownerReal = oldCache.ownerReal;
}
if (hidden == null) {
hidden = oldCache.hidden;
}
- if (hint == null || hint.length() == 0) {
+ if (StringUtils.isBlank(hint)) {
hint = oldCache.hint;
}
- if (size == null || size.length() == 0) {
+ if (StringUtils.isBlank(size)) {
size = oldCache.size;
}
if (difficulty == null || difficulty == 0) {
@@ -167,16 +171,16 @@ public class cgCache implements ICache {
if (distance == null) {
distance = oldCache.distance;
}
- if (latlon == null || latlon.length() == 0) {
+ if (StringUtils.isBlank(latlon)) {
latlon = oldCache.latlon;
}
- if (latitudeString == null || latitudeString.length() == 0) {
+ if (StringUtils.isBlank(latitudeString)) {
latitudeString = oldCache.latitudeString;
}
- if (longitudeString == null || longitudeString.length() == 0) {
+ if (StringUtils.isBlank(longitudeString)) {
longitudeString = oldCache.longitudeString;
}
- if (location == null || location.length() == 0) {
+ if (StringUtils.isBlank(location)) {
location = oldCache.location;
}
if (latitude == null) {
@@ -188,13 +192,13 @@ public class cgCache implements ICache {
if (elevation == null) {
elevation = oldCache.elevation;
}
- if (personalNote == null || personalNote.length() == 0) {
+ if (StringUtils.isNotBlank(personalNote)) {
personalNote = oldCache.personalNote;
}
- if (shortdesc == null || shortdesc.length() == 0) {
+ if (StringUtils.isBlank(shortdesc)) {
shortdesc = oldCache.shortdesc;
}
- if (description == null || description.length() == 0) {
+ if (StringUtils.isBlank(description)) {
description = oldCache.description;
}
if (favouriteCnt == null) {
@@ -266,7 +270,7 @@ public class cgCache implements ICache {
*/
boolean isGuidContainedInPage(final String page) {
// check if the guid of the cache is anywhere in the page
- if (guid == null || guid.length() == 0) {
+ if (StringUtils.isBlank(guid)) {
return false;
}
Pattern patternOk = Pattern.compile(guid, Pattern.CASE_INSENSITIVE);
@@ -285,7 +289,7 @@ public class cgCache implements ICache {
}
public boolean logVisit(IAbstractActivity fromActivity) {
- if (cacheid == null || cacheid.length() == 0) {
+ if (StringUtils.isBlank(cacheid)) {
fromActivity.showToast(((Activity)fromActivity).getResources().getString(R.string.err_cannot_log_visit));
return true;
}
@@ -301,9 +305,8 @@ public class cgCache implements ICache {
public boolean logOffline(final IAbstractActivity fromActivity, final int logType, final cgSettings settings, final cgBase base) {
String log = "";
- if (settings.getSignature() != null
- && settings.signatureAutoinsert
- && settings.getSignature().length() > 0) {
+ if (StringUtils.isNotBlank(settings.getSignature())
+ && settings.signatureAutoinsert) {
log = LogTemplateProvider.applyTemplates(settings.getSignature(), base);
}
logOffline(fromActivity, log, Calendar.getInstance(), logType);
@@ -326,9 +329,9 @@ public class cgCache implements ICache {
}
}
- public ArrayList<Integer> getPossibleLogTypes(cgSettings settings) {
+ public List<Integer> getPossibleLogTypes(cgSettings settings) {
boolean isOwner = owner != null && owner.equalsIgnoreCase(settings.getUsername());
- ArrayList<Integer> types = new ArrayList<Integer>();
+ List<Integer> types = new ArrayList<Integer>();
if ("event".equals(type) || "mega".equals(type) || "cito".equals(type) || "lostfound".equals(type)) {
types.add(cgBase.LOG_WILL_ATTEND);
types.add(cgBase.LOG_NOTE);
diff --git a/src/cgeo/geocaching/cgCacheListAdapter.java b/src/cgeo/geocaching/cgCacheListAdapter.java
index 8ef1e8f..968f809 100644
--- a/src/cgeo/geocaching/cgCacheListAdapter.java
+++ b/src/cgeo/geocaching/cgCacheListAdapter.java
@@ -5,6 +5,9 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
import android.app.Activity;
import android.content.Intent;
@@ -35,6 +38,7 @@ import cgeo.geocaching.filter.cgFilter;
import cgeo.geocaching.sorting.CacheComparator;
import cgeo.geocaching.sorting.DistanceComparator;
import cgeo.geocaching.sorting.VisitComparator;
+import cgeo.geocaching.utils.CollectionUtils;
public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
@@ -55,9 +59,9 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
private boolean sort = true;
private int checked = 0;
private boolean selectMode = false;
- 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 static Map<String, Drawable> gcIconDrawables = new HashMap<String, Drawable>();
+ private List<cgCompassMini> compasses = new ArrayList<cgCompassMini>();
+ private List<cgDistanceView> distances = new ArrayList<cgDistanceView>();
private int[] ratingBcgs = new int[3];
private float pixelDensity = 1f;
private static final int SWIPE_MIN_DISTANCE = 60;
@@ -286,13 +290,13 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
lastSort = System.currentTimeMillis();
}
- if (distances != null && distances.size() > 0) {
+ if (CollectionUtils.isNotEmpty(distances)) {
for (cgDistanceView distance : distances) {
distance.update(latitudeIn, longitudeIn);
}
}
- if (compasses != null && compasses.size() > 0) {
+ if (CollectionUtils.isNotEmpty(compasses)) {
for (cgCompassMini compass : compasses) {
compass.updateCoords(latitudeIn, longitudeIn);
}
@@ -306,7 +310,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
azimuth = azimuthIn;
- if (compasses != null && compasses.size() > 0) {
+ if (CollectionUtils.isNotEmpty(compasses)) {
for (cgCompassMini compass : compasses) {
compass.updateAzimuth(azimuth);
}
@@ -366,8 +370,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
holder.checkbox = (CheckBox) rowView.findViewById(R.id.checkbox);
holder.oneInfo = (RelativeLayout) rowView.findViewById(R.id.one_info);
holder.oneCheckbox = (RelativeLayout) rowView.findViewById(R.id.one_checkbox);
- holder.foundMark = (ImageView) rowView.findViewById(R.id.found_mark);
- holder.offlineMark = (ImageView) rowView.findViewById(R.id.offline_mark);
+ holder.logStatusMark = (ImageView) rowView.findViewById(R.id.log_status_mark);
holder.oneCache = (RelativeLayout) rowView.findViewById(R.id.one_cache);
holder.text = (TextView) rowView.findViewById(R.id.text);
holder.directionLayout = (RelativeLayout) rowView.findViewById(R.id.direction_layout);
@@ -441,15 +444,14 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
}
holder.direction.setContent(cache.latitude, cache.longitude);
- if (cache.logOffline) {
- holder.offlineMark.setVisibility(View.VISIBLE);
- holder.foundMark.setVisibility(View.GONE);
+ if (cache.found && cache.logOffline) {
+ holder.logStatusMark.setImageResource(R.drawable.mark_green_red);
} else if (cache.found) {
- holder.offlineMark.setVisibility(View.GONE);
- holder.foundMark.setVisibility(View.VISIBLE);
- } else {
- holder.offlineMark.setVisibility(View.GONE);
- holder.foundMark.setVisibility(View.GONE);
+ holder.logStatusMark.setImageResource(R.drawable.mark_green);
+ } else if (cache.logOffline) {
+ holder.logStatusMark.setImageResource(R.drawable.mark_red);
+ } else {
+ holder.logStatusMark.setVisibility(View.GONE);
}
if (cache.nameSp == null) {
@@ -581,10 +583,10 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
cacheInfo.append("; ");
cacheInfo.append(base.formatDate(cache.visitedDate));
} else {
- if (cache.geocode != null && cache.geocode.length() > 0) {
+ if (StringUtils.isNotBlank(cache.geocode)) {
cacheInfo.append(cache.geocode);
}
- if (cache.size != null && cache.size.length() > 0) {
+ if (StringUtils.isNotBlank(cache.size)) {
if (cacheInfo.length() > 0) {
cacheInfo.append(" | ");
}
diff --git a/src/cgeo/geocaching/cgCacheView.java b/src/cgeo/geocaching/cgCacheView.java
index 6705729..08c9d17 100644
--- a/src/cgeo/geocaching/cgCacheView.java
+++ b/src/cgeo/geocaching/cgCacheView.java
@@ -11,8 +11,7 @@ public class cgCacheView {
public RelativeLayout oneInfo;
public RelativeLayout oneCheckbox;
public CheckBox checkbox;
- public ImageView foundMark;
- public ImageView offlineMark;
+ public ImageView logStatusMark;
public TextView text;
public TextView favourite;
public TextView info;
diff --git a/src/cgeo/geocaching/cgCacheWrap.java b/src/cgeo/geocaching/cgCacheWrap.java
index bfa5b8f..ccf6fa7 100644
--- a/src/cgeo/geocaching/cgCacheWrap.java
+++ b/src/cgeo/geocaching/cgCacheWrap.java
@@ -1,6 +1,7 @@
package cgeo.geocaching;
import java.util.ArrayList;
+import java.util.List;
/**
* List of caches
@@ -10,5 +11,5 @@ public class cgCacheWrap {
public String url = "";
public String[] viewstates = null;
public int totalCnt = 0;
- public ArrayList<cgCache> cacheList = new ArrayList<cgCache>();
+ public List<cgCache> cacheList = new ArrayList<cgCache>();
} \ No newline at end of file
diff --git a/src/cgeo/geocaching/cgData.java b/src/cgeo/geocaching/cgData.java
index 64308a2..5959c0c 100644
--- a/src/cgeo/geocaching/cgData.java
+++ b/src/cgeo/geocaching/cgData.java
@@ -14,9 +14,12 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import org.apache.commons.lang3.StringUtils;
+
import android.content.ContentValues;
import android.content.Context;
import android.content.res.Resources;
@@ -27,6 +30,7 @@ import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteStatement;
import android.os.Environment;
import android.util.Log;
+import cgeo.geocaching.utils.CollectionUtils;
public class cgData {
@@ -112,6 +116,10 @@ public class cgData {
+ "updated long not null, " // date of save
+ "attribute text "
+ "); ";
+ private final static int ATTRIBUTES_GEOCODE = 2;
+ private final static int ATTRIBUTES_UPDATED = 3;
+ private final static int ATTRIBUTES_ATTRIBUTE = 4;
+
private static final String dbCreateWaypoints = ""
+ "create table " + dbTableWaypoints + " ("
+ "_id integer primary key autoincrement, "
@@ -825,7 +833,7 @@ public class cgData {
init();
Cursor cursor = null;
- ArrayList<String> thereA = new ArrayList<String>();
+ List<String> thereA = new ArrayList<String>();
try {
cursor = databaseRO.query(
@@ -881,7 +889,7 @@ public class cgData {
int dataDetailed = 0;
try {
- if (geocode != null && geocode.length() > 0) {
+ if (StringUtils.isNotBlank(geocode)) {
cursor = databaseRO.query(
dbTableCaches,
new String[]{"_id", "detailed", "detailedupdate", "updated"},
@@ -891,7 +899,7 @@ public class cgData {
null,
null,
"1");
- } else if (guid != null && guid.length() > 0) {
+ } else if (StringUtils.isNotBlank(guid)) {
cursor = databaseRO.query(
dbTableCaches,
new String[]{"_id", "detailed", "detailedupdate", "updated"},
@@ -959,7 +967,7 @@ public class cgData {
long reason = 0;
try {
- if (geocode != null && geocode.length() > 0) {
+ if (StringUtils.isNotBlank(geocode)) {
cursor = databaseRO.query(
dbTableCaches,
new String[]{"reason"},
@@ -969,7 +977,7 @@ public class cgData {
null,
null,
"1");
- } else if (guid != null && guid.length() > 0) {
+ } else if (StringUtils.isNotBlank(guid)) {
cursor = databaseRO.query(
dbTableCaches,
new String[]{"reason"},
@@ -1014,7 +1022,7 @@ public class cgData {
int rel = 0;
try {
- if (geocode != null && geocode.length() > 0) {
+ if (StringUtils.isNotBlank(geocode)) {
cursor = databaseRO.query(
dbTableCaches,
new String[]{"reliable_latlon"},
@@ -1024,7 +1032,7 @@ public class cgData {
null,
null,
"1");
- } else if (guid != null && guid.length() > 0) {
+ } else if (StringUtils.isNotBlank(guid)) {
cursor = databaseRO.query(
dbTableCaches,
new String[]{"reliable_latlon"},
@@ -1063,7 +1071,7 @@ public class cgData {
}
public String getGeocodeForGuid(String guid) {
- if (guid == null || guid.length() == 0) {
+ if (StringUtils.isBlank(guid)) {
return null;
}
@@ -1105,7 +1113,7 @@ public class cgData {
}
public String getCacheidForGeocode(String geocode) {
- if (geocode == null || geocode.length() == 0) {
+ if (StringUtils.isBlank(geocode)) {
return null;
}
@@ -1284,10 +1292,10 @@ public class cgData {
return false;
}
- public boolean saveAttributes(String geocode, ArrayList<String> attributes) {
+ public boolean saveAttributes(String geocode, List<String> attributes) {
init();
- if (geocode == null || geocode.length() == 0 || attributes == null) {
+ if (StringUtils.isBlank(geocode) || attributes == null) {
return false;
}
@@ -1296,15 +1304,20 @@ public class cgData {
databaseRW.delete(dbTableAttributes, "geocode = ?", new String[] {geocode});
if (!attributes.isEmpty()) {
- ContentValues values = new ContentValues();
- for (String oneAttribute : attributes) {
- values.clear();
- values.put("geocode", geocode);
- values.put("updated", System.currentTimeMillis());
- values.put("attribute", oneAttribute);
- databaseRW.insert(dbTableAttributes, null, values);
+ InsertHelper helper = new InsertHelper(databaseRW, dbTableAttributes);
+ long timeStamp = System.currentTimeMillis();
+
+ for (String attribute : attributes) {
+ helper.prepareForInsert();
+
+ helper.bind(ATTRIBUTES_GEOCODE, geocode);
+ helper.bind(ATTRIBUTES_UPDATED, timeStamp);
+ helper.bind(ATTRIBUTES_ATTRIBUTE, attribute);
+
+ helper.execute();
}
+ helper.close();
}
databaseRW.setTransactionSuccessful();
} finally {
@@ -1351,10 +1364,10 @@ public class cgData {
return success;
}
- public boolean saveWaypoints(String geocode, ArrayList<cgWaypoint> waypoints, boolean drop) {
+ public boolean saveWaypoints(String geocode,List <cgWaypoint> waypoints, boolean drop) {
init();
- if (geocode == null || geocode.length() == 0 || waypoints == null) {
+ if (StringUtils.isBlank(geocode) || waypoints == null) {
return false;
}
@@ -1367,6 +1380,7 @@ public class cgData {
if (!waypoints.isEmpty()) {
ContentValues values = new ContentValues();
+ long timeStamp = System.currentTimeMillis();
for (cgWaypoint oneWaypoint : waypoints) {
if (oneWaypoint.isUserDefined()) {
continue;
@@ -1374,7 +1388,7 @@ public class cgData {
values.clear();
values.put("geocode", geocode);
- values.put("updated", System.currentTimeMillis());
+ values.put("updated", timeStamp);
values.put("type", oneWaypoint.type);
values.put("prefix", oneWaypoint.prefix);
values.put("lookup", oneWaypoint.lookup);
@@ -1402,7 +1416,7 @@ public class cgData {
public boolean saveOwnWaypoint(int id, String geocode, cgWaypoint waypoint) {
init();
- if (((geocode == null || geocode.length() == 0) && id <= 0) || waypoint == null) {
+ if ((StringUtils.isBlank(geocode) && id <= 0) || waypoint == null) {
return false;
}
@@ -1458,10 +1472,10 @@ public class cgData {
return false;
}
- public boolean saveSpoilers(String geocode, ArrayList<cgImage> spoilers) {
+ public boolean saveSpoilers(String geocode, List<cgImage> spoilers) {
init();
- if (geocode == null || geocode.length() == 0 || spoilers == null) {
+ if (StringUtils.isBlank(geocode) || spoilers == null) {
return false;
}
@@ -1471,10 +1485,11 @@ public class cgData {
if (!spoilers.isEmpty()) {
ContentValues values = new ContentValues();
+ long timeStamp = System.currentTimeMillis();
for (cgImage oneSpoiler : spoilers) {
values.clear();
values.put("geocode", geocode);
- values.put("updated", System.currentTimeMillis());
+ values.put("updated", timeStamp);
values.put("url", oneSpoiler.url);
values.put("title", oneSpoiler.title);
values.put("description", oneSpoiler.description);
@@ -1490,14 +1505,14 @@ public class cgData {
return true;
}
- public boolean saveLogs(String geocode, ArrayList<cgLog> logs) {
+ public boolean saveLogs(String geocode, List<cgLog> logs) {
return saveLogs(geocode, logs, true);
}
- public boolean saveLogs(String geocode, ArrayList<cgLog> logs, boolean drop) {
+ public boolean saveLogs(String geocode, List<cgLog> logs, boolean drop) {
init();
- if (geocode == null || geocode.length() == 0 || logs == null) {
+ if (StringUtils.isBlank(geocode) || logs == null) {
return false;
}
@@ -1510,11 +1525,12 @@ public class cgData {
if (!logs.isEmpty()) {
InsertHelper helper = new InsertHelper(databaseRW, dbTableLogs);
+ long timeStamp = System.currentTimeMillis();
for (cgLog log : logs) {
helper.prepareForInsert();
helper.bind(LOGS_GEOCODE, geocode);
- helper.bind(LOGS_UPDATED, System.currentTimeMillis());
+ helper.bind(LOGS_UPDATED, timeStamp);
helper.bind(LOGS_TYPE, log.type);
helper.bind(LOGS_AUTHOR, log.author);
helper.bind(LOGS_LOG, log.log);
@@ -1523,7 +1539,7 @@ public class cgData {
long log_id = helper.execute();
- if ((log.logImages != null) && (log.logImages.size() > 0)) {
+ if (CollectionUtils.isNotEmpty(log.logImages)) {
ContentValues values = new ContentValues();
for (cgImage img : log.logImages) {
values.clear();
@@ -1544,14 +1560,14 @@ public class cgData {
return true;
}
- public boolean saveLogCount(String geocode, HashMap<Integer, Integer> logCounts) {
+ public boolean saveLogCount(String geocode, Map<Integer, Integer> logCounts) {
return saveLogCount(geocode, logCounts, true);
}
- public boolean saveLogCount(String geocode, HashMap<Integer, Integer> logCounts, boolean drop) {
+ public boolean saveLogCount(String geocode, Map<Integer, Integer> logCounts, boolean drop) {
init();
- if (geocode == null || geocode.length() == 0 || logCounts == null || logCounts.isEmpty()) {
+ if (StringUtils.isBlank(geocode) || CollectionUtils.isEmpty(logCounts)) {
return false;
}
@@ -1564,10 +1580,11 @@ public class cgData {
ContentValues values = new ContentValues();
Set<Entry<Integer, Integer>> logCountsItems = logCounts.entrySet();
+ long timeStamp = System.currentTimeMillis();
for (Entry<Integer, Integer> pair : logCountsItems) {
values.clear();
values.put("geocode", geocode);
- values.put("updated", System.currentTimeMillis());
+ values.put("updated", timeStamp);
values.put("type", pair.getKey().intValue());
values.put("count", pair.getValue().intValue());
@@ -1581,7 +1598,7 @@ public class cgData {
return true;
}
- public boolean saveInventory(String geocode, ArrayList<cgTrackable> trackables) {
+ public boolean saveInventory(String geocode, List<cgTrackable> trackables) {
init();
if (trackables == null) {
@@ -1596,12 +1613,13 @@ public class cgData {
if (!trackables.isEmpty()) {
ContentValues values = new ContentValues();
+ long timeStamp = System.currentTimeMillis();
for (cgTrackable oneTrackable : trackables) {
values.clear();
if (geocode != null) {
values.put("geocode", geocode);
}
- values.put("updated", System.currentTimeMillis());
+ values.put("updated", timeStamp);
values.put("tbcode", oneTrackable.geocode);
values.put("guid", oneTrackable.guid);
values.put("title", oneTrackable.name);
@@ -1627,12 +1645,12 @@ public class cgData {
return true;
}
- public ArrayList<Object> getBounds(Object[] geocodes) {
+ public List<Object> getBounds(Object[] geocodes) {
init();
Cursor cursor = null;
- final ArrayList<Object> viewport = new ArrayList<Object>();
+ final List<Object> viewport = new ArrayList<Object>();
try {
final StringBuilder where = new StringBuilder();
@@ -1698,19 +1716,19 @@ public class cgData {
Object[] geocodes = new Object[1];
Object[] guids = new Object[1];
- if (geocode != null && geocode.length() > 0) {
+ if (StringUtils.isNotBlank(geocode)) {
geocodes[0] = geocode;
} else {
geocodes = null;
}
- if (guid != null && guid.length() > 0) {
+ if (StringUtils.isNotBlank(guid)) {
guids[0] = guid;
} else {
guids = null;
}
- ArrayList<cgCache> caches = loadCaches(geocodes, guids, null, null, null, null, loadA, loadW, loadS, loadL, loadI, loadO);
+ List<cgCache> caches = loadCaches(geocodes, guids, null, null, null, null, loadA, loadW, loadS, loadL, loadI, loadO);
if (caches != null && caches.isEmpty() == false) {
return caches.get(0);
}
@@ -1718,11 +1736,11 @@ public class cgData {
return null;
}
- public ArrayList<cgCache> loadCaches(Object[] geocodes, Object[] guids) {
+ public List<cgCache> loadCaches(Object[] geocodes, Object[] guids) {
return loadCaches(geocodes, guids, null, null, null, null, false, true, false, false, false, false);
}
- public ArrayList<cgCache> loadCaches(Object[] geocodes, Object[] guids, boolean lite) {
+ public List<cgCache> loadCaches(Object[] geocodes, Object[] guids, boolean lite) {
if (lite) {
return loadCaches(geocodes, guids, null, null, null, null, false, true, false, false, false, false);
} else {
@@ -1730,12 +1748,12 @@ public class cgData {
}
}
- public ArrayList<cgCache> loadCaches(Object[] geocodes, Object[] guids, Long centerLat, Long centerLon, Long spanLat, Long spanLon, boolean loadA, boolean loadW, boolean loadS, boolean loadL, boolean loadI, boolean loadO) {
+ public List<cgCache> loadCaches(Object[] geocodes, Object[] guids, Long centerLat, Long centerLon, Long spanLat, Long spanLon, boolean loadA, boolean loadW, boolean loadS, boolean loadL, boolean loadI, boolean loadO) {
init();
StringBuilder where = new StringBuilder();
Cursor cursor = null;
- ArrayList<cgCache> caches = new ArrayList<cgCache>();
+ List<cgCache> caches = new ArrayList<cgCache>();
try {
if (geocodes != null && geocodes.length > 0) {
@@ -1901,7 +1919,7 @@ public class cgData {
cache.onWatchlist = cursor.getLong(cursor.getColumnIndex("onWatchlist")) == 1L;
if (loadA) {
- ArrayList<String> attributes = loadAttributes(cache.geocode);
+ List<String> attributes = loadAttributes(cache.geocode);
if (attributes != null && attributes.isEmpty() == false) {
if (cache.attributes == null)
cache.attributes = new ArrayList<String>();
@@ -1912,7 +1930,7 @@ public class cgData {
}
if (loadW) {
- ArrayList<cgWaypoint> waypoints = loadWaypoints(cache.geocode);
+ List<cgWaypoint> waypoints = loadWaypoints(cache.geocode);
if (waypoints != null && waypoints.isEmpty() == false) {
if (cache.waypoints == null)
cache.waypoints = new ArrayList<cgWaypoint>();
@@ -1923,7 +1941,7 @@ public class cgData {
}
if (loadS) {
- ArrayList<cgImage> spoilers = loadSpoilers(cache.geocode);
+ List<cgImage> spoilers = loadSpoilers(cache.geocode);
if (spoilers != null && spoilers.isEmpty() == false) {
if (cache.spoilers == null)
cache.spoilers = new ArrayList<cgImage>();
@@ -1934,7 +1952,7 @@ public class cgData {
}
if (loadL) {
- ArrayList<cgLog> logs = loadLogs(cache.geocode);
+ List<cgLog> logs = loadLogs(cache.geocode);
if (logs != null && logs.isEmpty() == false) {
if (cache.logs == null)
cache.logs = new ArrayList<cgLog>();
@@ -1942,7 +1960,7 @@ public class cgData {
cache.logs.clear();
cache.logs.addAll(logs);
}
- HashMap<Integer, Integer> logCounts = loadLogCounts(cache.geocode);
+ Map<Integer, Integer> logCounts = loadLogCounts(cache.geocode);
if (logCounts != null && logCounts.isEmpty() == false) {
cache.logCounts.clear();
cache.logCounts.putAll(logCounts);
@@ -1950,7 +1968,7 @@ public class cgData {
}
if (loadI) {
- ArrayList<cgTrackable> inventory = loadInventory(cache.geocode);
+ List<cgTrackable> inventory = loadInventory(cache.geocode);
if (inventory != null && inventory.isEmpty() == false) {
if (cache.inventory == null)
cache.inventory = new ArrayList<cgTrackable>();
@@ -1985,8 +2003,8 @@ public class cgData {
return caches;
}
- public ArrayList<String> loadAttributes(String geocode) {
- if (geocode == null || geocode.length() == 0) {
+ public List<String> loadAttributes(String geocode) {
+ if (StringUtils.isBlank(geocode)) {
return null;
}
@@ -2051,14 +2069,14 @@ public class cgData {
return waypoint;
}
- public ArrayList<cgWaypoint> loadWaypoints(String geocode) {
- if (geocode == null || geocode.length() == 0) {
+ public List<cgWaypoint> loadWaypoints(String geocode) {
+ if (StringUtils.isBlank(geocode)) {
return null;
}
init();
- ArrayList<cgWaypoint> waypoints = new ArrayList<cgWaypoint>();
+ List<cgWaypoint> waypoints = new ArrayList<cgWaypoint>();
Cursor cursor = databaseRO.query(
dbTableWaypoints,
@@ -2116,14 +2134,14 @@ public class cgData {
return waypoint;
}
- public ArrayList<cgImage> loadSpoilers(String geocode) {
- if (geocode == null || geocode.length() == 0) {
+ public List<cgImage> loadSpoilers(String geocode) {
+ if (StringUtils.isBlank(geocode)) {
return null;
}
init();
- ArrayList<cgImage> spoilers = new ArrayList<cgImage>();
+ List<cgImage> spoilers = new ArrayList<cgImage>();
Cursor cursor = databaseRO.query(
dbTableSpoilers,
@@ -2211,14 +2229,14 @@ public class cgData {
return success;
}
- public ArrayList<cgLog> loadLogs(String geocode) {
- if (geocode == null || geocode.length() == 0) {
+ public List<cgLog> loadLogs(String geocode) {
+ if (StringUtils.isBlank(geocode)) {
return null;
}
init();
- ArrayList<cgLog> logs = new ArrayList<cgLog>();
+ List<cgLog> logs = new ArrayList<cgLog>();
Cursor cursor = databaseRO.query(
dbTableLogs,
@@ -2254,14 +2272,14 @@ public class cgData {
return logs;
}
- public HashMap<Integer, Integer> loadLogCounts(String geocode) {
- if (geocode == null || geocode.length() == 0) {
+ public Map<Integer, Integer> loadLogCounts(String geocode) {
+ if (StringUtils.isBlank(geocode)) {
return null;
}
init();
- HashMap<Integer, Integer> logCounts = new HashMap<Integer, Integer>();
+ Map<Integer, Integer> logCounts = new HashMap<Integer, Integer>();
Cursor cursor = databaseRO.query(
dbTableLogCount,
@@ -2291,10 +2309,10 @@ public class cgData {
return logCounts;
}
- public ArrayList<cgImage> loadLogImages(int log_id) {
+ public List<cgImage> loadLogImages(int log_id) {
init();
- ArrayList<cgImage> logImgList = new ArrayList<cgImage>();
+ List<cgImage> logImgList = new ArrayList<cgImage>();
Cursor cursor = databaseRO.query(
dbTableLogImages,
@@ -2324,14 +2342,14 @@ public class cgData {
return logImgList;
}
- public ArrayList<cgTrackable> loadInventory(String geocode) {
- if (geocode == null || geocode.length() == 0) {
+ public List<cgTrackable> loadInventory(String geocode) {
+ if (StringUtils.isBlank(geocode)) {
return null;
}
init();
- ArrayList<cgTrackable> trackables = new ArrayList<cgTrackable>();
+ List<cgTrackable> trackables = new ArrayList<cgTrackable>();
Cursor cursor = databaseRO.query(
dbTableTrackables,
@@ -2340,7 +2358,7 @@ public class cgData {
null,
null,
null,
- null,
+ "title COLLATE NOCASE ASC",
"100");
if (cursor != null && cursor.getCount() > 0) {
@@ -2361,7 +2379,7 @@ public class cgData {
}
public cgTrackable loadTrackable(String geocode) {
- if (geocode == null || geocode.length() == 0) {
+ if (StringUtils.isBlank(geocode)) {
return null;
}
@@ -2464,14 +2482,14 @@ public class cgData {
return count;
}
- public ArrayList<String> loadBatchOfStoredGeocodes(boolean detailedOnly, Double latitude, Double longitude, String cachetype, int list) {
+ public List<String> loadBatchOfStoredGeocodes(boolean detailedOnly, Double latitude, Double longitude, String cachetype, int list) {
init();
if (list < 1) {
list = 1;
}
- ArrayList<String> geocodes = new ArrayList<String>();
+ List<String> geocodes = new ArrayList<String>();
StringBuilder specifySql = new StringBuilder();
@@ -2520,10 +2538,10 @@ public class cgData {
return geocodes;
}
- public ArrayList<String> loadBatchOfHistoricGeocodes(boolean detailedOnly, String cachetype) {
+ public List<String> loadBatchOfHistoricGeocodes(boolean detailedOnly, String cachetype) {
init();
- ArrayList<String> geocodes = new ArrayList<String>();
+ List<String> geocodes = new ArrayList<String>();
StringBuilder specifySql = new StringBuilder();
specifySql.append("visiteddate > 0");
@@ -2569,22 +2587,22 @@ public class cgData {
return geocodes;
}
- public ArrayList<String> getCachedInViewport(Long centerLat, Long centerLon, Long spanLat, Long spanLon, String cachetype) {
+ public List<String> getCachedInViewport(Long centerLat, Long centerLon, Long spanLat, Long spanLon, String cachetype) {
return getInViewport(false, centerLat, centerLon, spanLat, spanLon, cachetype);
}
- public ArrayList<String> getStoredInViewport(Long centerLat, Long centerLon, Long spanLat, Long spanLon, String cachetype) {
+ public List<String> getStoredInViewport(Long centerLat, Long centerLon, Long spanLat, Long spanLon, String cachetype) {
return getInViewport(true, centerLat, centerLon, spanLat, spanLon, cachetype);
}
- public ArrayList<String> getInViewport(boolean stored, Long centerLat, Long centerLon, Long spanLat, Long spanLon, String cachetype) {
+ public List<String> getInViewport(boolean stored, Long centerLat, Long centerLon, Long spanLat, Long spanLon, String cachetype) {
if (centerLat == null || centerLon == null || spanLat == null || spanLon == null) {
return null;
}
init();
- ArrayList<String> geocodes = new ArrayList<String>();
+ List<String> geocodes = new ArrayList<String>();
// viewport limitation
double latMin = (centerLat / 1e6) - ((spanLat / 1e6) / 2) - ((spanLat / 1e6) / 4);
@@ -2658,10 +2676,10 @@ public class cgData {
return geocodes;
}
- public ArrayList<String> getOfflineAll(String cachetype) {
+ public List<String> getOfflineAll(String cachetype) {
init();
- ArrayList<String> geocodes = new ArrayList<String>();
+ List<String> geocodes = new ArrayList<String>();
StringBuilder where = new StringBuilder();
@@ -2710,7 +2728,7 @@ public class cgData {
}
public void markStored(String geocode, int listId) {
- if (geocode == null || geocode.length() == 0) {
+ if (StringUtils.isBlank(geocode)) {
return;
}
@@ -2726,7 +2744,7 @@ public class cgData {
}
public boolean markDropped(String geocode) {
- if (geocode == null || geocode.length() == 0) {
+ if (StringUtils.isBlank(geocode)) {
return false;
}
@@ -2748,7 +2766,7 @@ public class cgData {
}
public boolean markFound(String geocode) {
- if (geocode == null || geocode.length() == 0) {
+ if (StringUtils.isBlank(geocode)) {
return false;
}
@@ -2779,7 +2797,7 @@ public class cgData {
Log.d(cgSettings.tag, "Database clean: started");
Cursor cursor = null;
- ArrayList<String> geocodes = new ArrayList<String>();
+ List<String> geocodes = new ArrayList<String>();
try {
if (more) {
@@ -2851,7 +2869,7 @@ public class cgData {
public void dropStored(int listId) {
init();
- ArrayList<String> geocodes = new ArrayList<String>();
+ List<String> geocodes = new ArrayList<String>();
try {
Cursor cursor = databaseRO.query(
@@ -2879,7 +2897,7 @@ public class cgData {
cursor.close();
}
- if (geocodes.size() > 0) {
+ if (CollectionUtils.isNotEmpty(geocodes)) {
String geocodeList = cgBase.implode(", ", geocodes.toArray());
databaseRW.execSQL("delete from " + dbTableCaches + " where geocode in (" + geocodeList + ")");
databaseRW.execSQL("delete from " + dbTableAttributes + " where geocode in (" + geocodeList + ")");
@@ -2898,10 +2916,10 @@ public class cgData {
}
public boolean saveLogOffline(String geocode, Date date, int type, String log) {
- if (geocode == null || geocode.length() == 0) {
+ if (StringUtils.isBlank(geocode)) {
return false;
}
- if (type <= 0 && (log == null || log.length() == 0)) {
+ if (type <= 0 && StringUtils.isBlank(log)) {
return false;
}
@@ -2936,7 +2954,7 @@ public class cgData {
}
public cgLog loadLogOffline(String geocode) {
- if (geocode == null || geocode.length() == 0) {
+ if (StringUtils.isBlank(geocode)) {
return null;
}
@@ -2972,7 +2990,7 @@ public class cgData {
}
public void clearLogOffline(String geocode) {
- if (geocode == null || geocode.length() == 0) {
+ if (StringUtils.isBlank(geocode)) {
return;
}
@@ -2982,7 +3000,7 @@ public class cgData {
}
public boolean hasLogOffline(String geocode) {
- if (geocode == null || geocode.length() == 0) {
+ if (StringUtils.isBlank(geocode)) {
return false;
}
@@ -3001,7 +3019,7 @@ public class cgData {
}
public void saveVisitDate(String geocode) {
- if (geocode == null || geocode.length() == 0) {
+ if (StringUtils.isBlank(geocode)) {
return;
}
@@ -3016,7 +3034,7 @@ public class cgData {
}
public void clearVisitDate(String geocode) {
- if (geocode == null || geocode.length() == 0) {
+ if (StringUtils.isBlank(geocode)) {
return;
}
@@ -3030,10 +3048,10 @@ public class cgData {
}
}
- public ArrayList<cgList> getLists(Resources res) {
+ public List<cgList> getLists(Resources res) {
init();
- ArrayList<cgList> lists = new ArrayList<cgList>();
+ List<cgList> lists = new ArrayList<cgList>();
lists.add(new cgList(true, 1, res.getString(R.string.list_inbox)));
// lists.add(new cgList(true, 2, res.getString(R.string.list_wpt)));
@@ -3123,7 +3141,7 @@ public class cgData {
public int createList(String name) {
int id = -1;
- if (name == null || name.length() == 0) {
+ if (StringUtils.isBlank(name)) {
return id;
}
@@ -3177,7 +3195,7 @@ public class cgData {
}
public void moveToList(String geocode, int listId) {
- if (geocode == null || geocode.length() == 0 || listId <= 0) {
+ if (StringUtils.isBlank(geocode) || listId <= 0) {
return;
}
@@ -3203,7 +3221,7 @@ public class cgData {
public boolean removeSearchedDestination(cgDestination destination) {
boolean success = true;
- if(destination == null){
+ if (destination == null){
success = false;
} else{
init();
diff --git a/src/cgeo/geocaching/cgDirectionImg.java b/src/cgeo/geocaching/cgDirectionImg.java
index 573cf47..1f513d3 100644
--- a/src/cgeo/geocaching/cgDirectionImg.java
+++ b/src/cgeo/geocaching/cgDirectionImg.java
@@ -5,6 +5,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
@@ -20,11 +21,11 @@ public class cgDirectionImg {
String dirName;
String fileName;
- if (geocode == null || geocode.length() == 0 || code == null || code.length() == 0) {
+ if (StringUtils.isBlank(geocode) || StringUtils.isBlank(code)) {
return;
}
- if (geocode != null && geocode.length() > 0) {
+ if (StringUtils.isNotBlank(geocode)) {
dirName = cgSettings.getStorage() + geocode + "/";
fileName = cgSettings.getStorage() + geocode + "/direction.png";
} else {
diff --git a/src/cgeo/geocaching/cgGeo.java b/src/cgeo/geocaching/cgGeo.java
index 8a191dd..bcc0de1 100644
--- a/src/cgeo/geocaching/cgGeo.java
+++ b/src/cgeo/geocaching/cgGeo.java
@@ -3,6 +3,9 @@ package cgeo.geocaching;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
import android.content.Context;
import android.content.SharedPreferences;
@@ -394,7 +397,7 @@ public class cgGeo {
final String username = settings.getUsername();
if (username != null) {
- final HashMap<String, String> params = new HashMap<String, String>();
+ final Map<String, String> params = new HashMap<String, String>();
final String latStr = String.format((Locale) null, "%.6f", latitudeNow);
final String lonStr = String.format((Locale) null, "%.6f", longitudeNow);
params.put("u", username);
@@ -407,7 +410,7 @@ public class cgGeo {
}
final String res = base.request(false, host, path, method, params, false, false, false).getData();
- if (res != null && res.length() > 0) {
+ if (StringUtils.isNotBlank(res)) {
lastGo4cacheLat = latitudeNow;
lastGo4cacheLon = longitudeNow;
}
diff --git a/src/cgeo/geocaching/cgHtmlImg.java b/src/cgeo/geocaching/cgHtmlImg.java
index e6e5a2e..cfb7cab 100644
--- a/src/cgeo/geocaching/cgHtmlImg.java
+++ b/src/cgeo/geocaching/cgHtmlImg.java
@@ -6,6 +6,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
+import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
@@ -67,7 +68,7 @@ public class cgHtmlImg implements Html.ImageGetter {
String fileName = null;
String fileNameSec = null;
- if (url == null || url.length() == 0) {
+ if (StringUtils.isBlank(url)) {
return null;
}
@@ -82,7 +83,7 @@ public class cgHtmlImg implements Html.ImageGetter {
urlExt = "";
}
- if (geocode != null && geocode.length() > 0) {
+ if (StringUtils.isNotBlank(geocode)) {
dirName = cgSettings.getStorage() + geocode + "/";
fileName = cgSettings.getStorage() + geocode + "/" + cgBase.md5(url) + urlExt;
fileNameSec = cgSettings.getStorageSec() + geocode + "/" + cgBase.md5(url) + urlExt;
diff --git a/src/cgeo/geocaching/cgLog.java b/src/cgeo/geocaching/cgLog.java
index 2d77a3d..ebf5699 100644
--- a/src/cgeo/geocaching/cgLog.java
+++ b/src/cgeo/geocaching/cgLog.java
@@ -1,6 +1,6 @@
package cgeo.geocaching;
-import java.util.ArrayList;
+import java.util.List;
public class cgLog {
public int id = 0;
@@ -9,7 +9,7 @@ public class cgLog {
public String log = "";
public long date = 0;
public int found = -1;
- public ArrayList<cgImage> logImages = null;
+ public List<cgImage> logImages = null;
public String cacheName = ""; // used for trackables
public String cacheGuid = ""; // used for trackables
}
diff --git a/src/cgeo/geocaching/cgOAuth.java b/src/cgeo/geocaching/cgOAuth.java
index 46e9c7d..13a1eb2 100644
--- a/src/cgeo/geocaching/cgOAuth.java
+++ b/src/cgeo/geocaching/cgOAuth.java
@@ -3,10 +3,11 @@ package cgeo.geocaching;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
-import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
public class cgOAuth {
- public static String signOAuth(String host, String path, String method, boolean https, HashMap<String, String> params, String token, String tokenSecret) {
+ public static String signOAuth(String host, String path, String method, boolean https, Map<String, String> params, String token, String tokenSecret) {
String paramsDone = "";
if (method.equalsIgnoreCase("GET") == false && method.equalsIgnoreCase("POST") == false) {
method = "POST";
@@ -32,7 +33,7 @@ public class cgOAuth {
params.keySet().toArray(keys);
Arrays.sort(keys);
- ArrayList<String> paramsEncoded = new ArrayList<String>();
+ List<String> paramsEncoded = new ArrayList<String>();
for (String key : keys) {
String value = params.get(key);
paramsEncoded.add(key + "=" + cgBase.urlencode_rfc3986(value));
diff --git a/src/cgeo/geocaching/cgSearch.java b/src/cgeo/geocaching/cgSearch.java
index f434660..76599b2 100644
--- a/src/cgeo/geocaching/cgSearch.java
+++ b/src/cgeo/geocaching/cgSearch.java
@@ -1,26 +1,27 @@
package cgeo.geocaching;
import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
public class cgSearch {
- private Long id = null;
- private ArrayList<String> geocodes = new ArrayList<String>();
+ private UUID id;
+ private List<String> geocodes = new ArrayList<String>();
- public int errorRetrieve = 0;
public String error = null;
public String url = "";
public String[] viewstates = null;
public int totalCnt = 0;
public cgSearch() {
- id = System.currentTimeMillis(); // possible collisions here - not guaranteed to be unique
+ id = UUID.randomUUID();
}
- public Long getCurrentId() {
+ public UUID getCurrentId() {
return id;
}
- public ArrayList<String> getGeocodes() {
+ public List<String> getGeocodes() {
return geocodes;
}
diff --git a/src/cgeo/geocaching/cgSelectMapfile.java b/src/cgeo/geocaching/cgSelectMapfile.java
index e9bed60..9ce9dd2 100644
--- a/src/cgeo/geocaching/cgSelectMapfile.java
+++ b/src/cgeo/geocaching/cgSelectMapfile.java
@@ -1,13 +1,12 @@
package cgeo.geocaching;
import java.io.File;
-import java.util.ArrayList;
-
-import cgeo.geocaching.files.FileList;
+import java.util.List;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
+import cgeo.geocaching.files.FileList;
public class cgSelectMapfile extends FileList<cgMapfileListAdapter> {
@@ -35,7 +34,7 @@ public class cgSelectMapfile extends FileList<cgMapfileListAdapter> {
}
@Override
- protected cgMapfileListAdapter getAdapter(ArrayList<File> files) {
+ protected cgMapfileListAdapter getAdapter(List<File> files) {
return new cgMapfileListAdapter(this, files);
}
diff --git a/src/cgeo/geocaching/cgSettings.java b/src/cgeo/geocaching/cgSettings.java
index 57cdf51..a1d2a59 100644
--- a/src/cgeo/geocaching/cgSettings.java
+++ b/src/cgeo/geocaching/cgSettings.java
@@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
import org.mapsforge.android.maps.MapDatabase;
import android.content.Context;
@@ -16,6 +17,7 @@ import android.util.Log;
import cgeo.geocaching.googlemaps.googleMapFactory;
import cgeo.geocaching.mapinterfaces.MapFactory;
import cgeo.geocaching.mapsforge.mfMapFactory;
+import cgeo.geocaching.utils.CollectionUtils;
/**
* General c:geo preferences/settings set by the user
@@ -153,7 +155,7 @@ public class cgSettings {
public boolean signatureAutoinsert = false;
// usable values
- public static final String tag = "c:geo";
+ public static final String tag = "cgeo";
/** Name of the preferences file */
public static final String preferences = "cgeo.pref";
@@ -272,15 +274,15 @@ public class cgSettings {
final String preUsername = prefs.getString(KEY_USERNAME, null);
final String prePassword = prefs.getString(KEY_PASSWORD, null);
- if (preUsername == null || prePassword == null || preUsername.length() == 0 || prePassword.length() == 0) {
+ if (StringUtils.isBlank(preUsername) || StringUtils.isBlank(prePassword)) {
return false;
} else {
return true;
}
}
- public HashMap<String, String> getLogin() {
- final HashMap<String, String> login = new HashMap<String, String>();
+ public Map<String, String> getLogin() {
+ final Map<String, String> login = new HashMap<String, String>();
if (username == null || password == null) {
final String preUsername = prefs.getString(KEY_USERNAME, null);
@@ -329,7 +331,7 @@ public class cgSettings {
@Override
public void edit(Editor edit) {
- if (username == null || username.length() == 0 || password == null || password.length() == 0) {
+ if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) {
// erase username and password
edit.remove(KEY_USERNAME);
edit.remove(KEY_PASSWORD);
@@ -346,7 +348,7 @@ public class cgSettings {
final String preUsername = prefs.getString(KEY_USERNAME, null);
final String prePassword = prefs.getString(KEY_GCVOTE_PASSWORD, null);
- if (preUsername == null || prePassword == null || preUsername.length() == 0 || prePassword.length() == 0) {
+ if (StringUtils.isBlank(preUsername) || StringUtils.isBlank(prePassword)) {
return false;
} else {
return true;
@@ -358,7 +360,7 @@ public class cgSettings {
@Override
public void edit(Editor edit) {
- if (password == null || password.length() == 0) {
+ if (StringUtils.isBlank(password)) {
// erase password
edit.remove(KEY_GCVOTE_PASSWORD);
} else {
@@ -369,8 +371,8 @@ public class cgSettings {
});
}
- public HashMap<String, String> getGCvoteLogin() {
- final HashMap<String, String> login = new HashMap<String, String>();
+ public Map<String, String> getGCvoteLogin() {
+ final Map<String, String> login = new HashMap<String, String>();
if (username == null || password == null) {
final String preUsername = prefs.getString(KEY_USERNAME, null);
@@ -397,7 +399,7 @@ public class cgSettings {
@Override
public void edit(Editor edit) {
- if (signature == null || signature.length() == 0) {
+ if (StringUtils.isBlank(signature)) {
// erase signature
edit.remove(KEY_SIGNATURE);
} else {
@@ -431,7 +433,7 @@ public class cgSettings {
// delete cookies
Map<String, ?> prefsValues = prefs.getAll();
- if (prefsValues != null && prefsValues.size() > 0) {
+ if (CollectionUtils.isNotEmpty(prefsValues)) {
Log.i(cgSettings.tag, "Removing cookies");
for (String key : prefsValues.keySet()) {
diff --git a/src/cgeo/geocaching/cgTrackable.java b/src/cgeo/geocaching/cgTrackable.java
index 2244fc7..1ab3e8c 100644
--- a/src/cgeo/geocaching/cgTrackable.java
+++ b/src/cgeo/geocaching/cgTrackable.java
@@ -1,8 +1,10 @@
package cgeo.geocaching;
-import android.text.Spannable;
import java.util.ArrayList;
import java.util.Date;
+import java.util.List;
+
+import android.text.Spannable;
public class cgTrackable {
static public int SPOTTED_UNSET = 0;
@@ -31,5 +33,5 @@ public class cgTrackable {
public String goal = null;
public String details = null;
public String image = null;
- public ArrayList<cgLog> logs = new ArrayList<cgLog>();
+ public List<cgLog> logs = new ArrayList<cgLog>();
}
diff --git a/src/cgeo/geocaching/cgWaypoint.java b/src/cgeo/geocaching/cgWaypoint.java
index 7746c2c..5876bbc 100644
--- a/src/cgeo/geocaching/cgWaypoint.java
+++ b/src/cgeo/geocaching/cgWaypoint.java
@@ -1,6 +1,8 @@
package cgeo.geocaching;
-import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
@@ -32,22 +34,22 @@ public class cgWaypoint {
}
public void merge(final cgWaypoint old) {
- if (prefix == null || prefix.length() == 0) {
+ if (StringUtils.isBlank(prefix)) {
prefix = old.prefix;
}
- if (lookup == null || lookup.length() == 0) {
+ if (StringUtils.isBlank(lookup)) {
lookup = old.lookup;
}
- if (name == null || name.length() == 0) {
+ if (StringUtils.isBlank(name)) {
name = old.name;
}
- if (latlon == null || latlon.length() == 0) {
+ if (StringUtils.isBlank(latlon)) {
latlon = old.latlon;
}
- if (latitudeString == null || latitudeString.length() == 0) {
+ if (StringUtils.isBlank(latitudeString)) {
latitudeString = old.latitudeString;
}
- if (longitudeString == null || longitudeString.length() == 0) {
+ if (StringUtils.isBlank(longitudeString)) {
longitudeString = old.longitudeString;
}
if (latitude == null) {
@@ -56,7 +58,7 @@ public class cgWaypoint {
if (longitude == null) {
longitude = old.longitude;
}
- if (note == null || note.length() == 0) {
+ if (StringUtils.isBlank(note)) {
note = old.note;
}
if (note != null && old.note != null) {
@@ -66,8 +68,8 @@ public class cgWaypoint {
}
}
- public static void mergeWayPoints(ArrayList<cgWaypoint> newPoints,
- ArrayList<cgWaypoint> oldPoints) {
+ public static void mergeWayPoints(List<cgWaypoint> newPoints,
+ List<cgWaypoint> oldPoints) {
// copy user modified details of the waypoints
if (newPoints != null && oldPoints != null) {
for (cgWaypoint old : oldPoints) {
diff --git a/src/cgeo/geocaching/cgeo.java b/src/cgeo/geocaching/cgeo.java
index 6384fb1..ceaf3b9 100644
--- a/src/cgeo/geocaching/cgeo.java
+++ b/src/cgeo/geocaching/cgeo.java
@@ -5,8 +5,11 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
import java.util.Map.Entry;
+import org.apache.commons.lang3.StringUtils;
+
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -28,6 +31,7 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.activity.ActivityMixin;
+import cgeo.geocaching.utils.CollectionUtils;
public class cgeo extends AbstractActivity {
@@ -83,7 +87,7 @@ public class cgeo extends AbstractActivity {
@Override
public void handleMessage(Message msg) {
try {
- if (addresses != null && addresses.isEmpty() == false) {
+ if (CollectionUtils.isNotEmpty(addresses)) {
final Address address = addresses.get(0);
final StringBuilder addText = new StringBuilder();
@@ -286,7 +290,7 @@ public class cgeo extends AbstractActivity {
if (requestCode == SCAN_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
String scan = intent.getStringExtra("SCAN_RESULT");
- if (scan == null || scan.length() == 0) {
+ if (StringUtils.isBlank(scan)) {
return;
}
String host = "http://coord.info/";
@@ -309,7 +313,7 @@ public class cgeo extends AbstractActivity {
// context menu for offline button
if (v.getId() == R.id.search_offline) {
- ArrayList<cgList> cacheLists = app.getLists();
+ List<cgList> cacheLists = app.getLists();
int listCount = cacheLists.size();
menu.setHeaderTitle(res.getString(R.string.list_title));
for (int i = 0; i < listCount; i++) {
@@ -329,11 +333,11 @@ public class cgeo extends AbstractActivity {
menu.add(1, 3, 0, res.getString(R.string.mystery));
// then add all other cache types sorted alphabetically
- HashMap<String, String> allTypes = new HashMap<String, String>(cgBase.cacheTypesInv);
+ Map<String, String> allTypes = new HashMap<String, String>(cgBase.cacheTypesInv);
allTypes.remove("traditional");
allTypes.remove("multi");
allTypes.remove("mystery");
- ArrayList<String> sorted = new ArrayList<String>(allTypes.values());
+ List<String> sorted = new ArrayList<String>(allTypes.values());
Collections.sort(sorted);
for (String choice : sorted) {
menu.add(1, menu.size(), 0, choice);
diff --git a/src/cgeo/geocaching/cgeoaddresses.java b/src/cgeo/geocaching/cgeoaddresses.java
index 797c018..2320cb9 100644
--- a/src/cgeo/geocaching/cgeoaddresses.java
+++ b/src/cgeo/geocaching/cgeoaddresses.java
@@ -19,7 +19,7 @@ import android.widget.LinearLayout;
import cgeo.geocaching.activity.AbstractActivity;
public class cgeoaddresses extends AbstractActivity {
- private final ArrayList<Address> addresses = new ArrayList<Address>();
+ private final List<Address> addresses = new ArrayList<Address>();
private String keyword = null;
private LayoutInflater inflater = null;
private LinearLayout addList = null;
diff --git a/src/cgeo/geocaching/cgeoadvsearch.java b/src/cgeo/geocaching/cgeoadvsearch.java
index 1849faa..56fbfb7 100644
--- a/src/cgeo/geocaching/cgeoadvsearch.java
+++ b/src/cgeo/geocaching/cgeoadvsearch.java
@@ -1,9 +1,11 @@
package cgeo.geocaching;
-import java.util.HashMap;
+import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.lang3.StringUtils;
+
import android.app.SearchManager;
import android.content.Intent;
import android.content.res.Configuration;
@@ -245,12 +247,12 @@ public class cgeoadvsearch extends AbstractActivity {
final String latText = latView.getText().toString();
final String lonText = lonView.getText().toString();
- if (latText == null || latText.length() == 0 || lonText == null || lonText.length() == 0) {
+ if (StringUtils.isEmpty(latText) || StringUtils.isEmpty(lonText)) {
latView.setText(cgBase.formatLatitude(geo.latitudeNow, true));
lonView.setText(cgBase.formatLongitude(geo.longitudeNow, true));
} else {
- HashMap<String, Object> latParsed = cgBase.parseCoordinate(latText, "lat");
- HashMap<String, Object> lonParsed = cgBase.parseCoordinate(lonText, "lat");
+ Map<String, Object> latParsed = cgBase.parseCoordinate(latText, "lat");
+ Map<String, Object> lonParsed = cgBase.parseCoordinate(lonText, "lat");
if (latParsed == null || latParsed.get("coordinate") == null || latParsed.get("string") == null) {
showToast(res.getString(R.string.err_parse_lat));
@@ -295,7 +297,7 @@ public class cgeoadvsearch extends AbstractActivity {
// find caches by coordinates
String keyText = ((EditText) findViewById(R.id.keyword)).getText().toString();
- if (keyText == null || keyText.length() == 0) {
+ if (StringUtils.isBlank(keyText)) {
helpDialog(res.getString(R.string.warn_search_help_title), res.getString(R.string.warn_search_help_keyword));
return;
}
@@ -330,7 +332,7 @@ public class cgeoadvsearch extends AbstractActivity {
private void findByAddressFn() {
final String addText = ((EditText) findViewById(R.id.address)).getText().toString();
- if (addText == null || addText.length() == 0) {
+ if (StringUtils.isBlank(addText)) {
helpDialog(res.getString(R.string.warn_search_help_title), res.getString(R.string.warn_search_help_address));
return;
}
@@ -363,7 +365,7 @@ public class cgeoadvsearch extends AbstractActivity {
public void findByUsernameFn() {
final String usernameText = ((EditText) findViewById(R.id.username)).getText().toString();
- if (usernameText == null || usernameText.length() == 0) {
+ if (StringUtils.isBlank(usernameText)) {
helpDialog(res.getString(R.string.warn_search_help_title), res.getString(R.string.warn_search_help_user));
return;
}
@@ -398,7 +400,7 @@ public class cgeoadvsearch extends AbstractActivity {
private void findByOwnerFn() {
final String usernameText = ((EditText) findViewById(R.id.owner)).getText().toString();
- if (usernameText == null || usernameText.length() == 0) {
+ if (StringUtils.isBlank(usernameText)) {
helpDialog(res.getString(R.string.warn_search_help_title), res.getString(R.string.warn_search_help_user));
return;
}
@@ -433,7 +435,7 @@ public class cgeoadvsearch extends AbstractActivity {
private void findByGeocodeFn() {
final String geocodeText = ((EditText) findViewById(R.id.geocode)).getText().toString();
- if (geocodeText == null || geocodeText.length() == 0 || geocodeText.equalsIgnoreCase("GC")) {
+ if (StringUtils.isBlank(geocodeText) || geocodeText.equalsIgnoreCase("GC")) {
helpDialog(res.getString(R.string.warn_search_help_title), res.getString(R.string.warn_search_help_gccode));
return;
}
@@ -464,7 +466,7 @@ public class cgeoadvsearch extends AbstractActivity {
private void findTrackableFn() {
final String trackableText = ((EditText) findViewById(R.id.trackable)).getText().toString();
- if (trackableText == null || trackableText.length() == 0 || trackableText.equalsIgnoreCase("TB")) {
+ if (StringUtils.isBlank(trackableText)|| trackableText.equalsIgnoreCase("TB")) {
helpDialog(res.getString(R.string.warn_search_help_title), res.getString(R.string.warn_search_help_tb));
return;
}
diff --git a/src/cgeo/geocaching/cgeoapplication.java b/src/cgeo/geocaching/cgeoapplication.java
index fece371..f580fa9 100644
--- a/src/cgeo/geocaching/cgeoapplication.java
+++ b/src/cgeo/geocaching/cgeoapplication.java
@@ -5,10 +5,16 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
import android.app.Application;
import android.content.Context;
import android.util.Log;
+import cgeo.geocaching.utils.CollectionUtils;
public class cgeoapplication extends Application {
@@ -20,8 +26,8 @@ public class cgeoapplication extends Application {
private boolean geoInUse = false;
private cgDirection dir = null;
private boolean dirInUse = false;
- final private HashMap<Long, cgSearch> searches = new HashMap<Long, cgSearch>(); // information about searches
- final private HashMap<String, cgCache> cachesCache = new HashMap<String, cgCache>(); // caching caches into memory
+ final private Map<UUID, cgSearch> searches = new HashMap<UUID, cgSearch>(); // information about searches
+ final private Map<String, cgCache> cachesCache = new HashMap<String, cgCache>(); // caching caches into memory
public boolean firstRun = true; // c:geo is just launched
public boolean warnedLanguage = false; // user was warned about different language settings on geocaching.com
private boolean databaseCleaned = false; // database was cleaned
@@ -220,7 +226,7 @@ public class cgeoapplication extends Application {
return storage.getCacheidForGeocode(geocode);
}
- public String getError(Long searchId) {
+ public String getError(final UUID searchId) {
if (searchId == null || searches.containsKey(searchId) == false) {
return null;
}
@@ -228,7 +234,7 @@ public class cgeoapplication extends Application {
return searches.get(searchId).error;
}
- public boolean setError(Long searchId, String error) {
+ public boolean setError(final UUID searchId, String error) {
if (searchId == null || searches.containsKey(searchId) == false) {
return false;
}
@@ -238,7 +244,7 @@ public class cgeoapplication extends Application {
return true;
}
- public String getUrl(Long searchId) {
+ public String getUrl(final UUID searchId) {
if (searchId == null || searches.containsKey(searchId) == false) {
return null;
}
@@ -246,7 +252,7 @@ public class cgeoapplication extends Application {
return searches.get(searchId).url;
}
- public boolean setUrl(Long searchId, String url) {
+ public boolean setUrl(final UUID searchId, String url) {
if (searchId == null || searches.containsKey(searchId) == false) {
return false;
}
@@ -256,7 +262,7 @@ public class cgeoapplication extends Application {
return true;
}
- public String[] getViewstates(Long searchId) {
+ public String[] getViewstates(final UUID searchId) {
if (searchId == null || searches.containsKey(searchId) == false) {
return null;
}
@@ -264,8 +270,8 @@ public class cgeoapplication extends Application {
return searches.get(searchId).viewstates;
}
- public boolean setViewstates(Long searchId, String[] viewstates) {
- if (cgBase.isEmpty(viewstates)) {
+ public boolean setViewstates(final UUID searchId, String[] viewstates) {
+ if (ArrayUtils.isEmpty(viewstates)) {
return false;
}
if (searchId == null || searches.containsKey(searchId) == false) {
@@ -277,7 +283,7 @@ public class cgeoapplication extends Application {
return true;
}
- public Integer getTotal(Long searchId) {
+ public Integer getTotal(final UUID searchId) {
if (searchId == null || searches.containsKey(searchId) == false) {
return null;
}
@@ -285,7 +291,7 @@ public class cgeoapplication extends Application {
return searches.get(searchId).totalCnt;
}
- public Integer getCount(Long searchId) {
+ public Integer getCount(final UUID searchId) {
if (searchId == null || searches.containsKey(searchId) == false) {
return 0;
}
@@ -293,13 +299,13 @@ public class cgeoapplication extends Application {
return searches.get(searchId).getCount();
}
- public Integer getNotOfflineCount(Long searchId) {
+ public Integer getNotOfflineCount(final UUID searchId) {
if (searchId == null || searches.containsKey(searchId) == false) {
return 0;
}
int count = 0;
- ArrayList<String> geocodes = searches.get(searchId).getGeocodes();
+ List<String> geocodes = searches.get(searchId).getGeocodes();
if (geocodes != null) {
for (String geocode : geocodes) {
if (isOffline(geocode, null) == false) {
@@ -316,7 +322,7 @@ public class cgeoapplication extends Application {
}
public cgCache getCacheByGeocode(String geocode, boolean loadA, boolean loadW, boolean loadS, boolean loadL, boolean loadI, boolean loadO) {
- if (geocode == null || geocode.length() == 0) {
+ if (StringUtils.isBlank(geocode)) {
return null;
}
@@ -338,7 +344,7 @@ public class cgeoapplication extends Application {
}
public cgTrackable getTrackableByGeocode(String geocode) {
- if (geocode == null || geocode.length() == 0) {
+ if (StringUtils.isBlank(geocode)) {
return null;
}
@@ -385,7 +391,7 @@ public class cgeoapplication extends Application {
return storage.loadWaypoint(id);
}
- public ArrayList<Object> getBounds(String geocode) {
+ public List<Object> getBounds(String geocode) {
if (geocode == null) {
return null;
}
@@ -396,7 +402,7 @@ public class cgeoapplication extends Application {
return getBounds(geocodeList);
}
- public ArrayList<Object> getBounds(Long searchId) {
+ public List<Object> getBounds(final UUID searchId) {
if (searchId == null || searches.containsKey(searchId) == false) {
return null;
}
@@ -406,12 +412,12 @@ public class cgeoapplication extends Application {
}
final cgSearch search = searches.get(searchId);
- final ArrayList<String> geocodeList = search.getGeocodes();
+ final List<String> geocodeList = search.getGeocodes();
return getBounds(geocodeList);
}
- public ArrayList<Object> getBounds(List<String> geocodes) {
+ public List<Object> getBounds(List<String> geocodes) {
if (geocodes == null || geocodes.isEmpty()) {
return null;
}
@@ -423,34 +429,34 @@ public class cgeoapplication extends Application {
return storage.getBounds(geocodes.toArray());
}
- public cgCache getCache(Long searchId) {
+ public cgCache getCache(final UUID searchId) {
if (searchId == null || searches.containsKey(searchId) == false) {
return null;
}
cgSearch search = searches.get(searchId);
- ArrayList<String> geocodeList = search.getGeocodes();
+ List<String> geocodeList = search.getGeocodes();
return getCacheByGeocode(geocodeList.get(0), true, true, true, true, true, true);
}
- public ArrayList<cgCache> getCaches(Long searchId) {
+ public List<cgCache> getCaches(final UUID searchId) {
return getCaches(searchId, null, null, null, null, false, true, false, false, false, true);
}
- public ArrayList<cgCache> getCaches(Long searchId, boolean loadA, boolean loadW, boolean loadS, boolean loadL, boolean loadI, boolean loadO) {
+ public List<cgCache> getCaches(final UUID searchId, boolean loadA, boolean loadW, boolean loadS, boolean loadL, boolean loadI, boolean loadO) {
return getCaches(searchId, null, null, null, null, loadA, loadW, loadS, loadL, loadI, loadO);
}
- public ArrayList<cgCache> getCaches(Long searchId, Long centerLat, Long centerLon, Long spanLat, Long spanLon) {
+ public List<cgCache> getCaches(final UUID searchId, Long centerLat, Long centerLon, Long spanLat, Long spanLon) {
return getCaches(searchId, centerLat, centerLon, spanLat, spanLon, false, true, false, false, false, true);
}
- public ArrayList<cgCache> getCaches(Long searchId, Long centerLat, Long centerLon, Long spanLat, Long spanLon, boolean loadA, boolean loadW, boolean loadS, boolean loadL, boolean loadI, boolean loadO) {
+ public List<cgCache> getCaches(final UUID searchId, Long centerLat, Long centerLon, Long spanLat, Long spanLon, boolean loadA, boolean loadW, boolean loadS, boolean loadL, boolean loadI, boolean loadO) {
if (searchId == null || searches.containsKey(searchId) == false) {
- ArrayList<cgCache> cachesOut = new ArrayList<cgCache>();
+ List<cgCache> cachesOut = new ArrayList<cgCache>();
- final ArrayList<cgCache> cachesPre = storage.loadCaches(null , null, centerLat, centerLon, spanLat, spanLon, loadA, loadW, loadS, loadL, loadI, loadO);
+ final List<cgCache> cachesPre = storage.loadCaches(null , null, centerLat, centerLon, spanLat, spanLon, loadA, loadW, loadS, loadL, loadI, loadO);
if (cachesPre != null) {
cachesOut.addAll(cachesPre);
@@ -459,16 +465,16 @@ public class cgeoapplication extends Application {
return cachesOut;
}
- ArrayList<cgCache> cachesOut = new ArrayList<cgCache>();
+ List<cgCache> cachesOut = new ArrayList<cgCache>();
cgSearch search = searches.get(searchId);
- ArrayList<String> geocodeList = search.getGeocodes();
+ List<String> geocodeList = search.getGeocodes();
if (storage == null) {
storage = new cgData(this);
}
- final ArrayList<cgCache> cachesPre = storage.loadCaches(geocodeList.toArray(), null, centerLat, centerLon, spanLat, spanLon, loadA, loadW, loadS, loadL, loadI, loadO);
+ final List<cgCache> cachesPre = storage.loadCaches(geocodeList.toArray(), null, centerLat, centerLon, spanLat, spanLon, loadA, loadW, loadS, loadL, loadI, loadO);
if (cachesPre != null) {
cachesOut.addAll(cachesPre);
}
@@ -482,7 +488,7 @@ public class cgeoapplication extends Application {
}
cgSearch search = new cgSearch();
- ArrayList<String> geocodes = storage.loadBatchOfStoredGeocodes(detailedOnly, latitude, longitude, cachetype, list);
+ List<String> geocodes = storage.loadBatchOfStoredGeocodes(detailedOnly, latitude, longitude, cachetype, list);
if (geocodes != null && geocodes.isEmpty() == false) {
for (String gccode : geocodes) {
search.addGeocode(gccode);
@@ -507,7 +513,7 @@ public class cgeoapplication extends Application {
}
cgSearch search = new cgSearch();
- ArrayList<String> geocodes = storage.loadBatchOfHistoricGeocodes(detailedOnly, cachetype);
+ List<String> geocodes = storage.loadBatchOfHistoricGeocodes(detailedOnly, cachetype);
if (geocodes != null && geocodes.isEmpty() == false) {
for (String gccode : geocodes) {
search.addGeocode(gccode);
@@ -518,13 +524,13 @@ public class cgeoapplication extends Application {
return search;
}
- public Long getCachedInViewport(Long centerLat, Long centerLon, Long spanLat, Long spanLon, String cachetype) {
+ public UUID getCachedInViewport(Long centerLat, Long centerLon, Long spanLat, Long spanLon, String cachetype) {
if (storage == null) {
storage = new cgData(this);
}
cgSearch search = new cgSearch();
- ArrayList<String> geocodes = storage.getCachedInViewport(centerLat, centerLon, spanLat, spanLon, cachetype);
+ List<String> geocodes = storage.getCachedInViewport(centerLat, centerLon, spanLat, spanLon, cachetype);
if (geocodes != null && geocodes.isEmpty() == false) {
for (String gccode : geocodes) {
search.addGeocode(gccode);
@@ -535,13 +541,13 @@ public class cgeoapplication extends Application {
return search.getCurrentId();
}
- public Long getStoredInViewport(Long centerLat, Long centerLon, Long spanLat, Long spanLon, String cachetype) {
+ public UUID getStoredInViewport(Long centerLat, Long centerLon, Long spanLat, Long spanLon, String cachetype) {
if (storage == null) {
storage = new cgData(this);
}
cgSearch search = new cgSearch();
- ArrayList<String> geocodes = storage.getStoredInViewport(centerLat, centerLon, spanLat, spanLon, cachetype);
+ List<String> geocodes = storage.getStoredInViewport(centerLat, centerLon, spanLat, spanLon, cachetype);
if (geocodes != null && geocodes.isEmpty() == false) {
for (String gccode : geocodes) {
search.addGeocode(gccode);
@@ -552,13 +558,13 @@ public class cgeoapplication extends Application {
return search.getCurrentId();
}
- public Long getOfflineAll(String cachetype) {
+ public UUID getOfflineAll(String cachetype) {
if (storage == null) {
storage = new cgData(this);
}
cgSearch search = new cgSearch();
- ArrayList<String> geocodes = storage.getOfflineAll(cachetype);
+ List<String> geocodes = storage.getOfflineAll(cachetype);
if (geocodes != null && geocodes.isEmpty() == false) {
for (String gccode : geocodes) {
search.addGeocode(gccode);
@@ -622,7 +628,7 @@ public class cgeoapplication extends Application {
return storage.saveSearchedDestination(destination);
}
- public boolean saveWaypoints(String geocode, ArrayList<cgWaypoint> waypoints, boolean drop) {
+ public boolean saveWaypoints(String geocode, List<cgWaypoint> waypoints, boolean drop) {
if (storage == null) {
storage = new cgData(this);
}
@@ -648,21 +654,21 @@ public class cgeoapplication extends Application {
storage = new cgData(this);
}
- final ArrayList<cgTrackable> list = new ArrayList<cgTrackable>();
+ final List<cgTrackable> list = new ArrayList<cgTrackable>();
list.add(trackable);
return storage.saveInventory("---", list);
}
- public void addGeocode(Long searchId, String geocode) {
- if (this.searches.containsKey(searchId) == false || geocode == null || geocode.length() == 0) {
+ public void addGeocode(final UUID searchId, String geocode) {
+ if (this.searches.containsKey(searchId) == false || StringUtils.isBlank(geocode)) {
return;
}
this.searches.get(searchId).addGeocode(geocode);
}
- public Long addSearch(Long searchId, ArrayList<cgCache> cacheList, Boolean newItem, int reason) {
+ public UUID addSearch(final UUID searchId, List<cgCache> cacheList, Boolean newItem, int reason) {
if (this.searches.containsKey(searchId) == false) {
return null;
}
@@ -672,12 +678,12 @@ public class cgeoapplication extends Application {
return addSearch(search, cacheList, newItem, reason);
}
- public Long addSearch(final cgSearch search, final ArrayList<cgCache> cacheList, final boolean newItem, final int reason) {
- if (cacheList == null || cacheList.isEmpty()) {
+ public UUID addSearch(final cgSearch search, final List<cgCache> cacheList, final boolean newItem, final int reason) {
+ if (CollectionUtils.isEmpty(cacheList)) {
return null;
}
- final long searchId = search.getCurrentId();
+ final UUID searchId = search.getCurrentId();
searches.put(searchId, search);
if (storage == null) {
@@ -709,7 +715,7 @@ public class cgeoapplication extends Application {
return false;
}
- final long searchId = search.getCurrentId();
+ final UUID searchId = search.getCurrentId();
if (searches.containsKey(searchId) == false) {
searches.put(searchId, search);
@@ -742,15 +748,15 @@ public class cgeoapplication extends Application {
storage.dropStored(listId);
}
- public ArrayList<cgTrackable> loadInventory(String geocode) {
+ public List<cgTrackable> loadInventory(String geocode) {
return storage.loadInventory(geocode);
}
- public HashMap<Integer,Integer> loadLogCounts(String geocode) {
+ public Map<Integer,Integer> loadLogCounts(String geocode) {
return storage.loadLogCounts(geocode);
}
- public ArrayList<cgImage> loadSpoilers(String geocode) {
+ public List<cgImage> loadSpoilers(String geocode) {
return storage.loadSpoilers(geocode);
}
@@ -770,14 +776,14 @@ public class cgeoapplication extends Application {
}
public boolean addLog(String geocode, cgLog log) {
- if (geocode == null || geocode.length() == 0) {
+ if (StringUtils.isBlank(geocode)) {
return false;
}
if (log == null) {
return false;
}
- ArrayList<cgLog> list = new ArrayList<cgLog>();
+ List<cgLog> list = new ArrayList<cgLog>();
list.add(log);
return storage.saveLogs(geocode, list, false);
@@ -816,7 +822,7 @@ public class cgeoapplication extends Application {
storage.clearVisitDate(geocode);
}
- public ArrayList<cgList> getLists() {
+ public List<cgList> getLists() {
return storage.getLists(getResources());
}
diff --git a/src/cgeo/geocaching/cgeoauth.java b/src/cgeo/geocaching/cgeoauth.java
index 1c2e8bb..0554a24 100644
--- a/src/cgeo/geocaching/cgeoauth.java
+++ b/src/cgeo/geocaching/cgeoauth.java
@@ -9,11 +9,14 @@ import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
+import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.net.ssl.HttpsURLConnection;
+import org.apache.commons.lang3.StringUtils;
+
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -119,7 +122,7 @@ public class cgeoauth extends AbstractActivity {
startButton.setEnabled(true);
startButton.setOnClickListener(new startListener());
- if (OAtoken == null || OAtoken.length() == 0 || OAtokenSecret == null || OAtokenSecret.length() == 0) {
+ if (StringUtils.isNotBlank(OAtoken) && StringUtils.isNotBlank(OAtokenSecret)) {
// start authorization process
startButton.setText(res.getString(R.string.auth_start));
} else {
@@ -185,7 +188,7 @@ public class cgeoauth extends AbstractActivity {
final String line = sb.toString();
- if (line != null && line.length() > 0) {
+ if (StringUtils.isNotBlank(line)) {
final Matcher paramsMatcher1 = paramsPattern1.matcher(line);
if (paramsMatcher1.find() && paramsMatcher1.groupCount() > 0) {
OAtoken = paramsMatcher1.group(1);
@@ -195,14 +198,14 @@ public class cgeoauth extends AbstractActivity {
OAtokenSecret = paramsMatcher2.group(1);
}
- if (OAtoken != null && OAtoken.length() > 0 && OAtokenSecret != null && OAtokenSecret.length() > 0) {
+ if (StringUtils.isNotBlank(OAtoken) && StringUtils.isNotBlank(OAtokenSecret)) {
final SharedPreferences.Editor prefsEdit = getSharedPreferences(cgSettings.preferences, 0).edit();
prefsEdit.putString("temp-token-public", OAtoken);
prefsEdit.putString("temp-token-secret", OAtokenSecret);
prefsEdit.commit();
try {
- final HashMap<String, String> paramsPre = new HashMap<String, String>();
+ final Map<String, String> paramsPre = new HashMap<String, String>();
paramsPre.put("oauth_callback", "oob");
final String paramsBrowser = cgOAuth.signOAuth(host, pathAuthorize, "GET", true, paramsPre, OAtoken, OAtokenSecret);
@@ -240,7 +243,7 @@ public class cgeoauth extends AbstractActivity {
String lineOne = null;
try {
- final HashMap<String, String> paramsPre = new HashMap<String, String>();
+ final Map<String, String> paramsPre = new HashMap<String, String>();
paramsPre.put("oauth_verifier", pinEntry.getText().toString());
int code = -1;
@@ -303,7 +306,7 @@ public class cgeoauth extends AbstractActivity {
OAtokenSecret = paramsMatcher2.group(1);
}
- if (OAtoken.length() == 0 || OAtokenSecret.length() == 0) {
+ if (StringUtils.isBlank(OAtoken) && StringUtils.isBlank(OAtokenSecret)) {
OAtoken = "";
OAtokenSecret = "";
diff --git a/src/cgeo/geocaching/cgeocaches.java b/src/cgeo/geocaching/cgeocaches.java
index 9953882..d8380bf 100644
--- a/src/cgeo/geocaching/cgeocaches.java
+++ b/src/cgeo/geocaching/cgeocaches.java
@@ -13,6 +13,10 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.commons.lang3.StringUtils;
import android.app.AlertDialog;
import android.app.ProgressDialog;
@@ -62,9 +66,11 @@ import cgeo.geocaching.sorting.SizeComparator;
import cgeo.geocaching.sorting.StateComparator;
import cgeo.geocaching.sorting.TerrainComparator;
import cgeo.geocaching.sorting.VoteComparator;
+import cgeo.geocaching.utils.CollectionUtils;
public class cgeocaches extends AbstractListActivity {
+ private static final int MAX_LIST_ITEMS = 1000;
private static final String EXTRAS_LIST_TYPE = "type";
private static final int MENU_COMPASS = 1;
private static final int MENU_REFRESH_STORED = 2;
@@ -139,8 +145,8 @@ public class cgeocaches extends AbstractListActivity {
private String keyword = null;
private String address = null;
private String username = null;
- private Long searchId = null;
- private ArrayList<cgCache> cacheList = new ArrayList<cgCache>();
+ private UUID searchId = null;
+ private List<cgCache> cacheList = new ArrayList<cgCache>();
private cgCacheListAdapter adapter = null;
private LayoutInflater inflater = null;
private View listFooter = null;
@@ -161,7 +167,7 @@ public class cgeocaches extends AbstractListActivity {
private geocachesExportFieldNotes threadF = null;
private geocachesRemoveFromHistory threadH = null;
private int listId = 0;
- private ArrayList<cgList> lists = null;
+ private List<cgList> lists = null;
private String selectedFilter = null;
private GeocodeComparator gcComparator = new GeocodeComparator();
private Handler loadCachesHandler = new Handler() {
@@ -169,12 +175,12 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void handleMessage(Message msg) {
try {
- if (searchId != null && searchId > 0) {
+ if (searchId != null) {
setTitle(title + " [" + app.getCount(searchId) + "]");
cacheList.clear();
- final ArrayList<cgCache> cacheListTmp = app.getCaches(searchId);
- if (cacheListTmp != null && cacheListTmp.isEmpty() == false) {
+ final List<cgCache> cacheListTmp = app.getCaches(searchId);
+ if (CollectionUtils.isNotEmpty(cacheListTmp)) {
cacheList.addAll(cacheListTmp);
cacheListTmp.clear();
@@ -193,7 +199,7 @@ public class cgeocaches extends AbstractListActivity {
final Integer count = app.getTotal(searchId);
if (count != null && count > 0) {
- if (cacheList.size() < app.getTotal(searchId) && cacheList.size() < 1000) {
+ if (cacheList.size() < app.getTotal(searchId) && cacheList.size() < MAX_LIST_ITEMS) {
setMoreCaches(true);
} else {
setMoreCaches(false);
@@ -225,7 +231,7 @@ public class cgeocaches extends AbstractListActivity {
AlertDialog alert = dialog.create();
alert.show();
- } else if (app != null && app.getError(searchId) != null && app.getError(searchId).length() > 0) {
+ } else if (app != null && StringUtils.isNotBlank(app.getError(searchId))) {
showToast(res.getString(R.string.err_download_fail) + app.getError(searchId) + ".");
hideLoading();
@@ -267,12 +273,12 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void handleMessage(Message msg) {
try {
- if (searchId != null && searchId > 0) {
+ if (searchId != null) {
setTitle(title + " [" + app.getCount(searchId) + "]");
cacheList.clear();
- final ArrayList<cgCache> cacheListTmp = app.getCaches(searchId);
- if (cacheListTmp != null && cacheListTmp.isEmpty() == false) {
+ final List<cgCache> cacheListTmp = app.getCaches(searchId);
+ if (CollectionUtils.isNotEmpty(cacheListTmp)) {
cacheList.addAll(cacheListTmp);
cacheListTmp.clear();
Collections.sort((List<cgCache>)cacheList, gcComparator);
@@ -292,7 +298,7 @@ public class cgeocaches extends AbstractListActivity {
} else {
final Integer count = app.getTotal(searchId);
if (count != null && count > 0) {
- if (cacheList.size() < app.getTotal(searchId) && cacheList.size() < 1000) {
+ if (cacheList.size() < app.getTotal(searchId) && cacheList.size() < MAX_LIST_ITEMS) {
setMoreCaches(true);
} else {
setMoreCaches(false);
@@ -302,7 +308,7 @@ public class cgeocaches extends AbstractListActivity {
}
}
- if (app.getError(searchId) != null && app.getError(searchId).length() > 0) {
+ if (StringUtils.isNotBlank(app.getError(searchId))) {
showToast(res.getString(R.string.err_download_fail) + app.getError(searchId) + ".");
listFooter.setOnClickListener(new moreCachesListener());
@@ -360,8 +366,8 @@ public class cgeocaches extends AbstractListActivity {
}
} else {
if (cacheList != null && searchId != null) {
- final ArrayList<cgCache> cacheListTmp = app.getCaches(searchId);
- if (cacheListTmp != null && cacheListTmp.isEmpty() == false) {
+ final List<cgCache> cacheListTmp = app.getCaches(searchId);
+ if (CollectionUtils.isNotEmpty(cacheListTmp)) {
cacheList.clear();
cacheList.addAll(cacheListTmp);
cacheListTmp.clear();
@@ -421,8 +427,8 @@ public class cgeocaches extends AbstractListActivity {
cacheList.clear();
- final ArrayList<cgCache> cacheListTmp = app.getCaches(searchId);
- if (cacheListTmp != null && cacheListTmp.isEmpty() == false) {
+ final List<cgCache> cacheListTmp = app.getCaches(searchId);
+ if (CollectionUtils.isNotEmpty(cacheListTmp)) {
cacheList.addAll(cacheListTmp);
cacheListTmp.clear();
@@ -449,8 +455,8 @@ public class cgeocaches extends AbstractListActivity {
cacheList.clear();
- final ArrayList<cgCache> cacheListTmp = app.getCaches(searchId);
- if (cacheListTmp != null && cacheListTmp.isEmpty() == false) {
+ final List<cgCache> cacheListTmp = app.getCaches(searchId);
+ if (CollectionUtils.isNotEmpty(cacheListTmp)) {
cacheList.addAll(cacheListTmp);
cacheListTmp.clear();
@@ -617,7 +623,7 @@ public class cgeocaches extends AbstractListActivity {
thread.start();
} else if (type.equals("address")) {
action = "planning";
- if (address != null && address.length() > 0) {
+ if (StringUtils.isNotBlank(address)) {
title = address;
setTitle(title);
showProgress(true);
@@ -741,7 +747,7 @@ public class cgeocaches extends AbstractListActivity {
subMenuSort.setHeaderTitle(res.getString(R.string.caches_sort_title));
// sort the context menu labels alphabetically for easier reading
- HashMap<String, Integer> comparators = new HashMap<String, Integer>();
+ Map<String, Integer> comparators = new HashMap<String, Integer>();
comparators.put(res.getString(R.string.caches_sort_distance), MENU_SORT_DISTANCE);
comparators.put(res.getString(R.string.caches_sort_difficulty), MENU_SORT_DIFFICULTY);
comparators.put(res.getString(R.string.caches_sort_terrain), MENU_SORT_TERRAIN);
@@ -756,7 +762,7 @@ public class cgeocaches extends AbstractListActivity {
comparators.put(res.getString(R.string.caches_sort_finds), MENU_SORT_FINDS);
comparators.put(res.getString(R.string.caches_sort_state), MENU_SORT_STATE);
- ArrayList<String> sortedLabels = new ArrayList<String>(comparators.keySet());
+ List<String> sortedLabels = new ArrayList<String>(comparators.keySet());
Collections.sort(sortedLabels);
for (String label : sortedLabels) {
Integer id = comparators.get(label);
@@ -1088,7 +1094,7 @@ public class cgeocaches extends AbstractListActivity {
}
final cgCache cache = adapter.getItem(adapterInfo.position);
- if (cache.name != null && cache.name.length() > 0) {
+ if (StringUtils.isNotBlank(cache.name)) {
menu.setHeaderTitle(cache.name);
} else {
menu.setHeaderTitle(cache.geocode);
@@ -1105,7 +1111,7 @@ public class cgeocaches extends AbstractListActivity {
}
if (cache.reason >= 1) {
menu.add(0, MENU_DROP_CACHE, 0, res.getString(R.string.cache_offline_drop));
- ArrayList<cgList> cacheLists = app.getLists();
+ List<cgList> cacheLists = app.getLists();
int listCount = cacheLists.size();
if (listCount > 1) {
SubMenu submenu = menu.addSubMenu(0, MENU_MOVE_TO_LIST, 0, res.getString(R.string.cache_menu_move_list));
@@ -1119,7 +1125,7 @@ public class cgeocaches extends AbstractListActivity {
}
private void createFakeContextMenuMoveToList(ContextMenu menu) {
- ArrayList<cgList> cacheLists = app.getLists();
+ List<cgList> cacheLists = app.getLists();
int listCount = cacheLists.size();
menu.setHeaderTitle(res.getString(R.string.cache_menu_move_list));
for (int i = 0; i < listCount; i++) {
@@ -1248,7 +1254,7 @@ public class cgeocaches extends AbstractListActivity {
} else if (id >= MENU_MOVE_SELECTED_OR_ALL_TO_LIST && id < MENU_MOVE_SELECTED_OR_ALL_TO_LIST + 100) {
int newListId = id - MENU_MOVE_SELECTED_OR_ALL_TO_LIST;
boolean moveAll = adapter.getChecked() == 0;
- final ArrayList<cgCache> cacheListTemp = new ArrayList<cgCache>(cacheList);
+ final List<cgCache> cacheListTemp = new ArrayList<cgCache>(cacheList);
for (cgCache c : cacheListTemp) {
if (moveAll || c.statusChecked) {
app.moveToList(c.geocode, newListId);
@@ -1267,9 +1273,9 @@ public class cgeocaches extends AbstractListActivity {
if (cache != null) {
// create a searchId for a single cache (as if in details view)
- HashMap<String, String> params = new HashMap<String, String>();
+ Map<String, String> params = new HashMap<String, String>();
params.put("geocode", cache.geocode);
- Long singleSearchId = base.searchByGeocode(params, 0, false);
+ final UUID singleSearchId = base.searchByGeocode(params, 0, false);
if (NavigationAppFactory.onMenuItemSelected(item, geo, this,
res, cache, singleSearchId, null, null)) {
@@ -1364,7 +1370,7 @@ public class cgeocaches extends AbstractListActivity {
}
if (more == false) {
- if (cacheList == null || cacheList.isEmpty()) {
+ if (CollectionUtils.isEmpty(cacheList)) {
listFooterText.setText(res.getString(R.string.caches_no_cache));
} else {
listFooterText.setText(res.getString(R.string.caches_more_caches_no));
@@ -1391,11 +1397,11 @@ public class cgeocaches extends AbstractListActivity {
setTitle(title);
}
- if (cacheList != null && cacheList.isEmpty() == false) {
+ if (CollectionUtils.isNotEmpty(cacheList)) {
final Integer count = app.getTotal(searchId);
if (count != null && count > 0) {
setTitle(title);
- if (cacheList.size() < app.getTotal(searchId) && cacheList.size() < 1000) {
+ if (cacheList.size() < app.getTotal(searchId) && cacheList.size() < MAX_LIST_ITEMS) {
setMoreCaches(true);
} else {
setMoreCaches(false);
@@ -1751,7 +1757,7 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void run() {
- HashMap<String, Object> params = new HashMap<String, Object>();
+ Map<String, Object> params = new HashMap<String, Object>();
if (latitude != null && longitude != null) {
params.put("latitude", latitude);
params.put("longitude", longitude);
@@ -1775,7 +1781,7 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void run() {
- HashMap<String, Object> params = new HashMap<String, Object>();
+ Map<String, Object> params = new HashMap<String, Object>();
if (latitude != null && longitude != null) {
params.put("cachetype", settings.cacheType);
}
@@ -1827,7 +1833,7 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void run() {
- HashMap<String, String> params = new HashMap<String, String>();
+ Map<String, String> params = new HashMap<String, String>();
params.put("latitude", String.format((Locale) null, "%.6f", latitude));
params.put("longitude", String.format((Locale) null, "%.6f", longitude));
params.put("cachetype", cachetype);
@@ -1861,7 +1867,7 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void run() {
- HashMap<String, String> params = new HashMap<String, String>();
+ Map<String, String> params = new HashMap<String, String>();
params.put("keyword", keyword);
params.put("cachetype", cachetype);
@@ -1884,7 +1890,7 @@ public class cgeocaches extends AbstractListActivity {
username = usernameIn;
cachetype = cachetypeIn;
- if (username == null || username.length() == 0) {
+ if (StringUtils.isBlank(username)) {
showToast(res.getString(R.string.warn_no_username));
finish();
@@ -1894,7 +1900,7 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void run() {
- HashMap<String, String> params = new HashMap<String, String>();
+ Map<String, String> params = new HashMap<String, String>();
params.put("username", username);
params.put("cachetype", cachetype);
@@ -1917,7 +1923,7 @@ public class cgeocaches extends AbstractListActivity {
username = usernameIn;
cachetype = cachetypeIn;
- if (username == null || username.length() == 0) {
+ if (StringUtils.isBlank(username)) {
showToast(res.getString(R.string.warn_no_username));
finish();
@@ -1927,7 +1933,7 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void run() {
- HashMap<String, String> params = new HashMap<String, String>();
+ Map<String, String> params = new HashMap<String, String>();
params.put("username", username);
params.put("cachetype", cachetype);
@@ -1969,7 +1975,7 @@ public class cgeocaches extends AbstractListActivity {
geo = app.removeGeo();
}
- final ArrayList<cgCache> cacheListTemp = new ArrayList<cgCache>(cacheList);
+ final List<cgCache> cacheListTemp = new ArrayList<cgCache>(cacheList);
for (cgCache cache : cacheListTemp) {
if (checked > 0 && cache.statusChecked == false) {
handler.sendEmptyMessage(0);
@@ -2143,7 +2149,7 @@ public class cgeocaches extends AbstractListActivity {
geo = app.removeGeo();
}
- final ArrayList<cgCache> cacheListTemp = new ArrayList<cgCache>(cacheList);
+ final List<cgCache> cacheListTemp = new ArrayList<cgCache>(cacheList);
for (cgCache cache : cacheListTemp) {
if (checked > 0 && cache.statusChecked == false) {
continue;
@@ -2248,7 +2254,7 @@ public class cgeocaches extends AbstractListActivity {
// We need our own HashMap because cgBase.LogTypes1 will give us localized and maybe
// different strings than gc.com expects in the field note
// We only need such logtypes that are possible to log via c:geo
- HashMap<Integer, String> logTypes = new HashMap<Integer, String>();
+ Map<Integer, String> logTypes = new HashMap<Integer, String>();
logTypes.put(cgBase.LOG_FOUND_IT, "Found it");
logTypes.put(cgBase.LOG_DIDNT_FIND_IT, "Didn't find it");
logTypes.put(cgBase.LOG_NOTE, "Write Note");
@@ -2371,7 +2377,7 @@ public class cgeocaches extends AbstractListActivity {
return;
}
- final ArrayList<CharSequence> listsTitle = new ArrayList<CharSequence>();
+ final List<CharSequence> listsTitle = new ArrayList<CharSequence>();
for (cgList list : lists) {
listsTitle.add(list.title);
}
@@ -2435,7 +2441,7 @@ public class cgeocaches extends AbstractListActivity {
public void run() {
int checked = adapter.getChecked();
if (checked > 0) {
- final ArrayList<cgCache> cacheListTemp = new ArrayList<cgCache>(cacheList);
+ final List<cgCache> cacheListTemp = new ArrayList<cgCache>(cacheList);
for (cgCache cache : cacheListTemp) {
if (cache.statusChecked) {
app.moveToList(cache.geocode, listId);
@@ -2462,7 +2468,7 @@ public class cgeocaches extends AbstractListActivity {
value = value.trim();
}
- if (value != null && value.length() > 0) {
+ if (StringUtils.isNotBlank(value)) {
int newId = app.createList(value);
if (newId >= 10) {
@@ -2521,7 +2527,7 @@ public class cgeocaches extends AbstractListActivity {
}
public void goMap(View view) {
- if (searchId == null || searchId == 0 || cacheList == null || cacheList.isEmpty()) {
+ if (searchId == null || CollectionUtils.isEmpty(cacheList)) {
showToast(res.getString(R.string.warn_no_cache_coord));
return;
@@ -2529,7 +2535,7 @@ public class cgeocaches extends AbstractListActivity {
Intent mapIntent = new Intent(this, settings.getMapFactory().getMapClass());
mapIntent.putExtra("detail", false);
- mapIntent.putExtra("searchid", searchId);
+ mapIntent.putExtra("searchid", searchId.toString());
startActivity(mapIntent);
}
@@ -2585,4 +2591,4 @@ public class cgeocaches extends AbstractListActivity {
context.startActivity(cachesIntent);
}
-} \ No newline at end of file
+}
diff --git a/src/cgeo/geocaching/cgeocoords.java b/src/cgeo/geocaching/cgeocoords.java
index ca6e610..1ee078f 100644
--- a/src/cgeo/geocaching/cgeocoords.java
+++ b/src/cgeo/geocaching/cgeocoords.java
@@ -1,7 +1,10 @@
package cgeo.geocaching;
import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
import android.app.Dialog;
import android.os.Bundle;
@@ -274,7 +277,7 @@ public class cgeocoords extends Dialog {
public void onClick(View v) {
Button e = (Button) v;
CharSequence text = e.getText();
- if (text == null || text.length() == 0) {
+ if (StringUtils.isBlank(text)) {
return;
}
switch (text.charAt(0)) {
@@ -465,8 +468,8 @@ public class cgeocoords extends Dialog {
if (currentFormat == coordInputFormatEnum.Plain) {
if (eLat.length() > 0 && eLon.length() > 0) {
// latitude & longitude
- HashMap<String, Object> latParsed = cgBase.parseCoordinate(eLat.getText().toString(), "lat");
- HashMap<String, Object> lonParsed = cgBase.parseCoordinate(eLon.getText().toString(), "lon");
+ Map<String, Object> latParsed = cgBase.parseCoordinate(eLat.getText().toString(), "lat");
+ Map<String, Object> lonParsed = cgBase.parseCoordinate(eLon.getText().toString(), "lon");
if (latParsed == null || latParsed.get("coordinate") == null || latParsed.get("string") == null) {
context.showToast(context.getResources().getString(R.string.err_parse_lat));
@@ -490,7 +493,7 @@ public class cgeocoords extends Dialog {
longitude = geo.longitudeNow;
}
}
- ArrayList<Double> co = new ArrayList<Double>();
+ List<Double> co = new ArrayList<Double>();
co.add(latitude);
co.add(longitude);
cuListener.update(co);
@@ -503,7 +506,7 @@ public class cgeocoords extends Dialog {
}
public interface CoordinateUpdate {
- public void update(ArrayList<Double> coords);
+ public void update(List<Double> coords);
}
}
diff --git a/src/cgeo/geocaching/cgeodetail.java b/src/cgeo/geocaching/cgeodetail.java
index 3000ec9..182778d 100644
--- a/src/cgeo/geocaching/cgeodetail.java
+++ b/src/cgeo/geocaching/cgeodetail.java
@@ -6,8 +6,13 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
+import java.util.List;
import java.util.Locale;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.UUID;
+
+import org.apache.commons.lang3.StringUtils;
import android.app.AlertDialog;
import android.app.ProgressDialog;
@@ -54,6 +59,7 @@ import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.apps.cache.GeneralAppsFactory;
import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
import cgeo.geocaching.compatibility.Compatibility;
+import cgeo.geocaching.utils.CollectionUtils;
/**
* Activity to display all details of a cache like owner, difficulty, description etc.
@@ -65,7 +71,7 @@ public class cgeodetail extends AbstractActivity {
super("c:geo-cache-details");
}
- public Long searchId = null;
+ public UUID searchId = null;
public cgCache cache = null;
public String geocode = null;
public String name = null;
@@ -89,7 +95,7 @@ public class cgeodetail extends AbstractActivity {
private ProgressDialog dropDialog = null;
private ProgressDialog watchlistDialog = null; // progress dialog for watchlist add/remove
private Thread watchlistThread = null; // thread for watchlist add/remove
- private HashMap<Integer, String> calendars = new HashMap<Integer, String>();
+ private Map<Integer, String> calendars = new HashMap<Integer, String>();
private ViewGroup attributeIconsLayout; // layout for attribute icons
private ViewGroup attributeDescriptionsLayout; // layout for attribute descriptions
@@ -158,7 +164,7 @@ public class cgeodetail extends AbstractActivity {
private Handler loadCacheHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
- if (searchId == null || searchId <= 0) {
+ if (searchId == null) {
showToast(res.getString(R.string.err_dwld_details_failed));
finish();
@@ -335,10 +341,10 @@ public class cgeodetail extends AbstractActivity {
geocode = uri.getQueryParameter("wp");
guid = uri.getQueryParameter("guid");
- if (geocode != null && geocode.length() > 0) {
+ if (StringUtils.isNotBlank(geocode)) {
geocode = geocode.toUpperCase();
guid = null;
- } else if (guid != null && guid.length() > 0) {
+ } else if (StringUtils.isNotBlank(guid)) {
geocode = null;
guid = guid.toLowerCase();
} else {
@@ -367,9 +373,9 @@ public class cgeodetail extends AbstractActivity {
app.setAction(geocode);
try {
- if (name != null && name.length() > 0) {
+ if (StringUtils.isNotBlank(name)) {
waitDialog = ProgressDialog.show(this, name, res.getString(R.string.cache_dialog_loading_details), true);
- } else if (geocode != null && geocode.length() > 0) {
+ } else if (StringUtils.isNotBlank(geocode)) {
waitDialog = ProgressDialog.show(this, geocode.toUpperCase(), res.getString(R.string.cache_dialog_loading_details), true);
} else {
waitDialog = ProgressDialog.show(this, res.getString(R.string.cache), res.getString(R.string.cache_dialog_loading_details), true);
@@ -442,7 +448,7 @@ public class cgeodetail extends AbstractActivity {
if (viewId == R.id.author) { // Author of a log entry
contextMenuUser = ((TextView)view).getText().toString();
} else if (viewId == R.id.value) { // The owner of the cache
- if (cache.ownerReal != null && cache.ownerReal.length() > 0) {
+ if (StringUtils.isNotBlank(cache.ownerReal)) {
contextMenuUser = cache.ownerReal;
} else {
contextMenuUser = cache.owner;
@@ -498,7 +504,7 @@ public class cgeodetail extends AbstractActivity {
}
addVisitMenu(menu, cache);
- if (cache != null && cache.spoilers != null && cache.spoilers.size() > 0) {
+ if (cache != null && CollectionUtils.isNotEmpty(cache.spoilers)) {
menu.add(1, 5, 0, res.getString(R.string.cache_menu_spoilers)).setIcon(android.R.drawable.ic_menu_gallery); // spoiler images
}
@@ -568,14 +574,14 @@ public class cgeodetail extends AbstractActivity {
geo = app.startGeo(this, geoUpdate, base, settings, 0, 0);
}
- if (searchId != null && searchId > 0) {
+ if (searchId != null) {
cache = app.getCache(searchId);
if (cache != null && cache.geocode != null) {
geocode = cache.geocode;
}
}
- if (geocode != null && geocode.length() > 0) {
+ if (StringUtils.isNotBlank(geocode)) {
app.setAction(geocode);
}
}
@@ -594,7 +600,7 @@ public class cgeodetail extends AbstractActivity {
if (cache == null) {
if (waitDialog != null && waitDialog.isShowing()) waitDialog.dismiss();
- if (geocode != null && geocode.length() > 0) {
+ if (StringUtils.isNotBlank(geocode)) {
showToast(res.getString(R.string.err_detail_cache_find) + " " + geocode + ".");
} else {
geocode = null;
@@ -607,13 +613,11 @@ public class cgeodetail extends AbstractActivity {
try {
- if (null == geocode && cache.geocode.length() > 0)
- {
+ if (StringUtils.isBlank(geocode)) {
geocode = cache.geocode;
}
- if (null == guid && cache.guid.length() > 0)
- {
+ if (StringUtils.isBlank(guid)) {
guid = cache.guid;
}
@@ -651,7 +655,7 @@ public class cgeodetail extends AbstractActivity {
itemName.setText(res.getString(R.string.cache_type));
String size = "";
- if (cache.size != null && cache.size.length() > 0) {
+ if (StringUtils.isNotBlank(cache.size)) {
// don't show "not chosen" for events, that should be the normal case
if (!(cache.isEventCache() && cache.size.equals("not chosen"))) {
size = " (" + cache.size + ")";
@@ -766,15 +770,15 @@ public class cgeodetail extends AbstractActivity {
}
// cache author
- if ((cache.owner != null && cache.owner.length() > 0) || (cache.ownerReal != null && cache.ownerReal.length() > 0)) {
+ if (StringUtils.isNotBlank(cache.owner) || StringUtils.isNotBlank(cache.ownerReal)) {
itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
itemName = (TextView) itemLayout.findViewById(R.id.name);
itemValue = (TextView) itemLayout.findViewById(R.id.value);
itemName.setText(res.getString(R.string.cache_owner));
- if (cache.owner != null && cache.owner.length() > 0) {
+ if (StringUtils.isNotBlank(cache.owner)) {
itemValue.setText(Html.fromHtml(cache.owner), TextView.BufferType.SPANNABLE);
- } else if (cache.ownerReal != null && cache.ownerReal.length() > 0) {
+ } else if (StringUtils.isNotBlank(cache.ownerReal)) {
itemValue.setText(Html.fromHtml(cache.ownerReal), TextView.BufferType.SPANNABLE);
}
itemValue.setOnClickListener(new userActions());
@@ -797,7 +801,7 @@ public class cgeodetail extends AbstractActivity {
}
// cache location
- if (cache.location != null && cache.location.length() > 0) {
+ if (StringUtils.isNotBlank(cache.location)) {
itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
itemName = (TextView) itemLayout.findViewById(R.id.name);
itemValue = (TextView) itemLayout.findViewById(R.id.value);
@@ -819,7 +823,7 @@ public class cgeodetail extends AbstractActivity {
}
// cache attributes
- if (cache.attributes != null && cache.attributes.size() > 0) {
+ if (CollectionUtils.isNotEmpty(cache.attributes)) {
final LinearLayout attribBox = (LinearLayout) findViewById(
R.id.attributes_innerbox);
@@ -865,7 +869,7 @@ public class cgeodetail extends AbstractActivity {
}
// cache inventory
- if (cache.inventory != null && cache.inventory.size() > 0) {
+ if (CollectionUtils.isNotEmpty(cache.inventory)) {
final LinearLayout inventBox = (LinearLayout) findViewById(R.id.inventory_box);
final TextView inventView = (TextView) findViewById(R.id.inventory);
@@ -927,7 +931,7 @@ public class cgeodetail extends AbstractActivity {
offlineRefresh.setClickable(true);
// cache personal note
- if (cache.personalNote != null && cache.personalNote.length() > 0) {
+ if (StringUtils.isNotBlank(cache.personalNote)) {
((LinearLayout) findViewById(R.id.personalnote_box)).setVisibility(View.VISIBLE);
TextView personalNoteText = (TextView) findViewById(R.id.personalnote);
@@ -937,7 +941,7 @@ public class cgeodetail extends AbstractActivity {
}
// cache short desc
- if (cache.shortdesc != null && cache.shortdesc.length() > 0) {
+ if (StringUtils.isNotBlank(cache.shortdesc)) {
((LinearLayout) findViewById(R.id.desc_box)).setVisibility(View.VISIBLE);
TextView descView = (TextView) findViewById(R.id.shortdesc);
@@ -950,7 +954,7 @@ public class cgeodetail extends AbstractActivity {
if (longDescDisplayed) {
parseLongDescription();
- if (longDesc != null && longDesc.length() > 0) {
+ if (StringUtils.isNotBlank(longDesc)) {
((LinearLayout) findViewById(R.id.desc_box)).setVisibility(View.VISIBLE);
TextView descView = (TextView) findViewById(R.id.description);
@@ -963,7 +967,7 @@ public class cgeodetail extends AbstractActivity {
showDesc.setOnTouchListener(null);
showDesc.setOnClickListener(null);
}
- } else if (longDescDisplayed == false && cache.description != null && cache.description.length() > 0) {
+ } else if (longDescDisplayed == false && StringUtils.isNotBlank(cache.description)) {
((LinearLayout) findViewById(R.id.desc_box)).setVisibility(View.VISIBLE);
Button showDesc = (Button) findViewById(R.id.show_description);
@@ -986,11 +990,11 @@ public class cgeodetail extends AbstractActivity {
LinearLayout waypoints = (LinearLayout) findViewById(R.id.waypoints);
waypoints.removeAllViews();
- if (cache.waypoints != null && cache.waypoints.size() > 0) {
+ if (CollectionUtils.isNotEmpty(cache.waypoints)) {
LinearLayout waypointView;
// sort waypoints: PP, Sx, FI, OWN
- ArrayList<cgWaypoint> sortedWaypoints = new ArrayList<cgWaypoint>(cache.waypoints);
+ List<cgWaypoint> sortedWaypoints = new ArrayList<cgWaypoint>(cache.waypoints);
Collections.sort(sortedWaypoints, new Comparator<cgWaypoint>() {
@Override
@@ -1000,7 +1004,7 @@ public class cgeodetail extends AbstractActivity {
}
private int order(cgWaypoint waypoint) {
- if (waypoint.prefix == null || waypoint.prefix.length() == 0) {
+ if (StringUtils.isEmpty(waypoint.prefix)) {
return 0;
}
// check only the first character. sometimes there are inconsistencies like FI or FN for the FINAL
@@ -1034,7 +1038,7 @@ public class cgeodetail extends AbstractActivity {
}
TextView nameView = (TextView) waypointView.findViewById(R.id.name);
- if (wpt.name.trim().length() == 0) {
+ if (StringUtils.isBlank(wpt.name)) {
nameView.setText(cgBase.formatCoords(wpt.latitude, wpt.longitude, true));
} else {
// avoid HTML parsing
@@ -1066,7 +1070,7 @@ public class cgeodetail extends AbstractActivity {
addWaypoint.setOnClickListener(new addWaypoint());
// cache hint
- if (cache.hint != null && cache.hint.length() > 0) {
+ if (StringUtils.isNotBlank(cache.hint)) {
((LinearLayout) findViewById(R.id.hint_box)).setVisibility(View.VISIBLE);
TextView hintView = ((TextView) findViewById(R.id.hint));
hintView.setText(cgBase.rot13(cache.hint.trim()));
@@ -1136,7 +1140,7 @@ public class cgeodetail extends AbstractActivity {
buff.append(": ");
// sort the log counts by type id ascending. that way the FOUND, DNF log types are the first and most visible ones
- ArrayList<Entry<Integer, Integer>> sortedLogCounts = new ArrayList<Entry<Integer,Integer>>();
+ List<Entry<Integer, Integer>> sortedLogCounts = new ArrayList<Entry<Integer,Integer>>();
sortedLogCounts.addAll(cache.logCounts.entrySet());
Collections.sort(sortedLogCounts, new Comparator<Entry<Integer, Integer>>() {
@@ -1302,10 +1306,10 @@ public class cgeodetail extends AbstractActivity {
@Override
public void run() {
- HashMap<String, String> params = new HashMap<String, String>();
- if (geocode != null && geocode.length() > 0) {
+ Map<String, String> params = new HashMap<String, String>();
+ if (StringUtils.isNotBlank(geocode)) {
params.put("geocode", geocode);
- } else if (guid != null && guid.length() > 0) {
+ } else if (StringUtils.isNotBlank(guid)) {
params.put("guid", guid);
} else {
return;
@@ -1378,15 +1382,15 @@ public class cgeodetail extends AbstractActivity {
}
}
- public ArrayList<cgCoord> getCoordinates() {
+ public List<cgCoord> getCoordinates() {
cgCoord coords = null;
- ArrayList<cgCoord> coordinates = new ArrayList<cgCoord>();
+ List<cgCoord> coordinates = new ArrayList<cgCoord>();
try {
// cache
coords = new cgCoord();
coords.type = "cache";
- if (name != null && name.length() > 0) {
+ if (StringUtils.isNotBlank(name)) {
coords.name = name;
} else {
coords.name = geocode.toUpperCase();
@@ -1492,11 +1496,11 @@ public class cgeodetail extends AbstractActivity {
description.append("http://coord.info/");
description.append(cache.geocode.toUpperCase());
description.append("\n\n");
- if (cache.shortdesc != null && cache.shortdesc.length() > 0) {
+ if (StringUtils.isNotBlank(cache.shortdesc)) {
description.append(Html.fromHtml(cache.shortdesc).toString());
}
- if (cache.personalNote != null && cache.personalNote.length() > 0) {
+ if (StringUtils.isNotBlank(cache.personalNote)) {
description.append("\n\n"+Html.fromHtml(cache.personalNote).toString());
}
@@ -1508,10 +1512,10 @@ public class cgeodetail extends AbstractActivity {
event.put("title", Html.fromHtml(cache.name).toString());
event.put("description", description.toString());
String location = "";
- if (cache.latitudeString != null && cache.latitudeString.length() > 0 && cache.longitudeString != null && cache.longitudeString.length() > 0) {
+ if (StringUtils.isNotBlank(cache.latitudeString) && StringUtils.isNotBlank(cache.longitudeString)) {
location += cache.latitudeString + " " + cache.longitudeString;
}
- if (cache.location != null && cache.location.length() > 0) {
+ if (StringUtils.isNotBlank(cache.location)) {
boolean addParenteses = false;
if (location.length() > 0) {
addParenteses = true;
@@ -1569,7 +1573,7 @@ public class cgeodetail extends AbstractActivity {
if (cache != null && cache.geocode != null) {
String subject = cache.geocode.toUpperCase();
- if (cache.name != null && cache.name.length() > 0){
+ if (StringUtils.isNotBlank(cache.name)){
subject = subject + " - " + cache.name;
}
intent.putExtra(Intent.EXTRA_SUBJECT, "Geocache " + subject);
@@ -1668,9 +1672,16 @@ public class cgeodetail extends AbstractActivity {
public void onClick(View arg0) {
// show list of trackables
try {
- Intent trackablesIntent = new Intent(cgeodetail.this, cgeotrackables.class);
- trackablesIntent.putExtra("geocode", geocode.toUpperCase());
- startActivity(trackablesIntent);
+ // jump directly into details if there is only one trackable
+ if (cache != null && cache.inventory != null && cache.inventory.size() == 1) {
+ cgTrackable trackable = cache.inventory.get(0);
+ cgeotrackable.startActivity(cgeodetail.this, trackable.guid, trackable.geocode, trackable.name);
+ }
+ else {
+ Intent trackablesIntent = new Intent(cgeodetail.this, cgeotrackables.class);
+ trackablesIntent.putExtra("geocode", geocode.toUpperCase());
+ startActivity(trackablesIntent);
+ }
} catch (Exception e) {
Log.e(cgSettings.tag, "cgeodetail.selectTrackable: " + e.toString());
}
@@ -1748,7 +1759,7 @@ public class cgeodetail extends AbstractActivity {
public void run() {
app.removeCacheFromCache(geocode);
- final HashMap<String, String> params = new HashMap<String, String>();
+ final Map<String, String> params = new HashMap<String, String>();
params.put("geocode", cache.geocode);
searchId = base.searchByGeocode(params, 0, true);
@@ -2073,7 +2084,7 @@ public class cgeodetail extends AbstractActivity {
base.context.getPackageName());
if (id > 0) {
String translated = res.getString(id);
- if (translated != null && translated.length() > 0) {
+ if (StringUtils.isNotBlank(translated)) {
attribute = translated;
}
}
diff --git a/src/cgeo/geocaching/cgeogpxes.java b/src/cgeo/geocaching/cgeogpxes.java
index db26a1f..92d0d48 100644
--- a/src/cgeo/geocaching/cgeogpxes.java
+++ b/src/cgeo/geocaching/cgeogpxes.java
@@ -1,7 +1,8 @@
package cgeo.geocaching;
import java.io.File;
-import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
import android.app.Activity;
import android.app.ProgressDialog;
@@ -57,7 +58,7 @@ public class cgeogpxes extends FileList<cgGPXListAdapter> {
};
@Override
- protected cgGPXListAdapter getAdapter(ArrayList<File> files) {
+ protected cgGPXListAdapter getAdapter(List<File> files) {
return new cgGPXListAdapter(this, getSettings(), files);
}
@@ -108,7 +109,7 @@ public class cgeogpxes extends FileList<cgGPXListAdapter> {
@Override
public void run() {
- final long searchId;
+ final UUID searchId;
String name = file.getName().toLowerCase();
if (name.endsWith("gpx")) {
searchId = GPXParser.parseGPX(app, file, listId, changeParseDialogHandler);
diff --git a/src/cgeo/geocaching/cgeoimages.java b/src/cgeo/geocaching/cgeoimages.java
index c5975d0..1efbb56 100644
--- a/src/cgeo/geocaching/cgeoimages.java
+++ b/src/cgeo/geocaching/cgeoimages.java
@@ -3,6 +3,9 @@ package cgeo.geocaching;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
import android.app.ProgressDialog;
import android.content.Intent;
@@ -30,7 +33,7 @@ public class cgeoimages extends AbstractActivity {
public static final int SPOILER_IMAGE = 2;
private int img_type;
- private ArrayList<cgImage> images = new ArrayList<cgImage>();
+ private List<cgImage> images = new ArrayList<cgImage>();
private String geocode = null;
private String title = null;
private String url = null;
@@ -92,7 +95,7 @@ public class cgeoimages extends AbstractActivity {
((TextView) rowView.findViewById(R.id.title)).setText(Html.fromHtml(img.title));
- if (img.description != null && img.description.length() > 0) {
+ if (StringUtils.isNotBlank(img.description)) {
final TextView descView = (TextView) rowView.findViewById(R.id.description);
descView.setText(Html.fromHtml(img.description), TextView.BufferType.SPANNABLE);
descView.setVisibility(View.VISIBLE);
diff --git a/src/cgeo/geocaching/cgeoinit.java b/src/cgeo/geocaching/cgeoinit.java
index e3111e2..39b8e51 100644
--- a/src/cgeo/geocaching/cgeoinit.java
+++ b/src/cgeo/geocaching/cgeoinit.java
@@ -2,6 +2,8 @@ package cgeo.geocaching;
import java.io.File;
+import org.apache.commons.lang3.StringUtils;
+
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -261,7 +263,7 @@ public class cgeoinit extends AbstractActivity {
});
CheckBox twitterButton = (CheckBox) findViewById(R.id.twitter_option);
- if (prefs.getInt("twitter", 0) == 0 || settings.tokenPublic == null || settings.tokenPublic.length() == 0 || settings.tokenSecret == null || settings.tokenSecret.length() == 0) {
+ if (prefs.getInt("twitter", 0) == 0 || StringUtils.isBlank(settings.tokenPublic) || StringUtils.isBlank(settings.tokenSecret)) {
twitterButton.setChecked(false);
} else {
twitterButton.setChecked(true);
@@ -435,7 +437,7 @@ public class cgeoinit extends AbstractActivity {
//Send2cgeo settings
String webDeviceName = prefs.getString("webDeviceName", null);
- if ((webDeviceName != null) &&(webDeviceName.length() > 0)) {
+ if (StringUtils.isNotBlank(webDeviceName)) {
((EditText) findViewById(R.id.webDeviceName)).setText(webDeviceName);
} else {
String s = android.os.Build.MODEL;
@@ -579,7 +581,7 @@ public class cgeoinit extends AbstractActivity {
}
edit.commit();
- if (settings.twitter == 1 && (settings.tokenPublic == null || settings.tokenPublic.length() == 0 || settings.tokenSecret == null || settings.tokenSecret.length() == 0)) {
+ if (settings.twitter == 1 && (StringUtils.isBlank(settings.tokenPublic) || StringUtils.isBlank(settings.tokenSecret))) {
Intent authIntent = new Intent(cgeoinit.this, cgeoauth.class);
startActivity(authIntent);
}
@@ -1009,7 +1011,7 @@ public class cgeoinit extends AbstractActivity {
final String username = ((EditText) findViewById(R.id.username)).getText().toString();
final String password = ((EditText) findViewById(R.id.password)).getText().toString();
- if (username == null || username.length() == 0 || password == null || password.length() == 0) {
+ if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) {
showToast(res.getString(R.string.err_missing_auth));
return;
}
@@ -1042,7 +1044,7 @@ public class cgeoinit extends AbstractActivity {
final String deviceCode = prefs.getString("webDeviceCode", null);
- if (deviceName == null || deviceName.length() == 0) {
+ if (StringUtils.isBlank(deviceName)) {
showToast(res.getString(R.string.err_missing_device_name));
return;
}
diff --git a/src/cgeo/geocaching/cgeonavigate.java b/src/cgeo/geocaching/cgeonavigate.java
index 4b51367..5125997 100644
--- a/src/cgeo/geocaching/cgeonavigate.java
+++ b/src/cgeo/geocaching/cgeonavigate.java
@@ -2,7 +2,11 @@ package cgeo.geocaching;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Locale;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
import android.content.Context;
import android.content.Intent;
@@ -22,7 +26,7 @@ import cgeo.geocaching.activity.AbstractActivity;
public class cgeonavigate extends AbstractActivity {
- public static ArrayList<cgCoord> coordinates = new ArrayList<cgCoord>();
+ public static List<cgCoord> coordinates = new ArrayList<cgCoord>();
private PowerManager pm = null;
private cgGeo geo = null;
private cgDirection dir = null;
@@ -86,8 +90,8 @@ public class cgeonavigate extends AbstractActivity {
dstLatitude = extras.getDouble("latitude");
dstLongitude = extras.getDouble("longitude");
- if (name != null && name.length() > 0) {
- if (title != null && title.length() > 0) {
+ if (StringUtils.isNotBlank(name)) {
+ if (StringUtils.isNotBlank(title)) {
title = title + ": " + name;
} else {
title = name;
@@ -101,9 +105,9 @@ public class cgeonavigate extends AbstractActivity {
return;
}
- if (title != null && title.length() > 0) {
+ if (StringUtils.isNotBlank(title)) {
app.setAction(title);
- } else if (name != null && name.length() > 0) {
+ } else if (StringUtils.isNotBlank(name)) {
app.setAction(name);
}
@@ -132,9 +136,9 @@ public class cgeonavigate extends AbstractActivity {
settings.load();
- if (title != null && title.length() > 0) {
+ if (StringUtils.isNotBlank(title)) {
app.setAction(title);
- } else if (name != null && name.length() > 0) {
+ } else if (StringUtils.isNotBlank(name)) {
app.setAction(name);
}
@@ -295,7 +299,7 @@ public class cgeonavigate extends AbstractActivity {
}
private void setTitle() {
- if (title != null && title.length() > 0) {
+ if (StringUtils.isNotBlank(title)) {
setTitle(title);
} else {
setTitle(res.getString(R.string.navigation));
@@ -324,8 +328,8 @@ public class cgeonavigate extends AbstractActivity {
updateDistanceInfo();
}
- public HashMap<String, Double> getCoordinatesNow() {
- HashMap<String, Double> coordsNow = new HashMap<String, Double>();
+ public Map<String, Double> getCoordinatesNow() {
+ Map<String, Double> coordsNow = new HashMap<String, Double>();
if (geo != null) {
coordsNow.put("latitude", geo.latitudeNow);
coordsNow.put("longitude", geo.longitudeNow);
@@ -464,4 +468,4 @@ public class cgeonavigate extends AbstractActivity {
}
}
}
-} \ No newline at end of file
+}
diff --git a/src/cgeo/geocaching/cgeopoint.java b/src/cgeo/geocaching/cgeopoint.java
index d9cdfc6..dba015d 100644
--- a/src/cgeo/geocaching/cgeopoint.java
+++ b/src/cgeo/geocaching/cgeopoint.java
@@ -1,11 +1,13 @@
package cgeo.geocaching;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.lang3.StringUtils;
+
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
@@ -290,7 +292,7 @@ public class cgeopoint extends AbstractActivity {
super.onPrepareOptionsMenu(menu);
try {
- ArrayList<Double> coords = getDestination();
+ List<Double> coords = getDestination();
if (coords != null && coords.get(0) != null && coords.get(1) != null) {
menu.findItem(0).setVisible(true);
@@ -314,7 +316,7 @@ public class cgeopoint extends AbstractActivity {
public boolean onOptionsItemSelected(MenuItem item) {
final int menuItem = item.getItemId();
- ArrayList<Double> coords = getDestination();
+ List<Double> coords = getDestination();
if(coords != null && !coords.isEmpty())
{
@@ -336,7 +338,8 @@ public class cgeopoint extends AbstractActivity {
return NavigationAppFactory.onMenuItemSelected(item, geo, this, res, null, null, null, coords);
}
- private void addToHistory(ArrayList<Double> coords) {
+ private void addToHistory(List
+ <Double> coords) {
// Add locations to history
cgDestination loc = new cgDestination();
loc.setLatitude(coords.get(0));
@@ -413,7 +416,7 @@ public class cgeopoint extends AbstractActivity {
}
private void cachesAround() {
- ArrayList<Double> coords = getDestination();
+ List<Double> coords = getDestination();
if (coords == null || coords.get(0) == null || coords.get(1) == null) {
showToast(res.getString(R.string.err_location_unknown));
@@ -473,8 +476,8 @@ public class cgeopoint extends AbstractActivity {
}
}
- private ArrayList<Double> getDestination() {
- ArrayList<Double> coords = new ArrayList<Double>();
+ private List<Double> getDestination() {
+ List<Double> coords = new ArrayList<Double>();
Double latitude = null;
Double longitude = null;
@@ -483,16 +486,16 @@ public class cgeopoint extends AbstractActivity {
String latText = ((EditText) findViewById(R.id.latitude)).getText().toString();
String lonText = ((EditText) findViewById(R.id.longitude)).getText().toString();
- if ((bearingText == null || bearingText.length() == 0) && (distanceText == null || distanceText.length() == 0)
- && (latText == null || latText.length() == 0) && (lonText == null || lonText.length() == 0)) {
+ if (StringUtils.isBlank(bearingText) && StringUtils.isBlank(distanceText)
+ && StringUtils.isBlank(latText) && StringUtils.isBlank(lonText)) {
showToast(res.getString(R.string.err_point_no_position_given));
return null;
}
- if (latText != null && latText.length() > 0 && lonText != null && lonText.length() > 0) {
+ if (StringUtils.isNotBlank(latText) && StringUtils.isNotBlank(lonText)) {
// latitude & longitude
- HashMap<String, Object> latParsed = cgBase.parseCoordinate(latText, "lat");
- HashMap<String, Object> lonParsed = cgBase.parseCoordinate(lonText, "lon");
+ Map<String, Object> latParsed = cgBase.parseCoordinate(latText, "lat");
+ Map<String, Object> lonParsed = cgBase.parseCoordinate(lonText, "lon");
if (latParsed == null || latParsed.get("coordinate") == null || latParsed.get("string") == null) {
showToast(res.getString(R.string.err_parse_lat));
@@ -516,7 +519,7 @@ public class cgeopoint extends AbstractActivity {
longitude = geo.longitudeNow;
}
- if (bearingText != null && bearingText.length() > 0 && distanceText != null && distanceText.length() > 0) {
+ if (StringUtils.isNotBlank(bearingText) && StringUtils.isNotBlank(distanceText)) {
// bearing & distance
Double bearing = null;
try {
@@ -573,7 +576,7 @@ public class cgeopoint extends AbstractActivity {
Double latParsed = null;
Double lonParsed = null;
- HashMap<String, Double> coordsDst = cgBase.getRadialDistance(latitude, longitude, bearing, distance);
+ Map<String, Double> coordsDst = cgBase.getRadialDistance(latitude, longitude, bearing, distance);
latParsed = coordsDst.get("latitude");
lonParsed = coordsDst.get("longitude");
diff --git a/src/cgeo/geocaching/cgeopopup.java b/src/cgeo/geocaching/cgeopopup.java
index 8531338..9b1d816 100644
--- a/src/cgeo/geocaching/cgeopopup.java
+++ b/src/cgeo/geocaching/cgeopopup.java
@@ -2,6 +2,8 @@ package cgeo.geocaching;
import java.util.Locale;
+import org.apache.commons.lang3.StringUtils;
+
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.res.Configuration;
@@ -117,7 +119,7 @@ public class cgeopopup extends AbstractActivity {
geocode = extras.getString("geocode");
}
- if (geocode == null || geocode.length() == 0) {
+ if (StringUtils.isBlank(geocode)) {
showToast(res.getString(R.string.err_detail_cache_find));
finish();
@@ -212,7 +214,7 @@ public class cgeopopup extends AbstractActivity {
TextView itemValue;
LinearLayout itemStars;
- if (cache.name != null && cache.name.length() > 0) {
+ if (StringUtils.isNotBlank(cache.name)) {
setTitle(cache.name);
} else {
setTitle(geocode.toUpperCase());
@@ -235,13 +237,13 @@ public class cgeopopup extends AbstractActivity {
itemName.setText(res.getString(R.string.cache_type));
if (cgBase.cacheTypesInv.containsKey(cache.type)) { // cache icon
- if (cache.size != null && cache.size.length() > 0) {
+ if (StringUtils.isNotBlank(cache.size)) {
itemValue.setText(cgBase.cacheTypesInv.get(cache.type) + " (" + cache.size + ")");
} else {
itemValue.setText(cgBase.cacheTypesInv.get(cache.type));
}
} else {
- if (cache.size != null && cache.size.length() > 0) {
+ if (StringUtils.isNotBlank(cache.size)) {
itemValue.setText(cgBase.cacheTypesInv.get("mystery") + " (" + cache.size + ")");
} else {
itemValue.setText(cgBase.cacheTypesInv.get("mystery"));
@@ -662,4 +664,4 @@ public class cgeopopup extends AbstractActivity {
super.goManual(view);
finish();
}
-} \ No newline at end of file
+}
diff --git a/src/cgeo/geocaching/cgeosmaps.java b/src/cgeo/geocaching/cgeosmaps.java
index 35d09d0..540d50c 100644
--- a/src/cgeo/geocaching/cgeosmaps.java
+++ b/src/cgeo/geocaching/cgeosmaps.java
@@ -1,6 +1,7 @@
package cgeo.geocaching;
import java.util.ArrayList;
+import java.util.List;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
@@ -13,10 +14,11 @@ import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import cgeo.geocaching.activity.AbstractActivity;
+import cgeo.geocaching.utils.CollectionUtils;
public class cgeosmaps extends AbstractActivity {
- private ArrayList<Bitmap> maps = new ArrayList<Bitmap>();
+ private List<Bitmap> maps = new ArrayList<Bitmap>();
private String geocode = null;
private LayoutInflater inflater = null;
private ProgressDialog waitDialog = null;
@@ -27,7 +29,7 @@ public class cgeosmaps extends AbstractActivity {
@Override
public void handleMessage(Message msg) {
try {
- if (maps == null || maps.isEmpty()) {
+ if (CollectionUtils.isEmpty(maps)) {
if (waitDialog != null) {
waitDialog.dismiss();
}
diff --git a/src/cgeo/geocaching/cgeotouch.java b/src/cgeo/geocaching/cgeotouch.java
index a085255..60c066c 100644
--- a/src/cgeo/geocaching/cgeotouch.java
+++ b/src/cgeo/geocaching/cgeotouch.java
@@ -3,6 +3,11 @@ package cgeo.geocaching;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
import android.app.Dialog;
import android.app.ProgressDialog;
@@ -24,7 +29,7 @@ import android.widget.TextView;
public class cgeotouch extends cgLogForm {
private cgTrackable trackable = null;
- private ArrayList<Integer> types = new ArrayList<Integer>();
+ private List<Integer> types = new ArrayList<Integer>();
private ProgressDialog waitDialog = null;
private String guid = null;
private String geocode = null;
@@ -46,7 +51,7 @@ public class cgeotouch extends cgLogForm {
private Handler loadDataHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
- if (cgBase.isEmpty(viewstates) && attempts < 2) {
+ if (ArrayUtils.isEmpty(viewstates) && attempts < 2) {
showToast(res.getString(R.string.err_log_load_data_again));
loadData thread;
@@ -54,7 +59,7 @@ public class cgeotouch extends cgLogForm {
thread.start();
return;
- } else if (cgBase.isEmpty(viewstates) && attempts >= 2) {
+ } else if (ArrayUtils.isEmpty(viewstates) && attempts >= 2) {
showToast(res.getString(R.string.err_log_load_data));
showProgress(false);
@@ -125,7 +130,7 @@ public class cgeotouch extends cgLogForm {
trackable = app.getTrackableByGeocode("logging trackable");
- if (trackable.name != null && trackable.name.length() > 0) {
+ if (StringUtils.isNotBlank(trackable.name)) {
setTitle(res.getString(R.string.trackable_touch) + trackable.name);
} else {
setTitle(res.getString(R.string.trackable_touch) + trackable.geocode.toUpperCase());
@@ -285,7 +290,7 @@ public class cgeotouch extends cgLogForm {
tweetCheck.setChecked(true);
Button buttonPost = (Button)findViewById(R.id.post);
- if (cgBase.isEmpty(viewstates)) {
+ if (ArrayUtils.isEmpty(viewstates)) {
buttonPost.setEnabled(false);
buttonPost.setOnTouchListener(null);
buttonPost.setOnClickListener(null);
@@ -358,14 +363,14 @@ public class cgeotouch extends cgLogForm {
@Override
public void run() {
- final HashMap<String, String> params = new HashMap<String, String>();
+ final Map<String, String> params = new HashMap<String, String>();
showProgressHandler.sendEmptyMessage(0);
gettingViewstate = true;
attempts ++;
try {
- if (guid != null && guid.length() > 0) {
+ if (StringUtils.isNotBlank(guid)) {
params.put("wid", guid);
} else {
loadDataHandler.sendEmptyMessage(0);
@@ -376,7 +381,7 @@ public class cgeotouch extends cgLogForm {
viewstates = cgBase.getViewstates(page);
- final ArrayList<Integer> typesPre = cgBase.parseTypes(page);
+ final List<Integer> typesPre = cgBase.parseTypes(page);
if (typesPre.size() > 0) {
types.clear();
types.addAll(typesPre);
@@ -428,7 +433,7 @@ public class cgeotouch extends cgLogForm {
if (
status == 1 && settings.twitter == 1 &&
- settings.tokenPublic != null && settings.tokenPublic.length() > 0 && settings.tokenSecret != null && settings.tokenSecret.length() > 0 &&
+ StringUtils.isNotBlank(settings.tokenPublic) && StringUtils.isNotBlank(settings.tokenSecret) &&
tweetCheck.isChecked() && tweetBox.getVisibility() == View.VISIBLE
) {
cgBase.postTweetTrackable(app, settings, geocode);
diff --git a/src/cgeo/geocaching/cgeotrackable.java b/src/cgeo/geocaching/cgeotrackable.java
index d41324e..c323894 100644
--- a/src/cgeo/geocaching/cgeotrackable.java
+++ b/src/cgeo/geocaching/cgeotrackable.java
@@ -3,6 +3,9 @@ package cgeo.geocaching;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
import android.app.ProgressDialog;
import android.content.Intent;
@@ -51,7 +54,7 @@ public class cgeotrackable extends AbstractActivity {
return;
}
- if (trackable != null && trackable.error.length() > 0) {
+ if (trackable != null && StringUtils.isNotBlank(trackable.error)) {
showToast(res.getString(R.string.err_tb_details_download) + " " + trackable.error + ".");
finish();
@@ -63,7 +66,7 @@ public class cgeotrackable extends AbstractActivity {
waitDialog.dismiss();
}
- if (geocode != null && geocode.length() > 0) {
+ if (StringUtils.isNotBlank(geocode)) {
showToast(res.getString(R.string.err_tb_find) + " " + geocode + ".");
} else {
showToast(res.getString(R.string.err_tb_find_that));
@@ -77,7 +80,7 @@ public class cgeotrackable extends AbstractActivity {
inflater = getLayoutInflater();
geocode = trackable.geocode.toUpperCase();
- if (trackable.name != null && trackable.name.length() > 0) {
+ if (StringUtils.isNotBlank(trackable.name)) {
setTitle(Html.fromHtml(trackable.name).toString());
} else {
setTitle(trackable.name.toUpperCase());
@@ -87,7 +90,7 @@ public class cgeotrackable extends AbstractActivity {
LinearLayout detailsList = (LinearLayout) findViewById(R.id.details_list);
// actiobar icon
- if (trackable.iconUrl != null && trackable.iconUrl.length() > 0) {
+ if (StringUtils.isNotBlank(trackable.iconUrl)) {
final tbIconHandler iconHandler = new tbIconHandler(((TextView) findViewById(R.id.actionbar_title)));
final tbIconThread iconThread = new tbIconThread(trackable.iconUrl, iconHandler);
iconThread.start();
@@ -99,7 +102,7 @@ public class cgeotrackable extends AbstractActivity {
itemValue = (TextView) itemLayout.findViewById(R.id.value);
itemName.setText(res.getString(R.string.trackable_name));
- if (trackable.name != null) {
+ if (StringUtils.isNotBlank(trackable.name)) {
itemValue.setText(Html.fromHtml(trackable.name).toString());
} else {
itemValue.setText(res.getString(R.string.trackable_unknown));
@@ -112,7 +115,7 @@ public class cgeotrackable extends AbstractActivity {
itemValue = (TextView) itemLayout.findViewById(R.id.value);
String tbType = null;
- if (trackable.type != null && trackable.type.length() > 0) {
+ if (StringUtils.isNotBlank(trackable.type)) {
tbType = Html.fromHtml(trackable.type).toString();
} else {
tbType = res.getString(R.string.trackable_unknown);
@@ -136,7 +139,7 @@ public class cgeotrackable extends AbstractActivity {
itemValue = (TextView) itemLayout.findViewById(R.id.value);
itemName.setText(res.getString(R.string.trackable_owner));
- if (trackable.owner != null) {
+ if (StringUtils.isNotBlank(trackable.owner)) {
itemValue.setText(Html.fromHtml(trackable.owner), TextView.BufferType.SPANNABLE);
itemLayout.setOnClickListener(new userActions());
} else {
@@ -145,10 +148,9 @@ public class cgeotrackable extends AbstractActivity {
detailsList.addView(itemLayout);
// trackable spotted
- if (
- (trackable.spottedName != null && trackable.spottedName.length() > 0) ||
- trackable.spottedType == cgTrackable.SPOTTED_UNKNOWN ||
- trackable.spottedType == cgTrackable.SPOTTED_OWNER
+ if (StringUtils.isNotBlank(trackable.spottedName) ||
+ trackable.spottedType == cgTrackable.SPOTTED_UNKNOWN ||
+ trackable.spottedType == cgTrackable.SPOTTED_OWNER
) {
itemLayout = (RelativeLayout)inflater.inflate(R.layout.cache_item, null);
itemName = (TextView) itemLayout.findViewById(R.id.name);
@@ -189,7 +191,7 @@ public class cgeotrackable extends AbstractActivity {
}
// trackable origin
- if (trackable.origin != null && trackable.origin.length() > 0) {
+ if (StringUtils.isNotBlank(trackable.origin)) {
itemLayout = (RelativeLayout)inflater.inflate(R.layout.cache_item, null);
itemName = (TextView) itemLayout.findViewById(R.id.name);
itemValue = (TextView) itemLayout.findViewById(R.id.value);
@@ -223,7 +225,7 @@ public class cgeotrackable extends AbstractActivity {
// trackable goal
- if (trackable.goal != null && trackable.goal.length() > 0) {
+ if (StringUtils.isNotBlank(trackable.goal)) {
((LinearLayout) findViewById(R.id.goal_box)).setVisibility(View.VISIBLE);
TextView descView = (TextView) findViewById(R.id.goal);
descView.setVisibility(View.VISIBLE);
@@ -232,7 +234,7 @@ public class cgeotrackable extends AbstractActivity {
}
// trackable details
- if (trackable.details != null && trackable.details.length() > 0) {
+ if (StringUtils.isNotBlank(trackable.details)) {
((LinearLayout) findViewById(R.id.details_box)).setVisibility(View.VISIBLE);
TextView descView = (TextView) findViewById(R.id.details);
descView.setVisibility(View.VISIBLE);
@@ -241,7 +243,7 @@ public class cgeotrackable extends AbstractActivity {
}
// trackable image
- if (trackable.image != null && trackable.image.length() > 0) {
+ if (StringUtils.isNotBlank(trackable.image)) {
((LinearLayout) findViewById(R.id.image_box)).setVisibility(View.VISIBLE);
LinearLayout imgView = (LinearLayout) findViewById(R.id.image);
@@ -331,15 +333,15 @@ public class cgeotrackable extends AbstractActivity {
guid = uri.getQueryParameter("guid");
id = uri.getQueryParameter("id");
- if (geocode != null && geocode.length() > 0) {
+ if (StringUtils.isNotBlank(geocode)) {
geocode = geocode.toUpperCase();
guid = null;
id = null;
- } else if (guid != null && guid.length() > 0) {
+ } else if (StringUtils.isNotBlank(guid)) {
geocode = null;
guid = guid.toLowerCase();
id = null;
- } else if (id != null && id.length() > 0) {
+ } else if (StringUtils.isNotBlank(id)) {
geocode = null;
guid = null;
id = id.toLowerCase();
@@ -369,9 +371,9 @@ public class cgeotrackable extends AbstractActivity {
return;
}
- if (name != null && name.length() > 0) {
+ if (StringUtils.isNotBlank(name)) {
waitDialog = ProgressDialog.show(this, Html.fromHtml(name).toString(), res.getString(R.string.trackable_details_loading), true);
- } else if (geocode != null && geocode.length() > 0) {
+ } else if (StringUtils.isNotBlank(geocode)) {
waitDialog = ProgressDialog.show(this, geocode.toUpperCase(), res.getString(R.string.trackable_details_loading), true);
} else {
waitDialog = ProgressDialog.show(this, res.getString(R.string.trackable), res.getString(R.string.trackable_details_loading), true);
@@ -485,12 +487,12 @@ public class cgeotrackable extends AbstractActivity {
}
public void loadTrackableFn(String geocode, String guid, String id) {
- HashMap<String, String> params = new HashMap<String, String>();
- if (geocode != null && geocode.length() > 0) {
+ Map<String, String> params = new HashMap<String, String>();
+ if (StringUtils.isNotBlank(geocode)) {
params.put("geocode", geocode);
- } else if (guid != null && guid.length() > 0) {
+ } else if (StringUtils.isNotBlank(guid)) {
params.put("guid", guid);
- } else if (id != null && id.length() > 0) {
+ } else if (StringUtils.isNotBlank(id)) {
params.put("id", id);
} else {
return;
@@ -522,7 +524,7 @@ public class cgeotrackable extends AbstractActivity {
}
((TextView) rowView.findViewById(R.id.author)).setText(Html.fromHtml(log.author), TextView.BufferType.SPANNABLE);
- if (log.cacheName == null || log.cacheName.length() == 0) {
+ if (StringUtils.isBlank(log.cacheName)) {
((TextView) rowView.findViewById(R.id.location)).setVisibility(View.GONE);
} else {
((TextView) rowView.findViewById(R.id.location)).setText(Html.fromHtml(log.cacheName));
@@ -616,4 +618,13 @@ public class cgeotrackable extends AbstractActivity {
}
}
}
+
+ public static void startActivity(final AbstractActivity fromContext,
+ final String guid, final String geocode, final String name) {
+ Intent trackableIntent = new Intent(fromContext, cgeotrackable.class);
+ trackableIntent.putExtra("guid", guid);
+ trackableIntent.putExtra("geocode", geocode);
+ trackableIntent.putExtra("name", name);
+ fromContext.startActivity(trackableIntent);
+ }
}
diff --git a/src/cgeo/geocaching/cgeotrackables.java b/src/cgeo/geocaching/cgeotrackables.java
index 3005ad4..1ad5e46 100644
--- a/src/cgeo/geocaching/cgeotrackables.java
+++ b/src/cgeo/geocaching/cgeotrackables.java
@@ -1,9 +1,9 @@
package cgeo.geocaching;
import java.util.ArrayList;
+import java.util.List;
import android.app.ProgressDialog;
-import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -16,7 +16,7 @@ import android.widget.LinearLayout;
import cgeo.geocaching.activity.AbstractActivity;
public class cgeotrackables extends AbstractActivity {
- private ArrayList<cgTrackable> trackables = new ArrayList<cgTrackable>();
+ private List<cgTrackable> trackables = new ArrayList<cgTrackable>();
private String geocode = null;
private LayoutInflater inflater = null;
private LinearLayout addList = null;
@@ -43,6 +43,11 @@ public class cgeotrackables extends AbstractActivity {
finish();
return;
+ } else if (trackables.size() == 1){
+ cgTrackable trackable = trackables.get(0);
+ cgeotrackable.startActivity(cgeotrackables.this, trackable.guid, trackable.geocode, trackable.name);
+ finish();
+ return;
} else {
LinearLayout oneTbPre = null;
for (cgTrackable trackable : trackables) {
@@ -139,13 +144,7 @@ public class cgeotrackables extends AbstractActivity {
}
public void onClick(View arg0) {
- Intent trackableIntent = new Intent(cgeotrackables.this, cgeotrackable.class);
- trackableIntent.putExtra("guid", guid);
- trackableIntent.putExtra("geocode", geocode);
- trackableIntent.putExtra("name", name);
- startActivity(trackableIntent);
-
- finish();
+ cgeotrackable.startActivity(cgeotrackables.this, guid, geocode, name);
return;
}
}
diff --git a/src/cgeo/geocaching/cgeovisit.java b/src/cgeo/geocaching/cgeovisit.java
index c26dba4..65a09c7 100644
--- a/src/cgeo/geocaching/cgeovisit.java
+++ b/src/cgeo/geocaching/cgeovisit.java
@@ -4,7 +4,12 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
+import java.util.List;
import java.util.Locale;
+import java.util.Map;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
import android.app.Dialog;
import android.app.ProgressDialog;
@@ -26,6 +31,7 @@ import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import cgeo.geocaching.LogTemplateProvider.LogTemplate;
+import cgeo.geocaching.utils.CollectionUtils;
public class cgeovisit extends cgLogForm {
static final String EXTRAS_FOUND = "found";
@@ -38,7 +44,7 @@ public class cgeovisit extends cgLogForm {
private LayoutInflater inflater = null;
private cgCache cache = null;
- private ArrayList<Integer> types = new ArrayList<Integer>();
+ private List<Integer> types = new ArrayList<Integer>();
private ProgressDialog waitDialog = null;
private String cacheid = null;
private String geocode = null;
@@ -46,7 +52,7 @@ public class cgeovisit extends cgLogForm {
private boolean alreadyFound = false;
private String[] viewstates = null;
private Boolean gettingViewstate = true;
- private ArrayList<cgTrackableLog> trackables = null;
+ private List<cgTrackableLog> trackables = null;
private Calendar date = Calendar.getInstance();
private int typeSelected = 1;
private int attempts = 0;
@@ -79,7 +85,7 @@ public class cgeovisit extends cgLogForm {
showToast(res.getString(R.string.info_log_type_changed));
}
- if (cgBase.isEmpty(viewstates) && attempts < 2) {
+ if (ArrayUtils.isEmpty(viewstates) && attempts < 2) {
showToast(res.getString(R.string.err_log_load_data_again));
loadData thread;
@@ -87,7 +93,7 @@ public class cgeovisit extends cgLogForm {
thread.start();
return;
- } else if (cgBase.isEmpty(viewstates) && attempts >= 2) {
+ } else if (ArrayUtils.isEmpty(viewstates) && attempts >= 2) {
showToast(res.getString(R.string.err_log_load_data));
showProgress(false);
@@ -103,7 +109,7 @@ public class cgeovisit extends cgLogForm {
post.setOnClickListener(new postListener());
// add trackables
- if (trackables != null && trackables.isEmpty() == false) {
+ if (CollectionUtils.isNotEmpty(trackables)) {
if (inflater == null) {
inflater = getLayoutInflater();
}
@@ -234,16 +240,16 @@ public class cgeovisit extends cgLogForm {
alreadyFound = extras.getBoolean(EXTRAS_FOUND);
}
- if ((cacheid == null || cacheid.length() == 0) && geocode != null && geocode.length() > 0) {
+ if ((StringUtils.isBlank(cacheid)) && StringUtils.isNotBlank(geocode)) {
cacheid = app.getCacheid(geocode);
}
- if ((geocode == null || geocode.length() == 0) && cacheid != null && cacheid.length() > 0) {
+ if ((StringUtils.isBlank(geocode)) && StringUtils.isNotBlank(cacheid)) {
geocode = app.getGeocode(cacheid);
}
cache = app.getCacheByGeocode(geocode);
- if (cache.name != null && cache.name.length() > 0) {
+ if (StringUtils.isNotBlank(cache.name)) {
setTitle(res.getString(R.string.log_new_log) + " " + cache.name);
} else {
setTitle(res.getString(R.string.log_new_log) + " " + cache.geocode.toUpperCase());
@@ -305,7 +311,7 @@ public class cgeovisit extends cgLogForm {
boolean signatureAvailable = settings.getSignature() != null;
menu.findItem(MENU_SIGNATURE).setVisible(signatureAvailable);
- boolean voteAvailable = settings.isGCvoteLogin() && typeSelected == cgBase.LOG_FOUND_IT && cache.guid != null && cache.guid.length() > 0;
+ boolean voteAvailable = settings.isGCvoteLogin() && typeSelected == cgBase.LOG_FOUND_IT && StringUtils.isNotBlank(cache.guid);
menu.findItem(SUBMENU_VOTE).setVisible(voteAvailable);
return true;
@@ -318,7 +324,7 @@ public class cgeovisit extends cgLogForm {
if (id == MENU_SIGNATURE) {
EditText log = (EditText) findViewById(R.id.log);
String content = log.getText().toString();
- if (content.length() > 0) {
+ if (StringUtils.isNotBlank(content)) {
insertIntoLog("\n");
}
insertIntoLog(LogTemplateProvider.applyTemplates(settings.getSignature(), base));
@@ -355,19 +361,19 @@ public class cgeovisit extends cgLogForm {
}
public boolean setRating(String guid, double vote) {
- if (guid == null || guid.length() == 0) {
+ if (StringUtils.isBlank(guid)) {
return false;
}
if (vote < 0.0 || vote > 5.0) {
return false;
}
- final HashMap<String, String> login = settings.getGCvoteLogin();
+ final Map<String, String> login = settings.getGCvoteLogin();
if (login == null) {
return false;
}
- final HashMap<String, String> params = new HashMap<String, String>();
+ final Map<String, String> params = new HashMap<String, String>();
params.put("userName", login.get("username"));
params.put("password", login.get("password"));
params.put("cacheId", guid);
@@ -498,10 +504,9 @@ public class cgeovisit extends cgLogForm {
}
post.setText(res.getString(R.string.log_post_no_rate));
}
- } else if (settings.getSignature() != null
+ } else if (StringUtils.isNotBlank(settings.getSignature())
&& settings.signatureAutoinsert
- && settings.getSignature().length() > 0
- && 0 == ((EditText) findViewById(R.id.log)).getText().length()) {
+ && StringUtils.isBlank(((EditText) findViewById(R.id.log)).getText())) {
insertIntoLog(LogTemplateProvider.applyTemplates(settings.getSignature(), base));
}
@@ -529,7 +534,7 @@ public class cgeovisit extends cgLogForm {
dateButton.setOnClickListener(new cgeovisitDateListener());
EditText logView = (EditText) findViewById(R.id.log);
- if (logView.getText().length() == 0 && text != null && text.length() > 0) {
+ if (StringUtils.isBlank(logView.getText()) && StringUtils.isNotBlank(text) ) {
logView.setText(text);
}
@@ -545,7 +550,7 @@ public class cgeovisit extends cgLogForm {
if (post == null) {
post = (Button) findViewById(R.id.post);
}
- if (cgBase.isEmpty(viewstates)) {
+ if (ArrayUtils.isEmpty(viewstates)) {
post.setEnabled(false);
post.setOnTouchListener(null);
post.setOnClickListener(null);
@@ -670,7 +675,7 @@ public class cgeovisit extends cgLogForm {
dateButton.setOnClickListener(new cgeovisitDateListener());
EditText logView = (EditText) findViewById(R.id.log);
- if (text != null && text.length() > 0) {
+ if (StringUtils.isNotBlank(text)) {
logView.setText(text);
} else {
logView.setText("");
@@ -698,14 +703,14 @@ public class cgeovisit extends cgLogForm {
@Override
public void run() {
- final HashMap<String, String> params = new HashMap<String, String>();
+ final Map<String, String> params = new HashMap<String, String>();
showProgressHandler.sendEmptyMessage(0);
gettingViewstate = true;
attempts++;
try {
- if (cacheid != null && cacheid.length() > 0) {
+ if (StringUtils.isNotBlank(cacheid)) {
params.put("ID", cacheid);
} else {
loadDataHandler.sendEmptyMessage(0);
@@ -717,8 +722,8 @@ public class cgeovisit extends cgLogForm {
viewstates = cgBase.getViewstates(page);
trackables = cgBase.parseTrackableLog(page);
- final ArrayList<Integer> typesPre = cgBase.parseTypes(page);
- if (typesPre.size() > 0) {
+ final List<Integer> typesPre = cgBase.parseTypes(page);
+ if (CollectionUtils.isNotEmpty(typesPre)) {
types.clear();
types.addAll(typesPre);
types.remove(Integer.valueOf(cgBase.LOG_UPDATE_COORDINATES));
@@ -799,8 +804,8 @@ public class cgeovisit extends cgLogForm {
if (
status == 1 && typeSelected == cgBase.LOG_FOUND_IT && settings.twitter == 1
- && settings.tokenPublic != null && settings.tokenPublic.length() > 0 && settings.tokenSecret != null
- && settings.tokenSecret.length() > 0 && tweetCheck.isChecked() && tweetBox.getVisibility() == View.VISIBLE
+ && StringUtils.isNotBlank(settings.tokenPublic) && StringUtils.isNotBlank(settings.tokenSecret)
+ && tweetCheck.isChecked() && tweetBox.getVisibility() == View.VISIBLE
) {
cgBase.postTweetCache(app, settings, geocode);
}
diff --git a/src/cgeo/geocaching/cgeowaypoint.java b/src/cgeo/geocaching/cgeowaypoint.java
index 59a6fb3..d623bb9 100644
--- a/src/cgeo/geocaching/cgeowaypoint.java
+++ b/src/cgeo/geocaching/cgeowaypoint.java
@@ -2,6 +2,8 @@ package cgeo.geocaching;
import java.util.ArrayList;
+import org.apache.commons.lang3.StringUtils;
+
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
@@ -56,7 +58,7 @@ public class cgeowaypoint extends AbstractActivity {
final View headline = (View) findViewById(R.id.headline);
registerNavigationMenu(headline);
- if (waypoint.name != null && waypoint.name.length() > 0) {
+ if (StringUtils.isNotBlank(waypoint.name)) {
setTitle(Html.fromHtml(waypoint.name.trim()).toString());
} else {
setTitle(res.getString(R.string.waypoint_title));
@@ -81,7 +83,7 @@ public class cgeowaypoint extends AbstractActivity {
}
registerNavigationMenu(coords);
- if (waypoint.note != null && waypoint.note.length() > 0) {
+ if (StringUtils.isNotBlank(waypoint.note)) {
final TextView note = (TextView) findViewById(R.id.note);
note.setText(Html.fromHtml(waypoint.note.trim()), TextView.BufferType.SPANNABLE);
registerNavigationMenu(note);
@@ -344,4 +346,4 @@ public class cgeowaypoint extends AbstractActivity {
public boolean onContextItemSelected(MenuItem item) {
return onOptionsItemSelected(item);
}
-} \ No newline at end of file
+}
diff --git a/src/cgeo/geocaching/cgeowaypointadd.java b/src/cgeo/geocaching/cgeowaypointadd.java
index 6e61e10..3c46ad0 100644
--- a/src/cgeo/geocaching/cgeowaypointadd.java
+++ b/src/cgeo/geocaching/cgeowaypointadd.java
@@ -1,10 +1,13 @@
package cgeo.geocaching;
import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.lang3.StringUtils;
+
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
@@ -94,7 +97,7 @@ public class cgeowaypointadd extends AbstractActivity {
id = extras.getInt("waypoint");
}
- if ((geocode == null || geocode.length() == 0) && id <= 0) {
+ if (StringUtils.isBlank(geocode) && id <= 0) {
showToast(res.getString(R.string.err_waypoint_cache_unknown));
finish();
@@ -119,7 +122,7 @@ public class cgeowaypointadd extends AbstractActivity {
Button addWaypoint = (Button) findViewById(R.id.add_waypoint);
addWaypoint.setOnClickListener(new coordsListener());
- ArrayList<String> wayPointNames = new ArrayList<String>(cgBase.waypointTypes.values());
+ List<String> wayPointNames = new ArrayList<String>(cgBase.waypointTypes.values());
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.name);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, wayPointNames);
textView.setAdapter(adapter);
@@ -220,7 +223,7 @@ public class cgeowaypointadd extends AbstractActivity {
coordsDialog.setCancelable(true);
coordsDialog.setOnCoordinateUpdate(new cgeocoords.CoordinateUpdate() {
@Override
- public void update(ArrayList<Double> coords) {
+ public void update(List<Double> coords) {
((Button) findViewById(R.id.buttonLatitude)).setText(cgBase.formatLatitude(coords.get(0), true));
((Button) findViewById(R.id.buttonLongitude)).setText(cgBase.formatLongitude(coords.get(1), true));
if (waypoint != null) {
@@ -236,7 +239,7 @@ public class cgeowaypointadd extends AbstractActivity {
private class coordsListener implements View.OnClickListener {
public void onClick(View arg0) {
- ArrayList<Double> coords = new ArrayList<Double>();
+ List<Double> coords = new ArrayList<Double>();
Double latitude = null;
Double longitude = null;
@@ -245,16 +248,16 @@ public class cgeowaypointadd extends AbstractActivity {
final String latText = ((Button) findViewById(R.id.buttonLatitude)).getText().toString();
final String lonText = ((Button) findViewById(R.id.buttonLongitude)).getText().toString();
- if ((bearingText == null || bearingText.length() == 0) && (distanceText == null || distanceText.length() == 0)
- && (latText == null || latText.length() == 0) && (lonText == null || lonText.length() == 0)) {
+ if (StringUtils.isNotBlank(bearingText) && StringUtils.isNotBlank(distanceText)
+ && StringUtils.isNotBlank(latText) && StringUtils.isNotBlank(lonText)) {
helpDialog(res.getString(R.string.err_point_no_position_given_title), res.getString(R.string.err_point_no_position_given));
return;
}
- if (latText != null && latText.length() > 0 && lonText != null && lonText.length() > 0) {
+ if (StringUtils.isNotBlank(latText) && StringUtils.isNotBlank(lonText)) {
// latitude & longitude
- HashMap<String, Object> latParsed = cgBase.parseCoordinate(latText, "lat");
- HashMap<String, Object> lonParsed = cgBase.parseCoordinate(lonText, "lon");
+ Map<String, Object> latParsed = cgBase.parseCoordinate(latText, "lat");
+ Map<String, Object> lonParsed = cgBase.parseCoordinate(lonText, "lon");
if (latParsed == null || latParsed.get("coordinate") == null || latParsed.get("string") == null) {
showToast(res.getString(R.string.err_parse_lat));
@@ -278,7 +281,7 @@ public class cgeowaypointadd extends AbstractActivity {
longitude = geo.longitudeNow;
}
- if (bearingText != null && bearingText.length() > 0 && distanceText != null && distanceText.length() > 0) {
+ if (StringUtils.isNotBlank(bearingText) && StringUtils.isNotBlank(distanceText)) {
// bearing & distance
Double bearing = null;
try {
@@ -335,7 +338,7 @@ public class cgeowaypointadd extends AbstractActivity {
Double latParsed = null;
Double lonParsed = null;
- HashMap<String, Double> coordsDst = cgBase.getRadialDistance(latitude, longitude, bearing, distance);
+ Map<String, Double> coordsDst = cgBase.getRadialDistance(latitude, longitude, bearing, distance);
latParsed = coordsDst.get("latitude");
lonParsed = coordsDst.get("longitude");
@@ -392,4 +395,4 @@ public class cgeowaypointadd extends AbstractActivity {
ActivityMixin.goManual(this, "c:geo-waypoint-new");
}
}
-} \ No newline at end of file
+}
diff --git a/src/cgeo/geocaching/connector/GCConnector.java b/src/cgeo/geocaching/connector/GCConnector.java
index 5d5de6b..1d61d2f 100644
--- a/src/cgeo/geocaching/connector/GCConnector.java
+++ b/src/cgeo/geocaching/connector/GCConnector.java
@@ -1,12 +1,14 @@
package cgeo.geocaching.connector;
+import org.apache.commons.lang3.StringUtils;
+
import cgeo.geocaching.cgCache;
public class GCConnector extends AbstractConnector implements IConnector {
@Override
public boolean canHandle(String geocode) {
- return geocode != null && geocode.toUpperCase().startsWith("GC");
+ return StringUtils.isNotBlank(geocode) && geocode.toUpperCase().startsWith("GC");
}
@Override
diff --git a/src/cgeo/geocaching/connector/OCConnector.java b/src/cgeo/geocaching/connector/OCConnector.java
index d23b3cd..8d1c42f 100644
--- a/src/cgeo/geocaching/connector/OCConnector.java
+++ b/src/cgeo/geocaching/connector/OCConnector.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.connector;
+import org.apache.commons.lang3.StringUtils;
+
import cgeo.geocaching.cgCache;
/**
@@ -9,7 +11,7 @@ import cgeo.geocaching.cgCache;
public class OCConnector extends AbstractConnector implements IConnector {
@Override
public boolean canHandle(String geocode) {
- return geocode != null && geocode.toUpperCase().startsWith("OC");
+ return StringUtils.isNotBlank(geocode) && geocode.toUpperCase().startsWith("OC");
}
@Override
diff --git a/src/cgeo/geocaching/connector/OXConnector.java b/src/cgeo/geocaching/connector/OXConnector.java
index 75d404e..dc78044 100644
--- a/src/cgeo/geocaching/connector/OXConnector.java
+++ b/src/cgeo/geocaching/connector/OXConnector.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.connector;
+import org.apache.commons.lang3.StringUtils;
+
import cgeo.geocaching.cgCache;
/**
@@ -10,7 +12,7 @@ public class OXConnector extends AbstractConnector implements IConnector {
@Override
public boolean canHandle(String geocode) {
- return geocode != null && geocode.toUpperCase().startsWith("OX");
+ return StringUtils.isNotBlank(geocode) && geocode.toUpperCase().startsWith("OX");
}
@Override
diff --git a/src/cgeo/geocaching/files/FileList.java b/src/cgeo/geocaching/files/FileList.java
index eae1e4d..08c8b11 100644
--- a/src/cgeo/geocaching/files/FileList.java
+++ b/src/cgeo/geocaching/files/FileList.java
@@ -2,6 +2,9 @@ package cgeo.geocaching.files;
import java.io.File;
import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang3.ArrayUtils;
import android.app.ProgressDialog;
import android.content.DialogInterface;
@@ -17,7 +20,7 @@ import cgeo.geocaching.activity.AbstractListActivity;
public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractListActivity {
- private ArrayList<File> files = new ArrayList<File>();
+ private List<File> files = new ArrayList<File>();
private T adapter = null;
private ProgressDialog waitDialog = null;
private loadFiles searchingThread = null;
@@ -113,7 +116,7 @@ public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractLis
getSettings().load();
}
- protected abstract T getAdapter(ArrayList<File> files);
+ protected abstract T getAdapter(List<File> files);
private void setAdapter() {
if (adapter == null) {
@@ -140,7 +143,7 @@ public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractLis
@Override
public void run() {
- ArrayList<File> list = new ArrayList<File>();
+ List<File> list = new ArrayList<File>();
try {
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
@@ -178,14 +181,14 @@ public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractLis
}
}
- private void listDir(ArrayList<File> result, File directory) {
+ private void listDir(List<File> result, File directory) {
if (directory == null || !directory.isDirectory() || !directory.canRead()) {
return;
}
final File[] files = directory.listFiles();
- if (files != null && files.length > 0) {
+ if (ArrayUtils.isNotEmpty(files)) {
for (File file : files) {
if (endSearching) {
return;
diff --git a/src/cgeo/geocaching/files/GPXParser.java b/src/cgeo/geocaching/files/GPXParser.java
index e96c1d6..0719621 100644
--- a/src/cgeo/geocaching/files/GPXParser.java
+++ b/src/cgeo/geocaching/files/GPXParser.java
@@ -9,9 +9,11 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
+import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.lang3.StringUtils;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
@@ -196,7 +198,7 @@ public abstract class GPXParser extends FileParser {
return formatSimple.parse(input);
}
- public long parse(final InputStream stream, Handler handlerIn) {
+ public UUID parse(final InputStream stream, Handler handlerIn) {
handler = handlerIn;
final RootElement root = new RootElement(namespace, "gpx");
@@ -225,14 +227,14 @@ public abstract class GPXParser extends FileParser {
@Override
public void end() {
- if (cache.geocode == null || cache.geocode.length() == 0) {
+ if (StringUtils.isBlank(cache.geocode)) {
// try to find geocode somewhere else
findGeoCode(name);
findGeoCode(desc);
findGeoCode(cmt);
}
- if (cache.geocode != null && cache.geocode.length() > 0
+ if (StringUtils.isNotBlank(cache.geocode)
&& cache.latitude != null && cache.longitude != null
&& ((type == null && sym == null)
|| (type != null && type.indexOf("geocache") > -1)
@@ -340,7 +342,7 @@ public abstract class GPXParser extends FileParser {
final Matcher matcher = patternGuid.matcher(url);
if (matcher.matches()) {
String guid = matcher.group(1);
- if (guid.length() > 0) {
+ if (StringUtils.isNotBlank(guid)) {
cache.guid = guid;
}
}
@@ -476,7 +478,7 @@ public abstract class GPXParser extends FileParser {
@Override
public void end(String country) {
- if (cache.location == null || cache.location.length() == 0) {
+ if (StringUtils.isBlank(cache.location)) {
cache.location = validate(country);
} else {
cache.location = cache.location + ", " + country.trim();
@@ -489,7 +491,7 @@ public abstract class GPXParser extends FileParser {
@Override
public void end(String state) {
- if (cache.location == null || cache.location.length() == 0) {
+ if (StringUtils.isBlank(cache.location)) {
cache.location = validate(state);
} else {
cache.location = state.trim() + ", " + cache.location;
@@ -549,7 +551,7 @@ public abstract class GPXParser extends FileParser {
@Override
public void end() {
- if (trackable.geocode != null && trackable.geocode.length() > 0 && trackable.name != null && trackable.name.length() > 0) {
+ if (StringUtils.isNotBlank(trackable.geocode) && StringUtils.isNotBlank(trackable.name)) {
if (cache.inventory == null) {
cache.inventory = new ArrayList<cgTrackable>();
}
@@ -593,7 +595,7 @@ public abstract class GPXParser extends FileParser {
@Override
public void end() {
- if (log.log != null && log.log.length() > 0) {
+ if (StringUtils.isNotBlank(log.log)) {
if (cache.logs == null) {
cache.logs = new ArrayList<cgLog>();
}
@@ -656,16 +658,16 @@ public abstract class GPXParser extends FileParser {
} catch (SAXException e) {
Log.e(cgSettings.tag, "Cannot parse .gpx file as GPX " + version + ": could not parse XML - " + e.toString());
}
- return parsed ? search.getCurrentId() : 0L;
+ return parsed ? search.getCurrentId() : null;
}
- private long parse(final File file, final Handler handlerIn) {
+ private UUID parse(final File file, final Handler handlerIn) {
if (file == null) {
- return 0L;
+ return null;
}
FileInputStream fis = null;
- long result = 0L;
+ UUID result = null;
try {
fis = new FileInputStream(file);
result = parse(fis, handlerIn);
@@ -697,14 +699,14 @@ public abstract class GPXParser extends FileParser {
cache.type = knownType;
}
else {
- if (cache.type == null || cache.type.length() == 0) {
+ if (StringUtils.isBlank(cache.type)) {
cache.type = "mystery"; // default for not recognized types
}
}
}
private void findGeoCode(final String input) {
- if (input == null || (cache.geocode != null && cache.geocode.length() != 0)) {
+ if (input == null || StringUtils.isNotBlank(cache.geocode)) {
return;
}
final Matcher matcherGeocode = patternGeocode.matcher(input);
@@ -718,14 +720,14 @@ public abstract class GPXParser extends FileParser {
}
}
- public static Long parseGPX(cgeoapplication app, File file, int listId, Handler handler) {
+ public static UUID parseGPX(cgeoapplication app, File file, int listId, Handler handler) {
final cgSearch search = new cgSearch();
- long searchId = 0L;
+ UUID searchId = null;
try {
GPXParser parser = new GPX10Parser(app, listId, search);
searchId = parser.parse(file, handler);
- if (searchId == 0L) {
+ if (searchId == null) {
parser = new GPX11Parser(app, listId, search);
searchId = parser.parse(file, handler);
}
diff --git a/src/cgeo/geocaching/files/LocParser.java b/src/cgeo/geocaching/files/LocParser.java
index fd68fdc..9f7f525 100644
--- a/src/cgeo/geocaching/files/LocParser.java
+++ b/src/cgeo/geocaching/files/LocParser.java
@@ -2,10 +2,14 @@ package cgeo.geocaching.files;
import java.io.File;
import java.util.HashMap;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.lang3.StringUtils;
+
import android.os.Handler;
import android.util.Log;
import cgeo.geocaching.cgBase;
@@ -34,7 +38,7 @@ public final class LocParser extends FileParser {
public static void parseLoc(final cgCacheWrap caches,
final String fileContent) {
- final HashMap<String, cgCoord> cidCoords = parseCoordinates(fileContent);
+ final Map<String, cgCoord> cidCoords = parseCoordinates(fileContent);
// save found cache coordinates
for (cgCache cache : caches.cacheList) {
@@ -53,15 +57,15 @@ public final class LocParser extends FileParser {
cache.terrain = coord.terrain;
cache.size = coord.size;
cache.geocode = coord.geocode.toUpperCase();
- if (cache.name == null || cache.name.length() == 0) {
+ if (StringUtils.isBlank(cache.name)) {
cache.name = coord.name;
}
}
- private static HashMap<String, cgCoord> parseCoordinates(
+ private static Map<String, cgCoord> parseCoordinates(
final String fileContent) {
- final HashMap<String, cgCoord> coords = new HashMap<String, cgCoord>();
- if (fileContent == null || fileContent.length() <= 0) {
+ final Map<String, cgCoord> coords = new HashMap<String, cgCoord>();
+ if (StringUtils.isBlank(fileContent)) {
return coords;
}
// >> premium only
@@ -71,7 +75,7 @@ public final class LocParser extends FileParser {
// parse coordinates
for (String pointString : points) {
final cgCoord pointCoord = new cgCoord();
- HashMap<String, Object> tmp = null;
+ Map<String, Object> tmp = null;
final Matcher matcherGeocode = patternGeocode.matcher(pointString);
if (matcherGeocode.find()) {
@@ -131,7 +135,7 @@ public final class LocParser extends FileParser {
}
}
- if (pointCoord.geocode != null && pointCoord.geocode.length() > 0) {
+ if (StringUtils.isNotBlank(pointCoord.geocode)) {
coords.put(pointCoord.geocode, pointCoord);
}
}
@@ -141,17 +145,17 @@ public final class LocParser extends FileParser {
return coords;
}
- public static long parseLoc(cgeoapplication app, File file, int listId,
+ public static UUID parseLoc(cgeoapplication app, File file, int listId,
Handler handler) {
cgSearch search = new cgSearch();
- long searchId = 0L;
+ UUID searchId = null;
try {
- HashMap<String, cgCoord> coords = parseCoordinates(readFile(file).toString());
+ Map<String, cgCoord> coords = parseCoordinates(readFile(file).toString());
final cgCacheWrap caches = new cgCacheWrap();
for (Entry<String, cgCoord> entry : coords.entrySet()) {
cgCoord coord = entry.getValue();
- if (coord.geocode == null || coord.geocode.length() == 0 || coord.name == null || coord.name.length() == 0) {
+ if (StringUtils.isBlank(coord.geocode) || StringUtils.isBlank(coord.name)) {
continue;
}
cgCache cache = new cgCache();
diff --git a/src/cgeo/geocaching/googlemaps/googleMapView.java b/src/cgeo/geocaching/googlemaps/googleMapView.java
index 8a06edb..d31ea68 100644
--- a/src/cgeo/geocaching/googlemaps/googleMapView.java
+++ b/src/cgeo/geocaching/googlemaps/googleMapView.java
@@ -18,6 +18,7 @@ import cgeo.geocaching.mapinterfaces.GeoPointImpl;
import cgeo.geocaching.mapinterfaces.MapControllerImpl;
import cgeo.geocaching.mapinterfaces.MapProjectionImpl;
import cgeo.geocaching.mapinterfaces.MapViewImpl;
+import cgeo.geocaching.mapinterfaces.OnDragListener;
import cgeo.geocaching.mapinterfaces.OverlayBase;
import cgeo.geocaching.mapinterfaces.OverlayImpl;
import cgeo.geocaching.mapinterfaces.OverlayImpl.overlayType;
@@ -26,8 +27,9 @@ import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
-public class googleMapView extends MapView implements MapViewImpl{
+public class googleMapView extends MapView implements MapViewImpl {
private GestureDetector gestureDetector;
+ private OnDragListener onDragListener;
public googleMapView(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -159,6 +161,11 @@ public class googleMapView extends MapView implements MapViewImpl{
}
@Override
+ public void setOnDragListener(OnDragListener onDragListener) {
+ this.onDragListener = onDragListener;
+ }
+
+ @Override
public boolean onTouchEvent(MotionEvent ev) {
gestureDetector.onTouchEvent(ev);
return super.onTouchEvent(ev);
@@ -168,7 +175,19 @@ public class googleMapView extends MapView implements MapViewImpl{
@Override
public boolean onDoubleTap(MotionEvent e) {
getController().zoomInFixing((int) e.getX(), (int) e.getY());
+ if (onDragListener != null) {
+ onDragListener.onDrag();
+ }
return true;
}
+
+ @Override
+ public boolean onScroll(MotionEvent e1, MotionEvent e2,
+ float distanceX, float distanceY) {
+ if (onDragListener != null) {
+ onDragListener.onDrag();
+ }
+ return super.onScroll(e1, e2, distanceX, distanceY);
+ }
}
}
diff --git a/src/cgeo/geocaching/mapcommon/cgMapMyOverlay.java b/src/cgeo/geocaching/mapcommon/cgMapMyOverlay.java
index b8c8723..a004405 100644
--- a/src/cgeo/geocaching/mapcommon/cgMapMyOverlay.java
+++ b/src/cgeo/geocaching/mapcommon/cgMapMyOverlay.java
@@ -1,6 +1,7 @@
package cgeo.geocaching.mapcommon;
import java.util.ArrayList;
+import java.util.List;
import android.app.Activity;
import android.graphics.Bitmap;
@@ -8,9 +9,9 @@ import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
+import android.graphics.Paint.Style;
import android.graphics.PaintFlagsDrawFilter;
import android.graphics.Point;
-import android.graphics.Paint.Style;
import android.location.Location;
import cgeo.geocaching.R;
import cgeo.geocaching.cgBase;
@@ -38,7 +39,7 @@ public class cgMapMyOverlay implements OverlayBase {
private PaintFlagsDrawFilter setfil = null;
private PaintFlagsDrawFilter remfil = null;
private Location historyRecent = null;
- private ArrayList<Location> history = new ArrayList<Location>();
+ private List<Location> history = new ArrayList<Location>();
private Point historyPointN = new Point();
private Point historyPointP = new Point();
private Activity activity;
diff --git a/src/cgeo/geocaching/mapcommon/cgMapOverlay.java b/src/cgeo/geocaching/mapcommon/cgMapOverlay.java
index d3f7c00..475ded2 100644
--- a/src/cgeo/geocaching/mapcommon/cgMapOverlay.java
+++ b/src/cgeo/geocaching/mapcommon/cgMapOverlay.java
@@ -1,6 +1,9 @@
package cgeo.geocaching.mapcommon;
import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
import android.app.AlertDialog;
import android.app.ProgressDialog;
@@ -10,9 +13,9 @@ import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
+import android.graphics.Paint.Style;
import android.graphics.PaintFlagsDrawFilter;
import android.graphics.Point;
-import android.graphics.Paint.Style;
import android.location.Location;
import android.text.Html;
import android.util.Log;
@@ -33,7 +36,7 @@ import cgeo.geocaching.mapinterfaces.OverlayBase;
public class cgMapOverlay extends ItemizedOverlayBase implements OverlayBase {
- private ArrayList<CacheOverlayItemImpl> items = new ArrayList<CacheOverlayItemImpl>();
+ private List<CacheOverlayItemImpl> items = new ArrayList<CacheOverlayItemImpl>();
private Context context = null;
private Boolean fromDetail = false;
private boolean displayCircles = false;
@@ -59,13 +62,13 @@ public class cgMapOverlay extends ItemizedOverlayBase implements OverlayBase {
}
public void updateItems(CacheOverlayItemImpl item) {
- ArrayList<CacheOverlayItemImpl> itemsPre = new ArrayList<CacheOverlayItemImpl>();
+ List<CacheOverlayItemImpl> itemsPre = new ArrayList<CacheOverlayItemImpl>();
itemsPre.add(item);
updateItems(itemsPre);
}
- public void updateItems(ArrayList<CacheOverlayItemImpl> itemsPre) {
+ public void updateItems(List<CacheOverlayItemImpl> itemsPre) {
if (itemsPre == null) {
return;
}
@@ -199,7 +202,7 @@ public class cgMapOverlay extends ItemizedOverlayBase implements OverlayBase {
cgCoord coordinate = item.getCoord();
- if (coordinate.type != null && coordinate.type.equalsIgnoreCase("cache") && coordinate.geocode != null && coordinate.geocode.length() > 0) {
+ if (coordinate.type != null && coordinate.type.equalsIgnoreCase("cache") && StringUtils.isNotBlank(coordinate.geocode)) {
Intent popupIntent = new Intent(context, cgeopopup.class);
popupIntent.putExtra("fromdetail", fromDetail);
diff --git a/src/cgeo/geocaching/mapcommon/cgUsersOverlay.java b/src/cgeo/geocaching/mapcommon/cgUsersOverlay.java
index f2ba50d..ce6f236 100644
--- a/src/cgeo/geocaching/mapcommon/cgUsersOverlay.java
+++ b/src/cgeo/geocaching/mapcommon/cgUsersOverlay.java
@@ -1,9 +1,12 @@
package cgeo.geocaching.mapcommon;
import java.util.ArrayList;
+import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.lang3.StringUtils;
+
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
@@ -23,7 +26,7 @@ import cgeo.geocaching.mapinterfaces.UserOverlayItemImpl;
public class cgUsersOverlay extends ItemizedOverlayBase implements OverlayBase {
- private ArrayList<UserOverlayItemImpl> items = new ArrayList<UserOverlayItemImpl>();
+ private List<UserOverlayItemImpl> items = new ArrayList<UserOverlayItemImpl>();
private Context context = null;
private final Pattern patternGeocode = Pattern.compile("^(GC[A-Z0-9]+)(\\: ?(.+))?$", Pattern.CASE_INSENSITIVE);
@@ -35,13 +38,13 @@ public class cgUsersOverlay extends ItemizedOverlayBase implements OverlayBase {
}
protected void updateItems(UserOverlayItemImpl item) {
- ArrayList<UserOverlayItemImpl> itemsPre = new ArrayList<UserOverlayItemImpl>();
+ List<UserOverlayItemImpl> itemsPre = new ArrayList<UserOverlayItemImpl>();
itemsPre.add(item);
updateItems(itemsPre);
}
- public void updateItems(ArrayList<UserOverlayItemImpl> itemsPre) {
+ public void updateItems(List<UserOverlayItemImpl> itemsPre) {
if (itemsPre == null) {
return;
}
@@ -109,7 +112,7 @@ public class cgUsersOverlay extends ItemizedOverlayBase implements OverlayBase {
dialog.setTitle(user.username);
dialog.setMessage(action);
dialog.setCancelable(true);
- if (geocode != null && geocode.length() > 0) {
+ if (StringUtils.isNotBlank(geocode)) {
dialog.setPositiveButton(geocode + "?", new cacheDetails(geocode));
}
dialog.setNeutralButton("Dismiss", new DialogInterface.OnClickListener() {
diff --git a/src/cgeo/geocaching/mapcommon/cgeomap.java b/src/cgeo/geocaching/mapcommon/cgeomap.java
index 22ea40b..c9fb60b 100644
--- a/src/cgeo/geocaching/mapcommon/cgeomap.java
+++ b/src/cgeo/geocaching/mapcommon/cgeomap.java
@@ -2,7 +2,10 @@ package cgeo.geocaching.mapcommon;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Locale;
+import java.util.Map;
+import java.util.UUID;
import android.app.Activity;
import android.app.ProgressDialog;
@@ -29,22 +32,23 @@ import cgeo.geocaching.cgCoord;
import cgeo.geocaching.cgDirection;
import cgeo.geocaching.cgGeo;
import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.cgSettings.mapSourceEnum;
import cgeo.geocaching.cgUpdateDir;
import cgeo.geocaching.cgUpdateLoc;
import cgeo.geocaching.cgUser;
import cgeo.geocaching.cgWaypoint;
import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.activity.ActivityMixin;
-import cgeo.geocaching.cgSettings.mapSourceEnum;
import cgeo.geocaching.mapinterfaces.ActivityImpl;
import cgeo.geocaching.mapinterfaces.CacheOverlayItemImpl;
import cgeo.geocaching.mapinterfaces.GeoPointImpl;
import cgeo.geocaching.mapinterfaces.MapControllerImpl;
import cgeo.geocaching.mapinterfaces.MapFactory;
import cgeo.geocaching.mapinterfaces.MapViewImpl;
+import cgeo.geocaching.mapinterfaces.OnDragListener;
import cgeo.geocaching.mapinterfaces.UserOverlayItemImpl;
-public class cgeomap extends MapBase {
+public class cgeomap extends MapBase implements OnDragListener {
private static final int MENU_SELECT_MAPVIEW = 1;
private static final int MENU_MAP_LIVE = 2;
@@ -73,14 +77,14 @@ public class cgeomap extends MapBase {
private cgUpdateDir dirUpdate = new UpdateDir();
// from intent
private boolean fromDetailIntent = false;
- private Long searchIdIntent = null;
+ private String searchIdIntent = null;
private String geocodeIntent = null;
private Double latitudeIntent = null;
private Double longitudeIntent = null;
private String waypointTypeIntent = null;
private int[] mapStateIntent = null;
// status data
- private Long searchId = null;
+ private UUID searchId = null;
private String token = null;
private boolean noMapTokenShowed = false;
// map status data
@@ -112,10 +116,10 @@ public class cgeomap extends MapBase {
private cgMapMyOverlay overlayMyLoc = null;
// data for overlays
private int cachesCnt = 0;
- private HashMap<Integer, Drawable> iconsCache = new HashMap<Integer, Drawable>();
- private ArrayList<cgCache> caches = new ArrayList<cgCache>();
- private ArrayList<cgUser> users = new ArrayList<cgUser>();
- private ArrayList<cgCoord> coordinates = new ArrayList<cgCoord>();
+ private Map<Integer, Drawable> iconsCache = new HashMap<Integer, Drawable>();
+ private List<cgCache> caches = new ArrayList<cgCache>();
+ private List<cgUser> users = new ArrayList<cgUser>();
+ private List<cgCoord> coordinates = new ArrayList<cgCoord>();
// storing for offline
private ProgressDialog waitDialog = null;
private int detailTotal = 0;
@@ -264,6 +268,7 @@ public class cgeomap extends MapBase {
mapView.setBuiltInZoomControls(true);
mapView.displayZoomControls(true);
mapView.preLoad();
+ mapView.setOnDragListener(this);
// initialize overlays
mapView.clearOverlays();
@@ -301,14 +306,14 @@ public class cgeomap extends MapBase {
Bundle extras = activity.getIntent().getExtras();
if (extras != null) {
fromDetailIntent = extras.getBoolean("detail");
- searchIdIntent = extras.getLong("searchid");
+ searchIdIntent = extras.getString("searchid");
geocodeIntent = extras.getString("geocode");
latitudeIntent = extras.getDouble("latitude");
longitudeIntent = extras.getDouble("longitude");
waypointTypeIntent = extras.getString("wpttype");
mapStateIntent = extras.getIntArray("mapstate");
- if (searchIdIntent == 0L) {
+ if ("".equals(searchIdIntent)) {
searchIdIntent = null;
}
if (latitudeIntent == 0.0) {
@@ -558,9 +563,9 @@ public class cgeomap extends MapBase {
searchIdIntent = null;
} else if (id == MENU_STORE_CACHES) {
if (live && !isLoading() && caches != null && !caches.isEmpty()) {
- final ArrayList<String> geocodes = new ArrayList<String>();
+ final List<String> geocodes = new ArrayList<String>();
- ArrayList<cgCache> cachesProtected = new ArrayList<cgCache>(caches);
+ List<cgCache> cachesProtected = new ArrayList<cgCache>(caches);
try {
if (cachesProtected.size() > 0) {
final GeoPointImpl mapCenter = mapView.getMapViewCenter();
@@ -1060,7 +1065,7 @@ public class cgeomap extends MapBase {
// stage 1 - pull and render from the DB only
if (fromDetailIntent) {
- searchId = searchIdIntent;
+ searchId = UUID.fromString(searchIdIntent);
} else {
if (!live || settings.maplive == 0) {
searchId = app.getStoredInViewport(centerLat, centerLon, spanLat, spanLon, settings.cacheType);
@@ -1188,7 +1193,7 @@ public class cgeomap extends MapBase {
return;
}
- HashMap<String, String> params = new HashMap<String, String>();
+ Map<String, String> params = new HashMap<String, String>();
params.put("usertoken", token);
params.put("latitude-min", String.format((Locale) null, "%.6f", latMin));
params.put("latitude-max", String.format((Locale) null, "%.6f", latMax));
@@ -1250,8 +1255,8 @@ public class cgeomap extends MapBase {
}
// display caches
- final ArrayList<cgCache> cachesProtected = new ArrayList<cgCache>(caches);
- final ArrayList<CacheOverlayItemImpl> items = new ArrayList<CacheOverlayItemImpl>();
+ final List<cgCache> cachesProtected = new ArrayList<cgCache>(caches);
+ final List<CacheOverlayItemImpl> items = new ArrayList<CacheOverlayItemImpl>();
if (cachesProtected != null && !cachesProtected.isEmpty()) {
int icon = 0;
@@ -1405,9 +1410,9 @@ public class cgeomap extends MapBase {
// display users of Go 4 Cache
private class DisplayUsersThread extends DoThread {
- private ArrayList<cgUser> users = null;
+ private List<cgUser> users = null;
- public DisplayUsersThread(ArrayList<cgUser> usersIn, long centerLatIn, long centerLonIn, long spanLatIn, long spanLonIn) {
+ public DisplayUsersThread(List<cgUser> usersIn, long centerLatIn, long centerLonIn, long spanLatIn, long spanLonIn) {
super(centerLatIn, centerLonIn, spanLatIn, spanLonIn);
users = usersIn;
@@ -1424,7 +1429,7 @@ public class cgeomap extends MapBase {
}
// display users
- ArrayList<UserOverlayItemImpl> items = new ArrayList<UserOverlayItemImpl>();
+ List<UserOverlayItemImpl> items = new ArrayList<UserOverlayItemImpl>();
int counter = 0;
UserOverlayItemImpl item = null;
@@ -1542,11 +1547,11 @@ public class cgeomap extends MapBase {
private class LoadDetails extends Thread {
private Handler handler = null;
- private ArrayList<String> geocodes = null;
+ private List<String> geocodes = null;
private volatile boolean stop = false;
private long last = 0L;
- public LoadDetails(Handler handlerIn, ArrayList<String> geocodesIn) {
+ public LoadDetails(Handler handlerIn, List<String> geocodesIn) {
handler = handlerIn;
geocodes = geocodesIn;
}
@@ -1633,7 +1638,7 @@ public class cgeomap extends MapBase {
}
// move map to view results of searchIdIntent
- private void centerMap(String geocodeCenter, Long searchIdCenter, Double latitudeCenter, Double longitudeCenter, int[] mapState) {
+ private void centerMap(String geocodeCenter, String searchIdCenter, Double latitudeCenter, Double longitudeCenter, int[] mapState) {
if (!centered && mapState != null) {
try {
@@ -1647,7 +1652,7 @@ public class cgeomap extends MapBase {
alreadyCentered = true;
} else if (!centered && (geocodeCenter != null || searchIdIntent != null)) {
try {
- ArrayList<Object> viewport = null;
+ List<Object> viewport = null;
if (geocodeCenter != null) {
viewport = app.getBounds(geocodeCenter);
@@ -1762,6 +1767,14 @@ public class cgeomap extends MapBase {
}
}
+ @Override
+ public void onDrag() {
+ if (followMyLocation) {
+ followMyLocation = false;
+ myLocSwitch.setImageResource(R.drawable.actionbar_mylocation_off);
+ }
+ }
+
// make geopoint
private GeoPointImpl makeGeoPoint(Double latitude, Double longitude) {
return settings.getMapFactory().getGeoPointBase((int) (latitude * 1e6), (int) (longitude * 1e6));
diff --git a/src/cgeo/geocaching/mapinterfaces/MapViewImpl.java b/src/cgeo/geocaching/mapinterfaces/MapViewImpl.java
index 8e99b3d..4c23f63 100644
--- a/src/cgeo/geocaching/mapinterfaces/MapViewImpl.java
+++ b/src/cgeo/geocaching/mapinterfaces/MapViewImpl.java
@@ -66,4 +66,5 @@ public interface MapViewImpl {
void repaintRequired(OverlayBase overlay);
+ void setOnDragListener(OnDragListener onDragListener);
}
diff --git a/src/cgeo/geocaching/mapinterfaces/OnDragListener.java b/src/cgeo/geocaching/mapinterfaces/OnDragListener.java
new file mode 100644
index 0000000..ebeb13f
--- /dev/null
+++ b/src/cgeo/geocaching/mapinterfaces/OnDragListener.java
@@ -0,0 +1,12 @@
+package cgeo.geocaching.mapinterfaces;
+
+/**
+ * Notifies the parent class when a MapView has been dragged
+ * @author cachapa
+ *
+ */
+public interface OnDragListener {
+
+ public void onDrag();
+
+}
diff --git a/src/cgeo/geocaching/mapsforge/mfMapView.java b/src/cgeo/geocaching/mapsforge/mfMapView.java
index 1e83f33..19e3b8d 100644
--- a/src/cgeo/geocaching/mapsforge/mfMapView.java
+++ b/src/cgeo/geocaching/mapsforge/mfMapView.java
@@ -13,6 +13,9 @@ import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
+import android.view.GestureDetector;
+import android.view.MotionEvent;
+import android.view.GestureDetector.SimpleOnGestureListener;
import cgeo.geocaching.cgSettings;
import cgeo.geocaching.mapcommon.cgMapMyOverlay;
import cgeo.geocaching.mapcommon.cgMapOverlay;
@@ -22,14 +25,18 @@ import cgeo.geocaching.mapinterfaces.GeoPointImpl;
import cgeo.geocaching.mapinterfaces.MapControllerImpl;
import cgeo.geocaching.mapinterfaces.MapProjectionImpl;
import cgeo.geocaching.mapinterfaces.MapViewImpl;
+import cgeo.geocaching.mapinterfaces.OnDragListener;
import cgeo.geocaching.mapinterfaces.OverlayBase;
import cgeo.geocaching.mapinterfaces.OverlayImpl;
import cgeo.geocaching.mapinterfaces.OverlayImpl.overlayType;
public class mfMapView extends MapView implements MapViewImpl {
+ private GestureDetector gestureDetector;
+ private OnDragListener onDragListener;
public mfMapView(Context context, AttributeSet attrs) {
super(context, attrs);
+ gestureDetector = new GestureDetector(context, new GestureListener());
}
@Override
@@ -205,4 +212,33 @@ public class mfMapView extends MapView implements MapViewImpl {
}
}
+ @Override
+ public void setOnDragListener(OnDragListener onDragListener) {
+ this.onDragListener = onDragListener;
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent ev) {
+ gestureDetector.onTouchEvent(ev);
+ return super.onTouchEvent(ev);
+ }
+
+ private class GestureListener extends SimpleOnGestureListener {
+ @Override
+ public boolean onDoubleTap(MotionEvent e) {
+ if (onDragListener != null) {
+ onDragListener.onDrag();
+ }
+ return true;
+ }
+
+ @Override
+ public boolean onScroll(MotionEvent e1, MotionEvent e2,
+ float distanceX, float distanceY) {
+ if (onDragListener != null) {
+ onDragListener.onDrag();
+ }
+ return super.onScroll(e1, e2, distanceX, distanceY);
+ }
+ }
}
diff --git a/src/cgeo/geocaching/sorting/GeocodeComparator.java b/src/cgeo/geocaching/sorting/GeocodeComparator.java
index dd16f08..957545b 100644
--- a/src/cgeo/geocaching/sorting/GeocodeComparator.java
+++ b/src/cgeo/geocaching/sorting/GeocodeComparator.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.sorting;
+import org.apache.commons.lang3.StringUtils;
+
import cgeo.geocaching.cgCache;
/**
@@ -10,8 +12,8 @@ public class GeocodeComparator extends AbstractCacheComparator {
@Override
protected boolean canCompare(cgCache cache1, cgCache cache2) {
- return cache1.geocode != null && cache1.geocode.length() > 0
- && cache2.geocode != null && cache2.geocode.length() > 0;
+ return StringUtils.isNotBlank(cache1.geocode)
+ && StringUtils.isNotBlank(cache2.geocode);
}
@Override
diff --git a/src/cgeo/geocaching/sorting/NameComparator.java b/src/cgeo/geocaching/sorting/NameComparator.java
index f1c5ae3..9f72258 100644
--- a/src/cgeo/geocaching/sorting/NameComparator.java
+++ b/src/cgeo/geocaching/sorting/NameComparator.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.sorting;
+import org.apache.commons.lang3.StringUtils;
+
import cgeo.geocaching.cgCache;
/**
@@ -10,7 +12,7 @@ public class NameComparator extends AbstractCacheComparator {
@Override
protected boolean canCompare(cgCache cache1, cgCache cache2) {
- return cache1.name != null && cache2.name != null;
+ return StringUtils.isNotBlank(cache1.name) && StringUtils.isNotBlank(cache2.name);
}
@Override
diff --git a/src/cgeo/geocaching/sorting/SizeComparator.java b/src/cgeo/geocaching/sorting/SizeComparator.java
index dd9d448..cff5c49 100644
--- a/src/cgeo/geocaching/sorting/SizeComparator.java
+++ b/src/cgeo/geocaching/sorting/SizeComparator.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.sorting;
+import org.apache.commons.lang3.StringUtils;
+
import cgeo.geocaching.cgCache;
/**
@@ -10,7 +12,7 @@ public class SizeComparator extends AbstractCacheComparator {
@Override
protected boolean canCompare(cgCache cache1, cgCache cache2) {
- return cache1.size != null && cache1.size.length() > 0 && cache2.size != null && cache2.size.length() > 0;
+ return StringUtils.isNotBlank(cache1.size) && StringUtils.isNotBlank(cache2.size);
}
@Override
diff --git a/src/cgeo/geocaching/utils/CollectionUtils.java b/src/cgeo/geocaching/utils/CollectionUtils.java
new file mode 100644
index 0000000..89b4b51
--- /dev/null
+++ b/src/cgeo/geocaching/utils/CollectionUtils.java
@@ -0,0 +1,25 @@
+package cgeo.geocaching.utils;
+
+import java.util.List;
+import java.util.Map;
+
+public class CollectionUtils {
+
+ public static <T> boolean isEmpty(List<T> list) {
+ return (list != null && list.size() == 0);
+ }
+ public static <T,T2> boolean isEmpty(Map<T,T2> map) {
+ return (map != null && map.size() == 0);
+ }
+
+
+ public static <T> boolean isNotEmpty(List<T> list) {
+ return (list != null && list.size() != 0);
+ }
+
+ public static <T,T2> boolean isNotEmpty(Map<T,T2> map) {
+ return (map != null && map.size() != 0);
+ }
+
+
+}