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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1066 - (show 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 package dk.thoerup.traininfo;
2
3 import java.util.HashMap;
4 import java.util.List;
5 import java.util.Map;
6
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 import android.widget.ImageView;
13 import android.widget.TextView;
14 import dk.thoerup.android.traininfo.common.DepartureEntry;
15
16 public class DepartureListAdapter extends BaseAdapter {
17
18 private List<DepartureEntry> departures;
19 LayoutInflater inflater;
20 Context context;
21
22 static Map<String,Integer> imageMap = new HashMap<String,Integer>();
23 static {
24 buildImageMap();
25 }
26
27 public DepartureListAdapter(Context context) {
28 super();
29 this.context = context;
30
31 inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
32
33 }
34
35 public void setDepartures(List<DepartureEntry> departures) {
36 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 public DepartureEntry getDeparture(int position) {
49 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 DepartureEntry station = departures.get(position);
65
66 View root = inflater.inflate(R.layout.departurerow , parent, false);
67
68 ((TextView) root.findViewById(R.id.Time)).setText(station.getTime());
69 ((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination());
70
71
72 if ( (station.getStatus() != null && station.getStatus().length() > 0) || (station.getNote() != null && station.getNote().length() > 0) ) {
73 ImageView image = (ImageView) root.findViewById(R.id.InfoIcon);
74
75
76 String status = (station.getStatus() != null) ? station.getStatus().toLowerCase() : "";
77 String note = (station.getNote() != null) ? station.getNote().toLowerCase() : "";
78
79 int iconID;
80 if (status.indexOf("aflyst") > -1 || note.indexOf("aflyst") > -1 ) {
81 iconID = R.drawable.warn20;
82 } 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 } else {
85 iconID = R.drawable.info20;
86 }
87
88 image.setImageResource( iconID );
89 }
90
91 ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon);
92 String trainNumber = station.getTrainNumber().trim();
93 String code = trainNumber.split(" ")[0].toLowerCase();
94
95 Integer imageId = imageMap.get(code);
96 if (imageId != null) {
97 typeIcon.setImageResource(imageId);
98 } else {
99 typeIcon.setImageResource(R.drawable.unknown);
100 }
101
102 return root;
103 }
104
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 imageMap.put("ie", R.drawable.ie);
115
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
125
126 }
127
128 }

  ViewVC Help
Powered by ViewVC 1.1.20