Skip to content

Commit

Permalink
Added ability to hide buttons/alert views
Browse files Browse the repository at this point in the history
  • Loading branch information
Devota Aabel committed Aug 31, 2018
1 parent 3c93e49 commit ce8fe34
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ private void extractConfiguration(NavigationViewOptions.Builder options,
.getBoolean(NavigationConstants.NAVIGATION_VIEW_SIMULATE_ROUTE, false));
options.directionsProfile(preferences
.getString(NavigationConstants.NAVIGATION_VIEW_ROUTE_PROFILE_KEY, DirectionsCriteria.PROFILE_DRIVING_TRAFFIC));
options.showFeedbackFab(preferences
.getBoolean(NavigationConstants.NAVIGATION_VIEW_SHOW_FEEDBACK_FAB, true));
options.showSoundFab(preferences
.getBoolean(NavigationConstants.NAVIGATION_VIEW_SHOW_SOUND_FAB, true));
options.showProblemAlertView(preferences
.getBoolean(NavigationConstants.NAVIGATION_VIEW_SHOW_PROBLEM_ALERT_VIEW, true));
options.showFeedbackSubmittedAlertView(preferences
.getBoolean(NavigationConstants.NAVIGATION_VIEW_SHOW_FEEDBACK_SUBMITTED_ALERT_VIEW,true));
navigationOptions.enableOffRouteDetection(preferences
.getBoolean(NavigationConstants.NAVIGATION_VIEW_OFF_ROUTE_ENABLED_KEY, true));
navigationOptions.snapToRoute(preferences
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ private static void storeConfiguration(NavigationLauncherOptions options, Shared
editor.putString(NavigationConstants.NAVIGATION_VIEW_ROUTE_PROFILE_KEY, options.directionsProfile());
editor.putBoolean(NavigationConstants.NAVIGATION_VIEW_OFF_ROUTE_ENABLED_KEY, options.enableOffRouteDetection());
editor.putBoolean(NavigationConstants.NAVIGATION_VIEW_SNAP_ENABLED_KEY, options.snapToRoute());
editor.putBoolean(NavigationConstants.NAVIGATION_VIEW_SHOW_FEEDBACK_FAB, options.showFeedbackFab());
editor.putBoolean(NavigationConstants.NAVIGATION_VIEW_SHOW_SOUND_FAB, options.showSoundFab());
editor.putBoolean(NavigationConstants.NAVIGATION_VIEW_SHOW_PROBLEM_ALERT_VIEW, options.showProblemAlertView());
editor.putBoolean(
NavigationConstants.NAVIGATION_VIEW_SHOW_FEEDBACK_SUBMITTED_ALERT_VIEW, options.showFeedbackSubmittedAlertView());
}

private static void storeThemePreferences(NavigationLauncherOptions options, SharedPreferences.Editor editor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public abstract static class Builder {

public abstract Builder waynameChipEnabled(boolean waynameChipEnabled);

public abstract Builder showFeedbackFab(boolean showFeedbackFab);

public abstract Builder showSoundFab(boolean showSoundFab);

public abstract Builder showProblemAlertView(boolean showProblemAlertView);

public abstract Builder showFeedbackSubmittedAlertView(boolean showFeedbackSubmittedAlertView);

public abstract Builder enableOffRouteDetection(boolean enableOffRouteDetection);

public abstract Builder snapToRoute(boolean snapToRoute);
Expand All @@ -38,6 +46,10 @@ public static NavigationLauncherOptions.Builder builder() {
.shouldSimulateRoute(false)
.enableOffRouteDetection(true)
.snapToRoute(true)
.waynameChipEnabled(true);
.waynameChipEnabled(true)
.showFeedbackFab(true)
.showSoundFab(true)
.showProblemAlertView(true)
.showFeedbackSubmittedAlertView(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@ public abstract class NavigationUiOptions {
public abstract boolean shouldSimulateRoute();

public abstract boolean waynameChipEnabled();

public abstract boolean showFeedbackFab();

public abstract boolean showSoundFab();

public abstract boolean showProblemAlertView();

public abstract boolean showFeedbackSubmittedAlertView();
}
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,12 @@ private void establish(NavigationViewOptions options) {
establishLanguage(localeUtils, options);
establishUnitType(localeUtils, options);
establishTimeFormat(options);
setupInstructionView(options);
}

private void setupInstructionView(NavigationViewOptions options) {
instructionView.setupHiddenViews(options.showFeedbackFab(), options.showSoundFab(), options.showProblemAlertView(),
options.showFeedbackSubmittedAlertView());
}

private void establishLanguage(LocaleUtils localeUtils, NavigationViewOptions options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public abstract static class Builder {

public abstract Builder waynameChipEnabled(boolean waynameChipEnabled);

public abstract Builder showFeedbackFab(boolean showFeedbackFab);

public abstract Builder showSoundFab(boolean showSoundFab);

public abstract Builder showProblemAlertView(boolean showProblemAlertView);

public abstract Builder showFeedbackSubmittedAlertView(boolean showFeedbackSubmittedAlertView);

public abstract Builder navigationOptions(MapboxNavigationOptions navigationOptions);

public abstract Builder feedbackListener(FeedbackListener feedbackListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ public class InstructionView extends RelativeLayout implements FeedbackBottomShe
private String unitType = "";
private boolean isMuted;
private boolean isRerouting;
private boolean showFeedbackFab;
private boolean showSoundFab;
private boolean showProblemAlertView;
private boolean showFeedbackSubmittedAlertView;
private ConstraintLayout soundLayout;
private ConstraintLayout feedbackLayout;

public InstructionView(Context context) {
this(context, null);
Expand Down Expand Up @@ -164,7 +170,10 @@ protected void onDetachedFromWindow() {
@Override
public void onFeedbackSelected(FeedbackItem feedbackItem) {
navigationViewModel.updateFeedback(feedbackItem);
alertView.show(NavigationConstants.FEEDBACK_SUBMITTED, 3000, false);

if (showFeedbackSubmittedAlertView) {
alertView.show(NavigationConstants.FEEDBACK_SUBMITTED, 3000, false);
}
}

@Override
Expand Down Expand Up @@ -361,6 +370,22 @@ public void setUnitType(@DirectionsCriteria.VoiceUnitCriteria String unitType) {
checkForDistanceFormatterUpdate();
}

/**
* Sets up the fields which track which views should be hidden according to developer specifications
*
* @param showFeedbackFab whether to show the feedback fab
* @param showSoundFab whether to show the sound fab
* @param showProblemAlertView whether to show the problem alert view
* @param showFeedbackSubmittedAlertView whether to show the feedback submitted alert view
*/
public void setupHiddenViews(boolean showFeedbackFab, boolean showSoundFab, boolean showProblemAlertView,
boolean showFeedbackSubmittedAlertView) {
this.showFeedbackFab = showFeedbackFab;
this.showSoundFab = showSoundFab;
this.showProblemAlertView = showProblemAlertView;
this.showFeedbackSubmittedAlertView = showFeedbackSubmittedAlertView;
}

/**
* Inflates this layout needed for this view and initializes the locale as the device locale.
*/
Expand Down Expand Up @@ -394,6 +419,8 @@ private void bind() {
instructionLayoutText = findViewById(R.id.instructionLayoutText);
instructionListLayout = findViewById(R.id.instructionListLayout);
rvInstructions = findViewById(R.id.rvInstructions);
soundLayout = findViewById(R.id.soundLayout);
feedbackLayout = findViewById(R.id.feedbackLayout);
initializeInstructionAutoSize();
}

Expand Down Expand Up @@ -503,6 +530,10 @@ private void showSoundChip() {
* Show AlertView with "Report Problem" text for 10 seconds - after waiting 2 seconds.
*/
private void showAlertView() {
if (!showProblemAlertView) {
return;
}

final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
Expand Down Expand Up @@ -596,13 +627,18 @@ public void onClick(View view) {
alertView.hide();
}
});
soundFab.setVisibility(VISIBLE);
soundFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
navigationViewModel.setMuted(toggleMute());
}
});

if (showSoundFab) {
setupSoundFab();
}

if (showFeedbackFab) {
setupFeedbackFab();
}
}

private void setupFeedbackFab() {
feedbackLayout.setVisibility(VISIBLE);
feedbackFab.setVisibility(VISIBLE);
feedbackFab.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -613,6 +649,17 @@ public void onClick(View view) {
});
}

private void setupSoundFab() {
soundLayout.setVisibility(VISIBLE);
soundFab.setVisibility(VISIBLE);
soundFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
navigationViewModel.setMuted(toggleMute());
}
});
}

private void initializeStepListClickListener() {
int deviceOrientation = getContext().getResources().getConfiguration().orientation;
boolean isOrientationLandscape = deviceOrientation == Configuration.ORIENTATION_LANDSCAPE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
layout="@layout/sound_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_alignParentEnd="true"
Expand All @@ -73,8 +74,10 @@
layout="@layout/feedback_button_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@id/soundLayout"/>
android:layout_below="@id/soundLayout"
android:layout_alignWithParentIfMissing="true"/>

</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ private NavigationConstants() {
public static final String NAVIGATION_VIEW_ROUTE_PROFILE_KEY = "navigation_view_route_profile";
public static final String NAVIGATION_VIEW_OFF_ROUTE_ENABLED_KEY = "navigation_view_off_route_enabled";
public static final String NAVIGATION_VIEW_SNAP_ENABLED_KEY = "navigation_view_snap_enabled";
public static final String NAVIGATION_VIEW_SHOW_SOUND_FAB = "navigation_view_show_sound_fab";
public static final String NAVIGATION_VIEW_SHOW_FEEDBACK_FAB = "navigation_view_show_feedback_fab";
public static final String NAVIGATION_VIEW_SHOW_PROBLEM_ALERT_VIEW = "navigation_view_show_problem_alert_view";
public static final String
NAVIGATION_VIEW_SHOW_FEEDBACK_SUBMITTED_ALERT_VIEW = "navigation_view_show_feedback_submitted_alert_view";

// Step Maneuver Types
public static final String STEP_MANEUVER_TYPE_TURN = "turn";
Expand Down

0 comments on commit ce8fe34

Please sign in to comment.