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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1257 - (show annotations) (download)
Mon Apr 4 15:28:12 2011 UTC (13 years, 1 month ago) by torben
File size: 2221 byte(s)
Begin a more complete translation
1 package dk.thoerup.traininfo;
2
3 import android.content.Context;
4 import android.util.Log;
5 import android.view.LayoutInflater;
6 import android.view.View;
7 import android.view.ViewGroup;
8 import android.widget.BaseAdapter;
9 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 {
14
15 private TimetableBean timetable;
16 LayoutInflater inflater;
17 Context context;
18
19 @Override
20 public boolean isEnabled(int position) {
21 return ( timetable.entries.get(position).getStationId() != -1 );
22 }
23
24 public TimetableListAdapter(Context context) {
25 super();
26 this.context = context;
27
28 inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
29 }
30
31 public void setTimetable(TimetableBean timetable) {
32 this.timetable = timetable;
33 notifyDataSetChanged();
34 }
35
36 @Override
37 public int getCount() {
38 if (timetable != null)
39 return timetable.entries.size();
40 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 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
63 public View getView(int position, View convertView, ViewGroup parent) {
64 TimetableEntry entry = timetable.entries.get(position);
65
66 View root = inflater.inflate(R.layout.timetablerow , parent, false);
67
68 TextView station = (TextView) root.findViewById(R.id.Station);
69 station.setText( entry.getStation() );
70
71 TextView arrival = (TextView) root.findViewById(R.id.Arrival);
72 arrival.setText( getTranslated(entry.getArrival()) );
73
74 TextView departure = (TextView) root.findViewById(R.id.Departure);
75 departure.setText( getTranslated(entry.getDeparture()) );
76
77
78 if (entry.isCurrent()) {
79 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 }
90
91 }

  ViewVC Help
Powered by ViewVC 1.1.20