in car_app_library/navigation/common/src/main/java/androidx/car/app/sample/navigation/common/car/NavigationScreen.java [132:268]
public Template onGetTemplate() {
mSurfaceRenderer.updateMarkerVisibility(
/* showMarkers=*/ false, /* numMarkers=*/ 0, /* activeMarker=*/ -1);
NavigationTemplate.Builder builder = new NavigationTemplate.Builder();
builder.setBackgroundColor(CarColor.SECONDARY);
// Set the action strip.
ActionStrip.Builder actionStripBuilder = new ActionStrip.Builder();
actionStripBuilder.addAction(mSettingsAction);
if (mIsNavigating) {
actionStripBuilder.addAction(
new Action.Builder()
.setTitle("Stop")
.setOnClickListener(this::stopNavigation)
.build());
} else {
actionStripBuilder.addAction(
new Action.Builder()
.setIcon(
new CarIcon.Builder(
IconCompat.createWithResource(
getCarContext(),
R.drawable.ic_search_black36dp))
.build())
.setOnClickListener(this::openSearch)
.build());
actionStripBuilder.addAction(
new Action.Builder()
.setTitle("Favorites")
.setOnClickListener(this::openFavorites)
.build());
}
builder.setActionStrip(actionStripBuilder.build());
// Set the map action strip with the pan and zoom buttons.
CarIcon.Builder panIconBuilder = new CarIcon.Builder(
IconCompat.createWithResource(
getCarContext(),
R.drawable.ic_pan_24));
if (mIsInPanMode) {
panIconBuilder.setTint(CarColor.BLUE);
}
builder.setMapActionStrip(new ActionStrip.Builder()
.addAction(new Action.Builder(Action.PAN)
.setIcon(panIconBuilder.build())
.build())
.addAction(
new Action.Builder()
.setIcon(
new CarIcon.Builder(
IconCompat.createWithResource(
getCarContext(),
R.drawable.ic_recenter_24))
.build())
.setOnClickListener(
() -> mSurfaceRenderer.handleRecenter())
.build())
.addAction(
new Action.Builder()
.setIcon(
new CarIcon.Builder(
IconCompat.createWithResource(
getCarContext(),
R.drawable.ic_zoom_out_24))
.build())
.setOnClickListener(
() -> mSurfaceRenderer.handleScale(INVALID_FOCAL_POINT_VAL,
INVALID_FOCAL_POINT_VAL,
ZOOM_OUT_BUTTON_SCALE_FACTOR))
.build())
.addAction(
new Action.Builder()
.setIcon(
new CarIcon.Builder(
IconCompat.createWithResource(
getCarContext(),
R.drawable.ic_zoom_in_24))
.build())
.setOnClickListener(
() -> mSurfaceRenderer.handleScale(INVALID_FOCAL_POINT_VAL,
INVALID_FOCAL_POINT_VAL,
ZOOM_IN_BUTTON_SCALE_FACTOR))
.build())
.build());
// When the user enters the pan mode, remind the user that they can exit the pan mode by
// pressing the select button again.
builder.setPanModeListener(isInPanMode -> {
if (isInPanMode) {
CarToast.makeText(getCarContext(),
"Press Select to exit the pan mode",
CarToast.LENGTH_LONG).show();
}
mIsInPanMode = isInPanMode;
invalidate();
});
if (mIsNavigating) {
if (mDestinationTravelEstimate != null) {
builder.setDestinationTravelEstimate(mDestinationTravelEstimate);
}
if (isRerouting()) {
builder.setNavigationInfo(new RoutingInfo.Builder().setLoading(true).build());
} else if (mHasArrived) {
MessageInfo messageInfo = new MessageInfo.Builder(
getCarContext().getString(R.string.navigation_arrived)).build();
builder.setNavigationInfo(messageInfo);
} else {
RoutingInfo.Builder info = new RoutingInfo.Builder();
Step tmp = mSteps.get(0);
Step.Builder currentStep =
new Step.Builder(tmp.getCue().toCharSequence())
.setManeuver(tmp.getManeuver())
.setRoad(tmp.getRoad().toCharSequence());
if (mShouldShowLanes) {
for (Lane lane : tmp.getLanes()) {
currentStep.addLane(lane);
}
currentStep.setLanesImage(tmp.getLanesImage());
}
info.setCurrentStep(currentStep.build(), mStepRemainingDistance);
if (mShouldShowNextStep && mSteps.size() > 1) {
info.setNextStep(mSteps.get(1));
}
if (mJunctionImage != null) {
info.setJunctionImage(mJunctionImage);
}
builder.setNavigationInfo(info.build());
}
}
return builder.build();
}