Exemple #1
0
 public synchronized void clearCurrentRoute(
     LatLon newFinalLocation, List<LatLon> newIntermediatePoints) {
   route = new RouteCalculationResult("");
   makeUturnWhenPossible = false;
   evalWaitInterval = 3000;
   app.runInUIThread(
       new Runnable() {
         @Override
         public void run() {
           for (IRouteInformationListener l : listeners) {
             l.routeWasCancelled();
           }
         }
       });
   this.finalLocation = newFinalLocation;
   this.intermediatePoints = newIntermediatePoints;
   if (currentRunningJob instanceof RouteRecalculationThread) {
     ((RouteRecalculationThread) currentRunningJob).stopCalculation();
   }
   if (newFinalLocation == null) {
     settings.FOLLOW_THE_ROUTE.set(false);
     settings.FOLLOW_THE_GPX_ROUTE.set(null);
     // clear last fixed location
     this.lastProjection = null;
     setFollowingMode(false);
   }
 }
 public void followRoute(
     ApplicationMode appMode,
     LatLon finalLocation,
     List<LatLon> intermediatePoints,
     net.osmand.Location currentLocation,
     GPXRouteParams gpxRoute) {
   getMapViewTrackingUtilities().backToLocationImpl();
   RoutingHelper routingHelper = app.getRoutingHelper();
   settings.APPLICATION_MODE.set(appMode);
   settings.FOLLOW_THE_ROUTE.set(true);
   if (gpxRoute == null) {
     settings.FOLLOW_THE_GPX_ROUTE.set(null);
   }
   routingHelper.setFollowingMode(true);
   routingHelper.setFinalAndCurrentLocation(
       finalLocation, intermediatePoints, currentLocation, gpxRoute);
   app.showDialogInitializingCommandPlayer(MapActivity.this);
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    app = getMyApplication();
    settings = app.getSettings();
    app.applyTheme(this);
    super.onCreate(savedInstanceState);

    mapActions = new MapActivityActions(this);
    mapLayers = new MapActivityLayers(this);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    // Full screen is not used here
    // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    // WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main);
    startProgressDialog = new ProgressDialog(this);
    startProgressDialog.setCancelable(true);
    app.checkApplicationIsBeingInitialized(this, startProgressDialog);
    parseLaunchIntentLocation();

    mapView = (OsmandMapTileView) findViewById(R.id.MapView);
    mapView.setTrackBallDelegate(
        new OsmandMapTileView.OnTrackBallListener() {
          @Override
          public boolean onTrackBallEvent(MotionEvent e) {
            showAndHideMapPosition();
            return MapActivity.this.onTrackballEvent(e);
          }
        });
    mapView.setAccessibilityActions(new MapAccessibilityActions(this));
    if (mapViewTrackingUtilities == null) {
      mapViewTrackingUtilities = new MapViewTrackingUtilities(app);
    }
    mapViewTrackingUtilities.setMapView(mapView);

    // Do some action on close
    startProgressDialog.setOnDismissListener(
        new DialogInterface.OnDismissListener() {
          @Override
          public void onDismiss(DialogInterface dialog) {
            app.getResourceManager().getRenderer().clearCache();
            mapView.refreshMap(true);
          }
        });

    app.getResourceManager()
        .getMapTileDownloader()
        .addDownloaderCallback(
            new IMapDownloaderCallback() {
              @Override
              public void tileDownloaded(DownloadRequest request) {
                if (request != null && !request.error && request.fileToSave != null) {
                  ResourceManager mgr = app.getResourceManager();
                  mgr.tileDownloaded(request);
                }
                if (request == null || !request.error) {
                  mapView.tileDownloaded(request);
                }
              }
            });
    createProgressBarForRouting();
    // This situtation could be when navigation suddenly crashed and after restarting
    // it tries to continue the last route
    if (settings.FOLLOW_THE_ROUTE.get()
        && !app.getRoutingHelper().isRouteCalculated()
        && !app.getRoutingHelper().isRouteBeingCalculated()) {
      FailSafeFuntions.restoreRoutingMode(this);
    }

    mapLayers.createLayers(mapView);

    if (!settings.isLastKnownMapLocation()) {
      // show first time when application ran
      net.osmand.Location location = app.getLocationProvider().getFirstTimeRunDefaultLocation();
      if (location != null) {
        mapView.setLatLon(location.getLatitude(), location.getLongitude());
        mapView.setZoom(14);
      }
    }
    addDialogProvider(mapActions);
    OsmandPlugin.onMapActivityCreate(this);
    if (lockView != null) {
      ((FrameLayout) mapView.getParent()).addView(lockView);
    }
  }