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 ;
3231import com .mapbox .services .android .navigation .ui .v5 .instruction .NavigationAlertView ;
3332import com .mapbox .services .android .navigation .ui .v5 .map .NavigationMapboxMap ;
3433import com .mapbox .services .android .navigation .ui .v5 .map .NavigationMapboxMapInstanceState ;
34+ import com .mapbox .services .android .navigation .ui .v5 .map .WayNameView ;
3535import com .mapbox .services .android .navigation .ui .v5 .summary .SummaryBottomSheet ;
3636import com .mapbox .services .android .navigation .v5 .location .replay .ReplayRouteLocationEngine ;
3737import com .mapbox .services .android .navigation .v5 .navigation .MapboxNavigation ;
@@ -74,6 +74,7 @@ public class NavigationView extends CoordinatorLayout implements LifecycleObserv
7474 private BottomSheetBehavior summaryBehavior ;
7575 private ImageButton cancelBtn ;
7676 private RecenterButton recenterBtn ;
77+ private WayNameView wayNameView ;
7778 private ImageButton routeOverviewBtn ;
7879
7980 private NavigationPresenter navigationPresenter ;
@@ -140,8 +141,10 @@ public boolean onBackPressed() {
140141 */
141142 public void onSaveInstanceState (Bundle outState ) {
142143 int bottomSheetBehaviorState = summaryBehavior == null ? INVALID_STATE : summaryBehavior .getState ();
143- NavigationViewInstanceState navigationViewInstanceState = new NavigationViewInstanceState (bottomSheetBehaviorState ,
144- recenterBtn .getVisibility (), instructionView .isShowingInstructionList ());
144+ boolean isWayNameVisible = wayNameView .getVisibility () == VISIBLE ;
145+ NavigationViewInstanceState navigationViewInstanceState = new NavigationViewInstanceState (
146+ bottomSheetBehaviorState , recenterBtn .getVisibility (), instructionView .isShowingInstructionList (),
147+ isWayNameVisible , wayNameView .retrieveWayNameText ());
145148 String instanceKey = getContext ().getString (R .string .navigation_view_instance_state );
146149 outState .putParcelable (instanceKey , navigationViewInstanceState );
147150 outState .putBoolean (getContext ().getString (R .string .navigation_running ), navigationViewModel .isRunning ());
@@ -160,6 +163,8 @@ public void onRestoreInstanceState(Bundle savedInstanceState) {
160163 String instanceKey = getContext ().getString (R .string .navigation_view_instance_state );
161164 NavigationViewInstanceState navigationViewInstanceState = savedInstanceState .getParcelable (instanceKey );
162165 recenterBtn .setVisibility (navigationViewInstanceState .getRecenterButtonVisibility ());
166+ wayNameView .setVisibility (navigationViewInstanceState .isWayNameVisible () ? VISIBLE : INVISIBLE );
167+ wayNameView .updateWayNameText (navigationViewInstanceState .getWayNameText ());
163168 resetBottomSheetState (navigationViewInstanceState .getBottomSheetBehaviorState ());
164169 updateInstructionListState (navigationViewInstanceState .isInstructionViewVisible ());
165170 mapInstanceState = savedInstanceState .getParcelable (MAP_INSTANCE_STATE_KEY );
@@ -171,7 +176,8 @@ public void onRestoreInstanceState(Bundle savedInstanceState) {
171176 * <p>
172177 * In an {@link Activity} this should be in {@link Activity#onDestroy()}.
173178 * <p>
174- * In a {@link android.app.Fragment}, this should be in {@link Fragment#onDestroyView()}.
179+ * In a {@link android.support.v4.app.Fragment}, this should
180+ * be in {@link android.support.v4.app.Fragment#onDestroyView()}.
175181 */
176182 public void onDestroy () {
177183 shutdown ();
@@ -211,6 +217,7 @@ public void onStop() {
211217 @ Override
212218 public void onMapReady (MapboxMap mapboxMap ) {
213219 initializeNavigationMap (mapView , mapboxMap );
220+ initializeWayNameListener ();
214221 onNavigationReadyCallback .onNavigationReady (navigationViewModel .isRunning ());
215222 isMapInitialized = true ;
216223 }
@@ -268,17 +275,6 @@ public void drawRoute(DirectionsRoute directionsRoute) {
268275 }
269276 }
270277
271- private void initializeNavigationMap (MapView mapView , MapboxMap map ) {
272- navigationMap = new NavigationMapboxMap (mapView , map );
273- if (mapInstanceState != null ) {
274- navigationMap .restoreFrom (mapInstanceState );
275- return ;
276- }
277- if (initialMapCameraPosition != null ) {
278- map .setCameraPosition (initialMapCameraPosition );
279- }
280- }
281-
282278 @ Override
283279 public void addMarker (Point position ) {
284280 if (navigationMap != null ) {
@@ -292,23 +288,33 @@ public void clearMarkers() {
292288 }
293289 }
294290
291+ /**
292+ * Updates the text of the way name view below the
293+ * navigation icon.
294+ * <p>
295+ * If you'd like to use this method without being overridden by the default way names
296+ * values we provide, please disabled auto-query with
297+ * {@link NavigationMapboxMap#updateWaynameQueryMap(boolean)}.
298+ *
299+ * @param wayname to update the view
300+ */
295301 public void updateWaynameView (String wayname ) {
296- if (navigationMap != null ) {
297- navigationMap .updateWaynameView (wayname );
298- }
302+ wayNameView .updateWayNameText (wayname );
299303 }
300304
305+ /**
306+ * Updates the visibility of the way name view that is show below
307+ * the navigation icon.
308+ * <p>
309+ * If you'd like to use this method without being overridden by the default visibility values
310+ * values we provide, please disabled auto-query with
311+ * {@link NavigationMapboxMap#updateWaynameQueryMap(boolean)}.
312+ *
313+ * @param isVisible true to show, false to hide
314+ */
301315 @ Override
302316 public void updateWaynameVisibility (boolean isVisible ) {
303- if (navigationMap != null ) {
304- navigationMap .updateWaynameVisibility (isVisible );
305- }
306- }
307-
308- public void updateWaynameQueryMap (boolean isEnabled ) {
309- if (navigationMap != null ) {
310- navigationMap .updateWaynameQueryMap (isEnabled );
311- }
317+ wayNameView .updateVisibility (isVisible );
312318 }
313319
314320 @ Override
@@ -497,6 +503,7 @@ private void bind() {
497503 summaryBottomSheet = findViewById (R .id .summaryBottomSheet );
498504 cancelBtn = findViewById (R .id .cancelBtn );
499505 recenterBtn = findViewById (R .id .recenterBtn );
506+ wayNameView = findViewById (R .id .wayNameView );
500507 routeOverviewBtn = findViewById (R .id .routeOverviewBtn );
501508 }
502509
@@ -525,6 +532,22 @@ private void initializeInstructionListListener() {
525532 navigationViewEventDispatcher ));
526533 }
527534
535+ private void initializeNavigationMap (MapView mapView , MapboxMap map ) {
536+ navigationMap = new NavigationMapboxMap (mapView , map );
537+ if (mapInstanceState != null ) {
538+ navigationMap .restoreFrom (mapInstanceState );
539+ return ;
540+ }
541+ if (initialMapCameraPosition != null ) {
542+ map .setCameraPosition (initialMapCameraPosition );
543+ }
544+ }
545+
546+ private void initializeWayNameListener () {
547+ NavigationViewWayNameListener wayNameListener = new NavigationViewWayNameListener (navigationPresenter );
548+ navigationMap .addOnWayNameChangedListener (wayNameListener );
549+ }
550+
528551 private void updateSavedInstanceStateMapStyle (@ Nullable Bundle savedInstanceState ) {
529552 if (savedInstanceState != null ) {
530553 String mapStyleUrl = ThemeSwitcher .retrieveMapStyle (getContext ());
0 commit comments