Skip to content

Commit

Permalink
Aded InstructionViewCallback to allow views to be alerted when the in…
Browse files Browse the repository at this point in the history
…struction list is shown or hidden. This fixes the bugs where the re-center button and other widgets are shown on top of the instruction list when it's expanded
  • Loading branch information
Devota Aabel committed Jun 5, 2018
1 parent e2102d2 commit ef33a5b
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,14 +32,15 @@
import retrofit2.Response;

public class EmbeddedNavigationActivity extends AppCompatActivity implements OnNavigationReadyCallback,
NavigationListener, ProgressChangeListener {
NavigationListener, ProgressChangeListener, InstructionListListener {

private NavigationView navigationView;
private View spacer;
private TextView speedWidget;
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) {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -406,6 +407,7 @@ private void initializeView() {
bind();
initializeNavigationViewModel();
initializeSummaryBottomSheet();
initializeInstructionListListener();
initializeNavigationEventDispatcher();
}

Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}
Expand All @@ -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) {
Expand All @@ -55,6 +58,10 @@ void assignBottomSheetCallback(@Nullable BottomSheetCallback bottomSheetCallback
this.bottomSheetCallback = bottomSheetCallback;
}

void assignInstructionListListener(@Nullable InstructionListListener instructionListListener) {
this.instructionViewCallback = instructionListListener;
}

/*
* Feedback listeners
*/
Expand Down Expand Up @@ -152,4 +159,10 @@ private void assignMilestoneEventListener(NavigationViewOptions navigationViewOp
navigation.addMilestoneEventListener(navigationViewOptions.milestoneEventListener());
}
}

void onInstructionListShown(boolean shown) {
if (instructionViewCallback != null) {
instructionViewCallback.onInstructionListVisibilityChanged(shown);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = "";
Expand All @@ -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.
* <p>
Expand Down Expand Up @@ -312,6 +318,7 @@ public void hideInstructionList() {
updateLandscapeConstraintsTo(R.layout.instruction_layout);
}
instructionListLayout.setVisibility(GONE);
instructionListListener.onInstructionListVisibilityChanged(false);
}

/**
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit ef33a5b

Please sign in to comment.