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 |
|
|
78 |
departures = (List<DepartureBean>) savedInstanceState.getSerializable("departures"); |
departures = (List<DepartureBean>) savedInstanceState.getSerializable("departures"); |
79 |
adapter.setDepartures(departures); |
adapter.setDepartures(departures); |
80 |
selectedItemId = savedInstanceState.getInt("selectedItemId"); |
selectedItemId = savedInstanceState.getInt("selectedItemId"); |
|
boolean detailsShowing = savedInstanceState.getBoolean("detailsShowing"); |
|
|
if (detailsShowing) |
|
|
showDialog(DLG_DETAILS); |
|
81 |
} |
} |
82 |
} |
} |
83 |
|
|
86 |
{ |
{ |
87 |
if (pgDialog != null && pgDialog.isShowing()) |
if (pgDialog != null && pgDialog.isShowing()) |
88 |
dismissDialog(DLG_PROGRESS); |
dismissDialog(DLG_PROGRESS); |
89 |
boolean detailsShowing = (detailsDialog != null && detailsDialog.isShowing()); |
|
|
if (detailsShowing) { |
|
|
dismissDialog(DLG_DETAILS); |
|
|
} |
|
|
outState.putBoolean("detailsShowing", detailsShowing); |
|
90 |
outState.putInt("selectedItemId", selectedItemId); |
outState.putInt("selectedItemId", selectedItemId); |
91 |
|
|
92 |
outState.putSerializable("departures", (ArrayList<DepartureBean>) departures); |
outState.putSerializable("departures", (ArrayList<DepartureBean>) departures); |
95 |
@Override |
@Override |
96 |
protected void onListItemClick(ListView l, View v, int position, long id) { |
protected void onListItemClick(ListView l, View v, int position, long id) { |
97 |
super.onListItemClick(l, v, position, id); |
super.onListItemClick(l, v, position, id); |
98 |
|
|
99 |
|
selectedItemId = position; |
100 |
|
|
101 |
|
DepartureBean dep = departures.get(selectedItemId); |
102 |
|
|
103 |
selectedItemId = position; |
Intent intent = new Intent(this, TimetableList.class); |
104 |
showDialog(DLG_DETAILS); |
intent.putExtra("departure", dep); |
105 |
|
|
106 |
|
startActivity(intent); |
107 |
|
|
108 |
} |
} |
109 |
|
|
110 |
|
|
113 |
super.onPrepareDialog(id, dialog); |
super.onPrepareDialog(id, dialog); |
114 |
|
|
115 |
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; |
|
116 |
case DLG_PROGRESS: |
case DLG_PROGRESS: |
117 |
pgDialog = (ProgressDialog) dialog; |
pgDialog = (ProgressDialog) dialog; |
118 |
break; |
break; |
126 |
ProgressDialog dlg = new ProgressDialog(this); |
ProgressDialog dlg = new ProgressDialog(this); |
127 |
dlg.setMessage("Fetch departure data"); |
dlg.setMessage("Fetch departure data"); |
128 |
dlg.setCancelable(true); |
dlg.setCancelable(true); |
129 |
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; |
|
130 |
default: |
default: |
131 |
return super.onCreateDialog(id); |
return super.onCreateDialog(id); |
132 |
} |
} |
149 |
public void onClick(View v) { |
public void onClick(View v) { |
150 |
if (dlg.isShowing()) |
if (dlg.isShowing()) |
151 |
dlg.dismiss(); |
dlg.dismiss(); |
152 |
} |
} |
153 |
|
} |
|
|
|
|
} |
|
154 |
|
|
155 |
View.OnClickListener mapLauncher = new View.OnClickListener() { |
View.OnClickListener mapLauncher = new View.OnClickListener() { |
156 |
@Override |
@Override |
165 |
class DepartureFetcher extends AsyncTask<Integer, Void, Void> { |
class DepartureFetcher extends AsyncTask<Integer, Void, Void> { |
166 |
|
|
167 |
boolean success; |
boolean success; |
168 |
String addr; |
|
169 |
@Override |
@Override |
170 |
protected void onPostExecute(Void result) { |
protected void onPostExecute(Void result) { |
171 |
super.onPostExecute(result); |
super.onPostExecute(result); |