From 00e4f99229d03d7db5ffd753e9e704e19abea3fa Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sun, 4 Mar 2012 07:28:42 +0100 Subject: refactoring: move constants and classes to the packages they belong to --- main/src/cgeo/geocaching/CacheDetailActivity.java | 6 +- main/src/cgeo/geocaching/Constants.java | 30 ---- main/src/cgeo/geocaching/GCConstants.java | 152 ------------------- main/src/cgeo/geocaching/cgBase.java | 10 +- main/src/cgeo/geocaching/cgCache.java | 2 +- main/src/cgeo/geocaching/cgData.java | 12 +- main/src/cgeo/geocaching/cgeo.java | 16 +- main/src/cgeo/geocaching/cgeoadvsearch.java | 1 + main/src/cgeo/geocaching/cgeonavigate.java | 3 +- .../geocaching/connector/ConnectorFactory.java | 1 + .../src/cgeo/geocaching/connector/GCConnector.java | 163 --------------------- main/src/cgeo/geocaching/connector/gc/GCBase.java | 1 - .../cgeo/geocaching/connector/gc/GCConnector.java | 162 ++++++++++++++++++++ .../cgeo/geocaching/connector/gc/GCConstants.java | 158 ++++++++++++++++++++ .../cgeo/geocaching/geopoint/DistanceParser.java | 6 +- .../cgeo/geocaching/geopoint/HumanDistance.java | 2 +- main/src/cgeo/geocaching/geopoint/IConversion.java | 12 +- main/src/cgeo/geocaching/maps/ScaleOverlay.java | 2 +- main/src/cgeo/geocaching/ui/CacheListAdapter.java | 5 +- main/src/cgeo/geocaching/ui/Formatter.java | 8 + .../cgeo/geocaching/utils/LogTemplateProvider.java | 2 +- 21 files changed, 378 insertions(+), 376 deletions(-) delete mode 100644 main/src/cgeo/geocaching/Constants.java delete mode 100644 main/src/cgeo/geocaching/GCConstants.java delete mode 100644 main/src/cgeo/geocaching/connector/GCConnector.java create mode 100644 main/src/cgeo/geocaching/connector/gc/GCConnector.java create mode 100644 main/src/cgeo/geocaching/connector/gc/GCConstants.java create mode 100644 main/src/cgeo/geocaching/ui/Formatter.java (limited to 'main/src/cgeo/geocaching') diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index d3076bc..b54c0cb 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -14,8 +14,10 @@ import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.enumerations.WaypointType; import cgeo.geocaching.geopoint.GeopointFormatter; import cgeo.geocaching.geopoint.HumanDistance; +import cgeo.geocaching.geopoint.IConversion; import cgeo.geocaching.network.HtmlImage; import cgeo.geocaching.network.Parameters; +import cgeo.geocaching.ui.Formatter; import cgeo.geocaching.ui.DecryptTextClickListener; import cgeo.geocaching.utils.BaseUtils; import cgeo.geocaching.utils.CancellableHandler; @@ -739,7 +741,7 @@ public class CacheDetailActivity extends AbstractActivity { dist.append(Math.abs((int) diff)); dist.append(" m"); } else { - dist.append(Math.abs((int) (diff * Constants.M2FT))); + dist.append(Math.abs((int) (diff * IConversion.METERS_TO_FEET))); dist.append(" ft"); } } @@ -2427,7 +2429,7 @@ public class CacheDetailActivity extends AbstractActivity { } if (CollectionUtils.isNotEmpty(infoTextList)) { final TextView infoView = (TextView) waypointView.findViewById(R.id.info); - infoView.setText(StringUtils.join(infoTextList, " · ")); + infoView.setText(StringUtils.join(infoTextList, Formatter.SEPARATOR)); infoView.setVisibility(View.VISIBLE); } diff --git a/main/src/cgeo/geocaching/Constants.java b/main/src/cgeo/geocaching/Constants.java deleted file mode 100644 index 180e039..0000000 --- a/main/src/cgeo/geocaching/Constants.java +++ /dev/null @@ -1,30 +0,0 @@ -package cgeo.geocaching; - -/** - * Various constant values used all over in c:geo - * - * @author blafoo - */ - -public final class Constants { - - /** Number of days (as ms) after temporarily saved caches are deleted */ - public static long DAYS_AFTER_CACHE_IS_DELETED = 3 * 24 * 60 * 60 * 1000; - - /** Number of logs to retrieve from GC.com */ - public final static int NUMBER_OF_LOGS = 35; - - /** User agent id */ - public final static String USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1"; - - /** Text separator used for formatting texts */ - public static final String SEPARATOR = " · "; - - /** - * Factor used to calculate distance from meters to foot; - *

- * ft = m * M2FT; - */ - public static final double M2FT = 3.2808399d; - -} diff --git a/main/src/cgeo/geocaching/GCConstants.java b/main/src/cgeo/geocaching/GCConstants.java deleted file mode 100644 index d884380..0000000 --- a/main/src/cgeo/geocaching/GCConstants.java +++ /dev/null @@ -1,152 +0,0 @@ -package cgeo.geocaching; - -import java.util.regex.Pattern; - -/** - * These patterns have been optimized for speed. Improve them only if you can prove - * that *YOUR* pattern is faster. Use RegExRealPerformanceTest to show. - * - * For further information about patterns have a look at - * http://download.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html - * - * @author blafoo - */ -public final class GCConstants { - - /** Live Map */ - public final static String URL_LIVE_MAP = "http://www.geocaching.com/map/default.aspx"; - /** Caches in a tile */ - public final static String URL_MAP_INFO = "http://www.geocaching.com/map/map.info"; - /** Tile itself */ - public final static String URL_MAP_TILE = "http://www.geocaching.com/map/map.tile"; - - /** - * Patterns for parsing the result of a (detailed) search - */ - public final static Pattern PATTERN_HINT = Pattern.compile("

]*>(.*?)
"); - public final static Pattern PATTERN_DESC = Pattern.compile("(.*?)[^<]*[^<]*

[^<]*

[^<]*

[^<]*\\W*Additional Hints"); - public final static Pattern PATTERN_SHORTDESC = Pattern.compile("(.*?)[^\\w^<]*"); - public final static Pattern PATTERN_GEOCODE = Pattern.compile("[^<]*]*>[^S]*Size[^:]*:[^<]*]*>[^<]*\"\\w+:]*>[^<]*[^<]*[^<]*[^<]*

"); - public final static Pattern PATTERN_LATLON = Pattern.compile("]*>(.*?)"); - public final static Pattern PATTERN_LATLON_ORIG = Pattern.compile("\\{\"isUserDefined\":true[^}]+?\"oldLatLngDisplay\":\"([^\"]+)\"\\}"); - public final static Pattern PATTERN_LOCATION = Pattern.compile(Pattern.quote("In ") + "(?:]*>)?(.*?)<"); - public final static Pattern PATTERN_PERSONALNOTE = Pattern.compile("

]*>(.*?)

"); - public final static Pattern PATTERN_NAME = Pattern.compile("(.*?)"); - public final static Pattern PATTERN_DIFFICULTY = Pattern.compile("]*>[^<]*]*>[^<]*]*>[^<]*
[^<]*

"); - public final static Pattern PATTERN_FOUND_ALTERNATIVE = Pattern.compile("
[^<]+([^<]+)"); - public final static Pattern PATTERN_TYPE = Pattern.compile("\"([^\"]+?)\"\\W*Hidden[\\s:]*([^<]+?)"); - public final static Pattern PATTERN_HIDDENEVENT = Pattern.compile("Event\\s*Date\\s*:\\s*([^<]+)", Pattern.DOTALL); - public final static Pattern PATTERN_FAVORITE = Pattern.compile("\"Remove"); - public final static Pattern PATTERN_FAVORITECOUNT = Pattern.compile("]+>[^<]*\\D*([0-9]+?)"); - public final static Pattern PATTERN_COUNTLOGS = Pattern.compile(""); - public final static Pattern PATTERN_LOGBOOK = Pattern.compile("initalLogs = (\\{.+\\});"); - /** Two groups ! */ - public final static Pattern PATTERN_COUNTLOG = Pattern.compile("]+> (\\d*[,.]?\\d+)"); - public static final Pattern PATTERN_PREMIUMMEMBERS = Pattern.compile("

This is a Premium Member Only cache.

"); - public final static Pattern PATTERN_ATTRIBUTES = Pattern.compile("

[^<]*]+>\\W*Attributes[^<]*

[^<]*
((?:[^<]*\"[^\"]+\"[^]*>)+?)[^<]*\\s+((?:]+>]+>[^<]+
(?:[^<]+

)?)+)\\s+

"); - public final static Pattern PATTERN_SPOILERSINSIDE = Pattern.compile("]+>]+>([^<]+)
(?:([^<]+)

)?"); - public final static Pattern PATTERN_INVENTORY = Pattern.compile("\\W*Inventory[^<]*[^<]*[^<]*
([^<]*
    (([^<]*
  • [^<]*]*>[^<]*]*>[^<]*[^<]+<\\/span>[^<]*<\\/a>[^<]*<\\/li>)+)[^<]*<\\/ul>)?"); - public final static Pattern PATTERN_INVENTORYINSIDE = Pattern.compile("[^<]*
  • [^<]*]*>[^<]*]*>[^<]*([^<]+)<\\/span>[^<]*<\\/a>[^<]*<\\/li>"); - public final static Pattern PATTERN_WATCHLIST = Pattern.compile("icon_stop_watchlist.gif"); - - // Info box top-right - public static final Pattern PATTERN_LOGIN_NAME = Pattern.compile("\"SignedInProfileLink\">([^<]+)"); - public static final Pattern PATTERN_MEMBER_STATUS = Pattern.compile("([^<]+)"); - /** Use replaceAll("[,.]","") on the resulting string before converting to an int */ - public static final Pattern PATTERN_CACHES_FOUND = Pattern.compile("title=\"Caches Found\"[\\s\\w=\"/.]*/>\\s*([\\d,.]+)"); - public static final Pattern PATTERN_AVATAR_IMAGE_PROFILE_PAGE = Pattern.compile("]*\\salt=\"Avatar\""); - public static final Pattern PATTERN_LOGIN_NAME_LOGIN_PAGE = Pattern.compile("You are logged in as[^<]*]*>([^<]+)[^<]*"); - public static final Pattern PATTERN_CUSTOMDATE = Pattern.compile("
  • ([^<]+)[^<]*]+>[^<]*\"([^\"]+)\"]*>[^<]*"); - public final static Pattern PATTERN_SEARCH_GUIDANDDISABLED = Pattern.compile("]*>[^<]*[^<]*([^<]*)?([^<]*)([^<]*)?[^<]+
    ([^<]*)]+>([^<]*)([^<]*]+>)?[^<]*
    [^<]*"); - /** Two groups **/ - public final static Pattern PATTERN_SEARCH_TRACKABLES = Pattern.compile("]*>(.*)"); - /** Second group used */ - public final static Pattern PATTERN_SEARCH_TRACKABLESINSIDE = Pattern.compile("(\"([^\"]+)\"[^<]*)"); - public final static Pattern PATTERN_SEARCH_DIRECTION = Pattern.compile("]*>"); - public final static Pattern PATTERN_SEARCH_GEOCODE = Pattern.compile("\\|\\W*(GC[0-9A-Z]+)[^\\|]*\\|"); - public final static Pattern PATTERN_SEARCH_ID = Pattern.compile("name=\"CID\"[^v]*value=\"([0-9]+)\""); - public final static Pattern PATTERN_SEARCH_FAVORITE = Pattern.compile("([0-9]+)"); - public final static Pattern PATTERN_SEARCH_TOTALCOUNT = Pattern.compile("Total Records[^<]*(\\d+)<\\/b>"); - public final static Pattern PATTERN_SEARCH_RECAPTCHA = Pattern.compile("]*src=\"[^\"]*/recaptcha/api/challenge\\?k=([^\"]+)\"[^>]*>"); - public final static Pattern PATTERN_SEARCH_RECAPTCHACHALLENGE = Pattern.compile("challenge : '([^']+)'"); - - /** - * Patterns for waypoints - */ - public final static Pattern PATTERN_WPTYPE = Pattern.compile("\\/wpttypes\\/sm\\/(.+)\\.jpg"); - public final static Pattern PATTERN_WPPREFIXORLOOKUPORLATLON = Pattern.compile(">([^<]*<[^>]+>)?([^<]+)(<[^>]+>[^<]*)?<\\/td>"); - public final static Pattern PATTERN_WPNAME = Pattern.compile(">[^<]*]+>([^<]*)<\\/a>"); - public final static Pattern PATTERN_WPNOTE = Pattern.compile("colspan=\"6\">(.*)<\\/td>"); - - /** - * Patterns for different purposes - */ - /** replace linebreak and paragraph tags */ - public final static Pattern PATTERN_LINEBREAK = Pattern.compile("<(br|p)[^>]*>"); - public final static Pattern PATTERN_TYPEBOX = Pattern.compile("", Pattern.CASE_INSENSITIVE); - public final static Pattern PATTERN_TYPE2 = Pattern.compile("[^<]+", Pattern.CASE_INSENSITIVE); - // FIXME: pattern is over specified - public final static Pattern PATTERN_TRACKABLE = Pattern.compile("]*>" - + "[^<]*[^<]*([A-Z0-9]+)[^<]*[^<]*([^<]+)[^<]*" - + "[^<]*[^<]*[^<]*", Pattern.CASE_INSENSITIVE); - public final static Pattern PATTERN_MAINTENANCE = Pattern.compile("]*>([^<]*]*>)?([^<]+)([^<]*)?", Pattern.CASE_INSENSITIVE); - public final static Pattern PATTERN_OK1 = Pattern.compile("]*>[^<]*]*>[^<]*[^<]*", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); - public final static Pattern PATTERN_OK2 = Pattern.compile("
    ", Pattern.CASE_INSENSITIVE); - public final static Pattern PATTERN_VIEWSTATEFIELDCOUNT = Pattern.compile("id=\"__VIEWSTATEFIELDCOUNT\"[^(value)]+value=\"(\\d+)\"[^>]+>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); - public final static Pattern PATTERN_VIEWSTATES = Pattern.compile("id=\"__VIEWSTATE(\\d*)\"[^(value)]+value=\"([^\"]+)\"[^>]+>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); - public final static Pattern PATTERN_USERTOKEN2 = Pattern.compile("userToken\\s*=\\s*'([^']+)'"); - - /** - * Patterns for GC and TB codes - */ - public final static Pattern PATTERN_GC_CODE = Pattern.compile("GC[0-9A-Z]*", Pattern.CASE_INSENSITIVE); - public final static Pattern PATTERN_TB_CODE = Pattern.compile("TB[0-9A-Z]*", Pattern.CASE_INSENSITIVE); - - /** Live Map since 14.02.2012 */ - public final static Pattern PATTERN_USERSESSION = Pattern.compile("UserSession\\('([^']+)'"); - public final static Pattern PATTERN_SESSIONTOKEN = Pattern.compile("sessionToken:'([^']+)'"); -} diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java index 5b4e867..92eba6f 100644 --- a/main/src/cgeo/geocaching/cgBase.java +++ b/main/src/cgeo/geocaching/cgBase.java @@ -3,7 +3,8 @@ package cgeo.geocaching; import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.connector.ConnectorFactory; -import cgeo.geocaching.connector.GCConnector; +import cgeo.geocaching.connector.gc.GCConnector; +import cgeo.geocaching.connector.gc.GCConstants; import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LoadFlags; @@ -144,6 +145,9 @@ public class cgBase { private static int actualCachesFound = -1; private static String actualStatus = ""; + /** User agent id */ + public final static String USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1"; + private cgBase() { //initialize(app); throw new UnsupportedOperationException(); // static class, not to be instantiated @@ -1155,7 +1159,7 @@ public class cgBase { final Parameters params = new Parameters( "tkn", userToken, "idx", "1", - "num", String.valueOf(Constants.NUMBER_OF_LOGS), + "num", String.valueOf(GCConstants.NUMBER_OF_LOGS), "decrypt", "true", // "sp", Boolean.toString(personal), // personal logs "sf", Boolean.toString(friends)); @@ -2420,7 +2424,7 @@ public class cgBase { private static HttpResponse request(final HttpRequestBase request) { request.setHeader("Accept-Charset", "utf-8,iso-8859-1;q=0.8,utf-16;q=0.8,*;q=0.7"); request.setHeader("Accept-Language", "en-US,*;q=0.9"); - request.getParams().setParameter(CoreProtocolPNames.USER_AGENT, Constants.USER_AGENT); + request.getParams().setParameter(CoreProtocolPNames.USER_AGENT, cgBase.USER_AGENT); return doRequest(request); } diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java index 9be3a86..9a2733f 100644 --- a/main/src/cgeo/geocaching/cgCache.java +++ b/main/src/cgeo/geocaching/cgCache.java @@ -3,9 +3,9 @@ package cgeo.geocaching; import cgeo.geocaching.cgData.StorageLocation; import cgeo.geocaching.activity.IAbstractActivity; import cgeo.geocaching.connector.ConnectorFactory; -import cgeo.geocaching.connector.GCConnector; import cgeo.geocaching.connector.IConnector; import cgeo.geocaching.connector.gc.GCBase; +import cgeo.geocaching.connector.gc.GCConnector; import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LoadFlags.RemoveFlag; diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index df87df4..83247c1 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -57,6 +57,10 @@ public class cgData { "inventoryunknown", "onWatchlist", "personal_note", "reliable_latlon", "coordsChanged", "finalDefined" // reason is replaced by listId in cgCache }; + + /** Number of days (as ms) after temporarily saved caches are deleted */ + private static long DAYS_AFTER_CACHE_IS_DELETED = 3 * 24 * 60 * 60 * 1000; + /** * holds the column indexes of the cache table to avoid lookups */ @@ -1001,7 +1005,7 @@ public class cgData { List list = new ArrayList(); try { - long timestamp = System.currentTimeMillis() - Constants.DAYS_AFTER_CACHE_IS_DELETED; + long timestamp = System.currentTimeMillis() - DAYS_AFTER_CACHE_IS_DELETED; cursor = databaseRO.query( dbTableCaches, new String[] { "geocode" }, @@ -1102,12 +1106,12 @@ public class cgData { return false; } - if (checkTime && detailed && dataDetailedUpdate < (System.currentTimeMillis() - Constants.DAYS_AFTER_CACHE_IS_DELETED)) { + if (checkTime && detailed && dataDetailedUpdate < (System.currentTimeMillis() - DAYS_AFTER_CACHE_IS_DELETED)) { // we want to check time for detailed cache, but data are older than 3 hours return false; } - if (checkTime && !detailed && dataUpdated < (System.currentTimeMillis() - Constants.DAYS_AFTER_CACHE_IS_DELETED)) { + if (checkTime && !detailed && dataUpdated < (System.currentTimeMillis() - DAYS_AFTER_CACHE_IS_DELETED)) { // we want to check time for short cache, but data are older than 3 hours return false; } @@ -2925,7 +2929,7 @@ public class cgData { null, null); } else { - long timestamp = System.currentTimeMillis() - Constants.DAYS_AFTER_CACHE_IS_DELETED; + long timestamp = System.currentTimeMillis() - DAYS_AFTER_CACHE_IS_DELETED; String timestampString = Long.toString(timestamp); cursor = databaseRO.query( dbTableCaches, diff --git a/main/src/cgeo/geocaching/cgeo.java b/main/src/cgeo/geocaching/cgeo.java index 0aa5cf7..2ce5f6d 100644 --- a/main/src/cgeo/geocaching/cgeo.java +++ b/main/src/cgeo/geocaching/cgeo.java @@ -9,7 +9,9 @@ import cgeo.geocaching.enumerations.StatusCode; import cgeo.geocaching.enumerations.WaypointType; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.HumanDistance; +import cgeo.geocaching.geopoint.IConversion; import cgeo.geocaching.maps.CGeoMap; +import cgeo.geocaching.ui.Formatter; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -73,17 +75,17 @@ public class cgeo extends AbstractActivity { TextView userInfoView = (TextView) findViewById(R.id.user_info); - String userInfo = "geocaching.com" + Constants.SEPARATOR; + StringBuilder userInfo = new StringBuilder("geocaching.com").append(Formatter.SEPARATOR); if (cgBase.isActualLoginStatus()) { - userInfo += cgBase.getActualUserName(); + userInfo.append(cgBase.getActualUserName()); if (cgBase.getActualCachesFound() >= 0) { - userInfo += " (" + String.valueOf(cgBase.getActualCachesFound()) + ")"; + userInfo.append(" (").append(String.valueOf(cgBase.getActualCachesFound())).append(')'); } - userInfo += Constants.SEPARATOR; + userInfo.append(Formatter.SEPARATOR); } - userInfo += cgBase.getActualStatus(); + userInfo.append(cgBase.getActualStatus()); - userInfoView.setText(userInfo); + userInfoView.setText(userInfo.toString()); } }; @@ -600,7 +602,7 @@ public class cgeo extends AbstractActivity { if (Settings.isUseMetricUnits()) { navAccuracy.setText("±" + Math.round(geo.accuracyNow) + " m"); } else { - navAccuracy.setText("±" + Math.round(geo.accuracyNow * Constants.M2FT) + " ft"); + navAccuracy.setText("±" + Math.round(geo.accuracyNow * IConversion.METERS_TO_FEET) + " ft"); } } else { navAccuracy.setText(null); diff --git a/main/src/cgeo/geocaching/cgeoadvsearch.java b/main/src/cgeo/geocaching/cgeoadvsearch.java index 97d3a08..db0088c 100644 --- a/main/src/cgeo/geocaching/cgeoadvsearch.java +++ b/main/src/cgeo/geocaching/cgeoadvsearch.java @@ -1,6 +1,7 @@ package cgeo.geocaching; import cgeo.geocaching.activity.AbstractActivity; +import cgeo.geocaching.connector.gc.GCConstants; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.GeopointFormatter; import cgeo.geocaching.geopoint.GeopointParser; diff --git a/main/src/cgeo/geocaching/cgeonavigate.java b/main/src/cgeo/geocaching/cgeonavigate.java index 53a62cc..57717d4 100644 --- a/main/src/cgeo/geocaching/cgeonavigate.java +++ b/main/src/cgeo/geocaching/cgeonavigate.java @@ -3,6 +3,7 @@ package cgeo.geocaching; import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.HumanDistance; +import cgeo.geocaching.geopoint.IConversion; import cgeo.geocaching.maps.CGeoMap; import cgeo.geocaching.ui.CompassView; @@ -366,7 +367,7 @@ public class cgeonavigate extends AbstractActivity { if (Settings.isUseMetricUnits()) { navAccuracy.setText("±" + Math.round(geo.accuracyNow) + " m"); } else { - navAccuracy.setText("±" + Math.round(geo.accuracyNow * Constants.M2FT) + " ft"); + navAccuracy.setText("±" + Math.round(geo.accuracyNow * IConversion.METERS_TO_FEET) + " ft"); } } else { navAccuracy.setText(null); diff --git a/main/src/cgeo/geocaching/connector/ConnectorFactory.java b/main/src/cgeo/geocaching/connector/ConnectorFactory.java index 471d43b..12e19ce 100644 --- a/main/src/cgeo/geocaching/connector/ConnectorFactory.java +++ b/main/src/cgeo/geocaching/connector/ConnectorFactory.java @@ -2,6 +2,7 @@ package cgeo.geocaching.connector; import cgeo.geocaching.ICache; import cgeo.geocaching.SearchResult; +import cgeo.geocaching.connector.gc.GCConnector; import cgeo.geocaching.connector.opencaching.ApiOpenCachingConnector; import cgeo.geocaching.connector.opencaching.OpenCachingConnector; import cgeo.geocaching.geopoint.Geopoint; diff --git a/main/src/cgeo/geocaching/connector/GCConnector.java b/main/src/cgeo/geocaching/connector/GCConnector.java deleted file mode 100644 index 74dc7f5..0000000 --- a/main/src/cgeo/geocaching/connector/GCConnector.java +++ /dev/null @@ -1,163 +0,0 @@ -package cgeo.geocaching.connector; - -import cgeo.geocaching.Constants; -import cgeo.geocaching.R; -import cgeo.geocaching.SearchResult; -import cgeo.geocaching.Settings; -import cgeo.geocaching.cgBase; -import cgeo.geocaching.cgCache; -import cgeo.geocaching.cgeoapplication; -import cgeo.geocaching.connector.gc.GCBase; -import cgeo.geocaching.enumerations.StatusCode; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Viewport; -import cgeo.geocaching.network.Parameters; -import cgeo.geocaching.utils.CancellableHandler; - -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringUtils; - -import android.util.Log; - -import java.util.regex.Pattern; - -public class GCConnector extends AbstractConnector { - - private static GCConnector instance; - private static final Pattern gpxZipFilePattern = Pattern.compile("\\d{7,}(_.+)?\\.zip", Pattern.CASE_INSENSITIVE); - - private GCConnector() { - // singleton - } - - public static GCConnector getInstance() { - if (instance == null) { - instance = new GCConnector(); - } - return instance; - } - - @Override - public boolean canHandle(String geocode) { - return StringUtils.startsWithIgnoreCase(geocode, "GC"); - } - - @Override - public boolean supportsRefreshCache(cgCache cache) { - return true; - } - - @Override - public String getCacheUrl(cgCache cache) { - // it would also be possible to use "http://www.geocaching.com/seek/cache_details.aspx?wp=" + cache.getGeocode(); - return "http://coord.info/" + cache.getGeocode(); - } - - @Override - public boolean supportsWatchList() { - return true; - } - - @Override - public boolean supportsLogging() { - return true; - } - - @Override - public String getName() { - return "GeoCaching.com"; - } - - @Override - public String getHost() { - return "www.geocaching.com"; - } - - @Override - public boolean supportsUserActions() { - return true; - } - - @Override - public boolean supportsCachesAround() { - return true; - } - - @Override - public SearchResult searchByGeocode(final String geocode, final String guid, final cgeoapplication app, final CancellableHandler handler) { - - if (app == null) { - Log.e(Settings.tag, "cgeoBase.searchByGeocode: No application found"); - return null; - } - - final Parameters params = new Parameters("decrypt", "y"); - if (StringUtils.isNotBlank(geocode)) { - params.put("wp", geocode); - } else if (StringUtils.isNotBlank(guid)) { - params.put("guid", guid); - } - params.put("log", "y"); - params.put("numlogs", String.valueOf(Constants.NUMBER_OF_LOGS)); - - cgBase.sendLoadProgressDetail(handler, R.string.cache_dialog_loading_details_status_loadpage); - - final String page = cgBase.requestLogged("http://www.geocaching.com/seek/cache_details.aspx", params, false, false, false); - - if (StringUtils.isEmpty(page)) { - SearchResult search = new SearchResult(); - if (app.isThere(geocode, guid, true, false)) { - if (StringUtils.isBlank(geocode) && StringUtils.isNotBlank(guid)) { - Log.i(Settings.tag, "Loading old cache from cache."); - - search.addGeocode(app.getGeocode(guid)); - } else { - search.addGeocode(geocode); - } - search.error = StatusCode.NO_ERROR; - return search; - } - - Log.e(Settings.tag, "cgeoBase.searchByGeocode: No data from server"); - search.error = StatusCode.COMMUNICATION_ERROR; - return search; - } - - final SearchResult searchResult = cgBase.parseCache(page, handler); - - if (searchResult == null || CollectionUtils.isEmpty(searchResult.getGeocodes())) { - Log.e(Settings.tag, "cgeoBase.searchByGeocode: No cache parsed"); - return searchResult; - } - - SearchResult search = searchResult.filterSearchResults(false, false, Settings.getCacheType()); - - return search; - } - - @Override - public SearchResult searchByCoordinate(Geopoint center) { - // TODO Auto-generated method stub - return super.searchByCoordinate(center); - } - - @Override - public SearchResult searchByViewport(Viewport viewport, String[] tokens) { - return GCBase.searchByViewport(viewport, tokens); - } - - @Override - public boolean isZippedGPXFile(final String fileName) { - return gpxZipFilePattern.matcher(fileName).matches(); - } - - @Override - public boolean isReliableLatLon(boolean cacheHasReliableLatLon) { - return cacheHasReliableLatLon; - } - - @Override - public String[] getTokens() { - return GCBase.getTokens(); - } -} diff --git a/main/src/cgeo/geocaching/connector/gc/GCBase.java b/main/src/cgeo/geocaching/connector/gc/GCBase.java index 04f7e58..8ec758c 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCBase.java +++ b/main/src/cgeo/geocaching/connector/gc/GCBase.java @@ -1,6 +1,5 @@ package cgeo.geocaching.connector.gc; -import cgeo.geocaching.GCConstants; import cgeo.geocaching.SearchResult; import cgeo.geocaching.Settings; import cgeo.geocaching.cgBase; diff --git a/main/src/cgeo/geocaching/connector/gc/GCConnector.java b/main/src/cgeo/geocaching/connector/gc/GCConnector.java new file mode 100644 index 0000000..9f71f62 --- /dev/null +++ b/main/src/cgeo/geocaching/connector/gc/GCConnector.java @@ -0,0 +1,162 @@ +package cgeo.geocaching.connector.gc; + +import cgeo.geocaching.R; +import cgeo.geocaching.SearchResult; +import cgeo.geocaching.Settings; +import cgeo.geocaching.cgBase; +import cgeo.geocaching.cgCache; +import cgeo.geocaching.cgeoapplication; +import cgeo.geocaching.connector.AbstractConnector; +import cgeo.geocaching.enumerations.StatusCode; +import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.network.Parameters; +import cgeo.geocaching.utils.CancellableHandler; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; + +import android.util.Log; + +import java.util.regex.Pattern; + +public class GCConnector extends AbstractConnector { + + private static GCConnector instance; + private static final Pattern gpxZipFilePattern = Pattern.compile("\\d{7,}(_.+)?\\.zip", Pattern.CASE_INSENSITIVE); + + private GCConnector() { + // singleton + } + + public static GCConnector getInstance() { + if (instance == null) { + instance = new GCConnector(); + } + return instance; + } + + @Override + public boolean canHandle(String geocode) { + return StringUtils.startsWithIgnoreCase(geocode, "GC"); + } + + @Override + public boolean supportsRefreshCache(cgCache cache) { + return true; + } + + @Override + public String getCacheUrl(cgCache cache) { + // it would also be possible to use "http://www.geocaching.com/seek/cache_details.aspx?wp=" + cache.getGeocode(); + return "http://coord.info/" + cache.getGeocode(); + } + + @Override + public boolean supportsWatchList() { + return true; + } + + @Override + public boolean supportsLogging() { + return true; + } + + @Override + public String getName() { + return "GeoCaching.com"; + } + + @Override + public String getHost() { + return "www.geocaching.com"; + } + + @Override + public boolean supportsUserActions() { + return true; + } + + @Override + public boolean supportsCachesAround() { + return true; + } + + @Override + public SearchResult searchByGeocode(final String geocode, final String guid, final cgeoapplication app, final CancellableHandler handler) { + + if (app == null) { + Log.e(Settings.tag, "cgeoBase.searchByGeocode: No application found"); + return null; + } + + final Parameters params = new Parameters("decrypt", "y"); + if (StringUtils.isNotBlank(geocode)) { + params.put("wp", geocode); + } else if (StringUtils.isNotBlank(guid)) { + params.put("guid", guid); + } + params.put("log", "y"); + params.put("numlogs", String.valueOf(GCConstants.NUMBER_OF_LOGS)); + + cgBase.sendLoadProgressDetail(handler, R.string.cache_dialog_loading_details_status_loadpage); + + final String page = cgBase.requestLogged("http://www.geocaching.com/seek/cache_details.aspx", params, false, false, false); + + if (StringUtils.isEmpty(page)) { + SearchResult search = new SearchResult(); + if (app.isThere(geocode, guid, true, false)) { + if (StringUtils.isBlank(geocode) && StringUtils.isNotBlank(guid)) { + Log.i(Settings.tag, "Loading old cache from cache."); + + search.addGeocode(app.getGeocode(guid)); + } else { + search.addGeocode(geocode); + } + search.error = StatusCode.NO_ERROR; + return search; + } + + Log.e(Settings.tag, "cgeoBase.searchByGeocode: No data from server"); + search.error = StatusCode.COMMUNICATION_ERROR; + return search; + } + + final SearchResult searchResult = cgBase.parseCache(page, handler); + + if (searchResult == null || CollectionUtils.isEmpty(searchResult.getGeocodes())) { + Log.e(Settings.tag, "cgeoBase.searchByGeocode: No cache parsed"); + return searchResult; + } + + SearchResult search = searchResult.filterSearchResults(false, false, Settings.getCacheType()); + + return search; + } + + @Override + public SearchResult searchByCoordinate(Geopoint center) { + // TODO Auto-generated method stub + return super.searchByCoordinate(center); + } + + @Override + public SearchResult searchByViewport(Viewport viewport, String[] tokens) { + return GCBase.searchByViewport(viewport, tokens); + } + + @Override + public boolean isZippedGPXFile(final String fileName) { + return gpxZipFilePattern.matcher(fileName).matches(); + } + + @Override + public boolean isReliableLatLon(boolean cacheHasReliableLatLon) { + return cacheHasReliableLatLon; + } + + @Override + public String[] getTokens() { + return GCBase.getTokens(); + } +} diff --git a/main/src/cgeo/geocaching/connector/gc/GCConstants.java b/main/src/cgeo/geocaching/connector/gc/GCConstants.java new file mode 100644 index 0000000..b166d95 --- /dev/null +++ b/main/src/cgeo/geocaching/connector/gc/GCConstants.java @@ -0,0 +1,158 @@ +package cgeo.geocaching.connector.gc; + +import java.util.regex.Pattern; + +/** + * These patterns have been optimized for speed. Improve them only if you can prove + * that *YOUR* pattern is faster. Use RegExRealPerformanceTest to show. + * + * For further information about patterns have a look at + * http://download.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html + * + * @author blafoo + */ +public final class GCConstants { + + /** Live Map */ + public final static String URL_LIVE_MAP = "http://www.geocaching.com/map/default.aspx"; + /** Caches in a tile */ + public final static String URL_MAP_INFO = "http://www.geocaching.com/map/map.info"; + /** Tile itself */ + public final static String URL_MAP_TILE = "http://www.geocaching.com/map/map.tile"; + + /** + * Patterns for parsing the result of a (detailed) search + */ + public final static Pattern PATTERN_HINT = Pattern.compile("
    ]*>(.*?)
    "); + public final static Pattern PATTERN_DESC = Pattern.compile("(.*?)[^<]*
    [^<]*

    [^<]*

    [^<]*

    [^<]*\\W*Additional Hints"); + public final static Pattern PATTERN_SHORTDESC = Pattern.compile("(.*?)[^\\w^<]*

"); + public final static Pattern PATTERN_GEOCODE = Pattern.compile("[^<]*]*>[^S]*Size[^:]*:[^<]*]*>[^<]*\"\\w+:]*>[^<]*[^<]*[^<]*[^<]*

"); + public final static Pattern PATTERN_LATLON = Pattern.compile("]*>(.*?)"); + public final static Pattern PATTERN_LATLON_ORIG = Pattern.compile("\\{\"isUserDefined\":true[^}]+?\"oldLatLngDisplay\":\"([^\"]+)\"\\}"); + public final static Pattern PATTERN_LOCATION = Pattern.compile(Pattern.quote("In ") + "(?:]*>)?(.*?)<"); + public final static Pattern PATTERN_PERSONALNOTE = Pattern.compile("

]*>(.*?)

"); + public final static Pattern PATTERN_NAME = Pattern.compile("(.*?)"); + public final static Pattern PATTERN_DIFFICULTY = Pattern.compile("]*>[^<]*]*>[^<]*]*>[^<]*
[^<]*

"); + public final static Pattern PATTERN_FOUND_ALTERNATIVE = Pattern.compile("
[^<]+([^<]+)"); + public final static Pattern PATTERN_TYPE = Pattern.compile("\"([^\"]+?)\"\\W*Hidden[\\s:]*([^<]+?)"); + public final static Pattern PATTERN_HIDDENEVENT = Pattern.compile("Event\\s*Date\\s*:\\s*([^<]+)", Pattern.DOTALL); + public final static Pattern PATTERN_FAVORITE = Pattern.compile("\"Remove"); + public final static Pattern PATTERN_FAVORITECOUNT = Pattern.compile("]+>[^<]*\\D*([0-9]+?)"); + public final static Pattern PATTERN_COUNTLOGS = Pattern.compile(""); + public final static Pattern PATTERN_LOGBOOK = Pattern.compile("initalLogs = (\\{.+\\});"); + /** Two groups ! */ + public final static Pattern PATTERN_COUNTLOG = Pattern.compile("]+> (\\d*[,.]?\\d+)"); + public static final Pattern PATTERN_PREMIUMMEMBERS = Pattern.compile("

This is a Premium Member Only cache.

"); + public final static Pattern PATTERN_ATTRIBUTES = Pattern.compile("

[^<]*]+>\\W*Attributes[^<]*

[^<]*
((?:[^<]*\"[^\"]+\"[^]*>)+?)[^<]*\\s+((?:]+>]+>[^<]+
(?:[^<]+

)?)+)\\s+

"); + public final static Pattern PATTERN_SPOILERSINSIDE = Pattern.compile("]+>]+>([^<]+)
(?:([^<]+)

)?"); + public final static Pattern PATTERN_INVENTORY = Pattern.compile("\\W*Inventory[^<]*[^<]*[^<]*
([^<]*
    (([^<]*
  • [^<]*]*>[^<]*]*>[^<]*[^<]+<\\/span>[^<]*<\\/a>[^<]*<\\/li>)+)[^<]*<\\/ul>)?"); + public final static Pattern PATTERN_INVENTORYINSIDE = Pattern.compile("[^<]*
  • [^<]*]*>[^<]*]*>[^<]*([^<]+)<\\/span>[^<]*<\\/a>[^<]*<\\/li>"); + public final static Pattern PATTERN_WATCHLIST = Pattern.compile("icon_stop_watchlist.gif"); + + // Info box top-right + public static final Pattern PATTERN_LOGIN_NAME = Pattern.compile("\"SignedInProfileLink\">([^<]+)"); + public static final Pattern PATTERN_MEMBER_STATUS = Pattern.compile("([^<]+)"); + /** Use replaceAll("[,.]","") on the resulting string before converting to an int */ + public static final Pattern PATTERN_CACHES_FOUND = Pattern.compile("title=\"Caches Found\"[\\s\\w=\"/.]*/>\\s*([\\d,.]+)"); + public static final Pattern PATTERN_AVATAR_IMAGE_PROFILE_PAGE = Pattern.compile("]*\\salt=\"Avatar\""); + public static final Pattern PATTERN_LOGIN_NAME_LOGIN_PAGE = Pattern.compile("You are logged in as[^<]*]*>([^<]+)[^<]*"); + public static final Pattern PATTERN_CUSTOMDATE = Pattern.compile("
  • ([^<]+)[^<]*]+>[^<]*\"([^\"]+)\"]*>[^<]*"); + public final static Pattern PATTERN_SEARCH_GUIDANDDISABLED = Pattern.compile("]*>[^<]*[^<]*([^<]*)?([^<]*)([^<]*)?[^<]+
    ([^<]*)]+>([^<]*)([^<]*]+>)?[^<]*
    [^<]*"); + /** Two groups **/ + public final static Pattern PATTERN_SEARCH_TRACKABLES = Pattern.compile("]*>(.*)"); + /** Second group used */ + public final static Pattern PATTERN_SEARCH_TRACKABLESINSIDE = Pattern.compile("(\"([^\"]+)\"[^<]*)"); + public final static Pattern PATTERN_SEARCH_DIRECTION = Pattern.compile("]*>"); + public final static Pattern PATTERN_SEARCH_GEOCODE = Pattern.compile("\\|\\W*(GC[0-9A-Z]+)[^\\|]*\\|"); + public final static Pattern PATTERN_SEARCH_ID = Pattern.compile("name=\"CID\"[^v]*value=\"([0-9]+)\""); + public final static Pattern PATTERN_SEARCH_FAVORITE = Pattern.compile("([0-9]+)"); + public final static Pattern PATTERN_SEARCH_TOTALCOUNT = Pattern.compile("Total Records[^<]*(\\d+)<\\/b>"); + public final static Pattern PATTERN_SEARCH_RECAPTCHA = Pattern.compile("]*src=\"[^\"]*/recaptcha/api/challenge\\?k=([^\"]+)\"[^>]*>"); + public final static Pattern PATTERN_SEARCH_RECAPTCHACHALLENGE = Pattern.compile("challenge : '([^']+)'"); + + /** + * Patterns for waypoints + */ + public final static Pattern PATTERN_WPTYPE = Pattern.compile("\\/wpttypes\\/sm\\/(.+)\\.jpg"); + public final static Pattern PATTERN_WPPREFIXORLOOKUPORLATLON = Pattern.compile(">([^<]*<[^>]+>)?([^<]+)(<[^>]+>[^<]*)?<\\/td>"); + public final static Pattern PATTERN_WPNAME = Pattern.compile(">[^<]*]+>([^<]*)<\\/a>"); + public final static Pattern PATTERN_WPNOTE = Pattern.compile("colspan=\"6\">(.*)<\\/td>"); + + /** + * Patterns for different purposes + */ + /** replace linebreak and paragraph tags */ + public final static Pattern PATTERN_LINEBREAK = Pattern.compile("<(br|p)[^>]*>"); + public final static Pattern PATTERN_TYPEBOX = Pattern.compile("", Pattern.CASE_INSENSITIVE); + public final static Pattern PATTERN_TYPE2 = Pattern.compile("[^<]+", Pattern.CASE_INSENSITIVE); + // FIXME: pattern is over specified + public final static Pattern PATTERN_TRACKABLE = Pattern.compile("]*>" + + "[^<]*[^<]*([A-Z0-9]+)[^<]*[^<]*([^<]+)[^<]*" + + "[^<]*[^<]*[^<]*", Pattern.CASE_INSENSITIVE); + public final static Pattern PATTERN_MAINTENANCE = Pattern.compile("]*>([^<]*]*>)?([^<]+)([^<]*)?", Pattern.CASE_INSENSITIVE); + public final static Pattern PATTERN_OK1 = Pattern.compile("]*>[^<]*]*>[^<]*[^<]*", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); + public final static Pattern PATTERN_OK2 = Pattern.compile("
    ", Pattern.CASE_INSENSITIVE); + public final static Pattern PATTERN_VIEWSTATEFIELDCOUNT = Pattern.compile("id=\"__VIEWSTATEFIELDCOUNT\"[^(value)]+value=\"(\\d+)\"[^>]+>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); + public final static Pattern PATTERN_VIEWSTATES = Pattern.compile("id=\"__VIEWSTATE(\\d*)\"[^(value)]+value=\"([^\"]+)\"[^>]+>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); + public final static Pattern PATTERN_USERTOKEN2 = Pattern.compile("userToken\\s*=\\s*'([^']+)'"); + + /** + * Patterns for GC and TB codes + */ + public final static Pattern PATTERN_GC_CODE = Pattern.compile("GC[0-9A-Z]*", Pattern.CASE_INSENSITIVE); + public final static Pattern PATTERN_TB_CODE = Pattern.compile("TB[0-9A-Z]*", Pattern.CASE_INSENSITIVE); + + /** Live Map since 14.02.2012 */ + public final static Pattern PATTERN_USERSESSION = Pattern.compile("UserSession\\('([^']+)'"); + public final static Pattern PATTERN_SESSIONTOKEN = Pattern.compile("sessionToken:'([^']+)'"); + /** Number of logs to retrieve from GC.com */ + public final static int NUMBER_OF_LOGS = 35; + + private GCConstants() { + // this class shall not have instances + } +} diff --git a/main/src/cgeo/geocaching/geopoint/DistanceParser.java b/main/src/cgeo/geocaching/geopoint/DistanceParser.java index 565382c..5f02895 100644 --- a/main/src/cgeo/geocaching/geopoint/DistanceParser.java +++ b/main/src/cgeo/geocaching/geopoint/DistanceParser.java @@ -35,12 +35,12 @@ public final class DistanceParser { return value; } if (unit.equals("yd")) { - return value * IConversion.yards2km; + return value * IConversion.YARDS_TO_KILOMETER; } if (unit.equals("mi")) { - return value * IConversion.miles2km; + return value * IConversion.MILES_TO_KILOMETER; } - return value * IConversion.feet2km; + return value * IConversion.FEET_TO_KILOMETER; } } diff --git a/main/src/cgeo/geocaching/geopoint/HumanDistance.java b/main/src/cgeo/geocaching/geopoint/HumanDistance.java index 7ae2684..278bb7b 100644 --- a/main/src/cgeo/geocaching/geopoint/HumanDistance.java +++ b/main/src/cgeo/geocaching/geopoint/HumanDistance.java @@ -23,7 +23,7 @@ public class HumanDistance { return String.format("%.2f", Double.valueOf(Math.round(distanceKilometers * 1000.0 * 100.0) / 100.0)) + " m"; } } else { - final float miles = distanceKilometers / IConversion.miles2km; + final float miles = distanceKilometers / IConversion.MILES_TO_KILOMETER; if (distanceKilometers > 100) { return String.format("%d", Math.round(miles)) + " mi"; } else if (distanceKilometers > 0.5) { diff --git a/main/src/cgeo/geocaching/geopoint/IConversion.java b/main/src/cgeo/geocaching/geopoint/IConversion.java index 1a2270d..b1cbffd 100644 --- a/main/src/cgeo/geocaching/geopoint/IConversion.java +++ b/main/src/cgeo/geocaching/geopoint/IConversion.java @@ -1,7 +1,13 @@ package cgeo.geocaching.geopoint; public interface IConversion { - public static final float miles2km = 1.609344f; - public static final float feet2km = 0.0003048f; - public static final float yards2km = 0.0009144f; + public static final float MILES_TO_KILOMETER = 1.609344f; + public static final float FEET_TO_KILOMETER = 0.0003048f; + public static final float YARDS_TO_KILOMETER = 0.0009144f; + /** + * Factor used to calculate distance from meters to foot; + *

    + * ft = m * METERS_TO_FEET; + */ + public static final double METERS_TO_FEET = 3.2808399d; } diff --git a/main/src/cgeo/geocaching/maps/ScaleOverlay.java b/main/src/cgeo/geocaching/maps/ScaleOverlay.java index 9152cae..f43ba25 100644 --- a/main/src/cgeo/geocaching/maps/ScaleOverlay.java +++ b/main/src/cgeo/geocaching/maps/ScaleOverlay.java @@ -86,7 +86,7 @@ public class ScaleOverlay implements GeneralOverlay { units = "m"; } } else { - distance /= IConversion.miles2km; + distance /= IConversion.MILES_TO_KILOMETER; if (distance > 100) { // 100+ mi > 1xx mi distanceRound = Math.floor(distance / 100) * 100; diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java index 1a53945..57e2a94 100644 --- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java +++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java @@ -1,7 +1,6 @@ package cgeo.geocaching.ui; import cgeo.geocaching.CacheDetailActivity; -import cgeo.geocaching.Constants; import cgeo.geocaching.R; import cgeo.geocaching.Settings; import cgeo.geocaching.cgBase; @@ -593,7 +592,7 @@ public class CacheListAdapter extends ArrayAdapter { infos.add(StringUtils.upperCase(cache.getGeocode())); infos.add(cgBase.formatDate(cache.getVisitedDate())); infos.add(cgBase.formatTime(cache.getVisitedDate())); - holder.info.setText(StringUtils.join(infos, Constants.SEPARATOR)); + holder.info.setText(StringUtils.join(infos, Formatter.SEPARATOR)); } else { ArrayList infos = new ArrayList(); if (StringUtils.isNotBlank(cache.getGeocode())) { @@ -619,7 +618,7 @@ public class CacheListAdapter extends ArrayAdapter { if (cacheListType != CacheListType.OFFLINE && cacheListType != CacheListType.HISTORY && cache.getListId() > 0) { infos.add(res.getString(R.string.cache_offline)); } - holder.info.setText(StringUtils.join(infos, Constants.SEPARATOR)); + holder.info.setText(StringUtils.join(infos, Formatter.SEPARATOR)); } return v; diff --git a/main/src/cgeo/geocaching/ui/Formatter.java b/main/src/cgeo/geocaching/ui/Formatter.java new file mode 100644 index 0000000..661a9a0 --- /dev/null +++ b/main/src/cgeo/geocaching/ui/Formatter.java @@ -0,0 +1,8 @@ +package cgeo.geocaching.ui; + +public interface Formatter { + + /** Text separator used for formatting texts */ + public static final String SEPARATOR = " · "; + +} diff --git a/main/src/cgeo/geocaching/utils/LogTemplateProvider.java b/main/src/cgeo/geocaching/utils/LogTemplateProvider.java index bc9b448..522bbf4 100644 --- a/main/src/cgeo/geocaching/utils/LogTemplateProvider.java +++ b/main/src/cgeo/geocaching/utils/LogTemplateProvider.java @@ -1,9 +1,9 @@ package cgeo.geocaching.utils; -import cgeo.geocaching.GCConstants; import cgeo.geocaching.R; import cgeo.geocaching.Settings; import cgeo.geocaching.cgBase; +import cgeo.geocaching.connector.gc.GCConstants; import org.apache.commons.lang3.StringUtils; -- cgit v1.1