use of net.osmand.plus.routing.RoutingHelper in project Osmand by osmandapp.
the class OsmAndLocationProvider method scheduleCheckIfGpsLost.
private void scheduleCheckIfGpsLost(final net.osmand.Location location) {
final RoutingHelper routingHelper = app.getRoutingHelper();
if (location != null) {
final long fixTime = location.getTime();
app.runMessageInUIThreadAndCancelPrevious(LOST_LOCATION_MSG_ID, new Runnable() {
@Override
public void run() {
net.osmand.Location lastKnown = getLastKnownLocation();
if (lastKnown != null && lastKnown.getTime() > fixTime) {
// false positive case, still strange how we got here with removeMessages
return;
}
gpsSignalLost = true;
if (routingHelper.isFollowingMode() && routingHelper.getLeftDistance() > 0) {
routingHelper.getVoiceRouter().gpsLocationLost();
}
setLocation(null);
}
}, LOST_LOCATION_CHECK_DELAY);
if (routingHelper.isFollowingMode() && routingHelper.getLeftDistance() > 0 && simulatePosition == null) {
app.runMessageInUIThreadAndCancelPrevious(START_SIMULATE_LOCATION_MSG_ID, new Runnable() {
@Override
public void run() {
net.osmand.Location lastKnown = getLastKnownLocation();
if (lastKnown != null && lastKnown.getTime() > fixTime) {
// false positive case, still strange how we got here with removeMessages
return;
}
List<RouteSegmentResult> tunnel = routingHelper.getUpcomingTunnel(1000);
if (tunnel != null) {
simulatePosition = new SimulationProvider();
simulatePosition.startSimulation(tunnel, location);
simulatePositionImpl();
}
}
}, START_LOCATION_SIMULATION_DELAY);
}
}
}
use of net.osmand.plus.routing.RoutingHelper in project Osmand by osmandapp.
the class OsmandAidlApi method registerNavigateGpxReceiver.
private void registerNavigateGpxReceiver(final MapActivity mapActivity) {
navigateGpxReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
boolean force = intent.getBooleanExtra(AIDL_FORCE, false);
GPXFile gpx = null;
if (intent.getStringExtra(AIDL_DATA) != null) {
String gpxStr = intent.getStringExtra(AIDL_DATA);
if (!Algorithms.isEmpty(gpxStr)) {
gpx = GPXUtilities.loadGPXFile(mapActivity, new ByteArrayInputStream(gpxStr.getBytes()));
}
} else if (intent.getParcelableExtra(AIDL_URI) != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
Uri gpxUri = intent.getParcelableExtra(AIDL_URI);
ParcelFileDescriptor gpxParcelDescriptor = null;
try {
gpxParcelDescriptor = mapActivity.getContentResolver().openFileDescriptor(gpxUri, "r");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if (gpxParcelDescriptor != null) {
FileDescriptor fileDescriptor = gpxParcelDescriptor.getFileDescriptor();
gpx = GPXUtilities.loadGPXFile(mapActivity, new FileInputStream(fileDescriptor));
}
}
}
if (gpx != null) {
final RoutingHelper routingHelper = app.getRoutingHelper();
if (routingHelper.isFollowingMode() && !force) {
final GPXFile gpxFile = gpx;
AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm();
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (!routingHelper.isFollowingMode()) {
startNavigation(mapActivity, gpxFile, null, null, null, null, null);
}
}
});
} else {
startNavigation(mapActivity, gpx, null, null, null, null, null);
}
}
}
};
mapActivity.registerReceiver(navigateGpxReceiver, new IntentFilter(AIDL_NAVIGATE_GPX));
}
use of net.osmand.plus.routing.RoutingHelper in project Osmand by osmandapp.
the class OsmandAidlApi method startNavigation.
private void startNavigation(MapActivity mapActivity, GPXFile gpx, LatLon from, PointDescription fromDesc, LatLon to, PointDescription toDesc, ApplicationMode mode) {
OsmandApplication app = mapActivity.getMyApplication();
RoutingHelper routingHelper = app.getRoutingHelper();
if (gpx == null) {
app.getSettings().APPLICATION_MODE.set(mode);
final TargetPointsHelper targets = mapActivity.getMyApplication().getTargetPointsHelper();
targets.removeAllWayPoints(false, true);
targets.navigateToPoint(to, true, -1, toDesc);
}
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(gpx, from, fromDesc, true, false);
if (!app.getTargetPointsHelper().checkPointToNavigateShort()) {
mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().show();
} else {
if (app.getSettings().APPLICATION_MODE.get() != routingHelper.getAppMode()) {
app.getSettings().APPLICATION_MODE.set(routingHelper.getAppMode());
}
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);
}
}
use of net.osmand.plus.routing.RoutingHelper in project Osmand by osmandapp.
the class MapControlsLayer method updateControls.
@SuppressWarnings("deprecation")
private void updateControls(@NonNull RotatedTileBox tileBox, DrawSettings drawSettings) {
boolean isNight = drawSettings != null && drawSettings.isNightMode();
int shadw = isNight ? Color.TRANSPARENT : Color.WHITE;
int textColor = isNight ? mapActivity.getResources().getColor(R.color.widgettext_night) : Color.BLACK;
if (shadowColor != shadw) {
shadowColor = shadw;
// TODOnightMode
// updatextColor(textColor, shadw, rulerControl, zoomControls, mapMenuControls);
}
// default buttons
boolean routePlanningMode = false;
RoutingHelper rh = mapActivity.getRoutingHelper();
if (rh.isRoutePlanningMode()) {
routePlanningMode = true;
} else if ((rh.isRouteCalculated() || rh.isRouteBeingCalculated()) && !rh.isFollowingMode()) {
routePlanningMode = true;
}
boolean routeFollowingMode = !routePlanningMode && rh.isFollowingMode();
boolean routeDialogOpened = MapRouteInfoMenu.isVisible();
boolean trackDialogOpened = TrackDetailsMenu.isVisible();
boolean contextMenuOpened = !mapActivity.getContextMenu().shouldShowTopControls();
boolean showRouteCalculationControls = routePlanningMode || ((app.accessibilityEnabled() || (System.currentTimeMillis() - touchEvent < TIMEOUT_TO_SHOW_BUTTONS)) && routeFollowingMode);
updateMyLocation(rh, routeDialogOpened || trackDialogOpened || contextMenuOpened);
boolean showButtons = (showRouteCalculationControls || !routeFollowingMode) && !isInMovingMarkerMode() && !isInGpxDetailsMode() && !isInMeasurementToolMode() && !isInPlanRouteMode() && !contextMenuOpened;
// routePlanningBtn.setIconResId(routeFollowingMode ? R.drawable.ic_action_gabout_dark : R.drawable.map_directions);
if (rh.isFollowingMode()) {
routePlanningBtn.setIconResId(R.drawable.map_start_navigation);
routePlanningBtn.setIconColorId(R.color.color_myloc_distance);
} else if (routePlanningMode) {
routePlanningBtn.setIconResId(R.drawable.map_directions);
routePlanningBtn.setIconColorId(R.color.color_myloc_distance);
} else {
routePlanningBtn.setIconResId(R.drawable.map_directions);
routePlanningBtn.resetIconColors();
}
routePlanningBtn.updateVisibility(showButtons);
menuControl.updateVisibility(showButtons);
mapZoomIn.updateVisibility(!routeDialogOpened && !contextMenuOpened);
mapZoomOut.updateVisibility(!routeDialogOpened && !contextMenuOpened);
boolean forceHideCompass = routeDialogOpened || trackDialogOpened || isInMeasurementToolMode() || isInPlanRouteMode() || contextMenuOpened;
compassHud.forceHideCompass = forceHideCompass;
compassHud.updateVisibility(!forceHideCompass && shouldShowCompass());
if (layersHud.setIconResId(settings.getApplicationMode().getMapIconId())) {
layersHud.update(app, isNight);
}
layersHud.updateVisibility(!routeDialogOpened && !trackDialogOpened && !isInMeasurementToolMode() && !isInPlanRouteMode() && !contextMenuOpened);
quickSearchHud.updateVisibility(!routeDialogOpened && !trackDialogOpened && !isInMeasurementToolMode() && !isInPlanRouteMode() && !contextMenuOpened);
if (!routePlanningMode && !routeFollowingMode) {
if (mapView.isZooming()) {
lastZoom = System.currentTimeMillis();
}
// if (!mapView.isZooming() || !OsmandPlugin.isDevelopment()) {
if ((System.currentTimeMillis() - lastZoom > 1000) || !OsmandPlugin.isDevelopment()) {
zoomText.setVisibility(View.GONE);
} else {
zoomText.setVisibility(View.VISIBLE);
zoomText.setTextColor(textColor);
zoomText.setText(getZoomLevel(tileBox));
}
}
mapRouteInfoMenu.setVisible(showRouteCalculationControls);
if (!forceHideCompass) {
updateCompass(isNight);
}
for (MapHudButton mc : controls) {
mc.update(mapActivity.getMyApplication(), isNight);
}
}
use of net.osmand.plus.routing.RoutingHelper in project Osmand by osmandapp.
the class MapControlsLayer method onNavigationClick.
private void onNavigationClick() {
if (mapRouteInfoMenu != null) {
mapRouteInfoMenu.cancelSelectionFromMap();
}
MapActivity.clearPrevActivityIntent();
RoutingHelper routingHelper = mapActivity.getRoutingHelper();
if (!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) {
if (!hasTargets) {
getTargets().restoreTargetPoints(false);
if (getTargets().getPointToNavigate() == null) {
mapActivity.getMapActions().setFirstMapMarkerAsTarget();
}
}
TargetPoint start = getTargets().getPointToStart();
if (start != null) {
mapActivity.getMapActions().enterRoutePlanningMode(new LatLon(start.getLatitude(), start.getLongitude()), start.getOriginalPointDescription());
} else {
mapActivity.getMapActions().enterRoutePlanningMode(null, null);
}
} else {
showRouteInfoControlDialog();
}
hasTargets = false;
}
Aggregations