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 |
|
|
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(); |
97 |
break; |
break; |
98 |
case NOPROVIDER: |
case NOPROVIDER: |
99 |
dialog.dismiss(); |
dialog.dismiss(); |
100 |
showMessageBox("No Location provider enabled. Plase enabled gps."); |
showMessageBox("No location provider enabled. Plase enable gps."); |
101 |
break; |
break; |
102 |
case FIXTIMEOUT: |
case FIXTIMEOUT: |
103 |
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 |
} |
} |