Add avoid roads bottom sheet
This commit is contained in:
parent
4335ec7ff7
commit
a327ad4093
14 changed files with 494 additions and 77 deletions
Binary file not shown.
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.6 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
38
OsmAnd/res/layout/bottom_sheet_item_btn.xml
Normal file
38
OsmAnd/res/layout/bottom_sheet_item_btn.xml
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_selected_item_title_height"
|
||||
android:minHeight="@dimen/dashboard_map_toolbar"
|
||||
android:orientation="vertical">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/button_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="36dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_marginLeft="@dimen/route_info_buttons_padding_top_bottom"
|
||||
android:layout_marginRight="@dimen/route_info_buttons_padding_top_bottom"
|
||||
android:layout_marginTop="7dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/button_descr"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="36dp"
|
||||
android:layout_gravity="center"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:letterSpacing="@dimen/text_button_letter_spacing"
|
||||
android:maxLines="1"
|
||||
android:text="@string/rendering_category_details"
|
||||
android:textSize="@dimen/text_button_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:ignore="UnusedAttribute"
|
||||
tools:textColor="?attr/wikivoyage_active_color" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
36
OsmAnd/res/layout/bottom_sheet_item_simple_right_icon.xml
Normal file
36
OsmAnd/res/layout/bottom_sheet_item_simple_right_icon.xml
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textAppearance="@style/TextAppearance.ListItemCategoryTitle"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
app:typeface="@string/font_roboto_medium"
|
||||
tools:text="Title" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="@dimen/standard_icon_size"
|
||||
android:layout_height="@dimen/standard_icon_size"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginStart="@dimen/bottom_sheet_icon_margin"
|
||||
tools:src="@drawable/ic_action_info_dark" />
|
||||
|
||||
</LinearLayout>
|
13
OsmAnd/res/layout/bottom_sheet_item_title_long.xml
Normal file
13
OsmAnd/res/layout/bottom_sheet_item_title_long.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingBottom="@dimen/bottom_sheet_content_margin_small"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
tools:text="Some long description" />
|
24
OsmAnd/res/layout/bottom_sheet_item_toolbar_title.xml
Normal file
24
OsmAnd/res/layout/bottom_sheet_item_toolbar_title.xml
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_selected_item_title_height"
|
||||
android:minHeight="@dimen/bottom_sheet_selected_item_title_height"
|
||||
osmand:contentInsetLeft="54dp"
|
||||
osmand:contentInsetStart="54dp">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_title_height"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
android:minHeight="@dimen/bottom_sheet_title_height"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:text="Some Title" />
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
34
OsmAnd/res/layout/bottom_sheet_item_with_switch_no_icon.xml
Normal file
34
OsmAnd/res/layout/bottom_sheet_item_with_switch_no_icon.xml
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/content_padding"
|
||||
android:layout_marginRight="@dimen/content_padding"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
tools:text="Some Title" />
|
||||
|
||||
<android.support.v7.widget.SwitchCompat
|
||||
android:id="@+id/compound_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:focusableInTouchMode="false" />
|
||||
|
||||
</LinearLayout>
|
|
@ -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
|
||||
-->
|
||||
<string name="avoid_roads_descr">Select road on the map or from the list below that you want to avoid during navigation:</string>
|
||||
<string name="show_along_the_route">Show along the route</string>
|
||||
<string name="simulate_navigation">Simulate navigation</string>
|
||||
<string name="choose_track_file_to_follow">Choose track file to follow</string>
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<String, Boolean> routingParametersMap;
|
||||
private List<LatLon> removedImpassableRoads;
|
||||
private LinearLayout stylesContainer;
|
||||
|
||||
List<BottomSheetItemWithCompoundButton> 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<String, Boolean>) savedInstanceState.getSerializable(AVOID_ROADS_TYPES_KEY);
|
||||
}
|
||||
if (savedInstanceState.containsKey(AVOID_ROADS_OBJECTS_KEY)) {
|
||||
removedImpassableRoads = (List<LatLon>) savedInstanceState.getSerializable(AVOID_ROADS_OBJECTS_KEY);
|
||||
}
|
||||
}
|
||||
if (routingParametersMap == null) {
|
||||
routingParametersMap = generateStylesMap(app);
|
||||
}
|
||||
if (removedImpassableRoads == null) {
|
||||
removedImpassableRoads = new ArrayList<LatLon>();
|
||||
}
|
||||
|
||||
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<String, Boolean> 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<String, Boolean> 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<Boolean> 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<String, Boolean> generateStylesMap(OsmandApplication app) {
|
||||
HashMap<String, Boolean> res = new HashMap<>();
|
||||
List<GeneralRouter.RoutingParameter> avoidParameters = app.getRoutingOptionsHelper().getAvoidRoutingPrefsForAppMode(app.getRoutingHelper().getAppMode());
|
||||
|
||||
for (GeneralRouter.RoutingParameter parameter : avoidParameters) {
|
||||
OsmandSettings.CommonPreference<Boolean> preference = app.getSettings().getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean());
|
||||
res.put(parameter.getId(), preference.get());
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
|
@ -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<RouteDataObject> 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();
|
||||
|
|
|
@ -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<GeneralRouter.RoutingParameter> 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<Boolean>[] 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();
|
||||
}
|
||||
|
|
|
@ -472,10 +472,9 @@ public class RoutingOptionsHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
public List<GeneralRouter.RoutingParameter> getAvoidRoutingPrefsForAppMode(ApplicationMode applicationMode) {
|
||||
List<GeneralRouter.RoutingParameter> avoidParameters = new ArrayList<GeneralRouter.RoutingParameter>();
|
||||
GeneralRouter router = getRouter(app.getDefaultRoutingConfig(), routingHelper.getAppMode());
|
||||
GeneralRouter router = getRouter(app.getDefaultRoutingConfig(), applicationMode);
|
||||
if (router != null) {
|
||||
for (Map.Entry<String, GeneralRouter.RoutingParameter> 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";
|
||||
|
|
Loading…
Reference in a new issue