/[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 840 by torben, Fri Jun 11 18:46:46 2010 UTC revision 1257 by torben, Mon Apr 4 15:28:12 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.util.Log;
5  import android.view.LayoutInflater;  import android.view.LayoutInflater;
6  import android.view.View;  import android.view.View;
7  import android.view.ViewGroup;  import android.view.ViewGroup;
8  import android.widget.BaseAdapter;  import android.widget.BaseAdapter;
9  import android.widget.TextView;  import android.widget.TextView;
10    import dk.thoerup.android.traininfo.common.TimetableBean;
11    import dk.thoerup.android.traininfo.common.TimetableEntry;
12    
13  public class TimetableListAdapter extends BaseAdapter {  public class TimetableListAdapter extends BaseAdapter {
14    
15          private List<TimetableBean> timetable;          private TimetableBean timetable;
16          LayoutInflater inflater;          LayoutInflater inflater;
17          Context context;          Context context;
18                    
19          @Override          @Override
20          public boolean isEnabled(int position) {          public boolean isEnabled(int position) {
21                  return ( timetable.get(position).getStationId() != -1 );                  return ( timetable.entries.get(position).getStationId() != -1 );
22          }          }
23    
24          public TimetableListAdapter(Context context) {          public TimetableListAdapter(Context context) {
# Line 27  public class TimetableListAdapter extend Line 28  public class TimetableListAdapter extend
28                  inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);                  inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
29          }          }
30                    
31          public void setTimetable(List<TimetableBean> timetable) {          public void setTimetable(TimetableBean timetable) {
32                  this.timetable = timetable;                  this.timetable = timetable;
33                  notifyDataSetChanged();                  notifyDataSetChanged();
34          }          }
# Line 35  public class TimetableListAdapter extend Line 36  public class TimetableListAdapter extend
36          @Override          @Override
37          public int getCount() {          public int getCount() {
38                  if (timetable != null)                  if (timetable != null)
39                          return timetable.size();                          return timetable.entries.size();
40                  else                  else
41                          return 0;                          return 0;
42          }          }
# Line 50  public class TimetableListAdapter extend Line 51  public class TimetableListAdapter extend
51                  return position;                  return position;
52          }          }
53    
54            String getTranslated(String str) {
55                    if (str == null)
56                            return str;            
57                    
58                    str = str.replace("Aflyst", context.getString(R.string.timetablelist_cancel) );
59                    return str;
60            }
61            
62          @Override          @Override
63          public View getView(int position, View convertView, ViewGroup parent) {          public View getView(int position, View convertView, ViewGroup parent) {
64                  TimetableBean timetableBean = timetable.get(position);                  TimetableEntry entry = timetable.entries.get(position);
65    
66                  View root = inflater.inflate(R.layout.timetablerow , parent, false);                  View root = inflater.inflate(R.layout.timetablerow , parent, false);
67                                    
68                  TextView station = (TextView) root.findViewById(R.id.Station);                  TextView station = (TextView) root.findViewById(R.id.Station);
69                  station.setText(timetableBean.getStation());                  station.setText( entry.getStation() );
70                                    
71                  TextView arrival = (TextView) root.findViewById(R.id.Arrival);                            TextView arrival = (TextView) root.findViewById(R.id.Arrival);          
72                  arrival.setText(timetableBean.getArrival());                  arrival.setText( getTranslated(entry.getArrival()) );
73                                    
74                  TextView departure = (TextView) root.findViewById(R.id.Departure);                                TextView departure = (TextView) root.findViewById(R.id.Departure);              
75                  departure.setText(timetableBean.getDeparture());                  departure.setText( getTranslated(entry.getDeparture()) );
76                                    
77                                    
78                  if (timetableBean.isCurrent()) {                  if (entry.isCurrent()) {
79                          final int bgcolor = 0xFFFFFFFF;                          final int bgcolor = 0xFFFFFFFF;
80                          final int fgcolor = 0xFF000000;                          final int fgcolor = 0xFF000000;
81                                                    

Legend:
Removed from v.840  
changed lines
  Added in v.1257

  ViewVC Help
Powered by ViewVC 1.1.20