Beispiel #1
0
 public void updateLocation(Location currentLocation) {
   if (isFollowingMode()
       || (settings.getPointToStart() == null && isRoutePlanningMode)
       || app.getLocationProvider().getLocationSimulation().isRouteAnimating()) {
     setCurrentLocation(currentLocation, false);
   }
 }
 public AlarmWidget(final OsmandApplication app, MapActivity ma) {
   layout = ma.findViewById(R.id.map_alarm_warning);
   icon = (ImageView) ma.findViewById(R.id.map_alarm_warning_icon);
   text = (TextView) ma.findViewById(R.id.map_alarm_warning_text);
   settings = app.getSettings();
   rh = ma.getRoutingHelper();
   trackingUtilities = ma.getMapViewTrackingUtilities();
   locationProvider = app.getLocationProvider();
   wh = app.getWaypointHelper();
 }
 public TopTextView(OsmandApplication app, MapActivity map) {
   topBar = map.findViewById(R.id.map_top_bar);
   addressText = (TextView) map.findViewById(R.id.map_address_text);
   addressTextShadow = (TextView) map.findViewById(R.id.map_address_text_shadow);
   waypointInfoBar = map.findViewById(R.id.waypoint_info_bar);
   this.routingHelper = app.getRoutingHelper();
   locationProvider = app.getLocationProvider();
   this.map = map;
   settings = app.getSettings();
   waypointHelper = app.getWaypointHelper();
   updateVisibility(false);
   turnDrawable = new NextTurnInfoWidget.TurnDrawable(map);
 }
Beispiel #4
0
 public void startNavigation() {
   stopCounter();
   OsmandApplication app = mapActivity.getMyApplication();
   RoutingHelper routingHelper = app.getRoutingHelper();
   if (routingHelper.isFollowingMode()) {
     switchToRouteFollowingLayout();
   } else {
     if (!app.getTargetPointsHelper().checkPointToNavigateShort()) {
       mapRouteInfoControlDialog.showDialog();
     } else {
       touchEvent = 0;
       mapActivity.getMapViewTrackingUtilities().backToLocationImpl();
       app.getSettings().FOLLOW_THE_ROUTE.set(true);
       routingHelper.setFollowingMode(true);
       routingHelper.setRoutePlanningMode(false);
       mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
       app.getRoutingHelper().notifyIfRouteIsCalculated();
       routingHelper.setCurrentLocation(app.getLocationProvider().getLastKnownLocation(), false);
     }
   }
 }
  @Override
  protected void onPause() {
    super.onPause();
    app.getLocationProvider().pauseAllUpdates();
    app.getDaynightHelper().stopSensorIfNeeded();
    settings.APPLICATION_MODE.removeListener(applicationModeListener);

    settings.setLastKnownMapLocation((float) mapView.getLatitude(), (float) mapView.getLongitude());
    AnimateDraggingMapThread animatedThread = mapView.getAnimatedDraggingThread();
    if (animatedThread.isAnimating() && animatedThread.getTargetZoom() != 0) {
      settings.setMapLocationToShow(
          animatedThread.getTargetLatitude(),
          animatedThread.getTargetLongitude(),
          (int) animatedThread.getTargetZoom());
    }

    settings.setLastKnownMapZoom(mapView.getZoom());
    settings.MAP_ACTIVITY_ENABLED.set(false);
    app.getResourceManager().interruptRendering();
    app.getResourceManager().setBusyIndicator(null);
    OsmandPlugin.onMapActivityPause(this);
  }
  public TextInfoWidget createGPSInfoControl(final MapActivity map) {
    final OsmandApplication app = map.getMyApplication();
    final OsmAndLocationProvider loc = app.getLocationProvider();
    final TextInfoWidget gpsInfoControl =
        new TextInfoWidget(map) {
          private int u = -1;
          private int f = -1;

          @Override
          public boolean updateInfo(DrawSettings d) {
            GPSInfo gpsInfo = loc.getGPSInfo();
            if (gpsInfo.usedSatellites != u || gpsInfo.foundSatellites != f) {
              u = gpsInfo.usedSatellites;
              f = gpsInfo.foundSatellites;
              setText(gpsInfo.usedSatellites + "/" + gpsInfo.foundSatellites, "");
              return true;
            }
            return false;
          }
        };
    gpsInfoControl.setIcons(R.drawable.widget_gps_info_day, R.drawable.widget_gps_info_night);
    gpsInfoControl.setText(null, null);
    gpsInfoControl.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            if (app.getNavigationService() != null) {
              AlertDialog.Builder dlg = new AlertDialog.Builder(map);
              dlg.setTitle(app.getString(R.string.sleep_mode_stop_dialog));

              // Show currently active wake-up interval
              int soi = app.getNavigationService().getServiceOffInterval();
              if (soi == 0) {
                dlg.setMessage(
                    app.getString(R.string.gps_wake_up_timer)
                        + ": "
                        + app.getString(R.string.int_continuosly));
              } else if (soi <= 90000) {
                dlg.setMessage(
                    app.getString(R.string.gps_wake_up_timer)
                        + ": "
                        + Integer.toString(soi / 1000)
                        + " "
                        + app.getString(R.string.int_seconds));
              } else {
                dlg.setMessage(
                    app.getString(R.string.gps_wake_up_timer)
                        + ": "
                        + Integer.toString(soi / 1000 / 60)
                        + " "
                        + app.getString(R.string.int_min));
              }

              dlg.setPositiveButton(app.getString(R.string.keep_navigation_service), null);
              dlg.setNegativeButton(
                  app.getString(R.string.stop_navigation_service),
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                      Intent serviceIntent = new Intent(app, NavigationService.class);
                      app.stopService(serviceIntent);
                    }
                  });
              dlg.show();

            } else {
              final ValueHolder<Integer> vs = new ValueHolder<Integer>();
              vs.value = 0;
              final AlertDialog[] dlgshow = new AlertDialog[1];
              AlertDialog.Builder dlg = new AlertDialog.Builder(map);
              dlg.setTitle(app.getString(R.string.enable_sleep_mode));
              WindowManager mgr = (WindowManager) map.getSystemService(Context.WINDOW_SERVICE);
              DisplayMetrics dm = new DisplayMetrics();
              mgr.getDefaultDisplay().getMetrics(dm);
              LinearLayout ll =
                  OsmandMonitoringPlugin.createIntervalChooseLayout(
                      map,
                      app.getString(R.string.gps_wake_up_timer) + " : %s",
                      OsmandMonitoringPlugin.SECONDS,
                      OsmandMonitoringPlugin.MINUTES,
                      null,
                      vs,
                      dm);
              if (Version.isGpsStatusEnabled(app)) {
                dlg.setNeutralButton(
                    R.string.gps_status,
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                        new StartGPSStatus(map).run();
                      }
                    });
              }
              dlg.setView(ll);
              dlg.setPositiveButton(
                  R.string.shared_string_ok,
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      app.startNavigationService(NavigationService.USED_BY_WAKE_UP, vs.value);
                    }
                  });
              dlg.setNegativeButton(R.string.shared_string_cancel, null);
              dlgshow[0] = dlg.show();
            }
          }
        });
    return gpsInfoControl;
  }
  @Override
  protected void onResume() {
    super.onResume();
    cancelNotification();
    if (settings.MAP_SCREEN_ORIENTATION.get() != getRequestedOrientation()) {
      setRequestedOrientation(settings.MAP_SCREEN_ORIENTATION.get());
      // can't return from this method we are not sure if activity will be recreated or not
    }

    app.getLocationProvider().checkIfLastKnownLocationIsValid();
    // for voice navigation
    if (settings.AUDIO_STREAM_GUIDANCE.get() != null) {
      setVolumeControlStream(settings.AUDIO_STREAM_GUIDANCE.get());
    } else {
      setVolumeControlStream(AudioManager.STREAM_MUSIC);
    }

    applicationModeListener =
        new StateChangedListener<ApplicationMode>() {
          @Override
          public void stateChanged(ApplicationMode change) {
            updateApplicationModeSettings();
          }
        };
    settings.APPLICATION_MODE.addListener(applicationModeListener);
    updateApplicationModeSettings();

    String filterId = settings.getPoiFilterForMap();
    PoiFilter poiFilter = app.getPoiFilters().getFilterById(filterId);
    if (poiFilter == null) {
      poiFilter = new PoiFilter(null, app);
    }

    mapLayers.getPoiMapLayer().setFilter(poiFilter);

    // if destination point was changed try to recalculate route
    TargetPointsHelper targets = app.getTargetPointsHelper();
    RoutingHelper routingHelper = app.getRoutingHelper();
    if (routingHelper.isFollowingMode()
        && (!Algorithms.objectEquals(targets.getPointToNavigate(), routingHelper.getFinalLocation())
            || !Algorithms.objectEquals(
                targets.getIntermediatePoints(), routingHelper.getIntermediatePoints()))) {
      routingHelper.setFinalAndCurrentLocation(
          targets.getPointToNavigate(),
          targets.getIntermediatePoints(),
          app.getLocationProvider().getLastKnownLocation(),
          routingHelper.getCurrentGPXRoute());
    }
    app.getLocationProvider().resumeAllUpdates();

    if (settings != null && settings.isLastKnownMapLocation()) {
      LatLon l = settings.getLastKnownMapLocation();
      mapView.setLatLon(l.getLatitude(), l.getLongitude());
      mapView.setZoom(settings.getLastKnownMapZoom());
    }

    settings.MAP_ACTIVITY_ENABLED.set(true);
    checkExternalStorage();
    showAndHideMapPosition();

    LatLon cur = new LatLon(mapView.getLatitude(), mapView.getLongitude());
    LatLon latLonToShow = settings.getAndClearMapLocationToShow();
    String mapLabelToShow = settings.getAndClearMapLabelToShow();
    Object toShow = settings.getAndClearObjectToShow();
    if (settings.isRouteToPointNavigateAndClear()) {
      // always enable and follow and let calculate it (GPS is not accessible in garage)
      mapActions.getDirections(null, null, false);
    }
    if (mapLabelToShow != null && latLonToShow != null) {
      mapLayers.getContextMenuLayer().setSelectedObject(toShow);
      mapLayers.getContextMenuLayer().setLocation(latLonToShow, mapLabelToShow);
    }
    if (latLonToShow != null && !latLonToShow.equals(cur)) {
      mapView
          .getAnimatedDraggingThread()
          .startMoving(
              latLonToShow.getLatitude(),
              latLonToShow.getLongitude(),
              settings.getMapZoomToShow(),
              true);
    }
    if (latLonToShow != null) {
      // remember if map should come back to isMapLinkedToLocation=true
      mapViewTrackingUtilities.setMapLinkedToLocation(false);
    }

    View progress = mapLayers.getMapInfoLayer().getProgressBar();
    if (progress != null) {
      app.getResourceManager().setBusyIndicator(new BusyIndicator(this, progress));
    }

    OsmandPlugin.onMapActivityResume(this);
    mapView.refreshMap(true);
  }
  @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);
    }
  }