A View which displays a map for navigation.
Users of this class must forward all the life cycle methods from the Activity
or Fragment
containing this view to the corresponding
ones in this class. In particular, you must forward on the following methods:
onCreate(Bundle)
onStart()
onResume()
onPause()
onStop()
onDestroy()
onConfigurationChanged(Configuration)
onSaveInstanceState(Bundle)
onTrimMemory(int)
If the NavView is added after its parent Activity
or Fragment
has been through its creation lifecycle, you must call onCreate(Bundle)
,
onStart()
and onResume()
manually to properly initialize it. Similarly, if a
NavView is detached from its parent Activity
or Fragment
,
you must manually call onPause()
, onStop()
and onDestroy()
to prevent leaks.
Note: You are advised not to add children to this view.
All calls to NavView should be performed on the UI thread.
Nested Class Summary
interface | NavigationView.OnNightModeChangedListener | Interface for a listener which will be notified when the UI enters or exits "night mode". | |
interface | NavigationView.OnRecenterButtonClickedListener | Interface for a listener which will be notified when the recenter button is clicked. |
Inherited Constant Summary
Inherited Field Summary
Public Constructor Summary
NavigationView(Context context)
|
|
NavigationView(Context context, AttributeSet attrs)
|
|
NavigationView(Context context, AttributeSet attrs, int defStyleAttr)
|
Public Method Summary
void |
addOnNightModeChangedListener(NavigationView.OnNightModeChangedListener listener)
Registers a listener which will be notified when the UI enters or exits night mode.
|
void |
addOnRecenterButtonClickedListener(NavigationView.OnRecenterButtonClickedListener listener)
Registers a listener which will be notified when the recenter button is clicked.
|
Camera |
getCamera()
Returns a camera object which can be used to alter the viewport of the map.
|
NavigationMap |
getMap()
Returns an object which can be used to add content to the map.
|
void |
onConfigurationChanged(Configuration config)
|
void |
onCreate(Bundle savedInstanceState)
|
void | |
void |
onPause()
|
void |
onResume()
|
void |
onSaveInstanceState(Bundle outState)
|
void |
onStart()
|
void |
onStop()
|
void |
onTrimMemory(int level)
|
void |
removeOnNightModeChangedListener(NavigationView.OnNightModeChangedListener listener)
Removes a listener added via
addOnNightModeChangedListener(OnNightModeChangedListener) . |
void |
removeOnRecenterButtonClickedListener(NavigationView.OnRecenterButtonClickedListener listener)
Removes a listener added via
addOnRecenterButtonClickedListener(OnRecenterButtonClickedListener) . |
void |
setCalloutInfoDisplayModeOverride(NavigationCalloutDisplayMode calloutInfoDisplayModeOverride)
Overrides default display mode for navigation callouts.
|
void |
setCalloutInfoFormatOverride(RouteCalloutInfoFormat calloutInfoFormatOverride)
Sets the callout info format mode for route callouts.
|
void |
setCompassEnabled(boolean enabled)
Sets whether the compass is visible.
|
void |
setCustomControl(View control, CustomControlPosition position)
Sets a custom control view which will appear at the given position in the navigation UI.
|
void |
setEtaCardEnabled(boolean enabled)
Sets whether the ETA card is visible during navigation.
|
void |
setForceNightMode(int nightMode)
Sets the current
ForceNightMode . |
void |
setHeaderEnabled(boolean enabled)
Sets whether the turn-by-turn navigation header is visible during navigation.
|
void |
setOnNightModeChangedListener(NavigationView.OnNightModeChangedListener listener)
This method is deprecated.
Use
setOnNightModeChangedListener(OnNightModeChangedListener) to set one
or more listeners and removeOnNightModeChangedListener(OnNightModeChangedListener)
to remove them to avoid memory leaks.
|
void |
setOnRecenterButtonClickedListener(NavigationView.OnRecenterButtonClickedListener listener)
This method is deprecated.
Use
setOnRecenterButtonClickedListener(OnRecenterButtonClickedListener) to
set one or more listeners and removeOnRecenterButtonClickedListener(OnRecenterButtonClickedListener) to remove them to
avoid memory leaks.
|
void |
setRecenterButtonEnabled(boolean enabled)
Sets whether the re-center button should be shown.
|
void |
setSpeedAlertOptions(SpeedAlertOptions speedAlertOptions)
This method is deprecated.
Use
Navigator.setSpeedAlertOptions(SpeedAlertOptions)
to set the speed limit options instead. Doing so will allow you to configure speeding
alerts independent of a Navigation UI.
|
void |
setSpeedLimitIconEnabled(boolean enabled)
Specifies whether the speed limit icon is shown.
|
void |
setSpeedometerEnabled(boolean enabled)
Specifies whether the speedometer is shown.
|
void |
setSpeedometerUiOptions(SpeedometerUiOptions speedometerUiOptions)
Sets the speedometer UI configuration
SpeedometerUiOptions based on SpeedAlertSeverity . |
void | |
void |
setTrafficIncidentCardsEnabled(boolean enabled)
Sets whether traffic incident cards should be shown when the user clicks on a traffic incident
icon.
|
void |
setTrafficPromptsEnabled(boolean enabled)
Sets whether traffic prompts should be shown.
|
Inherited Method Summary
Public Constructors
public NavigationView (Context context)
Parameters
context |
---|
public NavigationView (Context context, AttributeSet attrs)
Parameters
context | |
---|---|
attrs |
public NavigationView (Context context, AttributeSet attrs, int defStyleAttr)
Parameters
context | |
---|---|
attrs | |
defStyleAttr |
Public Methods
public void addOnNightModeChangedListener (NavigationView.OnNightModeChangedListener listener)
Registers a listener which will be notified when the UI enters or exits night mode. This method should only be called on the UI thread.
Note: In order to avoid memory leaks, use removeOnNightModeChangedListener(OnNightModeChangedListener)
to remove the listener that is
no longer required.
Parameters
listener | a listener which will be notified when the UI enters or exits night mode. |
---|
public void addOnRecenterButtonClickedListener (NavigationView.OnRecenterButtonClickedListener listener)
Registers a listener which will be notified when the recenter button is clicked. This method should only be called on the UI thread.
Note: In order to avoid memory leaks, use removeOnRecenterButtonClickedListener(OnRecenterButtonClickedListener)
to remove the listener
that is no longer required.
Parameters
listener | a listener which will be notified when the recenter button is clicked |
---|
public Camera getCamera ()
Returns a camera object which can be used to alter the viewport of the map. This method should only be called on the UI thread.
Returns
- the
Camera
object associated with this view
public NavigationMap getMap ()
Returns an object which can be used to add content to the map. This method should only be called on the UI thread.
public void onConfigurationChanged (Configuration config)
Parameters
config |
---|
public void onCreate (Bundle savedInstanceState)
Parameters
savedInstanceState |
---|
public void onDestroy ()
public void onPause ()
public void onResume ()
public void onSaveInstanceState (Bundle outState)
Parameters
outState |
---|
public void onStart ()
public void onStop ()
public void onTrimMemory (int level)
Parameters
level |
---|
public void removeOnNightModeChangedListener (NavigationView.OnNightModeChangedListener listener)
Removes a listener added via addOnNightModeChangedListener(OnNightModeChangedListener)
.
Parameters
listener | added via addOnRecenterButtonClickedListener(OnRecenterButtonClickedListener) .
|
---|
public void removeOnRecenterButtonClickedListener (NavigationView.OnRecenterButtonClickedListener listener)
Removes a listener added via addOnRecenterButtonClickedListener(OnRecenterButtonClickedListener)
.
Parameters
listener | added via addOnRecenterButtonClickedListener(OnRecenterButtonClickedListener) .
|
---|
public void setCalloutInfoDisplayModeOverride (NavigationCalloutDisplayMode calloutInfoDisplayModeOverride)
Overrides default display mode for navigation callouts. Passing null resets the default display mode.
Parameters
calloutInfoDisplayModeOverride | the new desired display mode. |
---|
public void setCalloutInfoFormatOverride (RouteCalloutInfoFormat calloutInfoFormatOverride)
Sets the callout info format mode for route callouts. If this method is not called, callouts will follow the behavior as defined by RouteCalloutInfoFormat.DEFAULT.
Parameters
calloutInfoFormatOverride | the new desired callout format. |
---|
public void setCompassEnabled (boolean enabled)
Sets whether the compass is visible. This method should only be called on the UI thread.
Parameters
enabled |
---|
public void setCustomControl (View control, CustomControlPosition position)
Sets a custom control view which will appear at the given position in the navigation UI. If any custom control already exists at the given position it will be replaced. Calling this method with a null control value will remove the custom control at the given position. If the control has already been added at a different position or already has a parent, it will be ignored. This method should only be called on the UI thread.
Parameters
control | a view that will be positioned within the navigation UI |
---|---|
position | determines where the custom control will be placed in the UI relative to built-in controls. |
public void setEtaCardEnabled (boolean enabled)
Sets whether the ETA card is visible during navigation. This method should only be called on the UI thread.
Parameters
enabled |
---|
public void setHeaderEnabled (boolean enabled)
Sets whether the turn-by-turn navigation header is visible during navigation. This method should only be called on the UI thread.
Parameters
enabled |
---|
public void setOnNightModeChangedListener (NavigationView.OnNightModeChangedListener listener)
This method is deprecated.
Use setOnNightModeChangedListener(OnNightModeChangedListener)
to set one
or more listeners and removeOnNightModeChangedListener(OnNightModeChangedListener)
to remove them to avoid memory leaks.
Sets a listener which will be notified immediately of the current "night mode" state and whenever when the UI enters or exits "night mode". This method should only be called on the UI thread.
Note: In order to avoid memory leaks, setOnNightModeChangedListener(null)
should be
called when the listener is no longer required.
Parameters
listener | a listener which will be notified when the UI enters or exits night mode |
---|
public void setOnRecenterButtonClickedListener (NavigationView.OnRecenterButtonClickedListener listener)
This method is deprecated.
Use setOnRecenterButtonClickedListener(OnRecenterButtonClickedListener)
to
set one or more listeners and removeOnRecenterButtonClickedListener(OnRecenterButtonClickedListener)
to remove them to
avoid memory leaks.
Sets a listener which will be notified when the recenter button is clicked. This method should only be called on the UI thread.
Note: In order to avoid memory leaks, setOnRecenterButtonClickedListener(null)
should be called when the listener is no longer required.
Parameters
listener | a listener which will be notified when the recenter button is clicked |
---|
public void setRecenterButtonEnabled (boolean enabled)
Sets whether the re-center button should be shown. This method should only be called on the UI thread.
Parameters
enabled |
---|
public void setSpeedAlertOptions (SpeedAlertOptions speedAlertOptions)
This method is deprecated.
Use Navigator.setSpeedAlertOptions(SpeedAlertOptions)
to set the speed limit options instead. Doing so will allow you to configure speeding
alerts independent of a Navigation UI.
Sets SpeedAlertOptions
for customizing the triggering thresholds for SpeedAlertSeverity
s.
You can use this method to customize the speed alert triggering thresholds in percentage for
both SpeedAlertSeverity.MINOR
and SpeedAlertSeverity.MAJOR
alerts. You can also
use this method to configure the time in seconds needed to upgrade speed alerts from SpeedAlertSeverity.MINOR
to SpeedAlertSeverity.MAJOR
.
By setting a null
SpeedAlertOptions
or not setting any, NavSDKâs default
speed alert will display: speed alert shows red text in white/dark background for day/night
mode respectively when the speed is less than 5 mph or 10 kph over the speed limit, and shows
white text in red background when speeding more than 5 mph or 10 kph.
Parameters
speedAlertOptions |
---|
public void setSpeedLimitIconEnabled (boolean enabled)
Specifies whether the speed limit icon is shown. Only call this method on the UI thread.
When enabled, a speed limit icon that indicates the speed limit of the road appears in the bottom start corner during guidance. The icon only appears in locations where reliable speed limit data is available. When speedometer is visible, they are attached.
If the recenter button is enabled, the speed limit icon is temporarily hidden when the recenter button is shown.
Note: Drivers must follow all posted signs on the road, and use the speed limit icon only as a reference. The accuracy of speed limit data cannot be guaranteed. You may report inaccuracies in our speed limit data by filing a case in the Google Cloud Support Portal.
Parameters
enabled |
---|
public void setSpeedometerEnabled (boolean enabled)
Specifies whether the speedometer is shown. Only call this method on the UI thread.
When enabled, a speedometer that indicates the vehicle speed appears in the bottom start corner during guidance. When speed limit icon is visible, they are attached, and then speedometer can have different colors for text and background, depending on the speeding severity.
Enabling speedometer also enables the speed limit icon altogether, however you can use
setSpeedLimitIconEnabled(boolean)
to disable/enable the speed limit icon separately.
When the recenter button is enabled, the speedometer is temporarily hidden when the recenter button displays.
Parameters
enabled |
---|
public void setSpeedometerUiOptions (SpeedometerUiOptions speedometerUiOptions)
Sets the speedometer UI configuration SpeedometerUiOptions
based on SpeedAlertSeverity
. Only call this method on the UI thread.
By setting a null
SpeedometerUiOptions
, you are clearing the previous one if
set. When no SpeedometerUiOptions
is configured, speedometer UI fallbacks to NavSDK
default configurations for speed alerts of different SpeedAlertSeverity
:
SpeedAlertSeverity.MINOR
speed alert in day mode: red text in white backgroundSpeedAlertSeverity.MINOR
speed alert in night mode: red text in dark backgroundSpeedAlertSeverity.MAJOR
speed alert in day mode: white text in red backgroundSpeedAlertSeverity.MAJOR
speed alert in night mode: white text in red background
Parameters
speedometerUiOptions |
---|
public void setStylingOptions (StylingOptions stylingOptions)
Sets some styling options for the navigation UI. This method should only be called on the UI thread.
Parameters
stylingOptions |
---|
public void setTrafficIncidentCardsEnabled (boolean enabled)
Sets whether traffic incident cards should be shown when the user clicks on a traffic incident icon. This method should only be called on the UI thread.
Note that when guided navigation is running, traffic incident details are shown in prompts.
To disable traffic incident details during navigation, setTrafficPromptsEnabled(boolean)
should
be used instead.
Parameters
enabled |
---|
See Also
public void setTrafficPromptsEnabled (boolean enabled)
Sets whether traffic prompts should be shown. Traffic prompts periodically appear to update the user on traffic conditions during navigation. This method should only be called on the UI thread.
Parameters
enabled |
---|