diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2012-03-04 07:28:42 +0100 |
---|---|---|
committer | Bananeweizen <bananeweizen@gmx.de> | 2012-03-04 07:28:42 +0100 |
commit | 00e4f99229d03d7db5ffd753e9e704e19abea3fa (patch) | |
tree | 584a05ec82c24ef86fcb0477b254c57aa28096d2 /main/src/cgeo/geocaching | |
parent | 32b4ba8e94c7aab44dab614b16cb203809d2a2a5 (diff) | |
download | cgeo-00e4f99229d03d7db5ffd753e9e704e19abea3fa.zip cgeo-00e4f99229d03d7db5ffd753e9e704e19abea3fa.tar.gz cgeo-00e4f99229d03d7db5ffd753e9e704e19abea3fa.tar.bz2 |
refactoring: move constants and classes to the packages they belong to
Diffstat (limited to 'main/src/cgeo/geocaching')
19 files changed, 68 insertions, 66 deletions
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; - * <p> - * ft = m * M2FT; - */ - public static final double M2FT = 3.2808399d; - -} 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<String> list = new ArrayList<String>(); 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/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/GCConnector.java b/main/src/cgeo/geocaching/connector/gc/GCConnector.java index 74dc7f5..9f71f62 100644 --- a/main/src/cgeo/geocaching/connector/GCConnector.java +++ b/main/src/cgeo/geocaching/connector/gc/GCConnector.java @@ -1,13 +1,12 @@ -package cgeo.geocaching.connector; +package cgeo.geocaching.connector.gc; -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.connector.AbstractConnector; import cgeo.geocaching.enumerations.StatusCode; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.Viewport; @@ -98,7 +97,7 @@ public class GCConnector extends AbstractConnector { params.put("guid", guid); } params.put("log", "y"); - params.put("numlogs", String.valueOf(Constants.NUMBER_OF_LOGS)); + params.put("numlogs", String.valueOf(GCConstants.NUMBER_OF_LOGS)); cgBase.sendLoadProgressDetail(handler, R.string.cache_dialog_loading_details_status_loadpage); diff --git a/main/src/cgeo/geocaching/GCConstants.java b/main/src/cgeo/geocaching/connector/gc/GCConstants.java index d884380..b166d95 100644 --- a/main/src/cgeo/geocaching/GCConstants.java +++ b/main/src/cgeo/geocaching/connector/gc/GCConstants.java @@ -1,4 +1,4 @@ -package cgeo.geocaching; +package cgeo.geocaching.connector.gc; import java.util.regex.Pattern; @@ -149,4 +149,10 @@ public final class GCConstants { /** 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; + * <p> + * 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<cgCache> { 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<String> infos = new ArrayList<String>(); if (StringUtils.isNotBlank(cache.getGeocode())) { @@ -619,7 +618,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { 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; |