Refactoring

This commit is contained in:
GaidamakUA 2016-03-25 18:56:48 +02:00
parent 12f8c1f115
commit 09b78d044f
26 changed files with 1004 additions and 719 deletions

View file

@ -7,9 +7,9 @@ import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.support.annotation.DrawableRes; import android.support.annotation.DrawableRes;
import android.support.annotation.LayoutRes; import android.support.annotation.LayoutRes;
import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat; import android.support.v4.graphics.drawable.DrawableCompat;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
@ -32,30 +32,14 @@ import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import gnu.trove.list.array.TIntArrayList;
public class ContextMenuAdapter { public class ContextMenuAdapter {
private static final Log LOG = PlatformUtil.getLog(ContextMenuAdapter.class); private static final Log LOG = PlatformUtil.getLog(ContextMenuAdapter.class);
private final Context ctx; private final Context ctx;
private View anchor;
@LayoutRes @LayoutRes
private int defaultLayoutId = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ? private int defaultLayoutId = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ?
R.layout.list_menu_item : R.layout.list_menu_item_native; R.layout.list_menu_item : R.layout.list_menu_item_native;
final TIntArrayList items = new TIntArrayList(); List<ContextMenuItem> items = new ArrayList<>();
final TIntArrayList isCategory = new TIntArrayList();
final ArrayList<String> itemNames = new ArrayList<String>();
final ArrayList<OnContextMenuClick> checkListeners = new ArrayList<>();
final ArrayList<OnIntegerValueChangedListener> integerListeners = new ArrayList<>();
final TIntArrayList selectedList = new TIntArrayList();
final TIntArrayList progressList = new TIntArrayList();
final TIntArrayList loadingList = new TIntArrayList();
final TIntArrayList layoutIds = new TIntArrayList();
final TIntArrayList iconList = new TIntArrayList();
final TIntArrayList lightIconList = new TIntArrayList();
final TIntArrayList secondaryLightIconList = new TIntArrayList();
final ArrayList<String> itemDescription = new ArrayList<String>();
private List<ApplicationMode> visibleModes = new ArrayList<ApplicationMode>();
private ConfigureMapMenu.OnClickListener changeAppModeListener = null; private ConfigureMapMenu.OnClickListener changeAppModeListener = null;
//neded to detect whether user opened all modes or not //neded to detect whether user opened all modes or not
private BooleanResult allModes = new BooleanResult(); private BooleanResult allModes = new BooleanResult();
@ -69,84 +53,61 @@ public class ContextMenuAdapter {
this.ctx = ctx; this.ctx = ctx;
} }
public void setAnchor(View anchor) {
this.anchor = anchor;
}
public View getAnchor() {
return anchor;
}
public int length() { public int length() {
return items.size(); return items.size();
} }
public int getElementId(int pos) { public int getElementId(int position) {
return items.get(pos); return items.get(position).getTitleId();
} }
public OnContextMenuClick getClickAdapter(int i) { public OnContextMenuClick getClickAdapter(int position) {
return checkListeners.get(i); return items.get(position).getCheckBoxListener();
} }
public OnIntegerValueChangedListener getIntegerLister(int i) { public OnIntegerValueChangedListener getIntegerLister(int position) {
return integerListeners.get(i); return items.get(position).getIntegerListener();
} }
public String getItemName(int pos) { public String getItemName(int position) {
return itemNames.get(pos); return items.get(position).getTitle();
} }
public String getItemDescr(int pos) { public String getItemDescr(int position) {
return itemDescription.get(pos); return items.get(position).getDescription();
} }
public void setItemName(int pos, String str) { public Boolean getSelection(int position) {
itemNames.set(pos, str); return items.get(position).getSelected();
} }
public void setItemDescription(int pos, String str) { public int getProgress(int position) {
itemDescription.set(pos, str); return items.get(position).getProgress();
} }
public int getSelection(int pos) { public int getLoading(int position) {
return selectedList.get(pos); return items.get(position).isLoading() ? 1 : 0;
} }
public int getProgress(int pos) { public Drawable getImage(OsmandApplication ctx, int position, boolean light) {
return progressList.get(pos); @DrawableRes
} int lst = items.get(position).getIcon();
if (lst != -1) {
public int getLoading(int pos) {
return loadingList.get(pos);
}
public void setSelection(int pos, int s) {
selectedList.set(pos, s);
}
public void setProgress(int pos, int s) {
progressList.set(pos, s);
}
public Drawable getImage(OsmandApplication ctx, int pos, boolean light) {
int lst = iconList.get(pos);
if (lst != 0) {
return ctx.getResources().getDrawable(lst); return ctx.getResources().getDrawable(lst);
} }
int lstLight = lightIconList.get(pos); @DrawableRes
if (lstLight != 0) { int lstLight = items.get(position).getLightIcon();
if (lstLight != -1) {
return ctx.getIconsCache().getIcon(lstLight, light); return ctx.getIconsCache().getIcon(lstLight, light);
} }
return null; return null;
} }
public Drawable getSecondaryImage(OsmandApplication ctx, int pos, boolean light) { public Drawable getSecondaryImage(OsmandApplication ctx, int position, boolean light) {
@DrawableRes @DrawableRes
int secondaryDrawableId = secondaryLightIconList.get(pos); int secondaryDrawableId = items.get(position).getSecondaryLightIcon();
if (secondaryDrawableId != 0) { if (secondaryDrawableId != -1) {
return ContextCompat.getDrawable(ctx, secondaryDrawableId); return ctx.getIconsCache().getIcon(secondaryDrawableId, light);
} }
return null; return null;
} }
@ -159,55 +120,50 @@ public class ContextMenuAdapter {
} }
} }
public boolean isCategory(int pos) { public boolean isCategory(int pos) {
return isCategory.get(pos) > 0; return items.get(pos).isCategory();
}
public Item item(String name) {
Item i = new Item();
i.id = (name.hashCode() << 4) | items.size();
i.name = name;
return i;
}
public Item item(@StringRes int resId) {
Item i = new Item();
i.id = resId;
i.name = ctx.getString(resId);
return i;
}
public String[] getItemNames() {
return itemNames.toArray(new String[itemNames.size()]);
}
public void removeItem(int pos) {
items.removeAt(pos);
itemNames.remove(pos);
selectedList.removeAt(pos);
progressList.removeAt(pos);
iconList.removeAt(pos);
lightIconList.removeAt(pos);
secondaryLightIconList.removeAt(pos);
checkListeners.remove(pos);
integerListeners.remove(pos);
isCategory.removeAt(pos);
layoutIds.removeAt(pos);
loadingList.removeAt(pos);
} }
public int getLayoutId(int position) { public int getLayoutId(int position) {
int l = layoutIds.get(position); int l = items.get(position).getLayout();
if (l != -1) { if (l != -1) {
return l; return l;
} }
return defaultLayoutId; return defaultLayoutId;
} }
public void setItemName(int position, String str) {
items.get(position).setTitle(str);
}
public void setItemDescription(int position, String str) {
items.get(position).setDescription(str);
}
public void setSelection(int position, boolean s) {
items.get(position).setSelected(s);
}
public void setProgress(int position, int progress) {
items.get(position).setProgress(progress);
}
// Adapter related
public String[] getItemNames() {
String[] itemNames = new String[items.size()];
for (int i = 0; i < items.size(); i++) {
itemNames[i] = items.get(i).getTitle();
}
return itemNames;
}
public void addItem(ContextMenuItem item) {
items.add(item);
}
public void removeItem(int pos) {
items.remove(pos);
}
public void setDefaultLayoutId(int defaultLayoutId) { public void setDefaultLayoutId(int defaultLayoutId) {
this.defaultLayoutId = defaultLayoutId; this.defaultLayoutId = defaultLayoutId;
@ -223,19 +179,17 @@ public class ContextMenuAdapter {
final int layoutId = defaultLayoutId; final int layoutId = defaultLayoutId;
final OsmandApplication app = ((OsmandApplication) activity.getApplication()); final OsmandApplication app = ((OsmandApplication) activity.getApplication());
return new ContextMenuArrayAdapter(activity, layoutId, R.id.title, return new ContextMenuArrayAdapter(activity, layoutId, R.id.title,
getItemNames(), app, holoLight); items.toArray(new ContextMenuItem[items.size()]), app, holoLight);
} }
public class ContextMenuArrayAdapter extends ArrayAdapter<String> { public class ContextMenuArrayAdapter extends ArrayAdapter<ContextMenuItem> {
private Activity activity;
private OsmandApplication app; private OsmandApplication app;
private boolean holoLight; private boolean holoLight;
private int layoutId; private int layoutId;
public ContextMenuArrayAdapter(Activity context, int resource, int textViewResourceId, public ContextMenuArrayAdapter(Activity context, int resource, int textViewResourceId,
String[] objects, OsmandApplication app, boolean holoLight) { ContextMenuItem[] objects, OsmandApplication app, boolean holoLight) {
super(context, resource, textViewResourceId, objects); super(context, resource, textViewResourceId, objects);
activity = context;
this.app = app; this.app = app;
this.holoLight = holoLight; this.holoLight = holoLight;
layoutId = resource; layoutId = resource;
@ -244,10 +198,12 @@ public class ContextMenuAdapter {
@Override @Override
public View getView(final int position, View convertView, ViewGroup parent) { public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View // User super class to create the View
final ContextMenuItem item = getItem(position);
Integer lid = getLayoutId(position); Integer lid = getLayoutId(position);
if (lid == R.layout.mode_toggles) { if (lid == R.layout.mode_toggles) {
final Set<ApplicationMode> selected = new LinkedHashSet<ApplicationMode>(); final Set<ApplicationMode> selected = new LinkedHashSet<ApplicationMode>();
return AppModeDialog.prepareAppModeDrawerView(activity, visibleModes, selected, allModes, true, new View.OnClickListener() { return AppModeDialog.prepareAppModeDrawerView((Activity) getContext(),
selected, allModes, true, new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (selected.size() > 0) { if (selected.size() > 0) {
@ -261,22 +217,22 @@ public class ContextMenuAdapter {
}); });
} }
if (convertView == null || (!lid.equals(convertView.getTag()))) { if (convertView == null || (!lid.equals(convertView.getTag()))) {
convertView = activity.getLayoutInflater().inflate(lid, parent, false); convertView = LayoutInflater.from(getContext()).inflate(lid, parent, false);
// AndroidUtils.setListItemBackground(ctx, convertView, !holoLight); // AndroidUtils.setListItemBackground(ctx, convertView, !holoLight);
convertView.setTag(lid); convertView.setTag(lid);
} }
TextView tv = (TextView) convertView.findViewById(R.id.title); TextView tv = (TextView) convertView.findViewById(R.id.title);
if (!isCategory(position)) { if (!isCategory(position)) {
AndroidUtils.setTextPrimaryColor(ctx, tv, !holoLight); AndroidUtils.setTextPrimaryColor(getContext(), tv, !holoLight);
} }
tv.setText(isCategory(position) ? getItemName(position).toUpperCase() : getItemName(position)); tv.setText(isCategory(position) ? getItemName(position).toUpperCase() : getItemName(position));
if (layoutId == R.layout.simple_list_menu_item) { if (layoutId == R.layout.simple_list_menu_item) {
int color = activity.getResources() int color = ContextCompat.getColor(getContext(),
.getColor(holoLight ? R.color.icon_color : R.color.dashboard_subheader_text_dark); holoLight ? R.color.icon_color : R.color.dashboard_subheader_text_dark);
Drawable imageId = app.getIconsCache().getPaintedContentIcon( Drawable imageId = ContextCompat.getDrawable(getContext(), item.getLightIcon());
lightIconList.get(position), color); DrawableCompat.setTint(imageId, color);
float density = activity.getResources().getDisplayMetrics().density; float density = getContext().getResources().getDisplayMetrics().density;
int paddingInPixels = (int) (24 * density); int paddingInPixels = (int) (24 * density);
int drawableSizeInPixels = (int) (24 * density); // 32 int drawableSizeInPixels = (int) (24 * density); // 32
imageId.setBounds(0, 0, drawableSizeInPixels, drawableSizeInPixels); imageId.setBounds(0, 0, drawableSizeInPixels, drawableSizeInPixels);
@ -293,9 +249,9 @@ public class ContextMenuAdapter {
} }
} }
@DrawableRes @DrawableRes
int secondaryLightDrawable = secondaryLightIconList.get(position); int secondaryLightDrawable = item.getSecondaryLightIcon();
if (secondaryLightDrawable != 0) { if (secondaryLightDrawable != -1) {
int color = ContextCompat.getColor(ctx, int color = ContextCompat.getColor(getContext(),
holoLight ? R.color.icon_color : R.color.dashboard_subheader_text_dark); holoLight ? R.color.icon_color : R.color.dashboard_subheader_text_dark);
Drawable drawable = getSecondaryImage(app, position, holoLight); Drawable drawable = getSecondaryImage(app, position, holoLight);
DrawableCompat.setTint(drawable, color); DrawableCompat.setTint(drawable, color);
@ -317,17 +273,17 @@ public class ContextMenuAdapter {
if (convertView.findViewById(R.id.toggle_item) != null) { if (convertView.findViewById(R.id.toggle_item) != null) {
final CompoundButton ch = (CompoundButton) convertView.findViewById(R.id.toggle_item); final CompoundButton ch = (CompoundButton) convertView.findViewById(R.id.toggle_item);
if (selectedList.get(position) != -1) { if (item.getSelected() != null) {
ch.setOnCheckedChangeListener(null); ch.setOnCheckedChangeListener(null);
ch.setVisibility(View.VISIBLE); ch.setVisibility(View.VISIBLE);
ch.setChecked(selectedList.get(position) > 0); ch.setChecked(item.getSelected());
final ArrayAdapter<String> la = this; final ArrayAdapter<ContextMenuItem> la = this;
final OnCheckedChangeListener listener = new OnCheckedChangeListener() { final OnCheckedChangeListener listener = new OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
OnContextMenuClick ca = getClickAdapter(position); OnContextMenuClick ca = getClickAdapter(position);
selectedList.set(position, isChecked ? 1 : 0); item.setSelected(isChecked);
if (ca != null) { if (ca != null) {
ca.onContextMenuClick(la, getElementId(position), position, isChecked); ca.onContextMenuClick(la, getElementId(position), position, isChecked);
} }
@ -342,13 +298,13 @@ public class ContextMenuAdapter {
if (convertView.findViewById(R.id.seekbar) != null) { if (convertView.findViewById(R.id.seekbar) != null) {
SeekBar seekBar = (SeekBar) convertView.findViewById(R.id.seekbar); SeekBar seekBar = (SeekBar) convertView.findViewById(R.id.seekbar);
if (progressList.get(position) != -1) { if (item.getProgress() != -1) {
seekBar.setProgress(getProgress(position)); seekBar.setProgress(getProgress(position));
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
OnIntegerValueChangedListener listener = getIntegerLister(position); OnIntegerValueChangedListener listener = getIntegerLister(position);
progressList.set(position, progress); item.setProgress(progress);
if (listener != null && fromUser) { if (listener != null && fromUser) {
listener.onIntegerValueChangedListener(progress); listener.onIntegerValueChangedListener(progress);
} }
@ -370,7 +326,7 @@ public class ContextMenuAdapter {
if (convertView.findViewById(R.id.ProgressBar) != null) { if (convertView.findViewById(R.id.ProgressBar) != null) {
ProgressBar bar = (ProgressBar) convertView.findViewById(R.id.ProgressBar); ProgressBar bar = (ProgressBar) convertView.findViewById(R.id.ProgressBar);
if (loadingList.get(position) == 1) { if (item.isLoading()) {
bar.setVisibility(View.VISIBLE); bar.setVisibility(View.VISIBLE);
} else { } else {
bar.setVisibility(View.INVISIBLE); bar.setVisibility(View.INVISIBLE);
@ -423,113 +379,4 @@ public class ContextMenuAdapter {
} }
} }
public class Item {
@DrawableRes
int icon = 0;
@DrawableRes
int lightIcon = 0;
@DrawableRes
int secondaryLightIcon = 0;
@StringRes
int id;
String name;
int selected = -1;
int progress = -1;
@LayoutRes
int layout = -1;
int loading = -1;
boolean cat;
int pos = -1;
String description = "";
private OnContextMenuClick checkBoxListener;
private OnIntegerValueChangedListener integerListener;
private Item() {
}
public Item icon(@DrawableRes int icon) {
this.icon = icon;
return this;
}
public Item colorIcon(@DrawableRes int icon) {
this.lightIcon = icon;
return this;
}
public Item secondaryIconColor(@DrawableRes int icon) {
this.secondaryLightIcon = icon;
return this;
}
public Item position(int pos) {
this.pos = pos;
return this;
}
public Item selected(int selected) {
this.selected = selected;
return this;
}
public Item progress(int progress) {
this.progress = progress;
return this;
}
public Item loading(int loading) {
this.loading = loading;
return this;
}
public Item layout(@LayoutRes int l) {
this.layout = l;
return this;
}
public Item description(String descr) {
this.description = descr;
return this;
}
public Item listen(OnContextMenuClick l) {
this.checkBoxListener = l;
return this;
}
public Item listenInteger(OnIntegerValueChangedListener l) {
this.integerListener = l;
return this;
}
public void reg() {
if (pos >= items.size() || pos < 0) {
pos = items.size();
}
items.insert(pos, id);
itemNames.add(pos, name);
itemDescription.add(pos, description);
selectedList.insert(pos, selected);
progressList.insert(pos, progress);
loadingList.insert(pos, loading);
layoutIds.insert(pos, layout);
iconList.insert(pos, icon);
lightIconList.insert(pos, lightIcon);
secondaryLightIconList.insert(pos, secondaryLightIcon);
checkListeners.add(pos, checkBoxListener);
integerListeners.add(pos, integerListener);
isCategory.insert(pos, cat ? 1 : 0);
}
public Item setCategory(boolean b) {
cat = b;
return this;
}
public Item name(String name) {
this.name = name;
return this;
}
}
} }

View file

@ -0,0 +1,235 @@
package net.osmand.plus;
import android.content.Context;
import android.support.annotation.DrawableRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
/**
* Created by GaidamakUA on 3/25/16.
*/
public class ContextMenuItem {
@StringRes
private final int titleId;
private String title;
@DrawableRes
private final int icon;
@DrawableRes
private final int lightIcon;
@DrawableRes
private final int secondaryLightIcon;
private Boolean selected;
private int progress;
@LayoutRes
private final int layout;
private boolean loading;
private final boolean category;
private final int pos;
private String description;
private ContextMenuAdapter.OnContextMenuClick checkBoxListener;
private ContextMenuAdapter.OnIntegerValueChangedListener integerListener;
private ContextMenuItem(int titleId, String title, int icon, int lightIcon, int secondaryLightIcon,
Boolean selected, int progress, int layout, boolean loading, boolean category,
int pos, String description, ContextMenuAdapter.OnContextMenuClick checkBoxListener,
ContextMenuAdapter.OnIntegerValueChangedListener integerListener) {
this.titleId = titleId;
this.title = title;
this.icon = icon;
this.lightIcon = lightIcon;
this.secondaryLightIcon = secondaryLightIcon;
this.selected = selected;
this.progress = progress;
this.layout = layout;
this.loading = loading;
this.category = category;
this.pos = pos;
this.description = description;
this.checkBoxListener = checkBoxListener;
this.integerListener = integerListener;
}
public int getTitleId() {
return titleId;
}
public String getTitle() {
return title;
}
public int getIcon() {
return icon;
}
public int getLightIcon() {
return lightIcon;
}
public int getSecondaryLightIcon() {
return secondaryLightIcon;
}
public Boolean getSelected() {
return selected;
}
public int getProgress() {
return progress;
}
public int getLayout() {
return layout;
}
public boolean isLoading() {
return loading;
}
public boolean isCategory() {
return category;
}
public int getPos() {
return pos;
}
public String getDescription() {
return description;
}
public ContextMenuAdapter.OnContextMenuClick getCheckBoxListener() {
return checkBoxListener;
}
public ContextMenuAdapter.OnIntegerValueChangedListener getIntegerListener() {
return integerListener;
}
public void setTitle(String title) {
this.title = title;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
public void setProgress(int progress) {
this.progress = progress;
}
public void setLoading(boolean loading) {
this.loading = loading;
}
public void setDescription(String description) {
this.description = description;
}
public void setCheckBoxListener(ContextMenuAdapter.OnContextMenuClick checkBoxListener) {
this.checkBoxListener = checkBoxListener;
}
public void setIntegerListener(ContextMenuAdapter.OnIntegerValueChangedListener integerListener) {
this.integerListener = integerListener;
}
public static ItemBuilder createBuilder(String title) {
return new ItemBuilder().setTitle(title);
}
public static class ItemBuilder {
private int mTitleId;
private String mTitle;
private int mIcon = -1;
private int mLightIcon = -1;
private int mSecondaryLightIcon = -1;
private Boolean mSelected = null;
private int mProgress = -1;
private int mLayout = -1;
private boolean mLoading = false;
private boolean mCat = false;
private int mPos = -1;
private String mDescription = null;
private ContextMenuAdapter.OnContextMenuClick mCheckBoxListener = null;
private ContextMenuAdapter.OnIntegerValueChangedListener mIntegerListener = null;
public ItemBuilder setTitleId(int titleId, @Nullable Context context) {
this.mTitleId = titleId;
if (context != null) {
mTitle = context.getString(titleId);
}
return this;
}
public ItemBuilder setTitle(String title) {
this.mTitle = title;
this.mTitleId = title.hashCode();
return this;
}
public ItemBuilder setIcon(int icon) {
mIcon = icon;
return this;
}
public ItemBuilder setColorIcon(int lightIcon) {
mLightIcon = lightIcon;
return this;
}
public ItemBuilder setSecondaryLightIcon(int secondaryLightIcon) {
mSecondaryLightIcon = secondaryLightIcon;
return this;
}
public ItemBuilder setSelected(boolean selected) {
mSelected = selected;
return this;
}
public ItemBuilder setProgress(int progress) {
mProgress = progress;
return this;
}
public ItemBuilder setLayout(int layout) {
mLayout = layout;
return this;
}
public ItemBuilder setLoading(boolean loading) {
mLoading = loading;
return this;
}
public ItemBuilder setCategory(boolean cat) {
mCat = cat;
return this;
}
public ItemBuilder setPosition(int pos) {
mPos = pos;
return this;
}
public ItemBuilder setDescription(String description) {
mDescription = description;
return this;
}
public ItemBuilder setListener(ContextMenuAdapter.OnContextMenuClick checkBoxListener) {
mCheckBoxListener = checkBoxListener;
return this;
}
public ItemBuilder setIntegerListener(ContextMenuAdapter.OnIntegerValueChangedListener integerListener) {
mIntegerListener = integerListener;
return this;
}
public ContextMenuItem createItem() {
return new ContextMenuItem(mTitleId, mTitle, mIcon, mLightIcon, mSecondaryLightIcon, mSelected, mProgress, mLayout, mLoading, mCat, mPos, mDescription, mCheckBoxListener, mIntegerListener);
}
}
}

View file

@ -30,6 +30,7 @@ import net.osmand.map.ITileSource;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
@ -279,15 +280,17 @@ public class MapActivityActions implements DialogProvider {
public void contextMenuPoint(final double latitude, final double longitude, final ContextMenuAdapter iadapter, Object selectedObj) { public void contextMenuPoint(final double latitude, final double longitude, final ContextMenuAdapter iadapter, Object selectedObj) {
final ContextMenuAdapter adapter = iadapter == null ? new ContextMenuAdapter(mapActivity) : iadapter; final ContextMenuAdapter adapter = iadapter == null ? new ContextMenuAdapter(mapActivity) : iadapter;
adapter.item(R.string.context_menu_item_search).colorIcon(R.drawable.ic_action_search_dark).reg(); ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder();
adapter.addItem(itemBuilder.setTitleId(R.string.context_menu_item_search, mapActivity)
.setColorIcon(R.drawable.ic_action_search_dark).createItem());
if (!mapActivity.getRoutingHelper().isFollowingMode() && !mapActivity.getRoutingHelper().isRoutePlanningMode()) { if (!mapActivity.getRoutingHelper().isFollowingMode() && !mapActivity.getRoutingHelper().isRoutePlanningMode()) {
adapter.item(R.string.context_menu_item_directions_from).colorIcon( adapter.addItem(itemBuilder.setTitleId(R.string.context_menu_item_directions_from, mapActivity)
R.drawable.ic_action_gdirections_dark).reg(); .setColorIcon(R.drawable.ic_action_gdirections_dark).createItem());
} }
if (getMyApplication().getTargetPointsHelper().getPointToNavigate() != null && if (getMyApplication().getTargetPointsHelper().getPointToNavigate() != null &&
(mapActivity.getRoutingHelper().isFollowingMode() || mapActivity.getRoutingHelper().isRoutePlanningMode())) { (mapActivity.getRoutingHelper().isFollowingMode() || mapActivity.getRoutingHelper().isRoutePlanningMode())) {
adapter.item(R.string.context_menu_item_last_intermediate_point).colorIcon( adapter.addItem(itemBuilder.setTitleId(R.string.context_menu_item_last_intermediate_point, mapActivity)
R.drawable.ic_action_intermediate).reg(); .setColorIcon(R.drawable.ic_action_intermediate).createItem());
} }
OsmandPlugin.registerMapContextMenu(mapActivity, latitude, longitude, adapter, selectedObj); OsmandPlugin.registerMapContextMenu(mapActivity, latitude, longitude, adapter, selectedObj);
@ -593,8 +596,9 @@ public class MapActivityActions implements DialogProvider {
final OsmandApplication app = mapActivity.getMyApplication(); final OsmandApplication app = mapActivity.getMyApplication();
ContextMenuAdapter optionsMenuHelper = new ContextMenuAdapter(app); ContextMenuAdapter optionsMenuHelper = new ContextMenuAdapter(app);
optionsMenuHelper.item(R.string.home).colorIcon(R.drawable.map_dashboard) optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.home, mapActivity)
.listen(new OnContextMenuClick() { .setColorIcon(R.drawable.map_dashboard)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
MapActivity.clearPrevActivityIntent(); MapActivity.clearPrevActivityIntent();
@ -602,30 +606,33 @@ public class MapActivityActions implements DialogProvider {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.DASHBOARD); mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.DASHBOARD);
return true; return true;
} }
}).reg(); }).createItem());
if (settings.USE_MAP_MARKERS.get()) { if (settings.USE_MAP_MARKERS.get()) {
optionsMenuHelper.item(R.string.map_markers).colorIcon(R.drawable.ic_action_flag_dark) optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_markers, mapActivity)
.listen(new OnContextMenuClick() { .setColorIcon(R.drawable.ic_action_flag_dark)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
MapActivity.clearPrevActivityIntent(); MapActivity.clearPrevActivityIntent();
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.MAP_MARKERS); mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.MAP_MARKERS);
return false; return false;
} }
}).reg(); }).createItem());
} else { } else {
optionsMenuHelper.item(R.string.waypoints).colorIcon(R.drawable.ic_action_intermediate) optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.waypoints, mapActivity)
.listen(new OnContextMenuClick() { .setColorIcon(R.drawable.ic_action_intermediate)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
MapActivity.clearPrevActivityIntent(); MapActivity.clearPrevActivityIntent();
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS); mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS);
return false; return false;
} }
}).reg(); }).createItem());
} }
optionsMenuHelper.item(R.string.get_directions).colorIcon(R.drawable.ic_action_gdirections_dark) optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.get_directions, mapActivity)
.listen(new OnContextMenuClick() { .setColorIcon(R.drawable.ic_action_gdirections_dark)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
MapActivity.clearPrevActivityIntent(); MapActivity.clearPrevActivityIntent();
@ -640,11 +647,11 @@ public class MapActivityActions implements DialogProvider {
} }
return true; return true;
} }
}).reg(); }).createItem());
// Default actions (Layers, Configure Map screen, Settings, Search, Favorites) // Default actions (Layers, Configure Map screen, Settings, Search, Favorites)
optionsMenuHelper.item(R.string.search_button) optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.search_button, mapActivity)
.colorIcon(R.drawable.ic_action_search_dark) .setColorIcon(R.drawable.ic_action_search_dark)
.listen(new OnContextMenuClick() { .setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization() Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization()
@ -659,10 +666,11 @@ public class MapActivityActions implements DialogProvider {
mapActivity.startActivity(newIntent); mapActivity.startActivity(newIntent);
return true; return true;
} }
}).reg(); }).createItem());
optionsMenuHelper.item(R.string.shared_string_my_places).colorIcon(R.drawable.ic_action_fav_dark) optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_my_places, mapActivity)
.listen(new OnContextMenuClick() { .setColorIcon(R.drawable.ic_action_fav_dark)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization() Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization()
@ -671,38 +679,41 @@ public class MapActivityActions implements DialogProvider {
mapActivity.startActivity(newIntent); mapActivity.startActivity(newIntent);
return true; return true;
} }
}).reg(); }).createItem());
optionsMenuHelper.item(R.string.show_point_options).colorIcon(R.drawable.ic_action_marker_dark) optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.show_point_options, mapActivity)
.listen(new OnContextMenuClick() { .setColorIcon(R.drawable.ic_action_marker_dark)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
MapActivity.clearPrevActivityIntent(); MapActivity.clearPrevActivityIntent();
mapActivity.getMapLayers().getContextMenuLayer().showContextMenu(mapView.getLatitude(), mapView.getLongitude(), true); mapActivity.getMapLayers().getContextMenuLayer().showContextMenu(mapView.getLatitude(), mapView.getLongitude(), true);
return true; return true;
} }
}).reg(); }).createItem());
optionsMenuHelper.item(R.string.configure_map).colorIcon(R.drawable.ic_action_layers_dark) optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.configure_map, mapActivity)
.listen(new OnContextMenuClick() { .setColorIcon(R.drawable.ic_action_layers_dark)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
MapActivity.clearPrevActivityIntent(); MapActivity.clearPrevActivityIntent();
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_MAP); mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_MAP);
return false; return false;
} }
}).reg(); }).createItem());
optionsMenuHelper.item(R.string.layer_map_appearance).colorIcon(R.drawable.ic_configure_screen_dark) optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_map_appearance, mapActivity)
.listen(new OnContextMenuClick() { .setColorIcon(R.drawable.ic_configure_screen_dark)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
MapActivity.clearPrevActivityIntent(); MapActivity.clearPrevActivityIntent();
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_SCREEN); mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_SCREEN);
return false; return false;
} }
}).reg(); }).createItem());
String d = getString(R.string.index_settings); String d = getString(R.string.index_settings);
if (app.getDownloadThread().getIndexes().isDownloadedFromInternet) { if (app.getDownloadThread().getIndexes().isDownloadedFromInternet) {
@ -711,8 +722,9 @@ public class MapActivityActions implements DialogProvider {
d += " (" + updt.size() + ")"; d += " (" + updt.size() + ")";
} }
} }
optionsMenuHelper.item(R.string.index_settings).name(d).colorIcon(R.drawable.ic_type_archive) optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.index_settings, null)
.listen(new OnContextMenuClick() { .setTitle(d).setColorIcon(R.drawable.ic_type_archive)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization() Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization()
@ -721,11 +733,12 @@ public class MapActivityActions implements DialogProvider {
mapActivity.startActivity(newIntent); mapActivity.startActivity(newIntent);
return true; return true;
} }
}).reg(); }).createItem());
if (Version.isGooglePlayEnabled(app)) { if (Version.isGooglePlayEnabled(app)) {
optionsMenuHelper.item(R.string.osm_live).colorIcon(R.drawable.ic_action_osm_live) optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.osm_live, mapActivity)
.listen(new OnContextMenuClick() { .setColorIcon(R.drawable.ic_action_osm_live)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
Intent intent = new Intent(mapActivity, OsmLiveActivity.class); Intent intent = new Intent(mapActivity, OsmLiveActivity.class);
@ -733,11 +746,12 @@ public class MapActivityActions implements DialogProvider {
mapActivity.startActivity(intent); mapActivity.startActivity(intent);
return false; return false;
} }
}).reg(); }).createItem());
} }
optionsMenuHelper.item(R.string.prefs_plugins).colorIcon(R.drawable.ic_extension_dark) optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.prefs_plugins, mapActivity)
.listen(new OnContextMenuClick() { .setColorIcon(R.drawable.ic_extension_dark)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization() Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization()
@ -746,11 +760,12 @@ public class MapActivityActions implements DialogProvider {
mapActivity.startActivity(newIntent); mapActivity.startActivity(newIntent);
return true; return true;
} }
}).reg(); }).createItem());
optionsMenuHelper.item(R.string.shared_string_settings).colorIcon(R.drawable.ic_action_settings) optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_settings, mapActivity)
.listen(new OnContextMenuClick() { .setColorIcon(R.drawable.ic_action_settings)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
final Intent settings = new Intent(mapActivity, getMyApplication().getAppCustomization() final Intent settings = new Intent(mapActivity, getMyApplication().getAppCustomization()
@ -759,9 +774,10 @@ public class MapActivityActions implements DialogProvider {
mapActivity.startActivity(settings); mapActivity.startActivity(settings);
return true; return true;
} }
}).reg(); }).createItem());
optionsMenuHelper.item(R.string.shared_string_help).colorIcon(R.drawable.ic_action_help) optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_help, mapActivity)
.listen(new OnContextMenuClick() { .setColorIcon(R.drawable.ic_action_help)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
Intent intent = new Intent(mapActivity, HelpActivity.class); Intent intent = new Intent(mapActivity, HelpActivity.class);
@ -769,7 +785,7 @@ public class MapActivityActions implements DialogProvider {
mapActivity.startActivity(intent); mapActivity.startActivity(intent);
return true; return true;
} }
}).reg(); }).createItem());
//////////// Others //////////// Others
OsmandPlugin.registerOptionsMenu(mapActivity, optionsMenuHelper); OsmandPlugin.registerOptionsMenu(mapActivity, optionsMenuHelper);

View file

@ -14,7 +14,7 @@ import net.osmand.access.AccessibleToast;
import net.osmand.map.ITileSource; import net.osmand.map.ITileSource;
import net.osmand.map.TileSourceManager.TileSourceTemplate; import net.osmand.map.TileSourceManager.TileSourceTemplate;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.Item; import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -262,7 +262,9 @@ public class MapActivityLayers {
OsmandApplication app = (OsmandApplication) getApplication(); OsmandApplication app = (OsmandApplication) getApplication();
final PoiFiltersHelper poiFilters = app.getPoiFilters(); final PoiFiltersHelper poiFilters = app.getPoiFilters();
final ContextMenuAdapter adapter = new ContextMenuAdapter(activity); final ContextMenuAdapter adapter = new ContextMenuAdapter(activity);
adapter.item(R.string.shared_string_search).colorIcon(R.drawable.ic_action_search_dark).reg(); adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.shared_string_search, app)
.setColorIcon(R.drawable.ic_action_search_dark).createItem());
final List<PoiUIFilter> list = new ArrayList<PoiUIFilter>(); final List<PoiUIFilter> list = new ArrayList<PoiUIFilter>();
list.add(poiFilters.getCustomPOIFilter()); list.add(poiFilters.getCustomPOIFilter());
for (PoiUIFilter f : poiFilters.getTopDefinedPoiFilters()) { for (PoiUIFilter f : poiFilters.getTopDefinedPoiFilters()) {
@ -301,13 +303,14 @@ public class MapActivityLayers {
private void addFilterToList(final ContextMenuAdapter adapter, final List<PoiUIFilter> list, PoiUIFilter f) { private void addFilterToList(final ContextMenuAdapter adapter, final List<PoiUIFilter> list, PoiUIFilter f) {
list.add(f); list.add(f);
Item it = adapter.item(f.getName()).selected(-1); ContextMenuItem.ItemBuilder builder = new ContextMenuItem.ItemBuilder();
builder.setTitle(f.getName());
if (RenderingIcons.containsBigIcon(f.getIconId())) { if (RenderingIcons.containsBigIcon(f.getIconId())) {
it.icon(RenderingIcons.getBigIconResourceId(f.getIconId())); builder.setIcon(RenderingIcons.getBigIconResourceId(f.getIconId()));
} else { } else {
it.icon(R.drawable.mx_user_defined); builder.setIcon(R.drawable.mx_user_defined);
} }
it.reg(); adapter.addItem(builder.createItem());
} }
public void selectMapLayer(final OsmandMapTileView mapView) { public void selectMapLayer(final OsmandMapTileView mapView) {

View file

@ -36,7 +36,7 @@ public class AppModeDialog {
//special method for drawer menu //special method for drawer menu
//needed because if there's more than 4 items - the don't fit in drawer //needed because if there's more than 4 items - the don't fit in drawer
public static View prepareAppModeDrawerView(Activity a, List<ApplicationMode> visible, final Set<ApplicationMode> selected, ContextMenuAdapter.BooleanResult allModes, public static View prepareAppModeDrawerView(Activity a, final Set<ApplicationMode> selected, ContextMenuAdapter.BooleanResult allModes,
boolean useMapTheme, final View.OnClickListener onClickListener) { boolean useMapTheme, final View.OnClickListener onClickListener) {
OsmandSettings settings = ((OsmandApplication) a.getApplication()).getSettings(); OsmandSettings settings = ((OsmandApplication) a.getApplication()).getSettings();
final List<ApplicationMode> values = new ArrayList<ApplicationMode>(ApplicationMode.values(settings)); final List<ApplicationMode> values = new ArrayList<ApplicationMode>(ApplicationMode.values(settings));

View file

@ -48,6 +48,7 @@ import net.osmand.data.PointDescription;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -590,8 +591,11 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
return true; return true;
} }
}; };
adapter.item(R.string.layer_recordings).selected(SHOW_RECORDINGS.get() ? 1 : 0) adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_recordings, app)
.colorIcon(R.drawable.ic_action_micro_dark).listen(listener).position(12).reg(); .setSelected(SHOW_RECORDINGS.get())
.setColorIcon(R.drawable.ic_action_micro_dark)
.setPosition(12)
.setListener(listener).createItem());
} }
@Override @Override
@ -600,33 +604,42 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
if (isRecording()) { if (isRecording()) {
return; return;
} }
adapter.item(R.string.recording_context_menu_arecord).colorIcon(R.drawable.ic_action_micro_dark) adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.recording_context_menu_arecord, app)
.listen(new OnContextMenuClick() { .setColorIcon(R.drawable.ic_action_micro_dark)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
recordAudio(latitude, longitude, mapActivity); recordAudio(latitude, longitude, mapActivity);
return true; return true;
} }
}).position(6).reg(); })
adapter.item(R.string.recording_context_menu_vrecord).colorIcon(R.drawable.ic_action_video_dark) .setPosition(6)
.listen(new OnContextMenuClick() { .createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.recording_context_menu_vrecord, app)
.setColorIcon(R.drawable.ic_action_video_dark)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
recordVideo(latitude, longitude, mapActivity); recordVideo(latitude, longitude, mapActivity);
return true; return true;
} }
}).position(7).reg(); })
adapter.item(R.string.recording_context_menu_precord).colorIcon(R.drawable.ic_action_photo_dark) .setPosition(7)
.listen(new OnContextMenuClick() { .createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.recording_context_menu_precord, app)
.setColorIcon(R.drawable.ic_action_photo_dark)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
takePhoto(latitude, longitude, mapActivity, false); takePhoto(latitude, longitude, mapActivity, false);
return true; return true;
} }
}).position(8).reg(); })
.setPosition(8)
.createItem());
} }
@Override @Override

View file

@ -6,6 +6,7 @@ import android.widget.ArrayAdapter;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -56,15 +57,17 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
@Override @Override
public void registerOptionsMenuItems(final MapActivity mapActivity, ContextMenuAdapter helper) { public void registerOptionsMenuItems(final MapActivity mapActivity, ContextMenuAdapter helper) {
if (Version.isDeveloperVersion(mapActivity.getMyApplication())) { if (Version.isDeveloperVersion(mapActivity.getMyApplication())) {
helper.item(R.string.version_settings).colorIcon(R.drawable.ic_action_gabout_dark) helper.addItem(new ContextMenuItem.ItemBuilder()
.listen(new OnContextMenuClick() { .setTitleId(R.string.version_settings, mapActivity)
.setColorIcon(R.drawable.ic_action_gabout_dark)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
final Intent mapIntent = new Intent(mapActivity, ContributionVersionActivity.class); final Intent mapIntent = new Intent(mapActivity, ContributionVersionActivity.class);
mapActivity.startActivityForResult(mapIntent, 0); mapActivity.startActivityForResult(mapIntent, 0);
return true; return true;
} }
}).reg(); }).createItem());
} }
} }

View file

@ -15,6 +15,7 @@ import net.osmand.core.android.MapRendererContext;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.ContextMenuAdapter.OnRowItemClick; import net.osmand.plus.ContextMenuAdapter.OnRowItemClick;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
@ -54,16 +55,20 @@ import gnu.trove.list.array.TIntArrayList;
public class ConfigureMapMenu { public class ConfigureMapMenu {
private static final Log LOG = PlatformUtil.getLog(ConfigureMapMenu.class); private static final Log LOG = PlatformUtil.getLog(ConfigureMapMenu.class);
public interface OnClickListener{ public interface OnClickListener {
public void onClick(boolean result); public void onClick(boolean result);
}; }
;
private boolean allModes = false; private boolean allModes = false;
public ContextMenuAdapter createListAdapter(final MapActivity ma) { public ContextMenuAdapter createListAdapter(final MapActivity ma) {
ContextMenuAdapter adapter = new ContextMenuAdapter(ma, allModes); ContextMenuAdapter adapter = new ContextMenuAdapter(ma, allModes);
adapter.setDefaultLayoutId(R.layout.drawer_list_item); adapter.setDefaultLayoutId(R.layout.drawer_list_item);
adapter.item(R.string.app_modes_choose).layout(R.layout.mode_toggles).reg(); adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.app_modes_choose, ma)
.setLayout(R.layout.mode_toggles).createItem());
adapter.setChangeAppModeListener(new OnClickListener() { adapter.setChangeAppModeListener(new OnClickListener() {
@Override @Override
public void onClick(boolean result) { public void onClick(boolean result) {
@ -73,10 +78,10 @@ public class ConfigureMapMenu {
}); });
createLayersItems(adapter, ma); createLayersItems(adapter, ma);
createRenderingAttributeItems(adapter, ma); createRenderingAttributeItems(adapter, ma);
return adapter; return adapter;
} }
private final class LayerMenuListener extends OnRowItemClick { private final class LayerMenuListener extends OnRowItemClick {
private MapActivity ma; private MapActivity ma;
private ContextMenuAdapter cm; private ContextMenuAdapter cm;
@ -95,16 +100,16 @@ public class ConfigureMapMenu {
} }
return files; return files;
} }
@Override @Override
public boolean onRowItemClick(ArrayAdapter<?> adapter, View view, int itemId, int pos) { public boolean onRowItemClick(ArrayAdapter<?> adapter, View view, int itemId, int pos) {
if(itemId == R.string.layer_poi) { if (itemId == R.string.layer_poi) {
selectPOILayer(ma.getMyApplication().getSettings()); selectPOILayer(ma.getMyApplication().getSettings());
return false; return false;
} else if(itemId == R.string.layer_gpx_layer && cm.getSelection(pos) == 1) { } else if (itemId == R.string.layer_gpx_layer && cm.getSelection(pos)) {
ma.getMapLayers().showGPXFileLayer(getAlreadySelectedGpx(), ma.getMapView()); ma.getMapLayers().showGPXFileLayer(getAlreadySelectedGpx(), ma.getMapView());
return false; return false;
} else { } else {
return super.onRowItemClick(adapter, view, itemId, pos); return super.onRowItemClick(adapter, view, itemId, pos);
} }
} }
@ -131,13 +136,13 @@ public class ConfigureMapMenu {
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
boolean areAnyGpxTracksVisible = boolean areAnyGpxTracksVisible =
ma.getMyApplication().getSelectedGpxHelper().isShowingAnyGpxFiles(); ma.getMyApplication().getSelectedGpxHelper().isShowingAnyGpxFiles();
cm.setSelection(pos, areAnyGpxTracksVisible ? 1 : 0); cm.setSelection(pos, areAnyGpxTracksVisible);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
}); });
} }
} else if (itemId == R.string.layer_map) { } else if (itemId == R.string.layer_map) {
if(OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) == null) { if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) == null) {
Intent intent = new Intent(ma, PluginActivity.class); Intent intent = new Intent(ma, PluginActivity.class);
intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, OsmandRasterMapsPlugin.ID); intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, OsmandRasterMapsPlugin.ID);
ma.startActivity(intent); ma.startActivity(intent);
@ -165,29 +170,46 @@ public class ConfigureMapMenu {
} }
} }
private void createLayersItems(ContextMenuAdapter adapter , MapActivity activity) { private void createLayersItems(ContextMenuAdapter adapter, MapActivity activity) {
OsmandApplication app = activity.getMyApplication(); OsmandApplication app = activity.getMyApplication();
OsmandSettings settings = app.getSettings(); OsmandSettings settings = app.getSettings();
LayerMenuListener l = new LayerMenuListener(activity, adapter); LayerMenuListener l = new LayerMenuListener(activity, adapter);
adapter.item(R.string.shared_string_show).setCategory(true).layout(R.layout.drawer_list_sub_header).reg(); adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.shared_string_show, activity)
.setCategory(true).setLayout(R.layout.drawer_list_sub_header).createItem());
// String appMode = " [" + settings.getApplicationMode().toHumanString(view.getApplication()) +"] "; // String appMode = " [" + settings.getApplicationMode().toHumanString(view.getApplication()) +"] ";
adapter.item(R.string.layer_poi).selected(settings.SELECTED_POI_FILTER_FOR_MAP.get() != null ? 1 : 0) adapter.addItem(new ContextMenuItem.ItemBuilder()
.colorIcon(R.drawable.ic_action_info_dark).listen(l).reg(); .setTitleId(R.string.layer_poi, activity)
adapter.item(R.string.layer_amenity_label).selected(settings.SHOW_POI_LABEL.get() ? 1 : 0) .setSelected(settings.SELECTED_POI_FILTER_FOR_MAP.get() != null)
.colorIcon(R.drawable.ic_action_text_dark).listen(l).reg(); .setColorIcon(R.drawable.ic_action_info_dark)
adapter.item(R.string.shared_string_favorites).selected(settings.SHOW_FAVORITES.get() ? 1 : 0) .setListener(l).createItem());
.colorIcon(R.drawable.ic_action_fav_dark).listen(l).reg(); adapter.addItem(new ContextMenuItem.ItemBuilder()
adapter.item(R.string.layer_gpx_layer).selected( .setTitleId(R.string.layer_amenity_label, activity)
app.getSelectedGpxHelper().isShowingAnyGpxFiles() ? 1 : 0) .setSelected(settings.SHOW_POI_LABEL.get())
.colorIcon(R.drawable.ic_action_polygom_dark) .setColorIcon(R.drawable.ic_action_text_dark)
.listen(l).reg(); .setListener(l).createItem());
adapter.item(R.string.layer_map).colorIcon(R.drawable.ic_world_globe_dark) adapter.addItem(new ContextMenuItem.ItemBuilder()
.listen(l).reg(); .setTitleId(R.string.shared_string_favorites, activity)
if(TransportRouteHelper.getInstance().routeIsCalculated()){ .setSelected(settings.SHOW_FAVORITES.get())
adapter.item(R.string.layer_transport_route).selected(1) .setColorIcon(R.drawable.ic_action_fav_dark)
.colorIcon(R.drawable.ic_action_bus_dark).listen(l).reg(); .setListener(l).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.layer_gpx_layer, activity)
.setSelected(app.getSelectedGpxHelper().isShowingAnyGpxFiles())
.setColorIcon(R.drawable.ic_action_polygom_dark)
.setListener(l).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.layer_map, activity)
.setColorIcon(R.drawable.ic_world_globe_dark)
.setListener(l).createItem());
if (TransportRouteHelper.getInstance().routeIsCalculated()) {
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.layer_transport_route, activity)
.setSelected(true)
.setColorIcon(R.drawable.ic_action_bus_dark)
.setListener(l).createItem());
} }
OsmandPlugin.registerLayerContextMenu(activity.getMapView(), adapter, activity); OsmandPlugin.registerLayerContextMenu(activity.getMapView(), adapter, activity);
app.getAppCustomization().prepareLayerContextMenu(activity, adapter); app.getAppCustomization().prepareLayerContextMenu(activity, adapter);
} }
@ -196,209 +218,224 @@ public class ConfigureMapMenu {
activity.getMyApplication().getResourceManager().getRenderer().clearCache(); activity.getMyApplication().getResourceManager().getRenderer().clearCache();
activity.updateMapSettings(); activity.updateMapSettings();
GPXLayer gpx = activity.getMapView().getLayerByClass(GPXLayer.class); GPXLayer gpx = activity.getMapView().getLayerByClass(GPXLayer.class);
if(gpx != null) { if (gpx != null) {
gpx.updateLayerStyle(); gpx.updateLayerStyle();
} }
RouteLayer rte = activity.getMapView().getLayerByClass(RouteLayer.class); RouteLayer rte = activity.getMapView().getLayerByClass(RouteLayer.class);
if(rte != null) { if (rte != null) {
rte.updateLayerStyle(); rte.updateLayerStyle();
} }
activity.getMapView().refreshMap(true); activity.getMapView().refreshMap(true);
} }
private void createRenderingAttributeItems(final ContextMenuAdapter adapter, final MapActivity activity) { private void createRenderingAttributeItems(final ContextMenuAdapter adapter, final MapActivity activity) {
adapter.item(R.string.map_widget_map_rendering).setCategory(true).layout(R.layout.drawer_list_sub_header).reg(); adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.map_widget_map_rendering, activity)
.setCategory(true)
.setLayout(R.layout.drawer_list_sub_header).createItem());
String descr = getRenderDescr(activity); String descr = getRenderDescr(activity);
adapter.item(R.string.map_widget_renderer).listen(new OnContextMenuClick() { adapter.addItem(new ContextMenuItem.ItemBuilder()
@Override .setTitleId(R.string.map_widget_renderer, activity)
public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) { .setListener(new OnContextMenuClick() {
AlertDialog.Builder bld = new AlertDialog.Builder(activity);
bld.setTitle(R.string.renderers);
final OsmandApplication app = activity.getMyApplication();
Collection<String> rendererNames = app.getRendererRegistry().getRendererNames();
final String[] items = rendererNames.toArray(new String[rendererNames.size()]);
final String[] visibleNames = new String[items.length];
int selected = -1;
final String selectedName = app.getRendererRegistry().getCurrentSelectedRenderer().getName();
for (int j = 0; j < items.length; j++) {
if (items[j].equals(selectedName)) {
selected = j;
}
visibleNames[j] = items[j].replace('_', ' ').replace('-', ' ');
}
bld.setSingleChoiceItems(visibleNames, selected, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
String renderer = items[which]; AlertDialog.Builder bld = new AlertDialog.Builder(activity);
RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer); bld.setTitle(R.string.renderers);
if (loaded != null) { final OsmandApplication app = activity.getMyApplication();
OsmandMapTileView view = activity.getMapView(); Collection<String> rendererNames = app.getRendererRegistry().getRendererNames();
view.getSettings().RENDERER.set(renderer); final String[] items = rendererNames.toArray(new String[rendererNames.size()]);
app.getRendererRegistry().setCurrentSelectedRender(loaded); final String[] visibleNames = new String[items.length];
refreshMapComplete(activity); int selected = -1;
} else { final String selectedName = app.getRendererRegistry().getCurrentSelectedRenderer().getName();
AccessibleToast.makeText(app, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show(); for (int j = 0; j < items.length; j++) {
if (items[j].equals(selectedName)) {
selected = j;
}
visibleNames[j] = items[j].replace('_', ' ').replace('-', ' ');
} }
adapter.setItemDescription(pos, getRenderDescr(activity)); bld.setSingleChoiceItems(visibleNames, selected, new DialogInterface.OnClickListener() {
activity.getDashboard().refreshContent(true);
dialog.dismiss();
}
});
bld.show();
return false;
}
}).description(descr).layout(R.layout.drawer_list_doubleitem).reg();
adapter.item(R.string.map_widget_day_night).description(getDayNightDescr(activity)).listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
final OsmandMapTileView view = activity.getMapView();
AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
bld.setTitle(R.string.daynight);
final String[] items = new String[OsmandSettings.DayNightMode.values().length];
for (int i = 0; i < items.length; i++) {
items[i] = OsmandSettings.DayNightMode.values()[i].toHumanString(activity.getMyApplication());
}
int i = view.getSettings().DAYNIGHT_MODE.get().ordinal();
bld.setSingleChoiceItems(items, i, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
view.getSettings().DAYNIGHT_MODE.set(OsmandSettings.DayNightMode.values()[which]);
refreshMapComplete(activity);
dialog.dismiss();
activity.getDashboard().refreshContent(true);
//adapter.setItemDescription(pos, getDayNightDescr(activity));
//ad.notifyDataSetInvalidated();
}
});
bld.show();
return false;
}
}).layout(R.layout.drawer_list_doubleitem).reg();
adapter.item(R.string.map_magnifier).listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
final OsmandMapTileView view = activity.getMapView();
final OsmandSettings.OsmandPreference<Float> mapDensity = view.getSettings().MAP_DENSITY;
final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
int p = (int) (mapDensity.get() * 100);
final TIntArrayList tlist = new TIntArrayList(new int[] { 33, 50, 75, 100, 150, 200, 300, 400 });
final List<String> values = new ArrayList<String>();
int i = -1;
for (int k = 0; k <= tlist.size(); k++) {
final boolean end = k == tlist.size();
if (i == -1) {
if ((end || p < tlist.get(k))) {
values.add(p + " %");
i = k;
} else if (p == tlist.get(k)) {
i = k;
}
}
if (k < tlist.size()) {
values.add(tlist.get(k) + " %");
}
}
if (values.size() != tlist.size()) {
tlist.insert(i, p);
}
bld.setTitle(R.string.map_magnifier);
bld.setSingleChoiceItems(values.toArray(new String[values.size()]), i,
new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
int p = tlist.get(which); String renderer = items[which];
mapDensity.set(p / 100.0f); RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer);
view.setComplexZoom(view.getZoom(), view.getSettingsMapDensity()); if (loaded != null) {
MapRendererContext mapContext = NativeCoreContext.getMapRendererContext(); OsmandMapTileView view = activity.getMapView();
if (mapContext != null) { view.getSettings().RENDERER.set(renderer);
mapContext.updateMapSettings(); app.getRendererRegistry().setCurrentSelectedRender(loaded);
refreshMapComplete(activity);
} else {
AccessibleToast.makeText(app, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
} }
adapter.setItemDescription(pos, String.format("%.0f", 100f * activity.getMyApplication().getSettings().MAP_DENSITY.get()) + " %"); adapter.setItemDescription(pos, getRenderDescr(activity));
activity.getDashboard().refreshContent(true);
dialog.dismiss();
}
});
bld.show();
return false;
}
}).setDescription(descr).setLayout(R.layout.drawer_list_doubleitem).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.map_widget_day_night, activity)
.setDescription(getDayNightDescr(activity))
.setListener(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
final OsmandMapTileView view = activity.getMapView();
AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
bld.setTitle(R.string.daynight);
final String[] items = new String[OsmandSettings.DayNightMode.values().length];
for (int i = 0; i < items.length; i++) {
items[i] = OsmandSettings.DayNightMode.values()[i].toHumanString(activity.getMyApplication());
}
int i = view.getSettings().DAYNIGHT_MODE.get().ordinal();
bld.setSingleChoiceItems(items, i, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
view.getSettings().DAYNIGHT_MODE.set(OsmandSettings.DayNightMode.values()[which]);
refreshMapComplete(activity);
dialog.dismiss();
activity.getDashboard().refreshContent(true);
//adapter.setItemDescription(pos, getDayNightDescr(activity));
//ad.notifyDataSetInvalidated();
}
});
bld.show();
return false;
}
}).setLayout(R.layout.drawer_list_doubleitem).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.map_magnifier, activity).setListener(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
final OsmandMapTileView view = activity.getMapView();
final OsmandSettings.OsmandPreference<Float> mapDensity = view.getSettings().MAP_DENSITY;
final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
int p = (int) (mapDensity.get() * 100);
final TIntArrayList tlist = new TIntArrayList(new int[]{33, 50, 75, 100, 150, 200, 300, 400});
final List<String> values = new ArrayList<String>();
int i = -1;
for (int k = 0; k <= tlist.size(); k++) {
final boolean end = k == tlist.size();
if (i == -1) {
if ((end || p < tlist.get(k))) {
values.add(p + " %");
i = k;
} else if (p == tlist.get(k)) {
i = k;
}
}
if (k < tlist.size()) {
values.add(tlist.get(k) + " %");
}
}
if (values.size() != tlist.size()) {
tlist.insert(i, p);
}
bld.setTitle(R.string.map_magnifier);
bld.setSingleChoiceItems(values.toArray(new String[values.size()]), i,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int p = tlist.get(which);
mapDensity.set(p / 100.0f);
view.setComplexZoom(view.getZoom(), view.getSettingsMapDensity());
MapRendererContext mapContext = NativeCoreContext.getMapRendererContext();
if (mapContext != null) {
mapContext.updateMapSettings();
}
adapter.setItemDescription(pos, String.format("%.0f", 100f * activity.getMyApplication().getSettings().MAP_DENSITY.get()) + " %");
ad.notifyDataSetInvalidated();
dialog.dismiss();
}
});
bld.show();
return false;
}
}).setDescription(String.format("%.0f", 100f * activity.getMyApplication().getSettings().MAP_DENSITY.get()) + " %")
.setLayout(R.layout.drawer_list_doubleitem)
.createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.text_size, activity).setListener(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
final OsmandMapTileView view = activity.getMapView();
AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
// test old descr as title
b.setTitle(R.string.text_size);
final Float[] txtValues = new Float[]{0.75f, 1f, 1.25f, 1.5f, 2f, 3f};
int selected = -1;
final String[] txtNames = new String[txtValues.length];
for (int i = 0; i < txtNames.length; i++) {
txtNames[i] = (int) (txtValues[i] * 100) + " %";
if (Math.abs(view.getSettings().TEXT_SCALE.get() - txtValues[i]) < 0.1f) {
selected = i;
}
}
b.setSingleChoiceItems(txtNames, selected, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
view.getSettings().TEXT_SCALE.set(txtValues[which]);
refreshMapComplete(activity);
adapter.setItemDescription(pos, getScale(activity));
ad.notifyDataSetInvalidated(); ad.notifyDataSetInvalidated();
dialog.dismiss(); dialog.dismiss();
} }
}); });
bld.show(); b.show();
return false; return false;
} }
}).description(String.format("%.0f", 100f * activity.getMyApplication().getSettings().MAP_DENSITY.get()) + " %").layout(R.layout.drawer_list_doubleitem).reg(); }).setDescription(getScale(activity)).setLayout(R.layout.drawer_list_doubleitem).createItem());
adapter.item(R.string.text_size).listen(new OnContextMenuClick() { adapter.addItem(new ContextMenuItem.ItemBuilder()
@Override .setTitleId(R.string.map_locale, activity).setListener(new OnContextMenuClick() {
public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
final OsmandMapTileView view = activity.getMapView();
AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
// test old descr as title
b.setTitle(R.string.text_size);
final Float[] txtValues = new Float[]{0.75f, 1f, 1.25f, 1.5f, 2f, 3f};
int selected = -1;
final String[] txtNames = new String[txtValues.length];
for (int i = 0; i < txtNames.length; i++) {
txtNames[i] = (int) (txtValues[i] * 100) + " %";
if (Math.abs(view.getSettings().TEXT_SCALE.get() - txtValues[i]) < 0.1f) {
selected = i;
}
}
b.setSingleChoiceItems(txtNames, selected, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
view.getSettings().TEXT_SCALE.set(txtValues[which]); final OsmandMapTileView view = activity.getMapView();
refreshMapComplete(activity); AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
adapter.setItemDescription(pos, getScale(activity)); // test old descr as title
ad.notifyDataSetInvalidated(); b.setTitle(R.string.map_preferred_locale);
dialog.dismiss(); final String[] txtIds = getSortedMapNamesIds(activity);
final String[] txtValues = getMapNamesValues(activity, txtIds);
int selected = -1;
for (int i = 0; i < txtIds.length; i++) {
if (view.getSettings().MAP_PREFERRED_LOCALE.get().equals(txtIds[i])) {
selected = i;
break;
}
}
b.setSingleChoiceItems(txtValues, selected, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
view.getSettings().MAP_PREFERRED_LOCALE.set(txtIds[which]);
refreshMapComplete(activity);
adapter.setItemDescription(pos, txtIds[which]);
ad.notifyDataSetInvalidated();
dialog.dismiss();
}
});
b.show();
return false;
} }
}); })
b.show(); .setDescription(activity.getMyApplication().getSettings().MAP_PREFERRED_LOCALE.get())
return false; .setLayout(R.layout.drawer_list_doubleitem).createItem());
}
}).description(getScale(activity)).layout(R.layout.drawer_list_doubleitem).reg();
adapter.item(R.string.map_locale).listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
final OsmandMapTileView view = activity.getMapView();
AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
// test old descr as title
b.setTitle(R.string.map_preferred_locale);
final String[] txtIds = getSortedMapNamesIds(activity);
final String[] txtValues = getMapNamesValues(activity, txtIds);
int selected = -1;
for (int i = 0; i < txtIds.length; i++) {
if(view.getSettings().MAP_PREFERRED_LOCALE.get().equals(txtIds[i])) {
selected = i;
break;
}
}
b.setSingleChoiceItems(txtValues, selected, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
view.getSettings().MAP_PREFERRED_LOCALE.set(txtIds[which]);
refreshMapComplete(activity);
adapter.setItemDescription(pos, txtIds[which]);
ad.notifyDataSetInvalidated();
dialog.dismiss();
}
});
b.show();
return false;
}
}).description(activity.getMyApplication().getSettings().MAP_PREFERRED_LOCALE.get()).layout(R.layout.drawer_list_doubleitem).reg();
RenderingRulesStorage renderer = activity.getMyApplication().getRendererRegistry().getCurrentSelectedRenderer(); RenderingRulesStorage renderer = activity.getMyApplication().getRendererRegistry().getCurrentSelectedRenderer();
if (renderer != null) { if (renderer != null) {
List<RenderingRuleProperty> customRules = new ArrayList<RenderingRuleProperty>(); List<RenderingRuleProperty> customRules = new ArrayList<RenderingRuleProperty>();
for(RenderingRuleProperty p : renderer.PROPS.getCustomRules()) { for (RenderingRuleProperty p : renderer.PROPS.getCustomRules()) {
if(!RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(p.getCategory())){ if (!RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(p.getCategory())) {
customRules.add(p); customRules.add(p);
} }
} }
createProperties(customRules, R.string.rendering_category_transport, "transport", createProperties(customRules, R.string.rendering_category_transport, "transport",
adapter, activity); adapter, activity);
createProperties(customRules, R.string.rendering_category_details, "details", createProperties(customRules, R.string.rendering_category_details, "details",
@ -407,30 +444,32 @@ public class ConfigureMapMenu {
adapter, activity); adapter, activity);
createProperties(customRules, R.string.rendering_category_routes, "routes", createProperties(customRules, R.string.rendering_category_routes, "routes",
adapter, activity); adapter, activity);
if(customRules.size() > 0) { if (customRules.size() > 0) {
adapter.item(R.string.rendering_category_others).setCategory(true).layout(R.layout.drawer_list_sub_header).reg(); adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.rendering_category_others, activity).setCategory(true)
.setLayout(R.layout.drawer_list_sub_header).createItem());
createCustomRenderingProperties(adapter, activity, customRules); createCustomRenderingProperties(adapter, activity, customRules);
} }
} }
} }
public static String[] mapNamesIds = new String[] { "", "en", "als", "af", "ar", "az", "be", "bg", "bn", "bpy", "br", "bs", "ca", "ceb", "cs", "cy", "da", "de", "el", "et", "es", "eu", "fa", "fi", "fr", "fy", "ga", "gl", "he", "hi", "hr", "ht", "hu", "hy", "id", "is", "it", "ja", "ka", "ko", "ku", "la", "lb", "lt", "lv", "mk", "ml", "mr", "ms", "nds", "new", "nl", "nn", "no", "nv", "os", "pl", "pms", "pt", "ro", "ru", "sh", "sc", "sk", "sl", "sq", "sr", "sv", "sw", "ta", "te", "th", "tl", "tr", "uk", "vi", "vo", "zh" };
public static String[] mapNamesIds = new String[]{"", "en", "als", "af", "ar", "az", "be", "bg", "bn", "bpy", "br", "bs", "ca", "ceb", "cs", "cy", "da", "de", "el", "et", "es", "eu", "fa", "fi", "fr", "fy", "ga", "gl", "he", "hi", "hr", "ht", "hu", "hy", "id", "is", "it", "ja", "ka", "ko", "ku", "la", "lb", "lt", "lv", "mk", "ml", "mr", "ms", "nds", "new", "nl", "nn", "no", "nv", "os", "pl", "pms", "pt", "ro", "ru", "sh", "sc", "sk", "sl", "sq", "sr", "sv", "sw", "ta", "te", "th", "tl", "tr", "uk", "vi", "vo", "zh"};
public static String[] getSortedMapNamesIds(Context ctx) { public static String[] getSortedMapNamesIds(Context ctx) {
String[] vls = getMapNamesValues(ctx, mapNamesIds); String[] vls = getMapNamesValues(ctx, mapNamesIds);
final Map<String, String> mp = new HashMap<String, String>(); final Map<String, String> mp = new HashMap<String, String>();
for(int i = 0; i < mapNamesIds.length; i++) { for (int i = 0; i < mapNamesIds.length; i++) {
mp.put(mapNamesIds[i], vls[i]); mp.put(mapNamesIds[i], vls[i]);
} }
ArrayList<String> lst = new ArrayList<String>(mp.keySet()); ArrayList<String> lst = new ArrayList<String>(mp.keySet());
Collections.sort(lst, new Comparator<String>() { Collections.sort(lst, new Comparator<String>() {
@Override @Override
public int compare(String lhs, String rhs) { public int compare(String lhs, String rhs) {
int i1 = Algorithms.isEmpty(lhs)? 0 : (lhs.equals("en") ? 1 : 2); int i1 = Algorithms.isEmpty(lhs) ? 0 : (lhs.equals("en") ? 1 : 2);
int i2 = Algorithms.isEmpty(rhs)? 0 : (rhs.equals("en") ? 1 : 2); int i2 = Algorithms.isEmpty(rhs) ? 0 : (rhs.equals("en") ? 1 : 2);
if(i1 != i2) { if (i1 != i2) {
return i1 < i2 ? -1 : 1; return i1 < i2 ? -1 : 1;
} }
return mp.get(lhs).compareTo(mp.get(rhs)); return mp.get(lhs).compareTo(mp.get(rhs));
@ -438,26 +477,26 @@ public class ConfigureMapMenu {
}); });
return lst.toArray(new String[lst.size()]); return lst.toArray(new String[lst.size()]);
} }
public static String[] getMapNamesValues(Context ctx, String[] ids) { public static String[] getMapNamesValues(Context ctx, String[] ids) {
String[] translates = new String[ids.length]; String[] translates = new String[ids.length];
for(int i = 0; i < translates.length; i++) { for (int i = 0; i < translates.length; i++) {
if(Algorithms.isEmpty(ids[i])) { if (Algorithms.isEmpty(ids[i])) {
translates[i] = ctx.getString(R.string.local_map_names); translates[i] = ctx.getString(R.string.local_map_names);
} else { } else {
translates[i] = ((OsmandApplication)ctx.getApplicationContext()).getLangTranslation(ids[i]); translates[i] = ((OsmandApplication) ctx.getApplicationContext()).getLangTranslation(ids[i]);
} }
} }
return translates; return translates;
} }
private void createProperties(List<RenderingRuleProperty> customRules, final int strId, String cat, private void createProperties(List<RenderingRuleProperty> customRules, final int strId, String cat,
final ContextMenuAdapter adapter, final MapActivity activity) { final ContextMenuAdapter adapter, final MapActivity activity) {
final List<RenderingRuleProperty> ps = new ArrayList<RenderingRuleProperty>(); final List<RenderingRuleProperty> ps = new ArrayList<RenderingRuleProperty>();
final List<OsmandSettings.CommonPreference<Boolean>> prefs = new ArrayList<OsmandSettings.CommonPreference<Boolean>>(); final List<OsmandSettings.CommonPreference<Boolean>> prefs = new ArrayList<OsmandSettings.CommonPreference<Boolean>>();
Iterator<RenderingRuleProperty> it = customRules.iterator(); Iterator<RenderingRuleProperty> it = customRules.iterator();
while (it.hasNext()) { while (it.hasNext()) {
RenderingRuleProperty p = it.next(); RenderingRuleProperty p = it.next();
if (cat.equals(p.getCategory()) && p.isBoolean()) { if (cat.equals(p.getCategory()) && p.isBoolean()) {
@ -468,17 +507,20 @@ public class ConfigureMapMenu {
it.remove(); it.remove();
} }
} }
if(prefs.size() > 0) { if (prefs.size() > 0) {
final String descr = getDescription(prefs); final String descr = getDescription(prefs);
adapter.item(strId).description(descr). adapter.addItem(new ContextMenuItem.ItemBuilder()
layout(R.layout.drawer_list_doubleitem).listen(new OnContextMenuClick() { .setTitleId(strId, activity)
.setDescription(descr)
.setLayout(R.layout.drawer_list_doubleitem)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> a, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> a, int itemId, int pos, boolean isChecked) {
showPreferencesDialog(adapter, a, pos, activity, activity.getString(strId), ps, prefs); showPreferencesDialog(adapter, a, pos, activity, activity.getString(strId), ps, prefs);
return false; return false;
} }
}).reg(); }).createItem());
// createCustomRenderingProperties(adapter, activity, ps); // createCustomRenderingProperties(adapter, activity, ps);
} }
} }
@ -496,26 +538,26 @@ public class ConfigureMapMenu {
return descr; return descr;
} }
protected void showPreferencesDialog(final ContextMenuAdapter adapter, final ArrayAdapter<?> a, final int pos, final MapActivity activity, protected void showPreferencesDialog(final ContextMenuAdapter adapter, final ArrayAdapter<?> a, final int pos, final MapActivity activity,
String category, List<RenderingRuleProperty> ps, final List<CommonPreference<Boolean>> prefs) { String category, List<RenderingRuleProperty> ps, final List<CommonPreference<Boolean>> prefs) {
AlertDialog.Builder bld = new AlertDialog.Builder(activity); AlertDialog.Builder bld = new AlertDialog.Builder(activity);
boolean[] checkedItems = new boolean[prefs.size()]; boolean[] checkedItems = new boolean[prefs.size()];
for (int i = 0; i < prefs.size(); i++) { for (int i = 0; i < prefs.size(); i++) {
checkedItems[i] = prefs.get(i).get(); checkedItems[i] = prefs.get(i).get();
} }
final boolean[] tempPrefs = new boolean[prefs.size()]; final boolean[] tempPrefs = new boolean[prefs.size()];
for (int i = 0; i < prefs.size(); i++) { for (int i = 0; i < prefs.size(); i++) {
tempPrefs[i] = prefs.get(i).get(); tempPrefs[i] = prefs.get(i).get();
} }
final String[] vals = new String[ps.size()]; final String[] vals = new String[ps.size()];
for(int i = 0; i < ps.size(); i++) { for (int i = 0; i < ps.size(); i++) {
RenderingRuleProperty p = ps.get(i); RenderingRuleProperty p = ps.get(i);
String propertyName = SettingsActivity.getStringPropertyName(activity, p.getAttrName(), String propertyName = SettingsActivity.getStringPropertyName(activity, p.getAttrName(),
p.getName()); p.getName());
vals[i] = propertyName; vals[i] = propertyName;
} }
bld.setMultiChoiceItems(vals, checkedItems, new OnMultiChoiceClickListener() { bld.setMultiChoiceItems(vals, checkedItems, new OnMultiChoiceClickListener() {
@Override @Override
@ -523,13 +565,13 @@ public class ConfigureMapMenu {
tempPrefs[which] = isChecked; tempPrefs[which] = isChecked;
} }
}); });
bld.setTitle(category); bld.setTitle(category);
bld.setNegativeButton(R.string.shared_string_cancel, null); bld.setNegativeButton(R.string.shared_string_cancel, null);
bld.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { bld.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) { public void onClick(DialogInterface dialog, int whichButton) {
for (int i = 0; i < prefs.size(); i++) { for (int i = 0; i < prefs.size(); i++) {
prefs.get(i).set(tempPrefs[i]); prefs.get(i).set(tempPrefs[i]);
} }
@ -537,9 +579,9 @@ public class ConfigureMapMenu {
a.notifyDataSetInvalidated(); a.notifyDataSetInvalidated();
refreshMapComplete(activity); refreshMapComplete(activity);
activity.getMapLayers().updateLayers(activity.getMapView()); activity.getMapLayers().updateLayers(activity.getMapView());
} }
}); });
bld.show(); bld.show();
} }
@ -557,17 +599,17 @@ public class ConfigureMapMenu {
} }
protected String getScale(final MapActivity activity) { protected String getScale(final MapActivity activity) {
int scale = (int)(activity.getMyApplication().getSettings().TEXT_SCALE.get() * 100); int scale = (int) (activity.getMyApplication().getSettings().TEXT_SCALE.get() * 100);
return scale + " %"; return scale + " %";
} }
private void createCustomRenderingProperties(final ContextMenuAdapter adapter , final MapActivity activity, private void createCustomRenderingProperties(final ContextMenuAdapter adapter, final MapActivity activity,
List<RenderingRuleProperty> customRules ){ List<RenderingRuleProperty> customRules) {
final OsmandMapTileView view = activity.getMapView(); final OsmandMapTileView view = activity.getMapView();
for (final RenderingRuleProperty p : customRules) { for (final RenderingRuleProperty p : customRules) {
if (p.getAttrName().equals(RenderingRuleStorageProperties.A_APP_MODE) || if (p.getAttrName().equals(RenderingRuleStorageProperties.A_APP_MODE) ||
p.getAttrName().equals(RenderingRuleStorageProperties.A_ENGINE_V1)){ p.getAttrName().equals(RenderingRuleStorageProperties.A_ENGINE_V1)) {
continue; continue;
} }
String propertyName = SettingsActivity.getStringPropertyName(view.getContext(), p.getAttrName(), String propertyName = SettingsActivity.getStringPropertyName(view.getContext(), p.getAttrName(),
@ -578,26 +620,29 @@ public class ConfigureMapMenu {
if (p.isBoolean()) { if (p.isBoolean()) {
final OsmandSettings.CommonPreference<Boolean> pref = view.getApplication().getSettings() final OsmandSettings.CommonPreference<Boolean> pref = view.getApplication().getSettings()
.getCustomRenderBooleanProperty(p.getAttrName()); .getCustomRenderBooleanProperty(p.getAttrName());
adapter.item(propertyName).listen(new OnContextMenuClick() { adapter.addItem(ContextMenuItem.createBuilder(propertyName)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
pref.set(!pref.get()); pref.set(!pref.get());
refreshMapComplete(activity); refreshMapComplete(activity);
return false; return false;
} }
}).selected(pref.get() ? 1 : 0).reg(); })
.setSelected(pref.get())
.createItem());
} else { } else {
final OsmandSettings.CommonPreference<String> pref = view.getApplication().getSettings() final OsmandSettings.CommonPreference<String> pref = view.getApplication().getSettings()
.getCustomRenderProperty(p.getAttrName()); .getCustomRenderProperty(p.getAttrName());
String descr; String descr;
if(!Algorithms.isEmpty(pref.get())) { if (!Algorithms.isEmpty(pref.get())) {
descr = SettingsActivity.getStringPropertyValue(activity, pref.get()); descr = SettingsActivity.getStringPropertyValue(activity, pref.get());
} else { } else {
descr = SettingsActivity.getStringPropertyValue(view.getContext(), descr = SettingsActivity.getStringPropertyValue(view.getContext(),
p.getDefaultValueDescription()); p.getDefaultValueDescription());
} }
adapter.item(propertyName).listen(new OnContextMenuClick() { adapter.addItem(ContextMenuItem.createBuilder(propertyName).setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) { public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
@ -614,7 +659,7 @@ public class ConfigureMapMenu {
String[] possibleValuesString = new String[p.getPossibleValues().length + 1]; String[] possibleValuesString = new String[p.getPossibleValues().length + 1];
possibleValuesString[0] = SettingsActivity.getStringPropertyValue(view.getContext(), possibleValuesString[0] = SettingsActivity.getStringPropertyValue(view.getContext(),
p.getDefaultValueDescription()); p.getDefaultValueDescription());
for (int j = 0; j < p.getPossibleValues().length; j++) { for (int j = 0; j < p.getPossibleValues().length; j++) {
possibleValuesString[j + 1] = SettingsActivity.getStringPropertyValue(view.getContext(), possibleValuesString[j + 1] = SettingsActivity.getStringPropertyValue(view.getContext(),
@ -624,7 +669,7 @@ public class ConfigureMapMenu {
b.setSingleChoiceItems(possibleValuesString, i, new DialogInterface.OnClickListener() { b.setSingleChoiceItems(possibleValuesString, i, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if(which == 0) { if (which == 0) {
pref.set(""); pref.set("");
} else { } else {
pref.set(p.getPossibleValues()[which - 1]); pref.set(p.getPossibleValues()[which - 1]);
@ -638,7 +683,7 @@ public class ConfigureMapMenu {
b.show(); b.show();
return false; return false;
} }
}).description(descr).layout(R.layout.drawer_list_doubleitem).reg(); }).setDescription(descr).setLayout(R.layout.drawer_list_doubleitem).createItem());
} }
} }
} }

View file

@ -5,6 +5,7 @@ import android.view.View;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -111,12 +112,17 @@ public class RasterMapMenu {
return false; return false;
} }
}; };
int selectedCode = selected ? 1 : 0;
mapTypeDescr = selected ? mapTypeDescr : mapActivity.getString(R.string.shared_string_none); mapTypeDescr = selected ? mapTypeDescr : mapActivity.getString(R.string.shared_string_none);
contextMenuAdapter.item(toggleActionStringId).listen(l).selected(selectedCode).reg(); contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(toggleActionStringId, mapActivity)
.setListener(l)
.setSelected(selected).createItem());
if (selected) { if (selected) {
contextMenuAdapter.item(mapTypeString).listen(l).layout(R.layout.two_line_list_item) contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.description(mapTypeDescr).reg(); .setTitleId(mapTypeString, mapActivity)
.setListener(l)
.setLayout(R.layout.two_line_list_item)
.setDescription(mapTypeDescr).createItem());
ContextMenuAdapter.OnIntegerValueChangedListener integerListener = ContextMenuAdapter.OnIntegerValueChangedListener integerListener =
new ContextMenuAdapter.OnIntegerValueChangedListener() { new ContextMenuAdapter.OnIntegerValueChangedListener() {
@Override @Override
@ -127,20 +133,25 @@ public class RasterMapMenu {
} }
}; };
// android:max="255" in layout is expected // android:max="255" in layout is expected
contextMenuAdapter.item(mapTypeStringTransparency) contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.layout(R.layout.progress_list_item) .setTitleId(mapTypeStringTransparency, mapActivity)
.colorIcon(R.drawable.ic_action_opacity) .setLayout(R.layout.progress_list_item)
.progress(mapTransparencyPreference.get()) .setColorIcon(R.drawable.ic_action_opacity)
.listen(l) .setProgress(mapTransparencyPreference.get())
.listenInteger(integerListener).reg(); .setListener(l)
.setIntegerListener(integerListener).createItem());
if (type == OsmandRasterMapsPlugin.RasterMapType.UNDERLAY) { if (type == OsmandRasterMapsPlugin.RasterMapType.UNDERLAY) {
contextMenuAdapter.item(R.string.show_polygons).listen(l) contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.selected(hidePolygonsPref.get() ? 0 : 1).reg(); .setTitleId(R.string.show_polygons, mapActivity)
.setListener(l)
.setSelected(hidePolygonsPref.get()).createItem());
} }
Boolean transparencySwitchState = settings.SHOW_LAYER_TRANSPARENCY_SEEKBAR.get() Boolean transparencySwitchState = settings.SHOW_LAYER_TRANSPARENCY_SEEKBAR.get()
&& mapLayers.getMapControlsLayer().isTransparencyBarInitialized(); && mapLayers.getMapControlsLayer().isTransparencyBarInitialized();
contextMenuAdapter.item(R.string.show_transparency_seekbar).listen(l) contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.selected(transparencySwitchState ? 1 : 0).reg(); .setTitleId(R.string.show_transparency_seekbar, mapActivity)
.setListener(l)
.setSelected(transparencySwitchState).createItem());
} }
} }

View file

@ -34,6 +34,7 @@ import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.Route; import net.osmand.plus.GPXUtilities.Route;
@ -640,7 +641,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
} }
@Override @Override
public void populateObjectContextMenu(LatLon latLon, Object o, ContextMenuAdapter adapter) { public void populateObjectContextMenu(LatLon latLon, Object o, ContextMenuAdapter adapter, MapActivity mapActivity) {
if (o != null && o instanceof WptPt) { if (o != null && o instanceof WptPt) {
final WptPt p = (WptPt) o; final WptPt p = (WptPt) o;
boolean containsPoint = false; boolean containsPoint = false;
@ -675,7 +676,10 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
return true; return true;
} }
}; };
adapter.item(R.string.delete_point).colorIcon(R.drawable.ic_action_delete_dark).listen(listener).reg(); adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.delete_point, mapActivity)
.setColorIcon(R.drawable.ic_action_delete_dark)
.setListener(listener).createItem());
} }
} }
} }

View file

@ -40,6 +40,7 @@ import net.osmand.IndexConstants;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
@ -200,16 +201,28 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
if (info.getType() == LocalIndexType.MAP_DATA || info.getType() == LocalIndexType.SRTM_DATA || if (info.getType() == LocalIndexType.MAP_DATA || info.getType() == LocalIndexType.SRTM_DATA ||
info.getType() == LocalIndexType.WIKI_DATA) { info.getType() == LocalIndexType.WIKI_DATA) {
if (!info.isBackupedData()) { if (!info.isBackupedData()) {
adapter.item(R.string.local_index_mi_backup).listen(listener).position(1).reg(); adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.local_index_mi_backup, getContext())
.setListener(listener)
.setPosition(1).createItem());
} }
} }
if (info.isBackupedData()) { if (info.isBackupedData()) {
adapter.item(R.string.local_index_mi_restore).listen(listener).position(2).reg(); adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.local_index_mi_restore, getContext())
.setListener(listener)
.setPosition(2).createItem());
} }
if (info.getType() != LocalIndexType.TTS_VOICE_DATA && info.getType() != LocalIndexType.VOICE_DATA) { if (info.getType() != LocalIndexType.TTS_VOICE_DATA && info.getType() != LocalIndexType.VOICE_DATA) {
adapter.item(R.string.shared_string_rename).listen(listener).position(3).reg(); adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.shared_string_rename, getContext())
.setListener(listener)
.setPosition(3).createItem());
} }
adapter.item(R.string.shared_string_delete).listen(listener).position(4).reg(); adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.shared_string_delete, getContext())
.setListener(listener)
.setPosition(4).createItem());
} }
private boolean performBasicOperation(int resId, final LocalIndexInfo info) { private boolean performBasicOperation(int resId, final LocalIndexInfo info) {
@ -588,16 +601,24 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
return true; return true;
} }
}; };
optionsMenuAdapter.item(R.string.local_index_mi_reload) optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.icon(R.drawable.ic_action_refresh_dark) .setTitleId(R.string.local_index_mi_reload,getContext())
.listen(listener).position(1).reg(); .setIcon(R.drawable.ic_action_refresh_dark)
optionsMenuAdapter.item(R.string.shared_string_delete) .setListener(listener)
.icon(R.drawable.ic_action_delete_dark) .createItem());
.listen(listener).position(2).reg(); optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
optionsMenuAdapter.item(R.string.local_index_mi_backup) .setTitleId(R.string.shared_string_delete,getContext())
.listen(listener).position(3).reg(); .setIcon(R.drawable.ic_action_delete_dark)
optionsMenuAdapter.item(R.string.local_index_mi_restore) .setListener(listener)
.listen(listener).position(4).reg(); .createItem());
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.local_index_mi_backup,getContext())
.setListener(listener)
.createItem());
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.local_index_mi_restore,getContext())
.setListener(listener)
.createItem());
// doesn't work correctly // doesn't work correctly
//int max = getResources().getInteger(R.integer.abs__max_action_buttons); //int max = getResources().getInteger(R.integer.abs__max_action_buttons);
int max = 3; int max = 3;

View file

@ -23,6 +23,7 @@ import net.osmand.CallbackWithObject;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.GPXTrackAnalysis; import net.osmand.plus.GPXUtilities.GPXTrackAnalysis;
@ -207,8 +208,8 @@ public class GpxUiHelper {
} }
s = s.replace('_', ' '); s = s.replace('_', ' ');
adapter.item(s).selected(multipleChoice ? 0 : -1) adapter.addItem(ContextMenuItem.createBuilder(s).setSelected(multipleChoice)
.colorIcon(R.drawable.ic_action_polygom_dark).reg(); .setColorIcon(R.drawable.ic_action_polygom_dark).createItem());
//if there's some selected files - need to mark them as selected //if there's some selected files - need to mark them as selected
if (selectedGpxList != null) { if (selectedGpxList != null) {
@ -223,12 +224,12 @@ public class GpxUiHelper {
final ContextMenuAdapter adapter, int i, String fileName) { final ContextMenuAdapter adapter, int i, String fileName) {
if (i == 0 && showCurrentTrack) { if (i == 0 && showCurrentTrack) {
if (selectedGpxList.contains("")) { if (selectedGpxList.contains("")) {
adapter.setSelection(i, 1); adapter.setSelection(i, true);
} }
} else { } else {
for (String file : selectedGpxList) { for (String file : selectedGpxList) {
if (file.endsWith(fileName)) { if (file.endsWith(fileName)) {
adapter.setSelection(i, 1); adapter.setSelection(i, true);
break; break;
} }
} }
@ -303,15 +304,15 @@ public class GpxUiHelper {
// } // }
// tv.setCompoundDrawablePadding(padding); // tv.setCompoundDrawablePadding(padding);
final CheckBox ch = ((CheckBox) v.findViewById(R.id.toggle_item)); final CheckBox ch = ((CheckBox) v.findViewById(R.id.toggle_item));
if (adapter.getSelection(position) == -1) { if (adapter.getSelection(position) == null) {
ch.setVisibility(View.INVISIBLE); ch.setVisibility(View.INVISIBLE);
} else { } else {
ch.setOnCheckedChangeListener(null); ch.setOnCheckedChangeListener(null);
ch.setChecked(adapter.getSelection(position) > 0); ch.setChecked(adapter.getSelection(position));
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() { ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
adapter.setSelection(position, isChecked ? 1 : 0); adapter.setSelection(position, isChecked);
} }
}); });
} }
@ -337,12 +338,12 @@ public class GpxUiHelper {
if (app != null && app.getSelectedGpxHelper() != null) { if (app != null && app.getSelectedGpxHelper() != null) {
app.getSelectedGpxHelper().clearAllGpxFileToShow(); app.getSelectedGpxHelper().clearAllGpxFileToShow();
} }
if (showCurrentGpx && adapter.getSelection(0) > 0) { if (showCurrentGpx && adapter.getSelection(0)) {
currentGPX = app.getSavingTrackHelper().getCurrentGpx(); currentGPX = app.getSavingTrackHelper().getCurrentGpx();
} }
List<String> s = new ArrayList<>(); List<String> s = new ArrayList<>();
for (int i = (showCurrentGpx ? 1 : 0); i < adapter.length(); i++) { for (int i = (showCurrentGpx ? 1 : 0); i < adapter.length(); i++) {
if (adapter.getSelection(i) > 0) { if (adapter.getSelection(i)) {
s.add(list.get(i)); s.add(list.get(i));
} }
} }
@ -360,7 +361,7 @@ public class GpxUiHelper {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (multipleChoice) { if (multipleChoice) {
adapter.setSelection(position, adapter.getSelection(position) > 0 ? 0 : 1); adapter.setSelection(position, !adapter.getSelection(position));
listAdapter.notifyDataSetInvalidated(); listAdapter.notifyDataSetInvalidated();
} else { } else {
dlg.dismiss(); dlg.dismiss();

View file

@ -555,7 +555,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
public void buttonMorePressed() { public void buttonMorePressed() {
final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(mapActivity); final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(mapActivity);
for (OsmandMapLayer layer : mapActivity.getMapView().getLayers()) { for (OsmandMapLayer layer : mapActivity.getMapView().getLayers()) {
layer.populateObjectContextMenu(latLon, object, menuAdapter); layer.populateObjectContextMenu(latLon, object, menuAdapter, mapActivity);
} }
mapActivity.getMapActions().contextMenuPoint(latLon.getLatitude(), latLon.getLongitude(), menuAdapter, object); mapActivity.getMapActions().contextMenuPoint(latLon.getLatitude(), latLon.getLongitude(), menuAdapter, object);

View file

@ -23,6 +23,7 @@ import net.osmand.Location;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -215,7 +216,8 @@ public class RoutePreferencesMenu {
String selectedValue = mapActivity.getMyApplication().getSettings().VOICE_PROVIDER.get(); String selectedValue = mapActivity.getMyApplication().getSettings().VOICE_PROVIDER.get();
entrieValues[k] = OsmandSettings.VOICE_PROVIDER_NOT_USE; entrieValues[k] = OsmandSettings.VOICE_PROVIDER_NOT_USE;
entries[k] = mapActivity.getResources().getString(R.string.shared_string_do_not_use); entries[k] = mapActivity.getResources().getString(R.string.shared_string_do_not_use);
adapter.item(entries[k]).reg(); ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder();
adapter.addItem(itemBuilder.setTitle(entries[k]).createItem());
if (OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(selectedValue)) { if (OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(selectedValue)) {
selected = k; selected = k;
} }
@ -224,7 +226,7 @@ public class RoutePreferencesMenu {
entries[k] = (s.contains("tts") ? mapActivity.getResources().getString(R.string.ttsvoice) + " " : "") + entries[k] = (s.contains("tts") ? mapActivity.getResources().getString(R.string.ttsvoice) + " " : "") +
FileNameTranslationHelper.getVoiceName(mapActivity, s); FileNameTranslationHelper.getVoiceName(mapActivity, s);
entrieValues[k] = s; entrieValues[k] = s;
adapter.item(entries[k]).reg(); adapter.addItem(itemBuilder.setTitle(entries[k]).createItem());
if (s.equals(selectedValue)) { if (s.equals(selectedValue)) {
selected = k; selected = k;
} }
@ -232,7 +234,7 @@ public class RoutePreferencesMenu {
} }
entrieValues[k] = MORE_VALUE; entrieValues[k] = MORE_VALUE;
entries[k] = mapActivity.getResources().getString(R.string.install_more); entries[k] = mapActivity.getResources().getString(R.string.install_more);
adapter.item(entries[k]).reg(); adapter.addItem(itemBuilder.setTitle(entries[k]).createItem());
AlertDialog.Builder bld = new AlertDialog.Builder(mapActivity); AlertDialog.Builder bld = new AlertDialog.Builder(mapActivity);
bld.setSingleChoiceItems(entries, selected, new DialogInterface.OnClickListener() { bld.setSingleChoiceItems(entries, selected, new DialogInterface.OnClickListener() {

View file

@ -23,6 +23,7 @@ import net.osmand.ValueHolder;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.NavigationService; import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
@ -140,13 +141,17 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
return true; return true;
} }
}; };
adapter.item(R.string.context_menu_item_add_waypoint).colorIcon(R.drawable.ic_action_gnew_label_dark) adapter.addItem(new ContextMenuItem.ItemBuilder()
.listen(listener).reg(); .setTitleId(R.string.context_menu_item_add_waypoint, mapActivity)
.setColorIcon(R.drawable.ic_action_gnew_label_dark)
.setListener(listener).createItem());
if (selectedObj instanceof WptPt) { if (selectedObj instanceof WptPt) {
WptPt pt = (WptPt) selectedObj; WptPt pt = (WptPt) selectedObj;
if (app.getSelectedGpxHelper().getSelectedGPXFile(pt) != null) { if (app.getSelectedGpxHelper().getSelectedGPXFile(pt) != null) {
adapter.item(R.string.context_menu_item_edit_waypoint).colorIcon(R.drawable.ic_action_edit_dark) adapter.addItem(new ContextMenuItem.ItemBuilder()
.listen(listener).reg(); .setTitleId(R.string.context_menu_item_edit_waypoint, mapActivity)
.setColorIcon(R.drawable.ic_action_edit_dark)
.setListener(listener).createItem());
} }
} }
} }

View file

@ -36,6 +36,7 @@ import net.osmand.IndexConstants;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.GPXTrackAnalysis; import net.osmand.plus.GPXUtilities.GPXTrackAnalysis;
@ -348,12 +349,13 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
return true; return true;
} }
}; };
optionsMenuAdapter.item(R.string.shared_string_show_on_map).icon(R.drawable.ic_show_on_map) optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_show_on_map, getActivity())
.listen(listener).reg(); .setIcon(R.drawable.ic_show_on_map)
optionsMenuAdapter.item(R.string.shared_string_delete) .setListener(listener).createItem());
.icon(R.drawable.ic_action_delete_dark).listen(listener).reg(); optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_delete, getActivity())
optionsMenuAdapter.item(R.string.local_index_mi_reload) .setIcon(R.drawable.ic_action_delete_dark).setListener(listener).createItem());
.icon(R.drawable.ic_action_refresh_dark).listen(listener).reg(); optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_reload, getActivity())
.setIcon(R.drawable.ic_action_refresh_dark).setListener(listener).createItem());
OsmandPlugin.onOptionsMenuActivity(getActivity(), this, optionsMenuAdapter); OsmandPlugin.onOptionsMenuActivity(getActivity(), this, optionsMenuAdapter);
for (int j = 0; j < optionsMenuAdapter.length(); j++) { for (int j = 0; j < optionsMenuAdapter.length(); j++) {
final MenuItem item; final MenuItem item;

View file

@ -21,6 +21,7 @@ import net.osmand.osm.PoiType;
import net.osmand.osm.edit.Node; import net.osmand.osm.edit.Node;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -216,15 +217,32 @@ public class OsmEditingPlugin extends OsmandPlugin {
isEditable = !amenity.getType().isWiki() && !poiType.isNotEditableOsm(); isEditable = !amenity.getType().isWiki() && !poiType.isNotEditableOsm();
} }
if (isEditable) { if (isEditable) {
adapter.item(R.string.poi_context_menu_modify).colorIcon(R.drawable.ic_action_edit_dark).listen(listener).position(1).reg(); adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.poi_context_menu_modify, mapActivity)
adapter.item(R.string.poi_context_menu_delete).colorIcon(R.drawable.ic_action_delete_dark).listen(listener).position(2).reg(); .setColorIcon(R.drawable.ic_action_edit_dark)
.setListener(listener)
.setPosition(1)
.createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.poi_context_menu_delete, mapActivity)
.setColorIcon(R.drawable.ic_action_delete_dark)
.setListener(listener)
.setPosition(2)
.createItem());
} else if (selectedObj instanceof OpenstreetmapPoint && ((OpenstreetmapPoint) selectedObj).getAction() != Action.DELETE) { } else if (selectedObj instanceof OpenstreetmapPoint && ((OpenstreetmapPoint) selectedObj).getAction() != Action.DELETE) {
adapter.item(R.string.poi_context_menu_modify_osm_change) adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.poi_context_menu_modify_osm_change, mapActivity)
.colorIcon(R.drawable.ic_action_edit_dark).listen(listener).position(1).reg(); .setColorIcon(R.drawable.ic_action_edit_dark)
.setListener(listener)
.setPosition(1)
.createItem());
} else { } else {
adapter.item(R.string.context_menu_item_create_poi).colorIcon(R.drawable.ic_action_plus_dark).listen(listener).position(-1).reg(); adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_create_poi, mapActivity)
.setColorIcon(R.drawable.ic_action_plus_dark)
.setListener(listener)
.setPosition(-1)
.createItem());
} }
adapter.item(R.string.context_menu_item_open_note).colorIcon(R.drawable.ic_action_bug_dark).listen(listener).reg(); adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_open_note, mapActivity)
.setColorIcon(R.drawable.ic_action_bug_dark)
.setListener(listener).createItem());
} }
@Override @Override
@ -239,8 +257,10 @@ public class OsmEditingPlugin extends OsmandPlugin {
@Override @Override
public void registerLayerContextMenuActions(OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) { public void registerLayerContextMenuActions(OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) {
adapter.item(R.string.layer_osm_bugs).selected(settings.SHOW_OSM_BUGS.get() ? 1 : 0) adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_osm_bugs, mapActivity)
.colorIcon(R.drawable.ic_action_bug_dark).listen(new OnContextMenuClick() { .setSelected(settings.SHOW_OSM_BUGS.get())
.setColorIcon(R.drawable.ic_action_bug_dark)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
@ -250,7 +270,9 @@ public class OsmEditingPlugin extends OsmandPlugin {
} }
return true; return true;
} }
}).position(16).reg(); })
.setPosition(16)
.createItem());
} }
@ -262,16 +284,16 @@ public class OsmEditingPlugin extends OsmandPlugin {
@Override @Override
public void contextMenuFragment(final Activity la, final Fragment fragment, final Object info, ContextMenuAdapter adapter) { public void contextMenuFragment(final Activity la, final Fragment fragment, final Object info, ContextMenuAdapter adapter) {
if (fragment instanceof AvailableGPXFragment) { if (fragment instanceof AvailableGPXFragment) {
adapter.item(R.string.local_index_mi_upload_gpx) adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_upload_gpx, la)
.colorIcon(R.drawable.ic_action_export) .setColorIcon(R.drawable.ic_action_export)
.listen(new OnContextMenuClick() { .setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
sendGPXFiles(la, (AvailableGPXFragment) fragment, (GpxInfo) info); sendGPXFiles(la, (AvailableGPXFragment) fragment, (GpxInfo) info);
return true; return true;
} }
}).reg(); }).createItem());
} }
} }
@ -279,9 +301,9 @@ public class OsmEditingPlugin extends OsmandPlugin {
public void optionsMenuFragment(final Activity activity, final Fragment fragment, ContextMenuAdapter optionsMenuAdapter) { public void optionsMenuFragment(final Activity activity, final Fragment fragment, ContextMenuAdapter optionsMenuAdapter) {
if (fragment instanceof AvailableGPXFragment) { if (fragment instanceof AvailableGPXFragment) {
final AvailableGPXFragment f = ((AvailableGPXFragment) fragment); final AvailableGPXFragment f = ((AvailableGPXFragment) fragment);
optionsMenuAdapter.item(R.string.local_index_mi_upload_gpx) optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_upload_gpx, activity)
.icon(R.drawable.ic_action_export) .setIcon(R.drawable.ic_action_export)
.listen(new OnContextMenuClick() { .setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
@ -296,7 +318,9 @@ public class OsmEditingPlugin extends OsmandPlugin {
}); });
return true; return true;
} }
}).position(5).reg(); })
.setPosition(5)
.createItem());
} }
} }

View file

@ -13,6 +13,7 @@ import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
@ -274,15 +275,18 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor {
@Override @Override
public void registerOptionsMenuItems(final MapActivity mapActivity, ContextMenuAdapter helper) { public void registerOptionsMenuItems(final MapActivity mapActivity, ContextMenuAdapter helper) {
helper.item(R.string.osmo_groups).colorIcon(R.drawable.ic_osmo_dark).position(6) helper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.osmo_groups, mapActivity)
.listen(new OnContextMenuClick() { .setColorIcon(R.drawable.ic_osmo_dark)
.setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
Intent intent = new Intent(mapActivity, OsMoGroupsActivity.class); Intent intent = new Intent(mapActivity, OsMoGroupsActivity.class);
mapActivity.startActivity(intent); mapActivity.startActivity(intent);
return true; return true;
} }
}).reg(); })
.setPosition(6)
.createItem());
} }

View file

@ -19,6 +19,7 @@ import net.osmand.data.LatLon;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
@ -226,9 +227,11 @@ public class ParkingPositionPlugin extends OsmandPlugin {
return true; return true;
} }
}; };
adapter.item(R.string.context_menu_item_add_parking_point) adapter.addItem(new ContextMenuItem.ItemBuilder()
.colorIcon(R.drawable.ic_action_parking_dark).listen(addListener).reg(); .setTitleId(R.string.context_menu_item_add_parking_point, mapActivity)
.setColorIcon(R.drawable.ic_action_parking_dark)
.setListener(addListener)
.createItem());
} }
/** /**

View file

@ -24,6 +24,7 @@ import net.osmand.map.TileSourceManager;
import net.osmand.map.TileSourceManager.TileSourceTemplate; import net.osmand.map.TileSourceManager.TileSourceTemplate;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -254,12 +255,22 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
String overlayMapDescr = settings.MAP_OVERLAY.get(); String overlayMapDescr = settings.MAP_OVERLAY.get();
overlayMapDescr = overlayMapDescr != null ? overlayMapDescr : mapActivity.getString(R.string.shared_string_none); overlayMapDescr = overlayMapDescr != null ? overlayMapDescr : mapActivity.getString(R.string.shared_string_none);
adapter.item(R.string.layer_overlay).layout(R.layout.drawer_list_doubleitem).description(overlayMapDescr) adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_overlay, mapActivity)
.colorIcon(R.drawable.ic_layer_top_dark).listen(listener).position(14).reg(); .setLayout(R.layout.drawer_list_doubleitem)
.setDescription(overlayMapDescr)
.setColorIcon(R.drawable.ic_layer_top_dark)
.setListener(listener)
.setPosition(14)
.createItem());
String underlayMapDescr = settings.MAP_UNDERLAY.get(); String underlayMapDescr = settings.MAP_UNDERLAY.get();
underlayMapDescr = underlayMapDescr != null ? underlayMapDescr : mapActivity.getString(R.string.shared_string_none); underlayMapDescr = underlayMapDescr != null ? underlayMapDescr : mapActivity.getString(R.string.shared_string_none);
adapter.item(R.string.layer_underlay).layout(R.layout.drawer_list_doubleitem).description(underlayMapDescr) adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_underlay, mapActivity)
.colorIcon(R.drawable.ic_layer_bottom_dark).listen(listener).position(15).reg(); .setLayout(R.layout.drawer_list_doubleitem)
.setDescription(underlayMapDescr)
.setColorIcon(R.drawable.ic_layer_bottom_dark)
.setListener(listener)
.setPosition(15)
.createItem());
} }
@ -280,10 +291,14 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
return true; return true;
} }
}; };
adapter.item(R.string.context_menu_item_update_map).colorIcon(R.drawable.ic_action_refresh_dark) adapter.addItem(new ContextMenuItem.ItemBuilder()
.listen(listener).reg(); .setTitleId(R.string.context_menu_item_update_map, mapActivity)
adapter.item(R.string.shared_string_download_map).colorIcon(R.drawable.ic_action_import) .setColorIcon(R.drawable.ic_action_refresh_dark)
.listen(listener).reg(); .setListener(listener).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.shared_string_download_map, mapActivity)
.setColorIcon(R.drawable.ic_action_import)
.setListener(listener).createItem());
} }
} }

View file

@ -8,6 +8,7 @@ import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
@ -83,7 +84,7 @@ public class RoutePointsLayer extends OsmandMapLayer implements ContextMenuLaye
} }
@Override @Override
public void populateObjectContextMenu(LatLon latLon, Object o, ContextMenuAdapter adapter) { public void populateObjectContextMenu(LatLon latLon, Object o, ContextMenuAdapter adapter, MapActivity mapActivity) {
if (o != null && o instanceof GPXUtilities.WptPt && plugin.getCurrentRoute() != null){ if (o != null && o instanceof GPXUtilities.WptPt && plugin.getCurrentRoute() != null){
final GPXUtilities.WptPt point = (GPXUtilities.WptPt) o; final GPXUtilities.WptPt point = (GPXUtilities.WptPt) o;
ContextMenuAdapter.OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() { ContextMenuAdapter.OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() {
@ -109,23 +110,33 @@ public class RoutePointsLayer extends OsmandMapLayer implements ContextMenuLaye
}; };
if (plugin.getCurrentRoute().getPointStatus(point)){ if (plugin.getCurrentRoute().getPointStatus(point)){
adapter.item(R.string.mark_as_not_visited).colorIcon( adapter.addItem(new ContextMenuItem.ItemBuilder()
R.drawable.ic_action_gremove_dark).listen(listener).reg(); .setTitleId(R.string.mark_as_not_visited, mapActivity)
.setColorIcon(R.drawable.ic_action_gremove_dark)
.setListener(listener)
.createItem());
} else { } else {
adapter.item(R.string.mark_as_visited).colorIcon( adapter.addItem(new ContextMenuItem.ItemBuilder()
R.drawable.ic_action_done).listen(listener).reg(); .setTitleId(R.string.mark_as_visited, mapActivity)
.setColorIcon(R.drawable.ic_action_done)
.setListener(listener)
.createItem());
} }
RoutePointsPlugin.RoutePoint routePoint = plugin.getCurrentRoute().getRoutePointFromWpt(point); RoutePointsPlugin.RoutePoint routePoint = plugin.getCurrentRoute().getRoutePointFromWpt(point);
if (routePoint != null) { if (routePoint != null) {
if (routePoint.isNextNavigate) { if (routePoint.isNextNavigate) {
adapter.item(R.string.navigate_to_next) adapter.addItem(new ContextMenuItem.ItemBuilder()
.colorIcon(R.drawable.ic_action_gnext_dark).listen(listener) .setTitleId(R.string.navigate_to_next, mapActivity)
.reg(); .setColorIcon(R.drawable.ic_action_gnext_dark)
.setListener(listener)
.createItem());
} else { } else {
adapter.item(R.string.mark_as_current) adapter.addItem(new ContextMenuItem.ItemBuilder()
.colorIcon(R.drawable.ic_action_signpost_dark) .setTitleId(R.string.mark_as_current, mapActivity)
.listen(listener).reg(); .setColorIcon(R.drawable.ic_action_signpost_dark)
.setListener(listener)
.createItem());
} }
} }
} }

View file

@ -6,6 +6,7 @@ import android.widget.ArrayAdapter;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -114,8 +115,14 @@ public class SRTMPlugin extends OsmandPlugin {
return true; return true;
} }
}; };
adapter.item(R.string.layer_hillshade).selected(HILLSHADE.get()? 1 : 0) adapter.addItem(new ContextMenuItem.ItemBuilder()
.colorIcon(R.drawable.ic_action_hillshade_dark).listen(listener).position(13).layout(R.layout.drawer_list_item).reg(); .setTitleId(R.string.layer_hillshade, mapActivity)
.setSelected(HILLSHADE.get())
.setColorIcon(R.drawable.ic_action_hillshade_dark)
.setListener(listener)
.setPosition(13)
.setLayout(R.layout.drawer_list_item)
.createItem());
} }
@Override @Override

View file

@ -18,6 +18,7 @@ import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
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.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.MapContextMenu;
@ -131,7 +132,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
} }
@Override @Override
public void populateObjectContextMenu(LatLon latLon, Object o, ContextMenuAdapter adapter) { public void populateObjectContextMenu(LatLon latLon, Object o, ContextMenuAdapter adapter, MapActivity mapActivity) {
if (menu.hasHiddenBottomInfo()) { if (menu.hasHiddenBottomInfo()) {
ContextMenuAdapter.OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() { ContextMenuAdapter.OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() {
@Override @Override
@ -142,9 +143,10 @@ public class ContextMenuLayer extends OsmandMapLayer {
return true; return true;
} }
}; };
adapter.item(R.string.shared_string_show_description) adapter.addItem(new ContextMenuItem.ItemBuilder()
.colorIcon(R.drawable.ic_action_note_dark).listen(listener) .setTitleId(R.string.shared_string_show_description, activity)
.reg(); .setColorIcon(R.drawable.ic_action_note_dark).setListener(listener)
.createItem());
} }
} }

View file

@ -13,6 +13,7 @@ import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
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.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
@ -160,7 +161,7 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements ContextMenuL
} }
@Override @Override
public void populateObjectContextMenu(final LatLon latLon, final Object o, ContextMenuAdapter adapter) { public void populateObjectContextMenu(final LatLon latLon, final Object o, ContextMenuAdapter adapter, MapActivity mapActivity) {
if (latLon != null && o == null if (latLon != null && o == null
&& (routingHelper.isRoutePlanningMode() || routingHelper.isFollowingMode())) { && (routingHelper.isRoutePlanningMode() || routingHelper.isFollowingMode())) {
@ -176,8 +177,10 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements ContextMenuL
} }
}; };
adapter.item(R.string.avoid_road).colorIcon( adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.avoid_road, activity)
R.drawable.ic_action_road_works_dark).listen(listener).reg(); .setColorIcon(R.drawable.ic_action_road_works_dark)
.setListener(listener)
.createItem());
} }
} }
} }

View file

@ -12,6 +12,7 @@ import net.osmand.data.QuadRect;
import net.osmand.data.QuadTree; import net.osmand.data.QuadTree;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.activities.MapActivity;
import net.osmand.util.MapAlgorithms; import net.osmand.util.MapAlgorithms;
import java.util.ArrayList; import java.util.ArrayList;
@ -37,7 +38,7 @@ public abstract class OsmandMapLayer {
public void onRetainNonConfigurationInstance(Map<String, Object> map) { public void onRetainNonConfigurationInstance(Map<String, Object> map) {
} }
public void populateObjectContextMenu(LatLon latLon, Object o, ContextMenuAdapter adapter) { public void populateObjectContextMenu(LatLon latLon, Object o, ContextMenuAdapter adapter, MapActivity mapActivity) {
} }
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) { public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {

View file

@ -11,6 +11,7 @@ import android.widget.LinearLayout;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.MapMarkersMode; import net.osmand.plus.OsmandSettings.MapMarkersMode;
import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.OsmandSettings.OsmandPreference;
@ -285,47 +286,50 @@ public class MapWidgetRegistry {
addControlId(map, cm, R.string.map_widget_top_text, settings.SHOW_STREET_NAME); addControlId(map, cm, R.string.map_widget_top_text, settings.SHOW_STREET_NAME);
} }
if (settings.USE_MAP_MARKERS.get()) { if (settings.USE_MAP_MARKERS.get()) {
cm.item(R.string.map_markers).description(settings.MAP_MARKERS_MODE.get().toHumanString(map)).listen(new OnContextMenuClick() { cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_markers, map)
@Override .setDescription(settings.MAP_MARKERS_MODE.get().toHumanString(map))
public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) { .setListener(new OnContextMenuClick() {
final OsmandMapTileView view = map.getMapView();
AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
bld.setTitle(R.string.map_markers);
final String[] items = new String[MapMarkersMode.values().length];
for (int i = 0; i < items.length; i++) {
items[i] = MapMarkersMode.values()[i].toHumanString(map);
}
int i = settings.MAP_MARKERS_MODE.get().ordinal();
bld.setSingleChoiceItems(items, i, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public boolean onContextMenuClick(final ArrayAdapter<?> ad, int itemId, final int pos, boolean isChecked) {
settings.MAP_MARKERS_MODE.set(MapMarkersMode.values()[which]); final OsmandMapTileView view = map.getMapView();
for (MapWidgetRegInfo info : right) { AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
if ("map_marker_1st".equals(info.key) || "map_marker_2nd".equals(info.key)) { bld.setTitle(R.string.map_markers);
changeVisibility(info, settings.MAP_MARKERS_MODE.get().isWidgets()); final String[] items = new String[MapMarkersMode.values().length];
for (int i = 0; i < items.length; i++) {
items[i] = MapMarkersMode.values()[i].toHumanString(map);
}
int i = settings.MAP_MARKERS_MODE.get().ordinal();
bld.setSingleChoiceItems(items, i, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
settings.MAP_MARKERS_MODE.set(MapMarkersMode.values()[which]);
for (MapWidgetRegInfo info : right) {
if ("map_marker_1st".equals(info.key) || "map_marker_2nd".equals(info.key)) {
changeVisibility(info, settings.MAP_MARKERS_MODE.get().isWidgets());
}
}
MapInfoLayer mil = map.getMapLayers().getMapInfoLayer();
if (mil != null) {
mil.recreateControls();
}
map.refreshMap();
dialog.dismiss();
cm.setItemDescription(pos, settings.MAP_MARKERS_MODE.get().toHumanString(map));
ad.notifyDataSetChanged();
} }
} });
MapInfoLayer mil = map.getMapLayers().getMapInfoLayer(); bld.show();
if (mil != null) { return false;
mil.recreateControls();
}
map.refreshMap();
dialog.dismiss();
cm.setItemDescription(pos, settings.MAP_MARKERS_MODE.get().toHumanString(map));
ad.notifyDataSetChanged();
} }
}); }).setLayout(R.layout.list_item_text_button).createItem());
bld.show();
return false;
}
}).layout(R.layout.list_item_text_button).reg();
} }
} }
private void addControlId(final MapActivity map, ContextMenuAdapter cm, int stringId, OsmandPreference<Boolean> pref) { private void addControlId(final MapActivity map, ContextMenuAdapter cm,
cm.item(stringId).selected(pref.get() ? 1 : 0) @StringRes int stringId, OsmandPreference<Boolean> pref) {
// .icons(r.drawableDark, r.drawableLight) cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(stringId, map)
.listen(new ApearanceOnContextMenuClick(pref, map)).reg(); .setSelected(pref.get())
.setListener(new ApearanceOnContextMenuClick(pref, map)).createItem());
} }
class ApearanceOnContextMenuClick implements OnContextMenuClick { class ApearanceOnContextMenuClick implements OnContextMenuClick {
@ -360,13 +364,16 @@ public class MapWidgetRegistry {
public void addControls(MapActivity map, ContextMenuAdapter cm, ApplicationMode mode) { public void addControls(MapActivity map, ContextMenuAdapter cm, ApplicationMode mode) {
cm.item(R.string.map_widget_right).setCategory(true).layout(R.layout.list_group_title_with_switch).reg(); cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_right, map)
.setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
addControls(map, cm, right, mode); addControls(map, cm, right, mode);
if (mode != ApplicationMode.DEFAULT) { if (mode != ApplicationMode.DEFAULT) {
cm.item(R.string.map_widget_left).setCategory(true).layout(R.layout.list_group_title_with_switch).reg(); cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_left, map)
.setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
addControls(map, cm, left, mode); addControls(map, cm, left, mode);
} }
cm.item(R.string.map_widget_appearance_rem).setCategory(true).layout(R.layout.list_group_title_with_switch).reg(); cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_appearance_rem, map)
.setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
addControlsAppearance(map, cm, mode); addControlsAppearance(map, cm, mode);
} }
@ -393,11 +400,11 @@ public class MapWidgetRegistry {
if ("map_marker_1st".equals(r.key) || "map_marker_2nd".equals(r.key)) { if ("map_marker_1st".equals(r.key) || "map_marker_2nd".equals(r.key)) {
continue; continue;
} }
adapter.item(r.messageId) adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(r.messageId, map)
.selected(r.visibleCollapsed(mode) || r.visible(mode) ? 1 : 0) .setSelected(r.visibleCollapsed(mode) || r.visible(mode))
.colorIcon(r.drawableMenu) .setColorIcon(r.drawableMenu)
.secondaryIconColor(R.drawable.ic_action_additional_option) .setSecondaryLightIcon(R.drawable.ic_action_additional_option)
.listen(new OnContextMenuClick() { .setListener(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> a, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> a, int itemId, int pos, boolean isChecked) {
changeVisibility(r); changeVisibility(r);
@ -406,12 +413,11 @@ public class MapWidgetRegistry {
mil.recreateControls(); mil.recreateControls();
} }
adapter.setItemName(pos, getText(mil.getMapActivity(), mode, r)); adapter.setItemName(pos, getText(mil.getMapActivity(), mode, r));
adapter.setSelection(pos, r.visibleCollapsed(mode) || r.visible(mode) ? 1 : 0); adapter.setSelection(pos, r.visibleCollapsed(mode) || r.visible(mode));
a.notifyDataSetChanged(); a.notifyDataSetChanged();
return false; return false;
} }
}) }).createItem());
.reg();
adapter.setItemName(adapter.length() - 1, getText(map, mode, r)); adapter.setItemName(adapter.length() - 1, getText(map, mode, r));
} }
} }
@ -492,7 +498,8 @@ public class MapWidgetRegistry {
public ContextMenuAdapter getViewConfigureMenuAdapter(final MapActivity map) { public ContextMenuAdapter getViewConfigureMenuAdapter(final MapActivity map) {
final ContextMenuAdapter cm = new ContextMenuAdapter(map); final ContextMenuAdapter cm = new ContextMenuAdapter(map);
cm.setDefaultLayoutId(R.layout.list_item_icon_and_menu); cm.setDefaultLayoutId(R.layout.list_item_icon_and_menu);
cm.item(R.string.app_modes_choose).layout(R.layout.mode_toggles).reg(); cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.app_modes_choose, map)
.setLayout(R.layout.mode_toggles).createItem());
cm.setChangeAppModeListener(new ConfigureMapMenu.OnClickListener() { cm.setChangeAppModeListener(new ConfigureMapMenu.OnClickListener() {
@Override @Override