From 18be0c4aa9cabcf5ece9ec5c531945d8da047609 Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 4 Jun 2018 18:53:16 +0300 Subject: [PATCH] add choose dialog for quick actions menu for map view properties(style,source,underlay,overlay) --- .../layout/quick_action_switchable_action.xml | 42 +++ OsmAnd/res/values/strings.xml | 1 + .../SelectMapViewQuickActionsBottomSheet.java | 337 ++++++++++++++++++ .../plus/quickaction/SwitchableAction.java | 9 +- .../quickaction/actions/MapOverlayAction.java | 27 ++ .../quickaction/actions/MapSourceAction.java | 27 ++ .../quickaction/actions/MapStyleAction.java | 24 +- .../actions/MapUnderlayAction.java | 27 ++ 8 files changed, 491 insertions(+), 3 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/dialogs/SelectMapViewQuickActionsBottomSheet.java diff --git a/OsmAnd/res/layout/quick_action_switchable_action.xml b/OsmAnd/res/layout/quick_action_switchable_action.xml index 8fa9f331d9..22f91d49e4 100644 --- a/OsmAnd/res/layout/quick_action_switchable_action.xml +++ b/OsmAnd/res/layout/quick_action_switchable_action.xml @@ -6,6 +6,48 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical"> + + + + + + + + + + + + + Edit actions Get OsmAnd Live to unlock all features: Daily map updates with unlimited downloads, all paid and free plugins, Wikipedia, Wikivoyage and much more. Modification of the default style to increase contrast of pedestrian and bicycle roads. Uses legacy Mapnik colors. Bookmark diff --git a/OsmAnd/src/net/osmand/plus/dialogs/SelectMapViewQuickActionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/dialogs/SelectMapViewQuickActionsBottomSheet.java new file mode 100644 index 0000000000..8a36d882ee --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/dialogs/SelectMapViewQuickActionsBottomSheet.java @@ -0,0 +1,337 @@ +package net.osmand.plus.dialogs; + + +import android.app.Activity; +import android.content.Context; +import android.content.res.ColorStateList; +import android.os.Bundle; +import android.support.annotation.ColorInt; +import android.support.annotation.Nullable; +import android.support.v4.util.Pair; +import android.support.v4.widget.CompoundButtonCompat; +import android.support.v4.widget.NestedScrollView; +import android.view.ContextThemeWrapper; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.LinearLayout.LayoutParams; +import android.widget.RadioButton; +import android.widget.TextView; +import android.widget.Toast; + +import net.osmand.AndroidUtils; +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; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; +import net.osmand.plus.quickaction.QuickActionFactory; +import net.osmand.plus.quickaction.actions.MapStyleAction; +import net.osmand.plus.quickaction.actions.MapSourceAction; +import net.osmand.plus.quickaction.actions.MapOverlayAction; +import net.osmand.plus.quickaction.actions.MapUnderlayAction; +import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; +import net.osmand.plus.render.RendererRegistry; +import net.osmand.plus.views.OsmandMapTileView; +import net.osmand.render.RenderingRulesStorage; +import net.osmand.util.Algorithms; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogFragment { + + public static final String TAG = SelectMapViewQuickActionsBottomSheet.class.getSimpleName(); + + private static final String SELECTED_ITEM_KEY = "selected_item"; + private static final String LAYER_OSM_VECTOR = "LAYER_OSM_VECTOR"; + private static final String KEY_NO_OVERLAY = "no_overlay"; + private static final String KEY_NO_UNDERLAY = "no_underlay"; + private static final String MAP = "map"; + + private LinearLayout stylesContainer; + private View.OnClickListener onClickListener; + private ColorStateList rbColorList; + private OsmandSettings settings; + + private ArrayList stylesList; + private HashMap pairsMap; + private String selectedItem; + private int type; + + @Override + @SuppressWarnings("unchecked") + public void createMenuItems(Bundle savedInstanceState) { + final Context context = getContext(); + if (context == null) { + return; + } + if (getArguments() == null) { + return; + } + Bundle args = getArguments(); + + type = args.getInt("type"); + if (type == MapStyleAction.TYPE) { + stylesList = args.getStringArrayList("test"); + } else { + pairsMap = (HashMap) args.getSerializable(MAP); + } + OsmandApplication app = (OsmandApplication) context.getApplicationContext(); + settings = app.getSettings(); + if (Algorithms.isEmpty(stylesList) && Algorithms.isEmpty(pairsMap)) { + return; + } + if (savedInstanceState != null) { + selectedItem = savedInstanceState.getString(SELECTED_ITEM_KEY); + } else { + if (type == MapStyleAction.TYPE) { + RenderingRulesStorage current = app.getRendererRegistry().getCurrentSelectedRenderer(); + if (current != null) { + selectedItem = current.getName(); + } else { + selectedItem = RendererRegistry.DEFAULT_RENDER; + } + } else if (type == MapSourceAction.TYPE) { + Pair currentPairItem = settings.MAP_ONLINE_DATA.get() + ? new Pair<>(settings.MAP_TILE_SOURCES.get(), settings.MAP_TILE_SOURCES.get()) + : new Pair<>(LAYER_OSM_VECTOR, getString(R.string.vector_data)); + selectedItem = currentPairItem.first; + } else if (type == MapUnderlayAction.TYPE) { + selectedItem = settings.MAP_UNDERLAY.get(); + } else if (type == MapOverlayAction.TYPE) { + selectedItem = settings.MAP_OVERLAY.get(); + } + } + rbColorList = AndroidUtils.createCheckedColorStateList(context, R.color.icon_color, getActiveColorId()); + + items.add(new TitleItem(getTitle())); + + NestedScrollView nestedScrollView = new NestedScrollView(context); + stylesContainer = new LinearLayout(context); + stylesContainer.setLayoutParams((new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT))); + stylesContainer.setOrientation(LinearLayout.VERTICAL); + stylesContainer.setPadding(0, getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small), + 0, getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small)); + + int itemsSize = 0; + if (type == MapSourceAction.TYPE || type == MapUnderlayAction.TYPE || type == MapOverlayAction.TYPE) { + itemsSize = pairsMap.size(); + } else if (type == MapStyleAction.TYPE) { + itemsSize = stylesList.size(); + } + for (int i = 0; i < itemsSize; i++) { + LayoutInflater.from(new ContextThemeWrapper(context, themeRes)) + .inflate(R.layout.bottom_sheet_item_with_radio_btn, stylesContainer, true); + } + + nestedScrollView.addView(stylesContainer); + items.add(new BaseBottomSheetItem.Builder().setCustomView(nestedScrollView).create()); + + populateItemsList(); + } + + private String getTitle() { + switch (type) { + case MapOverlayAction.TYPE: + return getString(R.string.map_overlay); + case MapUnderlayAction.TYPE: + return getString(R.string.map_underlay); + case MapSourceAction.TYPE: + return getString(R.string.map_source); + case MapStyleAction.TYPE: + return getString(R.string.map_widget_renderer); + } + return ""; + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putString(SELECTED_ITEM_KEY, selectedItem); + } + + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_close; + } + + @Override + protected void onRightBottomButtonClick() { + dismiss(); + } + + @Override + protected int getDismissButtonTextId() { + return R.string.quick_action_edit_actions; + } + + @Override + protected void onDismissButtonClickAction() { + MapActivity mapActivity = getMapActivity(); + if (mapActivity == null) { + return; + } + if (type == MapStyleAction.TYPE) { + changeMapStyle(mapActivity); + } else if (type == MapSourceAction.TYPE) { + changeMapSource(mapActivity); + } else if (type == MapOverlayAction.TYPE) { + changeMapOverlay(mapActivity); + } else if (type == MapUnderlayAction.TYPE) { + changeMapUnderlay(mapActivity); + } + } + + + private void changeMapStyle(MapActivity mapActivity) { + OsmandApplication app = mapActivity.getMyApplication(); + RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(selectedItem); + if (loaded != null) { + OsmandMapTileView view = mapActivity.getMapView(); + view.getSettings().RENDERER.set(selectedItem); + app.getRendererRegistry().setCurrentSelectedRender(loaded); + ConfigureMapMenu.refreshMapComplete(mapActivity); + mapActivity.getDashboard().refreshContent(true); + Toast.makeText(mapActivity, mapActivity.getString(R.string.quick_action_map_style_switch, selectedItem), Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(mapActivity, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show(); + } + } + + private void changeMapSource(MapActivity mapActivity) { + if (selectedItem.equals(LAYER_OSM_VECTOR)) { + settings.MAP_ONLINE_DATA.set(false); + mapActivity.getMapLayers().updateMapSource(mapActivity.getMapView(), null); + } else { + settings.MAP_TILE_SOURCES.set(selectedItem); + settings.MAP_ONLINE_DATA.set(true); + mapActivity.getMapLayers().updateMapSource(mapActivity.getMapView(), settings.MAP_TILE_SOURCES); + } + Toast.makeText(mapActivity, getString(R.string.quick_action_map_source_switch, pairsMap.get(selectedItem)), Toast.LENGTH_SHORT).show(); + } + + private void changeMapOverlay(MapActivity mapActivity) { + OsmandRasterMapsPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class); + if (plugin != null) { + boolean hasOverlay = !selectedItem.equals(KEY_NO_OVERLAY); + if (hasOverlay) { + settings.MAP_OVERLAY.set(selectedItem); + settings.MAP_OVERLAY_PREVIOUS.set(selectedItem); + } else { + settings.MAP_OVERLAY.set(null); + settings.MAP_OVERLAY_PREVIOUS.set(null); + } + plugin.updateMapLayers(mapActivity.getMapView(), settings.MAP_OVERLAY, mapActivity.getMapLayers()); + Toast.makeText(mapActivity, getString(R.string.quick_action_map_overlay_switch, pairsMap.get(selectedItem)), Toast.LENGTH_SHORT).show(); + } + } + + private void changeMapUnderlay(MapActivity mapActivity) { + OsmandRasterMapsPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class); + if (plugin != null) { + boolean hasUnderlay = !selectedItem.equals(KEY_NO_UNDERLAY); + if (hasUnderlay) { + settings.MAP_UNDERLAY.set(selectedItem); + settings.MAP_UNDERLAY_PREVIOUS.set(selectedItem); + } else { + settings.MAP_UNDERLAY.set(null); + settings.MAP_UNDERLAY_PREVIOUS.set(null); + } + final OsmandSettings.CommonPreference hidePolygonsPref = + mapActivity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons"); + hidePolygonsPref.set(hasUnderlay); + + plugin.updateMapLayers(mapActivity.getMapView(), settings.MAP_UNDERLAY, mapActivity.getMapLayers()); + Toast.makeText(mapActivity, getString(R.string.quick_action_map_underlay_switch, pairsMap.get(selectedItem)), Toast.LENGTH_SHORT).show(); + } + } + + @Override + protected boolean useScrollableItemsContainer() { + return false; + } + + @Nullable + private MapActivity getMapActivity() { + Activity activity = getActivity(); + if (activity != null && activity instanceof MapActivity) { + return (MapActivity) activity; + } + return null; + } + + private void populateItemsList() { + Context context = getContext(); + if (context == null) { + return; + } + int counter = 0; + if (type == MapStyleAction.TYPE) { + for (String entry : stylesList) { + boolean selected = entry.equals(selectedItem); + createItemRow(selected, counter, entry, entry, context); + counter++; + } + } else if (type == MapSourceAction.TYPE || type == MapOverlayAction.TYPE || type == MapUnderlayAction.TYPE) { + for (Map.Entry entry : pairsMap.entrySet()) { + String tag = entry.getKey(); + boolean selected = tag.equals(selectedItem); + createItemRow(selected, counter, entry.getValue(), tag, context); + counter++; + } + } + } + + private void createItemRow(boolean selected, int counter, String text, String tag, Context context) { + View view = stylesContainer.getChildAt(counter); + view.setTag(tag); + view.setOnClickListener(getOnClickListener()); + + TextView titleTv = (TextView) view.findViewById(R.id.title); + titleTv.setText(text); + titleTv.setTextColor(getStyleTitleColor(selected)); + + RadioButton rb = (RadioButton) view.findViewById(R.id.compound_button); + rb.setChecked(selected); + CompoundButtonCompat.setButtonTintList(rb, rbColorList); + ImageView imageView = (ImageView) view.findViewById(R.id.icon); + imageView.setImageDrawable(((OsmandApplication) context.getApplicationContext()) + .getIconsCache().getThemedIcon(QuickActionFactory.getActionIcon(type))); + } + + @ColorInt + private int getStyleTitleColor(boolean selected) { + int colorId = selected + ? getActiveColorId() + : nightMode ? R.color.primary_text_dark : R.color.primary_text_light; + return getResolvedColor(colorId); + } + + private View.OnClickListener getOnClickListener() { + if (onClickListener == null) { + onClickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + Context context = getContext(); + if (context == null) { + return; + } + selectedItem = (String) v.getTag(); + if (type == MapStyleAction.TYPE) { + Toast.makeText(context, selectedItem, Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(context, pairsMap.get(selectedItem), Toast.LENGTH_SHORT).show(); + } + populateItemsList(); + } + }; + } + return onClickListener; + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/quickaction/SwitchableAction.java b/OsmAnd/src/net/osmand/plus/quickaction/SwitchableAction.java index 1fcd721482..8b41e0f9c2 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/SwitchableAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/SwitchableAction.java @@ -4,6 +4,7 @@ import android.content.Context; import android.support.annotation.StringRes; import android.support.v4.view.MotionEventCompat; import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.SwitchCompat; import android.support.v7.widget.helper.ItemTouchHelper; import android.view.LayoutInflater; import android.view.MotionEvent; @@ -23,6 +24,7 @@ import java.util.List; public abstract class SwitchableAction extends QuickAction { + protected static final String KEY_DIALOG = "dialog"; private transient EditText title; protected SwitchableAction(int type) { @@ -43,7 +45,12 @@ public abstract class SwitchableAction extends QuickAction { View view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.quick_action_switchable_action, parent, false); - + + SwitchCompat showDialog = (SwitchCompat) view.findViewById(R.id.saveButton); + if (!getParams().isEmpty()) { + showDialog.setChecked(Boolean.valueOf(getParams().get(KEY_DIALOG))); + } + final RecyclerView list = (RecyclerView) view.findViewById(R.id.list); final QuickActionItemTouchHelperCallback touchHelperCallback = new QuickActionItemTouchHelperCallback(); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapOverlayAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/MapOverlayAction.java index df7ece07c2..0eefef4750 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapOverlayAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/MapOverlayAction.java @@ -1,8 +1,10 @@ package net.osmand.plus.quickaction.actions; import android.content.DialogInterface; +import android.os.Bundle; import android.support.v4.util.Pair; import android.support.v7.app.AlertDialog; +import android.support.v7.widget.SwitchCompat; import android.view.View; import android.widget.ArrayAdapter; import android.widget.Toast; @@ -14,12 +16,14 @@ import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.dialogs.SelectMapViewQuickActionsBottomSheet; import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.SwitchableAction; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import java.lang.reflect.Type; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -82,6 +86,22 @@ public class MapOverlayAction extends SwitchableAction> { OsmandSettings settings = activity.getMyApplication().getSettings(); List> sources = loadListFromParams(); + boolean showBottomSheetStyles = Boolean.valueOf(getParams().get(KEY_DIALOG)); + if (showBottomSheetStyles) { + SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet(); + HashMap hashMap = new HashMap<>(); + for (Pair pair : sources) { + hashMap.put(pair.first, pair.second); + } + Bundle args = new Bundle(); + args.putInt("type", TYPE); + args.putSerializable("map", hashMap); + fragment.setArguments(args); + fragment.show(activity.getSupportFragmentManager(), + SelectMapViewQuickActionsBottomSheet.TAG); + return; + } + Pair currentSource = new Pair<>( settings.MAP_OVERLAY.get(), settings.MAP_OVERLAY.get()); @@ -165,4 +185,11 @@ public class MapOverlayAction extends SwitchableAction> { } }; } + + @Override + public boolean fillParams(View root, MapActivity activity) { + super.fillParams(root, activity); + getParams().put(KEY_DIALOG, Boolean.toString(((SwitchCompat) root.findViewById(R.id.saveButton)).isChecked())); + return true; + } } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapSourceAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/MapSourceAction.java index 22d32295ef..2b32244697 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapSourceAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/MapSourceAction.java @@ -1,8 +1,10 @@ package net.osmand.plus.quickaction.actions; import android.content.DialogInterface; +import android.os.Bundle; import android.support.v4.util.Pair; import android.support.v7.app.AlertDialog; +import android.support.v7.widget.SwitchCompat; import android.view.View; import android.widget.ArrayAdapter; import android.widget.Toast; @@ -14,12 +16,14 @@ import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.dialogs.SelectMapViewQuickActionsBottomSheet; import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.SwitchableAction; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import java.lang.reflect.Type; import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -76,6 +80,22 @@ public class MapSourceAction extends SwitchableAction> { OsmandSettings settings = activity.getMyApplication().getSettings(); List> sources = loadListFromParams(); + boolean showBottomSheetStyles = Boolean.valueOf(getParams().get(KEY_DIALOG)); + if (showBottomSheetStyles) { + SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet(); + HashMap hashMap = new HashMap<>(); + for (Pair pair : sources) { + hashMap.put(pair.first, pair.second); + } + Bundle args = new Bundle(); + args.putInt("type", TYPE); + args.putSerializable("map", hashMap); + fragment.setArguments(args); + fragment.show(activity.getSupportFragmentManager(), + SelectMapViewQuickActionsBottomSheet.TAG); + return; + } + Pair currentSource = settings.MAP_ONLINE_DATA.get() ? new Pair<>(settings.MAP_TILE_SOURCES.get(), settings.MAP_TILE_SOURCES.get()) : new Pair<>(LAYER_OSM_VECTOR, activity.getString(R.string.vector_data)); @@ -173,4 +193,11 @@ public class MapSourceAction extends SwitchableAction> { protected String getItemName(Pair item) { return item.second; } + + @Override + public boolean fillParams(View root, MapActivity activity) { + super.fillParams(root, activity); + getParams().put(KEY_DIALOG, Boolean.toString(((SwitchCompat) root.findViewById(R.id.saveButton)).isChecked())); + return true; + } } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapStyleAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/MapStyleAction.java index b2e7de06c2..d3628ec79d 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapStyleAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/MapStyleAction.java @@ -1,7 +1,9 @@ package net.osmand.plus.quickaction.actions; import android.content.DialogInterface; +import android.os.Bundle; import android.support.v7.app.AlertDialog; +import android.support.v7.widget.SwitchCompat; import android.text.TextUtils; import android.view.View; import android.widget.ArrayAdapter; @@ -12,6 +14,7 @@ import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dialogs.ConfigureMapMenu; +import net.osmand.plus.dialogs.SelectMapViewQuickActionsBottomSheet; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.SwitchableAction; @@ -42,7 +45,17 @@ public class MapStyleAction extends SwitchableAction { public void execute(MapActivity activity) { List mapStyles = getFilteredStyles(); - + boolean showBottomSheetStyles = Boolean.valueOf(getParams().get(KEY_DIALOG)); + if (showBottomSheetStyles) { + SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet(); + Bundle args = new Bundle(); + args.putStringArrayList("test", (ArrayList) mapStyles); + args.putInt("type", TYPE); + fragment.setArguments(args); + fragment.show(activity.getSupportFragmentManager(), + SelectMapViewQuickActionsBottomSheet.TAG); + return; + } String curStyle = activity.getMyApplication().getSettings().RENDERER.get(); int index = mapStyles.indexOf(curStyle); String nextStyle = mapStyles.get(0); @@ -165,6 +178,13 @@ public class MapStyleAction extends SwitchableAction { getParams().put(getListKey(), TextUtils.join(",", styles)); } + @Override + public boolean fillParams(View root, MapActivity activity) { + super.fillParams(root, activity); + getParams().put(KEY_DIALOG, Boolean.toString(((SwitchCompat) root.findViewById(R.id.saveButton)).isChecked())); + return true; + } + @Override protected List loadListFromParams() { @@ -193,4 +213,4 @@ public class MapStyleAction extends SwitchableAction { ? filters.get(0) + " +" + (filters.size() - 1) : filters.get(0); } -} +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapUnderlayAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/MapUnderlayAction.java index 162b48a1fe..39c14c4dba 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapUnderlayAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/MapUnderlayAction.java @@ -1,8 +1,10 @@ package net.osmand.plus.quickaction.actions; import android.content.DialogInterface; +import android.os.Bundle; import android.support.v4.util.Pair; import android.support.v7.app.AlertDialog; +import android.support.v7.widget.SwitchCompat; import android.view.View; import android.widget.ArrayAdapter; import android.widget.Toast; @@ -14,12 +16,14 @@ import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.dialogs.SelectMapViewQuickActionsBottomSheet; import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.SwitchableAction; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import java.lang.reflect.Type; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -81,6 +85,22 @@ public class MapUnderlayAction extends SwitchableAction> { OsmandSettings settings = activity.getMyApplication().getSettings(); List> sources = loadListFromParams(); + boolean showBottomSheetStyles = Boolean.valueOf(getParams().get(KEY_DIALOG)); + if (showBottomSheetStyles) { + SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet(); + HashMap hashMap = new HashMap<>(); + for (Pair pair : sources) { + hashMap.put(pair.first, pair.second); + } + Bundle args = new Bundle(); + args.putInt("type", TYPE); + args.putSerializable("map", hashMap); + fragment.setArguments(args); + fragment.show(activity.getSupportFragmentManager(), + SelectMapViewQuickActionsBottomSheet.TAG); + return; + } + Pair currentSource = new Pair<>( settings.MAP_UNDERLAY.get(), settings.MAP_UNDERLAY.get()); @@ -168,4 +188,11 @@ public class MapUnderlayAction extends SwitchableAction> { } }; } + + @Override + public boolean fillParams(View root, MapActivity activity) { + super.fillParams(root, activity); + getParams().put(KEY_DIALOG, Boolean.toString(((SwitchCompat) root.findViewById(R.id.saveButton)).isChecked())); + return true; + } }