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,271 +837,373 @@ 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);
}
for (final RoutingOptionsHelper.LocalRoutingParameter parameter : mode.parameters) {
if (parameter instanceof MuteSoundRoutingParameter) {
String text = null;
final boolean active = !app.getRoutingHelper().getVoiceRouter().isMute();
if (mode.parameters.size() <= 2) {
text = app.getString(active ? R.string.shared_string_on : R.string.shared_string_off);
}
View item = createToolbarOptionView(active, text, parameter.getActiveIconId(), parameter.getDisabledIconId(), new OnClickListener() {
@Override
public void onClick(View v) {
OsmandApplication app = getApp();
if (app != null) {
app.getRoutingOptionsHelper().switchSound();
boolean active = !app.getRoutingHelper().getVoiceRouter().isMute();
String text = app.getString(active ? R.string.shared_string_on : R.string.shared_string_off);
Drawable itemDrawable = app.getUIUtilities().getIcon(active ? parameter.getActiveIconId() : parameter.getDisabledIconId(), nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light);
Drawable activeItemDrawable = app.getUIUtilities().getIcon(active ? parameter.getActiveIconId() : parameter.getDisabledIconId(), nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light);
if (Build.VERSION.SDK_INT >= 21) {
itemDrawable = AndroidUtils.createPressedStateListDrawable(itemDrawable, activeItemDrawable);
}
((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)).setTextColor(active ? colorActive : colorDisabled);
}
}
});
if (item != null) {
optionsContainer.addView(item, lp);
}
} else if (parameter instanceof ShowAlongTheRouteItem) {
final Set<PoiUIFilter> poiFilters = app.getPoiFilters().getSelectedPoiFilters();
final boolean traffic = app.getSettings().SHOW_TRAFFIC_WARNINGS.getModeValue(applicationMode);
final boolean fav = app.getSettings().SHOW_NEARBY_FAVORITES.getModeValue(applicationMode);
if (!poiFilters.isEmpty()) {
LinearLayout item = createToolbarOptionView(false, null, -1, -1, null);
if (item != null) {
item.findViewById(R.id.route_option_container).setVisibility(View.GONE);
Iterator<PoiUIFilter> it = poiFilters.iterator();
while (it.hasNext()) {
final PoiUIFilter poiUIFilter = it.next();
final View container = createToolbarSubOptionView(true, poiUIFilter.getName(), R.drawable.ic_action_remove_dark, !it.hasNext(), new OnClickListener() {
@Override
public void onClick(View v) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.getMyApplication().getPoiFilters().removeSelectedPoiFilter(poiUIFilter);
mapActivity.getMapView().refreshMap();
updateOptionsButtons();
}
}
});
if (container != null) {
item.addView(container, newLp);
}
}
optionsContainer.addView(item, lp);
}
}
if (traffic) {
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.way_alarms), 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.ALARMS, 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);
}
}
}
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) {
final LinearLayout item = createToolbarOptionView(false, null, -1, -1, null);
if (item != null) {
item.findViewById(R.id.route_option_container).setVisibility(View.GONE);
Map<LatLon, RouteDataObject> impassableRoads = new TreeMap<>();
if (parameter instanceof AvoidRoadsRoutingParameter) {
impassableRoads = app.getAvoidSpecificRoads().getImpassableRoads();
}
Iterator<RouteDataObject> it = impassableRoads.values().iterator();
while (it.hasNext()) {
final RouteDataObject routeDataObject = it.next();
final View container = createToolbarSubOptionView(false, app.getAvoidSpecificRoads().getText(routeDataObject), R.drawable.ic_action_remove_dark, !it.hasNext(), new OnClickListener() {
@Override
public void onClick(View v) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
OsmandApplication app = mapActivity.getMyApplication();
RoutingHelper routingHelper = app.getRoutingHelper();
if (routeDataObject != null) {
app.getAvoidSpecificRoads().removeImpassableRoad(routeDataObject);
}
if (routingHelper.isRouteCalculated() || routingHelper.isRouteBeingCalculated()) {
routingHelper.recalculateRouteDueToSettingsChange();
}
if (app.getAvoidSpecificRoads().getImpassableRoads().isEmpty()) {
mode.parameters.remove(parameter);
}
mapActivity.getMapView().refreshMap();
if (mode.parameters.size() > 2) {
item.removeView(v);
} else {
updateOptionsButtons();
}
}
}
});
if (container != null) {
item.addView(container, newLp);
}
}
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 = 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++) {
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() {
@Override
public void onClick(View v) {
CommonPreference<Boolean> preference = settings.getCustomRoutingBooleanProperty(routingParameter.getId(), routingParameter.getDefaultBoolean());
preference.setModeValue(app.getRoutingHelper().getAppMode(), false);
avoidedParameters.remove(routingParameter);
if (avoidedParameters.isEmpty()) {
mode.parameters.remove(parameter);
}
if (mode.parameters.size() > 2) {
item.removeView(v);
} else {
updateOptionsButtons();
}
}
});
if (container != null) {
item.addView(container, newLp);
}
}
if(avoidedParameters.size() > 0 || impassableRoads.size() > 0) {
optionsContainer.addView(item, lp);
}
}
} else if (parameter instanceof LocalRoutingParameterGroup) {
final LocalRoutingParameterGroup group = (LocalRoutingParameterGroup) parameter;
String text = null;
RoutingOptionsHelper.LocalRoutingParameter selected = group.getSelected(settings);
if (selected != null) {
text = group.getText(mapActivity);
}
View item = createToolbarOptionView(false, text, parameter.getActiveIconId(), parameter.getDisabledIconId(), new OnClickListener() {
@Override
public void onClick(View v) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.getMyApplication().getRoutingOptionsHelper().showLocalRoutingParameterGroupDialog(group, mapActivity, new RoutingOptionsHelper.OnClickListener() {
@Override
public void onClick() {
updateOptionsButtons();
}
});
}
}
});
if (item != null) {
optionsContainer.addView(item, lp);
}
} else {
String text;
boolean active;
if (parameter.routingParameter != null) {
if (parameter.routingParameter.getId().equals(GeneralRouter.USE_SHORTEST_WAY)) {
// if short route settings - it should be inverse of fast_route_mode
active = !settings.FAST_ROUTE_MODE.getModeValue(routingHelper.getAppMode());
} else {
active = parameter.isSelected(settings);
}
text = parameter.getText(mapActivity);
View item = createToolbarOptionView(active, text, parameter.getActiveIconId(), parameter.getDisabledIconId(), new OnClickListener() {
@Override
public void onClick(View v) {
OsmandApplication app = getApp();
if (parameter.routingParameter != null && app != null) {
boolean selected = !parameter.isSelected(settings);
app.getRoutingOptionsHelper().applyRoutingParameter(parameter, selected);
Drawable itemDrawable = app.getUIUtilities().getIcon(selected ? parameter.getActiveIconId() : parameter.getDisabledIconId(), nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light);
Drawable activeItemDrawable = app.getUIUtilities().getIcon(selected ? parameter.getActiveIconId() : parameter.getDisabledIconId(), nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light);
if (Build.VERSION.SDK_INT >= 21) {
itemDrawable = AndroidUtils.createPressedStateListDrawable(itemDrawable, activeItemDrawable);
}
((ImageView) v.findViewById(R.id.route_option_image_view)).setImageDrawable(selected ? activeItemDrawable : itemDrawable);
((TextView) v.findViewById(R.id.route_option_title)).setTextColor(selected ? colorActive : colorDisabled);
}
}
});
if (item != null) {
LinearLayout.LayoutParams newLp2 = new LinearLayout.LayoutParams(AndroidUtils.dpToPx(app, 100), ViewGroup.LayoutParams.MATCH_PARENT);
newLp2.setMargins(margin, 0, margin, 0);
optionsContainer.addView(item, newLp2);
}
}
}
}
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)); 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()); optionsContainer.setPadding(optionsContainer.getPaddingLeft(), optionsContainer.getPaddingTop(), rightPadding, optionsContainer.getPaddingBottom());
} }
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) {
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;
final boolean active = !mapActivity.getRoutingHelper().getVoiceRouter().isMute();
if (mode.parameters.size() <= 2) {
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() {
@Override
public void onClick(View v) {
OsmandApplication app = getApp();
if (app != null) {
app.getRoutingOptionsHelper().switchSound();
boolean active = !app.getRoutingHelper().getVoiceRouter().isMute();
String text = app.getString(active ? R.string.shared_string_on : R.string.shared_string_off);
Drawable itemDrawable = app.getUIUtilities().getIcon(active ? parameter.getActiveIconId() : parameter.getDisabledIconId(), nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light);
Drawable activeItemDrawable = app.getUIUtilities().getIcon(active ? parameter.getActiveIconId() : parameter.getDisabledIconId(), nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light);
if (Build.VERSION.SDK_INT >= 21) {
itemDrawable = AndroidUtils.createPressedStateListDrawable(itemDrawable, activeItemDrawable);
}
((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)).setTextColor(active ? colorActive : colorDisabled);
}
}
});
if (item != null) {
optionsContainer.addView(item, getContainerButtonLayoutParams(mapActivity, true));
}
}
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 boolean traffic = app.getSettings().SHOW_TRAFFIC_WARNINGS.getModeValue(applicationMode);
final boolean fav = app.getSettings().SHOW_NEARBY_FAVORITES.getModeValue(applicationMode);
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);
if (item != null) {
item.findViewById(R.id.route_option_container).setVisibility(View.GONE);
Iterator<PoiUIFilter> it = poiFilters.iterator();
while (it.hasNext()) {
final PoiUIFilter poiUIFilter = it.next();
final View container = createToolbarSubOptionView(true, poiUIFilter.getName(), R.drawable.ic_action_remove_dark, !it.hasNext(), new OnClickListener() {
@Override
public void onClick(View v) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.getMyApplication().getPoiFilters().removeSelectedPoiFilter(poiUIFilter);
mapActivity.getMapView().refreshMap();
updateOptionsButtons();
}
}
});
if (container != null) {
item.addView(container, getContainerButtonLayoutParams(mapActivity, false));
}
}
optionsContainer.addView(item, getContainerButtonLayoutParams(mapActivity, true));
}
}
private void createWaypointItem(MapActivity mapActivity, LinearLayout optionsContainer, final int waypointType) {
LinearLayout item = createToolbarOptionView(false, null, -1, -1, null);
if (item != null) {
item.findViewById(R.id.route_option_container).setVisibility(View.GONE);
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
public void onClick(View v) {
OsmandApplication app = getApp();
if (app != null) {
app.getWaypointHelper().enableWaypointType(waypointType, false);
updateOptionsButtons();
}
}
});
if (container != null) {
AndroidUtils.setBackground(app, container, nightMode, R.drawable.btn_border_light, R.drawable.btn_border_dark);
item.addView(container, getContainerButtonLayoutParams(mapActivity, false));
optionsContainer.addView(item, getContainerButtonLayoutParams(mapActivity, true));
}
}
}
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);
if (item != null) {
item.findViewById(R.id.route_option_container).setVisibility(View.GONE);
Map<LatLon, RouteDataObject> impassableRoads = new TreeMap<>();
if (parameter instanceof AvoidRoadsRoutingParameter) {
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();
while (it.hasNext()) {
final RouteDataObject routeDataObject = it.next();
final View container = createToolbarSubOptionView(false, app.getAvoidSpecificRoads().getText(routeDataObject), R.drawable.ic_action_remove_dark, !it.hasNext(), new OnClickListener() {
@Override
public void onClick(View v) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
OsmandApplication app = mapActivity.getMyApplication();
RoutingHelper routingHelper = app.getRoutingHelper();
if (routeDataObject != null) {
app.getAvoidSpecificRoads().removeImpassableRoad(routeDataObject);
}
routingHelper.recalculateRouteDueToSettingsChange();
if (app.getAvoidSpecificRoads().getImpassableRoads().isEmpty() && getAvoidedParameters(app).isEmpty()) {
mode.parameters.remove(parameter);
}
mapActivity.getMapView().refreshMap();
if (mode.parameters.size() > 2) {
item.removeView(v);
} else {
updateOptionsButtons();
}
}
}
});
if (container != null) {
item.addView(container, getContainerButtonLayoutParams(mapActivity, false));
}
}
}
private void createAvoidParametersItems(MapActivity mapActivity, final List<RoutingParameter> avoidedParameters, final LocalRoutingParameter parameter, final RouteMenuAppModes mode, final LinearLayout item) {
final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
for (int i = 0; i < avoidedParameters.size(); 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() {
@Override
public void onClick(View v) {
OsmandApplication app = getApp();
if (app == null) {
return;
}
CommonPreference<Boolean> preference = settings.getCustomRoutingBooleanProperty(routingParameter.getId(), routingParameter.getDefaultBoolean());
preference.setModeValue(app.getRoutingHelper().getAppMode(), false);
avoidedParameters.remove(routingParameter);
app.getRoutingHelper().recalculateRouteDueToSettingsChange();
if (app.getAvoidSpecificRoads().getImpassableRoads().isEmpty() && avoidedParameters.isEmpty()) {
mode.parameters.remove(parameter);
}
if (mode.parameters.size() > 2) {
item.removeView(v);
} else {
updateOptionsButtons();
}
}
});
if (container != null) {
item.addView(container, getContainerButtonLayoutParams(mapActivity, false));
}
}
}
private void createLocalRoutingParameterGroupButton(MapActivity mapActivity, final LocalRoutingParameter parameter, LinearLayout optionsContainer) {
final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
final LocalRoutingParameterGroup group = (LocalRoutingParameterGroup) parameter;
String text = null;
LocalRoutingParameter selected = group.getSelected(settings);
if (selected != null) {
text = group.getText(mapActivity);
}
View item = createToolbarOptionView(false, text, parameter.getActiveIconId(), parameter.getDisabledIconId(), new OnClickListener() {
@Override
public void onClick(View v) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.getMyApplication().getRoutingOptionsHelper().showLocalRoutingParameterGroupDialog(group, mapActivity, new RoutingOptionsHelper.OnClickListener() {
@Override
public void onClick() {
updateOptionsButtons();
}
});
}
}
});
if (item != null) {
optionsContainer.addView(item, getContainerButtonLayoutParams(mapActivity, true));
}
}
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;
boolean active;
if (parameter.routingParameter != null) {
if (parameter.routingParameter.getId().equals(GeneralRouter.USE_SHORTEST_WAY)) {
// if short route settings - it should be inverse of fast_route_mode
active = !settings.FAST_ROUTE_MODE.getModeValue(routingHelper.getAppMode());
} else {
active = parameter.isSelected(settings);
}
text = parameter.getText(mapActivity);
View item = createToolbarOptionView(active, text, parameter.getActiveIconId(), parameter.getDisabledIconId(), new OnClickListener() {
@Override
public void onClick(View v) {
OsmandApplication app = getApp();
if (parameter.routingParameter != null && app != null) {
boolean selected = !parameter.isSelected(settings);
app.getRoutingOptionsHelper().applyRoutingParameter(parameter, selected);
Drawable itemDrawable = app.getUIUtilities().getIcon(selected ? parameter.getActiveIconId() : parameter.getDisabledIconId(), nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light);
Drawable activeItemDrawable = app.getUIUtilities().getIcon(selected ? parameter.getActiveIconId() : parameter.getDisabledIconId(), nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light);
if (Build.VERSION.SDK_INT >= 21) {
itemDrawable = AndroidUtils.createPressedStateListDrawable(itemDrawable, activeItemDrawable);
}
((ImageView) v.findViewById(R.id.route_option_image_view)).setImageDrawable(selected ? activeItemDrawable : itemDrawable);
((TextView) v.findViewById(R.id.route_option_title)).setTextColor(selected ? colorActive : colorDisabled);
}
}
});
if (item != null) {
LinearLayout.LayoutParams layoutParams = getContainerButtonLayoutParams(mapActivity, false);
layoutParams.setMargins(margin, 0, margin, 0);
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);
}
}
@Nullable @Nullable
private LinearLayout createToolbarOptionView(boolean active, String title, @DrawableRes int activeIconId, private LinearLayout createToolbarOptionView(boolean active, String title, @DrawableRes int activeIconId,
@DrawableRes int disabledIconId, OnClickListener listener) { @DrawableRes int disabledIconId, OnClickListener listener) {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity == null) { if (mapActivity == null) {
return null; return null;
@ -1196,7 +1255,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
@Nullable @Nullable
private View createToolbarSubOptionView(boolean hideTextLine, String title, @DrawableRes int iconId, private View createToolbarSubOptionView(boolean hideTextLine, String title, @DrawableRes int iconId,
boolean lastItem, OnClickListener listener) { boolean lastItem, OnClickListener listener) {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity == null) { if (mapActivity == null) {
return null; return null;

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(" ");