Android Open Source - Go2-Rennes Itineraire Map 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  www.  j  ava  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.net.HttpURLConnection;
import java.net.URL;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

import fr.gotorennes.util.BackgroundTask;
import fr.gotorennes.view.MapDrawable;

public class ItineraireMapActivity extends AbstractMapActivity {

  double latitude;
  double longitude;
  double latitudeDest;
  double longitudeDest;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
  }

  @Override
  protected String getTrackingName() {
    return "carteItineraire";
  }
  
  @Override
  protected void init() {
    Intent intent = getIntent();
    
    latitude = intent.getDoubleExtra("latitude", 0);
    longitude = intent.getDoubleExtra("longitude", 0);
    final Location origin = new Location(latitude, longitude, "");
    
    latitudeDest = intent.getDoubleExtra("latitudeDest", 0);
    longitudeDest = intent.getDoubleExtra("longitudeDest", 0);
    final Location dest = new Location(latitudeDest, longitudeDest, "");
    
    final int icon = intent.getIntExtra("icon", 0);
    final int iconDest = intent.getIntExtra("iconDest", 0);

    
    BackgroundTask<Route> backgroundTask = new BackgroundTask<Route>() {

      @Override
      protected Route execute() {
        return getRoute(origin, dest);
      }

      @Override
      protected void callback(Route result) {

        Location locInit = result.locations.get(0);
        GeoPoint gpInit = new GeoPoint((int) (locInit.latitude * 1E6), (int) (locInit.longitude * 1E6));
        mapView.getOverlays().add(new RouteOverlay(gpInit, gpInit, 1));

        if (icon != 0) {
          MapItemOverlay overlay = new MapItemOverlay(new MapDrawable(getApplicationContext(), icon));
          overlay.addItem(new MapLocationOverlay("", locInit.latitude, locInit.longitude, null));
          mapView.getOverlays().add(overlay);
        }

        GeoPoint gp1;
        GeoPoint gp2 = gpInit;
        for (int i = 1; i < result.locations.size(); i++) {
          gp1 = gp2;
          Location loc = result.locations.get(i);
          gp2 = new GeoPoint((int) (loc.latitude * 1E6), (int) (loc.longitude * 1E6));
          mapView.getOverlays().add(new RouteOverlay(gp1, gp2, 2));

        }
        final GeoPoint gpFinal = new GeoPoint((int) (latitudeDest * 1E6), (int) (longitudeDest * 1E6));
        mapView.getOverlays().add(new RouteOverlay(gp2, gpFinal, 3));

        if (iconDest != 0) {
          MapItemOverlay overlay = new MapItemOverlay(new MapDrawable(getApplicationContext(), iconDest));
          overlay.addItem(new MapLocationOverlay("", latitudeDest, longitudeDest, null));
          mapView.getOverlays().add(overlay);
        }

        mapController.setZoom(18);
        mapController.animateTo(new GeoPoint((int) (latitude * 1e6), (int) (longitude * 1e6)));
      }

    };
    backgroundTask.start(this);
  }

  public static class BitmapOverlay extends Overlay {

    private GeoPoint geoPoint;
    private Bitmap bitmap;

    public BitmapOverlay(GeoPoint geoPoint, Bitmap bitmap) {
      super();
      this.geoPoint = geoPoint;
      this.bitmap = bitmap;
    }

    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {

      Point point = new Point();
      Projection projection = mapView.getProjection();
      projection.toPixels(geoPoint, point);

      Bitmap scaled = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth(), bitmap.getHeight(), true);

      canvas.drawBitmap(scaled, point.x - scaled.getWidth() / 2, point.y - scaled.getHeight(), new Paint());
      return super.draw(canvas, mapView, shadow, when);
    }
  }

  public static class RouteOverlay extends Overlay {
    private GeoPoint gp1;
    private GeoPoint gp2;
    private int mRadius = 6;
    private int mode = 0;

    public RouteOverlay(GeoPoint gp1, GeoPoint gp2, int mode) {
      this.gp1 = gp1;
      this.gp2 = gp2;
      this.mode = mode;
    }

    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
      Projection projection = mapView.getProjection();
      if (shadow == false) {
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(Color.BLUE);

        Point point = new Point();
        projection.toPixels(gp1, point);

        if (mode == 1) {
          RectF oval = new RectF(point.x - mRadius, point.y - mRadius, point.x + mRadius, point.y + mRadius);
          canvas.drawOval(oval, paint);
        } else if (mode == 2) {
          Point point2 = new Point();
          projection.toPixels(gp2, point2);
          paint.setStrokeWidth(5);
          paint.setAlpha(120);
          canvas.drawLine(point.x, point.y, point2.x, point2.y, paint);
        } else if (mode == 3) {
          Point point2 = new Point();
          projection.toPixels(gp2, point2);
          paint.setStrokeWidth(5);
          paint.setAlpha(120);
          canvas.drawLine(point.x, point.y, point2.x, point2.y, paint);
          RectF oval = new RectF(point2.x - mRadius, point2.y - mRadius, point2.x + mRadius, point2.y + mRadius);
          paint.setAlpha(255);
          canvas.drawOval(oval, paint);
        }
      }
      return super.draw(canvas, mapView, shadow, when);
    }
  }
  
  public void showExternalMap(View view) {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr=" + latitude + "," + longitude + "&daddr=" + latitudeDest + "," + longitudeDest)));
  }

  @Override
  protected void loadProximityData() {
    // Nothing
  }
}




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