SupportNavigationFragment

public class SupportNavigationFragment extends Fragment

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.SupportNavigationFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

Inherited Field Summary

Public Constructor Summary

SupportNavigationFragment()
Creates a navigation map fragment.

Public Method Summary

void
addOnNavigationUiChangedListener(OnNavigationUiChangedListener listener)
Adds a listener to the list of listeners which will be notified when navigation UI is enabled or disabled.
void
addOnNightModeChangedListener(NavigationView.OnNightModeChangedListener listener)
Adds a listener to the list of listeners which will be notified when the UI enters or exits night mode.
void
addOnRecenterButtonClickedListener(NavigationView.OnRecenterButtonClickedListener listener)
Adds a listener to the list of listeners which will be notified when the recenter button is clicked.
void
getMapAsync(OnMapReadyCallback mapReadyCallback)
Returns a non-null instance of the GoogleMap, ready to be used.
boolean
isNavigationUiEnabled()
Returns whether navigation UI is enabled.
static SupportNavigationFragment
newInstance()
Creates a map fragment, using default options.
static SupportNavigationFragment
newInstance(GoogleMapOptions options)
Creates a map fragment with the given options.
void
onConfigurationChanged(Configuration config)
View
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
void
void
void
onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState)
Parse attributes during inflation from a view hierarchy into the arguments we handle.
void
void
void
void
onSaveInstanceState(Bundle outState)
void
void
onStop()
void
void
void
void
setCalloutInfoDisplayModeOverride(NavigationCalloutDisplayMode calloutInfoDisplayModeOverride)
Overrides default display mode for route callouts during navigation.
void
setCalloutInfoFormatOverride(RouteCalloutInfoFormat calloutInfoFormatOverride)
Sets the callout info format mode for route callouts.
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
setNavigationUiEnabled(boolean enableNavigationUi)
Enables or disables navigation UI.
void
setRecenterButtonEnabled(boolean enabled)
Sets whether the re-center button should be shown.
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
setStylingOptions(StylingOptions stylingOptions)
Sets some styling options for the navigation UI.
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.
void
setTripProgressBarEnabled(boolean enabled)
Sets whether the trip progress bar is visible during navigation.
void
showRouteOverview()
Pans and zooms the map to show an overview of the remaining route.

Inherited Method Summary

Public Constructors

public SupportNavigationFragment ()

Creates a navigation map fragment. This constructor is public only for use by an inflater. Use newInstance() to create a SupportNavigationFragment programmatically.

Public Methods

public void addOnNavigationUiChangedListener (OnNavigationUiChangedListener listener)

Adds a listener to the list of listeners which will be notified when navigation UI is enabled or disabled.

Navigation UI can be turned on or off via:

This allows monitoring navigation UI changes triggered by different APIs.

Parameters
listener the listener to be added.

public void addOnNightModeChangedListener (NavigationView.OnNightModeChangedListener listener)

Adds a listener to the list of listeners 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)

Adds a listener to the list of listeners 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 void getMapAsync (OnMapReadyCallback mapReadyCallback)

Returns a non-null instance of the GoogleMap, ready to be used.

Note that:

  • This method must be called from the main thread.
  • The callback will be executed in the main thread.
  • The GoogleMap object provided by the callback is non-null.

Parameters
mapReadyCallback The callback object that will be triggered when the map is ready to be used.

public boolean isNavigationUiEnabled ()

Returns whether navigation UI is enabled.

Navigation UI can be turned on or off via:

public static SupportNavigationFragment newInstance ()

Creates a map fragment, using default options.

public static SupportNavigationFragment newInstance (GoogleMapOptions options)

Creates a map fragment with the given options.

Parameters
options

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 onDestroyView ()

public void onInflate (Activity activity, AttributeSet attrs, Bundle savedInstanceState)

Parse attributes during inflation from a view hierarchy into the arguments we handle.

Parameters
activity
attrs
savedInstanceState

public void onLowMemory ()

public void onPause ()

public void onResume ()

public void onSaveInstanceState (Bundle outState)

Parameters
outState

public void onStart ()

public void onStop ()

public void removeOnNavigationUiChangedListener (OnNavigationUiChangedListener listener)

Parameters
listener the listener to be removed.

public void removeOnNightModeChangedListener (NavigationView.OnNightModeChangedListener listener)

public void removeOnRecenterButtonClickedListener (NavigationView.OnRecenterButtonClickedListener listener)

public void setCalloutInfoDisplayModeOverride (NavigationCalloutDisplayMode calloutInfoDisplayModeOverride)

Overrides default display mode for route 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 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 setNavigationUiEnabled (boolean enableNavigationUi)

Enables or disables navigation UI.

When navigation UI is enabled, the fragment is in a navigation-ready state to focus on providing navigation experience. Navigation oriented features will be available under this mode. For example: the camera follows the user’s location, night mode support, navigation focused tile style, speedometer, high detail map style, etc. In contrast, features that are maps focused and conflict with navigation will be unavailable. For example: indoor, zoom control buttons(use gestures instead), my location button.

When navigation UI is disabled, the fragment will be in a maps focused state where these navigation focused features will be unavailable and those maps focused features would be available. However, if there is an ongoing guided navigation session, it will continue in the background. Guided navigation must be stopped by calling Navigator.stopGuidance().

Navigation UI will also be enabled when GoogleMap.followMyLocation(int) is called.

This call might be asynchronous. For example, when tries to enable navigation UI but no Navigator has not been created. In this case, navigation UI will be enabled only after an instance of Navigator is created. Uses addOnNavigationUiChangedListener(OnNavigationUiChangedListener) to listen to navigation mode change result.

Parameters
enableNavigationUi whether to enable navigation UI.

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 setSpeedLimitIconEnabled (boolean enabled)

Specifies whether the speed limit icon is shown. Only call this method on the UI thread. By default, the speed limit icon is not shown.

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. By default, the speedometer is not shown.

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:

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.

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

public void setTripProgressBarEnabled (boolean enabled)

Sets whether the trip progress bar is visible during navigation. This method should only be called on the UI thread.

THIS API IS A BETA RELEASE.
IT IS SUBJECT TO CHANGE AND BACKWARDS COMPATIBILITY IS NOT GUARANTEED

Parameters
enabled

public void showRouteOverview ()

Pans and zooms the map to show an overview of the remaining route. This will temporarily prevent the camera from following the user's position.

The camera can be reset to follow the user using GoogleMap.followMyLocation(int).