Merge pull request #5546 from osmandapp/QuickActionsChooseDialog
Add choose dialog for quick actions menu
This commit is contained in:
commit
d4065587c0
9 changed files with 425 additions and 46 deletions
|
@ -6,6 +6,48 @@
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:orientation="vertical">
|
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
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
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
|
- For wording and consistency, please note http://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
|
||||||
Thx - Hardy
|
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="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="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>
|
<string name="shared_string_bookmark">Bookmark</string>
|
||||||
|
|
|
@ -0,0 +1,240 @@
|
||||||
|
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.app.FragmentManager;
|
||||||
|
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 net.osmand.AndroidUtils;
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
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.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.render.RendererRegistry;
|
||||||
|
import net.osmand.render.RenderingRulesStorage;
|
||||||
|
|
||||||
|
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 LinearLayout itemsContainer;
|
||||||
|
private View.OnClickListener onClickListener;
|
||||||
|
private ColorStateList rbColorList;
|
||||||
|
|
||||||
|
private String selectedItem;
|
||||||
|
private QuickAction action;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
|
Bundle args = getArguments();
|
||||||
|
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 (action instanceof MapStyleAction) {
|
||||||
|
RenderingRulesStorage current = app.getRendererRegistry().getCurrentSelectedRenderer();
|
||||||
|
if (current != null) {
|
||||||
|
selectedItem = current.getName();
|
||||||
|
} else {
|
||||||
|
selectedItem = RendererRegistry.DEFAULT_RENDER;
|
||||||
|
}
|
||||||
|
} 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 (action instanceof MapOverlayAction) {
|
||||||
|
selectedItem = settings.MAP_OVERLAY.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rbColorList = AndroidUtils.createCheckedColorStateList(app, R.color.icon_color, getActiveColorId());
|
||||||
|
|
||||||
|
items.add(new TitleItem(action.getName(app)));
|
||||||
|
|
||||||
|
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 (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(app, themeRes))
|
||||||
|
.inflate(R.layout.bottom_sheet_item_with_radio_btn, itemsContainer, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
nestedScrollView.addView(itemsContainer);
|
||||||
|
items.add(new BaseBottomSheetItem.Builder().setCustomView(nestedScrollView).create());
|
||||||
|
|
||||||
|
populateItemsList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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() {
|
||||||
|
FragmentManager fm = getFragmentManager();
|
||||||
|
if (fm == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CreateEditActionDialog dialog = CreateEditActionDialog.newInstance(action.getId());
|
||||||
|
dialog.show(fm, CreateEditActionDialog.TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 (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);
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
} 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.second, tag);
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createItemRow(boolean selected, int counter, String text, String tag) {
|
||||||
|
View view = itemsContainer.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(getContentIcon(action.getIconRes()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@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) {
|
||||||
|
MapActivity mapActivity = getMapActivity();
|
||||||
|
if (mapActivity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
selectedItem = (String) v.getTag();
|
||||||
|
if (action instanceof SwitchableAction) {
|
||||||
|
((SwitchableAction) action).executeWithParams(mapActivity, selectedItem);
|
||||||
|
}
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return onClickListener;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
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.helper.ItemTouchHelper;
|
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
@ -16,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;
|
||||||
|
@ -23,6 +27,10 @@ import java.util.List;
|
||||||
|
|
||||||
public abstract class SwitchableAction<T> extends QuickAction {
|
public abstract class SwitchableAction<T> extends QuickAction {
|
||||||
|
|
||||||
|
public static final String KEY_ID = "id";
|
||||||
|
|
||||||
|
protected static final String KEY_DIALOG = "dialog";
|
||||||
|
|
||||||
private transient EditText title;
|
private transient EditText title;
|
||||||
|
|
||||||
protected SwitchableAction(int type) {
|
protected SwitchableAction(int type) {
|
||||||
|
@ -44,6 +52,11 @@ public abstract class SwitchableAction<T> extends QuickAction {
|
||||||
View view = LayoutInflater.from(parent.getContext())
|
View view = LayoutInflater.from(parent.getContext())
|
||||||
.inflate(R.layout.quick_action_switchable_action, parent, false);
|
.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 RecyclerView list = (RecyclerView) view.findViewById(R.id.list);
|
||||||
|
|
||||||
final QuickActionItemTouchHelperCallback touchHelperCallback = new QuickActionItemTouchHelperCallback();
|
final QuickActionItemTouchHelperCallback touchHelperCallback = new QuickActionItemTouchHelperCallback();
|
||||||
|
@ -90,6 +103,18 @@ public abstract class SwitchableAction<T> extends QuickAction {
|
||||||
return hasParams;
|
return hasParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract List<T> loadListFromParams();
|
||||||
|
|
||||||
|
public abstract void executeWithParams(MapActivity activity, 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<>();
|
||||||
|
@ -249,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
|
||||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.quickaction.actions;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
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.view.View;
|
import android.view.View;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
@ -55,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());
|
||||||
|
|
||||||
|
@ -82,6 +83,12 @@ public class MapOverlayAction extends SwitchableAction<Pair<String, String>> {
|
||||||
OsmandSettings settings = activity.getMyApplication().getSettings();
|
OsmandSettings settings = activity.getMyApplication().getSettings();
|
||||||
List<Pair<String, String>> sources = loadListFromParams();
|
List<Pair<String, String>> sources = loadListFromParams();
|
||||||
|
|
||||||
|
boolean showBottomSheetStyles = Boolean.valueOf(getParams().get(KEY_DIALOG));
|
||||||
|
if (showBottomSheetStyles) {
|
||||||
|
showChooseDialog(activity.getSupportFragmentManager());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Pair<String, String> currentSource = new Pair<>(
|
Pair<String, String> currentSource = new Pair<>(
|
||||||
settings.MAP_OVERLAY.get(),
|
settings.MAP_OVERLAY.get(),
|
||||||
settings.MAP_OVERLAY.get());
|
settings.MAP_OVERLAY.get());
|
||||||
|
@ -92,18 +99,25 @@ 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 activity, String params) {
|
||||||
|
OsmandRasterMapsPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class);
|
||||||
|
if (plugin != null) {
|
||||||
|
OsmandSettings settings = activity.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(activity.getMapView(), settings.MAP_OVERLAY, activity.getMapLayers());
|
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();
|
Toast.makeText(activity, activity.getString(R.string.quick_action_map_overlay_switch, params), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,4 +179,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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.quickaction.actions;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
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.view.View;
|
import android.view.View;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
@ -27,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);
|
||||||
|
@ -56,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());
|
||||||
|
|
||||||
|
@ -76,6 +77,12 @@ public class MapSourceAction extends SwitchableAction<Pair<String, String>> {
|
||||||
OsmandSettings settings = activity.getMyApplication().getSettings();
|
OsmandSettings settings = activity.getMyApplication().getSettings();
|
||||||
List<Pair<String, String>> sources = loadListFromParams();
|
List<Pair<String, String>> sources = loadListFromParams();
|
||||||
|
|
||||||
|
boolean showBottomSheetStyles = Boolean.valueOf(getParams().get(KEY_DIALOG));
|
||||||
|
if (showBottomSheetStyles) {
|
||||||
|
showChooseDialog(activity.getSupportFragmentManager());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Pair<String, String> currentSource = settings.MAP_ONLINE_DATA.get()
|
Pair<String, String> currentSource = settings.MAP_ONLINE_DATA.get()
|
||||||
? new Pair<>(settings.MAP_TILE_SOURCES.get(), settings.MAP_TILE_SOURCES.get())
|
? new Pair<>(settings.MAP_TILE_SOURCES.get(), settings.MAP_TILE_SOURCES.get())
|
||||||
: new Pair<>(LAYER_OSM_VECTOR, activity.getString(R.string.vector_data));
|
: new Pair<>(LAYER_OSM_VECTOR, activity.getString(R.string.vector_data));
|
||||||
|
@ -86,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 activity, String params) {
|
||||||
|
OsmandSettings settings = activity.getMyApplication().getSettings();
|
||||||
|
if (params.equals(LAYER_OSM_VECTOR)) {
|
||||||
|
settings.MAP_ONLINE_DATA.set(false);
|
||||||
|
activity.getMapLayers().updateMapSource(activity.getMapView(), null);
|
||||||
|
} else {
|
||||||
|
settings.MAP_TILE_SOURCES.set(params);
|
||||||
|
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, 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;
|
||||||
|
@ -173,4 +181,11 @@ public class MapSourceAction extends SwitchableAction<Pair<String, String>> {
|
||||||
protected String getItemName(Pair<String, String> item) {
|
protected String getItemName(Pair<String, String> item) {
|
||||||
return item.second;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.quickaction.actions;
|
||||||
|
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
|
import android.support.v7.widget.SwitchCompat;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
@ -42,7 +43,11 @@ public class MapStyleAction extends SwitchableAction<String> {
|
||||||
public void execute(MapActivity activity) {
|
public void execute(MapActivity activity) {
|
||||||
|
|
||||||
List<String> mapStyles = getFilteredStyles();
|
List<String> mapStyles = getFilteredStyles();
|
||||||
|
boolean showBottomSheetStyles = Boolean.valueOf(getParams().get(KEY_DIALOG));
|
||||||
|
if (showBottomSheetStyles) {
|
||||||
|
showChooseDialog(activity.getSupportFragmentManager());
|
||||||
|
return;
|
||||||
|
}
|
||||||
String curStyle = activity.getMyApplication().getSettings().RENDERER.get();
|
String curStyle = activity.getMyApplication().getSettings().RENDERER.get();
|
||||||
int index = mapStyles.indexOf(curStyle);
|
int index = mapStyles.indexOf(curStyle);
|
||||||
String nextStyle = mapStyles.get(0);
|
String nextStyle = mapStyles.get(0);
|
||||||
|
@ -50,22 +55,22 @@ 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()
|
@Override
|
||||||
.getRendererRegistry().getRenderer(nextStyle);
|
public void executeWithParams(MapActivity activity, String params) {
|
||||||
|
OsmandApplication app = activity.getMyApplication();
|
||||||
|
RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(params);
|
||||||
if (loaded != null) {
|
if (loaded != null) {
|
||||||
|
|
||||||
OsmandMapTileView view = activity.getMapView();
|
OsmandMapTileView view = activity.getMapView();
|
||||||
view.getSettings().RENDERER.set(nextStyle);
|
view.getSettings().RENDERER.set(params);
|
||||||
|
|
||||||
activity.getMyApplication().getRendererRegistry().setCurrentSelectedRender(loaded);
|
app.getRendererRegistry().setCurrentSelectedRender(loaded);
|
||||||
ConfigureMapMenu.refreshMapComplete(activity);
|
ConfigureMapMenu.refreshMapComplete(activity);
|
||||||
|
|
||||||
Toast.makeText(activity, activity.getString(R.string.quick_action_map_style_switch, nextStyle), Toast.LENGTH_SHORT).show();
|
Toast.makeText(activity, activity.getString(R.string.quick_action_map_style_switch, params), Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
Toast.makeText(activity, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
|
Toast.makeText(activity, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,7 +171,14 @@ public class MapStyleAction extends SwitchableAction<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<String> loadListFromParams() {
|
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
|
||||||
|
public List<String> loadListFromParams() {
|
||||||
|
|
||||||
List<String> styles = new ArrayList<>();
|
List<String> styles = new ArrayList<>();
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.quickaction.actions;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
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.view.View;
|
import android.view.View;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
@ -55,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());
|
||||||
|
|
||||||
|
@ -81,6 +82,12 @@ public class MapUnderlayAction extends SwitchableAction<Pair<String, String>> {
|
||||||
OsmandSettings settings = activity.getMyApplication().getSettings();
|
OsmandSettings settings = activity.getMyApplication().getSettings();
|
||||||
List<Pair<String, String>> sources = loadListFromParams();
|
List<Pair<String, String>> sources = loadListFromParams();
|
||||||
|
|
||||||
|
boolean showBottomSheetStyles = Boolean.valueOf(getParams().get(KEY_DIALOG));
|
||||||
|
if (showBottomSheetStyles) {
|
||||||
|
showChooseDialog(activity.getSupportFragmentManager());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Pair<String, String> currentSource = new Pair<>(
|
Pair<String, String> currentSource = new Pair<>(
|
||||||
settings.MAP_UNDERLAY.get(),
|
settings.MAP_UNDERLAY.get(),
|
||||||
settings.MAP_UNDERLAY.get());
|
settings.MAP_UNDERLAY.get());
|
||||||
|
@ -91,22 +98,29 @@ 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 activity, String params) {
|
||||||
|
OsmandRasterMapsPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class);
|
||||||
|
if (plugin != null) {
|
||||||
|
OsmandSettings settings = activity.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");
|
activity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
|
||||||
hidePolygonsPref.set(hasUnderlay);
|
hidePolygonsPref.set(hasUnderlay);
|
||||||
|
|
||||||
plugin.updateMapLayers(activity.getMapView(), settings.MAP_UNDERLAY, activity.getMapLayers());
|
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();
|
Toast.makeText(activity, activity.getString(R.string.quick_action_map_underlay_switch, params), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,4 +182,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