1 |
package dk.thoerup.traininfo; |
package dk.thoerup.traininfo; |
2 |
|
|
3 |
|
import java.util.HashMap; |
4 |
import java.util.List; |
import java.util.List; |
5 |
|
import java.util.Map; |
6 |
|
|
7 |
import android.content.Context; |
import android.content.Context; |
8 |
import android.view.LayoutInflater; |
import android.view.LayoutInflater; |
17 |
private List<DepartureBean> departures; |
private List<DepartureBean> departures; |
18 |
LayoutInflater inflater; |
LayoutInflater inflater; |
19 |
Context context; |
Context context; |
20 |
|
|
21 |
|
static Map<String,Integer> imageMap = new HashMap<String,Integer>(); |
22 |
|
static { |
23 |
|
buildImageMap(); |
24 |
|
} |
25 |
|
|
26 |
public DepartureListAdapter(Context context) { |
public DepartureListAdapter(Context context) { |
27 |
super(); |
super(); |
28 |
this.context = context; |
this.context = context; |
29 |
|
|
30 |
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
31 |
|
|
32 |
} |
} |
33 |
|
|
34 |
public void setDepartures(List<DepartureBean> departures) { |
public void setDepartures(List<DepartureBean> departures) { |
69 |
|
|
70 |
if (station.getStatus().length() > 0 || station.getNote().length() > 0) { |
if (station.getStatus().length() > 0 || station.getNote().length() > 0) { |
71 |
ImageView image = (ImageView) root.findViewById(R.id.InfoIcon); |
ImageView image = (ImageView) root.findViewById(R.id.InfoIcon); |
72 |
image.setImageResource(R.drawable.info20); |
|
73 |
|
int iconID; |
74 |
|
if (station.getStatus().toLowerCase().indexOf("aflyst") > -1 || |
75 |
|
station.getNote().toLowerCase().indexOf("aflyst") > -1 ) { |
76 |
|
iconID = R.drawable.warn20; |
77 |
|
} else { |
78 |
|
iconID = R.drawable.info20; |
79 |
|
} |
80 |
|
|
81 |
|
image.setImageResource( iconID ); |
82 |
} |
} |
83 |
|
|
84 |
ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon); |
ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon); |
85 |
String trainNumber = station.getTrainNumber() + " "; //Ugly hack: Append space do simplify icon selection code |
String trainNumber = station.getTrainNumber().trim(); |
86 |
|
String code = trainNumber.split(" ")[0].toLowerCase(); |
87 |
if ( trainNumber.substring(0, 2).equalsIgnoreCase("ra")) { //ra = regionaltog arriva |
|
88 |
typeIcon.setImageResource(R.drawable.re); |
Integer imageId = imageMap.get(code); |
89 |
} else if ( trainNumber.substring(0, 2).equalsIgnoreCase("re")) { |
if (imageId != null) { |
90 |
typeIcon.setImageResource(R.drawable.re); |
typeIcon.setImageResource(imageId); |
91 |
} else if ( trainNumber.substring(0,1).equalsIgnoreCase("l")) { |
} else { |
|
typeIcon.setImageResource(R.drawable.lyn); |
|
|
} else if ( trainNumber.substring(0,2).equalsIgnoreCase("ic")) { |
|
|
typeIcon.setImageResource(R.drawable.ic); |
|
|
} else if ( trainNumber.substring(0,2).equalsIgnoreCase("pp")) { |
|
|
typeIcon.setImageResource(R.drawable.pp); |
|
|
} else if ( trainNumber.substring(0,2).equalsIgnoreCase("ør")) { |
|
|
typeIcon.setImageResource(R.drawable.or); |
|
|
} else if ( trainNumber.equalsIgnoreCase("a ") ) { |
|
|
typeIcon.setImageResource(R.drawable.stog_a); //S-Tog: A banen #00b5f1 |
|
|
} else if ( trainNumber.equalsIgnoreCase("b ") ) { |
|
|
typeIcon.setImageResource(R.drawable.stog_b); //S-Tog:B banen #5aba52 |
|
|
} else if ( trainNumber.equalsIgnoreCase("bx ") ) { |
|
|
typeIcon.setImageResource(R.drawable.stog_bx); //S-Tog:Bx banen #a4d17d |
|
|
} else if ( trainNumber.equalsIgnoreCase("c ") ) { |
|
|
typeIcon.setImageResource(R.drawable.stog_c); //S-Tog:C banen #f89734 |
|
|
} else if ( trainNumber.equalsIgnoreCase("e ") ) { |
|
|
typeIcon.setImageResource(R.drawable.stog_e); //S-Tog:E banen #837eba |
|
|
} else if ( trainNumber.equalsIgnoreCase("f ") ) { |
|
|
typeIcon.setImageResource(R.drawable.stog_f); //S-Tog:F banen #ffc32d |
|
|
} else if ( trainNumber.equalsIgnoreCase("h ") ) { |
|
|
typeIcon.setImageResource(R.drawable.stog_h); //S-Tog:H banen #f05737 |
|
|
} else { |
|
92 |
typeIcon.setImageResource(R.drawable.unknown); |
typeIcon.setImageResource(R.drawable.unknown); |
93 |
} |
} |
|
//Mangler: SJ=Sverige?, EC, |
|
|
|
|
|
|
|
94 |
|
|
95 |
return root; |
return root; |
96 |
} |
} |
97 |
|
|
98 |
|
private static void buildImageMap() { |
99 |
|
imageMap.put("ra", R.drawable.re); //RA = regionaltog arriva |
100 |
|
imageMap.put("re", R.drawable.re); //RE = Regionaltog |
101 |
|
imageMap.put("l", R.drawable.lyn); //L = Lyn |
102 |
|
imageMap.put("ic", R.drawable.ic); //IC = Intercity |
103 |
|
imageMap.put("pp", R.drawable.pp); //PP = Privatbaner (eg. odderbanen eller LokalBanen) |
104 |
|
imageMap.put("ør", R.drawable.or); //ØR = Øresundstog |
105 |
|
imageMap.put("ec", R.drawable.ec); //EC = EuroCity |
106 |
|
imageMap.put("sj", R.drawable.sj); // SJ=Svenska Jernbaner |
107 |
|
|
108 |
|
imageMap.put("a", R.drawable.stog_a); //S-Tog: A banen #00b5f1 |
109 |
|
imageMap.put("b", R.drawable.stog_b); //S-Tog:B banen #5aba52 |
110 |
|
imageMap.put("bx", R.drawable.stog_bx); //S-Tog:Bx banen #a4d17d |
111 |
|
imageMap.put("c", R.drawable.stog_c); //S-Tog:C banen #f89734 |
112 |
|
imageMap.put("e", R.drawable.stog_e); //S-Tog:E banen #837eba |
113 |
|
imageMap.put("f", R.drawable.stog_f); //S-Tog:F banen #ffc32d |
114 |
|
imageMap.put("h", R.drawable.stog_h); //S-Tog:H banen #f05737 |
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
} |
119 |
|
|
120 |
} |
} |