diff --git a/OsmAnd/res/drawable-large-hdpi/map_start_navigation.png b/OsmAnd/res/drawable-large-hdpi/map_start_navigation.png index 7b07628242..3e784bf91e 100644 Binary files a/OsmAnd/res/drawable-large-hdpi/map_start_navigation.png and b/OsmAnd/res/drawable-large-hdpi/map_start_navigation.png differ diff --git a/OsmAnd/res/drawable-large-xhdpi/map_start_navigation.png b/OsmAnd/res/drawable-large-xhdpi/map_start_navigation.png index b76cb43c4a..ee62bbac20 100644 Binary files a/OsmAnd/res/drawable-large-xhdpi/map_start_navigation.png and b/OsmAnd/res/drawable-large-xhdpi/map_start_navigation.png differ diff --git a/OsmAnd/res/drawable-large/map_start_navigation.png b/OsmAnd/res/drawable-large/map_start_navigation.png index f118034580..9ab5382df1 100644 Binary files a/OsmAnd/res/drawable-large/map_start_navigation.png and b/OsmAnd/res/drawable-large/map_start_navigation.png differ diff --git a/OsmAnd/res/layout/bottom_sheet_item_btn.xml b/OsmAnd/res/layout/bottom_sheet_item_btn.xml new file mode 100644 index 0000000000..8664423c6e --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_btn.xml @@ -0,0 +1,38 @@ + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/bottom_sheet_item_simple_right_icon.xml b/OsmAnd/res/layout/bottom_sheet_item_simple_right_icon.xml new file mode 100644 index 0000000000..1a74dd281a --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_simple_right_icon.xml @@ -0,0 +1,36 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/bottom_sheet_item_title_long.xml b/OsmAnd/res/layout/bottom_sheet_item_title_long.xml new file mode 100644 index 0000000000..749f155f79 --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_title_long.xml @@ -0,0 +1,13 @@ + + \ No newline at end of file diff --git a/OsmAnd/res/layout/bottom_sheet_item_toolbar_title.xml b/OsmAnd/res/layout/bottom_sheet_item_toolbar_title.xml new file mode 100644 index 0000000000..98fdf1267a --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_toolbar_title.xml @@ -0,0 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/bottom_sheet_item_with_switch_no_icon.xml b/OsmAnd/res/layout/bottom_sheet_item_with_switch_no_icon.xml new file mode 100644 index 0000000000..c9b104fcad --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_with_switch_no_icon.xml @@ -0,0 +1,34 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 97f60153e1..c303adf04e 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -10,6 +10,7 @@ - For wording and consistency, please note https://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience Thx - Hardy --> + Select road on the map or from the list below that you want to avoid during navigation: Show along the route Simulate navigation Choose track file to follow diff --git a/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java b/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java index ce439474e8..3145a8b315 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java +++ b/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java @@ -101,7 +101,7 @@ public class AvoidSpecificRoads { return OsmAndFormatter.getFormattedDistance((float) dist, app); } - private String getText(@Nullable LatLon point) { + public String getText(@Nullable LatLon point) { if (point != null) { RouteDataObject obj = impassableRoads.get(point); if (obj != null) { @@ -121,6 +121,23 @@ public class AvoidSpecificRoads { return app.getString(R.string.shared_string_road); } + public String getText(@Nullable RouteDataObject obj) { + if (obj != null) { + String locale = app.getSettings().MAP_PREFERRED_LOCALE.get(); + boolean transliterate = app.getSettings().MAP_TRANSLITERATE_NAMES.get(); + String name = RoutingHelper.formatStreetName( + obj.getName(locale, transliterate), + obj.getRef(locale, transliterate, true), + obj.getDestinationName(locale, transliterate, true), + app.getString(R.string.towards) + ); + if (!TextUtils.isEmpty(name)) { + return name; + } + } + return app.getString(R.string.shared_string_road); + } + private void recalculateRoute() { RoutingHelper rh = app.getRoutingHelper(); if (rh.isRouteCalculated() || rh.isRouteBeingCalculated()) { @@ -128,7 +145,7 @@ public class AvoidSpecificRoads { } } - private void removeImpassableRoad(LatLon latLon) { + public void removeImpassableRoad(LatLon latLon) { app.getSettings().removeImpassableRoad(latLon); RouteDataObject obj = impassableRoads.remove(latLon); if (obj != null) { diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AvoidRoadsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AvoidRoadsBottomSheetDialogFragment.java new file mode 100644 index 0000000000..e3bd6533f8 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AvoidRoadsBottomSheetDialogFragment.java @@ -0,0 +1,296 @@ +package net.osmand.plus.routepreparationmenu; + +import android.app.Activity; +import android.content.Context; +import android.os.Build; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.support.v7.widget.Toolbar; +import android.view.ContextThemeWrapper; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import net.osmand.AndroidUtils; +import net.osmand.data.LatLon; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.SettingsBaseActivity; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.SubtitleDividerItem; +import net.osmand.plus.dashboard.DashboardOnMap; +import net.osmand.plus.helpers.AvoidSpecificRoads; +import net.osmand.plus.routing.RoutingHelper; +import net.osmand.router.GeneralRouter; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { + + public static final String TAG = AvoidRoadsBottomSheetDialogFragment.class.getSimpleName(); + + public static final int REQUEST_CODE = 0; + public static final int OPEN_AVOID_ROADS_DIALOG_REQUEST_CODE = 1; + + private static final String AVOID_ROADS_TYPES_KEY = "avoid_roads_types"; + private static final String AVOID_ROADS_OBJECTS_KEY = "avoid_roads_objects"; + + private HashMap routingParametersMap; + private List removedImpassableRoads; + private LinearLayout stylesContainer; + + List compoundButtons = new ArrayList<>(); + + @Override + public void createMenuItems(Bundle savedInstanceState) { + final OsmandApplication app = getMyApplication(); + if (app == null) { + return; + } + if (savedInstanceState != null) { + if (savedInstanceState.containsKey(AVOID_ROADS_TYPES_KEY)) { + routingParametersMap = (HashMap) savedInstanceState.getSerializable(AVOID_ROADS_TYPES_KEY); + } + if (savedInstanceState.containsKey(AVOID_ROADS_OBJECTS_KEY)) { + removedImpassableRoads = (List) savedInstanceState.getSerializable(AVOID_ROADS_OBJECTS_KEY); + } + } + if (routingParametersMap == null) { + routingParametersMap = generateStylesMap(app); + } + if (removedImpassableRoads == null) { + removedImpassableRoads = new ArrayList(); + } + + final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + final View titleView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.bottom_sheet_item_toolbar_title, null); + TextView textView = (TextView) titleView.findViewById(R.id.title); + textView.setText(R.string.impassable_road); + + Toolbar toolbar = (Toolbar) titleView.findViewById(R.id.toolbar); + toolbar.setNavigationIcon(getContentIcon(R.drawable.ic_arrow_back)); + toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up); + toolbar.setNavigationOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + dismiss(); + } + }); + + final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() + .setCustomView(titleView) + .create(); + items.add(titleItem); + + final SimpleBottomSheetItem descriptionItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() + .setTitle(getString(R.string.avoid_roads_descr)) + .setLayoutId(R.layout.bottom_sheet_item_title_long) + .create(); + items.add(descriptionItem); + + stylesContainer = new LinearLayout(app); + stylesContainer.setLayoutParams((new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT))); + stylesContainer.setOrientation(LinearLayout.VERTICAL); + stylesContainer.setPadding(0, getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small), 0, 0); + + for (final LatLon routeDataObject : app.getAvoidSpecificRoads().getImpassableRoads().keySet()) { + if (removedImpassableRoads.contains(routeDataObject)) { + continue; + } + LayoutInflater.from(new ContextThemeWrapper(app, themeRes)).inflate(R.layout.bottom_sheet_item_simple_right_icon, stylesContainer, true); + } + items.add(new BaseBottomSheetItem.Builder().setCustomView(stylesContainer).create()); + + populateImpassableRoadsObjects(); + + final View buttonView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.bottom_sheet_item_btn, null); + TextView buttonDescription = (TextView) buttonView.findViewById(R.id.button_descr); + buttonDescription.setText(R.string.shared_string_select_on_map); + buttonDescription.setTextColor(getResolvedColor(nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light)); + + FrameLayout buttonContainer = buttonView.findViewById(R.id.button_container); + AndroidUtils.setBackground(app, buttonContainer, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark); + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { + AndroidUtils.setBackground(app, buttonDescription, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); + } + + buttonContainer.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.getDashboard().setDashboardVisibility(false, DashboardOnMap.DashboardType.ROUTE_PREFERENCES); + mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().hide(); + app.getAvoidSpecificRoads().showDialog(mapActivity); + Fragment fragment = getTargetFragment(); + if (fragment != null) { + fragment.onActivityResult(getTargetRequestCode(), OPEN_AVOID_ROADS_DIALOG_REQUEST_CODE, null); + } + } + dismiss(); + } + }); + + final SimpleBottomSheetItem buttonItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() + .setCustomView(buttonView) + .create(); + items.add(buttonItem); + + items.add(new SubtitleDividerItem(app)); + + populateImpassableRoadsTypes(); + } + + private void populateImpassableRoadsObjects() { + Context context = getContext(); + if (context == null) { + return; + } + AvoidSpecificRoads avoidSpecificRoads = getMyApplication().getAvoidSpecificRoads(); + + int counter = 0; + for (final LatLon routeDataObject : avoidSpecificRoads.getImpassableRoads().keySet()) { + if (removedImpassableRoads.contains(routeDataObject)) { + continue; + } + String name = avoidSpecificRoads.getText(routeDataObject); + + View view = stylesContainer.getChildAt(counter); + view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + removedImpassableRoads.add(routeDataObject); + stylesContainer.removeView(v); + } + }); + + TextView titleTv = (TextView) view.findViewById(R.id.title); + titleTv.setText(name); + titleTv.setTextColor(getResolvedColor(nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light)); + + ImageView icon = (ImageView) view.findViewById(R.id.icon); + icon.setImageDrawable(getContentIcon(R.drawable.ic_action_remove_dark)); + + counter++; + } + + } + + private void populateImpassableRoadsTypes() { + Context context = getContext(); + if (context == null) { + return; + } + for (Map.Entry entry : routingParametersMap.entrySet()) { + final String parameterId = entry.getKey(); + boolean selected = entry.getValue(); + String parameterName = SettingsBaseActivity.getRoutingStringPropertyName(context, parameterId, ""); + + final BottomSheetItemWithCompoundButton[] item = new BottomSheetItemWithCompoundButton[1]; + item[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder() + .setChecked(selected) + .setTitle(parameterName) + .setLayoutId(R.layout.bottom_sheet_item_with_switch_no_icon) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + item[0].setChecked(!item[0].isChecked()); + routingParametersMap.put(parameterId, item[0].isChecked()); + } + }) + .setTag(parameterId) + .create(); + items.add(item[0]); + compoundButtons.add(item[0]); + } + } + + @Override + public void onResume() { + super.onResume(); + for (BottomSheetItemWithCompoundButton item : compoundButtons) { + final String routingParameterId = (String) item.getTag(); + item.setChecked(routingParametersMap.get(routingParameterId)); + } + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putSerializable(AVOID_ROADS_TYPES_KEY, routingParametersMap); + outState.putSerializable(AVOID_ROADS_OBJECTS_KEY, (Serializable) removedImpassableRoads); + } + + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_apply; + } + + + @Nullable + private MapActivity getMapActivity() { + Activity activity = getActivity(); + if (activity != null && activity instanceof MapActivity) { + return (MapActivity) activity; + } + return null; + } + + @Override + protected void onRightBottomButtonClick() { + final OsmandApplication app = getMyApplication(); + if (app == null) { + return; + } + + for (Map.Entry entry : routingParametersMap.entrySet()) { + String parameterId = entry.getKey(); + GeneralRouter.RoutingParameter parameter = app.getRoutingOptionsHelper().getRoutingPrefsForAppModeById(app.getRoutingHelper().getAppMode(), parameterId); + if (parameter != null) { + boolean checked = entry.getValue(); + OsmandSettings.CommonPreference preference = app.getSettings().getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean()); + preference.set(checked); + } + } + + AvoidSpecificRoads avoidSpecificRoads = app.getAvoidSpecificRoads(); + for (LatLon routeLocation : removedImpassableRoads) { + avoidSpecificRoads.removeImpassableRoad(routeLocation); + } + + RoutingHelper routingHelper = app.getRoutingHelper(); + if (routingHelper.isRouteCalculated() || routingHelper.isRouteBeingCalculated()) { + routingHelper.recalculateRouteDueToSettingsChange(); + } + + dismiss(); + } + + @NonNull + private HashMap generateStylesMap(OsmandApplication app) { + HashMap res = new HashMap<>(); + List avoidParameters = app.getRoutingOptionsHelper().getAvoidRoutingPrefsForAppMode(app.getRoutingHelper().getAppMode()); + + for (GeneralRouter.RoutingParameter parameter : avoidParameters) { + OsmandSettings.CommonPreference preference = app.getSettings().getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean()); + res.put(parameter.getId(), preference.get()); + } + + return res; + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index a1695f1207..00c30e6fa2 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -101,7 +101,6 @@ public class MapRouteInfoMenu implements IRouteInformationListener { private final MapContextMenu contextMenu; private final RoutingHelper routingHelper; private final RoutingOptionsHelper routingOptionsHelper; - private OsmandMapTileView mapView; private GeocodingLookupService geocodingLookupService; private boolean selectFromMapTouch; private boolean selectFromMapForTarget; @@ -157,7 +156,6 @@ public class MapRouteInfoMenu implements IRouteInformationListener { contextMenu = mapActivity.getContextMenu(); routingHelper = mapActivity.getRoutingHelper(); routingOptionsHelper = app.getRoutingOptionsHelper(); - mapView = mapActivity.getMapView(); routingHelper.addListener(this); portraitMode = AndroidUiHelper.isOrientationPortrait(mapActivity); currentMenuState = getInitialMenuState(); @@ -678,7 +676,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener { Iterator it = impassableRoads.values().iterator(); while (it.hasNext()) { final RouteDataObject routeDataObject = it.next(); - final LinearLayout container = createToolbarSubOptionView(false, getText(routeDataObject), R.drawable.ic_action_remove_dark, !it.hasNext(), new View.OnClickListener() { + final LinearLayout container = createToolbarSubOptionView(false, avoidSpecificRoads.getText(routeDataObject), R.drawable.ic_action_remove_dark, !it.hasNext(), new View.OnClickListener() { @Override public void onClick(View v) { if (routeDataObject != null) { @@ -825,23 +823,6 @@ public class MapRouteInfoMenu implements IRouteInformationListener { return container; } - private String getText(@Nullable RouteDataObject obj) { - if (obj != null) { - String locale = app.getSettings().MAP_PREFERRED_LOCALE.get(); - boolean transliterate = app.getSettings().MAP_TRANSLITERATE_NAMES.get(); - String name = RoutingHelper.formatStreetName( - obj.getName(locale, transliterate), - obj.getRef(locale, transliterate, true), - obj.getDestinationName(locale, transliterate, true), - app.getString(R.string.towards) - ); - if (!TextUtils.isEmpty(name)) { - return name; - } - } - return app.getString(R.string.shared_string_road); - } - private void clickRouteGo() { if (getTargets().getPointToNavigate() != null) { hide(); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java index 75fec5b315..27c276ee70 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java @@ -1,10 +1,8 @@ package net.osmand.plus.routepreparationmenu; -import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.FragmentManager; -import android.support.v7.app.AlertDialog; import android.view.View; import android.widget.ImageView; import android.widget.TextView; @@ -16,6 +14,7 @@ import net.osmand.plus.ApplicationMode; import net.osmand.plus.GPXUtilities; import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; @@ -28,7 +27,7 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; -import net.osmand.plus.dashboard.DashboardOnMap; +import net.osmand.plus.development.OsmandDevelopmentPlugin; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsTypesRoutingParameter; @@ -90,7 +89,6 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { } for (final LocalRoutingParameter optionsItem : list) { - if (optionsItem instanceof DividerItem) { items.add(new DividerHalfItem(app)); } else if (optionsItem instanceof MuteSoundRoutingParameter) { @@ -129,6 +127,9 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { .create(); items.add(showAlongTheRouteItem); } else if (optionsItem instanceof RouteSimulationItem) { + if (OsmandPlugin.getEnabledPlugin(OsmandDevelopmentPlugin.class) == null) { + continue; + } BaseBottomSheetItem routeSimulationItem = new SimpleBottomSheetItem.Builder() .setIcon(getContentIcon(R.drawable.ic_action_start_navigation)) .setTitle(getString(R.string.simulate_navigation)) @@ -152,15 +153,9 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { @Override public void onClick(View view) { routingOptionsHelper.addNewRouteMenuParameter(applicationMode, optionsItem); - List avoidParameters = routingOptionsHelper.getAvoidRoutingPrefsForAppMode(applicationMode); - String[] vals = new String[avoidParameters.size()]; - OsmandSettings.OsmandPreference[] bls = new OsmandSettings.OsmandPreference[avoidParameters.size()]; - for (int i = 0; i < avoidParameters.size(); i++) { - GeneralRouter.RoutingParameter p = avoidParameters.get(i); - vals[i] = SettingsBaseActivity.getRoutingStringPropertyName(app, p.getId(), p.getName()); - bls[i] = settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean()); - } - showBooleanSettings(vals, bls, getString(R.string.impassable_road), mapActivity); + AvoidRoadsBottomSheetDialogFragment avoidRoadsFragment = new AvoidRoadsBottomSheetDialogFragment(); + avoidRoadsFragment.setTargetFragment(RouteOptionsBottomSheet.this, AvoidRoadsBottomSheetDialogFragment.REQUEST_CODE); + avoidRoadsFragment.show(mapActivity.getSupportFragmentManager(), AvoidRoadsBottomSheetDialogFragment.TAG); } }) .create(); @@ -174,10 +169,9 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { @Override public void onClick(View view) { routingOptionsHelper.addNewRouteMenuParameter(applicationMode, optionsItem); - mapActivity.getDashboard().setDashboardVisibility(false, DashboardOnMap.DashboardType.ROUTE_PREFERENCES); - controlsLayer.getMapRouteInfoMenu().hide(); - app.getAvoidSpecificRoads().showDialog(mapActivity); - dismiss(); + AvoidRoadsBottomSheetDialogFragment avoidRoadsFragment = new AvoidRoadsBottomSheetDialogFragment(); + avoidRoadsFragment.setTargetFragment(RouteOptionsBottomSheet.this, AvoidRoadsBottomSheetDialogFragment.REQUEST_CODE); + avoidRoadsFragment.show(mapActivity.getSupportFragmentManager(), AvoidRoadsBottomSheetDialogFragment.TAG); } }) .create(); @@ -232,42 +226,6 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { return R.string.shared_string_close; } - - public static AlertDialog showBooleanSettings(String[] vals, final OsmandSettings.OsmandPreference[] prefs, final CharSequence title, MapActivity mapActivity) { - AlertDialog.Builder bld = new AlertDialog.Builder(mapActivity); - boolean[] checkedItems = new boolean[prefs.length]; - for (int i = 0; i < prefs.length; i++) { - checkedItems[i] = prefs[i].get(); - } - - final boolean[] tempPrefs = new boolean[prefs.length]; - for (int i = 0; i < prefs.length; i++) { - tempPrefs[i] = prefs[i].get(); - } - - bld.setMultiChoiceItems(vals, checkedItems, new DialogInterface.OnMultiChoiceClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which, boolean isChecked) { - tempPrefs[which] = isChecked; - } - }); - - bld.setTitle(title); - - bld.setNegativeButton(R.string.shared_string_cancel, null); - - bld.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - for (int i = 0; i < prefs.length; i++) { - prefs[i].set(tempPrefs[i]); - } - } - }); - - return bld.show(); - } - private void inflateRoutingParameter(final LocalRoutingParameter optionsItem) { if (optionsItem != null) { final LocalRoutingParameter parameter = (LocalRoutingParameter) optionsItem; @@ -326,6 +284,15 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { } } + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == AvoidRoadsBottomSheetDialogFragment.REQUEST_CODE + && resultCode == AvoidRoadsBottomSheetDialogFragment.OPEN_AVOID_ROADS_DIALOG_REQUEST_CODE) { + dismiss(); + } + } + private MapActivity getMapActivity() { return (MapActivity) getActivity(); } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java index 13decddc70..47eb2be30c 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java @@ -472,10 +472,9 @@ public class RoutingOptionsHelper { return null; } - public List getAvoidRoutingPrefsForAppMode(ApplicationMode applicationMode) { List avoidParameters = new ArrayList(); - GeneralRouter router = getRouter(app.getDefaultRoutingConfig(), routingHelper.getAppMode()); + GeneralRouter router = getRouter(app.getDefaultRoutingConfig(), applicationMode); if (router != null) { for (Map.Entry e : router.getParameters().entrySet()) { String param = e.getKey(); @@ -488,6 +487,17 @@ public class RoutingOptionsHelper { return avoidParameters; } + public GeneralRouter.RoutingParameter getRoutingPrefsForAppModeById(ApplicationMode applicationMode, String parameterId) { + GeneralRouter router = getRouter(app.getDefaultRoutingConfig(), applicationMode); + GeneralRouter.RoutingParameter parameter=null; + + if (router != null) { + parameter = router.getParameters().get(parameterId); + } + + return parameter; + } + public static class LocalRoutingParameter { public static final String KEY = "LocalRoutingParameter";