/[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 981 - (hide annotations) (download)
Sat Jul 10 16:03:10 2010 UTC (13 years, 10 months ago) by torben
File size: 3822 byte(s)
add support for parsing notification messages from departure xml docs
1 torben 237 package dk.thoerup.traininfo;
2    
3 torben 486 import java.util.HashMap;
4 torben 237 import java.util.List;
5 torben 486 import java.util.Map;
6 torben 237
7     import android.content.Context;
8     import android.view.LayoutInflater;
9     import android.view.View;
10     import android.view.ViewGroup;
11     import android.widget.BaseAdapter;
12 torben 244 import android.widget.ImageView;
13 torben 237 import android.widget.TextView;
14    
15     public class DepartureListAdapter extends BaseAdapter {
16    
17 torben 981 private List<DepartureEntry> departures;
18 torben 237 LayoutInflater inflater;
19     Context context;
20 torben 486
21     static Map<String,Integer> imageMap = new HashMap<String,Integer>();
22     static {
23     buildImageMap();
24     }
25    
26 torben 237 public DepartureListAdapter(Context context) {
27     super();
28     this.context = context;
29    
30     inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
31 torben 486
32 torben 237 }
33    
34 torben 981 public void setDepartures(List<DepartureEntry> departures) {
35 torben 237 this.departures = departures;
36     notifyDataSetChanged();
37     }
38    
39     @Override
40     public int getCount() {
41     if (departures != null)
42     return departures.size();
43     else
44     return 0;
45     }
46    
47 torben 981 public DepartureEntry getDeparture(int position) {
48 torben 237 return departures.get(position);
49     }
50    
51     @Override
52     public Object getItem(int position) {
53     return null;
54     }
55    
56     @Override
57     public long getItemId(int position) {
58     return position;
59     }
60    
61     @Override
62     public View getView(int position, View convertView, ViewGroup parent) {
63 torben 981 DepartureEntry station = departures.get(position);
64 torben 237
65 torben 491 View root = inflater.inflate(R.layout.departurerow , parent, false);
66 torben 237
67     ((TextView) root.findViewById(R.id.Time)).setText(station.getTime());
68     ((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination());
69    
70 torben 244 if (station.getStatus().length() > 0 || station.getNote().length() > 0) {
71 torben 250 ImageView image = (ImageView) root.findViewById(R.id.InfoIcon);
72 torben 483
73 torben 499 String status = station.getStatus().toLowerCase();
74     String note = station.getNote().toLowerCase();
75    
76 torben 483 int iconID;
77 torben 499 if (status.indexOf("aflyst") > -1 || note.indexOf("aflyst") > -1 ) {
78 torben 483 iconID = R.drawable.warn20;
79 torben 499 } else if (note.indexOf("kører kun til") > -1 || note.indexOf("afgår fra") > -1) { //If these strings are present, the train only covers part of the line
80     iconID = R.drawable.warnyellow20;
81 torben 483 } else {
82     iconID = R.drawable.info20;
83     }
84    
85     image.setImageResource( iconID );
86 torben 244 }
87 torben 237
88 torben 250 ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon);
89 torben 351 String trainNumber = station.getTrainNumber().trim();
90 torben 486 String code = trainNumber.split(" ")[0].toLowerCase();
91    
92     Integer imageId = imageMap.get(code);
93     if (imageId != null) {
94     typeIcon.setImageResource(imageId);
95     } else {
96 torben 333 typeIcon.setImageResource(R.drawable.unknown);
97 torben 486 }
98 torben 250
99 torben 237 return root;
100     }
101 torben 486
102     private static void buildImageMap() {
103     imageMap.put("ra", R.drawable.re); //RA = regionaltog arriva
104     imageMap.put("re", R.drawable.re); //RE = Regionaltog
105     imageMap.put("l", R.drawable.lyn); //L = Lyn
106     imageMap.put("ic", R.drawable.ic); //IC = Intercity
107     imageMap.put("pp", R.drawable.pp); //PP = Privatbaner (eg. odderbanen eller LokalBanen)
108     imageMap.put("ør", R.drawable.or); //ØR = Øresundstog
109     imageMap.put("ec", R.drawable.ec); //EC = EuroCity
110     imageMap.put("sj", R.drawable.sj); // SJ=Svenska Jernbaner
111 torben 546 imageMap.put("ie", R.drawable.ie);
112 torben 486
113     imageMap.put("a", R.drawable.stog_a); //S-Tog: A banen #00b5f1
114     imageMap.put("b", R.drawable.stog_b); //S-Tog:B banen #5aba52
115     imageMap.put("bx", R.drawable.stog_bx); //S-Tog:Bx banen #a4d17d
116     imageMap.put("c", R.drawable.stog_c); //S-Tog:C banen #f89734
117     imageMap.put("e", R.drawable.stog_e); //S-Tog:E banen #837eba
118     imageMap.put("f", R.drawable.stog_f); //S-Tog:F banen #ffc32d
119     imageMap.put("h", R.drawable.stog_h); //S-Tog:H banen #f05737
120    
121 torben 237
122 torben 486
123     }
124    
125 torben 237 }

  ViewVC Help
Powered by ViewVC 1.1.20