11package com .mapbox .services .android .navigation .ui .v5 ;
22
33import android .app .Activity ;
4- import android .app .Fragment ;
54import android .arch .lifecycle .LifecycleObserver ;
65import android .arch .lifecycle .LifecycleOwner ;
76import android .arch .lifecycle .ViewModelProviders ;
3332import com .mapbox .services .android .navigation .ui .v5 .instruction .NavigationAlertView ;
3433import com .mapbox .services .android .navigation .ui .v5 .map .NavigationMapboxMap ;
3534import com .mapbox .services .android .navigation .ui .v5 .map .NavigationMapboxMapInstanceState ;
35+ import com .mapbox .services .android .navigation .ui .v5 .map .WayNameView ;
3636import com .mapbox .services .android .navigation .ui .v5 .summary .SummaryBottomSheet ;
3737import com .mapbox .services .android .navigation .v5 .location .replay .ReplayRouteLocationEngine ;
3838import com .mapbox .services .android .navigation .v5 .navigation .MapboxNavigation ;
@@ -75,6 +75,7 @@ public class NavigationView extends CoordinatorLayout implements LifecycleObserv
7575 private BottomSheetBehavior summaryBehavior ;
7676 private ImageButton cancelBtn ;
7777 private RecenterButton recenterBtn ;
78+ private WayNameView wayNameView ;
7879 private ImageButton routeOverviewBtn ;
7980
8081 private NavigationPresenter navigationPresenter ;
@@ -141,8 +142,10 @@ public boolean onBackPressed() {
141142 */
142143 public void onSaveInstanceState (Bundle outState ) {
143144 int bottomSheetBehaviorState = summaryBehavior == null ? INVALID_STATE : summaryBehavior .getState ();
144- NavigationViewInstanceState navigationViewInstanceState = new NavigationViewInstanceState (bottomSheetBehaviorState ,
145- recenterBtn .getVisibility (), instructionView .isShowingInstructionList ());
145+ boolean isWayNameVisible = wayNameView .getVisibility () == VISIBLE ;
146+ NavigationViewInstanceState navigationViewInstanceState = new NavigationViewInstanceState (
147+ bottomSheetBehaviorState , recenterBtn .getVisibility (), instructionView .isShowingInstructionList (),
148+ isWayNameVisible , wayNameView .retrieveWayNameText ());
146149 String instanceKey = getContext ().getString (R .string .navigation_view_instance_state );
147150 outState .putParcelable (instanceKey , navigationViewInstanceState );
148151 outState .putBoolean (getContext ().getString (R .string .navigation_running ), navigationViewModel .isRunning ());
@@ -161,6 +164,8 @@ public void onRestoreInstanceState(Bundle savedInstanceState) {
161164 String instanceKey = getContext ().getString (R .string .navigation_view_instance_state );
162165 NavigationViewInstanceState navigationViewInstanceState = savedInstanceState .getParcelable (instanceKey );
163166 recenterBtn .setVisibility (navigationViewInstanceState .getRecenterButtonVisibility ());
167+ wayNameView .setVisibility (navigationViewInstanceState .isWayNameVisible () ? VISIBLE : INVISIBLE );
168+ wayNameView .updateWayNameText (navigationViewInstanceState .getWayNameText ());
164169 resetBottomSheetState (navigationViewInstanceState .getBottomSheetBehaviorState ());
165170 updateInstructionListState (navigationViewInstanceState .isInstructionViewVisible ());
166171 mapInstanceState = savedInstanceState .getParcelable (MAP_INSTANCE_STATE_KEY );
@@ -172,7 +177,8 @@ public void onRestoreInstanceState(Bundle savedInstanceState) {
172177 * <p>
173178 * In an {@link Activity} this should be in {@link Activity#onDestroy()}.
174179 * <p>
175- * In a {@link android.app.Fragment}, this should be in {@link Fragment#onDestroyView()}.
180+ * In a {@link android.support.v4.app.Fragment}, this should
181+ * be in {@link android.support.v4.app.Fragment#onDestroyView()}.
176182 */
177183 public void onDestroy () {
178184 shutdown ();
@@ -212,6 +218,7 @@ public void onStop() {
212218 @ Override
213219 public void onMapReady (MapboxMap mapboxMap ) {
214220 initializeNavigationMap (mapView , mapboxMap );
221+ initializeWayNameListener ();
215222 onNavigationReadyCallback .onNavigationReady (navigationViewModel .isRunning ());
216223 isMapInitialized = true ;
217224 }
@@ -269,17 +276,6 @@ public void drawRoute(DirectionsRoute directionsRoute) {
269276 }
270277 }
271278
272- private void initializeNavigationMap (MapView mapView , MapboxMap map ) {
273- navigationMap = new NavigationMapboxMap (mapView , map );
274- if (mapInstanceState != null ) {
275- navigationMap .restoreFrom (mapInstanceState );
276- return ;
277- }
278- if (initialMapCameraPosition != null ) {
279- map .setCameraPosition (initialMapCameraPosition );
280- }
281- }
282-
283279 @ Override
284280 public void addMarker (Point position ) {
285281 if (navigationMap != null ) {
@@ -293,23 +289,43 @@ public void clearMarkers() {
293289 }
294290 }
295291
296- public void updateWaynameView (String wayname ) {
297- if (navigationMap != null ) {
298- navigationMap .updateWaynameView (wayname );
299- }
292+ /**
293+ * Provides the current visibility of the way name view.
294+ *
295+ * @return true if visible, false if not visible
296+ */
297+ public boolean isWayNameVisible () {
298+ return wayNameView .getVisibility () == VISIBLE ;
300299 }
301300
301+ /**
302+ * Updates the text of the way name view below the
303+ * navigation icon.
304+ * <p>
305+ * If you'd like to use this method without being overridden by the default way names
306+ * values we provide, please disabled auto-query with
307+ * {@link NavigationMapboxMap#updateWaynameQueryMap(boolean)}.
308+ *
309+ * @param wayName to update the view
310+ */
302311 @ Override
303- public void updateWaynameVisibility (boolean isVisible ) {
304- if (navigationMap != null ) {
305- navigationMap .updateWaynameVisibility (isVisible );
306- }
312+ public void updateWayNameView (@ NonNull String wayName ) {
313+ wayNameView .updateWayNameText (wayName );
307314 }
308315
309- public void updateWaynameQueryMap (boolean isEnabled ) {
310- if (navigationMap != null ) {
311- navigationMap .updateWaynameQueryMap (isEnabled );
312- }
316+ /**
317+ * Updates the visibility of the way name view that is show below
318+ * the navigation icon.
319+ * <p>
320+ * If you'd like to use this method without being overridden by the default visibility values
321+ * values we provide, please disabled auto-query with
322+ * {@link NavigationMapboxMap#updateWaynameQueryMap(boolean)}.
323+ *
324+ * @param isVisible true to show, false to hide
325+ */
326+ @ Override
327+ public void updateWayNameVisibility (boolean isVisible ) {
328+ wayNameView .updateVisibility (isVisible );
313329 }
314330
315331 @ Override
@@ -377,6 +393,7 @@ public void startNavigation(NavigationViewOptions options) {
377393 * @since 0.16.0
378394 */
379395 public void stopNavigation () {
396+ navigationPresenter .onNavigationStopped ();
380397 navigationViewModel .stopNavigation ();
381398 }
382399
@@ -499,6 +516,7 @@ private void bind() {
499516 summaryBottomSheet = findViewById (R .id .summaryBottomSheet );
500517 cancelBtn = findViewById (R .id .cancelBtn );
501518 recenterBtn = findViewById (R .id .recenterBtn );
519+ wayNameView = findViewById (R .id .wayNameView );
502520 routeOverviewBtn = findViewById (R .id .routeOverviewBtn );
503521 }
504522
@@ -527,6 +545,22 @@ private void initializeInstructionListListener() {
527545 navigationViewEventDispatcher ));
528546 }
529547
548+ private void initializeNavigationMap (MapView mapView , MapboxMap map ) {
549+ navigationMap = new NavigationMapboxMap (mapView , map );
550+ if (mapInstanceState != null ) {
551+ navigationMap .restoreFrom (mapInstanceState );
552+ return ;
553+ }
554+ if (initialMapCameraPosition != null ) {
555+ map .setCameraPosition (initialMapCameraPosition );
556+ }
557+ }
558+
559+ private void initializeWayNameListener () {
560+ NavigationViewWayNameListener wayNameListener = new NavigationViewWayNameListener (navigationPresenter );
561+ navigationMap .addOnWayNameChangedListener (wayNameListener );
562+ }
563+
530564 private void updateSavedInstanceStateMapStyle (@ Nullable Bundle savedInstanceState ) {
531565 if (savedInstanceState != null ) {
532566 String mapStyleUrl = ThemeSwitcher .retrieveMapStyle (getContext ());
0 commit comments