Back to project page Go2-Rennes.
The source code is released under:
GNU General Public License
If you think the Android project Go2-Rennes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/******************************************************************************* * Copyright (c) 2011 Michel DAVID mimah35-at-gmail.com * //from ww w . jav a 2 s. co m * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. ******************************************************************************/ package fr.gotorennes; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.DialogInterface.OnCancelListener; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.text.Html; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.TextView; import fr.gotorennes.AbstractMapActivity.Etape; import fr.gotorennes.AbstractMapActivity.Itineraire; import fr.gotorennes.AbstractMapActivity.Location; import fr.gotorennes.AbstractMapActivity.TypeEtape; import fr.gotorennes.domain.Arret; import fr.gotorennes.domain.Circuit; import fr.gotorennes.domain.Ligne; import fr.gotorennes.domain.MetroStation; import fr.gotorennes.domain.Station; public class ItineraireBusResultActivity extends AbstractActivity { private boolean departOk = true; private boolean arriveeOk = true; private AsyncTask<String, String, List<Itineraire>> t; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.itineraires); } @Override protected void init(Intent intent) { final String adresseDepart = intent.getStringExtra("depart"); final String adresseArrivee = intent.getStringExtra("arrivee"); final Calendar calendrier = Calendar.getInstance(); calendrier.setTimeInMillis(intent.getLongExtra("date", System.currentTimeMillis())); final boolean directsUniquement = intent.getBooleanExtra("direct", false); final ProgressDialog waitDialog = ProgressDialog.show(this, getString(R.string.titre), getString(R.string.itineraire), true, true, new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if(t != null){ t.cancel(true); } finish(); } }); t = new AsyncTask<String, String, List<Itineraire>>() { @Override protected List<Itineraire> doInBackground(String... params) { List<Itineraire> itineraires = new ArrayList<Itineraire>(); int time = Arret.getTime(calendrier, false); int tempsMarcheMaximum = 10; publishProgress(getString(R.string.geolocalisationDepart)); Location depart = AbstractMapActivity.getLocation(getApplicationContext(), adresseDepart); if(depart == null) { departOk = false; return null; } publishProgress(getString(R.string.geolocalisationArrivee)); Location arrivee = AbstractMapActivity.getLocation(getApplicationContext(), adresseArrivee); if(arrivee == null) { arriveeOk = false; return null; } int tempsMarche = AbstractMapActivity.getTempsMarche(depart, arrivee); if (tempsMarche <= tempsMarcheMaximum) { publishProgress(getString(R.string.calculItinerairePieton)); itineraires.add( getItinerairePieton(time, depart, time + tempsMarche, arrivee) ); return itineraires; } publishProgress(getString(R.string.rechercheStationsDepart)); List<Station> stationsDepart = goToRennes.getBusDao().getStationsLesPlusProches(depart.latitude, depart.longitude); publishProgress(getString(R.string.rechercheStationsArrivee)); List<Station> stationsArrivee = goToRennes.getBusDao().getStationsLesPlusProches(arrivee.latitude, arrivee.longitude); List<Station> stationsCommunes = new ArrayList<Station>( stationsDepart ); stationsCommunes.retainAll(stationsArrivee); if(!stationsCommunes.isEmpty()) { publishProgress(getString(R.string.calculItinerairePieton)); itineraires.add( getItinerairePieton(time, depart, time + tempsMarche, arrivee) ); return itineraires; } publishProgress(getString(R.string.enregistrementCircuitsDepart)); Map<Circuit, Station> stationsDepartCircuit = new HashMap<Circuit, Station>(); for(Station stationDepart : stationsDepart) { List<Circuit> circuitsDepart = goToRennes.getBusDao().getCircuits(stationDepart); for(Circuit circuitDepart : circuitsDepart) { if(stationsDepartCircuit.containsKey(circuitDepart)) { Station stationEnregistree = stationsDepartCircuit.get(circuitDepart); double distance1 = AbstractMapActivity.getDistance(depart.latitude, depart.longitude, stationEnregistree.latitude, stationEnregistree.longitude); double distance2 = AbstractMapActivity.getDistance(depart.latitude, depart.longitude, stationDepart.latitude, stationDepart.longitude); if(distance2 < distance1) { stationsDepartCircuit.put(circuitDepart, stationDepart); } } else { stationsDepartCircuit.put(circuitDepart, stationDepart); } } } publishProgress(getString(R.string.enregistrementCircuitsArrivee)); Map<Circuit, Station> stationsArriveeCircuit = new HashMap<Circuit, Station>(); for(Station stationArrivee : stationsArrivee) { List<Circuit> circuitsArrivee = goToRennes.getBusDao().getCircuits(stationArrivee); for(Circuit circuitArrivee : circuitsArrivee) { if(stationsArriveeCircuit.containsKey(circuitArrivee)) { Station stationEnregistree = stationsArriveeCircuit.get(circuitArrivee); double distance1 = AbstractMapActivity.getDistance(arrivee.latitude, arrivee.longitude, stationEnregistree.latitude, stationEnregistree.longitude); double distance2 = AbstractMapActivity.getDistance(arrivee.latitude, arrivee.longitude, stationArrivee.latitude, stationArrivee.longitude); if(distance2 < distance1) { stationsArriveeCircuit.put(circuitArrivee, stationArrivee); } } else { stationsArriveeCircuit.put(circuitArrivee, stationArrivee); } } } publishProgress(getString(R.string.rechercheCircuitsDirects)); List<Circuit> circuitsCommuns = new ArrayList<Circuit>(stationsDepartCircuit.keySet()); circuitsCommuns.retainAll(stationsArriveeCircuit.keySet()); if(!circuitsCommuns.isEmpty()) { for(Iterator<Circuit> iter = circuitsCommuns.iterator(); iter.hasNext();) { Circuit circuit = iter.next(); Station stationDepart = stationsDepartCircuit.get(circuit); Station stationArrivee = stationsArriveeCircuit.get(circuit); if(!goToRennes.getBusDao().isCircuitValid(circuit, stationDepart, stationArrivee)) { iter.remove(); } } } for(int i = 1; i <= circuitsCommuns.size(); i++) { publishProgress(getString(R.string.rechercheHorairesCircuit) + " " + (100 * i / circuitsCommuns.size()) + "%" ); Circuit circuit = circuitsCommuns.get(i-1); Station stationDepart = stationsDepartCircuit.get(circuit); Location locationStationDepart = new Location(stationDepart, circuit.nom, getApplicationContext()); int tempsMarcheDepart = AbstractMapActivity.getTempsMarche(depart, locationStationDepart); Station stationArrivee = stationsArriveeCircuit.get(circuit); Location locationStationArrivee = new Location(stationArrivee, circuit.nom, getApplicationContext()); int tempsMarcheArrivee = AbstractMapActivity.getTempsMarche(locationStationArrivee, arrivee); Calendar calendrierArret = Calendar.getInstance(); calendrierArret.setTime(calendrier.getTime()); calendrierArret.add(Calendar.MINUTE, tempsMarcheDepart ); Ligne ligne = goToRennes.getBusDao().getLigne(circuit.idLigne); Arret arretDepart = goToRennes.getBusDao().getArret(stationsDepartCircuit.get(circuit).id, circuit.id, calendrierArret, ligne.isLigneDeNuit()); if(arretDepart == null) { continue; } Arret arretArrivee = goToRennes.getBusDao().getArret(arretDepart.idTrajet, stationsArriveeCircuit.get(circuit).id); if(arretArrivee == null) { continue; } //Cas bizarre... if(arretArrivee.arrivee < arretDepart.arrivee) { continue; } Etape etapePietonDepart = getEtape(TypeEtape.PIETON, time, depart, time + tempsMarcheDepart, locationStationDepart); Etape etapeBus = getEtape(TypeEtape.BUS, arretDepart.depart, locationStationDepart, arretArrivee.arrivee, locationStationArrivee, ligne.code); etapeBus.bitmapIcon = goToRennes.getBusStationService().getBitmapIcon(getApplicationContext(), circuit.idLigne); etapeBus.bitmapCarre = ligne.isLogoCarre(); Etape etapePietonArrivee = getEtape(TypeEtape.PIETON, etapeBus.arrivee, locationStationArrivee, etapeBus.arrivee + tempsMarcheArrivee, arrivee); itineraires.add( new Itineraire(etapePietonDepart, etapeBus, etapePietonArrivee) ); } MetroStation stationMetroDepart = null; Location locationStationMetroDepart = null; MetroStation stationMetroArrivee = null; Location locationStationMetroArrivee = null; boolean hasMetroDirect = false; int attenteMoyenneMetro = 2; if(time >= 315 && time < 1470) { //Heures d'ouverture du mtro publishProgress(getString(R.string.rechercheCircuitMetro)); List<MetroStation> stationsMetroDepart = goToRennes.getMetroStationService().getProximityMetroStations(depart.latitude, depart.longitude); if(stationsMetroDepart != null && !stationsMetroDepart.isEmpty()) { stationMetroDepart = stationsMetroDepart.get(0); locationStationMetroDepart = new Location(stationMetroDepart, null, getApplicationContext()); if(AbstractMapActivity.getTempsMarche(depart, locationStationMetroDepart) > tempsMarcheMaximum) { stationMetroDepart = null; locationStationMetroDepart = null; } } List<MetroStation> stationsMetroArrivee = goToRennes.getMetroStationService().getProximityMetroStations(arrivee.latitude, arrivee.longitude); if(stationsMetroArrivee != null && !stationsMetroArrivee.isEmpty()) { stationMetroArrivee = stationsMetroArrivee.get(0); locationStationMetroArrivee = new Location(stationMetroArrivee, null, getApplicationContext()); if(AbstractMapActivity.getTempsMarche(locationStationMetroArrivee, arrivee) > tempsMarcheMaximum) { stationMetroArrivee = null; locationStationMetroArrivee = null; } } if(stationMetroDepart != null && stationMetroArrivee != null ) { if(!stationMetroDepart.equals(stationMetroArrivee)) { int tempsMarcheDepart = AbstractMapActivity.getTempsMarche(depart, locationStationMetroDepart); int tempsMarcheArrivee = AbstractMapActivity.getTempsMarche(locationStationMetroArrivee, arrivee); int tempsParcours = Math.abs(stationMetroArrivee.sequence - stationMetroDepart.sequence) + 2; if(tempsMarcheDepart + tempsParcours + tempsMarcheDepart + attenteMoyenneMetro < tempsMarche) { Etape etapePietonDepart = getEtape(TypeEtape.PIETON, time, depart, time + tempsMarcheDepart, locationStationMetroDepart); Etape etapeMetro = getEtape(TypeEtape.METRO, time + tempsMarcheDepart + attenteMoyenneMetro, locationStationMetroDepart, time + tempsMarcheDepart + attenteMoyenneMetro + tempsParcours, locationStationMetroArrivee); Etape etapePietonArrivee = getEtape(TypeEtape.PIETON, etapeMetro.arrivee, locationStationMetroArrivee, etapeMetro.arrivee + tempsMarcheArrivee, arrivee); itineraires.add( new Itineraire(etapePietonDepart, etapeMetro, etapePietonArrivee) ); hasMetroDirect = true; } } } } if(!directsUniquement) { publishProgress("Recherche des circuits avec correspondances"); int tempsMarcheCorrespondance = 5; //Approximation correspondance int i = 0; for(Circuit circuitDepart : stationsDepartCircuit.keySet()) { i++; if(circuitsCommuns.contains(circuitDepart)) { continue; } Station stationDepart = stationsDepartCircuit.get(circuitDepart); Location locationStationDepart = new Location(stationDepart, circuitDepart.nom, getApplicationContext()); int tempsMarcheDepart = AbstractMapActivity.getTempsMarche(depart, locationStationDepart); Calendar calendrierArret = Calendar.getInstance(); calendrierArret.setTime(calendrier.getTime()); calendrierArret.add(Calendar.MINUTE, tempsMarcheDepart ); Ligne ligneDepart = goToRennes.getBusDao().getLigne(circuitDepart.idLigne); Arret arretDepart = goToRennes.getBusDao().getArret(stationDepart.id, circuitDepart.id, calendrierArret, ligneDepart.isLigneDeNuit()); if(arretDepart == null) { continue; } int j = 0; for(Circuit circuitArrivee : stationsArriveeCircuit.keySet()) { j++; publishProgress("Recherche du circuit " + (100 * (i-1) * stationsArriveeCircuit.size() + j) / (stationsDepartCircuit.size() * stationsArriveeCircuit.size() ) + "%" ); if(circuitsCommuns.contains(circuitArrivee)) { continue; } if(circuitDepart.equals(circuitArrivee) || circuitDepart.idLigne == circuitArrivee.idLigne) { continue; } Station stationArrivee = stationsArriveeCircuit.get(circuitArrivee); Location locationStationArrivee = new Location(stationArrivee, circuitArrivee.nom, getApplicationContext()); int tempsMarcheArrivee = AbstractMapActivity.getTempsMarche(locationStationArrivee, arrivee); long[] correspondance = goToRennes.getBusDao().getCorrespondance(circuitDepart, stationDepart, circuitArrivee, stationArrivee); if( correspondance != null) { Arret arretCorrespondance1 = goToRennes.getBusDao().getArret(arretDepart.idTrajet, correspondance[0]); if(arretCorrespondance1 == null) { continue; } //Cas bizarre... if(arretCorrespondance1.arrivee < arretDepart.arrivee) { continue; } Calendar calendrierCorrespondance = Calendar.getInstance(); calendrierCorrespondance.setTime(calendrier.getTime()); calendrierCorrespondance.set(Calendar.HOUR_OF_DAY, arretCorrespondance1.getHeuresArrivee(ligneDepart.isLigneDeNuit())); calendrierCorrespondance.set(Calendar.MINUTE, arretCorrespondance1.getMinutesArrivee()); calendrierCorrespondance.add(Calendar.MINUTE, tempsMarcheCorrespondance); Ligne ligneArrivee = goToRennes.getBusDao().getLigne(circuitArrivee.idLigne); Arret arretCorrespondance2 = goToRennes.getBusDao().getArret(correspondance[1], circuitArrivee.id, calendrierCorrespondance, ligneArrivee.isLigneDeNuit()); if(arretCorrespondance2 == null) { continue; } Arret arretArrivee = goToRennes.getBusDao().getArret(arretCorrespondance2.idTrajet, stationArrivee.id); if(arretArrivee == null) { continue; } //Cas bizarre... if(arretArrivee.arrivee < arretCorrespondance2.arrivee) { continue; } Etape etapePietonDepart = getEtape(TypeEtape.PIETON, time, depart, time + tempsMarcheDepart, locationStationDepart); Station stationCorrespondance1 = goToRennes.getBusDao().getStation(arretCorrespondance1.idStation); Location locationStation1 = new Location(stationCorrespondance1, circuitDepart.nom, getApplicationContext()); Etape etapeBus1 = getEtape(TypeEtape.BUS, arretDepart.depart, locationStationDepart, arretCorrespondance1.arrivee, locationStation1, ligneDepart.code); etapeBus1.bitmapIcon = goToRennes.getBusStationService().getBitmapIcon(getApplicationContext(), circuitDepart.idLigne); etapeBus1.bitmapCarre = ligneDepart.isLogoCarre(); Station stationCorrespondance2 = goToRennes.getBusDao().getStation(arretCorrespondance2.idStation); Location locationStation2 = new Location(stationCorrespondance2, circuitArrivee.nom, getApplicationContext()); Etape etapeCorrespondance = getEtape(TypeEtape.PIETON, etapeBus1.arrivee, locationStation1, etapeBus1.arrivee + 2, locationStation2); Etape etapeBus2 = getEtape(TypeEtape.BUS, arretCorrespondance2.depart, locationStation2, arretArrivee.arrivee, locationStationArrivee, ligneArrivee.code); etapeBus2.bitmapIcon = goToRennes.getBusStationService().getBitmapIcon(getApplicationContext(), circuitArrivee.idLigne); etapeBus2.bitmapCarre = ligneArrivee.isLogoCarre(); Etape etapePietonArrivee = getEtape(TypeEtape.PIETON, etapeBus2.arrivee, locationStationArrivee, etapeBus2.arrivee + tempsMarcheArrivee, arrivee); itineraires.add( new Itineraire(etapePietonDepart, etapeBus1, etapeCorrespondance, etapeBus2, etapePietonArrivee) ); } } if(stationMetroArrivee != null && !hasMetroDirect) { for(MetroStation stationMetro : goToRennes.getMetroStationService().getMetroStations()) { if(stationMetro.equals(stationMetroArrivee)) { continue; } Long correspondance = goToRennes.getBusDao().getCorrespondance(circuitDepart, stationDepart, stationMetro.latitude, stationMetro.longitude, false); if(correspondance != null) { int tempsMarcheArrivee = AbstractMapActivity.getTempsMarche(locationStationMetroArrivee, arrivee); Arret arretCorrespondance = goToRennes.getBusDao().getArret(arretDepart.idTrajet, correspondance); if(arretCorrespondance == null) { continue; } //Cas bizarre... if(arretCorrespondance.arrivee < arretDepart.arrivee) { continue; } int departMetro = arretCorrespondance.arrivee + tempsMarcheCorrespondance + attenteMoyenneMetro; int arriveeMetro = departMetro + Math.abs(stationMetro.sequence - stationMetroArrivee.sequence) + 2; Etape etapePietonDepart = getEtape(TypeEtape.PIETON, time, depart, time + tempsMarcheDepart, locationStationDepart); Station stationCorrespondance = goToRennes.getBusDao().getStation(arretCorrespondance.idStation); Location locationStation = new Location(stationCorrespondance, circuitDepart.nom, getApplicationContext()); Etape etapeBus = getEtape(TypeEtape.BUS, arretDepart.depart, locationStationDepart, arretCorrespondance.arrivee, locationStation, ligneDepart.code); etapeBus.bitmapIcon = goToRennes.getBusStationService().getBitmapIcon(getApplicationContext(), circuitDepart.idLigne); etapeBus.bitmapCarre = ligneDepart.isLogoCarre(); Location locationStationMetro = new Location(stationMetro, getMetroDirection(stationMetro, stationMetroArrivee ), getApplicationContext()); Etape etapeCorrespondance = getEtape(TypeEtape.PIETON, etapeBus.arrivee, locationStation, etapeBus.arrivee + 2, locationStationMetro); Etape etapeMetro = getEtape(TypeEtape.METRO, departMetro, locationStationMetro, arriveeMetro, locationStationMetroArrivee); Etape etapePietonArrivee = getEtape(TypeEtape.PIETON, etapeMetro.arrivee, locationStationMetroArrivee, etapeMetro.arrivee + tempsMarcheArrivee, arrivee); itineraires.add( new Itineraire(etapePietonDepart, etapeBus, etapeCorrespondance, etapeMetro, etapePietonArrivee) ); } } } } if(stationMetroDepart != null && !hasMetroDirect) { int tempsMarcheDepart = AbstractMapActivity.getTempsMarche(depart, locationStationMetroDepart); for(MetroStation stationMetro : goToRennes.getMetroStationService().getMetroStations()) { if(stationMetro.equals(stationMetroDepart)) { continue; } locationStationMetroDepart.direction = getMetroDirection(stationMetroDepart, stationMetro); Location locationStationMetro = new Location(stationMetro, "", getApplicationContext()); for(Circuit circuitArrivee : stationsArriveeCircuit.keySet()) { Station stationArrivee = stationsArriveeCircuit.get(circuitArrivee); Location locationStationArrivee = new Location(stationArrivee, circuitArrivee.nom, getApplicationContext()); int tempsMarcheArrivee = AbstractMapActivity.getTempsMarche(locationStationArrivee, arrivee); Long correspondance = goToRennes.getBusDao().getCorrespondance(circuitArrivee, stationArrivee, stationMetro.latitude, stationMetro.longitude, true); if(correspondance != null) { Calendar calendrierCorrespondance = Calendar.getInstance(); calendrierCorrespondance.setTime(calendrier.getTime()); calendrierCorrespondance.add(Calendar.MINUTE, tempsMarcheDepart + attenteMoyenneMetro); calendrierCorrespondance.add(Calendar.MINUTE, Math.abs(stationMetroDepart.sequence - stationMetro.sequence) + 2); calendrierCorrespondance.add(Calendar.MINUTE, tempsMarcheCorrespondance); Ligne ligneArrivee = goToRennes.getBusDao().getLigne(circuitArrivee.idLigne); Arret arretCorrespondance = goToRennes.getBusDao().getArret(correspondance, circuitArrivee.id, calendrierCorrespondance, ligneArrivee.isLigneDeNuit()); if(arretCorrespondance == null) { continue; } Arret arretArrivee = goToRennes.getBusDao().getArret(arretCorrespondance.idTrajet, stationArrivee.id); if(arretArrivee == null) { continue; } //Cas bizarre... if(arretArrivee.arrivee < arretCorrespondance.arrivee) { continue; } int departMetro = time + tempsMarcheDepart + attenteMoyenneMetro; int arriveeMetro = departMetro + Math.abs(stationMetroDepart.sequence - stationMetro.sequence) + 2; Etape etapePietonDepart = getEtape(TypeEtape.PIETON, time, depart, time + tempsMarcheDepart, locationStationMetroDepart); Etape etapeMetro = getEtape(TypeEtape.METRO, departMetro, locationStationMetroDepart, arriveeMetro, locationStationMetro); Station stationCorrespondance = goToRennes.getBusDao().getStation(arretCorrespondance.idStation); Location locationStation = new Location(stationCorrespondance, circuitArrivee.nom, getApplicationContext()); Etape etapeCorrespondance = getEtape(TypeEtape.PIETON, etapeMetro.arrivee, locationStationMetro, etapeMetro.arrivee + 2, locationStation); Etape etapeBus = getEtape(TypeEtape.BUS, arretCorrespondance.depart, locationStation, arretArrivee.arrivee, locationStationArrivee, ligneArrivee.code); etapeBus.bitmapIcon = goToRennes.getBusStationService().getBitmapIcon(getApplicationContext(), circuitArrivee.idLigne); etapeBus.bitmapCarre = ligneArrivee.isLogoCarre(); Etape etapePietonArrivee = getEtape(TypeEtape.PIETON, etapeBus.arrivee, locationStationArrivee, etapeBus.arrivee + tempsMarcheArrivee, arrivee); itineraires.add( new Itineraire(etapePietonDepart, etapeMetro, etapeCorrespondance, etapeBus, etapePietonArrivee) ); } } } } } Collections.sort(itineraires, new Comparator<Itineraire>() { @Override public int compare(Itineraire itineraire1, Itineraire itineraire2) { Integer arrivee1 = itineraire1.getArrivee(); Integer arrivee2 = itineraire2.getArrivee(); return arrivee1.compareTo(arrivee2); } }); //Filtre List<String> keys = new ArrayList<String>(); int itineraireIndex = 1; for(Iterator<Itineraire> iter = itineraires.iterator(); iter.hasNext();) { Itineraire itineraire = iter.next(); String key = itineraire.getKey(); if(keys.contains(key)) { iter.remove(); } else { keys.add(key); itineraire.index = itineraireIndex++; } } return itineraires.size() > 3 ? itineraires.subList(0, 3) : itineraires; } @Override protected void onPostExecute(List<Itineraire> result) { if( result == null || result.isEmpty() ) { waitDialog.dismiss(); if(!departOk) { showError(getString(R.string.erreurAdresseDepart), true); } else if(!arriveeOk) { showError(getString(R.string.erreurAdresseArrivee), true); } else { showError(getString(R.string.erreurItineraire), true); } return; } ListView listView = (ListView) findViewById(R.id.itineraires); listView.setAdapter(getItineraireAdapter(result)); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View view, int position, long id) { Itineraire itineraire = (Itineraire) adapter.getItemAtPosition(position); goToRennes.itineraireCourant = itineraire; Intent intent = new Intent(getApplicationContext(), ItineraireBusDetailActivity.class); startActivity(intent); } }); waitDialog.dismiss(); } @Override protected void onProgressUpdate(String... values) { waitDialog.setMessage(values[0]); } }; t.execute(adresseDepart, adresseArrivee); } protected String getMetroDirection(MetroStation m1, MetroStation m2) { return m1.sequence < m2.sequence ? getString(R.string.kennedy) : getString(R.string.poterie); } @Override protected String getTrackingName() { return "itinerairesBus"; } protected ListAdapter getItineraireAdapter(List<Itineraire> itineraires) { return new ArrayAdapter<Itineraire>(this, 0, itineraires) { @Override public View getView(int position, View convertView, ViewGroup parent) { View view = getLayoutInflater().inflate(R.layout.itineraires_listitem, null); Itineraire itineraire = getItem(position); TextView nom = (TextView) view.findViewById(R.id.name); nom.setText(String.valueOf(itineraire.index)); TextView arrivee = (TextView) view.findViewById(R.id.arrivee); arrivee.setText(Arret.getTime(itineraire.getArrivee())); LinearLayout details = (LinearLayout) view.findViewById(R.id.itineraire); for(final Etape etape : itineraire.etapes) { RelativeLayout dview = (RelativeLayout) getLayoutInflater().inflate(R.layout.itineraire_listitem, null); ImageView lineIcon = (ImageView) dview.findViewById(R.id.icon); if(etape.bitmapIcon != null) { lineIcon.setImageBitmap(etape.bitmapIcon); } else { lineIcon.setImageResource(etape.type.icon); } TextView name = (TextView) dview.findViewById(R.id.name); name.setText(Html.fromHtml(Arret.getTime(etape.depart) + " : " + etape.adresseDepart + "<br />" + Arret.getTime(etape.arrivee) + " : " + etape.adresseArrivee )); TextView duree = (TextView) dview.findViewById(R.id.duree); duree.setVisibility(View.GONE); TextView distance = (TextView) dview.findViewById(R.id.distance); distance.setVisibility(View.GONE); details.addView(dview); } return view; } }; } protected Etape getEtape(TypeEtape type, int depart, Location locationDepart, int arrivee, Location locationArrivee) { return getEtape(type, depart, locationDepart, arrivee, locationArrivee, null); } protected Etape getEtape(TypeEtape type, int depart, Location locationDepart, int arrivee, Location locationArrivee, String ligne) { Etape etape = new Etape(); etape.type = type; etape.locationDepart = locationDepart; etape.adresseDepart = locationDepart.adresse + (locationDepart.direction != null && type != TypeEtape.PIETON ? "<br/>" + getString(R.string.direction) + locationDepart.direction : ""); etape.locationArrivee = locationArrivee; etape.adresseArrivee = locationArrivee.adresse; etape.depart = depart; etape.arrivee = arrivee; etape.ligne = ligne; return etape; } protected Itineraire getItinerairePieton(int depart, Location locationDepart, int arrivee, Location locationArrivee) { Itineraire itineraire = new Itineraire(); itineraire.etapes.add(getEtape(TypeEtape.PIETON, depart, locationDepart, arrivee, locationArrivee)); return itineraire; } @Override protected int getMapIcon() { return 0; } }