Android Open Source - Go2-Rennes Proximite Result Activity






From Project

Back to project page Go2-Rennes.

License

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.

Java Source Code

/*******************************************************************************
 * Copyright (c) 2011 Michel DAVID mimah35-at-gmail.com
 * /*from w  w w  .ja  v a 2  s.c o 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.Collections;
import java.util.Comparator;
import java.util.List;

import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import fr.gotorennes.domain.Arret;
import fr.gotorennes.domain.BikeStation;
import fr.gotorennes.domain.Circuit;
import fr.gotorennes.domain.Ligne;
import fr.gotorennes.domain.MetroStation;
import fr.gotorennes.domain.PointDeVente;
import fr.gotorennes.domain.RelayPark;
import fr.gotorennes.domain.Station;
import fr.gotorennes.domain.StationGroup;
import fr.gotorennes.util.BackgroundTask;
import fr.gotorennes.view.ExpandableView;

public class ProximiteResultActivity extends AbstractActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.proximite_result);
  }
  
  @Override
  protected String getTrackingName() {
    return "proximitesResult";
  }
  
  @Override
  protected void init(Intent intent) {
    latitude = intent.getDoubleExtra("latitude", 0);
    longitude = intent.getDoubleExtra("longitude", 0);
    
    loadProximityData();    
  }

  protected List<MetroStation> getMetroStations() {
    return goToRennes.getMetroStationService().getProximityMetroStations(latitude, longitude);
  }

  protected void hideProximityData() {
    ExpandableView expandMetro = (ExpandableView) findViewById(R.id.expandMetro);
    expandMetro.setVisibility(View.GONE);
    expandMetro.reset();

    ExpandableView expandBus = (ExpandableView) findViewById(R.id.expandBus);
    expandBus.setVisibility(View.GONE);
    expandBus.reset();

    ExpandableView expandBike = (ExpandableView) findViewById(R.id.expandBike);
    expandBike.setVisibility(View.GONE);
    expandBike.reset();
  }

  protected void loadProximityData() {

    SharedPreferences prefs = getSharedPreferences("fr.gotorennes.Application", 0);

    ExpandableView expandMetro = (ExpandableView) findViewById(R.id.expandMetro);
    expandMetro.setBackgroundTask(getMetroBackgroundTask());
    expandMetro.setVisibility(prefs.getBoolean("checkMetro", true) ? View.VISIBLE : View.GONE);
    expandMetro.reset();

    ExpandableView expandBus = (ExpandableView) findViewById(R.id.expandBus);
    expandBus.setBackgroundTask(getBusBackgroundTask());
    expandBus.setVisibility(prefs.getBoolean("checkBus", true) ? View.VISIBLE : View.GONE);
    expandBus.reset();

    ExpandableView expandBike = (ExpandableView) findViewById(R.id.expandBike);
    expandBike.setBackgroundTask(getBikeBackgroundTask());
    expandBike.setVisibility(prefs.getBoolean("checkBike", true) ? View.VISIBLE : View.GONE);
    expandBike.reset();
  }

  protected List<PointDeVente> getPointsDeVente() {
    return goToRennes.getPointDeVenteService().getProximityPointsDeVente(latitude, longitude);
  }

  private BackgroundTask<?> getMetroBackgroundTask() {
    return new BackgroundTask<List<MetroStation>>() {

      @Override
      protected List<MetroStation> execute() {
        return getMetroStations();
      }

      @Override
      protected void callback(List<MetroStation> result) {

        if (result == null) {
          showError(getString(R.string.erreurChargementMetro));
          return;
        }

        LinearLayout listView = (LinearLayout) findViewById(R.id.metroStations);
        listView.removeAllViews();

        for (final MetroStation metroStation : result) {
          View view = layoutInflater.inflate(R.layout.metrostation_listitem, null);

          TextView name = (TextView) view.findViewById(R.id.name);
          name.setText(Html.fromHtml("<u>" + metroStation.name + "</u>"));

          TextView distance = (TextView) view.findViewById(R.id.distance);
          distance.setText(Html.fromHtml("<u>" + getFormattedDistance(metroStation.latitude, metroStation.longitude) + "</u>"));
          distance.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
              Intent intent = new Intent(getApplicationContext(), ItineraireMapActivity.class);
              intent.putExtra("latitude", latitude);
              intent.putExtra("longitude", longitude);
              intent.putExtra("latitudeDest", metroStation.latitude);
              intent.putExtra("longitudeDest", metroStation.longitude);
              intent.putExtra("icon", getMapIcon());
              intent.putExtra("iconDest", R.drawable.metro);
              intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
              startActivity(intent);
            }

          });

          name.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
              Intent intent = new Intent(getApplicationContext(), MetroStationActivity.class);
              intent.putExtra("metroStation", metroStation);
              intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
              startActivity(intent);
            }
          });
          listView.addView(view);
        }
      }
    };
  }

  protected List<StationGroup> getBusStations() {
    return goToRennes.getBusDao().getStationsProches(latitude, longitude);
  }

  private BackgroundTask<?> getBusBackgroundTask() {
    return new BackgroundTask<List<StationGroup>>() {

      @Override
      protected List<StationGroup> execute() {
        List<StationGroup> stations = getBusStations();
        Collections.sort(stations, new Comparator<StationGroup>() {

          @Override
          public int compare(StationGroup object1, StationGroup object2) {
            Double distance1 = AbstractMapActivity.getDistance(latitude, longitude, object1.latitude, object1.longitude);
            Double distance2 = AbstractMapActivity.getDistance(latitude, longitude, object2.latitude, object2.longitude);
            return distance1.compareTo(distance2);
          }
        });
        return stations;
      }

      @Override
      protected void callback(List<StationGroup> result) {
        LinearLayout listView = (LinearLayout) findViewById(R.id.busStations);
        listView.removeAllViews();

        for (final StationGroup stationGroup : result) {
          View view = layoutInflater.inflate(R.layout.busstop_listitem, null);

          TextView name = (TextView) view.findViewById(R.id.name);
          name.setText(Html.fromHtml("<u>" + stationGroup.nom + "</u>"));

          TextView distance = (TextView) view.findViewById(R.id.distance);
          distance.setText(Html.fromHtml("<u>" + getFormattedDistance(stationGroup.latitude, stationGroup.longitude) + "</u>"));
          distance.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
              Intent intent = new Intent(getApplicationContext(), ItineraireMapActivity.class);
              intent.putExtra("latitude", latitude);
              intent.putExtra("longitude", longitude);
              intent.putExtra("latitudeDest", stationGroup.latitude);
              intent.putExtra("longitudeDest", stationGroup.longitude);
              intent.putExtra("icon", getMapIcon());
              intent.putExtra("iconDest", R.drawable.bus);
              intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
              startActivity(intent);
            }

          });

          final LinearLayout details = (LinearLayout) view.findViewById(R.id.details);

          BackgroundTask<List<Passage>> backgroundTask = new BackgroundTask<List<Passage>>(true) {

            @Override
            protected List<Passage> execute() {
              
              List<Passage> passages = new ArrayList<Passage>();
              List<Station> stations = goToRennes.getBusDao().getStations(stationGroup);
              
              for(Station station : stations) {
                for(Ligne ligne : goToRennes.getBusDao().getLignes(station)) {
                  Passage passage = new Passage();
                  passage.station = station;
                  passage.ligne = ligne;
                  passage.arret = goToRennes.getBusDao().getProchainPassage(station.id, ligne.id, ligne.isLigneDeNuit());
                  if(passage.arret != null) {
                    passage.circuit = goToRennes.getBusDao().getCircuitByIdTrajet(passage.arret.idTrajet);
                  }
                  else {
                    passage.circuit = goToRennes.getBusDao().getCircuit(passage.ligne, passage.station);
                  }
                  passages.add(passage);
                }
              }
              
              Collections.sort(passages);
              return passages;
            }

            @Override
            protected void callback(List<Passage> result) {
              details.removeAllViews();

              for (final Passage passage : result) {
                
                View detailView = getLayoutInflater().inflate(R.layout.busstop_detail_listitem, null);
                
                Ligne ligne = passage.ligne;
                Arret arret = passage.arret;
                Circuit circuit = passage.circuit;
                
                ImageView lineIcon = (ImageView) detailView.findViewById(R.id.icon);
                Bitmap icon = goToRennes.getBusStationService().getBitmapIcon(ProximiteResultActivity.this, ligne.id);
                lineIcon.setImageBitmap(icon);
                  
                TextView name = (TextView) detailView.findViewById(R.id.name);
                name.setText(Html.fromHtml("<u>" + circuit.nom + "</u>"));
                
                if(arret != null) {
                    
                  TextView nextStop = (TextView) detailView.findViewById(R.id.nextStopTime);
                  nextStop.setText(arret.getDepart());
                    
                  TextView nextStopMinutes = (TextView) detailView.findViewById(R.id.nextStopTimeInMinutes);
                  nextStopMinutes.setText(arret.getDureeAvantDepart(ligne.isLigneDeNuit(), getResources()));
                }
                  
                name.setOnClickListener(new OnClickListener() {
        
                  @Override
                  public void onClick(View v) {
                    Intent intent = new Intent(ProximiteResultActivity.this, BusArretActivity.class);
                    intent.putExtra("station", passage.station);
                    intent.putExtra("ligne", passage.ligne);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                  }
                });
        
                details.addView(detailView);
              }
            }
          };
          backgroundTask.start(ProximiteResultActivity.this);

          name.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
              Intent intent = new Intent(getApplicationContext(), BusStationActivity.class);
              intent.putExtra("stationGroup", stationGroup);
              intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
              startActivity(intent);
            }
          });

          listView.addView(view);
        }
      }
    };
  }
  
  class Passage implements Comparable<Passage> {
    Station station;
    Ligne ligne;
    Circuit circuit;
    Arret arret;
    
    @Override
    public int compareTo(Passage another) {
      return ligne.compareTo(another.ligne);
    }
  }

  protected List<RelayPark> getRelayParks() {
    return goToRennes.getRelayParkService().getProximityRelayParks(latitude, longitude);
  }

  

  protected List<BikeStation> getBikeStations() {
    return goToRennes.getBikeStationService().getProximityBikeStations(latitude, longitude);
  }

  private BackgroundTask<?> getBikeBackgroundTask() {
    return new BackgroundTask<List<BikeStation>>() {

      @Override
      protected List<BikeStation> execute() {
        return getBikeStations();
      }

      @Override
      protected void callback(List<BikeStation> result) {
        if (result == null) {
          showError(getString(R.string.erreurChargementVelo));
          return;
        }

        LinearLayout listView = (LinearLayout) findViewById(R.id.bikeStations);
        listView.removeAllViews();

        for (final BikeStation bikeStation : result) {
          View view = layoutInflater.inflate(R.layout.bikestation_listitem, null);

          TextView name = (TextView) view.findViewById(R.id.bikeStationName);
          name.setText(Html.fromHtml("<u>" + bikeStation.name + "</u>"));

          TextView availableBikes = (TextView) view.findViewById(R.id.availableBikes);
          availableBikes.setText(String.valueOf(bikeStation.bikesAvailable));
          availableBikes.setTextColor(bikeStation.getBikeColor());

          TextView availableSlots = (TextView) view.findViewById(R.id.availableSlots);
          availableSlots.setText(String.valueOf(bikeStation.slotsAvailable));
          availableSlots.setTextColor(bikeStation.getSlotColor());

          TextView distance = (TextView) view.findViewById(R.id.distance);
          distance.setText(Html.fromHtml("<u>" + getFormattedDistance(bikeStation.latitude, bikeStation.longitude) + "</u>"));
          distance.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
              Intent intent = new Intent(getApplicationContext(), ItineraireMapActivity.class);
              intent.putExtra("latitude", latitude);
              intent.putExtra("longitude", longitude);
              intent.putExtra("latitudeDest", bikeStation.latitude);
              intent.putExtra("longitudeDest", bikeStation.longitude);
              intent.putExtra("icon", getMapIcon());
              intent.putExtra("iconDest", R.drawable.bike);
              intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
              startActivity(intent);
            }

          });

          name.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
              Intent intent = new Intent(getApplicationContext(), BikeStationActivity.class);
              intent.putExtra("bikeStation", bikeStation);
              intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
              startActivity(intent);
            }
          });

          listView.addView(view);
        }
      }
    };
  }

  protected static TextView populateRelayPark(View view, RelayPark relayPark, boolean underline) {
    TextView name = (TextView) view.findViewById(R.id.relayParkName);
    if (underline) {
      name.setText(Html.fromHtml("<u>" + relayPark.name + "</u>"));
    } else {
      name.setText(relayPark.name);
    }

    View openedView = view.findViewById(R.id.relayParkOpen);
    View closedView = view.findViewById(R.id.relayParkClose);
    View fullView = view.findViewById(R.id.relayParkFull);

    switch (relayPark.state) {
    case 0: // Ouvert
      openedView.setVisibility(View.VISIBLE);
      closedView.setVisibility(View.GONE);
      fullView.setVisibility(View.GONE);

      TextView available = (TextView) view.findViewById(R.id.available);
      available.setText(String.valueOf(relayPark.available));
      available.setTextColor(relayPark.getColor());

      TextView capacity = (TextView) view.findViewById(R.id.capacity);
      capacity.setText(String.valueOf(relayPark.capacity));
      break;
    case 2: // Complet
      openedView.setVisibility(View.GONE);
      closedView.setVisibility(View.GONE);
      fullView.setVisibility(View.VISIBLE);
      break;
    default:
      openedView.setVisibility(View.GONE);
      closedView.setVisibility(View.VISIBLE);
      fullView.setVisibility(View.GONE);
    }
    return name;
  }
  
  @Override
  protected int getMapIcon() {
    return 0;
  }
}




Java Source Code List

fr.gotorennes.AbstractActivity.java
fr.gotorennes.AbstractConfigurationActivity.java
fr.gotorennes.AbstractMapActivity.java
fr.gotorennes.AbstractWidgetProvider.java
fr.gotorennes.BikeStationActivity.java
fr.gotorennes.BikeStationWidgetConfigurationActivity.java
fr.gotorennes.BikeStationWidgetProvider.java
fr.gotorennes.BikeStationsActivity.java
fr.gotorennes.BikeWidgetProvider.java
fr.gotorennes.BusArretActivity.java
fr.gotorennes.BusCircuitsActivity.java
fr.gotorennes.BusCircuitsWidgetConfigurationActivity.java
fr.gotorennes.BusLignesActivity.java
fr.gotorennes.BusLignesWidgetConfigurationActivity.java
fr.gotorennes.BusStationActivity.java
fr.gotorennes.BusStationGroupsActivity.java
fr.gotorennes.BusStationsActivity.java
fr.gotorennes.BusStationsMapActivity.java
fr.gotorennes.BusStopWidgetConfigurationActivity.java
fr.gotorennes.BusStopWidgetProvider.java
fr.gotorennes.BusTripActivity.java
fr.gotorennes.CadenasActivity.java
fr.gotorennes.ClockActivity.java
fr.gotorennes.CreditsActivity.java
fr.gotorennes.FavorisActivity.java
fr.gotorennes.GoToRennesActivity.java
fr.gotorennes.GoToRennes.java
fr.gotorennes.ItineraireActivity.java
fr.gotorennes.ItineraireBusDetailActivity.java
fr.gotorennes.ItineraireBusResultActivity.java
fr.gotorennes.ItineraireMapActivity.java
fr.gotorennes.ItineraireVeloResultActivity.java
fr.gotorennes.MetroStationActivity.java
fr.gotorennes.MetroStationsActivity.java
fr.gotorennes.PointDeVenteActivity.java
fr.gotorennes.PointDeVentesActivity.java
fr.gotorennes.ProximiteActivity.java
fr.gotorennes.ProximiteResultActivity.java
fr.gotorennes.ProximityMapActivity.java
fr.gotorennes.RelayParkActivity.java
fr.gotorennes.RelayParkWidgetConfigurationActivity.java
fr.gotorennes.RelayParkWidgetProvider.java
fr.gotorennes.RelayParksActivity.java
fr.gotorennes.domain.Arret.java
fr.gotorennes.domain.BikeStation.java
fr.gotorennes.domain.Circuit.java
fr.gotorennes.domain.EquipementStatus.java
fr.gotorennes.domain.Equipement.java
fr.gotorennes.domain.Ligne.java
fr.gotorennes.domain.LineAlert.java
fr.gotorennes.domain.Localisable.java
fr.gotorennes.domain.MetroStation.java
fr.gotorennes.domain.NextDeparture.java
fr.gotorennes.domain.NextMetroDeparture.java
fr.gotorennes.domain.PointDeVenteCommune.java
fr.gotorennes.domain.PointDeVenteQuartier.java
fr.gotorennes.domain.PointDeVente.java
fr.gotorennes.domain.RelayPark.java
fr.gotorennes.domain.SensCirculation.java
fr.gotorennes.domain.StationGroup.java
fr.gotorennes.domain.Station.java
fr.gotorennes.persistence.BusDao.java
fr.gotorennes.persistence.BusDatabase.java
fr.gotorennes.remote.BikeStationService.java
fr.gotorennes.remote.BusStationService.java
fr.gotorennes.remote.CommuneService.java
fr.gotorennes.remote.EquipementService.java
fr.gotorennes.remote.EquipementStatusService.java
fr.gotorennes.remote.LineAlertService.java
fr.gotorennes.remote.MetroStationService.java
fr.gotorennes.remote.MetroStationStatusService.java
fr.gotorennes.remote.NextDepartureService.java
fr.gotorennes.remote.NextMetroDepartureService.java
fr.gotorennes.remote.PointDeVenteService.java
fr.gotorennes.remote.QuartierService.java
fr.gotorennes.remote.RelayParkService.java
fr.gotorennes.remote.RemoteService.java
fr.gotorennes.util.AsciiUtils.java
fr.gotorennes.util.BackgroundTask.java
fr.gotorennes.util.JoursUtils.java
fr.gotorennes.util.LocationUtils.java
fr.gotorennes.util.UpdateUtils.java
fr.gotorennes.view.ExpandableView.java
fr.gotorennes.view.FilterBar.java
fr.gotorennes.view.FilterSortBar.java
fr.gotorennes.view.LockPopupWindow.java
fr.gotorennes.view.MapDrawable.java
fr.gotorennes.view.TitleBar.java