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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 485 by torben, Thu Oct 29 11:48:28 2009 UTC revision 490 by torben, Thu Oct 29 19:27:29 2009 UTC
# Line 1  Line 1 
1  package dk.thoerup.traininfo;  package dk.thoerup.traininfo;
2    
3    import java.util.HashMap;
4  import java.util.List;  import java.util.List;
5    import java.util.Map;
6    
7  import android.content.Context;  import android.content.Context;
8    import android.util.Log;
9  import android.view.LayoutInflater;  import android.view.LayoutInflater;
10  import android.view.View;  import android.view.View;
11  import android.view.ViewGroup;  import android.view.ViewGroup;
# Line 15  public class DepartureListAdapter extend Line 18  public class DepartureListAdapter extend
18          private List<DepartureBean> departures;          private List<DepartureBean> departures;
19          LayoutInflater inflater;          LayoutInflater inflater;
20          Context context;          Context context;
21            
22            static Map<String,Integer> imageMap = new HashMap<String,Integer>();
23            static {
24                    buildImageMap();
25            }
26            
27          public DepartureListAdapter(Context context) {          public DepartureListAdapter(Context context) {
28                  super();                  super();
29                  this.context = context;                  this.context = context;
30                                    
31                  inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);                  inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
32                    
33          }          }
34                    
35          public void setDepartures(List<DepartureBean> departures) {          public void setDepartures(List<DepartureBean> departures) {
# Line 53  public class DepartureListAdapter extend Line 63  public class DepartureListAdapter extend
63          public View getView(int position, View convertView, ViewGroup parent) {          public View getView(int position, View convertView, ViewGroup parent) {
64                  DepartureBean station = departures.get(position);                  DepartureBean station = departures.get(position);
65    
66                  View root = inflater.inflate(R.layout.departurerow , parent, false);                  
67                    View root;
68                    if (convertView == null || convertView.getId() != R.id.DepartureRow ) {
69                            root = inflater.inflate(R.layout.departurerow , parent, false);
70                    } else {
71                            root = convertView;
72                    }
73    
74                                    
75                  ((TextView) root.findViewById(R.id.Time)).setText(station.getTime());                  ((TextView) root.findViewById(R.id.Time)).setText(station.getTime());
76                  ((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination());                  ((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination());
# Line 74  public class DepartureListAdapter extend Line 91  public class DepartureListAdapter extend
91                                    
92                  ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon);                  ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon);
93                  String trainNumber = station.getTrainNumber().trim();                  String trainNumber = station.getTrainNumber().trim();
94                  String code = trainNumber.split(" ")[0];                  String code = trainNumber.split(" ")[0].toLowerCase();
95                            
96                                    Integer imageId = imageMap.get(code);
97                                    if (imageId != null) {
98                  if ( code.equalsIgnoreCase("ra")) { //RA = regionaltog arriva                          typeIcon.setImageResource(imageId);
99                          typeIcon.setImageResource(R.drawable.re);                  } else {
                 } else if ( code.equalsIgnoreCase("re")) { //RE=Regionaltog  
                         typeIcon.setImageResource(R.drawable.re);  
                 } else if ( code.equalsIgnoreCase("l")) { //L=Lyn  
                         typeIcon.setImageResource(R.drawable.lyn);  
                 } else if ( code.equalsIgnoreCase("ic")) { // IC=Intercity  
                         typeIcon.setImageResource(R.drawable.ic);  
                 } else if ( code.equalsIgnoreCase("pp")) { // PP=Privatbaner (eg. odderbanen eller LokalBanen)  
                         typeIcon.setImageResource(R.drawable.pp);  
                 } else if ( code.equalsIgnoreCase("ør")) { // ØR=Øresundstog  
                         typeIcon.setImageResource(R.drawable.or);  
                 } else if ( code.equalsIgnoreCase("ec")) { // EC=EuroCity  
                         typeIcon.setImageResource(R.drawable.ec);  
                 } else if ( code.equalsIgnoreCase("sj")) { // SJ=Svenska Jernbaner  
                         typeIcon.setImageResource(R.drawable.sj);  
                 } else if ( code.equalsIgnoreCase("a") ) {  
                         typeIcon.setImageResource(R.drawable.stog_a); //S-Tog: A banen #00b5f1  
                 } else if ( code.equalsIgnoreCase("b") ) {  
                         typeIcon.setImageResource(R.drawable.stog_b); //S-Tog:B banen #5aba52  
                 } else if ( code.equalsIgnoreCase("bx") ) {  
                         typeIcon.setImageResource(R.drawable.stog_bx); //S-Tog:Bx banen #a4d17d  
                 } else if ( code.equalsIgnoreCase("c") ) {  
                         typeIcon.setImageResource(R.drawable.stog_c); //S-Tog:C banen #f89734  
                 } else if ( code.equalsIgnoreCase("e") ) {  
                         typeIcon.setImageResource(R.drawable.stog_e); //S-Tog:E banen #837eba  
                 } else if ( code.equalsIgnoreCase("f") ) {  
                         typeIcon.setImageResource(R.drawable.stog_f); //S-Tog:F banen #ffc32d  
                 } else if ( code.equalsIgnoreCase("h") ) {  
                         typeIcon.setImageResource(R.drawable.stog_h); //S-Tog:H banen #f05737  
                 }  else {  
100                          typeIcon.setImageResource(R.drawable.unknown);                          typeIcon.setImageResource(R.drawable.unknown);
101                  }                                }
                   
102                                    
103                  return root;                  return root;
104          }          }
105            
106            private static void buildImageMap() {
107                    imageMap.put("ra", R.drawable.re); //RA = regionaltog arriva
108                    imageMap.put("re", R.drawable.re); //RE = Regionaltog
109                    imageMap.put("l", R.drawable.lyn); //L =  Lyn
110                    imageMap.put("ic", R.drawable.ic); //IC = Intercity
111                    imageMap.put("pp", R.drawable.pp); //PP = Privatbaner (eg. odderbanen eller LokalBanen)
112                    imageMap.put("ør", R.drawable.or); //ØR = Øresundstog
113                    imageMap.put("ec", R.drawable.ec); //EC = EuroCity
114                    imageMap.put("sj", R.drawable.sj); // SJ=Svenska Jernbaner
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  }  }

Legend:
Removed from v.485  
changed lines
  Added in v.490

  ViewVC Help
Powered by ViewVC 1.1.20