--- android/TrainInfo/src/dk/thoerup/traininfo/StationList.java 2009/10/29 08:56:17 481 +++ android/TrainInfo/src/dk/thoerup/traininfo/StationList.java 2010/01/26 21:17:26 552 @@ -2,7 +2,7 @@ import java.util.ArrayList; import java.util.List; -import java.util.Locale; + import android.app.AlertDialog; import android.app.Dialog; @@ -12,14 +12,12 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; -import android.location.Address; -import android.location.Geocoder; import android.location.Location; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.Message; -import android.util.Log; + import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.Menu; @@ -63,7 +61,7 @@ String dialogMessage = ""; ProgressDialog dialog; - LocationLookup locator = null; + LocationLookup locationLookup = null; FindStationsTask findStationsTask; StationsFetchedHandler stationsFetched = new StationsFetchedHandler(); @@ -80,7 +78,6 @@ IntSet favorites = new IntSet(); WelcomeScreen.ListType listType; - String dialogTitle; SharedPreferences prefs; /////////////////////////////////////////////////////////////////////////////////////////// @@ -99,7 +96,7 @@ ListView lv = getListView(); lv.setOnCreateContextMenuListener(contextMenu); - locator = new LocationLookup(this, stationsFetched); + locationLookup = new LocationLookup(this, stationsFetched); prefs = getSharedPreferences("TrainStation", 0); @@ -108,8 +105,12 @@ favorites.fromString(favoriteString); } + listType = (WelcomeScreen.ListType) getIntent().getSerializableExtra("type"); + setTitle(); + if (savedInstanceState == null) { - listType = (WelcomeScreen.ListType) getIntent().getSerializableExtra("type"); + + switch (listType) { case ListNearest: startLookup(); @@ -128,10 +129,29 @@ stations = (ArrayList) savedInstanceState.getSerializable("stations"); adapter.setStations(stations); location = (GeoPair) savedInstanceState.getSerializable("location"); - dialogTitle = savedInstanceState.getString("title"); - setTitle(dialogTitle); } + } + protected void setTitle() { + String dialogTitle = getResources().getString(R.string.app_name); + switch (listType) { + case ListNearest: + dialogTitle += " - Nearby stations"; + break; + case ListSearch: + dialogTitle += " - Search"; + break; + case ListFavorites: + dialogTitle += " - Favorites"; + break; + default: + dialogTitle = "";//not possible + } + + setTitle(dialogTitle); + } + + @Override @@ -141,7 +161,7 @@ dialog.dismiss(); outState.putSerializable("stations", (ArrayList) stations); outState.putSerializable("location", location); - outState.putString("title", dialogTitle); + } @@ -168,7 +188,6 @@ case OPTIONS_MAP: Intent intent = new Intent(this,StationMapView.class); - intent.putExtra("userlocation", location ); ArrayList stationPoints = new ArrayList(); for (StationBean st : stations ) { @@ -180,12 +199,13 @@ startActivity(intent); break; case OPTIONS_GPSINFO: - Location loc = locator.getLocation(); + Location loc = locationLookup.getLocation(); StringBuffer message = new StringBuffer(); message.append("Location info:\n"); message.append("-Obtained by: ").append(loc != null ? loc.getProvider() : "-").append("\n"); message.append("-Accuracy: ").append(loc != null ? (int)loc.getAccuracy() : "-").append("m\n"); - + message.append("-Latitude: ").append(loc != null ? loc.getLatitude() : "-").append("\n"); + message.append("-Longitude: ").append(loc != null ? loc.getLongitude() : "-").append("\n"); MessageBox.showMessage(this, message.toString()); break; default: @@ -283,6 +303,9 @@ intent.putExtra("longitude", longitude); intent.putExtra("stationid", station.getId()); intent.putExtra("address", station.getAddress()); + intent.putExtra("isregional", station.isRegional()); + intent.putExtra("isstrain", station.isSTrain()); + intent.putExtra("ismetro", station.isMetro()); startActivity(intent); } @@ -294,7 +317,7 @@ dialogMessage = "Wait for location fix"; showDialog(DLG_PROGRESS); - locator.locateStations(); + locationLookup.locateStations(); stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000); } @@ -303,7 +326,7 @@ showDialog(DLG_PROGRESS); findStationsTask = new FindStationsTask(); - findStationsTask.searchByName(name, locator.getLocation()); + findStationsTask.searchByName(name, locationLookup.getLocation()); findStationsTask.execute(); } @@ -315,7 +338,7 @@ showDialog(DLG_PROGRESS); findStationsTask = new FindStationsTask(); - findStationsTask.searchByIds(favorites.toString(), locator.getLocation()); + findStationsTask.searchByIds(favorites.toString(), locationLookup.getLocation()); findStationsTask.execute(); } else { MessageBox.showMessage(this, "Favorite list is empty"); @@ -330,11 +353,12 @@ showDialog(DLG_PROGRESS); findStationsTask = new FindStationsTask(); - findStationsTask.searchByLocation( locator.getLocation() ); + findStationsTask.searchByLocation( locationLookup.getLocation() ); findStationsTask.execute(); } + /* TODO: Remove this no longer needed function String lookupAddress(double latitude, double longitude) { Geocoder coder = new Geocoder(this, new Locale("da")); @@ -359,7 +383,7 @@ } return sb.toString(); - } + }*/ //////////////////////////////////////////////////////////////////////////// @@ -374,7 +398,7 @@ dismissDialog(DLG_PROGRESS); startLocatorTask(); - location = GeoPair.fromLocation( locator.getLocation() ); + location = GeoPair.fromLocation( locationLookup.getLocation() ); break; @@ -384,8 +408,8 @@ break; case LOCATIONFIXTIMEOUT: if (isRunning) { - locator.stopSearch(); - if (locator.hasLocation()) { + locationLookup.stopSearch(); + if (locationLookup.hasLocation()) { stationsFetched.sendEmptyMessage( GOTLOCATION ); } else { dismissDialog(DLG_PROGRESS); @@ -473,10 +497,7 @@ List stations = stationProvider.getStations(); for (StationBean station : stations) { - String addr = lookupAddress(station.getLatitude(), station.getLongitude()); - station.setAddress(addr); - - + if (method.equals(LookupMethod.ByName) || method.equals(LookupMethod.ByList)) { if (loc != null) { //only do the distance calc if we have a location dummy.setLatitude(station.getLatitude()); @@ -497,23 +518,6 @@ super.onPostExecute(result); dialog.dismiss(); - //set title - switch (method) { - case ByLocation: - dialogTitle = "Traininfo DK - Nearby stations"; - break; - case ByName: - dialogTitle = "Traininfo DK - Search"; - break; - case ByList: - dialogTitle = "Traininfo DK - Favorites"; - break; - default: - dialogTitle = "";//not possible - } - - StationList.this.setTitle(dialogTitle); - //set title end if (success) { if (stationProvider.getStations().size() == 0)