/[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 2189 - (hide annotations) (download)
Fri May 30 18:34:42 2014 UTC (10 years ago) by torben
File size: 5130 byte(s)
enable tritinfo
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 1434 boolean showDetails = false;
19 torben 981 private List<DepartureEntry> departures;
20 torben 237 LayoutInflater inflater;
21     Context context;
22 torben 486
23     static Map<String,Integer> imageMap = new HashMap<String,Integer>();
24     static {
25     buildImageMap();
26     }
27    
28 torben 237 public DepartureListAdapter(Context context) {
29     super();
30     this.context = context;
31    
32 torben 1434 inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
33 torben 237 }
34 torben 1437
35    
36 torben 1434 public void toggleShowDetails() {
37     showDetails = !showDetails;
38     notifyDataSetChanged();
39     }
40    
41 torben 981 public void setDepartures(List<DepartureEntry> departures) {
42 torben 237 this.departures = departures;
43     notifyDataSetChanged();
44     }
45    
46     @Override
47     public int getCount() {
48     if (departures != null)
49     return departures.size();
50     else
51     return 0;
52     }
53    
54 torben 981 public DepartureEntry getDeparture(int position) {
55 torben 237 return departures.get(position);
56     }
57    
58     @Override
59     public Object getItem(int position) {
60     return null;
61     }
62    
63     @Override
64     public long getItemId(int position) {
65     return position;
66     }
67    
68     @Override
69     public View getView(int position, View convertView, ViewGroup parent) {
70 torben 981 DepartureEntry station = departures.get(position);
71 torben 237
72 torben 491 View root = inflater.inflate(R.layout.departurerow , parent, false);
73 torben 237
74     ((TextView) root.findViewById(R.id.Time)).setText(station.getTime());
75     ((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination());
76    
77 torben 1963 //Platform source'n TritInfo er ikke perfekt - så brug den ikke indtil videre
78 torben 2189 ((TextView) root.findViewById(R.id.Platform)).setText(station.getPlatform());
79 torben 1963
80 torben 1066 if ( (station.getStatus() != null && station.getStatus().length() > 0) || (station.getNote() != null && station.getNote().length() > 0) ) {
81 torben 250 ImageView image = (ImageView) root.findViewById(R.id.InfoIcon);
82 torben 483
83 torben 499
84 torben 1066 String status = (station.getStatus() != null) ? station.getStatus().toLowerCase() : "";
85     String note = (station.getNote() != null) ? station.getNote().toLowerCase() : "";
86    
87 torben 483 int iconID;
88 torben 499 if (status.indexOf("aflyst") > -1 || note.indexOf("aflyst") > -1 ) {
89 torben 483 iconID = R.drawable.warn20;
90 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
91     iconID = R.drawable.warnyellow20;
92 torben 483 } else {
93     iconID = R.drawable.info20;
94     }
95    
96     image.setImageResource( iconID );
97 torben 244 }
98 torben 237
99 torben 250 ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon);
100 torben 351 String trainNumber = station.getTrainNumber().trim();
101 torben 1434 String trainParts[] = trainNumber.split(" ");
102     String code = trainParts[0].toLowerCase();
103 torben 486
104 torben 1434 if (showDetails) {
105     root.findViewById(R.id.departureRow2).setVisibility( View.VISIBLE );
106     ((TextView) root.findViewById(R.id.TrainNumber)).setText(trainNumber);
107     ((TextView) root.findViewById(R.id.Origin)).setText( station.getOrigin() );
108     }
109    
110 torben 486 Integer imageId = imageMap.get(code);
111     if (imageId != null) {
112     typeIcon.setImageResource(imageId);
113     } else {
114 torben 333 typeIcon.setImageResource(R.drawable.unknown);
115 torben 486 }
116 torben 250
117 torben 237 return root;
118     }
119 torben 486
120 torben 1434 //TODO: all these traintypes / icons should be explained somewhere
121 torben 486 private static void buildImageMap() {
122 torben 1454 imageMap.put("ec", R.drawable.ec); //EC = EuroCity
123     // Missing FP ?
124     imageMap.put("ic", R.drawable.ic); //IC = Intercity
125     imageMap.put("il", R.drawable.il); //IntercityLyn Nonstop
126     // Missing Int ?
127     // Missing IR ?
128 torben 486 imageMap.put("l", R.drawable.lyn); //L = Lyn
129     imageMap.put("pp", R.drawable.pp); //PP = Privatbaner (eg. odderbanen eller LokalBanen)
130 torben 1454 // Missing PX
131     imageMap.put("ra", R.drawable.re); //RA = regionaltog arriva
132     imageMap.put("re", R.drawable.re); //RE = Regionaltog
133 torben 486 imageMap.put("ør", R.drawable.or); //ØR = Øresundstog
134 torben 1454
135     imageMap.put("sj", R.drawable.sj); //SJ=Svenska Jernbaner -- not mentioned on bane.dk
136     imageMap.put("ie", R.drawable.ie); //what's this ?? -- not mentioned on bane.dk
137 torben 486
138 torben 1454 //Missing IB ? -- not mentioned on bane.dk
139     //Missing RX ? -- not mentioned on bane.dk
140 torben 1963
141     for (int i=0; i<=5; i++) {
142     String add = (i==0) ? "" : "" + i;
143 torben 1454
144 torben 1963 imageMap.put("a" + add, R.drawable.stog_a); //S-Tog: A banen #00b5f1
145     imageMap.put("b" + add, R.drawable.stog_b); //S-Tog:B banen #5aba52
146     imageMap.put("bx" + add, R.drawable.stog_bx); //S-Tog:Bx banen #a4d17d
147     imageMap.put("c" + add, R.drawable.stog_c); //S-Tog:C banen #f89734
148     imageMap.put("e" + add, R.drawable.stog_e); //S-Tog:E banen #837eba
149     imageMap.put("f" + add, R.drawable.stog_f); //S-Tog:F banen #ffc32d
150     imageMap.put("h" + add, R.drawable.stog_h); //S-Tog:H banen #f05737
151     }
152 torben 237
153 torben 486
154     }
155    
156 torben 237 }

  ViewVC Help
Powered by ViewVC 1.1.20