use of net.osmand.plus.routing.RoutingHelper in project Osmand by osmandapp.
the class MapControlsLayer method addFirstIntermediate.
public void addFirstIntermediate(LatLon latLon) {
if (latLon != null) {
RoutingHelper routingHelper = mapActivity.getMyApplication().getRoutingHelper();
if (routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode()) {
PointDescription pointDescription = getPointDescriptionForTarget(latLon);
mapActivity.getContextMenu().close();
final TargetPointsHelper targets = mapActivity.getMyApplication().getTargetPointsHelper();
if (routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode()) {
targets.navigateToPoint(latLon, true, 0, pointDescription);
} else if (targets.getIntermediatePoints().isEmpty()) {
startRoutePlanningWithDestination(latLon, pointDescription, targets);
}
} else {
addDestination(latLon);
}
}
}
use of net.osmand.plus.routing.RoutingHelper in project Osmand by osmandapp.
the class MapControlsLayer method navigateButton.
public void navigateButton() {
if (!OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
ActivityCompat.requestPermissions(mapActivity, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_LOCATION_FOR_NAVIGATION_FAB_PERMISSION);
} else {
final MapContextMenu menu = mapActivity.getContextMenu();
final LatLon latLon = menu.getLatLon();
final PointDescription pointDescription = menu.getPointDescriptionForTarget();
menu.hide();
final TargetPointsHelper targets = mapActivity.getMyApplication().getTargetPointsHelper();
RoutingHelper routingHelper = mapActivity.getMyApplication().getRoutingHelper();
if (routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode()) {
DirectionsDialogs.addWaypointDialogAndLaunchMap(mapActivity, latLon.getLatitude(), latLon.getLongitude(), pointDescription);
} else if (targets.getIntermediatePoints().isEmpty()) {
startRoutePlanningWithDestination(latLon, pointDescription, targets);
menu.close();
} else {
AlertDialog.Builder bld = new AlertDialog.Builder(mapActivity);
bld.setTitle(R.string.new_directions_point_dialog);
final int[] defaultVls = new int[] { 0 };
bld.setSingleChoiceItems(new String[] { mapActivity.getString(R.string.clear_intermediate_points), mapActivity.getString(R.string.keep_intermediate_points) }, 0, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
defaultVls[0] = which;
}
});
bld.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (defaultVls[0] == 0) {
targets.removeAllWayPoints(false, true);
targets.navigateToPoint(latLon, true, -1, pointDescription);
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(null, null, null, true, true);
menu.close();
} else {
targets.navigateToPoint(latLon, true, -1, pointDescription);
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(null, null, null, true, true);
menu.close();
}
}
});
bld.setNegativeButton(R.string.shared_string_cancel, null);
bld.show();
}
}
}
use of net.osmand.plus.routing.RoutingHelper in project Osmand by osmandapp.
the class MapControlsLayer method startNavigation.
public void startNavigation() {
OsmandApplication app = mapActivity.getMyApplication();
RoutingHelper routingHelper = app.getRoutingHelper();
if (routingHelper.isFollowingMode()) {
switchToRouteFollowingLayout();
if (app.getSettings().APPLICATION_MODE.get() != routingHelper.getAppMode()) {
app.getSettings().APPLICATION_MODE.set(routingHelper.getAppMode());
}
} else {
if (!app.getTargetPointsHelper().checkPointToNavigateShort()) {
mapRouteInfoMenu.show();
} else {
touchEvent = 0;
app.logEvent(mapActivity, "start_navigation");
app.getSettings().APPLICATION_MODE.set(routingHelper.getAppMode());
mapActivity.getMapViewTrackingUtilities().backToLocationImpl(17);
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 RouteInfoWidgetsFactory method createTimeControl.
public TextInfoWidget createTimeControl(final MapActivity map) {
final RoutingHelper routingHelper = map.getRoutingHelper();
final int time = R.drawable.widget_time_day;
final int timeN = R.drawable.widget_time_night;
final int timeToGo = R.drawable.widget_time_to_distance_day;
final int timeToGoN = R.drawable.widget_time_to_distance_night;
final OsmandApplication ctx = map.getMyApplication();
final OsmandPreference<Boolean> showArrival = ctx.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME;
final TextInfoWidget leftTimeControl = new TextInfoWidget(map) {
private long cachedLeftTime = 0;
@Override
public boolean updateInfo(DrawSettings drawSettings) {
setIcons(showArrival.get() ? time : timeToGo, showArrival.get() ? timeN : timeToGoN);
int time = 0;
if (routingHelper != null && routingHelper.isRouteCalculated()) {
// boolean followingMode = routingHelper.isFollowingMode();
time = routingHelper.getLeftTime();
if (time != 0) {
if (/*followingMode && */
showArrival.get()) {
long toFindTime = time * 1000 + System.currentTimeMillis();
if (Math.abs(toFindTime - cachedLeftTime) > 30000) {
cachedLeftTime = toFindTime;
setContentTitle(map.getString(R.string.access_arrival_time));
if (DateFormat.is24HourFormat(ctx)) {
// $NON-NLS-1$
setText(DateFormat.format("k:mm", toFindTime).toString(), null);
} else {
setText(DateFormat.format("h:mm", toFindTime).toString(), // $NON-NLS-1$
DateFormat.format("aa", toFindTime).toString());
}
return true;
}
} else {
if (Math.abs(time - cachedLeftTime) > 30) {
cachedLeftTime = time;
int hours = time / (60 * 60);
int minutes = (time / 60) % 60;
setContentTitle(map.getString(R.string.map_widget_time));
// $NON-NLS-1$
setText(String.format("%d:%02d", hours, minutes), null);
return true;
}
}
}
}
if (time == 0 && cachedLeftTime != 0) {
cachedLeftTime = 0;
setText(null, null);
return true;
}
return false;
}
};
leftTimeControl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showArrival.set(!showArrival.get());
leftTimeControl.setIcons(showArrival.get() ? time : timeToGo, showArrival.get() ? timeN : timeToGoN);
map.getMapView().refreshMap();
}
});
leftTimeControl.setText(null, null);
leftTimeControl.setIcons(showArrival.get() ? time : timeToGo, showArrival.get() ? timeN : timeToGoN);
return leftTimeControl;
}
use of net.osmand.plus.routing.RoutingHelper in project Osmand by osmandapp.
the class RouteInfoWidgetsFactory method createMaxSpeedControl.
public TextInfoWidget createMaxSpeedControl(final MapActivity map) {
final RoutingHelper rh = map.getMyApplication().getRoutingHelper();
final OsmAndLocationProvider locationProvider = map.getMyApplication().getLocationProvider();
final MapViewTrackingUtilities trackingUtilities = map.getMapViewTrackingUtilities();
final TextInfoWidget speedControl = new TextInfoWidget(map) {
private float cachedSpeed = 0;
@Override
public boolean updateInfo(DrawSettings drawSettings) {
float mx = 0;
if ((rh == null || !rh.isFollowingMode() || rh.isDeviatedFromRoute() || rh.getCurrentGPXRoute() != null) && trackingUtilities.isMapLinkedToLocation()) {
RouteDataObject ro = locationProvider.getLastKnownRouteSegment();
if (ro != null) {
mx = ro.getMaximumSpeed(ro.bearingVsRouteDirection(locationProvider.getLastKnownLocation()));
}
} else if (rh != null) {
mx = rh.getCurrentMaxSpeed();
} else {
mx = 0f;
}
if (cachedSpeed != mx) {
cachedSpeed = mx;
if (cachedSpeed == 0) {
setText(null, null);
} else if (cachedSpeed == RouteDataObject.NONE_MAX_SPEED) {
setText(map.getString(R.string.max_speed_none), "");
} else {
String ds = OsmAndFormatter.getFormattedSpeed(cachedSpeed, map.getMyApplication());
int ls = ds.lastIndexOf(' ');
if (ls == -1) {
setText(ds, null);
} else {
setText(ds.substring(0, ls), ds.substring(ls + 1));
}
}
return true;
}
return false;
}
};
speedControl.setIcons(R.drawable.widget_max_speed_day, R.drawable.widget_max_speed_night);
speedControl.setText(null, null);
return speedControl;
}
Aggregations