Search in sources :

Example 1 with RoutingHelper

use of net.osmand.plus.routing.RoutingHelper in project Osmand by osmandapp.

the class FailSafeFuntions method enterRoutingMode.

public static void enterRoutingMode(MapActivity ma, GPXRouteParamsBuilder gpxRoute) {
    OsmandApplication app = ma.getMyApplication();
    ma.getMapViewTrackingUtilities().backToLocationImpl();
    RoutingHelper routingHelper = app.getRoutingHelper();
    if (gpxRoute == null) {
        app.getSettings().FOLLOW_THE_GPX_ROUTE.set(null);
    }
    routingHelper.setGpxParams(gpxRoute);
    if (app.getTargetPointsHelper().getPointToStart() == null) {
        app.getTargetPointsHelper().setStartPoint(null, false, null);
    }
    app.getSettings().FOLLOW_THE_ROUTE.set(true);
    routingHelper.setFollowingMode(true);
    app.getTargetPointsHelper().updateRouteAndRefresh(true);
    app.initVoiceCommandPlayer(ma, routingHelper.getAppMode(), true, null, false, false);
    if (ma.getDashboard().isVisible()) {
        ma.getDashboard().hideDashboard();
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) RoutingHelper(net.osmand.plus.routing.RoutingHelper)

Example 2 with RoutingHelper

use of net.osmand.plus.routing.RoutingHelper in project Osmand by osmandapp.

the class MapActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    long tm = System.currentTimeMillis();
    if (app.getMapMarkersHelper().getPlanRouteContext().isFragmentVisible()) {
        PlanRouteFragment.showInstance(this);
    }
    if (app.isApplicationInitializing() || DashboardOnMap.staticVisible) {
        if (!dashboardOnMap.isVisible()) {
            if (settings.SHOW_DASHBOARD_ON_START.get()) {
                dashboardOnMap.setDashboardVisibility(true, DashboardOnMap.staticVisibleType);
            } else {
                if (ErrorBottomSheetDialog.shouldShow(settings, this)) {
                    SecondSplashScreenFragment.SHOW = false;
                    new ErrorBottomSheetDialog().show(getSupportFragmentManager(), "dialog");
                } else if (RateUsBottomSheetDialog.shouldShow(app)) {
                    SecondSplashScreenFragment.SHOW = false;
                    new RateUsBottomSheetDialog().show(getSupportFragmentManager(), "dialog");
                }
            }
        } else {
            dashboardOnMap.updateDashboard();
        }
    }
    dashboardOnMap.updateLocation(true, true, false);
    getMyApplication().getNotificationHelper().refreshNotifications();
    // fixing bug with action bar appearing on android 2.3.3
    if (getSupportActionBar() != null) {
        getSupportActionBar().hide();
    }
    app.getLocationProvider().checkIfLastKnownLocationIsValid();
    // for voice navigation
    ApplicationMode routingAppMode = getRoutingHelper().getAppMode();
    if (routingAppMode != null && settings.AUDIO_STREAM_GUIDANCE.getModeValue(routingAppMode) != null) {
        setVolumeControlStream(settings.AUDIO_STREAM_GUIDANCE.getModeValue(routingAppMode));
    } else {
        setVolumeControlStream(AudioManager.STREAM_MUSIC);
    }
    changeKeyguardFlags();
    applicationModeListener = new StateChangedListener<ApplicationMode>() {

        @Override
        public void stateChanged(ApplicationMode change) {
            updateApplicationModeSettings();
        }
    };
    settings.APPLICATION_MODE.addListener(applicationModeListener);
    updateApplicationModeSettings();
    // if destination point was changed try to recalculate route
    TargetPointsHelper targets = app.getTargetPointsHelper();
    RoutingHelper routingHelper = app.getRoutingHelper();
    if (routingHelper.isFollowingMode() && (!Algorithms.objectEquals(targets.getPointToNavigate().point, routingHelper.getFinalLocation()) || !Algorithms.objectEquals(targets.getIntermediatePointsLatLonNavigation(), routingHelper.getIntermediatePoints()))) {
        targets.updateRouteAndRefresh(true);
    }
    app.getLocationProvider().resumeAllUpdates();
    if (settings != null && settings.isLastKnownMapLocation() && !intentLocation) {
        LatLon l = settings.getLastKnownMapLocation();
        mapView.setLatLon(l.getLatitude(), l.getLongitude());
        mapView.setIntZoom(settings.getLastKnownMapZoom());
    } else {
        intentLocation = false;
    }
    settings.MAP_ACTIVITY_ENABLED.set(true);
    checkExternalStorage();
    showAndHideMapPosition();
    readLocationToShow();
    OsmandPlugin.onMapActivityResume(this);
    final Intent intent = getIntent();
    if (intent != null) {
        if (Intent.ACTION_VIEW.equals(intent.getAction())) {
            if (intent.getData() != null) {
                final Uri data = intent.getData();
                final String scheme = data.getScheme();
                if ("file".equals(scheme)) {
                    importHelper.handleFileImport(data, new File(data.getPath()).getName(), true);
                    setIntent(null);
                } else if ("content".equals(scheme)) {
                    importHelper.handleContentImport(data, true);
                    setIntent(null);
                } else if ("google.navigation".equals(scheme) || "osmand.navigation".equals(scheme)) {
                    parseNavigationIntent(data);
                } else if ("osmand.api".equals(scheme)) {
                    ExternalApiHelper apiHelper = new ExternalApiHelper(this);
                    Intent result = apiHelper.processApiRequest(intent);
                    setResult(apiHelper.getResultCode(), result);
                    result.setAction(null);
                    setIntent(result);
                    if (apiHelper.needFinish()) {
                        finish();
                    }
                }
            }
        }
        if (intent.hasExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS)) {
            Bundle openMapMarkersGroupsExtra = intent.getBundleExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS);
            if (openMapMarkersGroupsExtra != null) {
                MapMarkersDialogFragment.showInstance(this, openMapMarkersGroupsExtra.getString(MapMarkersHelper.MapMarkersGroup.MARKERS_SYNC_GROUP_ID));
            }
            setIntent(null);
        }
    }
    mapView.refreshMap(true);
    if (atlasMapRendererView != null) {
        atlasMapRendererView.handleOnResume();
    }
    app.getDownloadThread().setUiActivity(this);
    if (mapViewTrackingUtilities.getShowRouteFinishDialog()) {
        DestinationReachedMenu.show(this);
        mapViewTrackingUtilities.setShowRouteFinishDialog(false);
    }
    routingHelper.addListener(this);
    app.getMapMarkersHelper().addListener(this);
    DiscountHelper.checkAndDisplay(this);
    QuickSearchDialogFragment searchDialogFragment = getQuickSearchDialogFragment();
    if (searchDialogFragment != null) {
        if (searchDialogFragment.isSearchHidden()) {
            searchDialogFragment.hide();
            searchDialogFragment.restoreToolbar();
        }
    }
    getMyApplication().getAppCustomization().resumeActivity(MapActivity.class, this);
    if (System.currentTimeMillis() - tm > 50) {
        System.err.println("OnCreate for MapActivity took " + (System.currentTimeMillis() - tm) + " ms");
    }
    boolean showWelcomeScreen = ((app.getAppInitializer().isFirstTime() && Version.isDeveloperVersion(app)) || !app.getResourceManager().isAnyMapInstalled()) && FirstUsageWelcomeFragment.SHOW;
    if (!showWelcomeScreen && !permissionDone && !app.getAppInitializer().isFirstTime()) {
        if (!permissionAsked) {
            if (app.isExternalStorageDirectoryReadOnly() && getSupportFragmentManager().findFragmentByTag(DataStoragePlaceDialogFragment.TAG) == null) {
                if (DownloadActivity.hasPermissionToWriteExternalStorage(this)) {
                    DataStoragePlaceDialogFragment.showInstance(getSupportFragmentManager(), true);
                } else {
                    ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, DownloadActivity.PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
                }
            }
        } else {
            if (permissionGranted) {
                restartApp();
            } else if (getSupportFragmentManager().findFragmentByTag(DataStoragePlaceDialogFragment.TAG) == null) {
                DataStoragePlaceDialogFragment.showInstance(getSupportFragmentManager(), true);
            }
            permissionAsked = false;
            permissionGranted = false;
            permissionDone = true;
        }
    }
    enableDrawer();
    if (showWelcomeScreen) {
        SecondSplashScreenFragment.SHOW = false;
        getSupportFragmentManager().beginTransaction().add(R.id.fragmentContainer, new FirstUsageWelcomeFragment(), FirstUsageWelcomeFragment.TAG).commitAllowingStateLoss();
    } else if (!isFirstScreenShowing() && XMasDialogFragment.shouldShowXmasDialog(app)) {
        SecondSplashScreenFragment.SHOW = false;
        new XMasDialogFragment().show(getSupportFragmentManager(), XMasDialogFragment.TAG);
    }
    FirstUsageWelcomeFragment.SHOW = false;
    if (SecondSplashScreenFragment.SHOW) {
        SecondSplashScreenFragment.SHOW = false;
        SecondSplashScreenFragment.VISIBLE = true;
        getSupportFragmentManager().beginTransaction().add(R.id.fragmentContainer, new SecondSplashScreenFragment(), SecondSplashScreenFragment.TAG).commitAllowingStateLoss();
        mapView.setOnDrawMapListener(this);
        splashScreenTimer = new Timer();
        splashScreenTimer.schedule(new TimerTask() {

            @Override
            public void run() {
                dismissSecondSplashScreen();
            }
        }, SECOND_SPLASH_TIME_OUT);
    } else {
        if (SecondSplashScreenFragment.VISIBLE) {
            dismissSecondSplashScreen();
        }
        // setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
        if (settings.MAP_SCREEN_ORIENTATION.get() != getRequestedOrientation()) {
            setRequestedOrientation(settings.MAP_SCREEN_ORIENTATION.get());
        }
    }
}
Also used : SecondSplashScreenFragment(net.osmand.SecondSplashScreenFragment) ExternalApiHelper(net.osmand.plus.helpers.ExternalApiHelper) Bundle(android.os.Bundle) ErrorBottomSheetDialog(net.osmand.plus.dialogs.ErrorBottomSheetDialog) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ApplicationMode(net.osmand.plus.ApplicationMode) RoutingHelper(net.osmand.plus.routing.RoutingHelper) Uri(android.net.Uri) LatLon(net.osmand.data.LatLon) Timer(java.util.Timer) TimerTask(java.util.TimerTask) QuickSearchDialogFragment(net.osmand.plus.search.QuickSearchDialogFragment) FirstUsageWelcomeFragment(net.osmand.plus.firstusage.FirstUsageWelcomeFragment) XMasDialogFragment(net.osmand.plus.dialogs.XMasDialogFragment) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) File(java.io.File) RateUsBottomSheetDialog(net.osmand.plus.dialogs.RateUsBottomSheetDialog)

Example 3 with RoutingHelper

use of net.osmand.plus.routing.RoutingHelper in project Osmand by osmandapp.

the class MapActivity method newRouteIsCalculated.

@Override
public void newRouteIsCalculated(boolean newRoute, ValueHolder<Boolean> showToast) {
    RoutingHelper rh = app.getRoutingHelper();
    if (newRoute && rh.isRoutePlanningMode() && mapView != null) {
        Location lt = rh.getLastProjection();
        if (lt == null) {
            lt = app.getTargetPointsHelper().getPointToStartLocation();
        }
        if (lt != null) {
            double left = lt.getLongitude(), right = lt.getLongitude();
            double top = lt.getLatitude(), bottom = lt.getLatitude();
            List<Location> list = rh.getCurrentCalculatedRoute();
            for (Location l : list) {
                left = Math.min(left, l.getLongitude());
                right = Math.max(right, l.getLongitude());
                top = Math.max(top, l.getLatitude());
                bottom = Math.min(bottom, l.getLatitude());
            }
            List<TargetPoint> targetPoints = app.getTargetPointsHelper().getIntermediatePointsWithTarget();
            for (TargetPoint l : targetPoints) {
                left = Math.min(left, l.getLongitude());
                right = Math.max(right, l.getLongitude());
                top = Math.max(top, l.getLatitude());
                bottom = Math.min(bottom, l.getLatitude());
            }
            RotatedTileBox tb = mapView.getCurrentRotatedTileBox().copy();
            int tileBoxWidthPx = 0;
            int tileBoxHeightPx = 0;
            MapRouteInfoMenu routeInfoMenu = mapLayers.getMapControlsLayer().getMapRouteInfoMenu();
            WeakReference<MapRouteInfoMenuFragment> fragmentRef = routeInfoMenu.findMenuFragment();
            if (fragmentRef != null) {
                MapRouteInfoMenuFragment f = fragmentRef.get();
                if (landscapeLayout) {
                    tileBoxWidthPx = tb.getPixWidth() - f.getWidth();
                } else {
                    tileBoxHeightPx = tb.getPixHeight() - f.getHeight();
                }
            }
            mapView.fitRectToMap(left, right, top, bottom, tileBoxWidthPx, tileBoxHeightPx, 0);
        }
    }
}
Also used : RotatedTileBox(net.osmand.data.RotatedTileBox) MapRouteInfoMenu(net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) MapRouteInfoMenuFragment(net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenuFragment) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) QuadPoint(net.osmand.data.QuadPoint) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) Location(net.osmand.Location)

Example 4 with RoutingHelper

use of net.osmand.plus.routing.RoutingHelper in project Osmand by osmandapp.

the class MapControlsLayer method replaceDestination.

public void replaceDestination(LatLon latLon) {
    RoutingHelper routingHelper = mapActivity.getMyApplication().getRoutingHelper();
    if (latLon != null) {
        if (routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode()) {
            PointDescription pointDescription = getPointDescriptionForTarget(latLon);
            mapActivity.getContextMenu().close();
            final TargetPointsHelper targets = mapActivity.getMyApplication().getTargetPointsHelper();
            targets.navigateToPoint(latLon, true, -1, pointDescription);
        } else {
            addDestination(latLon);
        }
    }
}
Also used : PointDescription(net.osmand.data.PointDescription) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPointsHelper(net.osmand.plus.TargetPointsHelper)

Example 5 with RoutingHelper

use of net.osmand.plus.routing.RoutingHelper in project Osmand by osmandapp.

the class MapControlsLayer method onTouchEvent.

@Override
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
    touchEvent = System.currentTimeMillis();
    RoutingHelper rh = mapActivity.getRoutingHelper();
    if (rh.isFollowingMode()) {
        mapActivity.refreshMap();
    }
    return false;
}
Also used : RoutingHelper(net.osmand.plus.routing.RoutingHelper)

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