add choose dialog for quick actions menu for map view properties(style,source,underlay,overlay)
This commit is contained in:
parent
a28358992e
commit
18be0c4aa9
8 changed files with 491 additions and 3 deletions
|
@ -6,6 +6,48 @@
|
|||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:background="?attr/bg_color"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="1"
|
||||
android:padding="16dp"
|
||||
android:text="@string/quick_action_interim_dialog"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size" />
|
||||
|
||||
<android.support.v7.widget.SwitchCompat
|
||||
android:id="@+id/saveButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="top"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/bg_shadow_list_bottom" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="top"
|
||||
android:layout_marginTop="16dp"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/bg_shadow_list_top" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
- For wording and consistency, please note http://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
|
||||
Thx - Hardy
|
||||
-->
|
||||
<string name="quick_action_edit_actions">Edit actions</string>
|
||||
<string name="get_osmand_live">Get OsmAnd Live to unlock all features: Daily map updates with unlimited downloads, all paid and free plugins, Wikipedia, Wikivoyage and much more.</string>
|
||||
<string name="unirs_render_descr">Modification of the default style to increase contrast of pedestrian and bicycle roads. Uses legacy Mapnik colors.</string>
|
||||
<string name="shared_string_bookmark">Bookmark</string>
|
||||
|
|
|
@ -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<String> stylesList;
|
||||
private HashMap<String, String> 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<String, String>) 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<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) {
|
||||
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<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;
|
||||
}
|
||||
|
||||
@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<String, String> 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;
|
||||
}
|
||||
}
|
|
@ -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<T> extends QuickAction {
|
||||
|
||||
protected static final String KEY_DIALOG = "dialog";
|
||||
private transient EditText title;
|
||||
|
||||
protected SwitchableAction(int type) {
|
||||
|
@ -44,6 +46,11 @@ public abstract class SwitchableAction<T> 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();
|
||||
|
|
|
@ -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<Pair<String, String>> {
|
|||
OsmandSettings settings = activity.getMyApplication().getSettings();
|
||||
List<Pair<String, String>> sources = loadListFromParams();
|
||||
|
||||
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("type", TYPE);
|
||||
args.putSerializable("map", hashMap);
|
||||
fragment.setArguments(args);
|
||||
fragment.show(activity.getSupportFragmentManager(),
|
||||
SelectMapViewQuickActionsBottomSheet.TAG);
|
||||
return;
|
||||
}
|
||||
|
||||
Pair<String, String> currentSource = new Pair<>(
|
||||
settings.MAP_OVERLAY.get(),
|
||||
settings.MAP_OVERLAY.get());
|
||||
|
@ -165,4 +185,11 @@ public class MapOverlayAction extends SwitchableAction<Pair<String, String>> {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Pair<String, String>> {
|
|||
OsmandSettings settings = activity.getMyApplication().getSettings();
|
||||
List<Pair<String, String>> sources = loadListFromParams();
|
||||
|
||||
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("type", TYPE);
|
||||
args.putSerializable("map", hashMap);
|
||||
fragment.setArguments(args);
|
||||
fragment.show(activity.getSupportFragmentManager(),
|
||||
SelectMapViewQuickActionsBottomSheet.TAG);
|
||||
return;
|
||||
}
|
||||
|
||||
Pair<String, String> 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<Pair<String, String>> {
|
|||
protected String getItemName(Pair<String, String> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String> {
|
|||
public void execute(MapActivity activity) {
|
||||
|
||||
List<String> mapStyles = getFilteredStyles();
|
||||
|
||||
boolean showBottomSheetStyles = Boolean.valueOf(getParams().get(KEY_DIALOG));
|
||||
if (showBottomSheetStyles) {
|
||||
SelectMapViewQuickActionsBottomSheet fragment = new SelectMapViewQuickActionsBottomSheet();
|
||||
Bundle args = new Bundle();
|
||||
args.putStringArrayList("test", (ArrayList<String>) 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<String> {
|
|||
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<String> loadListFromParams() {
|
||||
|
||||
|
|
|
@ -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<Pair<String, String>> {
|
|||
OsmandSettings settings = activity.getMyApplication().getSettings();
|
||||
List<Pair<String, String>> sources = loadListFromParams();
|
||||
|
||||
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("type", TYPE);
|
||||
args.putSerializable("map", hashMap);
|
||||
fragment.setArguments(args);
|
||||
fragment.show(activity.getSupportFragmentManager(),
|
||||
SelectMapViewQuickActionsBottomSheet.TAG);
|
||||
return;
|
||||
}
|
||||
|
||||
Pair<String, String> currentSource = new Pair<>(
|
||||
settings.MAP_UNDERLAY.get(),
|
||||
settings.MAP_UNDERLAY.get());
|
||||
|
@ -168,4 +188,11 @@ public class MapUnderlayAction extends SwitchableAction<Pair<String, String>> {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue