Merge branch 'r3.3'

This commit is contained in:
Chumva 2019-03-29 12:15:09 +02:00
commit f4f79c7b68
5 changed files with 379 additions and 313 deletions

View file

@ -302,11 +302,7 @@ public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFr
avoidSpecificRoads.removeImpassableRoad(routeLocation); avoidSpecificRoads.removeImpassableRoad(routeLocation);
} }
RoutingHelper routingHelper = app.getRoutingHelper(); app.getRoutingHelper().recalculateRouteDueToSettingsChange();
if (routingHelper.isRouteCalculated() || routingHelper.isRouteBeingCalculated()) {
routingHelper.recalculateRouteDueToSettingsChange();
}
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
final MapRouteInfoMenu mapRouteInfoMenu = mapActivity.getMapRouteInfoMenu(); final MapRouteInfoMenu mapRouteInfoMenu = mapActivity.getMapRouteInfoMenu();

View file

@ -1,5 +1,6 @@
package net.osmand.plus.routepreparationmenu; package net.osmand.plus.routepreparationmenu;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener; import android.content.DialogInterface.OnDismissListener;
import android.graphics.PointF; import android.graphics.PointF;
@ -59,9 +60,12 @@ import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment; import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment;
import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidPTTypesRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameterGroup; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameterGroup;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.MuteSoundRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.MuteSoundRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.RouteMenuAppModes;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.ShowAlongTheRouteItem; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.ShowAlongTheRouteItem;
import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener; import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
@ -803,57 +807,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
} }
final OsmandApplication app = mapActivity.getMyApplication(); final OsmandApplication app = mapActivity.getMyApplication();
RoutingHelper routingHelper = app.getRoutingHelper(); RoutingHelper routingHelper = app.getRoutingHelper();
final boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
final OsmandSettings settings = app.getSettings();
final int colorActive = ContextCompat.getColor(app, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light);
final int colorDisabled = ContextCompat.getColor(app, R.color.description_font_and_bottom_sheet_icons);
final ApplicationMode applicationMode = routingHelper.getAppMode(); final ApplicationMode applicationMode = routingHelper.getAppMode();
final RoutingOptionsHelper.RouteMenuAppModes mode = app.getRoutingOptionsHelper().modes.get(applicationMode); final RouteMenuAppModes mode = app.getRoutingOptionsHelper().modes.get(applicationMode);
int margin = AndroidUtils.dpToPx(app, 3);
View startButton = mainView.findViewById(R.id.start_button);
TextViewExProgress startButtonText = (TextViewExProgress) mainView.findViewById(R.id.start_button_descr);
boolean publicTransportMode = routingHelper.getAppMode() == ApplicationMode.PUBLIC_TRANSPORT;
int iconId = publicTransportMode ? R.drawable.ic_map : R.drawable.ic_action_start_navigation;
int color;
if (isRouteCalculated()) {
AndroidUtils.setBackground(app, startButton, nightMode, R.color.active_buttons_and_links_light, R.color.active_buttons_and_links_dark);
color = nightMode ? R.color.main_font_dark : R.color.card_and_list_background_light;
} else {
AndroidUtils.setBackground(app, startButton, nightMode, R.color.activity_background_light, R.color.activity_background_dark);
color = R.color.description_font_and_bottom_sheet_icons;
}
startButtonText.color2 = ContextCompat.getColor(app, color);
startButtonText.setCompoundDrawablesWithIntrinsicBounds(app.getUIUtilities().getIcon(iconId, color), null, null, null);
if (publicTransportMode) {
startButtonText.setText(R.string.shared_string_show_on_map);
} else if (routingHelper.isFollowingMode() || routingHelper.isPauseNavigation()) {
startButtonText.setText(R.string.shared_string_continue);
} else {
startButtonText.setText(R.string.shared_string_control_start);
}
startButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
clickRouteGo();
}
});
View cancelButton = mainView.findViewById(R.id.cancel_button);
TextView cancelButtonText = (TextView) mainView.findViewById(R.id.cancel_button_descr);
if (routingHelper.isRouteCalculated() || routingHelper.isRouteBeingCalculated() || isTransportRouteCalculated()) {
cancelButtonText.setText(R.string.shared_string_dismiss);
} else {
cancelButtonText.setText(R.string.shared_string_cancel);
}
AndroidUtils.setBackground(app, cancelButton, nightMode, R.color.card_and_list_background_light, R.color.card_and_list_background_dark);
cancelButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
clickRouteCancel();
}
});
updateControlButtons(mapActivity, mainView);
LinearLayout optionsButton = (LinearLayout) mainView.findViewById(R.id.map_options_route_button); LinearLayout optionsButton = (LinearLayout) mainView.findViewById(R.id.map_options_route_button);
TextView optionsTitle = (TextView) mainView.findViewById(R.id.map_options_route_button_title); TextView optionsTitle = (TextView) mainView.findViewById(R.id.map_options_route_button_title);
ImageView optionsIcon = (ImageView) mainView.findViewById(R.id.map_options_route_button_icon); ImageView optionsIcon = (ImageView) mainView.findViewById(R.id.map_options_route_button_icon);
@ -880,24 +837,92 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
if (mode == null) { if (mode == null) {
return; return;
} }
createRoutingParametersButtons(mapActivity, mode, optionsContainer);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT); int rightPadding = AndroidUtils.dpToPx(app, 70);
LinearLayout.LayoutParams newLp = new LinearLayout.LayoutParams(AndroidUtils.dpToPx(app, 100), ViewGroup.LayoutParams.MATCH_PARENT);
lp.setMargins(margin, 0, margin, 0);
if (mode.parameters.size() > 2) { if (mode.parameters.size() > 2) {
optionsTitle.setVisibility(View.GONE); optionsTitle.setVisibility(View.GONE);
} else { } else {
optionsTitle.setVisibility(View.VISIBLE); optionsTitle.setVisibility(View.VISIBLE);
rightPadding += AndroidUtils.getTextWidth(app.getResources().getDimensionPixelSize(R.dimen.text_button_text_size), app.getString(R.string.shared_string_options));
}
optionsContainer.setPadding(optionsContainer.getPaddingLeft(), optionsContainer.getPaddingTop(), rightPadding, optionsContainer.getPaddingBottom());
} }
for (final RoutingOptionsHelper.LocalRoutingParameter parameter : mode.parameters) { private void updateControlButtons(MapActivity mapActivity, View mainView) {
if (mapActivity == null || mainView == null) {
return;
}
final OsmandApplication app = mapActivity.getMyApplication();
final RoutingHelper helper = app.getRoutingHelper();
View startButton = mainView.findViewById(R.id.start_button);
TextViewExProgress startButtonText = (TextViewExProgress) mainView.findViewById(R.id.start_button_descr);
boolean publicTransportMode = helper.getAppMode() == ApplicationMode.PUBLIC_TRANSPORT;
int iconId = publicTransportMode ? R.drawable.ic_map : R.drawable.ic_action_start_navigation;
int color;
if (isRouteCalculated()) {
AndroidUtils.setBackground(app, startButton, nightMode, R.color.active_buttons_and_links_light, R.color.active_buttons_and_links_dark);
color = nightMode ? R.color.main_font_dark : R.color.card_and_list_background_light;
} else {
AndroidUtils.setBackground(app, startButton, nightMode, R.color.activity_background_light, R.color.activity_background_dark);
color = R.color.description_font_and_bottom_sheet_icons;
}
startButtonText.color2 = ContextCompat.getColor(app, color);
startButtonText.setCompoundDrawablesWithIntrinsicBounds(app.getUIUtilities().getIcon(iconId, color), null, null, null);
if (publicTransportMode) {
startButtonText.setText(R.string.shared_string_show_on_map);
} else if (helper.isFollowingMode() || helper.isPauseNavigation()) {
startButtonText.setText(R.string.shared_string_continue);
} else {
startButtonText.setText(R.string.shared_string_control_start);
}
startButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
clickRouteGo();
}
});
View cancelButton = mainView.findViewById(R.id.cancel_button);
TextView cancelButtonText = (TextView) mainView.findViewById(R.id.cancel_button_descr);
if (helper.isRouteCalculated() || helper.isRouteBeingCalculated() || isTransportRouteCalculated()) {
cancelButtonText.setText(R.string.shared_string_dismiss);
} else {
cancelButtonText.setText(R.string.shared_string_cancel);
}
AndroidUtils.setBackground(app, cancelButton, nightMode, R.color.card_and_list_background_light, R.color.card_and_list_background_dark);
cancelButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
clickRouteCancel();
}
});
}
private void createRoutingParametersButtons(MapActivity mapActivity, final RouteMenuAppModes mode, LinearLayout optionsContainer) {
if (mapActivity == null || optionsContainer == null) {
return;
}
for (final LocalRoutingParameter parameter : mode.parameters) {
if (parameter instanceof MuteSoundRoutingParameter) { if (parameter instanceof MuteSoundRoutingParameter) {
createMuteSoundRoutingParameterButton(mapActivity, (MuteSoundRoutingParameter) parameter, mode, optionsContainer);
} else if (parameter instanceof ShowAlongTheRouteItem) {
createShowAlongTheRouteItems(mapActivity, optionsContainer);
} else if (parameter instanceof AvoidRoadsRoutingParameter || parameter instanceof AvoidPTTypesRoutingParameter) {
createAvoidRoadsRoutingParameterButton(mapActivity, parameter, mode, optionsContainer);
} else if (parameter instanceof LocalRoutingParameterGroup) {
createLocalRoutingParameterGroupButton(mapActivity, parameter, optionsContainer);
} else {
createSimpleRoutingParameterButton(mapActivity, parameter, optionsContainer);
}
}
}
private void createMuteSoundRoutingParameterButton(MapActivity mapActivity, final MuteSoundRoutingParameter parameter, final RouteMenuAppModes mode, LinearLayout optionsContainer) {
final int colorActive = ContextCompat.getColor(mapActivity, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light);
final int colorDisabled = ContextCompat.getColor(mapActivity, R.color.description_font_and_bottom_sheet_icons);
String text = null; String text = null;
final boolean active = !app.getRoutingHelper().getVoiceRouter().isMute(); final boolean active = !mapActivity.getRoutingHelper().getVoiceRouter().isMute();
if (mode.parameters.size() <= 2) { if (mode.parameters.size() <= 2) {
text = app.getString(active ? R.string.shared_string_on : R.string.shared_string_off); text = mapActivity.getString(active ? R.string.shared_string_on : R.string.shared_string_off);
} }
View item = createToolbarOptionView(active, text, parameter.getActiveIconId(), parameter.getDisabledIconId(), new OnClickListener() { View item = createToolbarOptionView(active, text, parameter.getActiveIconId(), parameter.getDisabledIconId(), new OnClickListener() {
@Override @Override
@ -914,7 +939,6 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
if (Build.VERSION.SDK_INT >= 21) { if (Build.VERSION.SDK_INT >= 21) {
itemDrawable = AndroidUtils.createPressedStateListDrawable(itemDrawable, activeItemDrawable); itemDrawable = AndroidUtils.createPressedStateListDrawable(itemDrawable, activeItemDrawable);
} }
((ImageView) v.findViewById(R.id.route_option_image_view)).setImageDrawable(active ? activeItemDrawable : itemDrawable); ((ImageView) v.findViewById(R.id.route_option_image_view)).setImageDrawable(active ? activeItemDrawable : itemDrawable);
((TextView) v.findViewById(R.id.route_option_title)).setText(text); ((TextView) v.findViewById(R.id.route_option_title)).setText(text);
((TextView) v.findViewById(R.id.route_option_title)).setTextColor(active ? colorActive : colorDisabled); ((TextView) v.findViewById(R.id.route_option_title)).setTextColor(active ? colorActive : colorDisabled);
@ -922,13 +946,28 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
} }
}); });
if (item != null) { if (item != null) {
optionsContainer.addView(item, lp); optionsContainer.addView(item, getContainerButtonLayoutParams(mapActivity, true));
} }
} else if (parameter instanceof ShowAlongTheRouteItem) { }
private void createShowAlongTheRouteItems(MapActivity mapActivity, LinearLayout optionsContainer) {
OsmandApplication app = mapActivity.getMyApplication();
final ApplicationMode applicationMode = app.getRoutingHelper().getAppMode();
final Set<PoiUIFilter> poiFilters = app.getPoiFilters().getSelectedPoiFilters(); final Set<PoiUIFilter> poiFilters = app.getPoiFilters().getSelectedPoiFilters();
final boolean traffic = app.getSettings().SHOW_TRAFFIC_WARNINGS.getModeValue(applicationMode); final boolean traffic = app.getSettings().SHOW_TRAFFIC_WARNINGS.getModeValue(applicationMode);
final boolean fav = app.getSettings().SHOW_NEARBY_FAVORITES.getModeValue(applicationMode); final boolean fav = app.getSettings().SHOW_NEARBY_FAVORITES.getModeValue(applicationMode);
if (!poiFilters.isEmpty()) { if (!poiFilters.isEmpty()) {
createPoiFiltersItems(mapActivity, poiFilters, optionsContainer);
}
if (traffic) {
createWaypointItem(mapActivity, optionsContainer, WaypointHelper.ALARMS);
}
if (fav) {
createWaypointItem(mapActivity, optionsContainer, WaypointHelper.FAVORITES);
}
}
private void createPoiFiltersItems(MapActivity mapActivity, Set<PoiUIFilter> poiFilters, LinearLayout optionsContainer) {
LinearLayout item = createToolbarOptionView(false, null, -1, -1, null); LinearLayout item = createToolbarOptionView(false, null, -1, -1, null);
if (item != null) { if (item != null) {
item.findViewById(R.id.route_option_container).setVisibility(View.GONE); item.findViewById(R.id.route_option_container).setVisibility(View.GONE);
@ -947,64 +986,76 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
} }
}); });
if (container != null) { if (container != null) {
item.addView(container, newLp); item.addView(container, getContainerButtonLayoutParams(mapActivity, false));
} }
} }
optionsContainer.addView(item, lp); optionsContainer.addView(item, getContainerButtonLayoutParams(mapActivity, true));
} }
} }
if (traffic) {
private void createWaypointItem(MapActivity mapActivity, LinearLayout optionsContainer, final int waypointType) {
LinearLayout item = createToolbarOptionView(false, null, -1, -1, null); LinearLayout item = createToolbarOptionView(false, null, -1, -1, null);
if (item != null) { if (item != null) {
item.findViewById(R.id.route_option_container).setVisibility(View.GONE); item.findViewById(R.id.route_option_container).setVisibility(View.GONE);
final View container = createToolbarSubOptionView(true, app.getString(R.string.way_alarms), R.drawable.ic_action_remove_dark, true, new OnClickListener() { String title = "";
if (waypointType == WaypointHelper.ALARMS) {
title = mapActivity.getString(R.string.way_alarms);
} else if (waypointType == WaypointHelper.FAVORITES) {
title = mapActivity.getString(R.string.favourites);
}
final View container = createToolbarSubOptionView(true, title, R.drawable.ic_action_remove_dark, true, new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
OsmandApplication app = getApp(); OsmandApplication app = getApp();
if (app != null) { if (app != null) {
app.getWaypointHelper().enableWaypointType(WaypointHelper.ALARMS, false); app.getWaypointHelper().enableWaypointType(waypointType, false);
updateOptionsButtons(); updateOptionsButtons();
} }
} }
}); });
if (container != null) { if (container != null) {
AndroidUtils.setBackground(app, container, nightMode, R.drawable.btn_border_light, R.drawable.btn_border_dark); AndroidUtils.setBackground(app, container, nightMode, R.drawable.btn_border_light, R.drawable.btn_border_dark);
item.addView(container, newLp); item.addView(container, getContainerButtonLayoutParams(mapActivity, false));
optionsContainer.addView(item, lp); optionsContainer.addView(item, getContainerButtonLayoutParams(mapActivity, true));
}
}
}
if (fav) {
LinearLayout item = createToolbarOptionView(false, null, -1, -1, null);
if (item != null) {
item.findViewById(R.id.route_option_container).setVisibility(View.GONE);
final View container = createToolbarSubOptionView(true, app.getString(R.string.favourites), R.drawable.ic_action_remove_dark, true, new OnClickListener() {
@Override
public void onClick(View v) {
OsmandApplication app = getApp();
if (app != null) {
app.getWaypointHelper().enableWaypointType(WaypointHelper.FAVORITES, false);
updateOptionsButtons();
}
}
});
if (container != null) {
AndroidUtils.setBackground(app, container, nightMode, R.drawable.btn_border_light, R.drawable.btn_border_dark);
item.addView(container, newLp);
optionsContainer.addView(item, lp);
} }
} }
} }
} else if (parameter instanceof AvoidRoadsRoutingParameter || parameter instanceof RoutingOptionsHelper.AvoidPTTypesRoutingParameter) { private void createAvoidRoadsRoutingParameterButton(MapActivity mapActivity, final LocalRoutingParameter parameter, final RouteMenuAppModes mode, LinearLayout optionsContainer) {
OsmandApplication app = mapActivity.getMyApplication();
final LinearLayout item = createToolbarOptionView(false, null, -1, -1, null); final LinearLayout item = createToolbarOptionView(false, null, -1, -1, null);
if (item != null) { if (item != null) {
item.findViewById(R.id.route_option_container).setVisibility(View.GONE); item.findViewById(R.id.route_option_container).setVisibility(View.GONE);
Map<LatLon, RouteDataObject> impassableRoads = new TreeMap<>(); Map<LatLon, RouteDataObject> impassableRoads = new TreeMap<>();
if (parameter instanceof AvoidRoadsRoutingParameter) { if (parameter instanceof AvoidRoadsRoutingParameter) {
impassableRoads = app.getAvoidSpecificRoads().getImpassableRoads(); impassableRoads = app.getAvoidSpecificRoads().getImpassableRoads();
} }
final List<RoutingParameter> avoidedParameters = getAvoidedParameters(app);
createImpassableRoadsItems(mapActivity, impassableRoads, parameter, mode, item);
createAvoidParametersItems(mapActivity, avoidedParameters, parameter, mode, item);
if (avoidedParameters.size() > 0 || impassableRoads.size() > 0) {
optionsContainer.addView(item, getContainerButtonLayoutParams(mapActivity, true));
}
}
}
private List<RoutingParameter> getAvoidedParameters(OsmandApplication app) {
final ApplicationMode applicationMode = app.getRoutingHelper().getAppMode();
List<RoutingParameter> avoidParameters = app.getRoutingOptionsHelper().getAvoidRoutingPrefsForAppMode(applicationMode);
final List<RoutingParameter> avoidedParameters = new ArrayList<>();
for (int i = 0; i < avoidParameters.size(); i++) {
RoutingParameter p = avoidParameters.get(i);
CommonPreference<Boolean> preference = app.getSettings().getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean());
if (preference != null && preference.getModeValue(app.getRoutingHelper().getAppMode())) {
avoidedParameters.add(p);
}
}
return avoidedParameters;
}
private void createImpassableRoadsItems(MapActivity mapActivity, Map<LatLon, RouteDataObject> impassableRoads, final LocalRoutingParameter parameter, final RouteMenuAppModes mode, final LinearLayout item) {
OsmandApplication app = mapActivity.getMyApplication();
Iterator<RouteDataObject> it = impassableRoads.values().iterator(); Iterator<RouteDataObject> it = impassableRoads.values().iterator();
while (it.hasNext()) { while (it.hasNext()) {
final RouteDataObject routeDataObject = it.next(); final RouteDataObject routeDataObject = it.next();
@ -1018,10 +1069,8 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
if (routeDataObject != null) { if (routeDataObject != null) {
app.getAvoidSpecificRoads().removeImpassableRoad(routeDataObject); app.getAvoidSpecificRoads().removeImpassableRoad(routeDataObject);
} }
if (routingHelper.isRouteCalculated() || routingHelper.isRouteBeingCalculated()) {
routingHelper.recalculateRouteDueToSettingsChange(); routingHelper.recalculateRouteDueToSettingsChange();
} if (app.getAvoidSpecificRoads().getImpassableRoads().isEmpty() && getAvoidedParameters(app).isEmpty()) {
if (app.getAvoidSpecificRoads().getImpassableRoads().isEmpty()) {
mode.parameters.remove(parameter); mode.parameters.remove(parameter);
} }
mapActivity.getMapView().refreshMap(); mapActivity.getMapView().refreshMap();
@ -1034,28 +1083,27 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
} }
}); });
if (container != null) { if (container != null) {
item.addView(container, newLp); item.addView(container, getContainerButtonLayoutParams(mapActivity, false));
}
} }
} }
List<RoutingParameter> avoidParameters = app.getRoutingOptionsHelper().getAvoidRoutingPrefsForAppMode(applicationMode); private void createAvoidParametersItems(MapActivity mapActivity, final List<RoutingParameter> avoidedParameters, final LocalRoutingParameter parameter, final RouteMenuAppModes mode, final LinearLayout item) {
final List<RoutingParameter> avoidedParameters = new ArrayList<>(); final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
for (int i = 0; i < avoidParameters.size(); i++) {
RoutingParameter p = avoidParameters.get(i);
CommonPreference<Boolean> preference = settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean());
if (preference != null && preference.getModeValue(app.getRoutingHelper().getAppMode())) {
avoidedParameters.add(p);
}
}
for (int i = 0; i < avoidedParameters.size(); i++) { for (int i = 0; i < avoidedParameters.size(); i++) {
final RoutingParameter routingParameter = avoidedParameters.get(i); final RoutingParameter routingParameter = avoidedParameters.get(i);
final View container = createToolbarSubOptionView(false, SettingsBaseActivity.getRoutingStringPropertyName(app, routingParameter.getId(), routingParameter.getName()), R.drawable.ic_action_remove_dark, i == avoidedParameters.size() - 1, new OnClickListener() { final View container = createToolbarSubOptionView(false, SettingsBaseActivity.getRoutingStringPropertyName(app, routingParameter.getId(), routingParameter.getName()), R.drawable.ic_action_remove_dark, i == avoidedParameters.size() - 1, new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
OsmandApplication app = getApp();
if (app == null) {
return;
}
CommonPreference<Boolean> preference = settings.getCustomRoutingBooleanProperty(routingParameter.getId(), routingParameter.getDefaultBoolean()); CommonPreference<Boolean> preference = settings.getCustomRoutingBooleanProperty(routingParameter.getId(), routingParameter.getDefaultBoolean());
preference.setModeValue(app.getRoutingHelper().getAppMode(), false); preference.setModeValue(app.getRoutingHelper().getAppMode(), false);
avoidedParameters.remove(routingParameter); avoidedParameters.remove(routingParameter);
if (avoidedParameters.isEmpty()) { app.getRoutingHelper().recalculateRouteDueToSettingsChange();
if (app.getAvoidSpecificRoads().getImpassableRoads().isEmpty() && avoidedParameters.isEmpty()) {
mode.parameters.remove(parameter); mode.parameters.remove(parameter);
} }
if (mode.parameters.size() > 2) { if (mode.parameters.size() > 2) {
@ -1066,17 +1114,16 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
} }
}); });
if (container != null) { if (container != null) {
item.addView(container, newLp); item.addView(container, getContainerButtonLayoutParams(mapActivity, false));
} }
} }
if(avoidedParameters.size() > 0 || impassableRoads.size() > 0) {
optionsContainer.addView(item, lp);
} }
}
} else if (parameter instanceof LocalRoutingParameterGroup) { private void createLocalRoutingParameterGroupButton(MapActivity mapActivity, final LocalRoutingParameter parameter, LinearLayout optionsContainer) {
final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
final LocalRoutingParameterGroup group = (LocalRoutingParameterGroup) parameter; final LocalRoutingParameterGroup group = (LocalRoutingParameterGroup) parameter;
String text = null; String text = null;
RoutingOptionsHelper.LocalRoutingParameter selected = group.getSelected(settings); LocalRoutingParameter selected = group.getSelected(settings);
if (selected != null) { if (selected != null) {
text = group.getText(mapActivity); text = group.getText(mapActivity);
} }
@ -1095,9 +1142,17 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
} }
}); });
if (item != null) { if (item != null) {
optionsContainer.addView(item, lp); optionsContainer.addView(item, getContainerButtonLayoutParams(mapActivity, true));
} }
} else { }
private void createSimpleRoutingParameterButton(MapActivity mapActivity, final LocalRoutingParameter parameter, LinearLayout optionsContainer) {
OsmandApplication app = mapActivity.getMyApplication();
RoutingHelper routingHelper = app.getRoutingHelper();
final int colorActive = ContextCompat.getColor(app, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light);
final int colorDisabled = ContextCompat.getColor(app, R.color.description_font_and_bottom_sheet_icons);
int margin = AndroidUtils.dpToPx(app, 3);
final OsmandSettings settings = app.getSettings();
String text; String text;
boolean active; boolean active;
if (parameter.routingParameter != null) { if (parameter.routingParameter != null) {
@ -1128,18 +1183,22 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
} }
}); });
if (item != null) { if (item != null) {
LinearLayout.LayoutParams newLp2 = new LinearLayout.LayoutParams(AndroidUtils.dpToPx(app, 100), ViewGroup.LayoutParams.MATCH_PARENT); LinearLayout.LayoutParams layoutParams = getContainerButtonLayoutParams(mapActivity, false);
newLp2.setMargins(margin, 0, margin, 0); layoutParams.setMargins(margin, 0, margin, 0);
optionsContainer.addView(item, newLp2); optionsContainer.addView(item, layoutParams);
} }
} }
} }
private LinearLayout.LayoutParams getContainerButtonLayoutParams(Context context, boolean containerParams) {
if (containerParams) {
int margin = AndroidUtils.dpToPx(context, 3);
LinearLayout.LayoutParams containerBtnLp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
containerBtnLp.setMargins(margin, 0, margin, 0);
return containerBtnLp;
} else {
return new LinearLayout.LayoutParams(AndroidUtils.dpToPx(context, 100), ViewGroup.LayoutParams.MATCH_PARENT);
} }
int rightPadding = AndroidUtils.dpToPx(app, 70);
if (optionsTitle.getVisibility() == View.VISIBLE) {
rightPadding += AndroidUtils.getTextWidth(app.getResources().getDimensionPixelSize(R.dimen.text_button_text_size), app.getString(R.string.shared_string_options));
}
optionsContainer.setPadding(optionsContainer.getPaddingLeft(), optionsContainer.getPaddingTop(), rightPadding, optionsContainer.getPaddingBottom());
} }
@Nullable @Nullable

View file

@ -460,6 +460,17 @@ public class ShowAlongTheRouteBottomSheet extends MenuBottomSheetDialogFragment
} }
} }
private MapActivity getMapActivity() {
return (MapActivity) getActivity();
}
private void updateMenu() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.getMapRouteInfoMenu().updateMenu();
}
}
protected void selectDifferentRadius(final int type) { protected void selectDifferentRadius(final int type) {
int length = WaypointHelper.SEARCH_RADIUS_VALUES.length; int length = WaypointHelper.SEARCH_RADIUS_VALUES.length;
String[] names = new String[length]; String[] names = new String[length];
@ -548,6 +559,7 @@ public class ShowAlongTheRouteBottomSheet extends MenuBottomSheetDialogFragment
ShowAlongTheRouteBottomSheet fragment = fragmentRef.get(); ShowAlongTheRouteBottomSheet fragment = fragmentRef.get();
if (fragment != null && fragment.isAdded()) { if (fragment != null && fragment.isAdded()) {
fragment.updateAdapter(); fragment.updateAdapter();
fragment.updateMenu();
} }
} }
} }

View file

@ -2,7 +2,6 @@ package net.osmand.plus.routepreparationmenu.cards;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.view.MotionEvent; import android.view.MotionEvent;
@ -72,7 +71,7 @@ public class RouteStatisticCard extends BaseCard {
SpannableStringBuilder distanceStr = new SpannableStringBuilder(text); SpannableStringBuilder distanceStr = new SpannableStringBuilder(text);
int spaceIndex = text.indexOf(" "); int spaceIndex = text.indexOf(" ");
if (spaceIndex != -1) { if (spaceIndex != -1) {
distanceStr.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.primary_text_dark : R.color.primary_text_light)), 0, spaceIndex, 0); distanceStr.setSpan(new ForegroundColorSpan(getMainFontColor()), 0, spaceIndex, 0);
} }
distanceTv.setText(distanceStr); distanceTv.setText(distanceStr);
SpannableStringBuilder timeStr = new SpannableStringBuilder(); SpannableStringBuilder timeStr = new SpannableStringBuilder();
@ -84,7 +83,7 @@ public class RouteStatisticCard extends BaseCard {
} }
spaceIndex = timeStr.toString().lastIndexOf(" "); spaceIndex = timeStr.toString().lastIndexOf(" ");
if (spaceIndex != -1) { if (spaceIndex != -1) {
timeStr.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.primary_text_dark : R.color.primary_text_light)), 0, spaceIndex, 0); timeStr.setSpan(new ForegroundColorSpan(getMainFontColor()), 0, spaceIndex, 0);
} }
TextView timeTv = (TextView) view.findViewById(R.id.time); TextView timeTv = (TextView) view.findViewById(R.id.time);
timeTv.setText(timeStr); timeTv.setText(timeStr);

View file

@ -53,7 +53,7 @@ public class WarningCard extends BaseCard {
@Override @Override
public void onClick(@NonNull View widget) { public void onClick(@NonNull View widget) {
WikipediaDialogFragment.showFullArticle(app, Uri.parse(OSMAND_BLOG_LINK), nightMode); WikipediaDialogFragment.showFullArticle(mapActivity, Uri.parse(OSMAND_BLOG_LINK), nightMode);
} }
}; };
int startIndex = text.lastIndexOf(" "); int startIndex = text.lastIndexOf(" ");