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 |
|
|
45 |
startLookup(); |
startLookup(); |
46 |
} |
} |
47 |
|
|
48 |
|
@Override |
49 |
|
public void onSaveInstanceState(Bundle outState) |
50 |
|
{ |
51 |
|
if (dialog.isShowing()) |
52 |
|
dialog.dismiss(); |
53 |
|
} |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
@Override |
@Override |
96 |
switch (msg.what) { |
switch (msg.what) { |
97 |
case GOTLOCATION: |
case GOTLOCATION: |
98 |
dialog.setMessage("Finding nearby stations"); |
dialog.setMessage("Finding nearby stations"); |
99 |
|
locatorTask.execute(); |
100 |
break; |
break; |
101 |
case GOTSTATIONLIST: |
case GOTSTATIONLIST: |
102 |
dialog.dismiss(); |
dialog.dismiss(); |
104 |
break; |
break; |
105 |
case NOPROVIDER: |
case NOPROVIDER: |
106 |
dialog.dismiss(); |
dialog.dismiss(); |
107 |
showMessageBox("No Location provider enabled. Plase enabled gps."); |
showMessageBox("No location provider enabled. Plase enable gps."); |
108 |
break; |
break; |
109 |
case FIXTIMEOUT: |
case FIXTIMEOUT: |
110 |
dialog.dismiss(); |
dialog.dismiss(); |
153 |
.show(); |
.show(); |
154 |
|
|
155 |
} |
} |
156 |
|
|
157 |
|
class LocatorTask extends AsyncTask<Void,Void,Void> { |
158 |
|
@Override |
159 |
|
protected void onPreExecute() { |
160 |
|
super.onPreExecute(); |
161 |
|
} |
162 |
|
|
163 |
|
@Override |
164 |
|
protected Void doInBackground(Void... params) { |
165 |
|
locator.findNearestStations(); |
166 |
|
return null; |
167 |
|
} |
168 |
|
|
169 |
|
@Override |
170 |
|
protected void onPostExecute(Void result) { |
171 |
|
super.onPostExecute(result); |
172 |
|
} |
173 |
|
} |
174 |
} |
} |