/[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 491 by torben, Thu Oct 29 19:50:02 2009 UTC revision 1963 by torben, Sat Mar 30 10:31:12 2013 UTC
# Line 11  import android.view.ViewGroup; Line 11  import android.view.ViewGroup;
11  import android.widget.BaseAdapter;  import android.widget.BaseAdapter;
12  import android.widget.ImageView;  import android.widget.ImageView;
13  import android.widget.TextView;  import android.widget.TextView;
14    import dk.thoerup.android.traininfo.common.DepartureEntry;
15    
16  public class DepartureListAdapter extends BaseAdapter {  public class DepartureListAdapter extends BaseAdapter {
17    
18          private List<DepartureBean> departures;          boolean showDetails = false;
19            private List<DepartureEntry> departures;
20          LayoutInflater inflater;          LayoutInflater inflater;
21          Context context;          Context context;
22                    
# Line 27  public class DepartureListAdapter extend Line 29  public class DepartureListAdapter extend
29                  super();                  super();
30                  this.context = context;                  this.context = context;
31                                    
32                  inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);                  inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);          
33            }
34                                    
35    
36            public void toggleShowDetails() {
37                    showDetails = !showDetails;
38                    notifyDataSetChanged();
39          }          }
40                    
41          public void setDepartures(List<DepartureBean> departures) {          public void setDepartures(List<DepartureEntry> departures) {
42                  this.departures = departures;                  this.departures = departures;
43                  notifyDataSetChanged();                  notifyDataSetChanged();
44          }          }
# Line 44  public class DepartureListAdapter extend Line 51  public class DepartureListAdapter extend
51                          return 0;                          return 0;
52          }          }
53                    
54          public DepartureBean getDeparture(int position) {          public DepartureEntry getDeparture(int position) {
55                  return departures.get(position);                  return departures.get(position);
56          }          }
57    
# Line 60  public class DepartureListAdapter extend Line 67  public class DepartureListAdapter extend
67    
68          @Override          @Override
69          public View getView(int position, View convertView, ViewGroup parent) {          public View getView(int position, View convertView, ViewGroup parent) {
70                  DepartureBean station = departures.get(position);                  DepartureEntry station = departures.get(position);
71    
72                  View root = inflater.inflate(R.layout.departurerow , parent, false);                  View root = inflater.inflate(R.layout.departurerow , parent, false);
73                                    
74                  ((TextView) root.findViewById(R.id.Time)).setText(station.getTime());                  ((TextView) root.findViewById(R.id.Time)).setText(station.getTime());
75                  ((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination());                  ((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination());
76                                    
77                  if (station.getStatus().length() > 0 || station.getNote().length() > 0) {                  //Platform source'n TritInfo er ikke perfekt - så brug den ikke indtil videre
78                    //((TextView) root.findViewById(R.id.Platform)).setText(station.getPlatform());
79                    
80                    if ( (station.getStatus() != null && station.getStatus().length() > 0) || (station.getNote() != null && station.getNote().length() > 0) ) {
81                          ImageView image = (ImageView) root.findViewById(R.id.InfoIcon);                          ImageView image = (ImageView) root.findViewById(R.id.InfoIcon);
82                                                    
83                            
84                            String status = (station.getStatus() != null) ? station.getStatus().toLowerCase() : "";
85                            String note = (station.getNote() != null) ? station.getNote().toLowerCase() : "";
86                            
87                          int iconID;                          int iconID;
88                          if (station.getStatus().toLowerCase().indexOf("aflyst") > -1 ||                          if (status.indexOf("aflyst") > -1 || note.indexOf("aflyst") > -1 ) {
                                         station.getNote().toLowerCase().indexOf("aflyst") > -1 ) {  
89                                  iconID = R.drawable.warn20;                                  iconID = R.drawable.warn20;
90                            } 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
91                                    iconID = R.drawable.warnyellow20;
92                          } else {                          } else {
93                                  iconID = R.drawable.info20;                                  iconID = R.drawable.info20;
94                          }                          }
# Line 83  public class DepartureListAdapter extend Line 98  public class DepartureListAdapter extend
98                                    
99                  ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon);                  ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon);
100                  String trainNumber = station.getTrainNumber().trim();                  String trainNumber = station.getTrainNumber().trim();
101                  String code = trainNumber.split(" ")[0].toLowerCase();                  String trainParts[] = trainNumber.split(" ");
102                    String code = trainParts[0].toLowerCase();
103                    
104                    if (showDetails) {
105                            root.findViewById(R.id.departureRow2).setVisibility( View.VISIBLE );                    
106                            ((TextView) root.findViewById(R.id.TrainNumber)).setText(trainNumber);
107                            ((TextView) root.findViewById(R.id.Origin)).setText( station.getOrigin() );
108                    }
109                    
110                  Integer imageId = imageMap.get(code);                  Integer imageId = imageMap.get(code);
111                  if (imageId != null) {                  if (imageId != null) {
112                          typeIcon.setImageResource(imageId);                          typeIcon.setImageResource(imageId);
# Line 95  public class DepartureListAdapter extend Line 117  public class DepartureListAdapter extend
117                  return root;                  return root;
118          }          }
119                    
120            //TODO: all these traintypes / icons should be explained somewhere
121          private static void buildImageMap() {          private static void buildImageMap() {
122                  imageMap.put("ra", R.drawable.re); //RA = regionaltog arriva                  imageMap.put("ec", R.drawable.ec); //EC = EuroCity
123                  imageMap.put("re", R.drawable.re); //RE = Regionaltog                  // Missing FP ?
                 imageMap.put("l", R.drawable.lyn); //L =  Lyn  
124                  imageMap.put("ic", R.drawable.ic); //IC = Intercity                  imageMap.put("ic", R.drawable.ic); //IC = Intercity
125                    imageMap.put("il", R.drawable.il); //IntercityLyn Nonstop
126                    // Missing Int ?
127                    // Missing IR ?
128                    imageMap.put("l", R.drawable.lyn); //L =  Lyn
129                  imageMap.put("pp", R.drawable.pp); //PP = Privatbaner (eg. odderbanen eller LokalBanen)                  imageMap.put("pp", R.drawable.pp); //PP = Privatbaner (eg. odderbanen eller LokalBanen)
130                    // Missing PX
131                    imageMap.put("ra", R.drawable.re); //RA = regionaltog arriva
132                    imageMap.put("re", R.drawable.re); //RE = Regionaltog          
133                  imageMap.put("ør", R.drawable.or); //ØR = Øresundstog                  imageMap.put("ør", R.drawable.or); //ØR = Øresundstog
134                  imageMap.put("ec", R.drawable.ec); //EC = EuroCity                                                          
135                  imageMap.put("sj", R.drawable.sj); // SJ=Svenska Jernbaner                  imageMap.put("sj", R.drawable.sj); //SJ=Svenska Jernbaner -- not mentioned on bane.dk
136                                    imageMap.put("ie", R.drawable.ie); //what's this ?? -- not mentioned on bane.dk
137                  imageMap.put("a", R.drawable.stog_a);   //S-Tog: A banen #00b5f1                                                  
138                  imageMap.put("b", R.drawable.stog_b);   //S-Tog:B banen #5aba52                  //Missing IB ? -- not mentioned on bane.dk
139                  imageMap.put("bx", R.drawable.stog_bx); //S-Tog:Bx banen #a4d17d                  //Missing RX ? -- not mentioned on bane.dk
140                  imageMap.put("c", R.drawable.stog_c);   //S-Tog:C banen #f89734  
141                  imageMap.put("e", R.drawable.stog_e);   //S-Tog:E banen #837eba                  for (int i=0; i<=5; i++) {
142                  imageMap.put("f", R.drawable.stog_f);   //S-Tog:F banen #ffc32d                          String add = (i==0) ? "" : "" + i;
143                  imageMap.put("h", R.drawable.stog_h);   //S-Tog:H banen #f05737                  
144                                            imageMap.put("a" + add, R.drawable.stog_a);   //S-Tog: A banen #00b5f1                          
145                            imageMap.put("b" + add, R.drawable.stog_b);   //S-Tog:B banen #5aba52
146                            imageMap.put("bx" + add, R.drawable.stog_bx); //S-Tog:Bx banen #a4d17d
147                            imageMap.put("c" + add, R.drawable.stog_c);   //S-Tog:C banen #f89734
148                            imageMap.put("e" + add, R.drawable.stog_e);   //S-Tog:E banen #837eba
149                            imageMap.put("f" + add, R.drawable.stog_f);   //S-Tog:F banen #ffc32d
150                            imageMap.put("h" + add, R.drawable.stog_h);   //S-Tog:H banen #f05737
151                    }
152    
153    
154          }          }

Legend:
Removed from v.491  
changed lines
  Added in v.1963

  ViewVC Help
Powered by ViewVC 1.1.20