3 |
import java.util.List; |
import java.util.List; |
4 |
|
|
5 |
import android.content.Context; |
import android.content.Context; |
6 |
|
import android.location.GpsSatellite; |
7 |
|
import android.location.GpsStatus; |
8 |
import android.location.Location; |
import android.location.Location; |
9 |
import android.location.LocationListener; |
import android.location.LocationListener; |
10 |
import android.location.LocationManager; |
import android.location.LocationManager; |
11 |
import android.os.Bundle; |
import android.os.Bundle; |
12 |
import android.os.Handler; |
import android.os.Handler; |
13 |
|
import android.os.Message; |
14 |
import android.util.Log; |
import android.util.Log; |
15 |
|
|
16 |
|
|
17 |
public class LocationLookup implements LocationListener{ |
public class LocationLookup implements LocationListener, GpsStatus.Listener { |
18 |
|
|
19 |
LocationManager locManager; |
LocationManager locManager; |
20 |
Context cntx; |
Context cntx; |
57 |
if (providers.size() > 0) { |
if (providers.size() > 0) { |
58 |
for(String provider : providers) { |
for(String provider : providers) { |
59 |
Log.i("Provider", ""+provider); |
Log.i("Provider", ""+provider); |
60 |
if (provider.equalsIgnoreCase("gps")) |
if (provider.equalsIgnoreCase("gps")) { |
61 |
hasGps = true; |
locManager.addGpsStatusListener(this); |
62 |
|
hasGps = true; |
63 |
|
} |
64 |
|
|
65 |
locManager.requestLocationUpdates(provider, 0, 0, this); |
locManager.requestLocationUpdates(provider, 0, 0, this); |
66 |
Location tmpLastKnown = locManager.getLastKnownLocation(provider); |
Location tmpLastKnown = locManager.getLastKnownLocation(provider); |
67 |
if (tmpLastKnown != null) { |
if (tmpLastKnown != null) { |
70 |
} |
} |
71 |
} else { |
} else { |
72 |
// message that no suitable provider was found |
// message that no suitable provider was found |
73 |
hndl.sendEmptyMessage(StationList.NOPROVIDER); |
//hndl.sendEmptyMessage(StationList.NOPROVIDER); |
74 |
|
hndl.sendEmptyMessage(StationList.LookupStates.NOPROVIDER.ordinal()); |
75 |
|
|
76 |
} |
} |
77 |
} |
} |
78 |
@Override |
@Override |
95 |
|
|
96 |
} |
} |
97 |
stopSearch(); |
stopSearch(); |
98 |
hndl.sendEmptyMessage(StationList.GOTLOCATION); |
hndl.sendEmptyMessage(StationList.LookupStates.GOTLOCATION.ordinal()); |
99 |
} |
} |
100 |
|
|
101 |
private void saveLastKnownLocation(Location loc) { |
private void saveLastKnownLocation(Location loc) { |
112 |
{ |
{ |
113 |
if (isSearching) { |
if (isSearching) { |
114 |
isSearching = false; |
isSearching = false; |
115 |
|
locManager.removeGpsStatusListener(this); |
116 |
locManager.removeUpdates(this); |
locManager.removeUpdates(this); |
117 |
} |
} |
118 |
} |
} |
133 |
// TODO Auto-generated method stub |
// TODO Auto-generated method stub |
134 |
|
|
135 |
} |
} |
136 |
|
|
137 |
|
|
138 |
|
@Override //GpsStatus.Listener |
139 |
|
public void onGpsStatusChanged(int event) { |
140 |
|
if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) { |
141 |
|
int count = 0; |
142 |
|
GpsStatus status = locManager.getGpsStatus(null); |
143 |
|
for (GpsSatellite sat : status.getSatellites()) { |
144 |
|
count ++; |
145 |
|
} |
146 |
|
|
147 |
|
Message msg = new Message(); |
148 |
|
msg.what = StationList.LookupStates.GPS_SAT_COUNT.ordinal(); |
149 |
|
msg.arg1 = count; |
150 |
|
hndl.sendMessage(msg); |
151 |
|
} |
152 |
|
|
153 |
|
} |
154 |
} |
} |