From 01a6ad62356e5bb3d67b60508abed7771fbc2603 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sat, 12 Nov 2011 19:56:15 +0100 Subject: refactor Go4Cache code * renamed * encapsulated all fields * cached display strings from regex for better performance --- main/src/cgeo/geocaching/Go4Cache.java | 178 -------------------- main/src/cgeo/geocaching/cgGeo.java | 1 + main/src/cgeo/geocaching/cgUser.java | 13 -- main/src/cgeo/geocaching/go4cache/Go4Cache.java | 183 +++++++++++++++++++++ .../src/cgeo/geocaching/go4cache/Go4CacheUser.java | 91 ++++++++++ main/src/cgeo/geocaching/maps/CGeoMap.java | 14 +- .../cgeo/geocaching/maps/OtherCachersOverlay.java | 41 +---- .../geocaching/maps/google/GoogleMapFactory.java | 4 +- .../maps/google/GoogleOtherCachersOverlayItem.java | 12 +- .../geocaching/maps/interfaces/MapFactory.java | 4 +- .../interfaces/OtherCachersOverlayItemImpl.java | 4 +- .../maps/mapsforge/MapsforgeMapFactory.java | 4 +- .../MapsforgeOtherCachersOverlayItem.java | 12 +- 13 files changed, 308 insertions(+), 253 deletions(-) delete mode 100644 main/src/cgeo/geocaching/Go4Cache.java delete mode 100644 main/src/cgeo/geocaching/cgUser.java create mode 100644 main/src/cgeo/geocaching/go4cache/Go4Cache.java create mode 100644 main/src/cgeo/geocaching/go4cache/Go4CacheUser.java diff --git a/main/src/cgeo/geocaching/Go4Cache.java b/main/src/cgeo/geocaching/Go4Cache.java deleted file mode 100644 index d2ed032..0000000 --- a/main/src/cgeo/geocaching/Go4Cache.java +++ /dev/null @@ -1,178 +0,0 @@ -package cgeo.geocaching; - -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.GeopointFormatter.Format; -import cgeo.geocaching.geopoint.Viewport; -import cgeo.geocaching.utils.CryptUtils; - -import org.apache.commons.lang3.StringUtils; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import android.util.Log; - -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.ArrayBlockingQueue; - -/** - * - * Thread to send location information to go4cache.com. The singleton will be created - * only if, at any time, the user opts in to send this information. Then the same thread - * will take care of sending updated positions when available. - * - */ - -public class Go4Cache extends Thread { - - private static Go4Cache instance; - - final private ArrayBlockingQueue queue = new ArrayBlockingQueue(1); - final private cgeoapplication app; - final private cgBase base; - - private static Go4Cache getInstance(final cgeoapplication app) { - if (instance == null) { - synchronized(Go4Cache.class) { - instance = new Go4Cache(app); - instance.start(); - } - } - return instance; - } - - private Go4Cache(final cgeoapplication app) { - this.app = app; - base = cgBase.getInstance(app); - setPriority(Thread.MIN_PRIORITY); - } - - /** - * Send the coordinates to go4cache.com if the user opted in to do so. - * - * @param app - * the current application - * @param coords - * the current coordinates - */ - public static void signalCoordinates(final cgeoapplication app, final Geopoint coords) { - if (Settings.isPublicLoc()) { - getInstance(app).queue.offer(coords); - } - } - - @Override - public void run() { - Log.d(Settings.tag, "Go4Cache task started"); - Geopoint latestCoords = null; - String latestAction = null; - - try { - for (;;) { - final Geopoint currentCoords = queue.take(); - final String currentAction = app.getAction(); - - // If we are too close and we haven't changed our current action, no need - // to update our situation. - if (latestCoords != null && latestCoords.distanceTo(currentCoords) < 0.75 && StringUtils.equals(latestAction, currentAction)) { - continue; - } - - final String username = Settings.getUsername(); - if (StringUtils.isBlank(username)) { - continue; - } - - final String latStr = currentCoords.format(Format.LAT_DECDEGREE_RAW); - final String lonStr = currentCoords.format(Format.LON_DECDEGREE_RAW); - final Parameters params = new Parameters( - "u", username, - "lt", latStr, - "ln", lonStr, - "a", currentAction, - "s", (CryptUtils.sha1(username + "|" + latStr + "|" + lonStr + "|" + currentAction + "|" + CryptUtils.md5("carnero: developing your dreams"))).toLowerCase()); - if (base.version != null) { - params.put("v", base.version); - } - - cgBase.postRequest("http://api.go4cache.com/", params); - - // Update our coordinates even if the request was not succesful, as not to hammer the server - // with invalid requests for every new GPS position. - latestCoords = currentCoords; - latestAction = currentAction; - } - } catch (InterruptedException e) { - Log.e(Settings.tag, "Go4Cache.run: interrupted", e); - } - } - - /** - * Return an immutable list of users present in the given viewport. - * - * @param username - * the current username - * @param viewport - * the current viewport - * @return the list of users present in the viewport - */ - public static List getGeocachersInViewport(final String username, final Viewport viewport) { - final List users = new ArrayList(); - - if (username == null) { - return users; - } - - final Parameters params = new Parameters( - "u", username, - "ltm", viewport.bottomLeft.format(Format.LAT_DECDEGREE_RAW), - "ltx", viewport.topRight.format(Format.LAT_DECDEGREE_RAW), - "lnm", viewport.bottomLeft.format(Format.LON_DECDEGREE_RAW), - "lnx", viewport.topRight.format(Format.LON_DECDEGREE_RAW)); - - final String data = cgBase.getResponseData(cgBase.postRequest("http://api.go4cache.com/get.php", params)); - - if (StringUtils.isBlank(data)) { - Log.e(Settings.tag, "cgeoBase.getGeocachersInViewport: No data from server"); - return null; - } - - try { - final JSONArray usersData = new JSONObject(data).getJSONArray("users"); - final int count = usersData.length(); - for (int i = 0; i < count; i++) { - final JSONObject oneUser = usersData.getJSONObject(i); - users.add(parseUser(oneUser)); - } - } catch (Exception e) { - Log.e(Settings.tag, "cgBase.getGeocachersInViewport: " + e.toString()); - } - - return Collections.unmodifiableList(users); - } - - /** - * Parse user information from go4cache.com. - * - * @param oneUser - * a JSON object - * @return a cgCache user filled with information - * @throws JSONException - * if JSON could not be parsed correctly - * @throws ParseException - * if the date could not be parsed as expected - */ - private static cgUser parseUser(final JSONObject oneUser) throws JSONException, ParseException { - final cgUser user = new cgUser(); - final String located = oneUser.getString("located"); - user.located = cgBase.dateSqlIn.parse(located); - user.username = oneUser.getString("user"); - user.coords = new Geopoint(oneUser.getDouble("latitude"), oneUser.getDouble("longitude")); - user.action = oneUser.getString("action"); - user.client = oneUser.getString("client"); - return user; - } -} diff --git a/main/src/cgeo/geocaching/cgGeo.java b/main/src/cgeo/geocaching/cgGeo.java index 180a7a4..ebd6525 100644 --- a/main/src/cgeo/geocaching/cgGeo.java +++ b/main/src/cgeo/geocaching/cgGeo.java @@ -1,6 +1,7 @@ package cgeo.geocaching; import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.go4cache.Go4Cache; import android.content.Context; import android.content.SharedPreferences; diff --git a/main/src/cgeo/geocaching/cgUser.java b/main/src/cgeo/geocaching/cgUser.java deleted file mode 100644 index 2249133..0000000 --- a/main/src/cgeo/geocaching/cgUser.java +++ /dev/null @@ -1,13 +0,0 @@ -package cgeo.geocaching; - -import cgeo.geocaching.geopoint.Geopoint; - -import java.util.Date; - -public class cgUser { - public Date located = null; - public String username = null; - public Geopoint coords = null; - public String action = null; - public String client = null; -} diff --git a/main/src/cgeo/geocaching/go4cache/Go4Cache.java b/main/src/cgeo/geocaching/go4cache/Go4Cache.java new file mode 100644 index 0000000..ffd5974 --- /dev/null +++ b/main/src/cgeo/geocaching/go4cache/Go4Cache.java @@ -0,0 +1,183 @@ +package cgeo.geocaching.go4cache; + +import cgeo.geocaching.Parameters; +import cgeo.geocaching.Settings; +import cgeo.geocaching.cgBase; +import cgeo.geocaching.cgeoapplication; +import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.geopoint.GeopointFormatter.Format; +import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.utils.CryptUtils; + +import org.apache.commons.lang3.StringUtils; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import android.util.Log; + +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.concurrent.ArrayBlockingQueue; + +/** + * + * Thread to send location information to go4cache.com. The singleton will be created + * only if, at any time, the user opts in to send this information. Then the same thread + * will take care of sending updated positions when available. + * + */ + +public class Go4Cache extends Thread { + + private static Go4Cache instance; + + final private ArrayBlockingQueue queue = new ArrayBlockingQueue(1); + final private cgeoapplication app; + final private cgBase base; + + private static Go4Cache getInstance(final cgeoapplication app) { + if (null == instance) { + synchronized(Go4Cache.class) { + instance = new Go4Cache(app); + instance.start(); + } + } + return instance; + } + + private Go4Cache(final cgeoapplication app) { + super("Go4Cache"); + this.app = app; + base = cgBase.getInstance(app); + setPriority(Thread.MIN_PRIORITY); + } + + /** + * Send the coordinates to go4cache.com if the user opted in to do so. + * + * @param app + * the current application + * @param coords + * the current coordinates + */ + public static void signalCoordinates(final cgeoapplication app, final Geopoint coords) { + if (Settings.isPublicLoc()) { + getInstance(app).queue.offer(coords); + } + } + + @Override + public void run() { + Log.d(Settings.tag, "Go4Cache task started"); + Geopoint latestCoords = null; + String latestAction = null; + + try { + for (;;) { + final Geopoint currentCoords = queue.take(); + final String currentAction = app.getAction(); + + // If we are too close and we haven't changed our current action, no need + // to update our situation. + if (null != latestCoords && latestCoords.distanceTo(currentCoords) < 0.75 && StringUtils.equals(latestAction, currentAction)) { + continue; + } + + final String username = Settings.getUsername(); + if (StringUtils.isBlank(username)) { + continue; + } + + final String latStr = currentCoords.format(Format.LAT_DECDEGREE_RAW); + final String lonStr = currentCoords.format(Format.LON_DECDEGREE_RAW); + final Parameters params = new Parameters( + "u", username, + "lt", latStr, + "ln", lonStr, + "a", currentAction, + "s", (CryptUtils.sha1(username + "|" + latStr + "|" + lonStr + "|" + currentAction + "|" + CryptUtils.md5("carnero: developing your dreams"))).toLowerCase()); + if (null != base.version) { + params.put("v", base.version); + } + + cgBase.postRequest("http://api.go4cache.com/", params); + + // Update our coordinates even if the request was not successful, as not to hammer the server + // with invalid requests for every new GPS position. + latestCoords = currentCoords; + latestAction = currentAction; + } + } catch (InterruptedException e) { + Log.e(Settings.tag, "Go4Cache.run: interrupted", e); + } + } + + /** + * Return an immutable list of users present in the given viewport. + * + * @param username + * the current username + * @param viewport + * the current viewport + * @return the list of users present in the viewport + */ + public static List getGeocachersInViewport(final String username, final Viewport viewport) { + final List users = new ArrayList(); + + if (null == username) { + return users; + } + + final Parameters params = new Parameters( + "u", username, + "ltm", viewport.bottomLeft.format(Format.LAT_DECDEGREE_RAW), + "ltx", viewport.topRight.format(Format.LAT_DECDEGREE_RAW), + "lnm", viewport.bottomLeft.format(Format.LON_DECDEGREE_RAW), + "lnx", viewport.topRight.format(Format.LON_DECDEGREE_RAW)); + + final String data = cgBase.getResponseData(cgBase.postRequest("http://api.go4cache.com/get.php", params)); + + if (StringUtils.isBlank(data)) { + Log.e(Settings.tag, "cgeoBase.getGeocachersInViewport: No data from server"); + return null; + } + + try { + final JSONArray usersData = new JSONObject(data).getJSONArray("users"); + final int count = usersData.length(); + for (int i = 0; i < count; i++) { + final JSONObject oneUser = usersData.getJSONObject(i); + users.add(parseUser(oneUser)); + } + } catch (Exception e) { + Log.e(Settings.tag, "cgBase.getGeocachersInViewport: " + e.toString()); + } + + return Collections.unmodifiableList(users); + } + + /** + * Parse user information from go4cache.com. + * + * @param user + * a JSON object + * @return a cgCache user filled with information + * @throws JSONException + * if JSON could not be parsed correctly + * @throws ParseException + * if the date could not be parsed as expected + */ + private static Go4CacheUser parseUser(final JSONObject user) throws JSONException, ParseException { + final String located = user.getString("located"); + final Date userlocated = cgBase.dateSqlIn.parse(located); + final String username = user.getString("user"); + final Geopoint coords = new Geopoint(user.getDouble("latitude"), user.getDouble("longitude")); + final String action = user.getString("action"); + final String client = user.getString("client"); + return new Go4CacheUser(username, coords, userlocated, action, client); + } +} diff --git a/main/src/cgeo/geocaching/go4cache/Go4CacheUser.java b/main/src/cgeo/geocaching/go4cache/Go4CacheUser.java new file mode 100644 index 0000000..931bdaf --- /dev/null +++ b/main/src/cgeo/geocaching/go4cache/Go4CacheUser.java @@ -0,0 +1,91 @@ +package cgeo.geocaching.go4cache; + +import cgeo.geocaching.R; +import cgeo.geocaching.geopoint.Geopoint; + +import java.util.Date; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Go4CacheUser { + private static final Pattern patternGeocode = Pattern.compile("^(GC[A-Z0-9]+)(\\: ?(.+))?$", Pattern.CASE_INSENSITIVE); + + private final Date located; + private final String username; + private final Geopoint coords; + private final String action; + private final String client; + + private String actionForDisplay; + private String geocode; + + public Go4CacheUser(final String username, final Geopoint coords, final Date located, final String action, final String client) { + this.username = username; + this.coords = coords; + this.located = located; + this.action = action; + this.client = client; + } + + public Date getLocated() { + return located; + } + + public String getUsername() { + return username; + } + + public Geopoint getCoords() { + return coords; + } + + public int getIconId() { + if (null == client) { + return -1; + } + if (client.equalsIgnoreCase("c:geo")) { + return R.drawable.client_cgeo; + } else if (client.equalsIgnoreCase("preCaching")) { + return R.drawable.client_precaching; + } else if (client.equalsIgnoreCase("Handy Geocaching")) { + return R.drawable.client_handygeocaching; + } + return -1; + } + + private void getGeocodeAndAction() { + final Matcher matcherGeocode = patternGeocode.matcher(action.trim()); + + geocode = ""; + if (0 == action.length() || action.equalsIgnoreCase("pending")) { + actionForDisplay = "Looking around"; + } else if (action.equalsIgnoreCase("tweeting")) { + actionForDisplay = "Tweeting"; + } else if (matcherGeocode.find()) { + if (null != matcherGeocode.group(1)) { + geocode = matcherGeocode.group(1).trim().toUpperCase(); + } + if (null != matcherGeocode.group(3)) { + actionForDisplay = "Heading to " + geocode + " (" + matcherGeocode.group(3).trim() + ")"; + } else { + actionForDisplay = "Heading to " + geocode; + } + } else { + actionForDisplay = action; + } + } + + public String getAction() { + if (null == actionForDisplay) { + getGeocodeAndAction(); + } + return actionForDisplay; + } + + public String getGeocode() { + if (null == geocode) { + getGeocodeAndAction(); + } + return geocode; + } +} diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 59fcf8c..f59ddf0 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -1,6 +1,5 @@ package cgeo.geocaching.maps; -import cgeo.geocaching.Go4Cache; import cgeo.geocaching.R; import cgeo.geocaching.Settings; import cgeo.geocaching.Settings.mapSourceEnum; @@ -12,7 +11,6 @@ import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgSearch; import cgeo.geocaching.cgUpdateDir; import cgeo.geocaching.cgUpdateLoc; -import cgeo.geocaching.cgUser; import cgeo.geocaching.cgWaypoint; import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.cgeocaches; @@ -22,6 +20,8 @@ import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.WaypointType; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.go4cache.Go4Cache; +import cgeo.geocaching.go4cache.Go4CacheUser; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapActivityImpl; @@ -156,7 +156,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory /** List of caches in the viewport */ private List caches = new ArrayList(); /** List of users in the viewport */ - private List users = new ArrayList(); + private List users = new ArrayList(); private List coordinates = new ArrayList(); // storing for offline private ProgressDialog waitDialog = null; @@ -1529,9 +1529,9 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory */ private class DisplayUsersThread extends DoThread { - private List users = null; + private List users = null; - public DisplayUsersThread(List usersIn, long centerLatIn, long centerLonIn, long spanLatIn, long spanLonIn) { + public DisplayUsersThread(List usersIn, long centerLatIn, long centerLonIn, long spanLatIn, long spanLonIn) { super(centerLatIn, centerLonIn, spanLatIn, spanLonIn); setName("Display Users"); users = usersIn; @@ -1553,12 +1553,12 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory int counter = 0; OtherCachersOverlayItemImpl item = null; - for (cgUser userOne : users) { + for (Go4CacheUser userOne : users) { if (stop) { return; } - if (userOne.coords == null) { + if (userOne.getCoords() == null) { continue; } diff --git a/main/src/cgeo/geocaching/maps/OtherCachersOverlay.java b/main/src/cgeo/geocaching/maps/OtherCachersOverlay.java index 33274ba..8498b29 100644 --- a/main/src/cgeo/geocaching/maps/OtherCachersOverlay.java +++ b/main/src/cgeo/geocaching/maps/OtherCachersOverlay.java @@ -1,9 +1,8 @@ package cgeo.geocaching.maps; -import cgeo.geocaching.R; import cgeo.geocaching.Settings; -import cgeo.geocaching.cgUser; import cgeo.geocaching.cgeodetail; +import cgeo.geocaching.go4cache.Go4CacheUser; import cgeo.geocaching.maps.interfaces.ItemizedOverlayImpl; import cgeo.geocaching.maps.interfaces.MapProjectionImpl; import cgeo.geocaching.maps.interfaces.MapViewImpl; @@ -21,14 +20,11 @@ import android.util.Log; import java.util.ArrayList; import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; public class OtherCachersOverlay extends AbstractItemizedOverlay { private List items = new ArrayList(); private Context context = null; - private final Pattern patternGeocode = Pattern.compile("^(GC[A-Z0-9]+)(\\: ?(.+))?$", Pattern.CASE_INSENSITIVE); public OtherCachersOverlay(ItemizedOverlayImpl ovlImplIn, Context contextIn) { super(ovlImplIn); @@ -71,45 +67,20 @@ public class OtherCachersOverlay extends AbstractItemizedOverlay { } final OtherCachersOverlayItemImpl item = items.get(index); - final cgUser user = item.getUser(); + final Go4CacheUser user = item.getUser(); // set action - String action = null; - String geocode = null; - final Matcher matcherGeocode = patternGeocode.matcher(user.action.trim()); - - if (user.action.length() == 0 || user.action.equalsIgnoreCase("pending")) { - action = "Looking around"; - } else if (user.action.equalsIgnoreCase("tweeting")) { - action = "Tweeting"; - } else if (matcherGeocode.find()) { - if (matcherGeocode.group(1) != null) { - geocode = matcherGeocode.group(1).trim().toUpperCase(); - } - if (matcherGeocode.group(3) != null) { - action = "Heading to " + geocode + " (" + matcherGeocode.group(3).trim() + ")"; - } else { - action = "Heading to " + geocode; - } - } else { - action = user.action; - } + String action = user.getAction(); + String geocode = user.getGeocode(); // set icon - int icon = -1; - if (user.client.equalsIgnoreCase("c:geo")) { - icon = R.drawable.client_cgeo; - } else if (user.client.equalsIgnoreCase("preCaching")) { - icon = R.drawable.client_precaching; - } else if (user.client.equalsIgnoreCase("Handy Geocaching")) { - icon = R.drawable.client_handygeocaching; - } + int icon = user.getIconId(); final AlertDialog.Builder dialog = new AlertDialog.Builder(context); if (icon > -1) { dialog.setIcon(icon); } - dialog.setTitle(user.username); + dialog.setTitle(user.getUsername()); dialog.setMessage(action); dialog.setCancelable(true); if (StringUtils.isNotBlank(geocode)) { diff --git a/main/src/cgeo/geocaching/maps/google/GoogleMapFactory.java b/main/src/cgeo/geocaching/maps/google/GoogleMapFactory.java index 55f6837..d4ac68b 100644 --- a/main/src/cgeo/geocaching/maps/google/GoogleMapFactory.java +++ b/main/src/cgeo/geocaching/maps/google/GoogleMapFactory.java @@ -2,9 +2,9 @@ package cgeo.geocaching.maps.google; import cgeo.geocaching.R; import cgeo.geocaching.cgCoord; -import cgeo.geocaching.cgUser; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.go4cache.Go4CacheUser; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapFactory; @@ -43,7 +43,7 @@ public class GoogleMapFactory implements MapFactory { } @Override - public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context, cgUser userOne) { + public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context, Go4CacheUser userOne) { GoogleOtherCachersOverlayItem baseItem = new GoogleOtherCachersOverlayItem(context, userOne); return baseItem; } diff --git a/main/src/cgeo/geocaching/maps/google/GoogleOtherCachersOverlayItem.java b/main/src/cgeo/geocaching/maps/google/GoogleOtherCachersOverlayItem.java index f6fbcec..ac8e725 100644 --- a/main/src/cgeo/geocaching/maps/google/GoogleOtherCachersOverlayItem.java +++ b/main/src/cgeo/geocaching/maps/google/GoogleOtherCachersOverlayItem.java @@ -1,7 +1,7 @@ package cgeo.geocaching.maps.google; import cgeo.geocaching.R; -import cgeo.geocaching.cgUser; +import cgeo.geocaching.go4cache.Go4CacheUser; import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl; import com.google.android.maps.GeoPoint; @@ -12,10 +12,10 @@ import android.graphics.drawable.Drawable; public class GoogleOtherCachersOverlayItem extends OverlayItem implements OtherCachersOverlayItemImpl { private Context context = null; - private cgUser user = null; + private Go4CacheUser user = null; - public GoogleOtherCachersOverlayItem(Context contextIn, cgUser userIn) { - super(new GeoPoint(userIn.coords.getLatitudeE6(), userIn.coords.getLongitudeE6()), userIn.username, ""); + public GoogleOtherCachersOverlayItem(Context contextIn, Go4CacheUser userIn) { + super(new GeoPoint(userIn.getCoords().getLatitudeE6(), userIn.getCoords().getLongitudeE6()), userIn.getUsername(), ""); context = contextIn; user = userIn; @@ -25,7 +25,7 @@ public class GoogleOtherCachersOverlayItem extends OverlayItem implements OtherC public Drawable getMarker(int state) { Drawable marker = null; - if (user != null && user.located != null && user.located.getTime() >= (System.currentTimeMillis() - (20 * 60 * 1000))) { + if (user != null && user.getLocated() != null && user.getLocated().getTime() >= (System.currentTimeMillis() - (20 * 60 * 1000))) { marker = context.getResources().getDrawable(R.drawable.user_location_active); } else { marker = context.getResources().getDrawable(R.drawable.user_location); @@ -38,7 +38,7 @@ public class GoogleOtherCachersOverlayItem extends OverlayItem implements OtherC return marker; } - public cgUser getUser() { + public Go4CacheUser getUser() { return user; } } diff --git a/main/src/cgeo/geocaching/maps/interfaces/MapFactory.java b/main/src/cgeo/geocaching/maps/interfaces/MapFactory.java index 814703c..3bc6b8f 100644 --- a/main/src/cgeo/geocaching/maps/interfaces/MapFactory.java +++ b/main/src/cgeo/geocaching/maps/interfaces/MapFactory.java @@ -1,9 +1,9 @@ package cgeo.geocaching.maps.interfaces; import cgeo.geocaching.cgCoord; -import cgeo.geocaching.cgUser; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.go4cache.Go4CacheUser; import android.app.Activity; import android.content.Context; @@ -28,6 +28,6 @@ public interface MapFactory { public CachesOverlayItemImpl getCachesOverlayItem(final cgCoord coordinate, final CacheType type); public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context, - cgUser userOne); + Go4CacheUser userOne); } diff --git a/main/src/cgeo/geocaching/maps/interfaces/OtherCachersOverlayItemImpl.java b/main/src/cgeo/geocaching/maps/interfaces/OtherCachersOverlayItemImpl.java index 43fc58e..cc611ed 100644 --- a/main/src/cgeo/geocaching/maps/interfaces/OtherCachersOverlayItemImpl.java +++ b/main/src/cgeo/geocaching/maps/interfaces/OtherCachersOverlayItemImpl.java @@ -1,6 +1,6 @@ package cgeo.geocaching.maps.interfaces; -import cgeo.geocaching.cgUser; +import cgeo.geocaching.go4cache.Go4CacheUser; /** * Common functions of the provider-specific @@ -11,5 +11,5 @@ import cgeo.geocaching.cgUser; */ public interface OtherCachersOverlayItemImpl extends OverlayItemImpl { - public cgUser getUser(); + public Go4CacheUser getUser(); } diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapFactory.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapFactory.java index dabd91b..3499c1d 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapFactory.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapFactory.java @@ -2,9 +2,9 @@ package cgeo.geocaching.maps.mapsforge; import cgeo.geocaching.R; import cgeo.geocaching.cgCoord; -import cgeo.geocaching.cgUser; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.go4cache.Go4CacheUser; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapFactory; @@ -42,7 +42,7 @@ public class MapsforgeMapFactory implements MapFactory { } @Override - public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context, cgUser userOne) { + public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context, Go4CacheUser userOne) { MapsforgeOtherCachersOverlayItem baseItem = new MapsforgeOtherCachersOverlayItem(context, userOne); return baseItem; } diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlayItem.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlayItem.java index 6a83c16..f2cae3a 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlayItem.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlayItem.java @@ -1,7 +1,7 @@ package cgeo.geocaching.maps.mapsforge; import cgeo.geocaching.R; -import cgeo.geocaching.cgUser; +import cgeo.geocaching.go4cache.Go4CacheUser; import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl; import org.mapsforge.android.maps.GeoPoint; @@ -12,10 +12,10 @@ import android.graphics.drawable.Drawable; public class MapsforgeOtherCachersOverlayItem extends OverlayItem implements OtherCachersOverlayItemImpl { private Context context = null; - private cgUser user = null; + private Go4CacheUser user = null; - public MapsforgeOtherCachersOverlayItem(Context contextIn, cgUser userIn) { - super(new GeoPoint(userIn.coords.getLatitudeE6(), userIn.coords.getLongitudeE6()), userIn.username, ""); + public MapsforgeOtherCachersOverlayItem(Context contextIn, Go4CacheUser userIn) { + super(new GeoPoint(userIn.getCoords().getLatitudeE6(), userIn.getCoords().getLongitudeE6()), userIn.getUsername(), ""); context = contextIn; user = userIn; @@ -25,7 +25,7 @@ public class MapsforgeOtherCachersOverlayItem extends OverlayItem implements Oth public Drawable getMarker(int state) { Drawable marker = null; - if (user != null && user.located != null && user.located.getTime() >= (System.currentTimeMillis() - (20 * 60 * 1000))) { + if (user != null && user.getLocated() != null && user.getLocated().getTime() >= (System.currentTimeMillis() - (20 * 60 * 1000))) { marker = context.getResources().getDrawable(R.drawable.user_location_active); } else { marker = context.getResources().getDrawable(R.drawable.user_location); @@ -38,7 +38,7 @@ public class MapsforgeOtherCachersOverlayItem extends OverlayItem implements Oth return marker; } - public cgUser getUser() { + public Go4CacheUser getUser() { return user; } } -- cgit v1.1