/[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 253 by torben, Mon Aug 10 16:58:22 2009 UTC revision 1434 by torben, Tue May 3 16:28:56 2011 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 9  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            
23            static Map<String,Integer> imageMap = new HashMap<String,Integer>();
24            static {
25                    buildImageMap();
26            }
27            
28          public DepartureListAdapter(Context context) {          public DepartureListAdapter(Context context) {
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            public void setShowDetails(boolean showDetails) {
36                    this.showDetails = showDetails;
37            }
38            
39            public boolean getShowDetails() {
40                    return showDetails;
41            }
42            
43            public void toggleShowDetails() {
44                    showDetails = !showDetails;
45                    notifyDataSetChanged();
46          }          }
47                    
48          public void setDepartures(List<DepartureBean> departures) {          public void setDepartures(List<DepartureEntry> departures) {
49                  this.departures = departures;                  this.departures = departures;
50                  notifyDataSetChanged();                  notifyDataSetChanged();
51          }          }
# Line 35  public class DepartureListAdapter extend Line 58  public class DepartureListAdapter extend
58                          return 0;                          return 0;
59          }          }
60                    
61          public DepartureBean getDeparture(int position) {          public DepartureEntry getDeparture(int position) {
62                  return departures.get(position);                  return departures.get(position);
63          }          }
64    
# Line 51  public class DepartureListAdapter extend Line 74  public class DepartureListAdapter extend
74    
75          @Override          @Override
76          public View getView(int position, View convertView, ViewGroup parent) {          public View getView(int position, View convertView, ViewGroup parent) {
77                  DepartureBean station = departures.get(position);                  DepartureEntry station = departures.get(position);
78    
79                  View root = inflater.inflate(R.layout.departurerow , parent, false);                  View root = inflater.inflate(R.layout.departurerow , parent, false);
80                                    
81                  ((TextView) root.findViewById(R.id.Time)).setText(station.getTime());                  ((TextView) root.findViewById(R.id.Time)).setText(station.getTime());
82                  ((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination());                  ((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination());
83                                    
84                  if (station.getStatus().length() > 0 || station.getNote().length() > 0) {                  
85                    if ( (station.getStatus() != null && station.getStatus().length() > 0) || (station.getNote() != null && station.getNote().length() > 0) ) {
86                          ImageView image = (ImageView) root.findViewById(R.id.InfoIcon);                          ImageView image = (ImageView) root.findViewById(R.id.InfoIcon);
87                          image.setImageResource(R.drawable.info20);                          
88                            
89                            String status = (station.getStatus() != null) ? station.getStatus().toLowerCase() : "";
90                            String note = (station.getNote() != null) ? station.getNote().toLowerCase() : "";
91                            
92                            int iconID;
93                            if (status.indexOf("aflyst") > -1 || note.indexOf("aflyst") > -1 ) {
94                                    iconID = R.drawable.warn20;
95                            } 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
96                                    iconID = R.drawable.warnyellow20;
97                            } else {
98                                    iconID = R.drawable.info20;
99                            }
100                                    
101                            image.setImageResource( iconID );
102                  }                  }
103                                    
104                  ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon);                  ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon);
105                  String trainNumber = station.getTrainNumber();                  String trainNumber = station.getTrainNumber().trim();
106                  if (trainNumber.length() >= 2) {                  String trainParts[] = trainNumber.split(" ");
107                          if ( trainNumber.substring(0, 2).equalsIgnoreCase("ra")) { //ra = regionaltog arriva                  String code = trainParts[0].toLowerCase();
108                                  typeIcon.setImageResource(R.drawable.retog);          
109                          } else if ( trainNumber.substring(0, 2).equalsIgnoreCase("re")) {                  if (showDetails) {
110                                  typeIcon.setImageResource(R.drawable.retog);                          root.findViewById(R.id.departureRow2).setVisibility( View.VISIBLE );                    
111                          } else if (trainNumber.substring(0,1).equalsIgnoreCase("l")) {                          ((TextView) root.findViewById(R.id.TrainNumber)).setText(trainNumber);
112                                  typeIcon.setImageResource(R.drawable.lyntog);                          ((TextView) root.findViewById(R.id.Origin)).setText( station.getOrigin() );
                         } else if (trainNumber.substring(0,2).equalsIgnoreCase("ic")) {  
                                 typeIcon.setImageResource(R.drawable.ictog);  
                         } else if (trainNumber.substring(0,2).equalsIgnoreCase("pp")) {  
                                 typeIcon.setImageResource(R.drawable.pptog);  
                         }  
                 } else {  
                         //if each line needs seperate icons, switch on the first(and only( character  
                         typeIcon.setImageResource(R.drawable.stog);  
113                  }                  }
114                                    
115                                    Integer imageId = imageMap.get(code);
116                    if (imageId != null) {
117                            typeIcon.setImageResource(imageId);
118                    } else {
119                            typeIcon.setImageResource(R.drawable.unknown);
120                    }
121                                    
122                  return root;                  return root;
123          }          }
124            
125            //TODO: all these traintypes / icons should be explained somewhere
126            private static void buildImageMap() {
127                    imageMap.put("ra", R.drawable.re); //RA = regionaltog arriva
128                    imageMap.put("re", R.drawable.re); //RE = Regionaltog
129                    imageMap.put("l", R.drawable.lyn); //L =  Lyn
130                    imageMap.put("ic", R.drawable.ic); //IC = Intercity
131                    imageMap.put("pp", R.drawable.pp); //PP = Privatbaner (eg. odderbanen eller LokalBanen)
132                    imageMap.put("ør", R.drawable.or); //ØR = Øresundstog
133                    imageMap.put("ec", R.drawable.ec); //EC = EuroCity
134                    imageMap.put("sj", R.drawable.sj); // SJ=Svenska Jernbaner
135                    imageMap.put("ie", R.drawable.ie);
136                    //TODO: missing IL: IntercityLyn Nonstop
137                    
138                    imageMap.put("a", R.drawable.stog_a);   //S-Tog: A banen #00b5f1                                
139                    imageMap.put("b", R.drawable.stog_b);   //S-Tog:B banen #5aba52
140                    imageMap.put("bx", R.drawable.stog_bx); //S-Tog:Bx banen #a4d17d
141                    imageMap.put("c", R.drawable.stog_c);   //S-Tog:C banen #f89734
142                    imageMap.put("e", R.drawable.stog_e);   //S-Tog:E banen #837eba
143                    imageMap.put("f", R.drawable.stog_f);   //S-Tog:F banen #ffc32d
144                    imageMap.put("h", R.drawable.stog_h);   //S-Tog:H banen #f05737
145                    
146    
147    
148            }
149    
150  }  }

Legend:
Removed from v.253  
changed lines
  Added in v.1434

  ViewVC Help
Powered by ViewVC 1.1.20