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();
}
}
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());
}
}
}
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);
}
}
}
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);
}
}
}
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;
}
Aggregations