refactor location requesting

storage_ts_index
Georg Lukas 2011-03-06 17:00:59 +01:00
rodzic 16198e889f
commit 3240a5b309
1 zmienionych plików z 17 dodań i 8 usunięć

Wyświetl plik

@ -60,6 +60,20 @@ class AprsService extends Service with LocationListener {
Service.START_REDELIVER_INTENT Service.START_REDELIVER_INTENT
} }
def requestLocations(stay_on : Boolean) {
if (stay_on) {
locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER,
0, 0, this)
} else {
// get update interval and distance
val upd_int = prefs.getStringInt("interval", 10)
val upd_dist = prefs.getStringInt("distance", 10)
locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER,
upd_int * 60000, upd_dist * 1000, this)
}
}
def handleStart(i : Intent) { def handleStart(i : Intent) {
running = true running = true
@ -84,8 +98,7 @@ class AprsService extends Service with LocationListener {
locMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, locMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
upd_int * 60000, upd_dist * 1000, this) upd_int * 60000, upd_dist * 1000, this)
} }
locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, requestLocations(prefs.getString("gps_activation", "") == "always")
upd_int * 60000, upd_dist * 1000, this)
val callssid = AprsPacket.formatCallSsid(prefs.getCallsign(), prefs.getString("ssid", "")) val callssid = AprsPacket.formatCallSsid(prefs.getCallsign(), prefs.getString("ssid", ""))
val message = "%s: %d min, %d km".format(callssid, upd_int, upd_dist) val message = "%s: %d min, %d km".format(callssid, upd_int, upd_dist)
@ -121,8 +134,7 @@ class AprsService extends Service with LocationListener {
Log.d(TAG, "switching to fast lane"); Log.d(TAG, "switching to fast lane");
// request fast update rate // request fast update rate
locMan.removeUpdates(this); locMan.removeUpdates(this);
locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, requestLocations(true)
0, 0, this)
handler.postDelayed({ speedBearingEnd(true) }, 30000) handler.postDelayed({ speedBearingEnd(true) }, 30000)
} }
@ -137,10 +149,7 @@ class AprsService extends Service with LocationListener {
awaitingSpdCourse = null awaitingSpdCourse = null
// reset update speed // reset update speed
locMan.removeUpdates(this); locMan.removeUpdates(this);
val upd_int = prefs.getString("interval", "10").toInt requestLocations(prefs.getString("gps_activation", "") == "always")
val upd_dist = prefs.getString("distance", "10").toInt
locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER,
upd_int, upd_dist, this)
} }
def checkSpeedBearing(location : Location) : Boolean = { def checkSpeedBearing(location : Location) : Boolean = {