3 |
import java.text.NumberFormat; |
import java.text.NumberFormat; |
4 |
import java.util.ArrayList; |
import java.util.ArrayList; |
5 |
import java.util.List; |
import java.util.List; |
|
import java.util.Locale; |
|
6 |
|
|
7 |
import android.app.AlertDialog; |
import android.app.AlertDialog; |
8 |
import android.app.Dialog; |
import android.app.Dialog; |
10 |
import android.app.ProgressDialog; |
import android.app.ProgressDialog; |
11 |
import android.content.DialogInterface; |
import android.content.DialogInterface; |
12 |
import android.content.Intent; |
import android.content.Intent; |
|
import android.location.Address; |
|
|
import android.location.Geocoder; |
|
13 |
import android.net.Uri; |
import android.net.Uri; |
14 |
import android.os.AsyncTask; |
import android.os.AsyncTask; |
15 |
import android.os.Bundle; |
import android.os.Bundle; |
|
import android.util.Log; |
|
16 |
import android.view.View; |
import android.view.View; |
17 |
import android.widget.ListView; |
import android.widget.ListView; |
18 |
import android.widget.TextView; |
import android.widget.TextView; |
23 |
public class DepartureList extends ListActivity { |
public class DepartureList extends ListActivity { |
24 |
|
|
25 |
public static final int DLG_PROGRESS = 1; |
public static final int DLG_PROGRESS = 1; |
26 |
public static final int DLG_DETAILS = 2; |
|
27 |
|
|
28 |
DepartureListAdapter adapter; |
DepartureListAdapter adapter; |
29 |
DepartureProvider provider; |
DepartureProvider provider; |
33 |
//DepartureBean currentDeparture; |
//DepartureBean currentDeparture; |
34 |
|
|
35 |
ProgressDialog pgDialog; |
ProgressDialog pgDialog; |
36 |
Dialog detailsDialog; |
|
37 |
DepartureFetcher fetcher; |
DepartureFetcher fetcher; |
38 |
int stationId; |
int stationId; |
39 |
|
|
68 |
format.setMinimumFractionDigits(1); |
format.setMinimumFractionDigits(1); |
69 |
int distance = launchedBy.getIntExtra("distance", 0); |
int distance = launchedBy.getIntExtra("distance", 0); |
70 |
((TextView) findViewById(R.id.stationDistance)).setText( format.format((double)distance/1000.0) + " km." ); |
((TextView) findViewById(R.id.stationDistance)).setText( format.format((double)distance/1000.0) + " km." ); |
|
|
|
71 |
|
|
72 |
provider = ProviderFactory.getDepartureProvider(); |
boolean isRegional = launchedBy.getBooleanExtra("isregional", false); |
73 |
|
boolean isSTrain = launchedBy.getBooleanExtra("isstrain", false); |
74 |
|
//boolean isMetro = launchedBy.getBooleanExtra("ismetro", false); // not currently used |
75 |
|
|
76 |
if (savedInstanceState == null) { |
|
77 |
startDepartureFetcher(); |
if (isRegional == false && isSTrain == false) { |
78 |
|
getListView().setVisibility( View.GONE ); |
79 |
|
findViewById(R.id.metroonly).setVisibility( View.VISIBLE ); |
80 |
|
|
81 |
} else { |
} else { |
82 |
departures = (List<DepartureBean>) savedInstanceState.getSerializable("departures"); |
provider = ProviderFactory.getDepartureProvider(); |
83 |
adapter.setDepartures(departures); |
|
84 |
selectedItemId = savedInstanceState.getInt("selectedItemId"); |
if (savedInstanceState == null) { |
85 |
boolean detailsShowing = savedInstanceState.getBoolean("detailsShowing"); |
startDepartureFetcher(); |
86 |
if (detailsShowing) |
} else { |
87 |
showDialog(DLG_DETAILS); |
departures = (List<DepartureBean>) savedInstanceState.getSerializable("departures"); |
88 |
|
adapter.setDepartures(departures); |
89 |
|
selectedItemId = savedInstanceState.getInt("selectedItemId"); |
90 |
|
} |
91 |
} |
} |
92 |
} |
} |
93 |
|
|
96 |
{ |
{ |
97 |
if (pgDialog != null && pgDialog.isShowing()) |
if (pgDialog != null && pgDialog.isShowing()) |
98 |
dismissDialog(DLG_PROGRESS); |
dismissDialog(DLG_PROGRESS); |
99 |
boolean detailsShowing = (detailsDialog != null && detailsDialog.isShowing()); |
|
|
if (detailsShowing) { |
|
|
dismissDialog(DLG_DETAILS); |
|
|
} |
|
|
outState.putBoolean("detailsShowing", detailsShowing); |
|
100 |
outState.putInt("selectedItemId", selectedItemId); |
outState.putInt("selectedItemId", selectedItemId); |
101 |
|
|
102 |
outState.putSerializable("departures", (ArrayList<DepartureBean>) departures); |
outState.putSerializable("departures", (ArrayList<DepartureBean>) departures); |
105 |
@Override |
@Override |
106 |
protected void onListItemClick(ListView l, View v, int position, long id) { |
protected void onListItemClick(ListView l, View v, int position, long id) { |
107 |
super.onListItemClick(l, v, position, id); |
super.onListItemClick(l, v, position, id); |
108 |
|
|
109 |
|
selectedItemId = position; |
110 |
|
|
111 |
|
DepartureBean dep = departures.get(selectedItemId); |
112 |
|
|
113 |
selectedItemId = position; |
Intent intent = new Intent(this, TimetableList.class); |
114 |
showDialog(DLG_DETAILS); |
intent.putExtra("departure", dep); |
115 |
|
|
116 |
|
startActivity(intent); |
117 |
|
|
118 |
} |
} |
119 |
|
|
120 |
|
|
123 |
super.onPrepareDialog(id, dialog); |
super.onPrepareDialog(id, dialog); |
124 |
|
|
125 |
switch (id) { |
switch (id) { |
|
case DLG_DETAILS: |
|
|
DepartureBean currentDeparture = departures.get(selectedItemId); |
|
|
((TextView)dialog.findViewById(R.id.Time)).setText(currentDeparture.getTime()); |
|
|
((TextView)dialog.findViewById(R.id.Train)).setText(currentDeparture.getTrainNumber()); |
|
|
((TextView)dialog.findViewById(R.id.Destination)).setText( currentDeparture.getDestination()); |
|
|
((TextView)dialog.findViewById(R.id.Origin)).setText(currentDeparture.getOrigin()); |
|
|
((TextView)dialog.findViewById(R.id.Location)).setText(currentDeparture.getLocation()); |
|
|
((TextView)dialog.findViewById(R.id.Updated)).setText(currentDeparture.getLastUpdateString()); |
|
|
((TextView)dialog.findViewById(R.id.Status)).setText(currentDeparture.getStatus()); |
|
|
((TextView)dialog.findViewById(R.id.Note)).setText(currentDeparture.getNote()); |
|
|
detailsDialog = dialog; |
|
|
break; |
|
126 |
case DLG_PROGRESS: |
case DLG_PROGRESS: |
127 |
pgDialog = (ProgressDialog) dialog; |
pgDialog = (ProgressDialog) dialog; |
128 |
break; |
break; |
136 |
ProgressDialog dlg = new ProgressDialog(this); |
ProgressDialog dlg = new ProgressDialog(this); |
137 |
dlg.setMessage("Fetch departure data"); |
dlg.setMessage("Fetch departure data"); |
138 |
dlg.setCancelable(true); |
dlg.setCancelable(true); |
139 |
return dlg; |
return dlg; |
|
case DLG_DETAILS: |
|
|
//Context mContext = getApplicationContext(); |
|
|
Dialog dialog = new Dialog(this); |
|
|
dialog.setCancelable(true); |
|
|
|
|
|
dialog.setContentView(R.layout.departuredetails); |
|
|
dialog.setTitle("Departure details"); |
|
|
|
|
|
View root = dialog.findViewById(R.id.layout_root); |
|
|
root.setOnClickListener( new DialogDismisser(dialog) ); |
|
|
return dialog; |
|
140 |
default: |
default: |
141 |
return super.onCreateDialog(id); |
return super.onCreateDialog(id); |
142 |
} |
} |
159 |
public void onClick(View v) { |
public void onClick(View v) { |
160 |
if (dlg.isShowing()) |
if (dlg.isShowing()) |
161 |
dlg.dismiss(); |
dlg.dismiss(); |
162 |
} |
} |
163 |
|
} |
|
|
|
|
} |
|
164 |
|
|
165 |
View.OnClickListener mapLauncher = new View.OnClickListener() { |
View.OnClickListener mapLauncher = new View.OnClickListener() { |
166 |
@Override |
@Override |
175 |
class DepartureFetcher extends AsyncTask<Integer, Void, Void> { |
class DepartureFetcher extends AsyncTask<Integer, Void, Void> { |
176 |
|
|
177 |
boolean success; |
boolean success; |
178 |
String addr; |
|
179 |
@Override |
@Override |
180 |
protected void onPostExecute(Void result) { |
protected void onPostExecute(Void result) { |
181 |
super.onPostExecute(result); |
super.onPostExecute(result); |