/[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 483 by torben, Thu Oct 29 10:49:14 2009 UTC revision 499 by torben, Fri Nov 6 06:58: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.view.LayoutInflater;  import android.view.LayoutInflater;
# Line 15  public class DepartureListAdapter extend Line 17  public class DepartureListAdapter extend
17          private List<DepartureBean> departures;          private List<DepartureBean> departures;
18          LayoutInflater inflater;          LayoutInflater inflater;
19          Context context;          Context context;
20            
21            static Map<String,Integer> imageMap = new HashMap<String,Integer>();
22            static {
23                    buildImageMap();
24            }
25            
26          public DepartureListAdapter(Context context) {          public DepartureListAdapter(Context context) {
27                  super();                  super();
28                  this.context = context;                  this.context = context;
29                                    
30                  inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);                  inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
31                    
32          }          }
33                    
34          public void setDepartures(List<DepartureBean> departures) {          public void setDepartures(List<DepartureBean> departures) {
# Line 61  public class DepartureListAdapter extend Line 70  public class DepartureListAdapter extend
70                  if (station.getStatus().length() > 0 || station.getNote().length() > 0) {                  if (station.getStatus().length() > 0 || station.getNote().length() > 0) {
71                          ImageView image = (ImageView) root.findViewById(R.id.InfoIcon);                          ImageView image = (ImageView) root.findViewById(R.id.InfoIcon);
72                                                    
73                            String status = station.getStatus().toLowerCase();
74                            String note = station.getNote().toLowerCase();
75                            
76                          int iconID;                          int iconID;
77                          if (station.getStatus().toLowerCase().indexOf("aflyst") > -1 ||                          if (status.indexOf("aflyst") > -1 || note.indexOf("aflyst") > -1 ) {
                                         station.getNote().toLowerCase().indexOf("aflyst") > -1 ) {  
78                                  iconID = R.drawable.warn20;                                  iconID = R.drawable.warn20;
79                            } 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
80                                    iconID = R.drawable.warnyellow20;
81                          } else {                          } else {
82                                  iconID = R.drawable.info20;                                  iconID = R.drawable.info20;
83                          }                          }
# Line 74  public class DepartureListAdapter extend Line 87  public class DepartureListAdapter extend
87                                    
88                  ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon);                  ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon);
89                  String trainNumber = station.getTrainNumber().trim();                  String trainNumber = station.getTrainNumber().trim();
90                  String code = trainNumber.split(" ")[0];                  String code = trainNumber.split(" ")[0].toLowerCase();
91                            
92                                    Integer imageId = imageMap.get(code);
93                                    if (imageId != null) {
94                  if ( code.equalsIgnoreCase("ra")) { //ra = regionaltog arriva                          typeIcon.setImageResource(imageId);
95                          typeIcon.setImageResource(R.drawable.re);                  } else {
                 } else if ( code.equalsIgnoreCase("re")) {  
                         typeIcon.setImageResource(R.drawable.re);  
                 } else if ( code.equalsIgnoreCase("l")) {  
                         typeIcon.setImageResource(R.drawable.lyn);  
                 } else if ( code.equalsIgnoreCase("ic")) {  
                         typeIcon.setImageResource(R.drawable.ic);  
                 } else if ( code.equalsIgnoreCase("pp")) {  
                         typeIcon.setImageResource(R.drawable.pp);  
                 } else if ( code.equalsIgnoreCase("ør")) {  
                         typeIcon.setImageResource(R.drawable.or);  
                 } 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 {  
96                          typeIcon.setImageResource(R.drawable.unknown);                          typeIcon.setImageResource(R.drawable.unknown);
97                  }                  }
                 //Mangler: SJ=Sverige?, EC,        
                   
                   
98                                    
99                  return root;                  return root;
100          }          }
101            
102            private static void buildImageMap() {
103                    imageMap.put("ra", R.drawable.re); //RA = regionaltog arriva
104                    imageMap.put("re", R.drawable.re); //RE = Regionaltog
105                    imageMap.put("l", R.drawable.lyn); //L =  Lyn
106                    imageMap.put("ic", R.drawable.ic); //IC = Intercity
107                    imageMap.put("pp", R.drawable.pp); //PP = Privatbaner (eg. odderbanen eller LokalBanen)
108                    imageMap.put("ør", R.drawable.or); //ØR = Øresundstog
109                    imageMap.put("ec", R.drawable.ec); //EC = EuroCity
110                    imageMap.put("sj", R.drawable.sj); // SJ=Svenska Jernbaner
111                    
112                    imageMap.put("a", R.drawable.stog_a);   //S-Tog: A banen #00b5f1                                
113                    imageMap.put("b", R.drawable.stog_b);   //S-Tog:B banen #5aba52
114                    imageMap.put("bx", R.drawable.stog_bx); //S-Tog:Bx banen #a4d17d
115                    imageMap.put("c", R.drawable.stog_c);   //S-Tog:C banen #f89734
116                    imageMap.put("e", R.drawable.stog_e);   //S-Tog:E banen #837eba
117                    imageMap.put("f", R.drawable.stog_f);   //S-Tog:F banen #ffc32d
118                    imageMap.put("h", R.drawable.stog_h);   //S-Tog:H banen #f05737
119                    
120    
121    
122            }
123    
124  }  }

Legend:
Removed from v.483  
changed lines
  Added in v.499

  ViewVC Help
Powered by ViewVC 1.1.20