--- android/TrainInfo/src/dk/thoerup/traininfo/StationList.java 2011/03/26 01:49:11 1244 +++ android/TrainInfo/src/dk/thoerup/traininfo/StationList.java 2011/05/28 17:39:31 1486 @@ -50,18 +50,18 @@ import android.os.Message; import android.util.Log; import android.view.ContextMenu; +import android.view.ContextMenu.ContextMenuInfo; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.view.ContextMenu.ContextMenuInfo; import android.view.View.OnCreateContextMenuListener; import android.widget.AdapterView; import android.widget.EditText; import android.widget.ListView; import android.widget.Toast; import dk.thoerup.android.traininfo.common.StationBean; -import dk.thoerup.android.traininfo.common.StationBean.StationEntry; +import dk.thoerup.android.traininfo.common.StationEntry; import dk.thoerup.traininfo.provider.ProviderFactory; import dk.thoerup.traininfo.provider.StationProvider; import dk.thoerup.traininfo.stationmap.GeoPair; @@ -73,8 +73,8 @@ - public static final int OPTIONS_MAP = 2003; - public static final int OPTIONS_GPSINFO = 2004; + public static final int OPTIONS_MAP = 103; + public static final int OPTIONS_GPSINFO = 104; public static final int DLG_PROGRESS = 3001; public static final int DLG_STATIONNAME = 3002; @@ -231,19 +231,29 @@ item.setIcon(android.R.drawable.ic_menu_mapmode); item = menu.add(0, OPTIONS_GPSINFO, 0, getString(stationlist_gpsinfo)); - item.setIcon(android.R.drawable.ic_menu_mapmode); + item.setIcon(android.R.drawable.ic_menu_info_details); + boolean hasLoc = (locationLookup.getLocation() != null); + item.setEnabled(hasLoc); return true; } + + + @Override public boolean onOptionsItemSelected(MenuItem item) { boolean retval = true; - //TODO: Cleanup + switch (item.getItemId()) { case OPTIONS_MAP: + if ( stations == null || stations.entries == null || stations.entries.size() == 0 ) { + Toast.makeText(this, "No stations to show on map", Toast.LENGTH_SHORT).show(); //TODO: Translate + return true; + } + Intent intent = new Intent(this,StationMapView.class); ArrayList stationPoints = new ArrayList(); @@ -259,14 +269,12 @@ Location loc = locationLookup.getLocation(); StringBuffer message = new StringBuffer(); message.append( getString(stationlist_locationinfo) ).append(":\n"); - if (loc != null) { - message.append( getString(stationlist_obtainedby) ).append( loc.getProvider() ).append("\n"); - message.append( getString(stationlist_accuracy) ).append( (int)loc.getAccuracy()).append("m\n"); - message.append( getString(stationlist_latitude) ).append( (float)loc.getLatitude()).append("\n"); - message.append( getString(stationlist_longitude) ).append( (float)loc.getLongitude() ).append("\n"); - } else { - message.append( getString(stationlist_nolocation) ); - } + + message.append( getString(stationlist_obtainedby) ).append( loc.getProvider() ).append("\n"); + message.append( getString(stationlist_accuracy) ).append( (int)loc.getAccuracy()).append("m\n"); + message.append( getString(stationlist_latitude) ).append( (float)loc.getLatitude()).append("\n"); + message.append( getString(stationlist_longitude) ).append( (float)loc.getLongitude() ).append("\n"); + MessageBox.showMessage(this, message.toString(), false); break; @@ -461,13 +469,8 @@ if (locationLookup.elapsedTime() >= GPS_TIMEOUT_MS) { - try { - 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() ); - } + dismissDialog(DLG_PROGRESS); + locationLookup.stopSearch();