add QuickAction in choose dialog and executeWithParams for switchable actions

This commit is contained in:
Chumva 2018-06-06 15:31:03 +03:00
parent 08e8e8c972
commit fe478b7427
7 changed files with 151 additions and 275 deletions

View file

@ -19,11 +19,9 @@ import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
@ -31,133 +29,100 @@ import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.quickaction.CreateEditActionDialog; import net.osmand.plus.quickaction.CreateEditActionDialog;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionFactory; import net.osmand.plus.quickaction.QuickActionFactory;
import net.osmand.plus.quickaction.QuickActionRegistry;
import net.osmand.plus.quickaction.SwitchableAction;
import net.osmand.plus.quickaction.actions.MapStyleAction; import net.osmand.plus.quickaction.actions.MapStyleAction;
import net.osmand.plus.quickaction.actions.MapSourceAction; import net.osmand.plus.quickaction.actions.MapSourceAction;
import net.osmand.plus.quickaction.actions.MapOverlayAction; import net.osmand.plus.quickaction.actions.MapOverlayAction;
import net.osmand.plus.quickaction.actions.MapUnderlayAction; import net.osmand.plus.quickaction.actions.MapUnderlayAction;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.render.RenderingRulesStorage; import net.osmand.render.RenderingRulesStorage;
import net.osmand.util.Algorithms;
import java.util.ArrayList; import java.util.List;
import java.util.HashMap;
import java.util.Map;
import static net.osmand.plus.quickaction.SwitchableAction.KEY_ACTIONS_MAP;
import static net.osmand.plus.quickaction.SwitchableAction.KEY_ID;
import static net.osmand.plus.quickaction.SwitchableAction.KEY_TYPE;
import static net.osmand.plus.quickaction.actions.MapStyleAction.KEY_STYLES;
public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogFragment { public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogFragment {
public static final String TAG = SelectMapViewQuickActionsBottomSheet.class.getSimpleName(); public static final String TAG = SelectMapViewQuickActionsBottomSheet.class.getSimpleName();
private static final String SELECTED_ITEM_KEY = "selected_item"; 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 LinearLayout stylesContainer; private LinearLayout itemsContainer;
private View.OnClickListener onClickListener; private View.OnClickListener onClickListener;
private ColorStateList rbColorList; private ColorStateList rbColorList;
private OsmandSettings settings;
private ArrayList<String> stylesList;
private HashMap<String, String> pairsMap;
private String selectedItem; private String selectedItem;
private int type; private QuickAction action;
private long id;
@Override @Override
@SuppressWarnings("unchecked")
public void createMenuItems(Bundle savedInstanceState) { public void createMenuItems(Bundle savedInstanceState) {
final Context context = getContext();
if (context == null) {
return;
}
if (getArguments() == null) {
return;
}
Bundle args = getArguments(); Bundle args = getArguments();
if (args == null) {
type = args.getInt(KEY_TYPE);
id = args.getLong(KEY_ID);
if (type == MapStyleAction.TYPE) {
stylesList = args.getStringArrayList(KEY_STYLES);
} else {
pairsMap = (HashMap<String, String>) args.getSerializable(KEY_ACTIONS_MAP);
}
OsmandApplication app = (OsmandApplication) context.getApplicationContext();
settings = app.getSettings();
if (Algorithms.isEmpty(stylesList) && Algorithms.isEmpty(pairsMap)) {
return; return;
} }
MapActivity mapActivity = getMapActivity();
if (mapActivity == null) {
return;
}
long id = args.getLong(SwitchableAction.KEY_ID);
OsmandApplication app = mapActivity.getMyApplication();
QuickActionRegistry quickActionRegistry = mapActivity.getMapLayers().getQuickActionRegistry();
action = quickActionRegistry.getQuickAction(id);
action = QuickActionFactory.produceAction(action);
if (action == null) {
return;
}
OsmandSettings settings = app.getSettings();
if (savedInstanceState != null) { if (savedInstanceState != null) {
selectedItem = savedInstanceState.getString(SELECTED_ITEM_KEY); selectedItem = savedInstanceState.getString(SELECTED_ITEM_KEY);
} else { } else {
if (type == MapStyleAction.TYPE) { if (action instanceof MapStyleAction) {
RenderingRulesStorage current = app.getRendererRegistry().getCurrentSelectedRenderer(); RenderingRulesStorage current = app.getRendererRegistry().getCurrentSelectedRenderer();
if (current != null) { if (current != null) {
selectedItem = current.getName(); selectedItem = current.getName();
} else { } else {
selectedItem = RendererRegistry.DEFAULT_RENDER; selectedItem = RendererRegistry.DEFAULT_RENDER;
} }
} else if (type == MapSourceAction.TYPE) { } else if (action instanceof MapSourceAction) {
Pair<String, String> currentPairItem = settings.MAP_ONLINE_DATA.get() selectedItem = settings.MAP_ONLINE_DATA.get()
? new Pair<>(settings.MAP_TILE_SOURCES.get(), settings.MAP_TILE_SOURCES.get()) ? settings.MAP_TILE_SOURCES.get()
: new Pair<>(LAYER_OSM_VECTOR, getString(R.string.vector_data)); : MapSourceAction.LAYER_OSM_VECTOR;
selectedItem = currentPairItem.first; } else if (action instanceof MapUnderlayAction) {
} else if (type == MapUnderlayAction.TYPE) {
selectedItem = settings.MAP_UNDERLAY.get(); selectedItem = settings.MAP_UNDERLAY.get();
} else if (type == MapOverlayAction.TYPE) { } else if (action instanceof MapOverlayAction) {
selectedItem = settings.MAP_OVERLAY.get(); selectedItem = settings.MAP_OVERLAY.get();
} }
} }
rbColorList = AndroidUtils.createCheckedColorStateList(context, R.color.icon_color, getActiveColorId()); rbColorList = AndroidUtils.createCheckedColorStateList(app, R.color.icon_color, getActiveColorId());
items.add(new TitleItem(getTitle())); items.add(new TitleItem(action.getName(app)));
NestedScrollView nestedScrollView = new NestedScrollView(context); NestedScrollView nestedScrollView = new NestedScrollView(app);
stylesContainer = new LinearLayout(context); itemsContainer = new LinearLayout(app);
stylesContainer.setLayoutParams((new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT))); itemsContainer.setLayoutParams((new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)));
stylesContainer.setOrientation(LinearLayout.VERTICAL); itemsContainer.setOrientation(LinearLayout.VERTICAL);
stylesContainer.setPadding(0, getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small), int padding = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small);
0, getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small)); itemsContainer.setPadding(0, padding, 0, padding);
int itemsSize = 0; int itemsSize = 0;
if (type == MapSourceAction.TYPE || type == MapUnderlayAction.TYPE || type == MapOverlayAction.TYPE) { if (action instanceof SwitchableAction) {
itemsSize = pairsMap.size(); SwitchableAction switchableAction = (SwitchableAction) action;
} else if (type == MapStyleAction.TYPE) { List sources = switchableAction.loadListFromParams();
itemsSize = stylesList.size(); itemsSize = sources.size();
} }
for (int i = 0; i < itemsSize; i++) { for (int i = 0; i < itemsSize; i++) {
LayoutInflater.from(new ContextThemeWrapper(context, themeRes)) LayoutInflater.from(new ContextThemeWrapper(app, themeRes))
.inflate(R.layout.bottom_sheet_item_with_radio_btn, stylesContainer, true); .inflate(R.layout.bottom_sheet_item_with_radio_btn, itemsContainer, true);
} }
nestedScrollView.addView(stylesContainer); nestedScrollView.addView(itemsContainer);
items.add(new BaseBottomSheetItem.Builder().setCustomView(nestedScrollView).create()); items.add(new BaseBottomSheetItem.Builder().setCustomView(nestedScrollView).create());
populateItemsList(); 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 @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
@ -181,79 +146,14 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF
@Override @Override
protected void onDismissButtonClickAction() { protected void onDismissButtonClickAction() {
MapActivity mapActivity = getMapActivity();
FragmentManager fm = getFragmentManager(); FragmentManager fm = getFragmentManager();
if (mapActivity == null || fm == null) { if (fm == null) {
return; return;
} }
CreateEditActionDialog dialog = CreateEditActionDialog.newInstance(id); CreateEditActionDialog dialog = CreateEditActionDialog.newInstance(action.getId());
dialog.show(fm, CreateEditActionDialog.TAG); dialog.show(fm, CreateEditActionDialog.TAG);
} }
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<Boolean> 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 @Override
protected boolean useScrollableItemsContainer() { protected boolean useScrollableItemsContainer() {
return false; return false;
@ -274,24 +174,28 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF
return; return;
} }
int counter = 0; int counter = 0;
if (type == MapStyleAction.TYPE) { if (action instanceof MapStyleAction) {
MapStyleAction mapStyleAction = (MapStyleAction) action;
List<String> stylesList = mapStyleAction.getFilteredStyles();
for (String entry : stylesList) { for (String entry : stylesList) {
boolean selected = entry.equals(selectedItem); boolean selected = entry.equals(selectedItem);
createItemRow(selected, counter, entry, entry, context); createItemRow(selected, counter, entry, entry);
counter++; counter++;
} }
} else if (type == MapSourceAction.TYPE || type == MapOverlayAction.TYPE || type == MapUnderlayAction.TYPE) { } else if (action instanceof SwitchableAction) {
for (Map.Entry<String, String> entry : pairsMap.entrySet()) { SwitchableAction switchableAction = (SwitchableAction) action;
String tag = entry.getKey(); List<Pair<String, String>> sources = (List<Pair<String, String>>) switchableAction.loadListFromParams();
for (Pair<String, String> entry : sources) {
String tag = entry.first;
boolean selected = tag.equals(selectedItem); boolean selected = tag.equals(selectedItem);
createItemRow(selected, counter, entry.getValue(), tag, context); createItemRow(selected, counter, entry.second, tag);
counter++; counter++;
} }
} }
} }
private void createItemRow(boolean selected, int counter, String text, String tag, Context context) { private void createItemRow(boolean selected, int counter, String text, String tag) {
View view = stylesContainer.getChildAt(counter); View view = itemsContainer.getChildAt(counter);
view.setTag(tag); view.setTag(tag);
view.setOnClickListener(getOnClickListener()); view.setOnClickListener(getOnClickListener());
@ -303,8 +207,7 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF
rb.setChecked(selected); rb.setChecked(selected);
CompoundButtonCompat.setButtonTintList(rb, rbColorList); CompoundButtonCompat.setButtonTintList(rb, rbColorList);
ImageView imageView = (ImageView) view.findViewById(R.id.icon); ImageView imageView = (ImageView) view.findViewById(R.id.icon);
imageView.setImageDrawable(((OsmandApplication) context.getApplicationContext()) imageView.setImageDrawable(getContentIcon(action.getIconRes()));
.getIconsCache().getThemedIcon(QuickActionFactory.getActionIcon(type)));
} }
@ColorInt @ColorInt
@ -325,14 +228,8 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF
return; return;
} }
selectedItem = (String) v.getTag(); selectedItem = (String) v.getTag();
if (type == MapStyleAction.TYPE) { if (action instanceof SwitchableAction) {
changeMapStyle(mapActivity); ((SwitchableAction) action).executeWithParams(mapActivity, selectedItem);
} else if (type == MapSourceAction.TYPE) {
changeMapSource(mapActivity);
} else if (type == MapOverlayAction.TYPE) {
changeMapOverlay(mapActivity);
} else if (type == MapUnderlayAction.TYPE) {
changeMapUnderlay(mapActivity);
} }
dismiss(); dismiss();
} }

View file

@ -76,6 +76,10 @@ public class QuickAction {
return id; return id;
} }
public long getType() {
return type;
}
public boolean isActionEditable() { public boolean isActionEditable() {
return isActionEditable; return isActionEditable;
} }

View file

@ -1,7 +1,9 @@
package net.osmand.plus.quickaction; package net.osmand.plus.quickaction;
import android.content.Context; import android.content.Context;
import android.os.Bundle;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.MotionEventCompat; import android.support.v4.view.MotionEventCompat;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SwitchCompat; import android.support.v7.widget.SwitchCompat;
@ -17,6 +19,7 @@ import android.widget.TextView;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.SelectMapViewQuickActionsBottomSheet;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -24,8 +27,6 @@ import java.util.List;
public abstract class SwitchableAction<T> extends QuickAction { public abstract class SwitchableAction<T> extends QuickAction {
public static final String KEY_ACTIONS_MAP = "actions_map";
public static final String KEY_TYPE = "type";
public static final String KEY_ID = "id"; public static final String KEY_ID = "id";
protected static final String KEY_DIALOG = "dialog"; protected static final String KEY_DIALOG = "dialog";
@ -102,6 +103,18 @@ public abstract class SwitchableAction<T> extends QuickAction {
return hasParams; return hasParams;
} }
public abstract List<T> loadListFromParams();
public abstract void executeWithParams(MapActivity mapActivity, String params);
protected void showChooseDialog(FragmentManager fm) {
SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet();
Bundle args = new Bundle();
args.putLong(KEY_ID, id);
fragment.setArguments(args);
fragment.show(fm, SelectMapViewQuickActionsBottomSheet.TAG);
}
protected class Adapter extends RecyclerView.Adapter<Adapter.ItemHolder> implements QuickActionItemTouchHelperCallback.OnItemMoveCallback { protected class Adapter extends RecyclerView.Adapter<Adapter.ItemHolder> implements QuickActionItemTouchHelperCallback.OnItemMoveCallback {
private List<T> itemsList = new ArrayList<>(); private List<T> itemsList = new ArrayList<>();
@ -261,8 +274,6 @@ public abstract class SwitchableAction<T> extends QuickAction {
protected abstract void saveListToParams(List<T> list); protected abstract void saveListToParams(List<T> list);
protected abstract List<T> loadListFromParams();
protected abstract String getItemName(T item); protected abstract String getItemName(T item);
protected abstract protected abstract

View file

@ -1,7 +1,6 @@
package net.osmand.plus.quickaction.actions; package net.osmand.plus.quickaction.actions;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.util.Pair; import android.support.v4.util.Pair;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.SwitchCompat; import android.support.v7.widget.SwitchCompat;
@ -16,14 +15,12 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.SelectMapViewQuickActionsBottomSheet;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.SwitchableAction; import net.osmand.plus.quickaction.SwitchableAction;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -59,7 +56,7 @@ public class MapOverlayAction extends SwitchableAction<Pair<String, String>> {
} }
@Override @Override
protected List<Pair<String, String>> loadListFromParams() { public List<Pair<String, String>> loadListFromParams() {
String json = getParams().get(getListKey()); String json = getParams().get(getListKey());
@ -88,18 +85,7 @@ public class MapOverlayAction extends SwitchableAction<Pair<String, String>> {
boolean showBottomSheetStyles = Boolean.valueOf(getParams().get(KEY_DIALOG)); boolean showBottomSheetStyles = Boolean.valueOf(getParams().get(KEY_DIALOG));
if (showBottomSheetStyles) { if (showBottomSheetStyles) {
SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet(); showChooseDialog(activity.getSupportFragmentManager());
HashMap<String, String> hashMap = new HashMap<>();
for (Pair<String, String> pair : sources) {
hashMap.put(pair.first, pair.second);
}
Bundle args = new Bundle();
args.putInt(KEY_TYPE, TYPE);
args.putLong(KEY_ID, id);
args.putSerializable(KEY_ACTIONS_MAP, hashMap);
fragment.setArguments(args);
fragment.show(activity.getSupportFragmentManager(),
SelectMapViewQuickActionsBottomSheet.TAG);
return; return;
} }
@ -113,21 +99,28 @@ public class MapOverlayAction extends SwitchableAction<Pair<String, String>> {
if (index >= 0 && index + 1 < sources.size()) { if (index >= 0 && index + 1 < sources.size()) {
nextSource = sources.get(index + 1); nextSource = sources.get(index + 1);
} }
executeWithParams(activity, nextSource.first);
}
}
boolean hasOverlay = !nextSource.first.equals(KEY_NO_OVERLAY); @Override
public void executeWithParams(MapActivity mapActivity, String params) {
OsmandRasterMapsPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class);
if (plugin != null) {
OsmandSettings settings = mapActivity.getMyApplication().getSettings();
boolean hasOverlay = !params.equals(KEY_NO_OVERLAY);
if (hasOverlay) { if (hasOverlay) {
settings.MAP_OVERLAY.set(nextSource.first); settings.MAP_OVERLAY.set(params);
settings.MAP_OVERLAY_PREVIOUS.set(nextSource.first); settings.MAP_OVERLAY_PREVIOUS.set(params);
} else { } else {
settings.MAP_OVERLAY.set(null); settings.MAP_OVERLAY.set(null);
settings.MAP_OVERLAY_PREVIOUS.set(null); settings.MAP_OVERLAY_PREVIOUS.set(null);
} }
plugin.updateMapLayers(mapActivity.getMapView(), settings.MAP_OVERLAY, mapActivity.getMapLayers());
plugin.updateMapLayers(activity.getMapView(), settings.MAP_OVERLAY, activity.getMapLayers()); Toast.makeText(mapActivity, mapActivity.getString(R.string.quick_action_map_overlay_switch, params), Toast.LENGTH_SHORT).show();
Toast.makeText(activity, activity.getString(R.string.quick_action_map_overlay_switch, nextSource.second), Toast.LENGTH_SHORT).show();
} }
} }
@Override @Override
protected int getAddBtnText() { protected int getAddBtnText() {
return R.string.quick_action_map_overlay_action; return R.string.quick_action_map_overlay_action;

View file

@ -1,7 +1,6 @@
package net.osmand.plus.quickaction.actions; package net.osmand.plus.quickaction.actions;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.util.Pair; import android.support.v4.util.Pair;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.SwitchCompat; import android.support.v7.widget.SwitchCompat;
@ -16,14 +15,12 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.SelectMapViewQuickActionsBottomSheet;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.SwitchableAction; import net.osmand.plus.quickaction.SwitchableAction;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -31,9 +28,9 @@ import java.util.Map;
public class MapSourceAction extends SwitchableAction<Pair<String, String>> { public class MapSourceAction extends SwitchableAction<Pair<String, String>> {
public static final int TYPE = 17; public static final int TYPE = 17;
public static final String LAYER_OSM_VECTOR = "LAYER_OSM_VECTOR";
private final static String KEY_SOURCE = "source"; private final static String KEY_SOURCE = "source";
private final String LAYER_OSM_VECTOR = "LAYER_OSM_VECTOR";
public MapSourceAction() { public MapSourceAction() {
super(TYPE); super(TYPE);
@ -60,7 +57,7 @@ public class MapSourceAction extends SwitchableAction<Pair<String, String>> {
} }
@Override @Override
protected List<Pair<String, String>> loadListFromParams() { public List<Pair<String, String>> loadListFromParams() {
String json = getParams().get(getListKey()); String json = getParams().get(getListKey());
@ -82,18 +79,7 @@ public class MapSourceAction extends SwitchableAction<Pair<String, String>> {
boolean showBottomSheetStyles = Boolean.valueOf(getParams().get(KEY_DIALOG)); boolean showBottomSheetStyles = Boolean.valueOf(getParams().get(KEY_DIALOG));
if (showBottomSheetStyles) { if (showBottomSheetStyles) {
SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet(); showChooseDialog(activity.getSupportFragmentManager());
HashMap<String, String> hashMap = new HashMap<>();
for (Pair<String, String> pair : sources) {
hashMap.put(pair.first, pair.second);
}
Bundle args = new Bundle();
args.putInt(KEY_TYPE, TYPE);
args.putLong(KEY_ID, id);
args.putSerializable(KEY_ACTIONS_MAP, hashMap);
fragment.setArguments(args);
fragment.show(activity.getSupportFragmentManager(),
SelectMapViewQuickActionsBottomSheet.TAG);
return; return;
} }
@ -107,23 +93,24 @@ public class MapSourceAction extends SwitchableAction<Pair<String, String>> {
if (index >= 0 && index + 1 < sources.size()) { if (index >= 0 && index + 1 < sources.size()) {
nextSource = sources.get(index + 1); nextSource = sources.get(index + 1);
} }
executeWithParams(activity, nextSource.first);
if (nextSource.first.equals(LAYER_OSM_VECTOR)) {
settings.MAP_ONLINE_DATA.set(false);
activity.getMapLayers().updateMapSource(activity.getMapView(), null);
} else {
settings.MAP_TILE_SOURCES.set(nextSource.first);
settings.MAP_ONLINE_DATA.set(true);
activity.getMapLayers().updateMapSource(activity.getMapView(), settings.MAP_TILE_SOURCES);
}
Toast.makeText(activity, activity.getString(R.string.quick_action_map_source_switch, nextSource.second), Toast.LENGTH_SHORT).show();
} }
} }
@Override
public void executeWithParams(MapActivity mapActivity, String params) {
OsmandSettings settings = mapActivity.getMyApplication().getSettings();
if (params.equals(LAYER_OSM_VECTOR)) {
settings.MAP_ONLINE_DATA.set(false);
mapActivity.getMapLayers().updateMapSource(mapActivity.getMapView(), null);
} else {
settings.MAP_TILE_SOURCES.set(params);
settings.MAP_ONLINE_DATA.set(true);
mapActivity.getMapLayers().updateMapSource(mapActivity.getMapView(), settings.MAP_TILE_SOURCES);
}
Toast.makeText(mapActivity, mapActivity.getString(R.string.quick_action_map_source_switch, params), Toast.LENGTH_SHORT).show();
}
@Override @Override
protected int getAddBtnText() { protected int getAddBtnText() {
return R.string.quick_action_map_source_action; return R.string.quick_action_map_source_action;

View file

@ -1,7 +1,6 @@
package net.osmand.plus.quickaction.actions; package net.osmand.plus.quickaction.actions;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.SwitchCompat; import android.support.v7.widget.SwitchCompat;
import android.text.TextUtils; import android.text.TextUtils;
@ -14,7 +13,6 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.dialogs.SelectMapViewQuickActionsBottomSheet;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.SwitchableAction; import net.osmand.plus.quickaction.SwitchableAction;
@ -31,7 +29,7 @@ public class MapStyleAction extends SwitchableAction<String> {
public static final int TYPE = 14; public static final int TYPE = 14;
public final static String KEY_STYLES = "styles"; private final static String KEY_STYLES = "styles";
public MapStyleAction() { public MapStyleAction() {
super(TYPE); super(TYPE);
@ -47,14 +45,7 @@ public class MapStyleAction extends SwitchableAction<String> {
List<String> mapStyles = getFilteredStyles(); List<String> mapStyles = getFilteredStyles();
boolean showBottomSheetStyles = Boolean.valueOf(getParams().get(KEY_DIALOG)); boolean showBottomSheetStyles = Boolean.valueOf(getParams().get(KEY_DIALOG));
if (showBottomSheetStyles) { if (showBottomSheetStyles) {
SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet(); showChooseDialog(activity.getSupportFragmentManager());
Bundle args = new Bundle();
args.putStringArrayList(KEY_STYLES, (ArrayList<String>) mapStyles);
args.putInt(KEY_TYPE, TYPE);
args.putLong(KEY_ID, id);
fragment.setArguments(args);
fragment.show(activity.getSupportFragmentManager(),
SelectMapViewQuickActionsBottomSheet.TAG);
return; return;
} }
String curStyle = activity.getMyApplication().getSettings().RENDERER.get(); String curStyle = activity.getMyApplication().getSettings().RENDERER.get();
@ -64,26 +55,26 @@ public class MapStyleAction extends SwitchableAction<String> {
if (index >= 0 && index + 1 < mapStyles.size()) { if (index >= 0 && index + 1 < mapStyles.size()) {
nextStyle = mapStyles.get(index + 1); nextStyle = mapStyles.get(index + 1);
} }
executeWithParams(activity, nextStyle);
RenderingRulesStorage loaded = activity.getMyApplication()
.getRendererRegistry().getRenderer(nextStyle);
if (loaded != null) {
OsmandMapTileView view = activity.getMapView();
view.getSettings().RENDERER.set(nextStyle);
activity.getMyApplication().getRendererRegistry().setCurrentSelectedRender(loaded);
ConfigureMapMenu.refreshMapComplete(activity);
Toast.makeText(activity, activity.getString(R.string.quick_action_map_style_switch, nextStyle), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(activity, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
}
} }
@Override
public void executeWithParams(MapActivity mapActivity, String params) {
OsmandApplication app = mapActivity.getMyApplication();
RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(params);
if (loaded != null) {
OsmandMapTileView view = mapActivity.getMapView();
view.getSettings().RENDERER.set(params);
app.getRendererRegistry().setCurrentSelectedRender(loaded);
ConfigureMapMenu.refreshMapComplete(mapActivity);
Toast.makeText(mapActivity, mapActivity.getString(R.string.quick_action_map_style_switch, params), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(mapActivity, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
}
}
public List<String> getFilteredStyles() { public List<String> getFilteredStyles() {
List<String> filtered = new ArrayList<>(); List<String> filtered = new ArrayList<>();
@ -187,7 +178,7 @@ public class MapStyleAction extends SwitchableAction<String> {
} }
@Override @Override
protected List<String> loadListFromParams() { public List<String> loadListFromParams() {
List<String> styles = new ArrayList<>(); List<String> styles = new ArrayList<>();

View file

@ -1,7 +1,6 @@
package net.osmand.plus.quickaction.actions; package net.osmand.plus.quickaction.actions;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.util.Pair; import android.support.v4.util.Pair;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.SwitchCompat; import android.support.v7.widget.SwitchCompat;
@ -16,14 +15,12 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.SelectMapViewQuickActionsBottomSheet;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.SwitchableAction; import net.osmand.plus.quickaction.SwitchableAction;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -59,7 +56,7 @@ public class MapUnderlayAction extends SwitchableAction<Pair<String, String>> {
} }
@Override @Override
protected List<Pair<String, String>> loadListFromParams() { public List<Pair<String, String>> loadListFromParams() {
String json = getParams().get(getListKey()); String json = getParams().get(getListKey());
@ -87,18 +84,7 @@ public class MapUnderlayAction extends SwitchableAction<Pair<String, String>> {
boolean showBottomSheetStyles = Boolean.valueOf(getParams().get(KEY_DIALOG)); boolean showBottomSheetStyles = Boolean.valueOf(getParams().get(KEY_DIALOG));
if (showBottomSheetStyles) { if (showBottomSheetStyles) {
SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet(); showChooseDialog(activity.getSupportFragmentManager());
HashMap<String, String> hashMap = new HashMap<>();
for (Pair<String, String> pair : sources) {
hashMap.put(pair.first, pair.second);
}
Bundle args = new Bundle();
args.putInt(KEY_TYPE, TYPE);
args.putLong(KEY_ID, id);
args.putSerializable(KEY_ACTIONS_MAP, hashMap);
fragment.setArguments(args);
fragment.show(activity.getSupportFragmentManager(),
SelectMapViewQuickActionsBottomSheet.TAG);
return; return;
} }
@ -112,25 +98,32 @@ public class MapUnderlayAction extends SwitchableAction<Pair<String, String>> {
if (index >= 0 && index + 1 < sources.size()) { if (index >= 0 && index + 1 < sources.size()) {
nextSource = sources.get(index + 1); nextSource = sources.get(index + 1);
} }
executeWithParams(activity, nextSource.first);
}
}
boolean hasUnderlay = !nextSource.first.equals(KEY_NO_UNDERLAY); @Override
public void executeWithParams(MapActivity mapActivity, String params) {
OsmandRasterMapsPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class);
if (plugin != null) {
OsmandSettings settings = mapActivity.getMyApplication().getSettings();
boolean hasUnderlay = !params.equals(KEY_NO_UNDERLAY);
if (hasUnderlay) { if (hasUnderlay) {
settings.MAP_UNDERLAY.set(nextSource.first); settings.MAP_UNDERLAY.set(params);
settings.MAP_UNDERLAY_PREVIOUS.set(nextSource.first); settings.MAP_UNDERLAY_PREVIOUS.set(params);
} else { } else {
settings.MAP_UNDERLAY.set(null); settings.MAP_UNDERLAY.set(null);
settings.MAP_UNDERLAY_PREVIOUS.set(null); settings.MAP_UNDERLAY_PREVIOUS.set(null);
} }
final OsmandSettings.CommonPreference<Boolean> hidePolygonsPref = final OsmandSettings.CommonPreference<Boolean> hidePolygonsPref =
activity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons"); mapActivity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
hidePolygonsPref.set(hasUnderlay); hidePolygonsPref.set(hasUnderlay);
plugin.updateMapLayers(activity.getMapView(), settings.MAP_UNDERLAY, activity.getMapLayers()); plugin.updateMapLayers(mapActivity.getMapView(), settings.MAP_UNDERLAY, mapActivity.getMapLayers());
Toast.makeText(activity, activity.getString(R.string.quick_action_map_underlay_switch, nextSource.second), Toast.LENGTH_SHORT).show(); Toast.makeText(mapActivity, mapActivity.getString(R.string.quick_action_map_underlay_switch, params), Toast.LENGTH_SHORT).show();
} }
} }
@Override @Override
protected int getAddBtnText() { protected int getAddBtnText() {
return R.string.quick_action_map_underlay_action; return R.string.quick_action_map_underlay_action;