--- android/TrainInfo/src/dk/thoerup/traininfo/LocationLookup.java 2010/09/27 18:26:09 1141 +++ android/TrainInfo/src/dk/thoerup/traininfo/LocationLookup.java 2010/09/28 14:58:45 1142 @@ -3,15 +3,18 @@ import java.util.List; import android.content.Context; +import android.location.GpsSatellite; +import android.location.GpsStatus; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; +import android.os.Message; import android.util.Log; -public class LocationLookup implements LocationListener{ +public class LocationLookup implements LocationListener, GpsStatus.Listener { LocationManager locManager; Context cntx; @@ -54,8 +57,11 @@ if (providers.size() > 0) { for(String provider : providers) { Log.i("Provider", ""+provider); - if (provider.equalsIgnoreCase("gps")) - hasGps = true; + if (provider.equalsIgnoreCase("gps")) { + locManager.addGpsStatusListener(this); + hasGps = true; + } + locManager.requestLocationUpdates(provider, 0, 0, this); Location tmpLastKnown = locManager.getLastKnownLocation(provider); if (tmpLastKnown != null) { @@ -64,7 +70,9 @@ } } else { // message that no suitable provider was found - hndl.sendEmptyMessage(StationList.NOPROVIDER); + //hndl.sendEmptyMessage(StationList.NOPROVIDER); + hndl.sendEmptyMessage(StationList.LookupStates.NOPROVIDER.ordinal()); + } } @Override @@ -87,7 +95,7 @@ } stopSearch(); - hndl.sendEmptyMessage(StationList.GOTLOCATION); + hndl.sendEmptyMessage(StationList.LookupStates.GOTLOCATION.ordinal()); } private void saveLastKnownLocation(Location loc) { @@ -104,6 +112,7 @@ { if (isSearching) { isSearching = false; + locManager.removeGpsStatusListener(this); locManager.removeUpdates(this); } } @@ -124,4 +133,22 @@ // TODO Auto-generated method stub } + + + @Override //GpsStatus.Listener + public void onGpsStatusChanged(int event) { + if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) { + int count = 0; + GpsStatus status = locManager.getGpsStatus(null); + for (GpsSatellite sat : status.getSatellites()) { + count ++; + } + + Message msg = new Message(); + msg.what = StationList.LookupStates.GPS_SAT_COUNT.ordinal(); + msg.arg1 = count; + hndl.sendMessage(msg); + } + + } }