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

  ViewVC Help
Powered by ViewVC 1.1.20