Search in sources :

Example 6 with TargetPointsHelper

use of net.osmand.plus.TargetPointsHelper in project Osmand by osmandapp.

the class MapActivityActions method recalculateRoute.

public void recalculateRoute(boolean showDialog) {
    settings.USE_INTERMEDIATE_POINTS_NAVIGATION.set(true);
    OsmandApplication app = mapActivity.getMyApplication();
    TargetPointsHelper targets = app.getTargetPointsHelper();
    ApplicationMode mode = getRouteMode(null);
    // app.getSettings().APPLICATION_MODE.set(mode);
    app.getRoutingHelper().setAppMode(mode);
    // Test for #2810: No need to init player here?
    // app.initVoiceCommandPlayer(mapActivity, true, null, false, false);
    // save application mode controls
    settings.FOLLOW_THE_ROUTE.set(false);
    app.getRoutingHelper().setFollowingMode(false);
    app.getRoutingHelper().setRoutePlanningMode(true);
    // reset start point
    targets.setStartPoint(null, false, null);
    // then update start and destination point
    targets.updateRouteAndRefresh(true);
    mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
    mapActivity.getMapView().refreshMap(true);
    if (showDialog) {
        mapActivity.getMapLayers().getMapControlsLayer().showDialog();
    }
    if (targets.hasTooLongDistanceToNavigate()) {
        app.showToastMessage(R.string.route_is_too_long_v2);
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) ApplicationMode(net.osmand.plus.ApplicationMode) TargetPointsHelper(net.osmand.plus.TargetPointsHelper)

Example 7 with TargetPointsHelper

use of net.osmand.plus.TargetPointsHelper 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 8 with TargetPointsHelper

use of net.osmand.plus.TargetPointsHelper 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 9 with TargetPointsHelper

use of net.osmand.plus.TargetPointsHelper in project Osmand by osmandapp.

the class MapControlsLayer method addDestination.

public void addDestination(LatLon latLon) {
    if (latLon != null) {
        if (!OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
            requestedLatLon = latLon;
            ActivityCompat.requestPermissions(mapActivity, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION_FOR_ADD_DESTINATION_PERMISSION);
        } else {
            PointDescription pointDescription = getPointDescriptionForTarget(latLon);
            mapActivity.getContextMenu().close();
            final TargetPointsHelper targets = mapActivity.getMyApplication().getTargetPointsHelper();
            RoutingHelper routingHelper = mapActivity.getMyApplication().getRoutingHelper();
            if (routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode()) {
                targets.navigateToPoint(latLon, true, targets.getIntermediatePoints().size() + 1, pointDescription);
            } else if (targets.getIntermediatePoints().isEmpty()) {
                startRoutePlanningWithDestination(latLon, pointDescription, targets);
            }
        }
    }
}
Also used : PointDescription(net.osmand.data.PointDescription) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPointsHelper(net.osmand.plus.TargetPointsHelper)

Example 10 with TargetPointsHelper

use of net.osmand.plus.TargetPointsHelper in project Osmand by osmandapp.

the class PointNavigationLayer method collectObjectsFromPoint.

@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
    if (tileBox.getZoom() >= 3) {
        TargetPointsHelper tg = map.getMyApplication().getTargetPointsHelper();
        List<TargetPoint> intermediatePoints = tg.getAllPoints();
        int r = getDefaultRadiusPoi(tileBox);
        for (int i = 0; i < intermediatePoints.size(); i++) {
            TargetPoint tp = intermediatePoints.get(i);
            LatLon latLon = tp.point;
            if (latLon != null) {
                int ex = (int) point.x;
                int ey = (int) point.y;
                int x = (int) tileBox.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
                int y = (int) tileBox.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
                if (calculateBelongs(ex, ey, x, y, r)) {
                    o.add(tp);
                }
            }
        }
    }
}
Also used : LatLon(net.osmand.data.LatLon) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) Paint(android.graphics.Paint)

Aggregations

TargetPointsHelper (net.osmand.plus.TargetPointsHelper)36 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)19 LatLon (net.osmand.data.LatLon)18 PointDescription (net.osmand.data.PointDescription)11 TextView (android.widget.TextView)8 OsmandApplication (net.osmand.plus.OsmandApplication)8 RoutingHelper (net.osmand.plus.routing.RoutingHelper)8 View (android.view.View)7 Location (net.osmand.Location)7 ImageView (android.widget.ImageView)5 DialogInterface (android.content.DialogInterface)4 AlertDialog (android.support.v7.app.AlertDialog)4 AdapterView (android.widget.AdapterView)4 ArrayList (java.util.ArrayList)4 ApplicationMode (net.osmand.plus.ApplicationMode)4 Paint (android.graphics.Paint)3 Bundle (android.os.Bundle)3 ImageButton (android.widget.ImageButton)3 SuppressLint (android.annotation.SuppressLint)2 Intent (android.content.Intent)2