/[projects]/android/TrainInfo/src/dk/thoerup/traininfo/DepartureListAdapter.java
ViewVC logotype

Annotation of /android/TrainInfo/src/dk/thoerup/traininfo/DepartureListAdapter.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 343 - (hide annotations) (download)
Thu Sep 24 20:33:06 2009 UTC (14 years, 8 months ago) by torben
File size: 3647 byte(s)
Force UTF8 on this file, and alter to use correct station code
1 torben 237 package dk.thoerup.traininfo;
2    
3     import java.util.List;
4    
5     import android.content.Context;
6     import android.view.LayoutInflater;
7     import android.view.View;
8     import android.view.ViewGroup;
9     import android.widget.BaseAdapter;
10 torben 244 import android.widget.ImageView;
11 torben 237 import android.widget.TextView;
12    
13     public class DepartureListAdapter extends BaseAdapter {
14    
15     private List<DepartureBean> departures;
16     LayoutInflater inflater;
17     Context context;
18     public DepartureListAdapter(Context context) {
19     super();
20     this.context = context;
21    
22     inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
23     }
24    
25     public void setDepartures(List<DepartureBean> departures) {
26     this.departures = departures;
27     notifyDataSetChanged();
28     }
29    
30     @Override
31     public int getCount() {
32     if (departures != null)
33     return departures.size();
34     else
35     return 0;
36     }
37    
38     public DepartureBean getDeparture(int position) {
39     return departures.get(position);
40     }
41    
42     @Override
43     public Object getItem(int position) {
44     return null;
45     }
46    
47     @Override
48     public long getItemId(int position) {
49     return position;
50     }
51    
52     @Override
53     public View getView(int position, View convertView, ViewGroup parent) {
54     DepartureBean station = departures.get(position);
55    
56     View root = inflater.inflate(R.layout.departurerow , parent, false);
57    
58     ((TextView) root.findViewById(R.id.Time)).setText(station.getTime());
59     ((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination());
60    
61 torben 244 if (station.getStatus().length() > 0 || station.getNote().length() > 0) {
62 torben 250 ImageView image = (ImageView) root.findViewById(R.id.InfoIcon);
63 torben 244 image.setImageResource(R.drawable.info20);
64     }
65 torben 237
66 torben 250 ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon);
67 torben 332 String trainNumber = station.getTrainNumber() + " "; //Ugly hack: Append space do simplify icon selection code
68 torben 244
69 torben 332 if ( trainNumber.substring(0, 2).equalsIgnoreCase("ra")) { //ra = regionaltog arriva
70 torben 333 typeIcon.setImageResource(R.drawable.re);
71 torben 332 } else if ( trainNumber.substring(0, 2).equalsIgnoreCase("re")) {
72 torben 333 typeIcon.setImageResource(R.drawable.re);
73 torben 332 } else if ( trainNumber.substring(0,1).equalsIgnoreCase("l")) {
74 torben 333 typeIcon.setImageResource(R.drawable.lyn);
75 torben 332 } else if ( trainNumber.substring(0,2).equalsIgnoreCase("ic")) {
76 torben 333 typeIcon.setImageResource(R.drawable.ic);
77 torben 332 } else if ( trainNumber.substring(0,2).equalsIgnoreCase("pp")) {
78 torben 333 typeIcon.setImageResource(R.drawable.pp);
79 torben 343 } else if ( trainNumber.substring(0,2).equalsIgnoreCase("ør")) {
80 torben 333 typeIcon.setImageResource(R.drawable.or);
81 torben 332 } else if ( trainNumber.equalsIgnoreCase("a ") ) {
82 torben 333 typeIcon.setImageResource(R.drawable.stog_a); //S-Tog: A banen #00b5f1
83 torben 332 } else if ( trainNumber.equalsIgnoreCase("b ") ) {
84 torben 333 typeIcon.setImageResource(R.drawable.stog_b); //S-Tog:B banen #5aba52
85 torben 332 } else if ( trainNumber.equalsIgnoreCase("bx ") ) {
86 torben 333 typeIcon.setImageResource(R.drawable.stog_bx); //S-Tog:Bx banen #a4d17d
87 torben 332 } else if ( trainNumber.equalsIgnoreCase("c ") ) {
88 torben 333 typeIcon.setImageResource(R.drawable.stog_c); //S-Tog:C banen #f89734
89 torben 332 } else if ( trainNumber.equalsIgnoreCase("e ") ) {
90 torben 333 typeIcon.setImageResource(R.drawable.stog_e); //S-Tog:E banen #837eba
91 torben 332 } else if ( trainNumber.equalsIgnoreCase("f ") ) {
92 torben 333 typeIcon.setImageResource(R.drawable.stog_f); //S-Tog:F banen #ffc32d
93 torben 332 } else if ( trainNumber.equalsIgnoreCase("h ") ) {
94 torben 333 typeIcon.setImageResource(R.drawable.stog_h); //S-Tog:H banen #f05737
95     } else {
96     typeIcon.setImageResource(R.drawable.unknown);
97     }
98     //Mangler: SJ=Sverige?, EC,
99 torben 250
100 torben 332
101    
102 torben 237 return root;
103     }
104    
105     }

  ViewVC Help
Powered by ViewVC 1.1.20