A navigation component in an app. This fragment is the simplest way to use navigation in an application. It's a wrapper around a view of a navigation map to automatically handle the necessary life cycle needs. Being a fragment, this component can be added to an activity's layout file simply with the XML below.
<fragment class="com.google.android.libraries.navigation.NavigationFragment" android:layout_width="match_parent" android:layout_height="match_parent"/>
Inherited Constant Summary
Public Constructor Summary
Public Method Summary
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)
|
View |
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
void | |
void |
onPause()
|
void |
onResume()
|
void |
onSaveInstanceState(Bundle outState)
|
void |
onStart()
|
void |
onStop()
|
void |
onTrimMemory(int level)
|
void |
setCalloutInfoDisplayModeOverride(NavigationCalloutDisplayMode calloutInfoDisplayModeOverride)
Overrides default display mode for ETA callouts during navigation.
|
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 forceNightMode)
|
void |
setHeaderEnabled(boolean enabled)
Sets whether the turn-by-turn navigation header is visible during navigation.
|
void |
setOnNightModeChangedListener(NavigationView.OnNightModeChangedListener listener)
Sets a listener which will be notified when the UI enters or exits night mode.
|
void |
setOnRecenterButtonClickedListener(NavigationView.OnRecenterButtonClickedListener listener)
Sets a listener which will be notified when the recenter button is clicked.
|
void |
setRecenterButtonEnabled(boolean enabled)
Sets whether the re-center button should be shown.
|
void |
setSpeedAlertOptions(SpeedAlertOptions speedAlertOptions)
Sets
SpeedAlertOptions for customizing the triggering thresholds for SpeedAlertSeverity s. |
void |
setSpeedLimitIconEnabled(boolean enabled)
Specifies whether the speed limit icon is shown.
|
void |
setSpeedometerIconEnabled(boolean enabled)
Specifies whether the speedometer icon is shown.
|
void |
setSpeedometerUiOptions(SpeedometerUiOptions speedAlertUiOptions)
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 NavigationFragment ()
Public Methods
public Camera getCamera ()
Returns a camera object which can be used to alter the viewport of the map.
Returns
- the
Camera
object associated with this fragment
public void onConfigurationChanged (Configuration config)
Parameters
config |
---|
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
Parameters
inflater | |
---|---|
container | |
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 setCalloutInfoDisplayModeOverride (NavigationCalloutDisplayMode calloutInfoDisplayModeOverride)
Overrides default display mode for ETA callouts during navigation. 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 setForceNightMode (int forceNightMode)
Parameters
forceNightMode |
---|
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)
Sets 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, 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)
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)
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 MINOR
and MAJOR
alerts. You can also
use this method to configure the time in seconds needed to upgrade speed alerts from MINOR
to 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 icon 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 setSpeedometerIconEnabled (boolean enabled)
Specifies whether the speedometer icon is shown. Only call this method on the UI thread.
When enabled, a speedometer icon 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 speedomter icon also enables speed limit icon altogether, however you can use
setSpeedLimitIconEnabled(boolean)
to disable/enable speed limit icon separate
If the recenter button is enabled, then the speedometer icon is temporarily hidden when the recenter button displays.
Parameters
enabled |
---|
public void setSpeedometerUiOptions (SpeedometerUiOptions speedAlertUiOptions)
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
:
Parameters
speedAlertUiOptions |
---|
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.
Parameters
enabled |
---|
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 |
---|