add QuickAction in choose dialog and executeWithParams for switchable actions
This commit is contained in:
parent
08e8e8c972
commit
fe478b7427
7 changed files with 151 additions and 275 deletions
|
@ -19,11 +19,9 @@ 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;
|
||||
|
@ -31,133 +29,100 @@ 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.CreateEditActionDialog;
|
||||
import net.osmand.plus.quickaction.QuickAction;
|
||||
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.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;
|
||||
|
||||
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;
|
||||
import java.util.List;
|
||||
|
||||
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 LinearLayout stylesContainer;
|
||||
private LinearLayout itemsContainer;
|
||||
private View.OnClickListener onClickListener;
|
||||
private ColorStateList rbColorList;
|
||||
private OsmandSettings settings;
|
||||
|
||||
private ArrayList<String> stylesList;
|
||||
private HashMap<String, String> pairsMap;
|
||||
private String selectedItem;
|
||||
private int type;
|
||||
private long id;
|
||||
private QuickAction action;
|
||||
|
||||
@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(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)) {
|
||||
if (args == null) {
|
||||
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) {
|
||||
selectedItem = savedInstanceState.getString(SELECTED_ITEM_KEY);
|
||||
} else {
|
||||
if (type == MapStyleAction.TYPE) {
|
||||
if (action instanceof MapStyleAction) {
|
||||
RenderingRulesStorage current = app.getRendererRegistry().getCurrentSelectedRenderer();
|
||||
if (current != null) {
|
||||
selectedItem = current.getName();
|
||||
} else {
|
||||
selectedItem = RendererRegistry.DEFAULT_RENDER;
|
||||
}
|
||||
} else if (type == MapSourceAction.TYPE) {
|
||||
Pair<String, String> 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) {
|
||||
} else if (action instanceof MapSourceAction) {
|
||||
selectedItem = settings.MAP_ONLINE_DATA.get()
|
||||
? settings.MAP_TILE_SOURCES.get()
|
||||
: MapSourceAction.LAYER_OSM_VECTOR;
|
||||
} else if (action instanceof MapUnderlayAction) {
|
||||
selectedItem = settings.MAP_UNDERLAY.get();
|
||||
} else if (type == MapOverlayAction.TYPE) {
|
||||
} else if (action instanceof MapOverlayAction) {
|
||||
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);
|
||||
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));
|
||||
NestedScrollView nestedScrollView = new NestedScrollView(app);
|
||||
itemsContainer = new LinearLayout(app);
|
||||
itemsContainer.setLayoutParams((new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)));
|
||||
itemsContainer.setOrientation(LinearLayout.VERTICAL);
|
||||
int padding = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small);
|
||||
itemsContainer.setPadding(0, padding, 0, padding);
|
||||
|
||||
int itemsSize = 0;
|
||||
if (type == MapSourceAction.TYPE || type == MapUnderlayAction.TYPE || type == MapOverlayAction.TYPE) {
|
||||
itemsSize = pairsMap.size();
|
||||
} else if (type == MapStyleAction.TYPE) {
|
||||
itemsSize = stylesList.size();
|
||||
if (action instanceof SwitchableAction) {
|
||||
SwitchableAction switchableAction = (SwitchableAction) action;
|
||||
List sources = switchableAction.loadListFromParams();
|
||||
itemsSize = sources.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);
|
||||
LayoutInflater.from(new ContextThemeWrapper(app, themeRes))
|
||||
.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());
|
||||
|
||||
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);
|
||||
|
@ -181,79 +146,14 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF
|
|||
|
||||
@Override
|
||||
protected void onDismissButtonClickAction() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
FragmentManager fm = getFragmentManager();
|
||||
if (mapActivity == null || fm == null) {
|
||||
if (fm == null) {
|
||||
return;
|
||||
}
|
||||
CreateEditActionDialog dialog = CreateEditActionDialog.newInstance(id);
|
||||
CreateEditActionDialog dialog = CreateEditActionDialog.newInstance(action.getId());
|
||||
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
|
||||
protected boolean useScrollableItemsContainer() {
|
||||
return false;
|
||||
|
@ -274,24 +174,28 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF
|
|||
return;
|
||||
}
|
||||
int counter = 0;
|
||||
if (type == MapStyleAction.TYPE) {
|
||||
if (action instanceof MapStyleAction) {
|
||||
MapStyleAction mapStyleAction = (MapStyleAction) action;
|
||||
List<String> stylesList = mapStyleAction.getFilteredStyles();
|
||||
for (String entry : stylesList) {
|
||||
boolean selected = entry.equals(selectedItem);
|
||||
createItemRow(selected, counter, entry, entry, context);
|
||||
createItemRow(selected, counter, entry, entry);
|
||||
counter++;
|
||||
}
|
||||
} else if (type == MapSourceAction.TYPE || type == MapOverlayAction.TYPE || type == MapUnderlayAction.TYPE) {
|
||||
for (Map.Entry<String, String> entry : pairsMap.entrySet()) {
|
||||
String tag = entry.getKey();
|
||||
} else if (action instanceof SwitchableAction) {
|
||||
SwitchableAction switchableAction = (SwitchableAction) action;
|
||||
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);
|
||||
createItemRow(selected, counter, entry.getValue(), tag, context);
|
||||
createItemRow(selected, counter, entry.second, tag);
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createItemRow(boolean selected, int counter, String text, String tag, Context context) {
|
||||
View view = stylesContainer.getChildAt(counter);
|
||||
private void createItemRow(boolean selected, int counter, String text, String tag) {
|
||||
View view = itemsContainer.getChildAt(counter);
|
||||
view.setTag(tag);
|
||||
view.setOnClickListener(getOnClickListener());
|
||||
|
||||
|
@ -303,8 +207,7 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF
|
|||
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)));
|
||||
imageView.setImageDrawable(getContentIcon(action.getIconRes()));
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
|
@ -325,14 +228,8 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF
|
|||
return;
|
||||
}
|
||||
selectedItem = (String) v.getTag();
|
||||
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);
|
||||
if (action instanceof SwitchableAction) {
|
||||
((SwitchableAction) action).executeWithParams(mapActivity, selectedItem);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
|
|
@ -76,6 +76,10 @@ public class QuickAction {
|
|||
return id;
|
||||
}
|
||||
|
||||
public long getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public boolean isActionEditable() {
|
||||
return isActionEditable;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package net.osmand.plus.quickaction;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.view.MotionEventCompat;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
|
@ -17,6 +19,7 @@ import android.widget.TextView;
|
|||
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.dialogs.SelectMapViewQuickActionsBottomSheet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -24,8 +27,6 @@ import java.util.List;
|
|||
|
||||
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";
|
||||
|
||||
protected static final String KEY_DIALOG = "dialog";
|
||||
|
@ -102,6 +103,18 @@ public abstract class SwitchableAction<T> extends QuickAction {
|
|||
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 {
|
||||
|
||||
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 List<T> loadListFromParams();
|
||||
|
||||
protected abstract String getItemName(T item);
|
||||
|
||||
protected abstract
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
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;
|
||||
|
@ -16,14 +15,12 @@ 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;
|
||||
|
||||
|
@ -59,7 +56,7 @@ public class MapOverlayAction extends SwitchableAction<Pair<String, String>> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected List<Pair<String, String>> loadListFromParams() {
|
||||
public List<Pair<String, String>> loadListFromParams() {
|
||||
|
||||
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));
|
||||
if (showBottomSheetStyles) {
|
||||
SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet();
|
||||
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);
|
||||
showChooseDialog(activity.getSupportFragmentManager());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -113,21 +99,28 @@ public class MapOverlayAction extends SwitchableAction<Pair<String, String>> {
|
|||
if (index >= 0 && index + 1 < sources.size()) {
|
||||
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) {
|
||||
settings.MAP_OVERLAY.set(nextSource.first);
|
||||
settings.MAP_OVERLAY_PREVIOUS.set(nextSource.first);
|
||||
settings.MAP_OVERLAY.set(params);
|
||||
settings.MAP_OVERLAY_PREVIOUS.set(params);
|
||||
} else {
|
||||
settings.MAP_OVERLAY.set(null);
|
||||
settings.MAP_OVERLAY_PREVIOUS.set(null);
|
||||
}
|
||||
|
||||
plugin.updateMapLayers(activity.getMapView(), settings.MAP_OVERLAY, activity.getMapLayers());
|
||||
Toast.makeText(activity, activity.getString(R.string.quick_action_map_overlay_switch, nextSource.second), Toast.LENGTH_SHORT).show();
|
||||
plugin.updateMapLayers(mapActivity.getMapView(), settings.MAP_OVERLAY, mapActivity.getMapLayers());
|
||||
Toast.makeText(mapActivity, mapActivity.getString(R.string.quick_action_map_overlay_switch, params), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected int getAddBtnText() {
|
||||
return R.string.quick_action_map_overlay_action;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
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;
|
||||
|
@ -16,14 +15,12 @@ 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;
|
||||
|
@ -31,9 +28,9 @@ import java.util.Map;
|
|||
public class MapSourceAction extends SwitchableAction<Pair<String, String>> {
|
||||
|
||||
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 String LAYER_OSM_VECTOR = "LAYER_OSM_VECTOR";
|
||||
|
||||
public MapSourceAction() {
|
||||
super(TYPE);
|
||||
|
@ -60,7 +57,7 @@ public class MapSourceAction extends SwitchableAction<Pair<String, String>> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected List<Pair<String, String>> loadListFromParams() {
|
||||
public List<Pair<String, String>> loadListFromParams() {
|
||||
|
||||
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));
|
||||
if (showBottomSheetStyles) {
|
||||
SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet();
|
||||
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);
|
||||
showChooseDialog(activity.getSupportFragmentManager());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -107,23 +93,24 @@ public class MapSourceAction extends SwitchableAction<Pair<String, String>> {
|
|||
if (index >= 0 && index + 1 < sources.size()) {
|
||||
nextSource = sources.get(index + 1);
|
||||
}
|
||||
|
||||
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();
|
||||
executeWithParams(activity, nextSource.first);
|
||||
}
|
||||
}
|
||||
|
||||
@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
|
||||
protected int getAddBtnText() {
|
||||
return R.string.quick_action_map_source_action;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
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;
|
||||
|
@ -14,7 +13,6 @@ 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;
|
||||
|
@ -31,7 +29,7 @@ public class MapStyleAction extends SwitchableAction<String> {
|
|||
|
||||
public static final int TYPE = 14;
|
||||
|
||||
public final static String KEY_STYLES = "styles";
|
||||
private final static String KEY_STYLES = "styles";
|
||||
|
||||
public MapStyleAction() {
|
||||
super(TYPE);
|
||||
|
@ -47,14 +45,7 @@ public class MapStyleAction extends SwitchableAction<String> {
|
|||
List<String> mapStyles = getFilteredStyles();
|
||||
boolean showBottomSheetStyles = Boolean.valueOf(getParams().get(KEY_DIALOG));
|
||||
if (showBottomSheetStyles) {
|
||||
SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet();
|
||||
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);
|
||||
showChooseDialog(activity.getSupportFragmentManager());
|
||||
return;
|
||||
}
|
||||
String curStyle = activity.getMyApplication().getSettings().RENDERER.get();
|
||||
|
@ -64,26 +55,26 @@ public class MapStyleAction extends SwitchableAction<String> {
|
|||
if (index >= 0 && index + 1 < mapStyles.size()) {
|
||||
nextStyle = mapStyles.get(index + 1);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
executeWithParams(activity, nextStyle);
|
||||
}
|
||||
|
||||
@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() {
|
||||
|
||||
List<String> filtered = new ArrayList<>();
|
||||
|
@ -187,7 +178,7 @@ public class MapStyleAction extends SwitchableAction<String> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected List<String> loadListFromParams() {
|
||||
public List<String> loadListFromParams() {
|
||||
|
||||
List<String> styles = new ArrayList<>();
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
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;
|
||||
|
@ -16,14 +15,12 @@ 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;
|
||||
|
||||
|
@ -59,7 +56,7 @@ public class MapUnderlayAction extends SwitchableAction<Pair<String, String>> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected List<Pair<String, String>> loadListFromParams() {
|
||||
public List<Pair<String, String>> loadListFromParams() {
|
||||
|
||||
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));
|
||||
if (showBottomSheetStyles) {
|
||||
SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet();
|
||||
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);
|
||||
showChooseDialog(activity.getSupportFragmentManager());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -112,25 +98,32 @@ public class MapUnderlayAction extends SwitchableAction<Pair<String, String>> {
|
|||
if (index >= 0 && index + 1 < sources.size()) {
|
||||
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) {
|
||||
settings.MAP_UNDERLAY.set(nextSource.first);
|
||||
settings.MAP_UNDERLAY_PREVIOUS.set(nextSource.first);
|
||||
settings.MAP_UNDERLAY.set(params);
|
||||
settings.MAP_UNDERLAY_PREVIOUS.set(params);
|
||||
} else {
|
||||
settings.MAP_UNDERLAY.set(null);
|
||||
settings.MAP_UNDERLAY_PREVIOUS.set(null);
|
||||
}
|
||||
|
||||
final OsmandSettings.CommonPreference<Boolean> hidePolygonsPref =
|
||||
activity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
|
||||
mapActivity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
|
||||
hidePolygonsPref.set(hasUnderlay);
|
||||
|
||||
plugin.updateMapLayers(activity.getMapView(), settings.MAP_UNDERLAY, activity.getMapLayers());
|
||||
Toast.makeText(activity, activity.getString(R.string.quick_action_map_underlay_switch, nextSource.second), Toast.LENGTH_SHORT).show();
|
||||
plugin.updateMapLayers(mapActivity.getMapView(), settings.MAP_UNDERLAY, mapActivity.getMapLayers());
|
||||
Toast.makeText(mapActivity, mapActivity.getString(R.string.quick_action_map_underlay_switch, params), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected int getAddBtnText() {
|
||||
return R.string.quick_action_map_underlay_action;
|
||||
|
|
Loading…
Reference in a new issue