Search in sources :

Example 26 with RoutingHelper

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);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) RoutingHelper(net.osmand.plus.routing.RoutingHelper) Location(android.location.Location)

Example 27 with RoutingHelper

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));
}
Also used : Context(android.content.Context) AlertDialog(android.support.v7.app.AlertDialog) IntentFilter(android.content.IntentFilter) DialogInterface(android.content.DialogInterface) FileNotFoundException(java.io.FileNotFoundException) Intent(android.content.Intent) RoutingHelper(net.osmand.plus.routing.RoutingHelper) BroadcastReceiver(android.content.BroadcastReceiver) Uri(android.net.Uri) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileDescriptor(java.io.FileDescriptor) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ParcelFileDescriptor(android.os.ParcelFileDescriptor) GPXFile(net.osmand.plus.GPXUtilities.GPXFile)

Example 28 with RoutingHelper

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);
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPointsHelper(net.osmand.plus.TargetPointsHelper)

Example 29 with RoutingHelper

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);
    }
}
Also used : RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) SuppressLint(android.annotation.SuppressLint)

Example 30 with RoutingHelper

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;
}
Also used : LatLon(net.osmand.data.LatLon) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint)

Aggregations

RoutingHelper (net.osmand.plus.routing.RoutingHelper)38 LatLon (net.osmand.data.LatLon)9 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)9 OsmandApplication (net.osmand.plus.OsmandApplication)8 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)8 PointDescription (net.osmand.data.PointDescription)7 Intent (android.content.Intent)6 DialogInterface (android.content.DialogInterface)5 AlertDialog (android.support.v7.app.AlertDialog)5 View (android.view.View)5 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 Paint (android.graphics.Paint)4 NextDirectionInfo (net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo)4 TurnType (net.osmand.router.TurnType)4 PendingIntent (android.app.PendingIntent)3 BroadcastReceiver (android.content.BroadcastReceiver)3 Context (android.content.Context)3 IntentFilter (android.content.IntentFilter)3 Uri (android.net.Uri)3