diff --git a/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/navigationui/EmbeddedNavigationActivity.java b/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/navigationui/EmbeddedNavigationActivity.java index c68174b379c..41eb4ec4461 100644 --- a/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/navigationui/EmbeddedNavigationActivity.java +++ b/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/navigationui/EmbeddedNavigationActivity.java @@ -22,6 +22,7 @@ import com.mapbox.services.android.navigation.ui.v5.NavigationView; import com.mapbox.services.android.navigation.ui.v5.NavigationViewOptions; import com.mapbox.services.android.navigation.ui.v5.OnNavigationReadyCallback; +import com.mapbox.services.android.navigation.ui.v5.listeners.InstructionListListener; import com.mapbox.services.android.navigation.ui.v5.listeners.NavigationListener; import com.mapbox.services.android.navigation.v5.navigation.NavigationRoute; import com.mapbox.services.android.navigation.v5.routeprogress.ProgressChangeListener; @@ -31,7 +32,7 @@ import retrofit2.Response; public class EmbeddedNavigationActivity extends AppCompatActivity implements OnNavigationReadyCallback, - NavigationListener, ProgressChangeListener { + NavigationListener, ProgressChangeListener, InstructionListListener { private NavigationView navigationView; private View spacer; @@ -39,6 +40,7 @@ public class EmbeddedNavigationActivity extends AppCompatActivity implements OnN private static final Point ORIGIN = Point.fromLngLat(-77.03194990754128, 38.909664963450105); private static final Point DESTINATION = Point.fromLngLat(-77.0270025730133, 38.91057077063121); private boolean bottomSheetVisible = true; + private boolean instructionListShown = false; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -78,7 +80,8 @@ private void startNavigation(DirectionsRoute directionsRoute) { .navigationListener(this) .directionsRoute(directionsRoute) .shouldSimulateRoute(true) - .progressChangeListener(this); + .progressChangeListener(this) + .instructionListListener(this); setBottomSheetCallback(options); navigationView.startNavigation(options.build()); @@ -220,6 +223,14 @@ private void setSpeed(Location location) { 0, string.length() - 3, Spanned.SPAN_INCLUSIVE_INCLUSIVE); speedWidget.setText(spannableString); - speedWidget.setVisibility(View.VISIBLE); + if (!instructionListShown) { + speedWidget.setVisibility(View.VISIBLE); + } + } + + @Override + public void onInstructionListVisibilityChanged(boolean shown) { + instructionListShown = shown; + speedWidget.setVisibility(shown ? View.GONE : View.VISIBLE); } } diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationPresenter.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationPresenter.java index 1f624a4a193..688098430db 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationPresenter.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationPresenter.java @@ -52,4 +52,12 @@ void onNavigationLocationUpdate(Location location) { view.resumeCamera(location); view.updateLocationLayer(location); } + + public void onInstructionListVisibilityChanged(boolean visible) { + if (visible) { + view.hideRecenterBtn(); + } else { + view.showRecenterBtn(); + } + } } diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationView.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationView.java index 7861c799069..e68adcc320b 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationView.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationView.java @@ -34,6 +34,7 @@ import com.mapbox.services.android.navigation.ui.v5.camera.NavigationCamera; import com.mapbox.services.android.navigation.ui.v5.instruction.ImageCoordinator; import com.mapbox.services.android.navigation.ui.v5.instruction.InstructionView; +import com.mapbox.services.android.navigation.ui.v5.listeners.InstructionListListener; import com.mapbox.services.android.navigation.ui.v5.route.NavigationMapRoute; import com.mapbox.services.android.navigation.ui.v5.summary.SummaryBottomSheet; import com.mapbox.services.android.navigation.ui.v5.utils.ViewUtils; @@ -406,6 +407,7 @@ private void initializeView() { bind(); initializeNavigationViewModel(); initializeSummaryBottomSheet(); + initializeInstructionListListener(); initializeNavigationEventDispatcher(); } @@ -449,6 +451,16 @@ private void initializeNavigationEventDispatcher() { navigationViewModel.initializeEventDispatcher(navigationViewEventDispatcher); } + private void initializeInstructionListListener() { + instructionView.setInstructionListListener(new InstructionListListener() { + @Override + public void onInstructionListVisibilityChanged(boolean visible) { + navigationPresenter.onInstructionListVisibilityChanged(visible); + navigationViewEventDispatcher.onInstructionListShown(visible); + } + }); + } + /** * Sets the {@link BottomSheetBehavior} based on the last state stored * in {@link Bundle} savedInstanceState. diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewEventDispatcher.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewEventDispatcher.java index f5296992ece..f4015012f97 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewEventDispatcher.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewEventDispatcher.java @@ -9,6 +9,7 @@ import com.mapbox.geojson.Point; import com.mapbox.services.android.navigation.ui.v5.feedback.FeedbackItem; import com.mapbox.services.android.navigation.ui.v5.listeners.FeedbackListener; +import com.mapbox.services.android.navigation.ui.v5.listeners.InstructionListListener; import com.mapbox.services.android.navigation.ui.v5.listeners.NavigationListener; import com.mapbox.services.android.navigation.ui.v5.listeners.RouteListener; import com.mapbox.services.android.navigation.v5.navigation.MapboxNavigation; @@ -24,6 +25,7 @@ class NavigationViewEventDispatcher { private NavigationListener navigationListener; private RouteListener routeListener; private BottomSheetCallback bottomSheetCallback; + private InstructionListListener instructionViewCallback; /** * Initializes the listeners in the dispatcher, as well as the listeners in the {@link MapboxNavigation} @@ -37,6 +39,7 @@ void initializeListeners(NavigationViewOptions navigationViewOptions, MapboxNavi assignBottomSheetCallback(navigationViewOptions.bottomSheetCallback()); assignProgressChangeListener(navigationViewOptions, navigation); assignMilestoneEventListener(navigationViewOptions, navigation); + assignInstructionListListener(navigationViewOptions.instructionListListener()); } void assignFeedbackListener(@Nullable FeedbackListener feedbackListener) { @@ -55,6 +58,10 @@ void assignBottomSheetCallback(@Nullable BottomSheetCallback bottomSheetCallback this.bottomSheetCallback = bottomSheetCallback; } + void assignInstructionListListener(@Nullable InstructionListListener instructionListListener) { + this.instructionViewCallback = instructionListListener; + } + /* * Feedback listeners */ @@ -152,4 +159,10 @@ private void assignMilestoneEventListener(NavigationViewOptions navigationViewOp navigation.addMilestoneEventListener(navigationViewOptions.milestoneEventListener()); } } + + void onInstructionListShown(boolean shown) { + if (instructionViewCallback != null) { + instructionViewCallback.onInstructionListVisibilityChanged(shown); + } + } } diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewOptions.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewOptions.java index 80e8b271677..84469cf8adf 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewOptions.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationViewOptions.java @@ -7,6 +7,7 @@ import com.mapbox.api.directions.v5.DirectionsCriteria; import com.mapbox.api.directions.v5.models.DirectionsRoute; import com.mapbox.services.android.navigation.ui.v5.listeners.FeedbackListener; +import com.mapbox.services.android.navigation.ui.v5.listeners.InstructionListListener; import com.mapbox.services.android.navigation.ui.v5.listeners.NavigationListener; import com.mapbox.services.android.navigation.ui.v5.listeners.RouteListener; import com.mapbox.services.android.navigation.v5.milestone.Milestone; @@ -42,6 +43,9 @@ public abstract class NavigationViewOptions extends NavigationUiOptions { @Nullable public abstract BottomSheetCallback bottomSheetCallback(); + @Nullable + public abstract InstructionListListener instructionListListener(); + @AutoValue.Builder public abstract static class Builder { @@ -71,6 +75,8 @@ public abstract static class Builder { public abstract Builder bottomSheetCallback(BottomSheetCallback bottomSheetCallback); + public abstract Builder instructionListListener(InstructionListListener instructionListListener); + public abstract NavigationViewOptions build(); } diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/instruction/InstructionView.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/instruction/InstructionView.java index 2846387abf1..099851739eb 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/instruction/InstructionView.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/instruction/InstructionView.java @@ -48,6 +48,7 @@ import com.mapbox.services.android.navigation.ui.v5.feedback.FeedbackItem; import com.mapbox.services.android.navigation.ui.v5.instruction.maneuver.ManeuverView; import com.mapbox.services.android.navigation.ui.v5.instruction.turnlane.TurnLaneAdapter; +import com.mapbox.services.android.navigation.ui.v5.listeners.InstructionListListener; import com.mapbox.services.android.navigation.ui.v5.summary.list.InstructionListAdapter; import com.mapbox.services.android.navigation.v5.navigation.NavigationConstants; import com.mapbox.services.android.navigation.v5.navigation.metrics.FeedbackEvent; @@ -104,6 +105,7 @@ public class InstructionView extends RelativeLayout implements FeedbackBottomShe private AnimationSet fadeInSlowOut; private LegStep currentStep; private NavigationViewModel navigationViewModel; + private InstructionListListener instructionListListener; private String language = ""; private String unitType = ""; @@ -123,6 +125,10 @@ public InstructionView(Context context, @Nullable AttributeSet attrs, int defSty initialize(); } + public void setInstructionListListener(InstructionListListener instructionListListener) { + this.instructionListListener = instructionListListener; + } + /** * Once this view has finished inflating, it will bind the views. *
@@ -312,6 +318,7 @@ public void hideInstructionList() { updateLandscapeConstraintsTo(R.layout.instruction_layout); } instructionListLayout.setVisibility(GONE); + instructionListListener.onInstructionListVisibilityChanged(false); } /** @@ -321,6 +328,7 @@ public void hideInstructionList() { * can be animated appropriately. */ public void showInstructionList() { + instructionListListener.onInstructionListVisibilityChanged(true); beginDelayedTransition(); int orientation = getContext().getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/listeners/InstructionListListener.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/listeners/InstructionListListener.java new file mode 100644 index 00000000000..85c2667b7e8 --- /dev/null +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/listeners/InstructionListListener.java @@ -0,0 +1,14 @@ +package com.mapbox.services.android.navigation.ui.v5.listeners; + +/** + * A listener that is triggered when the instruction list in InstructionView is shown or hidden. + */ +public interface InstructionListListener { + /** + * Triggered when the instruction list is shown or hidden. + * + * @param visible whether the list is shown or hidden + * @since 0.15.0 + */ + void onInstructionListVisibilityChanged(boolean visible); +}