6 |
import android.app.ProgressDialog; |
import android.app.ProgressDialog; |
7 |
import android.content.DialogInterface; |
import android.content.DialogInterface; |
8 |
import android.content.Intent; |
import android.content.Intent; |
9 |
|
import android.os.AsyncTask; |
10 |
import android.os.Bundle; |
import android.os.Bundle; |
11 |
import android.os.Handler; |
import android.os.Handler; |
12 |
import android.os.Message; |
import android.os.Message; |
25 |
/** Called when the activity is first created. */ |
/** Called when the activity is first created. */ |
26 |
ProgressDialog dialog; |
ProgressDialog dialog; |
27 |
StationLocator locator = null; |
StationLocator locator = null; |
28 |
|
LocatorTask locatorTask = new LocatorTask(); |
29 |
|
|
30 |
boolean isRunning; |
boolean isRunning; |
31 |
|
|
35 |
super.onCreate(savedInstanceState); |
super.onCreate(savedInstanceState); |
36 |
setContentView(R.layout.main); |
setContentView(R.layout.main); |
37 |
|
|
38 |
|
//StationLocator.injectMockLocation(this); |
39 |
|
|
40 |
adapter = new StationListAdapter(this); |
adapter = new StationListAdapter(this); |
41 |
setListAdapter(adapter); |
setListAdapter(adapter); |
42 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
|
|
|
66 |
@Override |
@Override |
67 |
protected void onPrepareDialog(int id, Dialog dialog) { |
protected void onPrepareDialog(int id, Dialog dialog) { |
68 |
super.onPrepareDialog(id, dialog); |
super.onPrepareDialog(id, dialog); |
73 |
} |
} |
74 |
} |
} |
75 |
|
|
|
|
|
|
|
|
|
public void progressDialog() { |
|
|
dialog = new ProgressDialog(this); |
|
|
dialog.setMessage("Wait for location fix"); |
|
|
dialog.setCancelable(false); |
|
|
dialog.show(); |
|
|
} |
|
|
|
|
76 |
public void startLookup() { |
public void startLookup() { |
77 |
isRunning = true; |
isRunning = true; |
78 |
showDialog(DLG_PROGRESS); |
showDialog(DLG_PROGRESS); |
|
//progressDialog(); |
|
79 |
|
|
80 |
locator.locateStations(); |
locator.locateStations(); |
81 |
stationsFetched.sendEmptyMessageDelayed(FIXTIMEOUT, 20000); |
stationsFetched.sendEmptyMessageDelayed(FIXTIMEOUT, 20000); |
89 |
switch (msg.what) { |
switch (msg.what) { |
90 |
case GOTLOCATION: |
case GOTLOCATION: |
91 |
dialog.setMessage("Finding nearby stations"); |
dialog.setMessage("Finding nearby stations"); |
92 |
|
locatorTask.execute(); |
93 |
break; |
break; |
94 |
case GOTSTATIONLIST: |
case GOTSTATIONLIST: |
95 |
dialog.dismiss(); |
dialog.dismiss(); |
146 |
.show(); |
.show(); |
147 |
|
|
148 |
} |
} |
149 |
|
|
150 |
|
class LocatorTask extends AsyncTask<Void,Void,Void> { |
151 |
|
@Override |
152 |
|
protected void onPreExecute() { |
153 |
|
super.onPreExecute(); |
154 |
|
} |
155 |
|
|
156 |
|
@Override |
157 |
|
protected Void doInBackground(Void... params) { |
158 |
|
locator.findNearestStations(); |
159 |
|
return null; |
160 |
|
} |
161 |
|
|
162 |
|
@Override |
163 |
|
protected void onPostExecute(Void result) { |
164 |
|
super.onPostExecute(result); |
165 |
|
} |
166 |
|
} |
167 |
} |
} |