/[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 1551 - (show annotations) (download)
Thu Jul 7 20:45:17 2011 UTC (12 years, 10 months ago) by torben
File size: 2201 byte(s)
Minor cleanups (imports etc)
1 package dk.thoerup.traininfo;
2
3 import android.content.Context;
4 import android.view.LayoutInflater;
5 import android.view.View;
6 import android.view.ViewGroup;
7 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 {
13
14 private TimetableBean timetable;
15 LayoutInflater inflater;
16 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) {
24 super();
25 this.context = context;
26
27 inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
28 }
29
30 public void setTimetable(TimetableBean timetable) {
31 this.timetable = timetable;
32 notifyDataSetChanged();
33 }
34
35 @Override
36 public int getCount() {
37 if (timetable != null)
38 return timetable.entries.size();
39 else
40 return 0;
41 }
42
43 @Override
44 public Object getItem(int position) {
45 return null;
46 }
47
48 @Override
49 public long getItemId(int position) {
50 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
62 public View getView(int position, View convertView, ViewGroup parent) {
63 TimetableEntry entry = timetable.entries.get(position);
64
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 }

  ViewVC Help
Powered by ViewVC 1.1.20