10 |
import android.os.Bundle; |
import android.os.Bundle; |
11 |
import android.os.Handler; |
import android.os.Handler; |
12 |
import android.util.Log; |
import android.util.Log; |
|
import dk.thoerup.traininfo.provider.ProviderFactory; |
|
|
import dk.thoerup.traininfo.provider.StationProvider; |
|
13 |
|
|
14 |
public class StationLocator implements LocationListener{ |
|
15 |
|
public class LocationLookup implements LocationListener{ |
16 |
|
|
17 |
LocationManager locManager; |
LocationManager locManager; |
18 |
Context cntx; |
Context cntx; |
19 |
Handler hndl; |
Handler hndl; |
20 |
|
|
|
StationProvider provider; |
|
21 |
Location savedLocation = null; |
Location savedLocation = null; |
22 |
|
|
23 |
boolean hasGps; |
boolean hasGps; |
24 |
|
|
25 |
public StationLocator(Context c, Handler h) { |
public LocationLookup(Context c, Handler h) { |
26 |
cntx = c; |
cntx = c; |
27 |
hndl = h; |
hndl = h; |
28 |
|
|
|
provider = ProviderFactory.getStationProvider(); |
|
|
} |
|
|
|
|
|
public List<StationBean> getStations() { |
|
|
return provider.getStations(); |
|
29 |
} |
} |
30 |
|
|
31 |
public void abortLocationListener() { |
public void abortLocationListener() { |
35 |
public boolean hasLocation() { |
public boolean hasLocation() { |
36 |
return savedLocation != null; |
return savedLocation != null; |
37 |
} |
} |
38 |
|
|
39 |
|
public Location getLocation() |
40 |
|
{ |
41 |
|
return savedLocation; |
42 |
|
} |
43 |
|
|
44 |
public void locateStations() { |
public void locateStations() { |
45 |
hasGps = false; |
hasGps = false; |
78 |
locManager.removeUpdates(this); |
locManager.removeUpdates(this); |
79 |
hndl.sendEmptyMessage(TrainInfoList.GOTLOCATION); |
hndl.sendEmptyMessage(TrainInfoList.GOTLOCATION); |
80 |
} |
} |
81 |
|
/* |
82 |
public void findNearestStations() { |
|
|
findNearestStations(savedLocation); |
|
|
} |
|
|
|
|
83 |
public void findNearestStations(Location location) { |
public void findNearestStations(Location location) { |
84 |
provider.lookupStations(location); |
provider.lookupStations(location); |
85 |
|
|
87 |
hndl.sendEmptyMessage(TrainInfoList.GOTSTATIONLIST); |
hndl.sendEmptyMessage(TrainInfoList.GOTSTATIONLIST); |
88 |
else |
else |
89 |
hndl.sendEmptyMessage(TrainInfoList.LOOKUPSTATIONFAILED); |
hndl.sendEmptyMessage(TrainInfoList.LOOKUPSTATIONFAILED); |
90 |
} |
}*/ |
91 |
|
|
92 |
|
|
93 |
@Override |
@Override |
124 |
hillerod.setLatitude(55.929177); |
hillerod.setLatitude(55.929177); |
125 |
hillerod.setLongitude(12.308095); |
hillerod.setLongitude(12.308095); |
126 |
|
|
127 |
|
Location aarhus = new Location("gps"); //Aros |
128 |
|
aarhus.setLatitude(56.153828); |
129 |
|
aarhus.setLongitude(10.200369); |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
LocationManager lm = (LocationManager) cntx.getSystemService(Context.LOCATION_SERVICE); |
LocationManager lm = (LocationManager) cntx.getSystemService(Context.LOCATION_SERVICE); |
134 |
if (lm.getProvider("gps2") == null) |
if (lm.getProvider("gps2") == null) |
135 |
lm.addTestProvider("gps2", false, true, true, false, false, false, false, 0, Criteria.ACCURACY_FINE ); |
lm.addTestProvider("gps2", false, true, true, false, false, false, false, 0, Criteria.ACCURACY_FINE ); |
136 |
lm.setTestProviderEnabled("gps2", true); |
lm.setTestProviderEnabled("gps2", true); |
137 |
lm.setTestProviderLocation("gps2", hillerod); |
lm.setTestProviderLocation("gps2", kbh); |
138 |
} |
} |
139 |
|
|
140 |
public static void removeMockLocation(Context cntx) { |
public static void removeMockLocation(Context cntx) { |