use of net.osmand.plus.routing.RoutingHelper in project Osmand by osmandapp.
the class MeasurementEditingContext method scheduleRouteCalculateIfNotEmpty.
void scheduleRouteCalculateIfNotEmpty() {
needUpdateCacheForSnap = true;
if (application == null || (before.points.size() == 0 && after.points.size() == 0)) {
return;
}
snapToRoadPairsToCalculate.clear();
findPointsToCalculate(Arrays.asList(before.points, after.points));
RoutingHelper routingHelper = application.getRoutingHelper();
if (!snapToRoadPairsToCalculate.isEmpty() && progressListener != null && !routingHelper.isRouteBeingCalculated()) {
routingHelper.startRouteCalculationThread(getParams(), true, true);
application.runInUIThread(new Runnable() {
@Override
public void run() {
progressListener.showProgressBar();
}
});
}
}
use of net.osmand.plus.routing.RoutingHelper in project Osmand by osmandapp.
the class NavigationInfo method updateCompassValue.
@Override
public synchronized void updateCompassValue(float heading) {
RoutingHelper router = app.getRoutingHelper();
if (router.isFollowingMode() && router.isRouteCalculated()) {
synchronized (router) {
NextDirectionInfo nextDirection = router.getNextRouteDirectionInfo(new NextDirectionInfo(), true);
if (nextDirection != null) {
updateTargetDirection(router.getLocationFromRouteDirection(nextDirection.directionInfo), heading);
}
}
} else {
TargetPoint target = app.getTargetPointsHelper().getPointToNavigate();
updateTargetDirection((target != null) ? target.point : null, heading);
}
}
use of net.osmand.plus.routing.RoutingHelper in project Osmand by osmandapp.
the class OsmandAidlApi method registerNavigateReceiver.
private void registerNavigateReceiver(final MapActivity mapActivity) {
navigateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String profileStr = intent.getStringExtra(AIDL_PROFILE);
final ApplicationMode profile = ApplicationMode.valueOfStringKey(profileStr, DEFAULT_PROFILE);
boolean validProfile = false;
for (ApplicationMode mode : VALID_PROFILES) {
if (mode == profile) {
validProfile = true;
break;
}
}
if (validProfile) {
String startName = intent.getStringExtra(AIDL_START_NAME);
if (Algorithms.isEmpty(startName)) {
startName = "";
}
String destName = intent.getStringExtra(AIDL_DEST_NAME);
if (Algorithms.isEmpty(destName)) {
destName = "";
}
final LatLon start;
final PointDescription startDesc;
double startLat = intent.getDoubleExtra(AIDL_START_LAT, 0);
double startLon = intent.getDoubleExtra(AIDL_START_LON, 0);
if (startLat != 0 && startLon != 0) {
start = new LatLon(startLat, startLon);
startDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, startName);
} else {
start = null;
startDesc = null;
}
double destLat = intent.getDoubleExtra(AIDL_DEST_LAT, 0);
double destLon = intent.getDoubleExtra(AIDL_DEST_LON, 0);
final LatLon dest = new LatLon(destLat, destLon);
final PointDescription destDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, destName);
final RoutingHelper routingHelper = app.getRoutingHelper();
boolean force = intent.getBooleanExtra(AIDL_FORCE, true);
if (routingHelper.isFollowingMode() && !force) {
AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm();
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (!routingHelper.isFollowingMode()) {
startNavigation(mapActivity, null, start, startDesc, dest, destDesc, profile);
}
}
});
} else {
startNavigation(mapActivity, null, start, startDesc, dest, destDesc, profile);
}
}
}
};
mapActivity.registerReceiver(navigateReceiver, new IntentFilter(AIDL_NAVIGATE));
}
use of net.osmand.plus.routing.RoutingHelper in project Osmand by osmandapp.
the class NavigationNotification method buildNotification.
@Override
public Builder buildNotification(boolean wearable) {
if (!isEnabled()) {
return null;
}
NavigationService service = app.getNavigationService();
String notificationTitle;
StringBuilder notificationText = new StringBuilder();
color = 0;
icon = R.drawable.ic_action_start_navigation;
turnBitmap = null;
ongoing = true;
RoutingHelper routingHelper = app.getRoutingHelper();
boolean followingMode = routingHelper.isFollowingMode() || app.getLocationProvider().getLocationSimulation().isRouteAnimating();
if (service != null && (service.getUsedBy() & USED_BY_NAVIGATION) != 0) {
color = app.getResources().getColor(R.color.osmand_orange);
String distanceStr = OsmAndFormatter.getFormattedDistance(app.getRoutingHelper().getLeftDistance(), app);
String timeStr = OsmAndFormatter.getFormattedDuration(app.getRoutingHelper().getLeftTime(), app);
String etaStr = SimpleDateFormat.getTimeInstance(DateFormat.SHORT).format(new Date(System.currentTimeMillis() + app.getRoutingHelper().getLeftTime() * 1000));
TurnType turnType = null;
boolean deviatedFromRoute;
int turnImminent = 0;
int nextTurnDistance = 0;
int nextNextTurnDistance = 0;
RouteDirectionInfo ri = null;
if (routingHelper.isRouteCalculated() && followingMode) {
deviatedFromRoute = routingHelper.isDeviatedFromRoute();
if (deviatedFromRoute) {
turnImminent = 0;
turnType = TurnType.valueOf(TurnType.OFFR, leftSide);
nextTurnDistance = (int) routingHelper.getRouteDeviation();
} else {
NextDirectionInfo calc1 = new NextDirectionInfo();
NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(calc1, true);
if (r != null && r.distanceTo > 0 && r.directionInfo != null) {
ri = r.directionInfo;
turnType = r.directionInfo.getTurnType();
nextTurnDistance = r.distanceTo;
turnImminent = r.imminent;
NextDirectionInfo next = routingHelper.getNextRouteDirectionInfoAfter(r, calc1, true);
nextNextTurnDistance = next.distanceTo;
}
}
if (turnType != null) {
TurnDrawable drawable = new TurnDrawable(app, false);
int height = (int) app.getResources().getDimension(android.R.dimen.notification_large_icon_height);
int width = (int) app.getResources().getDimension(android.R.dimen.notification_large_icon_width);
drawable.setBounds(0, 0, width, height);
drawable.setTurnType(turnType);
drawable.setTurnImminent(turnImminent, deviatedFromRoute);
turnBitmap = drawableToBitmap(drawable);
}
notificationTitle = OsmAndFormatter.getFormattedDistance(nextTurnDistance, app) + (turnType != null ? " • " + RouteCalculationResult.toString(turnType, app, true) : "");
if (ri != null && !Algorithms.isEmpty(ri.getDescriptionRoutePart())) {
notificationText.append(ri.getDescriptionRoutePart());
if (nextNextTurnDistance > 0) {
notificationText.append(" ").append(OsmAndFormatter.getFormattedDistance(nextNextTurnDistance, app));
}
notificationText.append("\n");
}
int distanceToNextIntermediate = routingHelper.getLeftDistanceNextIntermediate();
if (distanceToNextIntermediate > 0) {
int nextIntermediateIndex = routingHelper.getRoute().getNextIntermediate();
List<TargetPoint> intermediatePoints = app.getTargetPointsHelper().getIntermediatePoints();
if (nextIntermediateIndex < intermediatePoints.size()) {
TargetPoint nextIntermediate = intermediatePoints.get(nextIntermediateIndex);
notificationText.append(OsmAndFormatter.getFormattedDistance(distanceToNextIntermediate, app)).append(" • ").append(nextIntermediate.getOnlyName());
notificationText.append("\n");
}
}
notificationText.append(distanceStr).append(" • ").append(timeStr).append(" • ").append(etaStr);
} else {
notificationTitle = app.getString(R.string.shared_string_navigation);
String error = routingHelper.getLastRouteCalcErrorShort();
if (Algorithms.isEmpty(error)) {
notificationText.append(app.getString(R.string.route_calculation)).append("...");
} else {
notificationText.append(error);
}
}
} else if (routingHelper.isRoutePlanningMode() && routingHelper.isPauseNavigation()) {
ongoing = false;
notificationTitle = app.getString(R.string.shared_string_navigation);
notificationText.append(app.getString(R.string.shared_string_paused));
} else {
return null;
}
final Builder notificationBuilder = createBuilder(wearable).setContentTitle(notificationTitle).setStyle(new BigTextStyle().bigText(notificationText)).setLargeIcon(turnBitmap);
Intent stopIntent = new Intent(OSMAND_STOP_NAVIGATION_SERVICE_ACTION);
PendingIntent stopPendingIntent = PendingIntent.getBroadcast(app, 0, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(R.drawable.ic_action_remove_dark, app.getString(R.string.shared_string_control_stop), stopPendingIntent);
if (routingHelper.isRouteCalculated() && followingMode) {
Intent pauseIntent = new Intent(OSMAND_PAUSE_NAVIGATION_SERVICE_ACTION);
PendingIntent pausePendingIntent = PendingIntent.getBroadcast(app, 0, pauseIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(R.drawable.ic_pause, app.getString(R.string.shared_string_pause), pausePendingIntent);
} else if (routingHelper.isRouteCalculated() && routingHelper.isPauseNavigation()) {
Intent resumeIntent = new Intent(OSMAND_RESUME_NAVIGATION_SERVICE_ACTION);
PendingIntent resumePendingIntent = PendingIntent.getBroadcast(app, 0, resumeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(R.drawable.ic_play_dark, app.getString(R.string.shared_string_continue), resumePendingIntent);
}
return notificationBuilder;
}
use of net.osmand.plus.routing.RoutingHelper in project Osmand by osmandapp.
the class NavigationNotification method init.
@Override
public void init() {
leftSide = app.getSettings().DRIVING_REGION.get().leftHandDriving;
app.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
RoutingHelper routingHelper = app.getRoutingHelper();
routingHelper.setRoutePlanningMode(true);
routingHelper.setFollowingMode(false);
routingHelper.setPauseNavigation(true);
}
}, new IntentFilter(OSMAND_PAUSE_NAVIGATION_SERVICE_ACTION));
app.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
RoutingHelper routingHelper = app.getRoutingHelper();
routingHelper.setRoutePlanningMode(false);
routingHelper.setFollowingMode(true);
}
}, new IntentFilter(OSMAND_RESUME_NAVIGATION_SERVICE_ACTION));
app.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
app.stopNavigation();
}
}, new IntentFilter(OSMAND_STOP_NAVIGATION_SERVICE_ACTION));
}
Aggregations