--- android/TrainInfo/src/dk/thoerup/traininfo/DepartureListAdapter.java 2009/08/09 17:46:09 244 +++ android/TrainInfo/src/dk/thoerup/traininfo/DepartureListAdapter.java 2009/10/29 19:50:02 491 @@ -1,6 +1,8 @@ package dk.thoerup.traininfo; +import java.util.HashMap; import java.util.List; +import java.util.Map; import android.content.Context; import android.view.LayoutInflater; @@ -15,11 +17,18 @@ private List departures; LayoutInflater inflater; Context context; + + static Map imageMap = new HashMap(); + static { + buildImageMap(); + } + public DepartureListAdapter(Context context) { super(); this.context = context; inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + } public void setDepartures(List departures) { @@ -59,12 +68,53 @@ ((TextView) root.findViewById(R.id.Destination)).setText(station.getDestination()); if (station.getStatus().length() > 0 || station.getNote().length() > 0) { - ImageView image = (ImageView) root.findViewById(R.id.Icon); - image.setImageResource(R.drawable.info20); + ImageView image = (ImageView) root.findViewById(R.id.InfoIcon); + + int iconID; + if (station.getStatus().toLowerCase().indexOf("aflyst") > -1 || + station.getNote().toLowerCase().indexOf("aflyst") > -1 ) { + iconID = R.drawable.warn20; + } else { + iconID = R.drawable.info20; + } + + image.setImageResource( iconID ); } + ImageView typeIcon = (ImageView) root.findViewById(R.id.TypeIcon); + String trainNumber = station.getTrainNumber().trim(); + String code = trainNumber.split(" ")[0].toLowerCase(); + + Integer imageId = imageMap.get(code); + if (imageId != null) { + typeIcon.setImageResource(imageId); + } else { + typeIcon.setImageResource(R.drawable.unknown); + } return root; } + + private static void buildImageMap() { + imageMap.put("ra", R.drawable.re); //RA = regionaltog arriva + imageMap.put("re", R.drawable.re); //RE = Regionaltog + imageMap.put("l", R.drawable.lyn); //L = Lyn + imageMap.put("ic", R.drawable.ic); //IC = Intercity + imageMap.put("pp", R.drawable.pp); //PP = Privatbaner (eg. odderbanen eller LokalBanen) + imageMap.put("ør", R.drawable.or); //ØR = Øresundstog + imageMap.put("ec", R.drawable.ec); //EC = EuroCity + imageMap.put("sj", R.drawable.sj); // SJ=Svenska Jernbaner + + imageMap.put("a", R.drawable.stog_a); //S-Tog: A banen #00b5f1 + imageMap.put("b", R.drawable.stog_b); //S-Tog:B banen #5aba52 + imageMap.put("bx", R.drawable.stog_bx); //S-Tog:Bx banen #a4d17d + imageMap.put("c", R.drawable.stog_c); //S-Tog:C banen #f89734 + imageMap.put("e", R.drawable.stog_e); //S-Tog:E banen #837eba + imageMap.put("f", R.drawable.stog_f); //S-Tog:F banen #ffc32d + imageMap.put("h", R.drawable.stog_h); //S-Tog:H banen #f05737 + + + + } }