Android 12 Developer Preview is here! Try it out, and give us your feedback!

Step.Builder

public static final class Step.Builder
extends Object

java.lang.Object
   ↳ com.google.android.libraries.car.app.navigation.model.Step.Builder


A builder of Step.

Summary

Public methods

Step.Builder addLane(Lane lane)

Adds the information of a single road lane at the point where the driver should execute this step.

Step build()

Constructs the Step defined by this builder.

Step.Builder clearLanes()

Clears any lanes that may have been added with addLane(Lane) up to this point.

Step.Builder setCue(CharSequence cue)

Sets a text description of this maneuver.

Step.Builder setLanesImage(CarIcon lanesImage)

Sets an image representing all the lanes or null if no lanes image is available.

Step.Builder setManeuver(Maneuver maneuver)

Sets the maneuver to be performed on this step or null if this step doesn't involve a maneuver.

Step.Builder setRoad(CharSequence road)

Sets a text description of the road for the step or null if unknown.

Inherited methods

Public methods

addLane

public Step.Builder addLane (Lane lane)

Adds the information of a single road lane at the point where the driver should execute this step.

Lane information is primarily used when the step is passed to the vehicle cluster or heads up displays. Some vehicles may not use the information at all. The navigation template primarily uses the lanes image provided in setLanesImage(CarIcon).

Lanes are displayed from left to right.

Parameters
lane Lane

Returns
Step.Builder

build

public Step build ()

Constructs the Step defined by this builder.

Returns
Step

Throws
IllegalStateException if lanesImage was set but no lanes were added.

clearLanes

public Step.Builder clearLanes ()

Clears any lanes that may have been added with addLane(Lane) up to this point.

Returns
Step.Builder

setCue

public Step.Builder setCue (CharSequence cue)

Sets a text description of this maneuver.

Must always be set when the step is created and is used as a fallback when Maneuver is not set or is unavailable.

For example "Turn left", "Make a U-Turn", "Sharp Right", or "Take the exit using the left lane"

The cue string can contain images that replace spans of text by using CarIconSpan.

In the following example, the "520" text is replaced with an icon:

SpannableString string = new SpannableString("Turn right on 520 East");
 string.setSpan(textWithImage.setSpan(
     CarIconSpan.create(CarIcon.of(
         IconCompat.createWithResource(getCarContext(), R.drawable.ic_520_highway))),
         14, 17, SPAN_INCLUSIVE_EXCLUSIVE));
 

The host may choose to display the string without the images, so it is important that the string content is readable without the images. This may be the case, for example, if the string is sent to a cluster display that does not support images, or if the host limits the number of images that may be allowed for one line of text.

Image Sizing Guidance

The size these images will be displayed at varies depending on where the Step object is used. Refer to the documentation of those APIs for details.

See CarIcon for more details related to providing icon and image resources that work with different car screen pixel densities.

Parameters
cue CharSequence

Returns
Step.Builder

Throws
NullPointerException if cue is null

setLanesImage

public Step.Builder setLanesImage (CarIcon lanesImage)

Sets an image representing all the lanes or null if no lanes image is available.

This image takes priority over Lanes that may have been added with addLane(Lane). If an image is added for the lanes with this method then corresponding lane data using addLane(Lane) must also have been added in case it is shown on a display with limited resources such as the car cluster or heads-up display (HUD).

This image should ideally have a transparent background.

Image Sizing Guidance

The provided image should have a maximum size of 294 x 44 dp. If the image exceeds this maximum size in either one of the dimensions, it will be scaled down and centered inside the bounding box while preserving the aspect ratio.

See CarIcon for more details related to providing icon and image resources that work with different car screen pixel densities.

Parameters
lanesImage CarIcon

Returns
Step.Builder

setManeuver

public Step.Builder setManeuver (Maneuver maneuver)

Sets the maneuver to be performed on this step or null if this step doesn't involve a maneuver.

Parameters
maneuver Maneuver

Returns
Step.Builder

setRoad

public Step.Builder setRoad (CharSequence road)

Sets a text description of the road for the step or null if unknown.

This value is primarily used for vehicle cluster and heads-up displays and may not appear in the navigation template.

For example, a Step for a left turn might provide "State Street" for the road.

Parameters
road CharSequence

Returns
Step.Builder

Throws
NullPointerException if destinations is null