50 |
import android.os.Message; |
import android.os.Message; |
51 |
import android.util.Log; |
import android.util.Log; |
52 |
import android.view.ContextMenu; |
import android.view.ContextMenu; |
53 |
|
import android.view.ContextMenu.ContextMenuInfo; |
54 |
import android.view.LayoutInflater; |
import android.view.LayoutInflater; |
55 |
import android.view.Menu; |
import android.view.Menu; |
56 |
import android.view.MenuItem; |
import android.view.MenuItem; |
57 |
import android.view.View; |
import android.view.View; |
|
import android.view.ContextMenu.ContextMenuInfo; |
|
58 |
import android.view.View.OnCreateContextMenuListener; |
import android.view.View.OnCreateContextMenuListener; |
59 |
import android.widget.AdapterView; |
import android.widget.AdapterView; |
60 |
import android.widget.EditText; |
import android.widget.EditText; |
61 |
import android.widget.ListView; |
import android.widget.ListView; |
62 |
import android.widget.Toast; |
import android.widget.Toast; |
63 |
import dk.thoerup.android.traininfo.common.StationBean; |
import dk.thoerup.android.traininfo.common.StationBean; |
64 |
import dk.thoerup.android.traininfo.common.StationBean.StationEntry; |
import dk.thoerup.android.traininfo.common.StationEntry; |
65 |
import dk.thoerup.traininfo.provider.ProviderFactory; |
import dk.thoerup.traininfo.provider.ProviderFactory; |
66 |
import dk.thoerup.traininfo.provider.StationProvider; |
import dk.thoerup.traininfo.provider.StationProvider; |
67 |
import dk.thoerup.traininfo.stationmap.GeoPair; |
import dk.thoerup.traininfo.stationmap.GeoPair; |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
public static final int OPTIONS_MAP = 2003; |
public static final int OPTIONS_MAP = 103; |
77 |
public static final int OPTIONS_GPSINFO = 2004; |
public static final int OPTIONS_GPSINFO = 104; |
78 |
|
|
79 |
public static final int DLG_PROGRESS = 3001; |
public static final int DLG_PROGRESS = 3001; |
80 |
public static final int DLG_STATIONNAME = 3002; |
public static final int DLG_STATIONNAME = 3002; |
231 |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
232 |
|
|
233 |
item = menu.add(0, OPTIONS_GPSINFO, 0, getString(stationlist_gpsinfo)); |
item = menu.add(0, OPTIONS_GPSINFO, 0, getString(stationlist_gpsinfo)); |
234 |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
item.setIcon(android.R.drawable.ic_menu_info_details); |
235 |
|
boolean hasLoc = (locationLookup.getLocation() != null); |
236 |
|
item.setEnabled(hasLoc); |
237 |
|
|
238 |
return true; |
return true; |
239 |
} |
} |
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
@Override |
@Override |
245 |
public boolean onOptionsItemSelected(MenuItem item) { |
public boolean onOptionsItemSelected(MenuItem item) { |
246 |
boolean retval = true; |
boolean retval = true; |
247 |
|
|
248 |
//TODO: Cleanup |
|
249 |
switch (item.getItemId()) { |
switch (item.getItemId()) { |
250 |
case OPTIONS_MAP: |
case OPTIONS_MAP: |
251 |
|
|
252 |
|
if ( stations == null || stations.entries == null || stations.entries.size() == 0 ) { |
253 |
|
Toast.makeText(this, "No stations to show on map", Toast.LENGTH_SHORT).show(); //TODO: Translate |
254 |
|
return true; |
255 |
|
} |
256 |
|
|
257 |
Intent intent = new Intent(this,StationMapView.class); |
Intent intent = new Intent(this,StationMapView.class); |
258 |
|
|
259 |
ArrayList<GeoPair> stationPoints = new ArrayList<GeoPair>(); |
ArrayList<GeoPair> stationPoints = new ArrayList<GeoPair>(); |
269 |
Location loc = locationLookup.getLocation(); |
Location loc = locationLookup.getLocation(); |
270 |
StringBuffer message = new StringBuffer(); |
StringBuffer message = new StringBuffer(); |
271 |
message.append( getString(stationlist_locationinfo) ).append(":\n"); |
message.append( getString(stationlist_locationinfo) ).append(":\n"); |
272 |
if (loc != null) { |
|
273 |
message.append( getString(stationlist_obtainedby) ).append( loc.getProvider() ).append("\n"); |
message.append( getString(stationlist_obtainedby) ).append( loc.getProvider() ).append("\n"); |
274 |
message.append( getString(stationlist_accuracy) ).append( (int)loc.getAccuracy()).append("m\n"); |
message.append( getString(stationlist_accuracy) ).append( (int)loc.getAccuracy()).append("m\n"); |
275 |
message.append( getString(stationlist_latitude) ).append( (float)loc.getLatitude()).append("\n"); |
message.append( getString(stationlist_latitude) ).append( (float)loc.getLatitude()).append("\n"); |
276 |
message.append( getString(stationlist_longitude) ).append( (float)loc.getLongitude() ).append("\n"); |
message.append( getString(stationlist_longitude) ).append( (float)loc.getLongitude() ).append("\n"); |
277 |
} else { |
|
|
message.append( getString(stationlist_nolocation) ); |
|
|
} |
|
278 |
|
|
279 |
MessageBox.showMessage(this, message.toString(), false); |
MessageBox.showMessage(this, message.toString(), false); |
280 |
break; |
break; |
469 |
|
|
470 |
|
|
471 |
if (locationLookup.elapsedTime() >= GPS_TIMEOUT_MS) { |
if (locationLookup.elapsedTime() >= GPS_TIMEOUT_MS) { |
472 |
try { |
dismissDialog(DLG_PROGRESS); |
473 |
dismissDialog(DLG_PROGRESS); |
|
|
} catch (IllegalArgumentException ex) { |
|
|
// I get stacktraces that reports an exception is thrown here - |
|
|
// but i can not recreate the situation that causes said exception |
|
|
Log.e("TrainInfo", "Why the f*** is this exception thrown here ?? " + ex.getMessage() ); |
|
|
} |
|
474 |
|
|
475 |
locationLookup.stopSearch(); |
locationLookup.stopSearch(); |
476 |
|
|