1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| for (int b = 0; b < liste.getLength(); b++) {
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) liste.item(b);
String x = parser.getValue(e, KEY_LAT);
lat = Double.parseDouble(x);
String y = parser.getValue(e, KEY_LON);
lon = Double.parseDouble(y);
Location location2 = new Location("");
location2.setLatitude(lat);
location2.setLongitude(lon);
//on determine la distance entre le restaurant et l'utilisateur que l'on convertit en Km
double dist = Loading.location.distanceTo(location2);
double km = dist/1000;
DecimalFormat df = new DecimalFormat("000.00");
//on ajoute les information récupérer (adresse, distance,etc...) dans une HashList
map.put(KEY_ID, parser.getValue(e, KEY_ID));
map.put(KEY_ADR, parser.getValue(e, KEY_ADR));
map.put(KEY_ZIP, parser.getValue(e, KEY_ZIP));
map.put(KEY_VILLE, parser.getValue(e, KEY_VILLE));
map.put(KEY_TEL, parser.getValue(e, KEY_TEL));
map.put(KEY_NOM, parser.getValue(e, KEY_NOM));
map.put(KEY_LON, parser.getValue(e, KEY_LON));
map.put(KEY_LAT, parser.getValue(e, KEY_LAT));
String dateString = parser.getValue(e, KEY_DATE);
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
Calendar curDate = null;
try
{
curDate = Calendar.getInstance();
curDate.setTime(format.parse(dateString.replace('/','-')));
int year = curDate.get(Calendar.YEAR);
curDate.set(Calendar.YEAR, year + 2000);
curDate.set(Calendar.HOUR_OF_DAY, 0);
curDate.set(Calendar.MINUTE, 0);
curDate.set(Calendar.SECOND, 0);
curDate.set(Calendar.MILLISECOND, 0);
}
catch (ParseException ee)
{
curDate = null;
ee.printStackTrace();
}
map.put(KEY_DATE, dateString);
map.put(KEY_DIS, String.valueOf(df.format(km))+" km");
// que l'on ajoute ensuite Ã* une ArrayList que l'on va pouvoir trier
System.out.println("dayDateeeeeeeeeeeeeeeeee");
System.out.println(DateFormat.format("yyyy-MM-dd hh:mm:ss", dayDate.getTime()));
System.out.println("curDateeeeeeeeeeeeeeeeee");
System.out.println(DateFormat.format("yyyy-MM-dd hh:mm:ss", curDate.getTime()));
if (curDate.compareTo(dayDate) >= 0)
{
if ((usedDate == null) || (usedDate.compareTo(curDate) > 0))
{
restaulist.clear();
usedDate = curDate;
}
if(curDate.compareTo(usedDate) == 0)
restaulist.add(map);
}
}
Collections.sort(restaulist, new PositionComparator());
TextView lblDate = (TextView) findViewById(R.id.date);
android.text.format.DateFormat df = new android.text.format.DateFormat();
final String dateLongue = (String) df.format("EEEEEEEEEEEEEEEEE d MMMMMMMMMMMMMM yyyy", usedDate);
lblDate.setText(dateLongue);
list=(ListView)findViewById(R.id.listviewcarte);
adapter=new GpsAdapter(GpsActivity.this, restaulist);
list.setAdapter(adapter); |
Partager