diff --git a/OsmAnd/res/drawable/route_info_trans_gradient_dark.xml b/OsmAnd/res/drawable/route_info_trans_gradient_dark.xml index 34082c4708..cf3653787d 100644 --- a/OsmAnd/res/drawable/route_info_trans_gradient_dark.xml +++ b/OsmAnd/res/drawable/route_info_trans_gradient_dark.xml @@ -9,6 +9,7 @@ android:endColor="@color/activity_background_dark" android:centerX="0.2" android:type="linear" /> + \ No newline at end of file diff --git a/OsmAnd/res/drawable/route_info_trans_gradient_light.xml b/OsmAnd/res/drawable/route_info_trans_gradient_light.xml index cc325d1e1b..76dd06c92e 100644 --- a/OsmAnd/res/drawable/route_info_trans_gradient_light.xml +++ b/OsmAnd/res/drawable/route_info_trans_gradient_light.xml @@ -9,6 +9,7 @@ android:endColor="@color/card_and_list_background_light" android:centerX="0.2" android:type="linear" /> + \ No newline at end of file diff --git a/OsmAnd/res/layout/plan_route_info.xml b/OsmAnd/res/layout/plan_route_info.xml index aeb2320ec3..7544d69812 100644 --- a/OsmAnd/res/layout/plan_route_info.xml +++ b/OsmAnd/res/layout/plan_route_info.xml @@ -222,6 +222,8 @@ android:layout_marginBottom="3dp" android:layout_marginTop="5dp" android:gravity="left" + android:singleLine="true" + android:ellipsize="end" android:text="@string/intermediate_destinations" android:textSize="@dimen/default_sub_text_size" /> @@ -416,6 +418,7 @@ android:layout_height="match_parent" android:layout_gravity="start" android:paddingBottom="@dimen/bottom_sheet_content_margin_small" + android:paddingLeft="@dimen/bottom_sheet_content_margin_small" android:paddingTop="@dimen/bottom_sheet_content_margin_small"> - - + android:gravity="start|center_vertical"> + + - - \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index 092f87b225..fb9ec35ae6 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -40,6 +40,7 @@ import android.view.Gravity; import android.view.View; import android.view.ViewParent; import android.view.inputmethod.InputMethodManager; +import android.widget.FrameLayout; import android.widget.TextView; import net.osmand.plus.R; @@ -310,6 +311,15 @@ public class AndroidUtils { } } + public static void setForeground(Context ctx, View view, boolean night, int lightResId, int darkResId) { + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { + view.setForeground(ctx.getResources().getDrawable(night ? darkResId : lightResId, + ctx.getTheme())); + } else if (view instanceof FrameLayout) { + ((FrameLayout) view).setForeground(ctx.getResources().getDrawable(night ? darkResId : lightResId)); + } + } + public static void setDashButtonBackground(Context ctx, View view, boolean night) { setBackground(ctx, view, night, R.drawable.dashboard_button_light, R.drawable.dashboard_button_dark); } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index f38899d01f..6520a33095 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -7,6 +7,7 @@ import android.graphics.PointF; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; +import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; @@ -28,7 +29,6 @@ import android.widget.LinearLayout; import android.widget.ListView; import android.widget.Spinner; import android.widget.TextView; -import android.widget.Toast; import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.data.LineData; @@ -60,14 +60,15 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SettingsBaseActivity; import net.osmand.plus.activities.ShowRouteInfoDialogFragment; import net.osmand.plus.activities.actions.AppModeDialog; -import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AvoidSpecificRoads; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.MapMarkerDialogHelper; +import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.other.FavouritesBottomSheetMenuFragment; import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment; +import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener; @@ -477,7 +478,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener { gpx = GPXUtilities.makeGpxFromRoute(routingHelper.getRoute()); } - private void updateOptionsButtons(View main) { + private void updateOptionsButtons(final View main) { final boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); final OsmandSettings settings = app.getSettings(); @@ -531,6 +532,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener { scrollView.setHorizontalScrollBarEnabled(false); final ApplicationMode applicationMode = routingHelper.getAppMode(); + int margin = app.getResources().getDimensionPixelSize(R.dimen.text_margin_small); final RoutingOptionsHelper.RouteMenuAppModes mode = routingOptionsHelper.modes.get(applicationMode); LinearLayout optionsContainer = (LinearLayout) main.findViewById(R.id.route_options_container); @@ -538,82 +540,102 @@ public class MapRouteInfoMenu implements IRouteInformationListener { if (mode == null) { return; } + 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); + + LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT); + LinearLayout.LayoutParams newLp = new LinearLayout.LayoutParams(AndroidUtils.dpToPx(app, 100), ViewGroup.LayoutParams.MATCH_PARENT); + + lp.setMargins(margin, 0, margin, 0); for (final RoutingOptionsHelper.LocalRoutingParameter parameter : mode.parameters) { - final LinearLayout item = (LinearLayout) mapActivity.getLayoutInflater().inflate(R.layout.route_option_btn, null); - final TextView textView = (TextView) item.findViewById(R.id.route_option_title); - final ImageView imageView = (ImageView) item.findViewById(R.id.route_option_image_view); - 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); - - LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, app.getResources().getDimensionPixelSize(R.dimen.route_info_settings_buttons_height)); - int margin = app.getResources().getDimensionPixelSize(R.dimen.text_margin_small); - lp.setMargins(margin, 0, margin, 0); - - AndroidUtils.setBackground(app, item, 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, item.findViewById(R.id.route_option_container), nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); - } - if (parameter instanceof RoutingOptionsHelper.MuteSoundRoutingParameter) { - Drawable itemDrawable = app.getUIUtilities().getIcon(R.drawable.ic_action_volume_up, nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light); - final Drawable activeItemDrawable = app.getUIUtilities().getIcon(R.drawable.ic_action_volume_up, 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); + String text = null; + if (mode.parameters.size() <= 2) { + text = app.getString(R.string.sound_is, (app.getText(app.getRoutingHelper().getVoiceRouter().isMute() ? R.string.shared_string_off : R.string.shared_string_on))); } - imageView.setImageDrawable(app.getRoutingHelper().getVoiceRouter().isMute() ? itemDrawable : activeItemDrawable); - - if (mode.parameters.size() > 2) { - textView.setVisibility(View.GONE); - } else { - textView.setVisibility(View.VISIBLE); - textView.setTextColor(app.getRoutingHelper().getVoiceRouter().isMute() ? colorDisabled : colorActive); - String text = app.getString(R.string.sound_is, (app.getText(app.getRoutingHelper().getVoiceRouter().isMute() ? R.string.shared_string_off : R.string.shared_string_on))); - textView.setText(text); - } - item.setOnClickListener(new View.OnClickListener() { + View item = createToolbarOptionView(!app.getRoutingHelper().getVoiceRouter().isMute(), text, R.drawable.ic_action_volume_up, new View.OnClickListener() { @Override public void onClick(View v) { routingOptionsHelper.switchSound(); - Drawable itemDrawable = app.getUIUtilities().getIcon(R.drawable.ic_action_volume_up, nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light); + Drawable activeItemDrawable = app.getUIUtilities().getIcon(R.drawable.ic_action_volume_up, 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.setImageDrawable(app.getRoutingHelper().getVoiceRouter().isMute() ? itemDrawable : activeItemDrawable); + ((ImageView) v.findViewById(R.id.route_option_image_view)).setImageDrawable(app.getRoutingHelper().getVoiceRouter().isMute() ? itemDrawable : activeItemDrawable); - String text = app.getString(R.string.sound_is, (app.getText(app.getRoutingHelper().getVoiceRouter().isMute() ? R.string.shared_string_off : R.string.shared_string_on))); - textView.setText(text); - textView.setTextColor(app.getRoutingHelper().getVoiceRouter().isMute() && mode.parameters.size() <= 2 ? colorDisabled : colorActive); + String text = app.getString(R.string.sound_is, (app.getText(app.getRoutingHelper().getVoiceRouter().isMute() && mode.parameters.size() <= 2 ? R.string.shared_string_off : R.string.shared_string_on))); + ((TextView) v.findViewById(R.id.route_option_title)).setText(text); + ((TextView) v.findViewById(R.id.route_option_title)).setTextColor(app.getRoutingHelper().getVoiceRouter().isMute() && mode.parameters.size() <= 2 ? colorDisabled : colorActive); } }); - optionsContainer.addView(item, lp); - - } else if (parameter instanceof RoutingOptionsHelper.ShowAlongTheRouteItem) { - Drawable itemDrawable = app.getUIUtilities().getIcon(R.drawable.ic_action_snap_to_road, nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light); - if (Build.VERSION.SDK_INT >= 21) { - Drawable activeItemDrawable = app.getUIUtilities().getIcon(R.drawable.ic_action_snap_to_road, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light); - itemDrawable = AndroidUtils.createPressedStateListDrawable(itemDrawable, activeItemDrawable); + if (mode.parameters.size() > 2) { + optionsContainer.addView(item, lp); + } else { + optionsContainer.addView(item, newLp); } - imageView.setImageDrawable(itemDrawable); - textView.setText(R.string.show_along_the_route); - item.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Toast.makeText(app, app.getText(R.string.show_along_the_route), Toast.LENGTH_LONG).show(); + } else if (parameter instanceof RoutingOptionsHelper.ShowAlongTheRouteItem) { + final Set 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()) { + final LinearLayout item = createToolbarOptionView(false, null, -1, null); + item.findViewById(R.id.route_option_container).setVisibility(View.GONE); + Iterator it = poiFilters.iterator(); + while (it.hasNext()) { + final PoiUIFilter poiUIFilter = it.next(); + final LinearLayout container = createToolbarSubOptionView(true, poiUIFilter.getName(), R.drawable.ic_action_remove_dark, !it.hasNext(), new View.OnClickListener() { + @Override + public void onClick(View v) { + app.getPoiFilters().removeSelectedPoiFilter(poiUIFilter); + if (!app.getPoiFilters().isShowingAnyPoi()) { + mode.parameters.remove(parameter); + } + mapActivity.getMapView().refreshMap(); + updateOptionsButtons(mainView); + } + }); + item.addView(container, newLp); } - }); - optionsContainer.addView(item, lp); + optionsContainer.addView(item, lp); + } + if (traffic) { + final LinearLayout item = createToolbarOptionView(false, null, -1, null); + AndroidUtils.setBackground(app, item, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark); + item.findViewById(R.id.route_option_container).setVisibility(View.GONE); + final LinearLayout container = createToolbarSubOptionView(true, app.getString(R.string.way_alarms), R.drawable.ic_action_remove_dark, true, new View.OnClickListener() { + @Override + public void onClick(View v) { + app.getWaypointHelper().enableWaypointType(WaypointHelper.ALARMS, false); + updateOptionsButtons(mainView); + } + }); + item.addView(container,newLp); + optionsContainer.addView(item, lp); + } + if (fav) { + final LinearLayout item = createToolbarOptionView(false, null, -1, null); + AndroidUtils.setBackground(app, item, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark); + item.findViewById(R.id.route_option_container).setVisibility(View.GONE); + final LinearLayout container = createToolbarSubOptionView(true, app.getString(R.string.favourites), R.drawable.ic_action_remove_dark, true, new View.OnClickListener() { + @Override + public void onClick(View v) { + app.getWaypointHelper().enableWaypointType(WaypointHelper.FAVORITES, false); + updateOptionsButtons(mainView); + } + }); + item.addView(container,newLp); + optionsContainer.addView(item, lp); + } } else if (parameter instanceof RoutingOptionsHelper.AvoidRoadsTypesRoutingParameter) { + final LinearLayout item = createToolbarOptionView(false, null, -1, null); + item.findViewById(R.id.route_option_container).setVisibility(View.GONE); List avoidParameters = routingOptionsHelper.getAvoidRoutingPrefsForAppMode(applicationMode); - List avoidedParameters = new ArrayList(); - - String[] propertyNames = new String[avoidParameters.size()]; + final List avoidedParameters = new ArrayList(); for (int i = 0; i < avoidParameters.size(); i++) { GeneralRouter.RoutingParameter p = avoidParameters.get(i); - propertyNames[i] = SettingsBaseActivity.getRoutingStringPropertyName(app, p.getId(), p.getName()); OsmandSettings.CommonPreference preference = settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean()); if (preference != null && preference.get()) { avoidedParameters.add(p); @@ -622,170 +644,71 @@ public class MapRouteInfoMenu implements IRouteInformationListener { if (avoidedParameters.isEmpty()) { continue; } - - Drawable itemDrawable = app.getUIUtilities().getIcon(R.drawable.ic_action_road_works_dark, nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light); - if (Build.VERSION.SDK_INT >= 21) { - Drawable activeItemDrawable = app.getUIUtilities().getIcon(R.drawable.ic_action_road_works_dark, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light); - itemDrawable = AndroidUtils.createPressedStateListDrawable(itemDrawable, activeItemDrawable); - } - - if (avoidedParameters.size() > 2) { - imageView.setImageDrawable(itemDrawable); - textView.setText(R.string.impassable_road); - - item.setOnClickListener(new View.OnClickListener() { + for (int i = 0; i < avoidedParameters.size(); i++) { + final GeneralRouter.RoutingParameter routingParameter = avoidedParameters.get(i); + final LinearLayout container = createToolbarSubOptionView(false, SettingsBaseActivity.getRoutingStringPropertyName(app, routingParameter.getId(), routingParameter.getName()), R.drawable.ic_action_remove_dark, i == avoidedParameters.size() - 1, new View.OnClickListener() { @Override public void onClick(View v) { - routingOptionsHelper.addNewRouteMenuParameter(applicationMode, parameter); - 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()); + OsmandSettings.CommonPreference preference = settings.getCustomRoutingBooleanProperty(routingParameter.getId(), routingParameter.getDefaultBoolean()); + preference.set(false); + avoidedParameters.remove(routingParameter); + if (avoidedParameters.isEmpty()) { + mode.parameters.remove(parameter); } - RouteOptionsBottomSheet.showBooleanSettings(vals, bls, app.getString(R.string.impassable_road), mapActivity); - } - }); - } else { - item.findViewById(R.id.route_option_container).setVisibility(View.GONE); - for (int i = 0; i < avoidedParameters.size(); i++) { - final GeneralRouter.RoutingParameter routingParameter = avoidedParameters.get(i); - final LinearLayout container = (LinearLayout) mapActivity.getLayoutInflater().inflate(R.layout.route_options_container, null); - final TextView routeOptionTV = (TextView) container.findViewById(R.id.route_removable_option_title); - final ImageView routeOptionImageView = (ImageView) container.findViewById(R.id.removable_option_icon); - - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { - AndroidUtils.setBackground(app, container, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); - } else { - AndroidUtils.setBackground(app, container, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); - } - - if (i == avoidedParameters.size() - 1) { - container.findViewById(R.id.options_divider_end).setVisibility(View.GONE); - } - - AndroidUtils.setBackground(app, container.findViewById(R.id.options_divider_end), nightMode, - R.color.divider_light, R.color.divider_dark); - AndroidUtils.setBackground(app, container.findViewById(R.id.options_divider_start), nightMode, - R.color.divider_light, R.color.divider_dark); - - Drawable active = app.getUIUtilities().getIcon(R.drawable.ic_action_remove_dark, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light); - routeOptionImageView.setImageDrawable(active); - - AndroidUtils.setBackground(app, routeOptionImageView, nightMode, R.drawable.route_info_trans_gradient_light, R.drawable.route_info_trans_gradient_dark); - routeOptionTV.setText(SettingsBaseActivity.getRoutingStringPropertyName(app, routingParameter.getId(), routingParameter.getName())); - - container.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - OsmandSettings.CommonPreference preference = settings.getCustomRoutingBooleanProperty(routingParameter.getId(), routingParameter.getDefaultBoolean()); - preference.set(false); - Toast.makeText(app, SettingsBaseActivity.getRoutingStringPropertyName(app, routingParameter.getId(), routingParameter.getName()), Toast.LENGTH_LONG).show(); + if (mode.parameters.size() > 2) { + item.removeView(v); + } else { updateOptionsButtons(mainView); } - }); - item.addView(container); - } + } + }); + item.addView(container,newLp); } optionsContainer.addView(item, lp); } else if (parameter instanceof RoutingOptionsHelper.AvoidRoadsRoutingParameter) { - + final LinearLayout item = createToolbarOptionView(false, null, -1, null); + item.findViewById(R.id.route_option_container).setVisibility(View.GONE); AvoidSpecificRoads avoidSpecificRoads = app.getAvoidSpecificRoads(); Map impassableRoads = avoidSpecificRoads.getImpassableRoads(); - if (impassableRoads.isEmpty()) { continue; } - - Drawable itemDrawable = app.getUIUtilities().getIcon(R.drawable.ic_action_road_works_dark, nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light); - if (Build.VERSION.SDK_INT >= 21) { - Drawable activeItemDrawable = app.getUIUtilities().getIcon(R.drawable.ic_action_road_works_dark, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light); - itemDrawable = AndroidUtils.createPressedStateListDrawable(itemDrawable, activeItemDrawable); - } - - if (impassableRoads.size() > 2) { - - imageView.setImageDrawable(itemDrawable); - textView.setText(R.string.impassable_road); - item.setOnClickListener(new View.OnClickListener() { + 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() { @Override public void onClick(View v) { - mapActivity.getDashboard().setDashboardVisibility(false, DashboardOnMap.DashboardType.ROUTE_PREFERENCES); - mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().hide(); - app.getAvoidSpecificRoads().showDialog(mapActivity); - } - }); - - imageView.setImageDrawable(itemDrawable); - textView.setText(R.string.impassable_road); - } else { - item.findViewById(R.id.route_option_container).setVisibility(View.GONE); - Iterator> it = impassableRoads.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry pair = it.next(); - - final LatLon latLon = pair.getKey(); - final RouteDataObject routeDataObject = pair.getValue(); - final LinearLayout container = (LinearLayout) mapActivity.getLayoutInflater().inflate(R.layout.route_options_container, null); - final TextView routeOptionTV = (TextView) container.findViewById(R.id.route_removable_option_title); - final ImageView routeOptionImageView = (ImageView) container.findViewById(R.id.removable_option_icon); - - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { - AndroidUtils.setBackground(app, container, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); - } else { - AndroidUtils.setBackground(app, container, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); - } - - if (!it.hasNext()) { - container.findViewById(R.id.options_divider_end).setVisibility(View.GONE); - } - - AndroidUtils.setBackground(app, container.findViewById(R.id.options_divider_end), nightMode, - R.color.divider_light, R.color.divider_dark); - AndroidUtils.setBackground(app, container.findViewById(R.id.options_divider_start), nightMode, - R.color.divider_light, R.color.divider_dark); - - Drawable active = app.getUIUtilities().getIcon(R.drawable.ic_action_remove_dark, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light); - routeOptionImageView.setImageDrawable(active); - - AndroidUtils.setBackground(app, routeOptionImageView, nightMode, R.drawable.route_info_trans_gradient_light, R.drawable.route_info_trans_gradient_dark); - routeOptionTV.setText(getText(routeDataObject)); - - container.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - app.getAvoidSpecificRoads().removeImpassableRoad(routeDataObject); - Toast.makeText(app, getText(routeDataObject), Toast.LENGTH_LONG).show(); + 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(mainView); } - }); - item.addView(container); - } + } + }); + item.addView(container,newLp); } optionsContainer.addView(item, lp); } else if (parameter instanceof RoutingOptionsHelper.LocalRoutingParameterGroup) { - - Drawable itemDrawable = app.getUIUtilities().getIcon(R.drawable.mx_amenity_fuel, nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light); - if (Build.VERSION.SDK_INT >= 21) { - Drawable activeItemDrawable = app.getUIUtilities().getIcon(R.drawable.mx_amenity_fuel, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light); - itemDrawable = AndroidUtils.createPressedStateListDrawable(itemDrawable, activeItemDrawable); - } - - imageView.setImageDrawable(itemDrawable); + String text = null; RoutingOptionsHelper.LocalRoutingParameter selected = ((RoutingOptionsHelper.LocalRoutingParameterGroup) parameter).getSelected(settings); if (selected != null) { - textView.setText(((RoutingOptionsHelper.LocalRoutingParameterGroup) parameter).getText(mapActivity)); + text = ((RoutingOptionsHelper.LocalRoutingParameterGroup) parameter).getText(mapActivity); } - - item.setOnClickListener(new View.OnClickListener() { + View item = createToolbarOptionView(false, text, R.drawable.mx_amenity_fuel, new View.OnClickListener() { @Override public void onClick(View v) { - routingOptionsHelper.showDialog((RoutingOptionsHelper.LocalRoutingParameterGroup) parameter, mapActivity, new RoutingOptionsHelper.OnClickListener() { + routingOptionsHelper.showLocalRoutingParameterGroupDialog((RoutingOptionsHelper.LocalRoutingParameterGroup) parameter, mapActivity, new RoutingOptionsHelper.OnClickListener() { @Override - public void onClick(String text) { - Toast.makeText(app, text, Toast.LENGTH_LONG).show(); + public void onClick() { updateOptionsButtons(mainView); } }); @@ -793,39 +716,106 @@ public class MapRouteInfoMenu implements IRouteInformationListener { }); optionsContainer.addView(item, lp); } else { + String text; + boolean active; if (parameter.routingParameter != null) { - boolean checked; if (parameter.routingParameter.getId().equals("short_way")) { // if short route settings - it should be inverse of fast_route_mode - checked = !settings.FAST_ROUTE_MODE.getModeValue(routingHelper.getAppMode()); + active = !settings.FAST_ROUTE_MODE.getModeValue(routingHelper.getAppMode()); } else { - checked = parameter.isSelected(settings); + active = parameter.isSelected(settings); } - textView.setTextColor(checked ? colorActive : colorDisabled); - textView.setText(parameter.getText(mapActivity)); - } - Drawable itemDrawable = app.getUIUtilities().getIcon(R.drawable.mx_amenity_fuel, nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light); - if (Build.VERSION.SDK_INT >= 21) { - Drawable activeItemDrawable = app.getUIUtilities().getIcon(R.drawable.mx_amenity_fuel, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light); - itemDrawable = AndroidUtils.createPressedStateListDrawable(itemDrawable, activeItemDrawable); - } - imageView.setImageDrawable(itemDrawable); - item.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (parameter.routingParameter != null) { - boolean selected = parameter.isSelected(settings); - routingOptionsHelper.applyRoutingParameter(parameter, !selected); - textView.setTextColor(parameter.isSelected(settings) ? colorActive : colorDisabled); + text = parameter.getText(mapActivity); + View item = createToolbarOptionView(active, text, R.drawable.mx_amenity_fuel, new View.OnClickListener() { + @Override + public void onClick(View v) { + if (parameter.routingParameter != null) { + boolean selected = parameter.isSelected(settings); + routingOptionsHelper.applyRoutingParameter(parameter, !selected); + ((TextView) v.findViewById(R.id.route_option_title)).setTextColor(parameter.isSelected(settings) ? colorActive : colorDisabled); + } } - } - }); - optionsContainer.addView(item, lp); + }); + LinearLayout.LayoutParams newLp2 = new LinearLayout.LayoutParams(AndroidUtils.dpToPx(app, 100), ViewGroup.LayoutParams.MATCH_PARENT); + newLp2.setMargins(margin, 0, margin, 0); + optionsContainer.addView(item, newLp2); + } } } optionsContainer.setPadding(optionsContainer.getPaddingLeft(), optionsContainer.getPaddingTop(), options.getWidth(), optionsContainer.getPaddingBottom()); } + private LinearLayout createToolbarOptionView(boolean active, String title, @DrawableRes int iconId, View.OnClickListener listener) { + final LinearLayout item = (LinearLayout) mapActivity.getLayoutInflater().inflate(R.layout.route_option_btn, null); + final TextView textView = (TextView) item.findViewById(R.id.route_option_title); + final ImageView imageView = (ImageView) item.findViewById(R.id.route_option_image_view); + 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); + + AndroidUtils.setBackground(app, item, 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, item.findViewById(R.id.route_option_container), nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); + } + + Drawable itemDrawable = null; + Drawable activeItemDrawable = null; + if (iconId != -1) { + itemDrawable = app.getUIUtilities().getIcon(iconId, nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light); + activeItemDrawable = app.getUIUtilities().getIcon(iconId, 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); + } + } + if (title == null) { + textView.setVisibility(View.GONE); + if (activeItemDrawable != null) { + imageView.setImageDrawable(activeItemDrawable); + } else { + imageView.setVisibility(View.GONE); + } + } else { + textView.setVisibility(View.VISIBLE); + textView.setTextColor(active ? colorActive : colorDisabled); + textView.setText(title); + if (itemDrawable != null) { + imageView.setImageDrawable(itemDrawable); + } else { + imageView.setVisibility(View.GONE); + } + } + item.setOnClickListener(listener); + + return item; + } + + private LinearLayout createToolbarSubOptionView(boolean hideTextLine, String title, @DrawableRes int iconId, boolean lastItem, View.OnClickListener listener) { + final LinearLayout container = (LinearLayout) mapActivity.getLayoutInflater().inflate(R.layout.route_options_container, null); + final TextView routeOptionTV = (TextView) container.findViewById(R.id.route_removable_option_title); + final ImageView routeOptionImageView = (ImageView) container.findViewById(R.id.removable_option_icon); + + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { + AndroidUtils.setForeground(app, container, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); + } else { + AndroidUtils.setForeground(app, container, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); + } + AndroidUtils.setBackground(app, container.findViewById(R.id.options_divider_end), nightMode, R.color.divider_light, R.color.divider_dark); + AndroidUtils.setBackground(app, routeOptionImageView, nightMode, R.drawable.route_info_trans_gradient_light, R.drawable.route_info_trans_gradient_dark); + + if (lastItem) { + container.findViewById(R.id.options_divider_end).setVisibility(View.GONE); + }else { + container.findViewById(R.id.options_divider_end).setVisibility(View.VISIBLE); + } + if (hideTextLine) { + container.findViewById(R.id.title_divider).setVisibility(View.GONE); + } + routeOptionTV.setText(title); + routeOptionImageView.setImageDrawable(app.getUIUtilities().getIcon(iconId, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light)); + container.setOnClickListener(listener); + + return container; + } + private String getText(@Nullable RouteDataObject obj) { if (obj != null) { String locale = app.getSettings().MAP_PREFERRED_LOCALE.get(); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java index 0839f306ec..75fec5b315 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java @@ -3,13 +3,9 @@ package net.osmand.plus.routepreparationmenu; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; import android.support.v4.app.FragmentManager; import android.support.v7.app.AlertDialog; -import android.util.TypedValue; import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; @@ -17,8 +13,6 @@ import android.widget.Toast; import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; import net.osmand.plus.ApplicationMode; -import net.osmand.plus.ContextMenuAdapter; -import net.osmand.plus.ContextMenuItem; import net.osmand.plus.GPXUtilities; import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; @@ -77,12 +71,13 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { routingHelper = app.getRoutingHelper(); routingOptionsHelper = app.getRoutingOptionsHelper(); mapActivity = getMapActivity(); - controlsLayer = mapActivity.getMapLayers().getMapControlsLayer(); applicationMode = routingHelper.getAppMode(); } @Override public void createMenuItems(Bundle savedInstanceState) { + controlsLayer = mapActivity.getMapLayers().getMapControlsLayer(); + items.add(new TitleItem(app.getString(R.string.shared_string_settings), nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light)); List list = new ArrayList<>(); @@ -121,7 +116,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { } else if (optionsItem instanceof ShowAlongTheRouteItem) { BaseBottomSheetItem showAlongTheRouteItem = new SimpleBottomSheetItem.Builder() - .setIcon(getContentIcon(R.drawable.ic_action_snap_to_road)) + .setIcon(getContentIcon(R.drawable.ic_action_show_along_route)) .setTitle(getString(R.string.show_along_the_route)) .setLayoutId(R.layout.bottom_sheet_item_simple) .setOnClickListener(new View.OnClickListener() { @@ -187,7 +182,6 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { }) .create(); items.add(avoidRoadsRoutingParameter); - } else if (optionsItem instanceof GpxLocalRoutingParameter) { View v = mapActivity.getLayoutInflater().inflate(R.layout.plan_route_gpx, null); AndroidUtils.setListItemBackground(mapActivity, v, nightMode); @@ -210,7 +204,6 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { }) .create(); items.add(gpxLocalRoutingParameter); - } else if (optionsItem instanceof OtherSettingsRoutingParameter) { BaseBottomSheetItem otherSettingsRoutingParameter = new SimpleBottomSheetItem.Builder() .setIcon(getContentIcon(R.drawable.map_action_settings)) @@ -280,7 +273,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { final LocalRoutingParameter parameter = (LocalRoutingParameter) optionsItem; final BottomSheetItemWithCompoundButton[] item = new BottomSheetItemWithCompoundButton[1]; BottomSheetItemWithCompoundButton.Builder builder = new BottomSheetItemWithCompoundButton.Builder(); - builder.setIcon(getContentIcon(R.drawable.mx_amenity_fuel)); + builder.setIcon(getContentIcon(R.drawable.ic_action_fuel)); if (parameter.routingParameter != null) { builder.setTitle(parameter.getText(mapActivity)); } @@ -296,73 +289,15 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { @Override public void onClick(View v) { routingOptionsHelper.addNewRouteMenuParameter(applicationMode, parameter); - - final ContextMenuAdapter adapter = new ContextMenuAdapter(); - int i = 0; - int selectedIndex = -1; - for (LocalRoutingParameter p : group.getRoutingParameters()) { - adapter.addItem(ContextMenuItem.createBuilder(p.getText(mapActivity)) - .setSelected(false).createItem()); - if (p.isSelected(settings)) { - selectedIndex = i; - } - i++; - } - if (selectedIndex == -1) { - selectedIndex = 0; - } - - AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity); - final int layout = R.layout.list_menu_item_native_singlechoice; - - final ArrayAdapter listAdapter = new ArrayAdapter(mapActivity, layout, R.id.text1, - adapter.getItemNames()) { - @NonNull + routingOptionsHelper.showLocalRoutingParameterGroupDialog(group, mapActivity, new RoutingOptionsHelper.OnClickListener() { @Override - public View getView(final int position, View convertView, ViewGroup parent) { - // User super class to create the View - View v = convertView; - if (v == null) { - v = mapActivity.getLayoutInflater().inflate(layout, null); + public void onClick() { + LocalRoutingParameter selected = group.getSelected(settings); + if (selected != null) { + item[0].setDescription(selected.getText(mapActivity)); } - final ContextMenuItem item = adapter.getItem(position); - TextView tv = (TextView) v.findViewById(R.id.text1); - tv.setText(item.getTitle()); - tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f); - - return v; - } - }; - - final int[] selectedPosition = {selectedIndex}; - builder.setSingleChoiceItems(listAdapter, selectedIndex, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int position) { - selectedPosition[0] = position; } }); - builder.setTitle(group.getText(mapActivity)) - .setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - int position = selectedPosition[0]; - if (position >= 0 && position < group.getRoutingParameters().size()) { - for (int i = 0; i < group.getRoutingParameters().size(); i++) { - LocalRoutingParameter rp = group.getRoutingParameters().get(i); - rp.setSelected(settings, i == position); - } - mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange(); - LocalRoutingParameter selected = group.getSelected(settings); - if (selected != null) { - item[0].setDescription(selected.getText(mapActivity)); - } - } - } - }) - .setNegativeButton(R.string.shared_string_cancel, null); - - builder.create().show(); } }); } else { diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java index 51454d95c9..13decddc70 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java @@ -31,7 +31,6 @@ import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.helpers.FileNameTranslationHelper; -import net.osmand.plus.mapcontextmenu.TransportStopRouteAdapter; import net.osmand.plus.routing.RouteProvider; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.voice.JSMediaCommandPlayerImpl; @@ -277,16 +276,15 @@ public class RoutingOptionsHelper { } public interface OnClickListener { - void onClick(String text); + void onClick(); } - public void showDialog(final LocalRoutingParameterGroup group, final MapActivity mapActivity, final OnClickListener listener) { + public void showLocalRoutingParameterGroupDialog(final LocalRoutingParameterGroup group, final MapActivity mapActivity, final OnClickListener listener) { final ContextMenuAdapter adapter = new ContextMenuAdapter(); int i = 0; int selectedIndex = -1; for (LocalRoutingParameter p : group.getRoutingParameters()) { - adapter.addItem(ContextMenuItem.createBuilder(p.getText(mapActivity)) - .setSelected(false).createItem()); + adapter.addItem(ContextMenuItem.createBuilder(p.getText(mapActivity)).setSelected(false).createItem()); if (p.isSelected(settings)) { selectedIndex = i; } @@ -295,12 +293,10 @@ public class RoutingOptionsHelper { if (selectedIndex == -1) { selectedIndex = 0; } - AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity); final int layout = R.layout.list_menu_item_native_singlechoice; - final ArrayAdapter listAdapter = new ArrayAdapter(mapActivity, layout, R.id.text1, - adapter.getItemNames()) { + final ArrayAdapter listAdapter = new ArrayAdapter(mapActivity, layout, R.id.text1, adapter.getItemNames()) { @NonNull @Override public View getView(final int position, View convertView, ViewGroup parent) { @@ -327,7 +323,6 @@ public class RoutingOptionsHelper { }); builder.setTitle(group.getText(mapActivity)) .setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { - @Override public void onClick(DialogInterface dialog, int which) { int position = selectedPosition[0]; @@ -337,15 +332,13 @@ public class RoutingOptionsHelper { rp.setSelected(settings, i == position); } mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange(); - LocalRoutingParameter selected = group.getSelected(settings); - if (selected != null&&listener != null) { - listener.onClick(selected.getText(mapActivity)); + if (listener != null) { + listener.onClick(); } } } }) .setNegativeButton(R.string.shared_string_cancel, null); - builder.create().show(); } @@ -507,6 +500,13 @@ public class RoutingOptionsHelper { return true; } + public String getId() { + if (routingParameter != null) { + return routingParameter.getId(); + } + return KEY; + } + public LocalRoutingParameter(ApplicationMode am) { this.am = am; } @@ -548,6 +548,13 @@ public class RoutingOptionsHelper { private String groupName; private List routingParameters = new ArrayList<>(); + public String getId() { + if (groupName != null) { + return groupName; + } + return KEY; + } + public LocalRoutingParameterGroup(ApplicationMode am, String groupName) { super(am); this.groupName = groupName; @@ -596,6 +603,10 @@ public class RoutingOptionsHelper { public static final String KEY = "MuteSoundRoutingParameter"; + public String getId() { + return KEY; + } + public MuteSoundRoutingParameter() { super(null); } @@ -605,6 +616,10 @@ public class RoutingOptionsHelper { public static final String KEY = "DividerItem"; + public String getId() { + return KEY; + } + public boolean canAddToRouteMenu() { return false; } @@ -618,6 +633,10 @@ public class RoutingOptionsHelper { public static final String KEY = "RouteSimulationItem"; + public String getId() { + return KEY; + } + public boolean canAddToRouteMenu() { return false; } @@ -631,6 +650,10 @@ public class RoutingOptionsHelper { public static final String KEY = "ShowAlongTheRouteItem"; + public String getId() { + return KEY; + } + public ShowAlongTheRouteItem() { super(null); } @@ -640,6 +663,10 @@ public class RoutingOptionsHelper { public static final String KEY = "AvoidRoadsRoutingParameter"; + public String getId() { + return KEY; + } + public AvoidRoadsRoutingParameter() { super(null); } @@ -650,6 +677,10 @@ public class RoutingOptionsHelper { public static final String KEY = "AvoidRoadsTypesRoutingParameter"; + public String getId() { + return KEY; + } + public AvoidRoadsTypesRoutingParameter() { super(null); } @@ -660,6 +691,10 @@ public class RoutingOptionsHelper { public static final String KEY = "GpxLocalRoutingParameter"; + public String getId() { + return KEY; + } + public boolean canAddToRouteMenu() { return false; } @@ -673,6 +708,10 @@ public class RoutingOptionsHelper { public static final String KEY = "OtherSettingsRoutingParameter"; + public String getId() { + return KEY; + } + public boolean canAddToRouteMenu() { return false; } @@ -686,6 +725,10 @@ public class RoutingOptionsHelper { public static final String KEY = "OtherLocalRoutingParameter"; + public String getId() { + return KEY; + } + public boolean canAddToRouteMenu() { return false; } @@ -721,6 +764,10 @@ public class RoutingOptionsHelper { public static final String KEY = "InterruptMusicRoutingParameter"; + public String getId() { + return KEY; + } + public InterruptMusicRoutingParameter() { super(null); } @@ -730,6 +777,10 @@ public class RoutingOptionsHelper { public static final String KEY = "VoiceGuidanceRoutingParameter"; + public String getId() { + return KEY; + } + public VoiceGuidanceRoutingParameter() { super(null); } @@ -748,7 +799,7 @@ public class RoutingOptionsHelper { public boolean containsParameter(LocalRoutingParameter parameter) { for (LocalRoutingParameter p : parameters) { - if (p.getClass().equals(parameter.getClass())) { + if (p.getId().equals(parameter.getId())) { return true; } }