/[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 343 by torben, Thu Sep 24 20:33:06 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());
77                                    
78                  if (station.getStatus().length() > 0 || station.getNote().length() > 0) {                  if (station.getStatus().length() > 0 || station.getNote().length() > 0) {
79                          ImageView image = (ImageView) root.findViewById(R.id.InfoIcon);                          ImageView image = (ImageView) root.findViewById(R.id.InfoIcon);
80                          image.setImageResource(R.drawable.info20);                          
81                            int iconID;
82                            if (station.getStatus().toLowerCase().indexOf("aflyst") > -1 ||
83                                            station.getNote().toLowerCase().indexOf("aflyst") > -1 ) {
84                                    iconID = R.drawable.warn20;
85                            } else {
86                                    iconID = R.drawable.info20;
87                            }
88                                    
89                            image.setImageResource( iconID );
90                  }                  }
91                                    
92                  ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon);                  ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon);
93                  String trainNumber = station.getTrainNumber() + " "; //Ugly hack: Append space do simplify icon selection code                  String trainNumber = station.getTrainNumber().trim();
94                                    String code = trainNumber.split(" ")[0].toLowerCase();
95                  if ( trainNumber.substring(0, 2).equalsIgnoreCase("ra")) { //ra = regionaltog arriva          
96                          typeIcon.setImageResource(R.drawable.re);                  Integer imageId = imageMap.get(code);
97                  } else if (  trainNumber.substring(0, 2).equalsIgnoreCase("re")) {                  if (imageId != null) {
98                          typeIcon.setImageResource(R.drawable.re);                          typeIcon.setImageResource(imageId);
99                  } else if (  trainNumber.substring(0,1).equalsIgnoreCase("l")) {                  } else {
                         typeIcon.setImageResource(R.drawable.lyn);  
                 } else if (  trainNumber.substring(0,2).equalsIgnoreCase("ic")) {  
                         typeIcon.setImageResource(R.drawable.ic);  
                 } else if ( trainNumber.substring(0,2).equalsIgnoreCase("pp")) {  
                         typeIcon.setImageResource(R.drawable.pp);  
                 } else if ( trainNumber.substring(0,2).equalsIgnoreCase("ør")) {  
                         typeIcon.setImageResource(R.drawable.or);  
                 } else if ( trainNumber.equalsIgnoreCase("a ") ) {  
                         typeIcon.setImageResource(R.drawable.stog_a); //S-Tog: A banen #00b5f1  
                 } else if ( trainNumber.equalsIgnoreCase("b ") ) {  
                         typeIcon.setImageResource(R.drawable.stog_b); //S-Tog:B banen #5aba52  
                 } else if ( trainNumber.equalsIgnoreCase("bx ") ) {  
                         typeIcon.setImageResource(R.drawable.stog_bx); //S-Tog:Bx banen #a4d17d  
                 } else if ( trainNumber.equalsIgnoreCase("c ") ) {  
                         typeIcon.setImageResource(R.drawable.stog_c); //S-Tog:C banen #f89734  
                 } else if ( trainNumber.equalsIgnoreCase("e ") ) {  
                         typeIcon.setImageResource(R.drawable.stog_e); //S-Tog:E banen #837eba  
                 } else if ( trainNumber.equalsIgnoreCase("f ") ) {  
                         typeIcon.setImageResource(R.drawable.stog_f); //S-Tog:F banen #ffc32d  
                 } else if ( trainNumber.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                  }                  }
                 //Mangler: SJ=Sverige?, EC,        
                   
                   
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.343  
changed lines
  Added in v.490

  ViewVC Help
Powered by ViewVC 1.1.20