aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo/geocaching
diff options
context:
space:
mode:
authorGerald Barker <geraldbarker@gmail.com>2011-09-03 15:02:21 +0100
committerGerald Barker <geraldbarker@gmail.com>2011-09-03 15:02:21 +0100
commit4785a805cc419376e4e1adb732f728f7548cdc5c (patch)
treebac56c4ae7ec07a189f98c6ca4156b1d87c85903 /src/cgeo/geocaching
parent95391b46e46ca939bb153458f46f662664ce26c0 (diff)
downloadcgeo-4785a805cc419376e4e1adb732f728f7548cdc5c.zip
cgeo-4785a805cc419376e4e1adb732f728f7548cdc5c.tar.gz
cgeo-4785a805cc419376e4e1adb732f728f7548cdc5c.tar.bz2
more refctoring missed in first pass
Diffstat (limited to 'src/cgeo/geocaching')
-rw-r--r--src/cgeo/geocaching/cgBase.java52
-rw-r--r--src/cgeo/geocaching/cgCache.java5
-rw-r--r--src/cgeo/geocaching/cgCacheListAdapter.java2
-rw-r--r--src/cgeo/geocaching/cgDirectionImg.java2
-rw-r--r--src/cgeo/geocaching/cgWaypoint.java6
-rw-r--r--src/cgeo/geocaching/cgeocaches.java4
-rw-r--r--src/cgeo/geocaching/cgeoimages.java4
-rw-r--r--src/cgeo/geocaching/cgeopopup.java2
-rw-r--r--src/cgeo/geocaching/cgeotouch.java4
-rw-r--r--src/cgeo/geocaching/files/GPXParser.java2
-rw-r--r--src/cgeo/geocaching/mapcommon/cgMapOverlay.java6
11 files changed, 35 insertions, 54 deletions
diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java
index 0e0df78..f2eeae8 100644
--- a/src/cgeo/geocaching/cgBase.java
+++ b/src/cgeo/geocaching/cgBase.java
@@ -657,7 +657,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) {
@@ -671,7 +671,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();
}
@@ -809,7 +809,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()) {
@@ -920,7 +920,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) {
@@ -1012,7 +1012,7 @@ 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;
}
@@ -1506,7 +1506,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()) {
@@ -2406,28 +2406,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;
@@ -2912,7 +2890,7 @@ 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 && StringUtils.isNotBlank(caches.url)) {
@@ -3822,7 +3800,7 @@ 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;
}
@@ -4207,7 +4185,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;
@@ -4555,7 +4533,7 @@ public class cgBase {
Log.e(cgSettings.tag, "cgeoBase.requestJSON: " + e.toString());
}
- if (buffer != null && buffer.length() > 0) {
+ if (StringUtils.isNotBlank(buffer)) {
break;
}
@@ -4674,7 +4652,7 @@ 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) {
+ if (cache.reason > 0 || StringUtils.isBlank(cache.description)) {
final HashMap<String, String> params = new HashMap<String, String>();
params.put("geocode", cache.geocode);
final Long searchId = searchByGeocode(params, listId, false);
@@ -4703,7 +4681,7 @@ public class cgBase {
}
// store spoilers
- if (cache.spoilers != null && cache.spoilers.isEmpty() == false) {
+ if (CollectionUtils.isNotEmpty(cache.spoilers)) {
for (cgImage oneSpoiler : cache.spoilers) {
imgGetter.getDrawable(oneSpoiler.url);
}
@@ -4712,7 +4690,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);
}
@@ -4943,7 +4921,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) {
@@ -4963,7 +4941,7 @@ public class cgBase {
icon = gcIcons.get("traditional");
}
} else {
- if (type != null && type.length() > 0) {
+ if (StringUtils.isNotBlank(type)) {
iconTxt = type;
} else {
iconTxt = "waypoint";
diff --git a/src/cgeo/geocaching/cgCache.java b/src/cgeo/geocaching/cgCache.java
index 336b3a3..bf3a0c2 100644
--- a/src/cgeo/geocaching/cgCache.java
+++ b/src/cgeo/geocaching/cgCache.java
@@ -303,9 +303,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);
diff --git a/src/cgeo/geocaching/cgCacheListAdapter.java b/src/cgeo/geocaching/cgCacheListAdapter.java
index c8bc8e0..7070386 100644
--- a/src/cgeo/geocaching/cgCacheListAdapter.java
+++ b/src/cgeo/geocaching/cgCacheListAdapter.java
@@ -584,7 +584,7 @@ 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 (StringUtils.isNotBlank(cache.size)) {
diff --git a/src/cgeo/geocaching/cgDirectionImg.java b/src/cgeo/geocaching/cgDirectionImg.java
index 33f186a..1f513d3 100644
--- a/src/cgeo/geocaching/cgDirectionImg.java
+++ b/src/cgeo/geocaching/cgDirectionImg.java
@@ -21,7 +21,7 @@ public class cgDirectionImg {
String dirName;
String fileName;
- if (StringUtils.isBlank(geocode) || code == null || code.length() == 0) {
+ if (StringUtils.isBlank(geocode) || StringUtils.isBlank(code)) {
return;
}
diff --git a/src/cgeo/geocaching/cgWaypoint.java b/src/cgeo/geocaching/cgWaypoint.java
index c41b97a..6b437f6 100644
--- a/src/cgeo/geocaching/cgWaypoint.java
+++ b/src/cgeo/geocaching/cgWaypoint.java
@@ -34,10 +34,10 @@ 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 (StringUtils.isBlank(name)) {
@@ -58,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) {
diff --git a/src/cgeo/geocaching/cgeocaches.java b/src/cgeo/geocaching/cgeocaches.java
index a6d7300..b2b1870 100644
--- a/src/cgeo/geocaching/cgeocaches.java
+++ b/src/cgeo/geocaching/cgeocaches.java
@@ -228,7 +228,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();
@@ -305,7 +305,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());
diff --git a/src/cgeo/geocaching/cgeoimages.java b/src/cgeo/geocaching/cgeoimages.java
index c5975d0..b933c46 100644
--- a/src/cgeo/geocaching/cgeoimages.java
+++ b/src/cgeo/geocaching/cgeoimages.java
@@ -4,6 +4,8 @@ import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
+import org.apache.commons.lang3.StringUtils;
+
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap.CompressFormat;
@@ -92,7 +94,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/cgeopopup.java b/src/cgeo/geocaching/cgeopopup.java
index c2f4f76..9b1d816 100644
--- a/src/cgeo/geocaching/cgeopopup.java
+++ b/src/cgeo/geocaching/cgeopopup.java
@@ -214,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());
diff --git a/src/cgeo/geocaching/cgeotouch.java b/src/cgeo/geocaching/cgeotouch.java
index fed64ae..f75ced7 100644
--- a/src/cgeo/geocaching/cgeotouch.java
+++ b/src/cgeo/geocaching/cgeotouch.java
@@ -128,7 +128,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());
@@ -431,7 +431,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/files/GPXParser.java b/src/cgeo/geocaching/files/GPXParser.java
index ebeb38e..707bd1a 100644
--- a/src/cgeo/geocaching/files/GPXParser.java
+++ b/src/cgeo/geocaching/files/GPXParser.java
@@ -341,7 +341,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;
}
}
diff --git a/src/cgeo/geocaching/mapcommon/cgMapOverlay.java b/src/cgeo/geocaching/mapcommon/cgMapOverlay.java
index d3f7c00..2b8406e 100644
--- a/src/cgeo/geocaching/mapcommon/cgMapOverlay.java
+++ b/src/cgeo/geocaching/mapcommon/cgMapOverlay.java
@@ -2,6 +2,8 @@ package cgeo.geocaching.mapcommon;
import java.util.ArrayList;
+import org.apache.commons.lang3.StringUtils;
+
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
@@ -10,9 +12,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;
@@ -199,7 +201,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);