/[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 1434 - (hide annotations) (download)
Tue May 3 16:28:56 2011 UTC (13 years ago) by torben
File size: 4732 byte(s)
Add detailed DepartureView
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    
35 torben 1434 public void setShowDetails(boolean showDetails) {
36     this.showDetails = showDetails;
37     }
38    
39     public boolean getShowDetails() {
40     return showDetails;
41     }
42    
43     public void toggleShowDetails() {
44     showDetails = !showDetails;
45     notifyDataSetChanged();
46     }
47    
48 torben 981 public void setDepartures(List<DepartureEntry> departures) {
49 torben 237 this.departures = departures;
50     notifyDataSetChanged();
51     }
52    
53     @Override
54     public int getCount() {
55     if (departures != null)
56     return departures.size();
57     else
58     return 0;
59     }
60    
61 torben 981 public DepartureEntry getDeparture(int position) {
62 torben 237 return departures.get(position);
63     }
64    
65     @Override
66     public Object getItem(int position) {
67     return null;
68     }
69    
70     @Override
71     public long getItemId(int position) {
72     return position;
73     }
74    
75     @Override
76     public View getView(int position, View convertView, ViewGroup parent) {
77 torben 981 DepartureEntry station = departures.get(position);
78 torben 237
79 torben 491 View root = inflater.inflate(R.layout.departurerow , parent, false);
80 torben 237
81     ((TextView) root.findViewById(R.id.Time)).setText(station.getTime());
82     ((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination());
83    
84 torben 1066
85     if ( (station.getStatus() != null && station.getStatus().length() > 0) || (station.getNote() != null && station.getNote().length() > 0) ) {
86 torben 250 ImageView image = (ImageView) root.findViewById(R.id.InfoIcon);
87 torben 483
88 torben 499
89 torben 1066 String status = (station.getStatus() != null) ? station.getStatus().toLowerCase() : "";
90     String note = (station.getNote() != null) ? station.getNote().toLowerCase() : "";
91    
92 torben 483 int iconID;
93 torben 499 if (status.indexOf("aflyst") > -1 || note.indexOf("aflyst") > -1 ) {
94 torben 483 iconID = R.drawable.warn20;
95 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
96     iconID = R.drawable.warnyellow20;
97 torben 483 } else {
98     iconID = R.drawable.info20;
99     }
100    
101     image.setImageResource( iconID );
102 torben 244 }
103 torben 237
104 torben 250 ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon);
105 torben 351 String trainNumber = station.getTrainNumber().trim();
106 torben 1434 String trainParts[] = trainNumber.split(" ");
107     String code = trainParts[0].toLowerCase();
108 torben 486
109 torben 1434 if (showDetails) {
110     root.findViewById(R.id.departureRow2).setVisibility( View.VISIBLE );
111     ((TextView) root.findViewById(R.id.TrainNumber)).setText(trainNumber);
112     ((TextView) root.findViewById(R.id.Origin)).setText( station.getOrigin() );
113     }
114    
115 torben 486 Integer imageId = imageMap.get(code);
116     if (imageId != null) {
117     typeIcon.setImageResource(imageId);
118     } else {
119 torben 333 typeIcon.setImageResource(R.drawable.unknown);
120 torben 486 }
121 torben 250
122 torben 237 return root;
123     }
124 torben 486
125 torben 1434 //TODO: all these traintypes / icons should be explained somewhere
126 torben 486 private static void buildImageMap() {
127     imageMap.put("ra", R.drawable.re); //RA = regionaltog arriva
128     imageMap.put("re", R.drawable.re); //RE = Regionaltog
129     imageMap.put("l", R.drawable.lyn); //L = Lyn
130     imageMap.put("ic", R.drawable.ic); //IC = Intercity
131     imageMap.put("pp", R.drawable.pp); //PP = Privatbaner (eg. odderbanen eller LokalBanen)
132     imageMap.put("ør", R.drawable.or); //ØR = Øresundstog
133     imageMap.put("ec", R.drawable.ec); //EC = EuroCity
134     imageMap.put("sj", R.drawable.sj); // SJ=Svenska Jernbaner
135 torben 546 imageMap.put("ie", R.drawable.ie);
136 torben 1434 //TODO: missing IL: IntercityLyn Nonstop
137 torben 486
138     imageMap.put("a", R.drawable.stog_a); //S-Tog: A banen #00b5f1
139     imageMap.put("b", R.drawable.stog_b); //S-Tog:B banen #5aba52
140     imageMap.put("bx", R.drawable.stog_bx); //S-Tog:Bx banen #a4d17d
141     imageMap.put("c", R.drawable.stog_c); //S-Tog:C banen #f89734
142     imageMap.put("e", R.drawable.stog_e); //S-Tog:E banen #837eba
143     imageMap.put("f", R.drawable.stog_f); //S-Tog:F banen #ffc32d
144     imageMap.put("h", R.drawable.stog_h); //S-Tog:H banen #f05737
145    
146 torben 237
147 torben 486
148     }
149    
150 torben 237 }

  ViewVC Help
Powered by ViewVC 1.1.20