/[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 351 - (show annotations) (download)
Mon Sep 28 21:39:49 2009 UTC (14 years, 7 months ago) by torben
File size: 3448 byte(s)
Simplify icon selection a bit
1 package dk.thoerup.traininfo;
2
3 import java.util.List;
4
5 import android.content.Context;
6 import android.view.LayoutInflater;
7 import android.view.View;
8 import android.view.ViewGroup;
9 import android.widget.BaseAdapter;
10 import android.widget.ImageView;
11 import android.widget.TextView;
12
13 public class DepartureListAdapter extends BaseAdapter {
14
15 private List<DepartureBean> departures;
16 LayoutInflater inflater;
17 Context context;
18 public DepartureListAdapter(Context context) {
19 super();
20 this.context = context;
21
22 inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
23 }
24
25 public void setDepartures(List<DepartureBean> departures) {
26 this.departures = departures;
27 notifyDataSetChanged();
28 }
29
30 @Override
31 public int getCount() {
32 if (departures != null)
33 return departures.size();
34 else
35 return 0;
36 }
37
38 public DepartureBean getDeparture(int position) {
39 return departures.get(position);
40 }
41
42 @Override
43 public Object getItem(int position) {
44 return null;
45 }
46
47 @Override
48 public long getItemId(int position) {
49 return position;
50 }
51
52 @Override
53 public View getView(int position, View convertView, ViewGroup parent) {
54 DepartureBean station = departures.get(position);
55
56 View root = inflater.inflate(R.layout.departurerow , parent, false);
57
58 ((TextView) root.findViewById(R.id.Time)).setText(station.getTime());
59 ((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination());
60
61 if (station.getStatus().length() > 0 || station.getNote().length() > 0) {
62 ImageView image = (ImageView) root.findViewById(R.id.InfoIcon);
63 image.setImageResource(R.drawable.info20);
64 }
65
66 ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon);
67 String trainNumber = station.getTrainNumber().trim();
68 String code = trainNumber.split(" ")[0];
69
70
71
72 if ( code.equalsIgnoreCase("ra")) { //ra = regionaltog arriva
73 typeIcon.setImageResource(R.drawable.re);
74 } else if ( code.equalsIgnoreCase("re")) {
75 typeIcon.setImageResource(R.drawable.re);
76 } else if ( code.equalsIgnoreCase("l")) {
77 typeIcon.setImageResource(R.drawable.lyn);
78 } else if ( code.equalsIgnoreCase("ic")) {
79 typeIcon.setImageResource(R.drawable.ic);
80 } else if ( code.equalsIgnoreCase("pp")) {
81 typeIcon.setImageResource(R.drawable.pp);
82 } else if ( code.equalsIgnoreCase("ør")) {
83 typeIcon.setImageResource(R.drawable.or);
84 } else if ( code.equalsIgnoreCase("a") ) {
85 typeIcon.setImageResource(R.drawable.stog_a); //S-Tog: A banen #00b5f1
86 } else if ( code.equalsIgnoreCase("b") ) {
87 typeIcon.setImageResource(R.drawable.stog_b); //S-Tog:B banen #5aba52
88 } else if ( code.equalsIgnoreCase("bx") ) {
89 typeIcon.setImageResource(R.drawable.stog_bx); //S-Tog:Bx banen #a4d17d
90 } else if ( code.equalsIgnoreCase("c") ) {
91 typeIcon.setImageResource(R.drawable.stog_c); //S-Tog:C banen #f89734
92 } else if ( code.equalsIgnoreCase("e") ) {
93 typeIcon.setImageResource(R.drawable.stog_e); //S-Tog:E banen #837eba
94 } else if ( code.equalsIgnoreCase("f") ) {
95 typeIcon.setImageResource(R.drawable.stog_f); //S-Tog:F banen #ffc32d
96 } else if ( code.equalsIgnoreCase("h") ) {
97 typeIcon.setImageResource(R.drawable.stog_h); //S-Tog:H banen #f05737
98 } else {
99 typeIcon.setImageResource(R.drawable.unknown);
100 }
101 //Mangler: SJ=Sverige?, EC,
102
103
104
105 return root;
106 }
107
108 }

  ViewVC Help
Powered by ViewVC 1.1.20