diff options
author | Samuel Tardieu <sam@rfc1149.net> | 2011-11-07 18:21:19 +0100 |
---|---|---|
committer | Samuel Tardieu <sam@rfc1149.net> | 2011-11-07 18:35:29 +0100 |
commit | 3668637ef8de16add92db0f6a15282fc23282ba4 (patch) | |
tree | d98475917ef39f3ef923af01babde43bc3295daa /main/src/cgeo/geocaching/cgGeo.java | |
parent | 48a1073edac0a3ed8296c38abcd421381710c47a (diff) | |
download | cgeo-3668637ef8de16add92db0f6a15282fc23282ba4.zip cgeo-3668637ef8de16add92db0f6a15282fc23282ba4.tar.gz cgeo-3668637ef8de16add92db0f6a15282fc23282ba4.tar.bz2 |
Use a separate and unique thread for Go4Cache
This change creates a new Go4Cache thread which is started only
when the user opts in in sending their position to go4cache.com.
Instead of creating a new thread for every update, the same
thread is reused and orders are given through a one-position queue.
Diffstat (limited to 'main/src/cgeo/geocaching/cgGeo.java')
-rw-r--r-- | main/src/cgeo/geocaching/cgGeo.java | 61 |
1 files changed, 3 insertions, 58 deletions
diff --git a/main/src/cgeo/geocaching/cgGeo.java b/main/src/cgeo/geocaching/cgGeo.java index dfe6852..180a7a4 100644 --- a/main/src/cgeo/geocaching/cgGeo.java +++ b/main/src/cgeo/geocaching/cgGeo.java @@ -1,9 +1,6 @@ package cgeo.geocaching; import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.utils.CryptUtils; - -import org.apache.commons.lang3.StringUtils; import android.content.Context; import android.content.SharedPreferences; @@ -16,7 +13,6 @@ import android.os.Bundle; import android.util.Log; import java.util.Iterator; -import java.util.Locale; public class cgGeo { @@ -24,7 +20,6 @@ public class cgGeo { private cgeoapplication app = null; private LocationManager geoManager = null; private cgUpdateLoc geoUpdate = null; - private cgBase base = null; private SharedPreferences prefs = null; private cgeoGeoListener geoNetListener = null; private cgeoGeoListener geoGpsListener = null; @@ -34,8 +29,6 @@ public class cgGeo { private Location locGps = null; private Location locNet = null; private long locGpsLast = 0L; - private boolean g4cRunning = false; - private Geopoint lastGo4cacheCoords = null; public Location location = null; public int gps = -1; public Geopoint coordsNow = null; @@ -48,11 +41,10 @@ public class cgGeo { public Integer satellitesFixed = null; public double distanceNow = 0d; - public cgGeo(Context contextIn, cgeoapplication appIn, cgUpdateLoc geoUpdateIn, cgBase baseIn, int timeIn, int distanceIn) { + public cgGeo(Context contextIn, cgeoapplication appIn, cgUpdateLoc geoUpdateIn, int timeIn, int distanceIn) { context = contextIn; app = appIn; geoUpdate = geoUpdateIn; - base = baseIn; time = timeIn; distance = distanceIn; @@ -340,7 +332,7 @@ public class cgGeo { if (gps == 1) { // save travelled distance only when location is from GPS - if (coordsBefore != null && coordsNow != null) { + if (coordsBefore != null) { final float dst = coordsBefore.distanceTo(coordsNow); if (dst > 0.005) { @@ -358,54 +350,7 @@ public class cgGeo { } if (gps > -1) { - (new publishLoc()).start(); - } - } - - private class publishLoc extends Thread { - - private publishLoc() { - setPriority(Thread.MIN_PRIORITY); - } - - @Override - public void run() { - if (g4cRunning) { - return; - } - - if (Settings.isPublicLoc() && (lastGo4cacheCoords == null || coordsNow.distanceTo(lastGo4cacheCoords) > 0.75)) { - g4cRunning = true; - - String action = null; - if (app != null) { - action = app.getAction(); - } else { - action = ""; - } - - final String username = Settings.getUsername(); - if (username != null) { - final String latStr = String.format((Locale) null, "%.6f", coordsNow.getLatitude()); - final String lonStr = String.format((Locale) null, "%.6f", coordsNow.getLongitude()); - final Parameters params = new Parameters( - "u", username, - "lt", latStr, - "ln", lonStr, - "a", action, - "s", (CryptUtils.sha1(username + "|" + latStr + "|" + lonStr + "|" + action + "|" + CryptUtils.md5("carnero: developing your dreams"))).toLowerCase()); - if (base.version != null) { - params.put("v", base.version); - } - final String res = cgBase.getResponseData(cgBase.postRequest("http://api.go4cache.com/", params)); - - if (StringUtils.isNotBlank(res)) { - lastGo4cacheCoords = coordsNow; - } - } - } - - g4cRunning = false; + Go4Cache.signalCoordinates(app, coordsNow); } } |