From a327ad40933af64859e579df7804b58207298b32 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 23 Nov 2018 15:29:48 +0200 Subject: [PATCH] Add avoid roads bottom sheet --- .../map_start_navigation.png | Bin 1547 -> 1664 bytes .../map_start_navigation.png | Bin 1867 -> 1936 bytes .../drawable-large/map_start_navigation.png | Bin 1406 -> 1437 bytes OsmAnd/res/layout/bottom_sheet_item_btn.xml | 38 +++ .../bottom_sheet_item_simple_right_icon.xml | 36 +++ .../layout/bottom_sheet_item_title_long.xml | 13 + .../bottom_sheet_item_toolbar_title.xml | 24 ++ .../bottom_sheet_item_with_switch_no_icon.xml | 34 ++ OsmAnd/res/values/strings.xml | 1 + .../plus/helpers/AvoidSpecificRoads.java | 21 +- .../AvoidRoadsBottomSheetDialogFragment.java | 296 ++++++++++++++++++ .../MapRouteInfoMenu.java | 21 +- .../RouteOptionsBottomSheet.java | 73 ++--- .../RoutingOptionsHelper.java | 14 +- 14 files changed, 494 insertions(+), 77 deletions(-) create mode 100644 OsmAnd/res/layout/bottom_sheet_item_btn.xml create mode 100644 OsmAnd/res/layout/bottom_sheet_item_simple_right_icon.xml create mode 100644 OsmAnd/res/layout/bottom_sheet_item_title_long.xml create mode 100644 OsmAnd/res/layout/bottom_sheet_item_toolbar_title.xml create mode 100644 OsmAnd/res/layout/bottom_sheet_item_with_switch_no_icon.xml create mode 100644 OsmAnd/src/net/osmand/plus/routepreparationmenu/AvoidRoadsBottomSheetDialogFragment.java diff --git a/OsmAnd/res/drawable-large-hdpi/map_start_navigation.png b/OsmAnd/res/drawable-large-hdpi/map_start_navigation.png index 7b07628242132356c168a869ab3a4f71dd97ae44..3e784bf91e36cd27f638ec1209eff688d53ea418 100644 GIT binary patch delta 824 zcmV-81IPS}41f)=UjiRSHZem%IW|Q$FfuVQML0P&H8VIyL^m-+LO3xuIYX0v0v#Vl zHZem%IWNkljz~ z!B9d#4+OjknwX$Qpa&C-RV$Ey0kz!9!D!R~-aPmpcu^B$IC9}Yf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6^lhBnqCcpKmZ9K0e>Wb z1dsp{Kmy1K?T2@|^n)5515|)N!5<`os?`Q(;C=8W0aUGfaEjd{fc{q+K3n$s7`$2l z{nOow@o*NL6F?=cfb&zle-d6QfRwrkH&5~Y9Jo8_fEK~mYJ7eMUXWx!z3}21pA($Z zNd?r*-D@Uwb9YM|Aj)-C)p6W1_7Z+Kj0>RU@MR0_cEK%i05n}eOjoqRKYwRE?YF$c zjOsa~s&>t%QbQh&9fv#NiKs?UuSYn3{sGyjb}{M#w*u(G=i%8=1awK&R}j;c)q+}s z#diAwOhR+EuEiE08W%PO2xzUcR8X@8sGx#ZPgDSPsBrf9Y=QSi0Z#PEzFg-HEG1S*z!hetX@1(LL8VlQbDsQi2(s`$9@9Z}M=v$2xevBifpCczowQ@w& zx@SMm-P0?$01`j~NB{{S0VIHusy_k@067+h)s#ofsSE%B002ovPDHLkV1lA& B#KHgo diff --git a/OsmAnd/res/drawable-large/map_start_navigation.png b/OsmAnd/res/drawable-large/map_start_navigation.png index f11803458063fc8f38055ec627b53fa25917ca11..9ab5382df1346b39400a4da52b407f649db72b25 100644 GIT binary patch delta 597 zcmeyzHJ5us9Fu~hsiljlv!SW0nSqg^p{s?ZnW?dbn~S-ji<5<+xux^uIwl#IA`_g7 zb}^-?7?>KS7+D%7>82#5Sm>G<8>i?d8CV$V8kwdVS)`g+BpN2AOm<;zsyE&}p@xBh zakr<7V@SoVq(A@v+aFF~^5JRb;fZFCWZHNyp(wyo;5fe+`%31G`U1C^HXceS2r#@N zBhV+8!S2aa$Rl)Ly2F+2l4GR9na(5W%#RGbcv6-uNO;2d=(vLp!_)b#m*y{2{Mvg@ zaZ1kOG$u*!0Cq*r!yp#S6Qu?!C|^UsbQiVUlDVX zvl6!tca_D887x~3x0Fp#G->HzeRg5OqM6NJCpa!zL|J!Rq8t z|HgG?^9&Ci4$j61r!phKi4s>=zEB9bnCRZwd@A$8*Dm$zj$s%6iEVAv6Of+pc!7}; z5Bt{oa>kAJTOQc(i7Kny7)O-B zE#<52_Ki2Bj0G8FTUhnkA8mKI!*k@4#gz%oM;k1JJH9g(N}HMXEM^XKKI_Q9$i`sO Wy;1zIVaNvtAn zb}^-?B&8Z!BpO>9=^79NW5g3*_)eB zHOvs~ddz;yvCBcG??^do(#yt@08W9;3Lj@ST9hr2QQSV_wmKAZUtWPwbQEQVDh`w~l zQB*`^5$Bb%38DhG10N_TXBf9;@hws*@!(QTl3C*HSJ}jRLuj&dXJLS)=FS!ez25re zR~)$nm3{Of^@=;1DXo^yjrZ9crDy)YO4bk>N*ymWoC+RtgsX~&+uq- zfFW;2=DR-k`~DfTYW!CXt_>i$u>LRpOIqq|I1<$`H!j2nf-epWiz^oFqSZE6$Z z_`~+7G@xBZ!SJqx^KCajkBk51ZYds!s(x(Ew0*%vBleExOdq+8gg-@Uh_NNrEATNq oy8dLz!ixvn0@($b8JKt&Hhi@GdMPJq2Lljzy85}Sb4q9e0H$BkqW}N^ 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";