use of net.osmand.plus.views.mapwidgets.LanesDrawable in project Osmand by osmandapp.
the class TripHelper method buildTrip.
@NonNull
public Trip buildTrip(float density) {
RoutingHelper routingHelper = app.getRoutingHelper();
OsmandSettings settings = app.getSettings();
TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
TargetPoint pointToNavigate = targetPointsHelper.getPointToNavigate();
Trip.Builder tripBuilder = new Trip.Builder();
if (pointToNavigate != null) {
Pair<Destination, TravelEstimate> dest = getDestination(pointToNavigate);
tripBuilder.addDestination(dest.first, dest.second);
lastDestination = dest.first;
lastDestinationTravelEstimate = dest.second;
} else {
lastDestination = null;
lastDestinationTravelEstimate = null;
}
boolean routeBeingCalculated = routingHelper.isRouteBeingCalculated();
tripBuilder.setLoading(routeBeingCalculated);
if (!routeBeingCalculated) {
Step.Builder stepBuilder = new Step.Builder();
Maneuver.Builder turnBuilder;
TurnType turnType = null;
boolean leftSide = settings.DRIVING_REGION.get().leftHandDriving;
boolean deviatedFromRoute = routingHelper.isDeviatedFromRoute();
int turnImminent = 0;
int nextTurnDistance = 0;
RouteCalculationResult.NextDirectionInfo nextDirInfo;
RouteCalculationResult.NextDirectionInfo calc = new RouteCalculationResult.NextDirectionInfo();
if (deviatedFromRoute) {
turnType = TurnType.valueOf(TurnType.OFFR, leftSide);
nextTurnDistance = (int) routingHelper.getRouteDeviation();
} else {
nextDirInfo = routingHelper.getNextRouteDirectionInfo(calc, true);
if (nextDirInfo != null && nextDirInfo.distanceTo > 0 && nextDirInfo.directionInfo != null) {
turnType = nextDirInfo.directionInfo.getTurnType();
nextTurnDistance = nextDirInfo.distanceTo;
turnImminent = nextDirInfo.imminent;
}
}
if (turnType != null) {
TurnDrawable drawable = new TurnDrawable(app, false);
int height = (int) (TURN_IMAGE_SIZE_DP * density);
int width = (int) (TURN_IMAGE_SIZE_DP * density);
drawable.setBounds(0, 0, width, height);
drawable.setTurnType(turnType);
drawable.setTurnImminent(turnImminent, deviatedFromRoute);
Bitmap turnBitmap = drawableToBitmap(drawable, width, height);
turnBuilder = new Maneuver.Builder(getManeuverType(turnType));
if (turnType.isRoundAbout()) {
turnBuilder.setRoundaboutExitNumber(turnType.getExitOut());
}
turnBuilder.setIcon(new CarIcon.Builder(IconCompat.createWithBitmap(turnBitmap)).build());
} else {
turnBuilder = new Maneuver.Builder(Maneuver.TYPE_UNKNOWN);
}
Maneuver maneuver = turnBuilder.build();
String cue = turnType != null ? RouteCalculationResult.toString(turnType, app, true) : "";
stepBuilder.setManeuver(maneuver);
stepBuilder.setCue(cue);
nextDirInfo = routingHelper.getNextRouteDirectionInfo(calc, false);
if (nextDirInfo != null && nextDirInfo.directionInfo != null && nextDirInfo.directionInfo.getTurnType() != null) {
int[] lanes = nextDirInfo.directionInfo.getTurnType().getLanes();
int locimminent = nextDirInfo.imminent;
// Do not show too far
if ((nextDirInfo.distanceTo > 800 && nextDirInfo.directionInfo.getTurnType().isSkipToSpeak()) || nextDirInfo.distanceTo > 1200) {
lanes = null;
}
// int dist = nextDirInfo.distanceTo;
if (lanes != null) {
for (int lane : lanes) {
int firstTurnType = TurnType.getPrimaryTurn(lane);
int secondTurnType = TurnType.getSecondaryTurn(lane);
int thirdTurnType = TurnType.getTertiaryTurn(lane);
Lane.Builder laneBuilder = new Lane.Builder();
laneBuilder.addDirection(LaneDirection.create(getLaneDirection(TurnType.valueOf(firstTurnType, leftSide)), (lane & 1) == 1));
if (secondTurnType > 0) {
laneBuilder.addDirection(LaneDirection.create(getLaneDirection(TurnType.valueOf(secondTurnType, leftSide)), false));
}
if (thirdTurnType > 0) {
laneBuilder.addDirection(LaneDirection.create(getLaneDirection(TurnType.valueOf(thirdTurnType, leftSide)), false));
}
stepBuilder.addLane(laneBuilder.build());
}
LanesDrawable lanesDrawable = new LanesDrawable(app, 1f, TURN_LANE_IMAGE_SIZE * density, TURN_LANE_IMAGE_MIN_DELTA * density, TURN_LANE_IMAGE_MARGIN * density, TURN_LANE_IMAGE_SIZE * density);
lanesDrawable.lanes = lanes;
lanesDrawable.imminent = locimminent == 0;
lanesDrawable.isNightMode = app.getDaynightHelper().isNightMode();
// prefer 500 x 74 dp
lanesDrawable.updateBounds();
Bitmap lanesBitmap = drawableToBitmap(lanesDrawable, lanesDrawable.getIntrinsicWidth(), lanesDrawable.getIntrinsicHeight());
stepBuilder.setLanesImage(new CarIcon.Builder(IconCompat.createWithBitmap(lanesBitmap)).build());
}
}
int leftTurnTimeSec = routingHelper.getLeftTimeNextTurn();
long turnArrivalTime = System.currentTimeMillis() + leftTurnTimeSec * 1000L;
Distance stepDistance = getDistance(app, nextTurnDistance);
DateTimeWithZone stepDateTime = DateTimeWithZone.create(turnArrivalTime, TimeZone.getDefault());
TravelEstimate.Builder stepTravelEstimateBuilder = new TravelEstimate.Builder(stepDistance, stepDateTime);
stepTravelEstimateBuilder.setRemainingTimeSeconds(leftTurnTimeSec);
Step step = stepBuilder.build();
TravelEstimate stepTravelEstimate = stepTravelEstimateBuilder.build();
tripBuilder.addStep(step, stepTravelEstimate);
lastStep = step;
lastStepTravelEstimate = stepTravelEstimate;
if (!deviatedFromRoute) {
nextDirInfo = routingHelper.getNextRouteDirectionInfo(calc, true);
CurrentStreetName currentName = routingHelper.getCurrentName(nextDirInfo);
tripBuilder.setCurrentRoad(currentName.text);
lastCurrentRoad = currentName.text;
} else {
lastCurrentRoad = null;
}
} else {
lastStep = null;
lastStepTravelEstimate = null;
}
return tripBuilder.build();
}
use of net.osmand.plus.views.mapwidgets.LanesDrawable in project Osmand by osmandapp.
the class RouteDirectionsCard method getRouteDirectionView.
private View getRouteDirectionView(final int directionInfoIndex, RouteDirectionInfo model, List<RouteDirectionInfo> directionsInfo) {
MapActivity mapActivity = getMapActivity();
if (mapActivity == null) {
return null;
}
OsmandApplication app = mapActivity.getMyApplication();
ContextThemeWrapper context = new ContextThemeWrapper(mapActivity, nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme);
View row = LayoutInflater.from(context).inflate(R.layout.route_info_list_item, null);
TextView label = (TextView) row.findViewById(R.id.description);
TextView distanceLabel = (TextView) row.findViewById(R.id.distance);
TextView timeLabel = (TextView) row.findViewById(R.id.time);
TextView cumulativeDistanceLabel = (TextView) row.findViewById(R.id.cumulative_distance);
TextView cumulativeTimeLabel = (TextView) row.findViewById(R.id.cumulative_time);
ImageView directionIcon = (ImageView) row.findViewById(R.id.direction);
ImageView lanesIcon = (ImageView) row.findViewById(R.id.lanes);
row.findViewById(R.id.divider).setVisibility(directionInfoIndex == directionsInfo.size() - 1 ? View.INVISIBLE : View.VISIBLE);
TurnPathHelper.RouteDrawable drawable = new TurnPathHelper.RouteDrawable(mapActivity.getResources(), true);
drawable.setColorFilter(new PorterDuffColorFilter(getActiveColor(), PorterDuff.Mode.SRC_ATOP));
drawable.setRouteType(model.getTurnType());
directionIcon.setImageDrawable(drawable);
int[] lanes = model.getTurnType().getLanes();
if (lanes != null) {
LanesDrawable lanesDrawable = new LanesDrawable(mapActivity, 1);
lanesDrawable.lanes = lanes;
lanesDrawable.isTurnByTurn = true;
lanesDrawable.isNightMode = nightMode;
lanesDrawable.updateBounds();
lanesIcon.setImageDrawable(lanesDrawable);
lanesIcon.setVisibility(View.VISIBLE);
}
label.setText(model.getDescriptionRoutePart());
if (model.distance > 0) {
distanceLabel.setText(OsmAndFormatter.getFormattedDistance(model.distance, app));
timeLabel.setText(getTimeDescription(app, model));
row.setContentDescription(label.getText() + " " + timeLabel.getText());
} else {
if (Algorithms.isEmpty(label.getText().toString())) {
label.setText(mapActivity.getString((directionInfoIndex != directionsInfo.size() - 1) ? R.string.arrived_at_intermediate_point : R.string.arrived_at_destination));
}
distanceLabel.setText("");
timeLabel.setText("");
row.setContentDescription("");
}
RouteDetailsFragment.CumulativeInfo cumulativeInfo = RouteDetailsFragment.getRouteDirectionCumulativeInfo(directionInfoIndex, directionsInfo);
cumulativeDistanceLabel.setText(OsmAndFormatter.getFormattedDistance(cumulativeInfo.distance, app));
cumulativeTimeLabel.setText(Algorithms.formatDuration(cumulativeInfo.time, app.accessibilityEnabled()));
row.setOnClickListener(v -> notifyButtonPressed(directionInfoIndex));
return row;
}
Aggregations