Android Open Source - Go2-Rennes Favoris 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. j  a  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.List;
import java.util.Map;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
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.RelativeLayout;
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.RelayPark;
import fr.gotorennes.domain.Station;
import fr.gotorennes.util.BackgroundTask;

public class FavorisActivity extends AbstractActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.favoris);
  }
  
  @Override
  protected String getTrackingName() {
    return "favoris";
  }
  
  @Override
  protected int getMapIcon() {
    return 0;
  }

  @Override
  protected void init(Intent intent) {
    
    BackgroundTask<List<Ligne>> backgroundTask = new BackgroundTask<List<Ligne>>() {

      List<View> arrets = new ArrayList<View>();
      List<View> metros = new ArrayList<View>();
      List<View> bikes = new ArrayList<View>();
      List<View> relayParks = new ArrayList<View>();
      
      @Override
      protected List<Ligne> execute() {
        SharedPreferences prefs = getSharedPreferences("fr.gotorennes.Application", 0);
        
        Map<String, ?> map = prefs.getAll();
        for (Map.Entry<String, ?> entry : map.entrySet()) {
          
          String key = entry.getKey();
          String id = key.substring(key.indexOf("-") + 1);
          
          //Avant version 0.8 -> migration du favoris
          if (key.startsWith("arret-")) {
            String[] ids = id.split(";");
            
            Station station = goToRennes.getBusDao().getStation(Long.parseLong(ids[0]));
            Circuit circuit = goToRennes.getBusDao().getCircuit(Long.parseLong(ids[1]));
                        
            Editor editor = prefs.edit();
            editor.remove(key);
            if( circuit != null) {
              Ligne ligne = goToRennes.getBusDao().getLigne(circuit.idLigne);
              
              id = station.code + ";" + ligne.code;
              key = "arretbus-" + id;
            
              editor.putString(key, "");
            }
            editor.commit();            
          }
          //Migration 0.8.1 vers les codes au lieu des ids
          if (key.startsWith("bus-")) {
            String[] ids = id.split(";");
            
            Station station = goToRennes.getBusDao().getStation(Long.parseLong(ids[0]));
            Ligne ligne = goToRennes.getBusDao().getLigne(Long.parseLong(ids[1]));
            
            Editor editor = prefs.edit();
            editor.remove(key);
            if( station != null || ligne != null ) {
              id = station.code + ";" + ligne.code;
              key = "arretbus-" + id;
            
              editor.putString(key, "");
            }
            editor.commit();            
          }
          
          if (key.startsWith("arretbus-")) {
            String[] ids = id.split(";");
            final Station station = goToRennes.getBusDao().getStation(ids[0]);
            final Ligne ligne = goToRennes.getBusDao().getLigne(ids[1]);
            
            if (station == null || ligne == null) {
              Editor editor = prefs.edit();
              editor.remove(key);
              editor.commit();
              continue;
            }
                  
            View view = (RelativeLayout) getLayoutInflater().inflate(R.layout.favoris_listitem, null);
            
            ImageView lineIcon = (ImageView) view.findViewById(R.id.icon);

            Bitmap icon = goToRennes.getBusStationService().getBitmapIcon(FavorisActivity.this, ligne.id);
            lineIcon.setImageBitmap(icon);
            
            TextView name = (TextView) view.findViewById(R.id.stationName);
            name.setText(Html.fromHtml("<u>" + station.nom + "</u>"));
            
            TextView direction = (TextView) view.findViewById(R.id.directionName);
            
            Arret arret = goToRennes.getBusDao().getProchainPassage(station.id, ligne.id, ligne.isLigneDeNuit());
            if(arret != null) {
              TextView nextStop = (TextView) view.findViewById(R.id.nextStopTime);
              nextStop.setText(arret.getDepart());
              
              TextView nextStopMinutes = (TextView) view.findViewById(R.id.nextStopTimeInMinutes);
              nextStopMinutes.setText(arret.getDureeAvantDepart(ligne.isLigneDeNuit(), getResources()));
              
              Circuit circuit = goToRennes.getBusDao().getCircuitByIdTrajet(arret.idTrajet);
              direction.setText(getString(R.string.vers) + circuit.nom);
            }
            else {
              Circuit circuit = goToRennes.getBusDao().getCircuit(ligne, station);
              if(circuit == null) {
                Editor editor = prefs.edit();
                editor.remove(key);
                editor.commit();
                continue;
              }
              direction.setText(getString(R.string.vers) + circuit.nom);
            }
            
            TextView distance = (TextView) view.findViewById(R.id.distance);
            distance.setText(getMyLocationFormattedDistance(station.latitude, station.longitude));
            
            name.setOnClickListener(new OnClickListener() {

              @Override
              public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), BusArretActivity.class);
                intent.putExtra("station", station);
                intent.putExtra("ligne", ligne);
                startActivity(intent);
              }
            });
            arrets.add(view);
            
          } else if (key.startsWith("metro-")) {
            final MetroStation station = goToRennes.getMetroStationService().getMetroStation(id);
            if (station != null) {
              View view = (RelativeLayout) getLayoutInflater().inflate(R.layout.metrostation_listitem, null);
              
              TextView name = (TextView) view.findViewById(R.id.name);
              name.setText(Html.fromHtml("<u>" + station.name + "</u>"));
              
              TextView distance = (TextView) view.findViewById(R.id.distance);
              distance.setText(getMyLocationFormattedDistance(station.latitude, station.longitude));
              
              name.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                  Intent intent = new Intent(getApplicationContext(), MetroStationActivity.class);
                  intent.putExtra("metroStation", station);
                  startActivity(intent);
                }
              });
              metros.add(view);
            }
            
          } else if (key.startsWith("bike-")) {
            final BikeStation station = goToRennes.getBikeStationService().getBikeStation(id);
            if (station != null) {
              View view = (RelativeLayout) getLayoutInflater().inflate(R.layout.bikestation_listitem, null);
              
              TextView name = (TextView) view.findViewById(R.id.bikeStationName);
              name.setText(Html.fromHtml("<u>" + station.name + "</u>"));
              
              TextView availableBikes = (TextView) view.findViewById(R.id.availableBikes);
              availableBikes.setText(String.valueOf(station.bikesAvailable));
              availableBikes.setTextColor(station.getBikeColor());

              TextView availableSlots = (TextView) view.findViewById(R.id.availableSlots);
              availableSlots.setText(String.valueOf(station.slotsAvailable));
              availableSlots.setTextColor(station.getSlotColor());
              
              TextView distance = (TextView) view.findViewById(R.id.distance);
              distance.setText(getMyLocationFormattedDistance(station.latitude, station.longitude));
              
              name.setOnClickListener(new OnClickListener() {
  
                @Override
                public void onClick(View v) {
                  Intent intent = new Intent(getApplicationContext(), BikeStationActivity.class);
                  intent.putExtra("bikeStation", station);
                  startActivity(intent);
                }
              });
              bikes.add(view);
            }
          } else if (key.startsWith("relayPark-")) {
            final RelayPark station = goToRennes.getRelayParkService().getRelayPark(id);
            if (station != null) {
              View view = (RelativeLayout) getLayoutInflater().inflate(R.layout.relaypark_listitem, null);
              
              ProximiteResultActivity.populateRelayPark(view, station, true);
              
              TextView distance = (TextView) view.findViewById(R.id.distance);
              distance.setText(getMyLocationFormattedDistance(station.latitude, station.longitude));
              
              TextView name = (TextView) view.findViewById(R.id.relayParkName);
              name.setOnClickListener(new OnClickListener() {
  
                @Override
                public void onClick(View v) {
                  Intent intent = new Intent(getApplicationContext(), RelayParkActivity.class);
                  intent.putExtra("relayPark", station);
                  startActivity(intent);
                }
              });
              relayParks.add(view);
            }
          } else {
            // Autres proprits
            continue;
          }
        }
        return null;
      }

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

        LinearLayout listViewBus = (LinearLayout) findViewById(R.id.favorisBus);
        findViewById(R.id.titreBus).setVisibility(arrets.isEmpty() ? View.GONE : View.VISIBLE);
        LinearLayout listViewMetro = (LinearLayout) findViewById(R.id.favorisMetro);
        findViewById(R.id.titreMetro).setVisibility(metros.isEmpty() ? View.GONE : View.VISIBLE);
        LinearLayout listViewVelo = (LinearLayout) findViewById(R.id.favorisVelo);
        findViewById(R.id.titreVelo).setVisibility(bikes.isEmpty() ? View.GONE : View.VISIBLE);
        LinearLayout listViewParcRelais = (LinearLayout) findViewById(R.id.favorisParcRelais);
        findViewById(R.id.titreParcRelais).setVisibility(relayParks.isEmpty() ? View.GONE : View.VISIBLE);

        for (View view : arrets) {
          listViewBus.addView(view);
        }
        for (View view : metros) {
          listViewMetro.addView(view);
        }
        for (View view : bikes) {
          listViewVelo.addView(view);
        }
        for (View view : relayParks) {
          listViewParcRelais.addView(view);
        }
      }
    };
    backgroundTask.start(this);
  }
}




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