aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/connector/gc
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/connector/gc')
-rw-r--r--main/src/cgeo/geocaching/connector/gc/AbstractSearchThread.java2
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCConnector.java76
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCConstants.java12
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCMap.java27
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCParser.java159
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCSmiliesProvider.java2
-rw-r--r--main/src/cgeo/geocaching/connector/gc/IconDecoder.java609
-rw-r--r--main/src/cgeo/geocaching/connector/gc/Login.java7
-rw-r--r--main/src/cgeo/geocaching/connector/gc/Tile.java5
-rw-r--r--main/src/cgeo/geocaching/connector/gc/UTFGrid.java2
10 files changed, 716 insertions, 185 deletions
diff --git a/main/src/cgeo/geocaching/connector/gc/AbstractSearchThread.java b/main/src/cgeo/geocaching/connector/gc/AbstractSearchThread.java
index d0e45f6..f19064d 100644
--- a/main/src/cgeo/geocaching/connector/gc/AbstractSearchThread.java
+++ b/main/src/cgeo/geocaching/connector/gc/AbstractSearchThread.java
@@ -12,7 +12,7 @@ abstract public class AbstractSearchThread extends Thread {
private final Handler handler;
private static AbstractSearchThread currentInstance;
- public AbstractSearchThread(final Handler handler) {
+ protected AbstractSearchThread(final Handler handler) {
this.handler = handler;
}
diff --git a/main/src/cgeo/geocaching/connector/gc/GCConnector.java b/main/src/cgeo/geocaching/connector/gc/GCConnector.java
index 5607d97..b196504 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCConnector.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCConnector.java
@@ -3,7 +3,7 @@ package cgeo.geocaching.connector.gc;
import cgeo.geocaching.R;
import cgeo.geocaching.SearchResult;
import cgeo.geocaching.cgCache;
-import cgeo.geocaching.cgeoapplication;
+import cgeo.geocaching.cgData;
import cgeo.geocaching.connector.AbstractConnector;
import cgeo.geocaching.connector.capability.ISearchByCenter;
import cgeo.geocaching.connector.capability.ISearchByGeocode;
@@ -20,18 +20,22 @@ import java.util.regex.Pattern;
public class GCConnector extends AbstractConnector implements ISearchByGeocode, ISearchByCenter {
- private static GCConnector instance;
+ private static final String HTTP_COORD_INFO = "http://coord.info/";
private static final Pattern gpxZipFilePattern = Pattern.compile("\\d{7,}(_.+)?\\.zip", Pattern.CASE_INSENSITIVE);
private GCConnector() {
// singleton
}
+ /**
+ * initialization on demand holder pattern
+ */
+ private static class Holder {
+ private static final GCConnector INSTANCE = new GCConnector();
+ }
+
public static GCConnector getInstance() {
- if (instance == null) {
- instance = new GCConnector();
- }
- return instance;
+ return Holder.INSTANCE;
}
@Override
@@ -49,6 +53,11 @@ public class GCConnector extends AbstractConnector implements ISearchByGeocode,
}
@Override
+ public boolean supportsOwnCoordinates() {
+ return true;
+ }
+
+ @Override
public boolean supportsWatchList() {
return true;
}
@@ -82,11 +91,10 @@ public class GCConnector extends AbstractConnector implements ISearchByGeocode,
if (StringUtils.isEmpty(page)) {
final SearchResult search = new SearchResult();
- if (cgeoapplication.getInstance().isThere(geocode, guid, true, false)) {
+ if (cgData.isThere(geocode, guid, true, false)) {
if (StringUtils.isBlank(geocode) && StringUtils.isNotBlank(guid)) {
Log.i("Loading old cache from cache.");
-
- search.addGeocode(cgeoapplication.getInstance().getGeocode(guid));
+ search.addGeocode(cgData.getGeocodeForGuid(guid));
} else {
search.addGeocode(geocode);
}
@@ -102,7 +110,7 @@ public class GCConnector extends AbstractConnector implements ISearchByGeocode,
final SearchResult searchResult = GCParser.parseCache(page, handler);
if (searchResult == null || CollectionUtils.isEmpty(searchResult.getGeocodes())) {
- Log.e("GCConnector.searchByGeocode: No cache parsed");
+ Log.w("GCConnector.searchByGeocode: No cache parsed");
return searchResult;
}
@@ -128,7 +136,7 @@ public class GCConnector extends AbstractConnector implements ISearchByGeocode,
public static boolean addToWatchlist(cgCache cache) {
final boolean added = GCParser.addToWatchlist(cache);
if (added) {
- cgeoapplication.getInstance().updateCache(cache);
+ cgData.saveChangedCache(cache);
}
return added;
}
@@ -136,28 +144,64 @@ public class GCConnector extends AbstractConnector implements ISearchByGeocode,
public static boolean removeFromWatchlist(cgCache cache) {
final boolean removed = GCParser.removeFromWatchlist(cache);
if (removed) {
- cgeoapplication.getInstance().updateCache(cache);
+ cgData.saveChangedCache(cache);
}
return removed;
}
+ /**
+ * Add a cache to the favorites list.
+ *
+ * This must not be called from the UI thread.
+ *
+ * @param cache the cache to add
+ * @return <code>true</code> if the cache was sucessfully added, <code>false</code> otherwise
+ */
+
public static boolean addToFavorites(cgCache cache) {
final boolean added = GCParser.addToFavorites(cache);
if (added) {
- cgeoapplication.getInstance().updateCache(cache);
+ cgData.saveChangedCache(cache);
}
return added;
}
+ /**
+ * Remove a cache from the favorites list.
+ *
+ * This must not be called from the UI thread.
+ *
+ * @param cache the cache to add
+ * @return <code>true</code> if the cache was sucessfully added, <code>false</code> otherwise
+ */
+
public static boolean removeFromFavorites(cgCache cache) {
final boolean removed = GCParser.removeFromFavorites(cache);
if (removed) {
- cgeoapplication.getInstance().updateCache(cache);
+ cgData.saveChangedCache(cache);
}
return removed;
}
@Override
+ public boolean uploadModifiedCoordinates(cgCache cache, Geopoint wpt) {
+ final boolean uploaded = GCParser.uploadModifiedCoordinates(cache, wpt);
+ if (uploaded) {
+ cgData.saveChangedCache(cache);
+ }
+ return uploaded;
+ }
+
+ @Override
+ public boolean deleteModifiedCoordinates(cgCache cache) {
+ final boolean deleted = GCParser.deleteModifiedCoordinates(cache);
+ if (deleted) {
+ cgData.saveChangedCache(cache);
+ }
+ return deleted;
+ }
+
+ @Override
public SearchResult searchByCenter(Geopoint center) {
// TODO make search by coordinate use this method. currently it is just a marker that this connector supports search by center
return null;
@@ -168,4 +212,8 @@ public class GCConnector extends AbstractConnector implements ISearchByGeocode,
return true;
}
+ @Override
+ protected String getCacheUrlPrefix() {
+ return HTTP_COORD_INFO;
+ }
}
diff --git a/main/src/cgeo/geocaching/connector/gc/GCConstants.java b/main/src/cgeo/geocaching/connector/gc/GCConstants.java
index 2b4ca46..282c88c 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCConstants.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCConstants.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.connector.gc;
+import java.util.Locale;
import java.util.regex.Pattern;
/**
@@ -49,7 +50,7 @@ public final class GCConstants {
public final static Pattern PATTERN_FAVORITE = Pattern.compile("<div id=\"pnlFavoriteCache\">"); // without 'class="hideMe"' inside the tag !
public final static Pattern PATTERN_FAVORITECOUNT = Pattern.compile("<a id=\"uxFavContainerLink\"[^>]+>[^<]*<div[^<]*<span class=\"favorite-value\">\\D*([0-9]+?)</span>");
public final static Pattern PATTERN_COUNTLOGS = Pattern.compile("<span id=\"ctl00_ContentBody_lblFindCounts\"><p(.+?)</p></span>");
- public final static Pattern PATTERN_LOGBOOK = Pattern.compile("initalLogs = (\\{.+\\});");
+ public final static Pattern PATTERN_LOGBOOK = Pattern.compile("initalLogs = (\\{.+\\});"); // The "inital" typo really comes from gc.com site
/** Two groups ! */
public final static Pattern PATTERN_COUNTLOG = Pattern.compile("<img src=\"/images/logtypes/([0-9]+)\\.png\"[^>]+> (\\d*[,.]?\\d+)");
public static final Pattern PATTERN_PREMIUMMEMBERS = Pattern.compile("<p class=\"Warning NoBottomSpacing\">This is a Premium Member Only cache.</p>");
@@ -103,7 +104,7 @@ public final class GCConstants {
public final static Pattern PATTERN_TRACKABLE_ICON = Pattern.compile("<img id=\"ctl00_ContentBody_BugTypeImage\" class=\"TravelBugHeaderIcon\" src=\"([^\"]+)\"[^>]*>");
public final static Pattern PATTERN_TRACKABLE_TYPE = Pattern.compile("<img id=\"ctl00_ContentBody_BugTypeImage\" class=\"TravelBugHeaderIcon\" src=\"[^\"]+\" alt=\"([^\"]+)\"[^>]*>");
public final static Pattern PATTERN_TRACKABLE_DISTANCE = Pattern.compile("<h4[^>]*\\W*Tracking History \\(([0-9.,]+(km|mi))[^\\)]*\\)");
- public final static Pattern PATTERN_TRACKABLE_LOG = Pattern.compile("<tr class=\"Data BorderTop .+?src=\"/images/logtypes/([^.]+)\\.png[^>]+>&nbsp;([^<]+)</td>.+?guid.+?>([^<]+)</a>.+?(?:guid=([^\"]+)\">(<span[^>]+>)?([^<]+)</.+?)?<td colspan=\"4\">(.+?)(?:<ul.+?ul>)?\\s*</td>\\s*</tr>");
+ public final static Pattern PATTERN_TRACKABLE_LOG = Pattern.compile("<tr class=\"Data BorderTop .+?src=\"/images/logtypes/([^.]+)\\.png[^>]+>&nbsp;([^<]+)</td>.+?guid.+?>([^<]+)</a>.+?(?:guid=([^\"]+)\">(<span[^>]+>)?([^<]+)</.+?)?<td colspan=\"4\">\\s*<div>(.*?)</div>\\s*(?:<ul.+?ul>)?\\s*</td>\\s*</tr>");
public final static Pattern PATTERN_TRACKABLE_LOG_IMAGES = Pattern.compile("<li><a href=\"([^\"]+)\".+?LogImgTitle.+?>([^<]+)</");
/**
@@ -164,8 +165,9 @@ public final class GCConstants {
public final static String STRING_PREMIUMONLY_2 = "Sorry, the owner of this listing has made it viewable to Premium Members only.";
public final static String STRING_PREMIUMONLY_1 = "has chosen to make this cache listing visible to Premium Members only.";
- public final static String STRING_UNPUBLISHED_OWNER = "Cache is Unpublished";
+ public final static String STRING_UNPUBLISHED_OWNER = "cache has not been published yet";
public final static String STRING_UNPUBLISHED_OTHER = "you cannot view this cache listing until it has been published";
+ public final static String STRING_UNPUBLISHED_FROM_SEARCH = "UnpublishedCacheSearchWidget";
public final static String STRING_UNKNOWN_ERROR = "An Error Has Occurred";
public final static String STRING_DISABLED = "<li>This cache is temporarily unavailable.";
public final static String STRING_ARCHIVED = "<li>This cache has been archived,";
@@ -185,14 +187,14 @@ public final class GCConstants {
* see http://support.groundspeak.com/index.php?pg=kb.printer.friendly&id=1#p221
*/
public static long gccodeToGCId(final String gccode) {
- long gcid = 0;
long base = GC_BASE31;
- String geocodeWO = gccode.substring(2).toUpperCase();
+ String geocodeWO = gccode.substring(2).toUpperCase(Locale.US);
if ((geocodeWO.length() < 4) || (geocodeWO.length() == 4 && SEQUENCE_GCID.indexOf(geocodeWO.charAt(0)) < 16)) {
base = GC_BASE16;
}
+ long gcid = 0;
for (int p = 0; p < geocodeWO.length(); p++) {
gcid = base * gcid + SEQUENCE_GCID.indexOf(geocodeWO.charAt(p));
}
diff --git a/main/src/cgeo/geocaching/connector/gc/GCMap.java b/main/src/cgeo/geocaching/connector/gc/GCMap.java
index 681a1d7..9a8123d 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCMap.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCMap.java
@@ -3,6 +3,7 @@ package cgeo.geocaching.connector.gc;
import cgeo.geocaching.SearchResult;
import cgeo.geocaching.Settings;
import cgeo.geocaching.cgCache;
+import cgeo.geocaching.cgData;
import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
@@ -40,10 +41,10 @@ public class GCMap {
final SearchResult result = new SearchResult();
final String geocodeList = StringUtils.join(geocodes.toArray(), "|");
- final String referer = GCConstants.URL_LIVE_MAP_DETAILS;
try {
final Parameters params = new Parameters("i", geocodeList, "_", String.valueOf(System.currentTimeMillis()));
+ final String referer = GCConstants.URL_LIVE_MAP_DETAILS;
final String data = StringUtils.defaultString(Tile.requestMapInfo(referer, params, referer));
// Example JSON information
@@ -166,6 +167,8 @@ public class GCMap {
// iterate over the data and construct all caches in this tile
Map<String, List<UTFGridPosition>> positions = new HashMap<String, List<UTFGridPosition>>(); // JSON id as key
+ Map<String, List<UTFGridPosition>> singlePositions = new HashMap<String, List<UTFGridPosition>>(); // JSON id as key
+
for (int i = 1; i < keys.length(); i++) { // index 0 is empty
String key = keys.getString(i);
if (StringUtils.isNotBlank(key)) {
@@ -177,12 +180,20 @@ public class GCMap {
nameCache.put(id, cacheInfo.getString("n"));
List<UTFGridPosition> listOfPositions = positions.get(id);
+ List<UTFGridPosition> singleListOfPositions = singlePositions.get(id);
+
if (listOfPositions == null) {
listOfPositions = new ArrayList<UTFGridPosition>();
positions.put(id, listOfPositions);
+ singleListOfPositions = new ArrayList<UTFGridPosition>();
+ singlePositions.put(id, singleListOfPositions);
}
listOfPositions.add(pos);
+ if (dataForKey.length() == 1) {
+ singleListOfPositions.add(pos);
+ }
+
}
}
}
@@ -198,12 +209,16 @@ public class GCMap {
cache.setName(nameCache.get(id));
cache.setZoomlevel(tile.getZoomlevel());
cache.setCoords(tile.getCoord(xy));
- if (strategy.flags.contains(StrategyFlag.PARSE_TILES) && positions.size() < 64 && bitmap != null) {
- // don't parse if there are too many caches. The decoding would return too much wrong results
- IconDecoder.parseMapPNG(cache, bitmap, xy, tile.getZoomlevel());
+ if (strategy.flags.contains(StrategyFlag.PARSE_TILES) && bitmap != null) {
+ for (UTFGridPosition singlePos : singlePositions.get(id)) {
+ if (IconDecoder.parseMapPNG(cache, bitmap, singlePos, tile.getZoomlevel())) {
+ break; // cache parsed
+ }
+ }
} else {
cache.setType(CacheType.UNKNOWN);
}
+
boolean exclude = false;
if (Settings.isExcludeMyCaches() && (cache.isFound() || cache.isOwn())) { // workaround for BM
exclude = true;
@@ -313,7 +328,7 @@ public class GCMap {
String data = Tile.requestMapInfo(GCConstants.URL_MAP_INFO, params, GCConstants.URL_LIVE_MAP);
if (StringUtils.isEmpty(data)) {
- Log.e("GCBase.searchByViewport: No data from server for tile (" + tile.getX() + "/" + tile.getY() + ")");
+ Log.w("GCBase.searchByViewport: No data from server for tile (" + tile.getX() + "/" + tile.getY() + ")");
} else {
final SearchResult search = GCMap.parseMapJSON(data, tile, bitmap, strategy);
if (search == null || CollectionUtils.isEmpty(search.getGeocodes())) {
@@ -341,7 +356,7 @@ public class GCMap {
if (search != null && !search.isEmpty()) {
final Set<String> geocodes = search.getGeocodes();
if (Settings.isPremiumMember()) {
- lastSearchViewport = cgeoapplication.getInstance().getBounds(geocodes);
+ lastSearchViewport = cgData.getBounds(geocodes);
} else {
lastSearchViewport = new Viewport(center, center);
}
diff --git a/main/src/cgeo/geocaching/connector/gc/GCParser.java b/main/src/cgeo/geocaching/connector/gc/GCParser.java
index 7fc06c1..44d634c 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCParser.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCParser.java
@@ -6,6 +6,7 @@ import cgeo.geocaching.SearchResult;
import cgeo.geocaching.Settings;
import cgeo.geocaching.TrackableLog;
import cgeo.geocaching.cgCache;
+import cgeo.geocaching.cgData;
import cgeo.geocaching.cgImage;
import cgeo.geocaching.cgTrackable;
import cgeo.geocaching.cgWaypoint;
@@ -43,12 +44,7 @@ import org.json.JSONObject;
import android.net.Uri;
import android.text.Html;
-import android.text.Spannable;
-import android.text.Spanned;
-import android.text.style.ForegroundColorSpan;
-import android.text.style.StrikethroughSpan;
-import java.net.URLDecoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -71,8 +67,6 @@ public abstract class GCParser {
}
final List<String> cids = new ArrayList<String>();
- String recaptchaChallenge = null;
- String recaptchaText = null;
String page = pageContent;
final SearchResult searchResult = new SearchResult();
@@ -81,6 +75,7 @@ public abstract class GCParser {
// recaptcha
AbstractSearchThread thread = AbstractSearchThread.getCurrentInstance();
+ String recaptchaChallenge = null;
if (showCaptcha) {
String recaptchaJsParam = BaseUtils.getMatch(page, GCConstants.PATTERN_SEARCH_RECAPTCHA, false, null);
@@ -163,23 +158,26 @@ public abstract class GCParser {
continue;
}
- String inventoryPre = null;
-
- cache.setGeocode(BaseUtils.getMatch(row, GCConstants.PATTERN_SEARCH_GEOCODE, true, 1, cache.getGeocode(), true).toUpperCase());
+ cache.setGeocode(BaseUtils.getMatch(row, GCConstants.PATTERN_SEARCH_GEOCODE, true, 1, cache.getGeocode(), true));
// cache type
cache.setType(CacheType.getByPattern(BaseUtils.getMatch(row, GCConstants.PATTERN_SEARCH_TYPE, true, 1, null, true)));
// cache direction - image
if (Settings.getLoadDirImg()) {
- cache.setDirectionImg(URLDecoder.decode(BaseUtils.getMatch(row, GCConstants.PATTERN_SEARCH_DIRECTION, true, 1, cache.getDirectionImg(), true)));
+ cache.setDirectionImg(Network.decode(BaseUtils.getMatch(row, GCConstants.PATTERN_SEARCH_DIRECTION, true, 1, cache.getDirectionImg(), true)));
}
// cache inventory
final Matcher matcherTbs = GCConstants.PATTERN_SEARCH_TRACKABLES.matcher(row);
+ String inventoryPre = null;
while (matcherTbs.find()) {
if (matcherTbs.groupCount() > 0) {
- cache.setInventoryItems(Integer.parseInt(matcherTbs.group(1)));
+ try {
+ cache.setInventoryItems(Integer.parseInt(matcherTbs.group(1)));
+ } catch (NumberFormatException e) {
+ Log.e("Error parsing trackables count", e);
+ }
inventoryPre = matcherTbs.group(2);
}
}
@@ -222,16 +220,6 @@ public abstract class GCParser {
Log.w("GCParser.parseSearch: Failed to parse favourite count");
}
- if (cache.getNameSp() == null) {
- cache.setNameSp((new Spannable.Factory()).newSpannable(cache.getName()));
- if (cache.isDisabled() || cache.isArchived()) { // strike
- cache.getNameSp().setSpan(new StrikethroughSpan(), 0, cache.getNameSp().toString().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- }
- if (cache.isArchived()) {
- cache.getNameSp().setSpan(new ForegroundColorSpan(cgeoapplication.getInstance().getResources().getColor(R.color.archived_cache_color)), 0, cache.getNameSp().toString().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- }
- }
-
searchResult.addCache(cache);
}
@@ -245,6 +233,7 @@ public abstract class GCParser {
Log.w("GCParser.parseSearch: Failed to parse cache count");
}
+ String recaptchaText = null;
if (thread != null && recaptchaChallenge != null) {
if (thread.getText() == null) {
thread.waitForUser();
@@ -253,7 +242,7 @@ public abstract class GCParser {
recaptchaText = thread.getText();
}
- if (cids.size() > 0 && (Settings.isPremiumMember() || showCaptcha) && (recaptchaChallenge == null || StringUtils.isNotBlank(recaptchaText))) {
+ if (!cids.isEmpty() && (Settings.isPremiumMember() || showCaptcha) && (recaptchaChallenge == null || StringUtils.isNotBlank(recaptchaText))) {
Log.i("Trying to get .loc for " + cids.size() + " caches");
try {
@@ -326,7 +315,7 @@ public abstract class GCParser {
// save full detailed caches
CancellableHandler.sendLoadProgressDetail(handler, R.string.cache_dialog_loading_details_status_cache);
- cgeoapplication.getInstance().saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB));
+ cgData.saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB));
// update progress message so user knows we're still working. This is more of a place holder than
// actual indication of what the program is doing
@@ -345,7 +334,7 @@ public abstract class GCParser {
final SearchResult searchResult = new SearchResult();
- if (page.contains(GCConstants.STRING_UNPUBLISHED_OTHER) || page.contains(GCConstants.STRING_UNPUBLISHED_OWNER)) {
+ if (page.contains(GCConstants.STRING_UNPUBLISHED_OTHER) || page.contains(GCConstants.STRING_UNPUBLISHED_OWNER) || page.contains(GCConstants.STRING_UNPUBLISHED_FROM_SEARCH)) {
searchResult.setError(StatusCode.UNPUBLISHED_CACHE);
return searchResult;
}
@@ -383,10 +372,12 @@ public abstract class GCParser {
cache.setName(cacheName);
// owner real name
- cache.setOwnerUserId(URLDecoder.decode(BaseUtils.getMatch(page, GCConstants.PATTERN_OWNER_USERID, true, cache.getOwnerUserId())));
+ cache.setOwnerUserId(Network.decode(BaseUtils.getMatch(page, GCConstants.PATTERN_OWNER_USERID, true, cache.getOwnerUserId())));
cache.setOwn(StringUtils.equalsIgnoreCase(cache.getOwnerUserId(), Settings.getUsername()));
+ cache.setUserModifiedCoords(false);
+
String tableInside = page;
int pos = tableInside.indexOf(GCConstants.STRING_CACHEDETAILS);
@@ -401,13 +392,21 @@ public abstract class GCParser {
// cache terrain
String result = BaseUtils.getMatch(tableInside, GCConstants.PATTERN_TERRAIN, true, null);
if (result != null) {
- cache.setTerrain(Float.parseFloat(StringUtils.replaceChars(result, '_', '.')));
+ try {
+ cache.setTerrain(Float.parseFloat(StringUtils.replaceChars(result, '_', '.')));
+ } catch (NumberFormatException e) {
+ Log.e("Error parsing terrain value", e);
+ }
}
// cache difficulty
result = BaseUtils.getMatch(tableInside, GCConstants.PATTERN_DIFFICULTY, true, null);
if (result != null) {
- cache.setDifficulty(Float.parseFloat(StringUtils.replaceChars(result, '_', '.')));
+ try {
+ cache.setDifficulty(Float.parseFloat(StringUtils.replaceChars(result, '_', '.')));
+ } catch (NumberFormatException e) {
+ Log.e("Error parsing difficulty value", e);
+ }
}
// owner
@@ -432,10 +431,14 @@ public abstract class GCParser {
}
// favourite
- cache.setFavoritePoints(Integer.parseInt(BaseUtils.getMatch(tableInside, GCConstants.PATTERN_FAVORITECOUNT, true, "0")));
+ try {
+ cache.setFavoritePoints(Integer.parseInt(BaseUtils.getMatch(tableInside, GCConstants.PATTERN_FAVORITECOUNT, true, "0")));
+ } catch (NumberFormatException e) {
+ Log.e("Error parsing favourite count", e);
+ }
// cache size
- cache.setSize(CacheSize.getById(BaseUtils.getMatch(tableInside, GCConstants.PATTERN_SIZE, true, CacheSize.NOT_CHOSEN.id).toLowerCase()));
+ cache.setSize(CacheSize.getById(BaseUtils.getMatch(tableInside, GCConstants.PATTERN_SIZE, true, CacheSize.NOT_CHOSEN.id)));
}
// cache found
@@ -503,15 +506,15 @@ public abstract class GCParser {
while (matcherAttributesInside.find()) {
if (matcherAttributesInside.groupCount() > 1 && !matcherAttributesInside.group(2).equalsIgnoreCase("blank")) {
// by default, use the tooltip of the attribute
- String attribute = matcherAttributesInside.group(2).toLowerCase();
+ String attribute = matcherAttributesInside.group(2).toLowerCase(Locale.US);
// if the image name can be recognized, use the image name as attribute
- String imageName = matcherAttributesInside.group(1).trim();
- if (imageName.length() > 0) {
+ final String imageName = matcherAttributesInside.group(1).trim();
+ if (StringUtils.isNotEmpty(imageName)) {
int start = imageName.lastIndexOf('/');
int end = imageName.lastIndexOf('.');
if (start >= 0 && end >= 0) {
- attribute = imageName.substring(start + 1, end).replace('-', '_').toLowerCase();
+ attribute = imageName.substring(start + 1, end).replace('-', '_').toLowerCase(Locale.US);
}
}
attributes.add(attribute);
@@ -620,7 +623,7 @@ public abstract class GCParser {
final String originalCoords = BaseUtils.getMatch(page, GCConstants.PATTERN_LATLON_ORIG, false, null);
if (null != originalCoords) {
- final cgWaypoint waypoint = new cgWaypoint(cgeoapplication.getInstance().getString(R.string.cache_coordinates_original), WaypointType.WAYPOINT, false);
+ final cgWaypoint waypoint = new cgWaypoint(cgeoapplication.getInstance().getString(R.string.cache_coordinates_original), WaypointType.ORIGINAL, false);
waypoint.setCoords(new Geopoint(originalCoords));
cache.addOrChangeWaypoint(waypoint, false);
cache.setUserModifiedCoords(true);
@@ -628,10 +631,7 @@ public abstract class GCParser {
} catch (Geopoint.GeopointException e) {
}
- int wpBegin;
- int wpEnd;
-
- wpBegin = page.indexOf("<table class=\"Table\" id=\"ctl00_ContentBody_Waypoints\">");
+ int wpBegin = page.indexOf("<table class=\"Table\" id=\"ctl00_ContentBody_Waypoints\">");
if (wpBegin != -1) { // parse waypoints
if (CancellableHandler.isCancelled(handler)) {
return null;
@@ -640,7 +640,7 @@ public abstract class GCParser {
String wpList = page.substring(wpBegin);
- wpEnd = wpList.indexOf("</p>");
+ int wpEnd = wpList.indexOf("</p>");
if (wpEnd > -1 && wpEnd <= wpList.length()) {
wpList = wpList.substring(0, wpEnd);
}
@@ -657,9 +657,8 @@ public abstract class GCParser {
final String[] wpItems = wpList.split("<tr");
- String[] wp;
for (int j = 1; j < wpItems.length; j++) {
- wp = wpItems[j].split("<td");
+ String[] wp = wpItems[j].split("<td");
// waypoint name
// res is null during the unit tests
@@ -750,7 +749,7 @@ public abstract class GCParser {
final SearchResult searchResult = parseSearch(url, page, showCaptcha);
if (searchResult == null || CollectionUtils.isEmpty(searchResult.getGeocodes())) {
- Log.e("GCParser.searchByNextPage: No cache parsed");
+ Log.w("GCParser.searchByNextPage: No cache parsed");
return search;
}
@@ -917,7 +916,7 @@ public abstract class GCParser {
trackable = parseTrackable(page, geocode);
if (trackable == null) {
- Log.e("GCParser.searchTrackable: No trackable parsed");
+ Log.w("GCParser.searchTrackable: No trackable parsed");
return null;
}
@@ -1052,7 +1051,7 @@ public abstract class GCParser {
Log.i("Log successfully posted to cache #" + cacheid);
if (geocode != null) {
- cgeoapplication.getInstance().saveVisitDate(geocode);
+ cgData.saveVisitDate(geocode);
}
Login.getLoginStatus(page);
@@ -1205,6 +1204,8 @@ public abstract class GCParser {
/**
* Adds the cache to the favorites of the user.
*
+ * This must not be called from the UI thread.
+ *
* @param cache
* the cache to add
* @return <code>false</code> if an error occurred, <code>true</code> otherwise
@@ -1235,7 +1236,9 @@ public abstract class GCParser {
}
/**
- * Removes the cache from the Favorites
+ * Removes the cache from the favorites.
+ *
+ * This must not be called from the UI thread.
*
* @param cache
* the cache to remove
@@ -1250,8 +1253,6 @@ public abstract class GCParser {
*
* @param page
* the HTML page to parse, already processed through {@link BaseUtils#replaceWhitespace}
- * @param app
- * if not null, the application to use to save the trackable
* @return the parsed trackable, or null if none could be parsed
*/
static cgTrackable parseTrackable(final String page, final String possibleTrackingcode) {
@@ -1267,7 +1268,7 @@ public abstract class GCParser {
final cgTrackable trackable = new cgTrackable();
// trackable geocode
- trackable.setGeocode(BaseUtils.getMatch(page, GCConstants.PATTERN_TRACKABLE_GEOCODE, true, trackable.getGeocode()).toUpperCase());
+ trackable.setGeocode(BaseUtils.getMatch(page, GCConstants.PATTERN_TRACKABLE_GEOCODE, true, trackable.getGeocode()));
// trackable id
trackable.setGuid(BaseUtils.getMatch(page, GCConstants.PATTERN_TRACKABLE_GUID, true, trackable.getGuid()));
@@ -1398,7 +1399,8 @@ public abstract class GCParser {
}
// Apply the pattern for images in a trackable log entry against each full log (group(0))
- final Matcher matcherLogImages = GCConstants.PATTERN_TRACKABLE_LOG_IMAGES.matcher(matcherLogs.group(0));
+ final String logEntry = matcherLogs.group(0);
+ final Matcher matcherLogImages = GCConstants.PATTERN_TRACKABLE_LOG_IMAGES.matcher(logEntry);
/*
* 1. Image URL
* 2. Image title
@@ -1421,7 +1423,7 @@ public abstract class GCParser {
}
if (cgeoapplication.getInstance() != null) {
- cgeoapplication.getInstance().saveTrackable(trackable);
+ cgData.saveTrackable(trackable);
}
return trackable;
@@ -1560,10 +1562,13 @@ public abstract class GCParser {
final Matcher typeMatcher = GCConstants.PATTERN_TYPE2.matcher(typesText);
while (typeMatcher.find()) {
if (typeMatcher.groupCount() > 1) {
- final int type = Integer.parseInt(typeMatcher.group(2));
-
- if (type > 0) {
- types.add(LogType.getById(type));
+ try {
+ int type = Integer.parseInt(typeMatcher.group(2));
+ if (type > 0) {
+ types.add(LogType.getById(type));
+ }
+ } catch (NumberFormatException e) {
+ Log.e("Error parsing log types", e);
}
}
}
@@ -1673,4 +1678,48 @@ public abstract class GCParser {
}
}
+ public static boolean uploadModifiedCoordinates(cgCache cache, Geopoint wpt) {
+ return editModifiedCoordinates(cache, wpt);
+ }
+
+ public static boolean deleteModifiedCoordinates(cgCache cache) {
+ return editModifiedCoordinates(cache, null);
+ }
+
+ public static boolean editModifiedCoordinates(cgCache cache, Geopoint wpt) {
+ final String page = requestHtmlPage(cache.getGeocode(), null, "n", "0");
+ final String userToken = BaseUtils.getMatch(page, GCConstants.PATTERN_USERTOKEN, "");
+ if (StringUtils.isEmpty(userToken)) {
+ return false;
+ }
+
+ try {
+ JSONObject jo;
+ if (wpt != null) {
+ jo = new JSONObject().put("dto", (new JSONObject().put("ut", userToken)
+ .put("data", new JSONObject()
+ .put("lat", wpt.getLatitudeE6() / 1E6)
+ .put("lng", wpt.getLongitudeE6() / 1E6))));
+ } else {
+ jo = new JSONObject().put("dto", (new JSONObject().put("ut", userToken)));
+ }
+
+ final String uriSuffix = wpt != null ? "SetUserCoordinate" : "ResetUserCoordinate";
+
+ final String uriPrefix = "http://www.geocaching.com/seek/cache_details.aspx/";
+ HttpResponse response = Network.postJsonRequest(uriPrefix + uriSuffix, jo);
+ Log.i("Sending to " + uriPrefix + uriSuffix + " :" + jo.toString());
+
+ if (response != null && response.getStatusLine().getStatusCode() == 200) {
+ Log.i("GCParser.editModifiedCoordinates - edited on GC.com");
+ return true;
+ }
+
+ } catch (JSONException e) {
+ Log.e("Unknown exception with json wrap code", e);
+ }
+ Log.e("GCParser.deleteModifiedCoordinates - cannot delete modified coords");
+ return false;
+ }
+
}
diff --git a/main/src/cgeo/geocaching/connector/gc/GCSmiliesProvider.java b/main/src/cgeo/geocaching/connector/gc/GCSmiliesProvider.java
index 1083a89..eba9301 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCSmiliesProvider.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCSmiliesProvider.java
@@ -26,7 +26,7 @@ public class GCSmiliesProvider {
public final String text;
- private Smiley(final String text) {
+ Smiley(final String text) {
this.text = text;
}
diff --git a/main/src/cgeo/geocaching/connector/gc/IconDecoder.java b/main/src/cgeo/geocaching/connector/gc/IconDecoder.java
index 74e78cc..1452157 100644
--- a/main/src/cgeo/geocaching/connector/gc/IconDecoder.java
+++ b/main/src/cgeo/geocaching/connector/gc/IconDecoder.java
@@ -11,106 +11,191 @@ import android.graphics.Bitmap;
*/
public abstract class IconDecoder {
- public static void parseMapPNG(final cgCache cache, Bitmap bitmap, UTFGridPosition xy, int zoomlevel) {
+ public static boolean parseMapPNG(final cgCache cache, Bitmap bitmap, UTFGridPosition xy, int zoomlevel) {
if (zoomlevel >= 14) {
- parseMapPNG14(cache, bitmap, xy);
- } else {
- parseMapPNG13(cache, bitmap, xy);
+ return parseMapPNG14(cache, bitmap, xy);
}
+ if (zoomlevel <= 11) {
+ return parseMapPNG11(cache, bitmap, xy);
+ }
+ return parseMapPNG13(cache, bitmap, xy);
}
- private static final int[] OFFSET_X = new int[] { 0, -1, -1, 0, 1, 1, 1, 0, -1, -2, -2, -2, -2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2 };
- private static final int[] OFFSET_Y = new int[] { 0, 0, 1, 1, 1, 0, -1, -1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2 };
+ public static int CT_TRADITIONAL = 0;
+ public static int CT_MULTI = 1;
+ public static int CT_MYSTERY = 2;
+ public static int CT_EVENT = 3;
+ public static int CT_VIRTUAL = 4;
+ public static int CT_FOUND = 5;
+ public static int CT_OWN = 6;
+ public static int CT_MEGAEVENT = 7;
+ public static int CT_CITO = 8;
+ public static int CT_WEBCAM = 9;
+ public static int CT_WHEREIGO = 10;
+ public static int CT_EARTH = 11;
+ public static int CT_LETTERBOX = 12;
/**
- * The icon decoder walks a spiral around the center pixel position of the cache
- * and searches for characteristic colors.
+ * The icon decoder over all 16 pixels of image . It should not be invoked on any part of image that might overlay
+ * with other caches.
+ * Is uses decision tree to determine right type.
*
* @param cache
* @param bitmap
* @param xy
+ * @return true if parsing was successful
*/
- private static void parseMapPNG13(final cgCache cache, Bitmap bitmap, UTFGridPosition xy) {
- final int xCenter = xy.getX() * 4 + 2;
- final int yCenter = xy.getY() * 4 + 2;
+ private static boolean parseMapPNG13(final cgCache cache, Bitmap bitmap, UTFGridPosition xy) {
+ final int topX = xy.getX() * 4;
+ final int topY = xy.getY() * 4;
final int bitmapWidth = bitmap.getWidth();
final int bitmapHeight = bitmap.getHeight();
- int countMulti = 0;
- int countFound = 0;
+ if ((topX < 0) || (topY < 0) || (topX + 4 > bitmapWidth) || (topY + 4 > bitmapHeight)) {
+ return false; //out of image position
+ }
- for (int i = 0; i < OFFSET_X.length; i++) {
+ int[] pngType = new int[7];
+ for (int x = topX; x < topX + 4; x++) {
+ for (int y = topY; y < topY + 4; y++) {
+ int color = bitmap.getPixel(x, y);
- // assert that we are still in the tile
- final int x = xCenter + OFFSET_X[i];
- if (x < 0 || x >= bitmapWidth) {
- continue;
- }
-
- final int y = yCenter + OFFSET_Y[i];
- if (y < 0 || y >= bitmapHeight) {
- continue;
- }
+ if ((color & 0xFFFFFF) == 0x5f5f5f) {
+ continue; //Border in every icon is the same and therefore no use to us
+ }
+ if ((color >>> 24) != 255) {
+ continue; //transparent pixels (or semi_transparent) are only shadows of border
+ }
- int color = bitmap.getPixel(x, y) & 0x00FFFFFF;
+ int red = (color & 0xFF0000) >> 16;
+ int green = (color & 0xFF00) >> 8;
+ int blue = color & 0xFF;
- // transparent pixels are not interesting
- if (color == 0) {
- continue;
+ int type = getCacheTypeFromPixel13(red, green, blue);
+ pngType[type]++;
}
+ }
- int red = (color & 0xFF0000) >> 16;
- int green = (color & 0xFF00) >> 8;
- int blue = color & 0xFF;
+ int type = -1;
+ int count = 0;
- // these are quite sure, so one pixel is enough for matching
- if (green > 0x80 && green > red && green > blue) {
- cache.setType(CacheType.TRADITIONAL);
- return;
- }
- if (blue > 0x80 && blue > red && blue > green) {
- cache.setType(CacheType.MYSTERY);
- return;
- }
- if (red > 0x90 && blue < 0x10 && green < 0x10) {
- cache.setType(CacheType.EVENT);
- return;
+ for (int x = 0; x < 7; x++)
+ {
+ if (pngType[x] > count) {
+ count = pngType[x];
+ type = x;
}
+ }
- // next two are hard to distinguish, therefore we sample all pixels of the spiral
- if (red > 0xFA && green > 0xD0) {
- countMulti++;
+ if (count > 1) { // 2 pixels need to detect same type and we say good to go
+ switch (type) {
+ case 0:
+ cache.setType(CacheType.TRADITIONAL);
+ return true;
+ case 1:
+ cache.setType(CacheType.MULTI);
+ return true;
+ case 2:
+ cache.setType(CacheType.MYSTERY); //mystery, whereigo, groundspeak HQ and mystery is most common
+ return true;
+ case 3:
+ cache.setType(CacheType.EVENT); //event, cito, mega-event and event is most common
+ return true;
+ case 4:
+ cache.setType(CacheType.EARTH); //It's an image of ghost (webcam, earth, virtual) and earth in most common
+ return true;
+ case 5:
+ cache.setFound(true);
+ return true;
+ case 6:
+ cache.setOwn(true);
+ return true;
}
- if (red < 0xF3 && red > 0xa0 && green > 0x20 && blue < 0x80) {
- countFound++;
+ }
+ return false;
+ }
+
+ /**
+ * The icon decoder over all 16 pixels of image . It should not be invoked on any part of image that might overlay
+ * with other caches.
+ * Is uses decision tree to determine right type.
+ *
+ * @param cache
+ * @param bitmap
+ * @param xy
+ * @return true if parsing was successful
+ */
+ private static boolean parseMapPNG11(final cgCache cache, Bitmap bitmap, UTFGridPosition xy) {
+ final int topX = xy.getX() * 4;
+ final int topY = xy.getY() * 4;
+ final int bitmapWidth = bitmap.getWidth();
+ final int bitmapHeight = bitmap.getHeight();
+
+ if ((topX < 0) || (topY < 0) || (topX + 4 > bitmapWidth) || (topY + 4 > bitmapHeight)) {
+ return false; //out of image position
+ }
+
+ int[] pngType = new int[5];
+ for (int x = topX; x < topX + 4; x++) {
+ for (int y = topY; y < topY + 4; y++) {
+ int color = bitmap.getPixel(x, y);
+
+
+ if ((color >>> 24) != 255) {
+ continue; //transparent pixels (or semi_transparent) are only shadows of border
+ }
+
+ int r = (color & 0xFF0000) >> 16;
+ int g = (color & 0xFF00) >> 8;
+ int b = color & 0xFF;
+
+ //Duplicate colors does not add any value
+ if (((r == 52) && (g == 52) && (b == 52)) ||
+ ((r == 69) && (g == 69) && (b == 69)) ||
+ ((r == 90) && (g == 90) && (b == 90)) ||
+ ((r == 233) && (g == 233) && (b == 234)) ||
+ ((r == 255) && (g == 255) && (b == 255))) {
+ continue;
+ }
+
+ int type = getCacheTypeFromPixel11(r, g, b);
+ pngType[type]++;
}
}
- // now check whether we are sure about found/multi
- if (countFound > countMulti && countFound >= 2) {
- cache.setFound(true);
+ int type = -1;
+ int count = 0;
+
+ for (int x = 0; x < 5; x++)
+ {
+ if (pngType[x] > count) {
+ count = pngType[x];
+ type = x;
+ }
}
- if (countMulti > countFound && countMulti >= 5) {
- cache.setType(CacheType.MULTI);
+
+ if (count > 1) { // 2 pixels need to detect same type and we say good to go
+ switch (type) {
+ case 0:
+ cache.setType(CacheType.TRADITIONAL);
+ return true;
+ case 1:
+ cache.setType(CacheType.MULTI);
+ return true;
+ case 2:
+ cache.setType(CacheType.MYSTERY); //mystery, whereigo, groundspeak HQ and mystery is most common
+ return true;
+ case 3:
+ cache.setType(CacheType.EVENT); //event, cito, mega-event and event is most common
+ return true;
+ case 4:
+ cache.setType(CacheType.EARTH); //webcam, earth, virtual and earth in most common
+ return true;
+ }
}
+ return false;
}
- // Pixel colors in tile
- private final static int COLOR_BORDER_GRAY = 0x5F5F5F;
- private final static int COLOR_TRADITIONAL = 0x316013;
- private final static int COLOR_MYSTERY = 0x243C97;
- private final static int COLOR_MULTI = 0xFFDE19;
- private final static int COLOR_FOUND = 0xFBEA5D;
-
- // Offset inside cache icon
- private final static int POSX_TRADI = 7;
- private final static int POSY_TRADI = -12;
- private final static int POSX_MULTI = 5; // for orange 8
- private final static int POSY_MULTI = -9; // for orange 10
- private final static int POSX_MYSTERY = 5;
- private final static int POSY_MYSTERY = -13;
- private final static int POSX_FOUND = 10;
- private final static int POSY_FOUND = -8;
/**
* For level 14 find the borders of the icons and then use a single pixel and color to match.
@@ -119,44 +204,376 @@ public abstract class IconDecoder {
* @param bitmap
* @param xy
*/
- private static void parseMapPNG14(cgCache cache, Bitmap bitmap, UTFGridPosition xy) {
- int x = xy.getX() * 4 + 2;
- int y = xy.getY() * 4 + 2;
+ private static boolean parseMapPNG14(cgCache cache, Bitmap bitmap, UTFGridPosition xy) {
+ final int topX = xy.getX() * 4;
+ final int topY = xy.getY() * 4;
+ final int bitmapWidth = bitmap.getWidth();
+ final int bitmapHeight = bitmap.getHeight();
+
+ if ((topX < 0) || (topY < 0) || (topX + 4 > bitmapWidth) || (topY + 4 > bitmapHeight)) {
+ return false; //out of image position
+ }
+
+ int[] pngType = new int[13];
+ for (int x = topX; x < topX + 4; x++) {
+ for (int y = topY; y < topY + 4; y++) {
+ int color = bitmap.getPixel(x, y);
+
+ if ((color & 0xFFFFFF) == 0x5f5f5f) {
+ continue; //Border in every icon is the same and therefore no use to us
+ }
+ if ((color >>> 24) != 255) {
+ continue; //transparent pixels (or semi_transparent) are only shadows of border
+ }
+
+ int r = (color & 0xFF0000) >> 16;
+ int g = (color & 0xFF00) >> 8;
+ int b = color & 0xFF;
+
+ //Duplicate colors does not add any value
+ if (((r == 216) && (g == 216) && (b == 216)) ||
+ ((r == 23) && (g == 23) && (b == 23)) ||
+ ((r == 240) && (g == 240) && (b == 240)) ||
+ ((r == 44) && (g == 44) && (b == 44)) ||
+ ((r == 228) && (g == 228) && (b == 228)) ||
+ ((r == 225) && (g == 225) && (b == 225)) ||
+ ((r == 199) && (g == 199) && (b == 199)) ||
+ ((r == 161) && (g == 161) && (b == 161)) ||
+ ((r == 8) && (g == 8) && (b == 8)) ||
+ ((r == 200) && (g == 200) && (b == 200)) ||
+ ((r == 255) && (g == 255) && (b == 255)) ||
+ ((r == 250) && (g == 250) && (b == 250)) ||
+ ((r == 95) && (g == 95) && (b == 95)) ||
+ ((r == 236) && (g == 236) && (b == 236)) ||
+ ((r == 215) && (g == 215) && (b == 215)) ||
+ ((r == 232) && (g == 232) && (b == 232)) ||
+ ((r == 217) && (g == 217) && (b == 217)) ||
+ ((r == 0) && (g == 0) && (b == 0)) ||
+ ((r == 167) && (g == 167) && (b == 167)) ||
+ ((r == 247) && (g == 247) && (b == 247)) ||
+ ((r == 144) && (g == 144) && (b == 144)) ||
+ ((r == 231) && (g == 231) && (b == 231)) ||
+ ((r == 248) && (g == 248) && (b == 248))) {
+ continue;
+ }
- // search for left border
- int countX = 0;
- while ((bitmap.getPixel(x, y) & 0x00FFFFFF) != COLOR_BORDER_GRAY) {
- if (--x < 0 || ++countX > 20) {
- return;
+ int type = getCacheTypeFromPixel14(r, g, b);
+ pngType[type]++;
}
}
- // search for bottom border
- int countY = 0;
- while ((bitmap.getPixel(x, y) & 0x00FFFFFF) != 0x000000) {
- if (++y >= Tile.TILE_SIZE || ++countY > 20) {
- return;
+
+ int type = -1;
+ int count = 0;
+
+ for (int x = 0; x < 7; x++)
+ {
+ if (pngType[x] > count) {
+ count = pngType[x];
+ type = x;
+ }
+ }
+ /*
+ * public static int CT_MEGAEVENT = 7;
+ * public static int CT_CITO = 8;
+ * public static int CT_WEBCAM = 9;
+ * public static int CT_WHEREIGO = 10;
+ * public static int CT_EARTH = 11;
+ * public static int CT_LETTERBOX = 12;
+ */
+ if (count > 1) { // 2 pixels need to detect same type and we say good to go
+ switch (type) {
+ case 0:
+ cache.setType(CacheType.TRADITIONAL);
+ return true;
+ case 1:
+ cache.setType(CacheType.MULTI);
+ return true;
+ case 2:
+ cache.setType(CacheType.MYSTERY);
+ return true;
+ case 3:
+ cache.setType(CacheType.EVENT);
+ return true;
+ case 4:
+ cache.setType(CacheType.VIRTUAL);
+ return true;
+ case 5:
+ cache.setFound(true);
+ return true;
+ case 6:
+ cache.setOwn(true);
+ return true;
+ case 7:
+ cache.setType(CacheType.MEGA_EVENT);
+ return true;
+ case 8:
+ cache.setType(CacheType.CITO);
+ return true;
+ case 9:
+ cache.setType(CacheType.WEBCAM);
+ return true;
+ case 10:
+ cache.setType(CacheType.WHERIGO);
+ return true;
+ case 11:
+ cache.setType(CacheType.EARTH);
+ return true;
+ case 12:
+ cache.setType(CacheType.LETTERBOX);
+ return true;
+ }
+ }
+ return false;
+
+ }
+
+ /**
+ * This method returns detected type from specific pixel from geocaching.com live map.
+ * It was constructed based on classification tree made by Orange (http://orange.biolab.si/)
+ * Input file was made from every non-transparent pixel of every possible "middle" cache icon from GC map
+ *
+ * @param r
+ * Red component of pixel (from 0 - 255)
+ * @param g
+ * Green component of pixel (from 0 - 255)
+ * @param b
+ * Blue component of pixel (from 0 - 255)
+ * @return Value from 0 to 6 representing detected type or state of the cache.
+ */
+ private static int getCacheTypeFromPixel13(int r, int g, int b) {
+ if (g < 110) {
+ if (r > 87) {
+ return ((g > 73) && (b < 63)) ? CT_FOUND : CT_EVENT;
+ }
+ return CT_MYSTERY;
+ }
+ if (b > 137) {
+ if ((r < 184) && (g > 190)) {
+ return CT_TRADITIONAL;
+ }
+ if ((r < 184) && (g < 191) && (r < 136)) {
+ return CT_MYSTERY;
}
+ return CT_VIRTUAL;
}
+ if (r < 158) {
+ return ((r > 129) && (r < 153)) ? CT_FOUND : CT_TRADITIONAL;
+ }
+ if (b > 33) {
+ if (b > 57) {
+ if (b > 100) {
+ return (r > 229) ? CT_MULTI : CT_EVENT;
+ }
+ return ((r > 254) && (g < 236)) ? CT_MULTI : CT_FOUND;
+ }
+ if ((g > 173) && ((g < 224))) {
+ return ((r < 243) && (r > 223)) ? CT_FOUND : CT_OWN;
+ }
+ return CT_FOUND;
+ }
+ return CT_MULTI;
+ }
- try {
- if ((bitmap.getPixel(x + POSX_TRADI, y + POSY_TRADI) & 0x00FFFFFF) == COLOR_TRADITIONAL) {
- cache.setType(CacheType.TRADITIONAL);
- return;
+ /**
+ * This method returns detected type from specific pixel from geocaching.com live map level 14 or higher.
+ * It was constructed based on classification tree made by Orange (http://orange.biolab.si/)
+ * Input file was made from every non-transparent pixel of every possible "full" cache icon from GC map
+ *
+ * @param r
+ * Red component of pixel (from 0 - 255)
+ * @param g
+ * Green component of pixel (from 0 - 255)
+ * @param b
+ * Blue component of pixel (from 0 - 255)
+ * @return Value from 0 to 6 representing detected type or state of the cache.
+ */
+ private static int getCacheTypeFromPixel14(int r, int g, int b) {
+ if (b < 140) {
+ if (r > 155) {
+ if (g < 159) {
+ if (r < 173) {
+ return (r > 161) ? CT_MEGAEVENT : CT_OWN;
+ }
+ if (r < 206) {
+ if (b > 49) {
+ return (b > 83) ? CT_EVENT : CT_FOUND;
+ }
+ return (b < 31) ? CT_EARTH : CT_FOUND;
+ }
+ return (r < 221) ? CT_FOUND : CT_MULTI;
+ }
+ if (r > 210) {
+ if (g < 188) {
+ return CT_FOUND;
+ }
+ if (r < 246) {
+ return CT_OWN;
+ }
+ if (r < 254) {
+ return CT_FOUND;
+ }
+ if (r < 255) {
+ return CT_EVENT;
+ }
+ if (g < 208) {
+ return CT_EARTH;
+ }
+ if (g > 225) {
+ return CT_EARTH;
+ }
+ return (b < 36) ? CT_MULTI : CT_OWN;
+ }
+ return (b < 66) ? CT_OWN : CT_EARTH;
+ }
+ if (r < 63) {
+ if (b > 26) {
+ if (b < 29) {
+ return CT_WEBCAM;
+ }
+ if (g > 102) {
+ return CT_CITO;
+ }
+ return (r < 26) ? CT_CITO : CT_WEBCAM;
+ }
+ if (g < 38) {
+ return CT_WEBCAM;
+ }
+ return (r < 41) ? CT_EARTH : CT_TRADITIONAL;
+ }
+ if (b < 119) {
+ if (g < 81) {
+ return CT_WEBCAM;
+ }
+ if (b < 90) {
+ return CT_OWN;
+ }
+ return (r < 104) ? CT_WEBCAM : CT_OWN;
+ }
+ if (r < 132) {
+ return (b < 124) ? CT_MULTI : CT_WHEREIGO;
+ }
+ if (g > 164) {
+ return CT_TRADITIONAL;
+ }
+ if (b < 134) {
+ return CT_OWN;
+ }
+ return (b > 137) ? CT_OWN : CT_WHEREIGO;
+ }
+ if (b < 245) {
+ if (r < 180) {
+ if (b < 218) {
+ if (g < 71) {
+ return CT_MYSTERY;
+ }
+ if (r < 96) {
+ return CT_WHEREIGO;
+ }
+ if (b > 165) {
+ return CT_WHEREIGO;
+ }
+ if (r < 153) {
+ return CT_WHEREIGO;
+ }
+ if (r < 160) {
+ return CT_WEBCAM;
+ }
+ return (r < 162) ? CT_WHEREIGO : CT_WEBCAM;
+ }
+ return (r < 158) ? CT_MEGAEVENT : CT_EARTH;
}
- if ((bitmap.getPixel(x + POSX_MYSTERY, y + POSY_MYSTERY) & 0x00FFFFFF) == COLOR_MYSTERY) {
- cache.setType(CacheType.MYSTERY);
- return;
+ if (g > 232) {
+ if (g > 247) {
+ return CT_CITO;
+ }
+ if (r < 237) {
+ return CT_OWN;
+ }
+ if (g < 238) {
+ return CT_OWN;
+ }
+ if (r > 243) {
+ return CT_WEBCAM;
+ }
+ return (g > 238) ? CT_OWN : CT_WEBCAM;
}
- if ((bitmap.getPixel(x + POSX_MULTI, y + POSY_MULTI) & 0x00FFFFFF) == COLOR_MULTI) {
- cache.setType(CacheType.MULTI);
- return;
+ if (r < 228) {
+ if (b > 238) {
+ return CT_MYSTERY;
+ }
+ if (r < 193) {
+ if (r < 184) {
+ return CT_OWN;
+ }
+ if (g < 186) {
+ return CT_WHEREIGO;
+ }
+ return (r > 189) ? CT_WHEREIGO : CT_OWN;
+ }
+ if (g < 223) {
+ if (r > 216) {
+ return CT_OWN;
+ }
+ if (g > 217) {
+ return CT_WHEREIGO;
+ }
+ if (b > 211) {
+ return CT_WEBCAM;
+ }
+ if (b < 196) {
+ return CT_WEBCAM;
+ }
+ if (r > 210) {
+ return CT_OWN;
+ }
+ return (g > 206) ? CT_WHEREIGO : CT_OWN;
+ }
+ if (g < 224) {
+ return CT_OWN;
+ }
+ return (r < 226) ? CT_WHEREIGO : CT_OWN;
}
- if ((bitmap.getPixel(x + POSX_FOUND, y + POSY_FOUND) & 0x00FFFFFF) == COLOR_FOUND) {
- cache.setFound(true);
+ return (b < 216) ? CT_FOUND : CT_OWN;
+ }
+ if (r < 238) {
+ if (r > 141) {
+ return (r > 185) ? CT_LETTERBOX : CT_CITO;
}
- } catch (IllegalArgumentException e) {
- // intentionally left blank
+ return (r < 41) ? CT_EARTH : CT_LETTERBOX;
}
+ return (r < 243) ? CT_WHEREIGO : CT_OWN;
+ }
+ /**
+ * This method returns detected type from specific pixel from geocaching.com live map level 11 or lower.
+ * It was constructed based on classification tree made by Orange (http://orange.biolab.si/)
+ * Input file was made from every non-transparent pixel of every possible "full" cache icon from GC map
+ *
+ * @param r
+ * Red component of pixel (from 0 - 255)
+ * @param g
+ * Green component of pixel (from 0 - 255)
+ * @param b
+ * Blue component of pixel (from 0 - 255)
+ * @return Value from 0 to 4 representing detected type or state of the cache.
+ */
+ private static int getCacheTypeFromPixel11(int r, int g, int b) {
+ if (b < 139) {
+ if (g > 104) {
+ if (r < 173) {
+ return CT_TRADITIONAL;
+ }
+ return (r > 225) ? CT_MULTI : CT_EVENT;
+ }
+ if (b < 25) {
+ return CT_EVENT;
+ }
+ return (r < 87) ? CT_MYSTERY : CT_EVENT;
+ }
+ if (r > 140) {
+ return (r < 197) ? CT_TRADITIONAL : CT_VIRTUAL;
+ }
+ return CT_MYSTERY;
}
+
}
diff --git a/main/src/cgeo/geocaching/connector/gc/Login.java b/main/src/cgeo/geocaching/connector/gc/Login.java
index c3f29cc..494bcee 100644
--- a/main/src/cgeo/geocaching/connector/gc/Login.java
+++ b/main/src/cgeo/geocaching/connector/gc/Login.java
@@ -361,14 +361,13 @@ public abstract class Login {
String[] viewstates = new String[count];
// Get the viewstates
- int no;
final Matcher matcherViewstates = GCConstants.PATTERN_VIEWSTATES.matcher(page);
while (matcherViewstates.find()) {
String sno = matcherViewstates.group(1); // number of viewstate
- if (sno.length() == 0) {
+ int no;
+ if (StringUtils.isEmpty(sno)) {
no = 0;
- }
- else {
+ } else {
try {
no = Integer.parseInt(sno);
} catch (NumberFormatException e) {
diff --git a/main/src/cgeo/geocaching/connector/gc/Tile.java b/main/src/cgeo/geocaching/connector/gc/Tile.java
index 5404446..73ded4d 100644
--- a/main/src/cgeo/geocaching/connector/gc/Tile.java
+++ b/main/src/cgeo/geocaching/connector/gc/Tile.java
@@ -17,6 +17,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
+import java.util.Locale;
import java.util.Set;
/**
@@ -99,7 +100,7 @@ public class Tile {
/**
* Calculate latitude/longitude for a given x/y position in this tile.
- *
+ *
* @see <a
* href="http://developers.cloudmade.com/projects/tiles/examples/convert-coordinates-to-tile-numbers">Cloudmade</a>
*/
@@ -115,7 +116,7 @@ public class Tile {
@Override
public String toString() {
- return String.format("(%d/%d), zoom=%d", tileX, tileY, zoomlevel);
+ return String.format(Locale.US, "(%d/%d), zoom=%d", tileX, tileY, zoomlevel);
}
/**
diff --git a/main/src/cgeo/geocaching/connector/gc/UTFGrid.java b/main/src/cgeo/geocaching/connector/gc/UTFGrid.java
index a4eeff5..6d20eb6 100644
--- a/main/src/cgeo/geocaching/connector/gc/UTFGrid.java
+++ b/main/src/cgeo/geocaching/connector/gc/UTFGrid.java
@@ -29,7 +29,7 @@ public final class UTFGrid {
}
/** Calculate from a list of positions (x/y) the coords */
- protected static UTFGridPosition getPositionInGrid(List<UTFGridPosition> positions) {
+ public static UTFGridPosition getPositionInGrid(List<UTFGridPosition> positions) {
int minX = GRID_MAXX;
int maxX = 0;
int minY = GRID_MAXY;