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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1257 - (hide annotations) (download)
Mon Apr 4 15:28:12 2011 UTC (13 years, 2 months ago) by torben
File size: 2221 byte(s)
Begin a more complete translation
1 torben 362 package dk.thoerup.traininfo;
2    
3     import android.content.Context;
4 torben 1257 import android.util.Log;
5 torben 362 import android.view.LayoutInflater;
6     import android.view.View;
7     import android.view.ViewGroup;
8     import android.widget.BaseAdapter;
9 torben 365 import android.widget.TextView;
10 torben 1066 import dk.thoerup.android.traininfo.common.TimetableBean;
11     import dk.thoerup.android.traininfo.common.TimetableEntry;
12 torben 362
13     public class TimetableListAdapter extends BaseAdapter {
14    
15 torben 1066 private TimetableBean timetable;
16 torben 362 LayoutInflater inflater;
17     Context context;
18    
19 torben 366 @Override
20     public boolean isEnabled(int position) {
21 torben 1066 return ( timetable.entries.get(position).getStationId() != -1 );
22 torben 366 }
23    
24 torben 362 public TimetableListAdapter(Context context) {
25     super();
26     this.context = context;
27    
28     inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
29     }
30    
31 torben 1066 public void setTimetable(TimetableBean timetable) {
32 torben 362 this.timetable = timetable;
33     notifyDataSetChanged();
34     }
35    
36     @Override
37     public int getCount() {
38     if (timetable != null)
39 torben 1066 return timetable.entries.size();
40 torben 362 else
41     return 0;
42     }
43    
44     @Override
45     public Object getItem(int position) {
46     return null;
47     }
48    
49     @Override
50     public long getItemId(int position) {
51     return position;
52     }
53    
54 torben 1257 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 torben 362 @Override
63     public View getView(int position, View convertView, ViewGroup parent) {
64 torben 1066 TimetableEntry entry = timetable.entries.get(position);
65 torben 365
66 torben 491 View root = inflater.inflate(R.layout.timetablerow , parent, false);
67 torben 365
68     TextView station = (TextView) root.findViewById(R.id.Station);
69 torben 1257 station.setText( entry.getStation() );
70 torben 365
71     TextView arrival = (TextView) root.findViewById(R.id.Arrival);
72 torben 1257 arrival.setText( getTranslated(entry.getArrival()) );
73 torben 365
74     TextView departure = (TextView) root.findViewById(R.id.Departure);
75 torben 1257 departure.setText( getTranslated(entry.getDeparture()) );
76 torben 365
77    
78 torben 1066 if (entry.isCurrent()) {
79 torben 365 final int bgcolor = 0xFFFFFFFF;
80     final int fgcolor = 0xFF000000;
81    
82     station.setTextColor(fgcolor);
83     arrival.setTextColor(fgcolor);
84     departure.setTextColor(fgcolor);
85     root.setBackgroundColor(bgcolor);
86     }
87    
88     return root;
89 torben 362 }
90    
91     }

  ViewVC Help
Powered by ViewVC 1.1.20