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

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

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

revision 362 by torben, Tue Sep 29 21:30:16 2009 UTC revision 1551 by torben, Thu Jul 7 20:45:17 2011 UTC
# Line 1  Line 1 
1  package dk.thoerup.traininfo;  package dk.thoerup.traininfo;
2    
 import java.util.List;  
   
3  import android.content.Context;  import android.content.Context;
4  import android.view.LayoutInflater;  import android.view.LayoutInflater;
5  import android.view.View;  import android.view.View;
6  import android.view.ViewGroup;  import android.view.ViewGroup;
7  import android.widget.BaseAdapter;  import android.widget.BaseAdapter;
8    import android.widget.TextView;
9    import dk.thoerup.android.traininfo.common.TimetableBean;
10    import dk.thoerup.android.traininfo.common.TimetableEntry;
11    
12  public class TimetableListAdapter extends BaseAdapter {  public class TimetableListAdapter extends BaseAdapter {
13    
14          private List<TimetableBean> timetable;          private TimetableBean timetable;
15          LayoutInflater inflater;          LayoutInflater inflater;
16          Context context;          Context context;
17                    
18            @Override
19            public boolean isEnabled(int position) {
20                    return ( timetable.entries.get(position).getStationEntry() != null );
21            }
22    
23          public TimetableListAdapter(Context context) {          public TimetableListAdapter(Context context) {
24                  super();                  super();
25                  this.context = context;                  this.context = context;
# Line 21  public class TimetableListAdapter extend Line 27  public class TimetableListAdapter extend
27                  inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);                  inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
28          }          }
29                    
30          public void setTimetable(List<TimetableBean> timetable) {          public void setTimetable(TimetableBean timetable) {
31                  this.timetable = timetable;                  this.timetable = timetable;
32                  notifyDataSetChanged();                  notifyDataSetChanged();
33          }          }
# Line 29  public class TimetableListAdapter extend Line 35  public class TimetableListAdapter extend
35          @Override          @Override
36          public int getCount() {          public int getCount() {
37                  if (timetable != null)                  if (timetable != null)
38                          return timetable.size();                          return timetable.entries.size();
39                  else                  else
40                          return 0;                          return 0;
41          }          }
# Line 44  public class TimetableListAdapter extend Line 50  public class TimetableListAdapter extend
50                  return position;                  return position;
51          }          }
52    
53            String getTranslated(String str) {
54                    if (str == null)
55                            return str;            
56                    
57                    str = str.replace("Aflyst", context.getString(R.string.timetablelist_cancel) );
58                    return str;
59            }
60            
61          @Override          @Override
62          public View getView(int position, View convertView, ViewGroup parent) {          public View getView(int position, View convertView, ViewGroup parent) {
63                  // TODO Auto-generated method stub                  TimetableEntry entry = timetable.entries.get(position);
64                  return null;  
65                    View root = inflater.inflate(R.layout.timetablerow , parent, false);
66                    
67                    TextView station = (TextView) root.findViewById(R.id.Station);
68                    station.setText( entry.getStation() );
69                    
70                    TextView arrival = (TextView) root.findViewById(R.id.Arrival);          
71                    arrival.setText( getTranslated(entry.getArrival()) );
72                    
73                    TextView departure = (TextView) root.findViewById(R.id.Departure);              
74                    departure.setText( getTranslated(entry.getDeparture()) );
75                    
76                    
77                    if (entry.isCurrent()) {
78                            final int bgcolor = 0xFFFFFFFF;
79                            final int fgcolor = 0xFF000000;
80                            
81                            station.setTextColor(fgcolor);
82                            arrival.setTextColor(fgcolor);
83                            departure.setTextColor(fgcolor);
84                            root.setBackgroundColor(bgcolor);
85                    }
86                    
87                    return root;
88          }          }
89    
90  }  }

Legend:
Removed from v.362  
changed lines
  Added in v.1551

  ViewVC Help
Powered by ViewVC 1.1.20