2 |
|
|
3 |
import java.util.ArrayList; |
import java.util.ArrayList; |
4 |
import java.util.List; |
import java.util.List; |
5 |
|
import java.util.Locale; |
6 |
|
|
7 |
import android.app.Dialog; |
import android.app.Dialog; |
8 |
import android.app.ListActivity; |
import android.app.ListActivity; |
9 |
import android.app.ProgressDialog; |
import android.app.ProgressDialog; |
10 |
import android.content.Intent; |
import android.content.Intent; |
11 |
|
import android.location.Address; |
12 |
|
import android.location.Geocoder; |
13 |
import android.os.AsyncTask; |
import android.os.AsyncTask; |
14 |
import android.os.Bundle; |
import android.os.Bundle; |
15 |
import android.os.Handler; |
import android.os.Handler; |
16 |
import android.os.Message; |
import android.os.Message; |
17 |
|
import android.util.Log; |
18 |
import android.view.View; |
import android.view.View; |
19 |
import android.widget.ListView; |
import android.widget.ListView; |
20 |
import dk.thoerup.traininfo.util.MessageBox; |
import dk.thoerup.traininfo.util.MessageBox; |
44 |
super.onCreate(savedInstanceState); |
super.onCreate(savedInstanceState); |
45 |
setContentView(R.layout.main); |
setContentView(R.layout.main); |
46 |
|
|
47 |
StationLocator.removeMockLocation(this); |
//StationLocator.removeMockLocation(this); |
48 |
//StationLocator.injectMockLocation(this); |
StationLocator.injectMockLocation(this); |
49 |
|
|
50 |
adapter = new StationListAdapter(this); |
adapter = new StationListAdapter(this); |
51 |
setListAdapter(adapter); |
setListAdapter(adapter); |
149 |
@Override |
@Override |
150 |
protected void onListItemClick(ListView l, View v, int position, long id) { |
protected void onListItemClick(ListView l, View v, int position, long id) { |
151 |
super.onListItemClick(l, v, position, id); |
super.onListItemClick(l, v, position, id); |
152 |
|
|
|
|
|
153 |
StationBean station = stations.get(position); |
StationBean station = stations.get(position); |
154 |
|
|
155 |
|
double latitude = station.getLatitude(); |
156 |
|
double longitude = station.getLongitude(); |
157 |
|
String addr = station.getAddress(); |
158 |
|
|
159 |
|
if (addr == null || addr.trim().equals("") ) |
160 |
|
addr = lookupAddress(latitude, longitude); |
161 |
|
|
162 |
|
|
163 |
Intent intent = new Intent(this, DepartureList.class); |
Intent intent = new Intent(this, DepartureList.class); |
164 |
intent.putExtra("name", station.getName()); |
intent.putExtra("name", station.getName()); |
165 |
intent.putExtra("address", station.getAddress()); |
intent.putExtra("address", addr); |
166 |
intent.putExtra("distance", station.getDistance()); |
intent.putExtra("distance", station.getDistance()); |
167 |
intent.putExtra("latitude", station.getLatitude()); |
intent.putExtra("latitude", latitude); |
168 |
intent.putExtra("longitude", station.getLongitude()); |
intent.putExtra("longitude", longitude); |
169 |
|
intent.putExtra("code", station.getCode()); |
170 |
startActivity(intent); |
startActivity(intent); |
171 |
} |
} |
172 |
|
|
173 |
|
String lookupAddress(double latitude, double longitude) { |
174 |
|
|
175 |
|
Geocoder coder = new Geocoder(this, new Locale("da")); |
176 |
|
StringBuilder sb = new StringBuilder(); |
177 |
|
Log.i("lookupaddr", "" + latitude + "/" + longitude); |
178 |
|
try { |
179 |
|
List<Address> addressList = coder.getFromLocation(latitude, longitude, 1); |
180 |
|
Address addr = addressList.get(0); |
181 |
|
|
182 |
|
|
183 |
|
int max = addr.getMaxAddressLineIndex(); |
184 |
|
for (int i=0; i<max; i++) { |
185 |
|
if (i>0) |
186 |
|
sb.append(", "); |
187 |
|
|
188 |
|
sb.append(addr.getAddressLine(i)); |
189 |
|
} |
190 |
|
|
191 |
|
|
192 |
|
} catch (Exception e) { |
193 |
|
Log.e("DepartureList", "geocoder failed", e); |
194 |
|
} |
195 |
|
|
196 |
|
return sb.toString(); |
197 |
|
} |
198 |
|
|
199 |
|
|
200 |
class LocatorTask extends AsyncTask<Void,Void,Void> { |
class LocatorTask extends AsyncTask<Void,Void,Void> { |
201 |
@Override |
@Override |