1 |
package dk.thoerup.traininfo; |
package dk.thoerup.traininfo; |
2 |
|
|
|
import java.util.ArrayList; |
|
3 |
import java.util.List; |
import java.util.List; |
4 |
|
|
|
import org.json.JSONArray; |
|
|
import org.json.JSONObject; |
|
|
|
|
5 |
import android.content.Context; |
import android.content.Context; |
6 |
import android.location.Criteria; |
import android.location.Criteria; |
7 |
import android.location.Location; |
import android.location.Location; |
8 |
import android.location.LocationListener; |
import android.location.LocationListener; |
9 |
import android.location.LocationManager; |
import android.location.LocationManager; |
|
import android.location.LocationProvider; |
|
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; |
13 |
import dk.thoerup.traininfo.provider.ProviderFactory; |
import dk.thoerup.traininfo.provider.ProviderFactory; |
14 |
import dk.thoerup.traininfo.provider.StationProvider; |
import dk.thoerup.traininfo.provider.StationProvider; |
|
import dk.thoerup.traininfo.util.DownloadUtil; |
|
15 |
|
|
16 |
public class StationLocator implements LocationListener{ |
public class StationLocator implements LocationListener{ |
17 |
|
|
19 |
Context cntx; |
Context cntx; |
20 |
Handler hndl; |
Handler hndl; |
21 |
|
|
22 |
List<StationBean> stationList = new ArrayList<StationBean>(); |
StationProvider provider; |
|
|
|
|
|
|
23 |
Location savedLocation = null; |
Location savedLocation = null; |
24 |
|
|
25 |
public StationLocator(Context c, Handler h) { |
public StationLocator(Context c, Handler h) { |
26 |
cntx = c; |
cntx = c; |
27 |
hndl = h; |
hndl = h; |
28 |
|
|
29 |
|
provider = ProviderFactory.getStationProvider(); |
30 |
} |
} |
31 |
|
|
32 |
public List<StationBean> getStations() { |
public List<StationBean> getStations() { |
33 |
return stationList; |
return provider.getStations(); |
34 |
} |
} |
35 |
|
|
36 |
public void abortLocationListener() { |
public void abortLocationListener() { |
83 |
} |
} |
84 |
|
|
85 |
public void findNearestStations(Location location) { |
public void findNearestStations(Location location) { |
86 |
StationProvider prov = ProviderFactory.getStationProvider(); |
provider.lookupStations(location); |
|
prov.lookupStations(location); |
|
|
this.stationList = prov.getStations(); |
|
87 |
|
|
88 |
if (stationList.size() > 0) |
if ( provider.getStations().size() > 0) |
89 |
hndl.sendEmptyMessage(TrainInfoList.GOTSTATIONLIST); |
hndl.sendEmptyMessage(TrainInfoList.GOTSTATIONLIST); |
90 |
else |
else |
91 |
hndl.sendEmptyMessage(TrainInfoList.LOOKUPSTATIONFAILED); |
hndl.sendEmptyMessage(TrainInfoList.LOOKUPSTATIONFAILED); |