From 09b78d044fb10b9b9841d5235a292e67529d259f Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Fri, 25 Mar 2016 18:56:48 +0200 Subject: [PATCH] Refactoring --- .../net/osmand/plus/ContextMenuAdapter.java | 325 +++------- .../src/net/osmand/plus/ContextMenuItem.java | 235 ++++++++ .../plus/activities/MapActivityActions.java | 114 ++-- .../plus/activities/MapActivityLayers.java | 15 +- .../activities/actions/AppModeDialog.java | 2 +- .../audionotes/AudioVideoNotesPlugin.java | 35 +- .../development/OsmandDevelopmentPlugin.java | 9 +- .../osmand/plus/dialogs/ConfigureMapMenu.java | 559 ++++++++++-------- .../osmand/plus/dialogs/RasterMapMenu.java | 39 +- .../DistanceCalculatorPlugin.java | 8 +- .../download/ui/LocalIndexesFragment.java | 49 +- .../net/osmand/plus/helpers/GpxUiHelper.java | 21 +- .../plus/mapcontextmenu/MapContextMenu.java | 2 +- .../other/RoutePreferencesMenu.java | 8 +- .../monitoring/OsmandMonitoringPlugin.java | 13 +- .../plus/myplaces/AvailableGPXFragment.java | 14 +- .../osmand/plus/osmedit/OsmEditingPlugin.java | 58 +- .../src/net/osmand/plus/osmo/OsMoPlugin.java | 10 +- .../parkingpoint/ParkingPositionPlugin.java | 9 +- .../rastermaps/OsmandRasterMapsPlugin.java | 31 +- .../RoutePointsLayer.java | 33 +- .../osmand/plus/srtmplugin/SRTMPlugin.java | 11 +- .../osmand/plus/views/ContextMenuLayer.java | 10 +- .../plus/views/ImpassableRoadsLayer.java | 9 +- .../net/osmand/plus/views/OsmandMapLayer.java | 3 +- .../views/mapwidgets/MapWidgetRegistry.java | 101 ++-- 26 files changed, 1004 insertions(+), 719 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/ContextMenuItem.java diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java index c4228c06a4..e609ec89ad 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java @@ -7,9 +7,9 @@ import android.graphics.drawable.Drawable; import android.os.Build; import android.support.annotation.DrawableRes; import android.support.annotation.LayoutRes; -import android.support.annotation.StringRes; import android.support.v4.content.ContextCompat; import android.support.v4.graphics.drawable.DrawableCompat; +import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; @@ -32,30 +32,14 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; -import gnu.trove.list.array.TIntArrayList; - public class ContextMenuAdapter { private static final Log LOG = PlatformUtil.getLog(ContextMenuAdapter.class); private final Context ctx; - private View anchor; @LayoutRes private int defaultLayoutId = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ? R.layout.list_menu_item : R.layout.list_menu_item_native; - final TIntArrayList items = new TIntArrayList(); - final TIntArrayList isCategory = new TIntArrayList(); - final ArrayList itemNames = new ArrayList(); - final ArrayList checkListeners = new ArrayList<>(); - final ArrayList 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 itemDescription = new ArrayList(); - private List visibleModes = new ArrayList(); + List items = new ArrayList<>(); private ConfigureMapMenu.OnClickListener changeAppModeListener = null; //neded to detect whether user opened all modes or not private BooleanResult allModes = new BooleanResult(); @@ -69,84 +53,61 @@ public class ContextMenuAdapter { this.ctx = ctx; } - public void setAnchor(View anchor) { - this.anchor = anchor; - } - - public View getAnchor() { - return anchor; - } - public int length() { return items.size(); } - public int getElementId(int pos) { - return items.get(pos); + public int getElementId(int position) { + return items.get(position).getTitleId(); } - public OnContextMenuClick getClickAdapter(int i) { - return checkListeners.get(i); + public OnContextMenuClick getClickAdapter(int position) { + return items.get(position).getCheckBoxListener(); } - public OnIntegerValueChangedListener getIntegerLister(int i) { - return integerListeners.get(i); + public OnIntegerValueChangedListener getIntegerLister(int position) { + return items.get(position).getIntegerListener(); } - public String getItemName(int pos) { - return itemNames.get(pos); + public String getItemName(int position) { + return items.get(position).getTitle(); } - public String getItemDescr(int pos) { - return itemDescription.get(pos); + public String getItemDescr(int position) { + return items.get(position).getDescription(); } - public void setItemName(int pos, String str) { - itemNames.set(pos, str); + public Boolean getSelection(int position) { + return items.get(position).getSelected(); } - public void setItemDescription(int pos, String str) { - itemDescription.set(pos, str); + public int getProgress(int position) { + return items.get(position).getProgress(); } - public int getSelection(int pos) { - return selectedList.get(pos); + public int getLoading(int position) { + return items.get(position).isLoading() ? 1 : 0; } - public int getProgress(int pos) { - return progressList.get(pos); - } - - 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) { + public Drawable getImage(OsmandApplication ctx, int position, boolean light) { + @DrawableRes + int lst = items.get(position).getIcon(); + if (lst != -1) { return ctx.getResources().getDrawable(lst); } - int lstLight = lightIconList.get(pos); - if (lstLight != 0) { + @DrawableRes + int lstLight = items.get(position).getLightIcon(); + if (lstLight != -1) { return ctx.getIconsCache().getIcon(lstLight, light); } return null; } - public Drawable getSecondaryImage(OsmandApplication ctx, int pos, boolean light) { + public Drawable getSecondaryImage(OsmandApplication ctx, int position, boolean light) { @DrawableRes - int secondaryDrawableId = secondaryLightIconList.get(pos); - if (secondaryDrawableId != 0) { - return ContextCompat.getDrawable(ctx, secondaryDrawableId); + int secondaryDrawableId = items.get(position).getSecondaryLightIcon(); + if (secondaryDrawableId != -1) { + return ctx.getIconsCache().getIcon(secondaryDrawableId, light); } return null; } @@ -159,55 +120,50 @@ public class ContextMenuAdapter { } } - public boolean isCategory(int pos) { - return isCategory.get(pos) > 0; - } - - 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); + return items.get(pos).isCategory(); } public int getLayoutId(int position) { - int l = layoutIds.get(position); + int l = items.get(position).getLayout(); if (l != -1) { return l; } 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) { this.defaultLayoutId = defaultLayoutId; @@ -223,19 +179,17 @@ public class ContextMenuAdapter { final int layoutId = defaultLayoutId; final OsmandApplication app = ((OsmandApplication) activity.getApplication()); return new ContextMenuArrayAdapter(activity, layoutId, R.id.title, - getItemNames(), app, holoLight); + items.toArray(new ContextMenuItem[items.size()]), app, holoLight); } - public class ContextMenuArrayAdapter extends ArrayAdapter { - private Activity activity; + public class ContextMenuArrayAdapter extends ArrayAdapter { private OsmandApplication app; private boolean holoLight; private int layoutId; 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); - activity = context; this.app = app; this.holoLight = holoLight; layoutId = resource; @@ -244,10 +198,12 @@ public class ContextMenuAdapter { @Override public View getView(final int position, View convertView, ViewGroup parent) { // User super class to create the View + final ContextMenuItem item = getItem(position); Integer lid = getLayoutId(position); if (lid == R.layout.mode_toggles) { final Set selected = new LinkedHashSet(); - return AppModeDialog.prepareAppModeDrawerView(activity, visibleModes, selected, allModes, true, new View.OnClickListener() { + return AppModeDialog.prepareAppModeDrawerView((Activity) getContext(), + selected, allModes, true, new View.OnClickListener() { @Override public void onClick(View view) { if (selected.size() > 0) { @@ -261,22 +217,22 @@ public class ContextMenuAdapter { }); } 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); convertView.setTag(lid); } TextView tv = (TextView) convertView.findViewById(R.id.title); if (!isCategory(position)) { - AndroidUtils.setTextPrimaryColor(ctx, tv, !holoLight); + AndroidUtils.setTextPrimaryColor(getContext(), tv, !holoLight); } tv.setText(isCategory(position) ? getItemName(position).toUpperCase() : getItemName(position)); if (layoutId == R.layout.simple_list_menu_item) { - int color = activity.getResources() - .getColor(holoLight ? R.color.icon_color : R.color.dashboard_subheader_text_dark); - Drawable imageId = app.getIconsCache().getPaintedContentIcon( - lightIconList.get(position), color); - float density = activity.getResources().getDisplayMetrics().density; + int color = ContextCompat.getColor(getContext(), + holoLight ? R.color.icon_color : R.color.dashboard_subheader_text_dark); + Drawable imageId = ContextCompat.getDrawable(getContext(), item.getLightIcon()); + DrawableCompat.setTint(imageId, color); + float density = getContext().getResources().getDisplayMetrics().density; int paddingInPixels = (int) (24 * density); int drawableSizeInPixels = (int) (24 * density); // 32 imageId.setBounds(0, 0, drawableSizeInPixels, drawableSizeInPixels); @@ -293,9 +249,9 @@ public class ContextMenuAdapter { } } @DrawableRes - int secondaryLightDrawable = secondaryLightIconList.get(position); - if (secondaryLightDrawable != 0) { - int color = ContextCompat.getColor(ctx, + int secondaryLightDrawable = item.getSecondaryLightIcon(); + if (secondaryLightDrawable != -1) { + int color = ContextCompat.getColor(getContext(), holoLight ? R.color.icon_color : R.color.dashboard_subheader_text_dark); Drawable drawable = getSecondaryImage(app, position, holoLight); DrawableCompat.setTint(drawable, color); @@ -317,17 +273,17 @@ public class ContextMenuAdapter { if (convertView.findViewById(R.id.toggle_item) != null) { final CompoundButton ch = (CompoundButton) convertView.findViewById(R.id.toggle_item); - if (selectedList.get(position) != -1) { + if (item.getSelected() != null) { ch.setOnCheckedChangeListener(null); ch.setVisibility(View.VISIBLE); - ch.setChecked(selectedList.get(position) > 0); - final ArrayAdapter la = this; + ch.setChecked(item.getSelected()); + final ArrayAdapter la = this; final OnCheckedChangeListener listener = new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { OnContextMenuClick ca = getClickAdapter(position); - selectedList.set(position, isChecked ? 1 : 0); + item.setSelected(isChecked); if (ca != null) { ca.onContextMenuClick(la, getElementId(position), position, isChecked); } @@ -342,13 +298,13 @@ public class ContextMenuAdapter { if (convertView.findViewById(R.id.seekbar) != null) { SeekBar seekBar = (SeekBar) convertView.findViewById(R.id.seekbar); - if (progressList.get(position) != -1) { + if (item.getProgress() != -1) { seekBar.setProgress(getProgress(position)); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { OnIntegerValueChangedListener listener = getIntegerLister(position); - progressList.set(position, progress); + item.setProgress(progress); if (listener != null && fromUser) { listener.onIntegerValueChangedListener(progress); } @@ -370,7 +326,7 @@ public class ContextMenuAdapter { if (convertView.findViewById(R.id.ProgressBar) != null) { ProgressBar bar = (ProgressBar) convertView.findViewById(R.id.ProgressBar); - if (loadingList.get(position) == 1) { + if (item.isLoading()) { bar.setVisibility(View.VISIBLE); } else { 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; - } - - } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuItem.java b/OsmAnd/src/net/osmand/plus/ContextMenuItem.java new file mode 100644 index 0000000000..75b4969404 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/ContextMenuItem.java @@ -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); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index c4ffe64caf..dee089cfcc 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -30,6 +30,7 @@ import net.osmand.map.ITileSource; import net.osmand.plus.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; +import net.osmand.plus.ContextMenuItem; import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities.GPXFile; 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) { 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()) { - adapter.item(R.string.context_menu_item_directions_from).colorIcon( - R.drawable.ic_action_gdirections_dark).reg(); + adapter.addItem(itemBuilder.setTitleId(R.string.context_menu_item_directions_from, mapActivity) + .setColorIcon(R.drawable.ic_action_gdirections_dark).createItem()); } - if (getMyApplication().getTargetPointsHelper().getPointToNavigate() != null && + if (getMyApplication().getTargetPointsHelper().getPointToNavigate() != null && (mapActivity.getRoutingHelper().isFollowingMode() || mapActivity.getRoutingHelper().isRoutePlanningMode())) { - adapter.item(R.string.context_menu_item_last_intermediate_point).colorIcon( - R.drawable.ic_action_intermediate).reg(); + adapter.addItem(itemBuilder.setTitleId(R.string.context_menu_item_last_intermediate_point, mapActivity) + .setColorIcon(R.drawable.ic_action_intermediate).createItem()); } OsmandPlugin.registerMapContextMenu(mapActivity, latitude, longitude, adapter, selectedObj); @@ -593,8 +596,9 @@ public class MapActivityActions implements DialogProvider { final OsmandApplication app = mapActivity.getMyApplication(); ContextMenuAdapter optionsMenuHelper = new ContextMenuAdapter(app); - optionsMenuHelper.item(R.string.home).colorIcon(R.drawable.map_dashboard) - .listen(new OnContextMenuClick() { + optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.home, mapActivity) + .setColorIcon(R.drawable.map_dashboard) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { MapActivity.clearPrevActivityIntent(); @@ -602,30 +606,33 @@ public class MapActivityActions implements DialogProvider { mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.DASHBOARD); return true; } - }).reg(); + }).createItem()); if (settings.USE_MAP_MARKERS.get()) { - optionsMenuHelper.item(R.string.map_markers).colorIcon(R.drawable.ic_action_flag_dark) - .listen(new OnContextMenuClick() { + optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_markers, mapActivity) + .setColorIcon(R.drawable.ic_action_flag_dark) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { MapActivity.clearPrevActivityIntent(); mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.MAP_MARKERS); return false; } - }).reg(); + }).createItem()); } else { - optionsMenuHelper.item(R.string.waypoints).colorIcon(R.drawable.ic_action_intermediate) - .listen(new OnContextMenuClick() { + optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.waypoints, mapActivity) + .setColorIcon(R.drawable.ic_action_intermediate) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { MapActivity.clearPrevActivityIntent(); mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS); return false; } - }).reg(); + }).createItem()); } - optionsMenuHelper.item(R.string.get_directions).colorIcon(R.drawable.ic_action_gdirections_dark) - .listen(new OnContextMenuClick() { + optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.get_directions, mapActivity) + .setColorIcon(R.drawable.ic_action_gdirections_dark) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { MapActivity.clearPrevActivityIntent(); @@ -640,11 +647,11 @@ public class MapActivityActions implements DialogProvider { } return true; } - }).reg(); + }).createItem()); // Default actions (Layers, Configure Map screen, Settings, Search, Favorites) - optionsMenuHelper.item(R.string.search_button) - .colorIcon(R.drawable.ic_action_search_dark) - .listen(new OnContextMenuClick() { + optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.search_button, mapActivity) + .setColorIcon(R.drawable.ic_action_search_dark) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization() @@ -659,10 +666,11 @@ public class MapActivityActions implements DialogProvider { mapActivity.startActivity(newIntent); return true; } - }).reg(); + }).createItem()); - optionsMenuHelper.item(R.string.shared_string_my_places).colorIcon(R.drawable.ic_action_fav_dark) - .listen(new OnContextMenuClick() { + optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_my_places, mapActivity) + .setColorIcon(R.drawable.ic_action_fav_dark) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization() @@ -671,38 +679,41 @@ public class MapActivityActions implements DialogProvider { mapActivity.startActivity(newIntent); return true; } - }).reg(); + }).createItem()); - optionsMenuHelper.item(R.string.show_point_options).colorIcon(R.drawable.ic_action_marker_dark) - .listen(new OnContextMenuClick() { + optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.show_point_options, mapActivity) + .setColorIcon(R.drawable.ic_action_marker_dark) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { MapActivity.clearPrevActivityIntent(); mapActivity.getMapLayers().getContextMenuLayer().showContextMenu(mapView.getLatitude(), mapView.getLongitude(), true); return true; } - }).reg(); + }).createItem()); - optionsMenuHelper.item(R.string.configure_map).colorIcon(R.drawable.ic_action_layers_dark) - .listen(new OnContextMenuClick() { + optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.configure_map, mapActivity) + .setColorIcon(R.drawable.ic_action_layers_dark) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { MapActivity.clearPrevActivityIntent(); mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_MAP); return false; } - }).reg(); + }).createItem()); - optionsMenuHelper.item(R.string.layer_map_appearance).colorIcon(R.drawable.ic_configure_screen_dark) - .listen(new OnContextMenuClick() { + optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_map_appearance, mapActivity) + .setColorIcon(R.drawable.ic_configure_screen_dark) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { MapActivity.clearPrevActivityIntent(); mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_SCREEN); return false; } - }).reg(); + }).createItem()); String d = getString(R.string.index_settings); if (app.getDownloadThread().getIndexes().isDownloadedFromInternet) { @@ -711,8 +722,9 @@ public class MapActivityActions implements DialogProvider { d += " (" + updt.size() + ")"; } } - optionsMenuHelper.item(R.string.index_settings).name(d).colorIcon(R.drawable.ic_type_archive) - .listen(new OnContextMenuClick() { + optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.index_settings, null) + .setTitle(d).setColorIcon(R.drawable.ic_type_archive) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization() @@ -721,11 +733,12 @@ public class MapActivityActions implements DialogProvider { mapActivity.startActivity(newIntent); return true; } - }).reg(); + }).createItem()); if (Version.isGooglePlayEnabled(app)) { - optionsMenuHelper.item(R.string.osm_live).colorIcon(R.drawable.ic_action_osm_live) - .listen(new OnContextMenuClick() { + optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.osm_live, mapActivity) + .setColorIcon(R.drawable.ic_action_osm_live) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { Intent intent = new Intent(mapActivity, OsmLiveActivity.class); @@ -733,11 +746,12 @@ public class MapActivityActions implements DialogProvider { mapActivity.startActivity(intent); return false; } - }).reg(); + }).createItem()); } - optionsMenuHelper.item(R.string.prefs_plugins).colorIcon(R.drawable.ic_extension_dark) - .listen(new OnContextMenuClick() { + optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.prefs_plugins, mapActivity) + .setColorIcon(R.drawable.ic_extension_dark) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization() @@ -746,11 +760,12 @@ public class MapActivityActions implements DialogProvider { mapActivity.startActivity(newIntent); return true; } - }).reg(); + }).createItem()); - optionsMenuHelper.item(R.string.shared_string_settings).colorIcon(R.drawable.ic_action_settings) - .listen(new OnContextMenuClick() { + optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_settings, mapActivity) + .setColorIcon(R.drawable.ic_action_settings) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { final Intent settings = new Intent(mapActivity, getMyApplication().getAppCustomization() @@ -759,9 +774,10 @@ public class MapActivityActions implements DialogProvider { mapActivity.startActivity(settings); return true; } - }).reg(); - optionsMenuHelper.item(R.string.shared_string_help).colorIcon(R.drawable.ic_action_help) - .listen(new OnContextMenuClick() { + }).createItem()); + optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_help, mapActivity) + .setColorIcon(R.drawable.ic_action_help) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { Intent intent = new Intent(mapActivity, HelpActivity.class); @@ -769,7 +785,7 @@ public class MapActivityActions implements DialogProvider { mapActivity.startActivity(intent); return true; } - }).reg(); + }).createItem()); //////////// Others OsmandPlugin.registerOptionsMenu(mapActivity, optionsMenuHelper); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java index f0d25628f4..b481d897c0 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java @@ -14,7 +14,7 @@ import net.osmand.access.AccessibleToast; import net.osmand.map.ITileSource; import net.osmand.map.TileSourceManager.TileSourceTemplate; 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.WptPt; import net.osmand.plus.OsmandApplication; @@ -262,7 +262,9 @@ public class MapActivityLayers { OsmandApplication app = (OsmandApplication) getApplication(); final PoiFiltersHelper poiFilters = app.getPoiFilters(); 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 list = new ArrayList(); list.add(poiFilters.getCustomPOIFilter()); for (PoiUIFilter f : poiFilters.getTopDefinedPoiFilters()) { @@ -301,13 +303,14 @@ public class MapActivityLayers { private void addFilterToList(final ContextMenuAdapter adapter, final List list, PoiUIFilter 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())) { - it.icon(RenderingIcons.getBigIconResourceId(f.getIconId())); + builder.setIcon(RenderingIcons.getBigIconResourceId(f.getIconId())); } 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) { diff --git a/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java b/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java index 2a888ae2ba..676cc5687e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java +++ b/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java @@ -36,7 +36,7 @@ public class AppModeDialog { //special method for drawer menu //needed because if there's more than 4 items - the don't fit in drawer - public static View prepareAppModeDrawerView(Activity a, List visible, final Set selected, ContextMenuAdapter.BooleanResult allModes, + public static View prepareAppModeDrawerView(Activity a, final Set selected, ContextMenuAdapter.BooleanResult allModes, boolean useMapTheme, final View.OnClickListener onClickListener) { OsmandSettings settings = ((OsmandApplication) a.getApplication()).getSettings(); final List values = new ArrayList(ApplicationMode.values(settings)); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index d8eaab3821..1ce3704ef9 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -48,6 +48,7 @@ import net.osmand.data.PointDescription; import net.osmand.plus.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; +import net.osmand.plus.ContextMenuItem; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; @@ -590,8 +591,11 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { return true; } }; - adapter.item(R.string.layer_recordings).selected(SHOW_RECORDINGS.get() ? 1 : 0) - .colorIcon(R.drawable.ic_action_micro_dark).listen(listener).position(12).reg(); + adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_recordings, app) + .setSelected(SHOW_RECORDINGS.get()) + .setColorIcon(R.drawable.ic_action_micro_dark) + .setPosition(12) + .setListener(listener).createItem()); } @Override @@ -600,33 +604,42 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { if (isRecording()) { return; } - adapter.item(R.string.recording_context_menu_arecord).colorIcon(R.drawable.ic_action_micro_dark) - .listen(new OnContextMenuClick() { + adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.recording_context_menu_arecord, app) + .setColorIcon(R.drawable.ic_action_micro_dark) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { recordAudio(latitude, longitude, mapActivity); return true; } - }).position(6).reg(); - adapter.item(R.string.recording_context_menu_vrecord).colorIcon(R.drawable.ic_action_video_dark) - .listen(new OnContextMenuClick() { + }) + .setPosition(6) + .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 public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { recordVideo(latitude, longitude, mapActivity); return true; } - }).position(7).reg(); - adapter.item(R.string.recording_context_menu_precord).colorIcon(R.drawable.ic_action_photo_dark) - .listen(new OnContextMenuClick() { + }) + .setPosition(7) + .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 public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { takePhoto(latitude, longitude, mapActivity, false); return true; } - }).position(8).reg(); + }) + .setPosition(8) + .createItem()); } @Override diff --git a/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java b/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java index 8f0974f212..ec8f246ae5 100644 --- a/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java +++ b/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java @@ -6,6 +6,7 @@ import android.widget.ArrayAdapter; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; +import net.osmand.plus.ContextMenuItem; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; @@ -56,15 +57,17 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin { @Override public void registerOptionsMenuItems(final MapActivity mapActivity, ContextMenuAdapter helper) { if (Version.isDeveloperVersion(mapActivity.getMyApplication())) { - helper.item(R.string.version_settings).colorIcon(R.drawable.ic_action_gabout_dark) - .listen(new OnContextMenuClick() { + helper.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.version_settings, mapActivity) + .setColorIcon(R.drawable.ic_action_gabout_dark) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { final Intent mapIntent = new Intent(mapActivity, ContributionVersionActivity.class); mapActivity.startActivityForResult(mapIntent, 0); return true; } - }).reg(); + }).createItem()); } } diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java index 108001cde0..5bd24db967 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java @@ -15,6 +15,7 @@ import net.osmand.core.android.MapRendererContext; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.ContextMenuAdapter.OnRowItemClick; +import net.osmand.plus.ContextMenuItem; import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; @@ -54,16 +55,20 @@ import gnu.trove.list.array.TIntArrayList; public class ConfigureMapMenu { private static final Log LOG = PlatformUtil.getLog(ConfigureMapMenu.class); - public interface OnClickListener{ + public interface OnClickListener { public void onClick(boolean result); - }; + } + + ; private boolean allModes = false; public ContextMenuAdapter createListAdapter(final MapActivity ma) { ContextMenuAdapter adapter = new ContextMenuAdapter(ma, allModes); 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() { @Override public void onClick(boolean result) { @@ -73,10 +78,10 @@ public class ConfigureMapMenu { }); createLayersItems(adapter, ma); createRenderingAttributeItems(adapter, ma); - + return adapter; } - + private final class LayerMenuListener extends OnRowItemClick { private MapActivity ma; private ContextMenuAdapter cm; @@ -95,16 +100,16 @@ public class ConfigureMapMenu { } return files; } - + @Override 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()); 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()); return false; - } else { + } else { return super.onRowItemClick(adapter, view, itemId, pos); } } @@ -131,13 +136,13 @@ public class ConfigureMapMenu { public void onDismiss(DialogInterface dialog) { boolean areAnyGpxTracksVisible = ma.getMyApplication().getSelectedGpxHelper().isShowingAnyGpxFiles(); - cm.setSelection(pos, areAnyGpxTracksVisible ? 1 : 0); + cm.setSelection(pos, areAnyGpxTracksVisible); adapter.notifyDataSetChanged(); } }); } } 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.putExtra(PluginActivity.EXTRA_PLUGIN_ID, OsmandRasterMapsPlugin.ID); 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(); OsmandSettings settings = app.getSettings(); 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()) +"] "; - adapter.item(R.string.layer_poi).selected(settings.SELECTED_POI_FILTER_FOR_MAP.get() != null ? 1 : 0) - .colorIcon(R.drawable.ic_action_info_dark).listen(l).reg(); - adapter.item(R.string.layer_amenity_label).selected(settings.SHOW_POI_LABEL.get() ? 1 : 0) - .colorIcon(R.drawable.ic_action_text_dark).listen(l).reg(); - adapter.item(R.string.shared_string_favorites).selected(settings.SHOW_FAVORITES.get() ? 1 : 0) - .colorIcon(R.drawable.ic_action_fav_dark).listen(l).reg(); - adapter.item(R.string.layer_gpx_layer).selected( - app.getSelectedGpxHelper().isShowingAnyGpxFiles() ? 1 : 0) - .colorIcon(R.drawable.ic_action_polygom_dark) - .listen(l).reg(); - adapter.item(R.string.layer_map).colorIcon(R.drawable.ic_world_globe_dark) - .listen(l).reg(); - if(TransportRouteHelper.getInstance().routeIsCalculated()){ - adapter.item(R.string.layer_transport_route).selected(1) - .colorIcon(R.drawable.ic_action_bus_dark).listen(l).reg(); + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.layer_poi, activity) + .setSelected(settings.SELECTED_POI_FILTER_FOR_MAP.get() != null) + .setColorIcon(R.drawable.ic_action_info_dark) + .setListener(l).createItem()); + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.layer_amenity_label, activity) + .setSelected(settings.SHOW_POI_LABEL.get()) + .setColorIcon(R.drawable.ic_action_text_dark) + .setListener(l).createItem()); + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.shared_string_favorites, activity) + .setSelected(settings.SHOW_FAVORITES.get()) + .setColorIcon(R.drawable.ic_action_fav_dark) + .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); app.getAppCustomization().prepareLayerContextMenu(activity, adapter); } @@ -196,209 +218,224 @@ public class ConfigureMapMenu { activity.getMyApplication().getResourceManager().getRenderer().clearCache(); activity.updateMapSettings(); GPXLayer gpx = activity.getMapView().getLayerByClass(GPXLayer.class); - if(gpx != null) { + if (gpx != null) { gpx.updateLayerStyle(); } RouteLayer rte = activity.getMapView().getLayerByClass(RouteLayer.class); - if(rte != null) { + if (rte != null) { rte.updateLayerStyle(); } activity.getMapView().refreshMap(true); } - + 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); - adapter.item(R.string.map_widget_renderer).listen(new OnContextMenuClick() { - @Override - public boolean onContextMenuClick(final ArrayAdapter ad, int itemId, final int pos, boolean isChecked) { - AlertDialog.Builder bld = new AlertDialog.Builder(activity); - bld.setTitle(R.string.renderers); - final OsmandApplication app = activity.getMyApplication(); - Collection 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() { - + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.map_widget_renderer, activity) + .setListener(new OnContextMenuClick() { @Override - public void onClick(DialogInterface dialog, int which) { - String renderer = items[which]; - RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer); - if (loaded != null) { - OsmandMapTileView view = activity.getMapView(); - view.getSettings().RENDERER.set(renderer); - app.getRendererRegistry().setCurrentSelectedRender(loaded); - refreshMapComplete(activity); - } else { - AccessibleToast.makeText(app, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show(); + public boolean onContextMenuClick(final ArrayAdapter ad, int itemId, final int pos, boolean isChecked) { + AlertDialog.Builder bld = new AlertDialog.Builder(activity); + bld.setTitle(R.string.renderers); + final OsmandApplication app = activity.getMyApplication(); + Collection 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('-', ' '); } - adapter.setItemDescription(pos, getRenderDescr(activity)); - activity.getDashboard().refreshContent(true); - dialog.dismiss(); - } + bld.setSingleChoiceItems(visibleNames, selected, new DialogInterface.OnClickListener() { - }); - 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 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 values = new ArrayList(); - 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(); + String renderer = items[which]; + RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer); + if (loaded != null) { + OsmandMapTileView view = activity.getMapView(); + view.getSettings().RENDERER.set(renderer); + 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 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 values = new ArrayList(); + 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(); dialog.dismiss(); } }); - bld.show(); - return false; - } - }).description(String.format("%.0f", 100f * activity.getMyApplication().getSettings().MAP_DENSITY.get()) + " %").layout(R.layout.drawer_list_doubleitem).reg(); + b.show(); + return false; + } + }).setDescription(getScale(activity)).setLayout(R.layout.drawer_list_doubleitem).createItem()); - adapter.item(R.string.text_size).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.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() { + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.map_locale, activity).setListener(new OnContextMenuClick() { @Override - public void onClick(DialogInterface dialog, int which) { - view.getSettings().TEXT_SCALE.set(txtValues[which]); - refreshMapComplete(activity); - adapter.setItemDescription(pos, getScale(activity)); - ad.notifyDataSetInvalidated(); - dialog.dismiss(); + 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; } - }); - b.show(); - return false; - } - }).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(); + }) + .setDescription(activity.getMyApplication().getSettings().MAP_PREFERRED_LOCALE.get()) + .setLayout(R.layout.drawer_list_doubleitem).createItem()); RenderingRulesStorage renderer = activity.getMyApplication().getRendererRegistry().getCurrentSelectedRenderer(); if (renderer != null) { List customRules = new ArrayList(); - for(RenderingRuleProperty p : renderer.PROPS.getCustomRules()) { - if(!RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(p.getCategory())){ + for (RenderingRuleProperty p : renderer.PROPS.getCustomRules()) { + if (!RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(p.getCategory())) { customRules.add(p); } } - + createProperties(customRules, R.string.rendering_category_transport, "transport", adapter, activity); createProperties(customRules, R.string.rendering_category_details, "details", @@ -407,30 +444,32 @@ public class ConfigureMapMenu { adapter, activity); createProperties(customRules, R.string.rendering_category_routes, "routes", adapter, activity); - - if(customRules.size() > 0) { - adapter.item(R.string.rendering_category_others).setCategory(true).layout(R.layout.drawer_list_sub_header).reg(); + + if (customRules.size() > 0) { + 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); } } } - - 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) { String[] vls = getMapNamesValues(ctx, mapNamesIds); final Map mp = new HashMap(); - for(int i = 0; i < mapNamesIds.length; i++) { + for (int i = 0; i < mapNamesIds.length; i++) { mp.put(mapNamesIds[i], vls[i]); } ArrayList lst = new ArrayList(mp.keySet()); Collections.sort(lst, new Comparator() { @Override public int compare(String lhs, String rhs) { - int i1 = Algorithms.isEmpty(lhs)? 0 : (lhs.equals("en") ? 1 : 2); - int i2 = Algorithms.isEmpty(rhs)? 0 : (rhs.equals("en") ? 1 : 2); - if(i1 != i2) { + int i1 = Algorithms.isEmpty(lhs) ? 0 : (lhs.equals("en") ? 1 : 2); + int i2 = Algorithms.isEmpty(rhs) ? 0 : (rhs.equals("en") ? 1 : 2); + if (i1 != i2) { return i1 < i2 ? -1 : 1; } return mp.get(lhs).compareTo(mp.get(rhs)); @@ -438,26 +477,26 @@ public class ConfigureMapMenu { }); return lst.toArray(new String[lst.size()]); } - + public static String[] getMapNamesValues(Context ctx, String[] ids) { String[] translates = new String[ids.length]; - for(int i = 0; i < translates.length; i++) { - if(Algorithms.isEmpty(ids[i])) { - translates[i] = ctx.getString(R.string.local_map_names); + for (int i = 0; i < translates.length; i++) { + if (Algorithms.isEmpty(ids[i])) { + translates[i] = ctx.getString(R.string.local_map_names); } else { - translates[i] = ((OsmandApplication)ctx.getApplicationContext()).getLangTranslation(ids[i]); + translates[i] = ((OsmandApplication) ctx.getApplicationContext()).getLangTranslation(ids[i]); } } - + return translates; } - private void createProperties(List customRules, final int strId, String cat, - final ContextMenuAdapter adapter, final MapActivity activity) { + private void createProperties(List customRules, final int strId, String cat, + final ContextMenuAdapter adapter, final MapActivity activity) { final List ps = new ArrayList(); final List> prefs = new ArrayList>(); Iterator it = customRules.iterator(); - + while (it.hasNext()) { RenderingRuleProperty p = it.next(); if (cat.equals(p.getCategory()) && p.isBoolean()) { @@ -468,17 +507,20 @@ public class ConfigureMapMenu { it.remove(); } } - if(prefs.size() > 0) { + if (prefs.size() > 0) { final String descr = getDescription(prefs); - adapter.item(strId).description(descr). - layout(R.layout.drawer_list_doubleitem).listen(new OnContextMenuClick() { - + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(strId, activity) + .setDescription(descr) + .setLayout(R.layout.drawer_list_doubleitem) + .setListener(new OnContextMenuClick() { + @Override public boolean onContextMenuClick(ArrayAdapter a, int itemId, int pos, boolean isChecked) { showPreferencesDialog(adapter, a, pos, activity, activity.getString(strId), ps, prefs); return false; } - }).reg(); + }).createItem()); // createCustomRenderingProperties(adapter, activity, ps); } } @@ -496,26 +538,26 @@ public class ConfigureMapMenu { return descr; } - protected void showPreferencesDialog(final ContextMenuAdapter adapter, final ArrayAdapter a, final int pos, final MapActivity activity, - String category, List ps, final List> prefs) { + protected void showPreferencesDialog(final ContextMenuAdapter adapter, final ArrayAdapter a, final int pos, final MapActivity activity, + String category, List ps, final List> prefs) { AlertDialog.Builder bld = new AlertDialog.Builder(activity); boolean[] checkedItems = new boolean[prefs.size()]; for (int i = 0; i < prefs.size(); i++) { checkedItems[i] = prefs.get(i).get(); } - + final boolean[] tempPrefs = new boolean[prefs.size()]; for (int i = 0; i < prefs.size(); i++) { tempPrefs[i] = prefs.get(i).get(); } 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); String propertyName = SettingsActivity.getStringPropertyName(activity, p.getAttrName(), p.getName()); vals[i] = propertyName; } - + bld.setMultiChoiceItems(vals, checkedItems, new OnMultiChoiceClickListener() { @Override @@ -523,13 +565,13 @@ public class ConfigureMapMenu { tempPrefs[which] = isChecked; } }); - + bld.setTitle(category); - + bld.setNegativeButton(R.string.shared_string_cancel, null); - + 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++) { prefs.get(i).set(tempPrefs[i]); } @@ -537,9 +579,9 @@ public class ConfigureMapMenu { a.notifyDataSetInvalidated(); refreshMapComplete(activity); activity.getMapLayers().updateLayers(activity.getMapView()); - } + } }); - + bld.show(); } @@ -557,17 +599,17 @@ public class ConfigureMapMenu { } 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 + " %"; } - - - private void createCustomRenderingProperties(final ContextMenuAdapter adapter , final MapActivity activity, - List customRules ){ + + + private void createCustomRenderingProperties(final ContextMenuAdapter adapter, final MapActivity activity, + List customRules) { final OsmandMapTileView view = activity.getMapView(); for (final RenderingRuleProperty p : customRules) { if (p.getAttrName().equals(RenderingRuleStorageProperties.A_APP_MODE) || - p.getAttrName().equals(RenderingRuleStorageProperties.A_ENGINE_V1)){ + p.getAttrName().equals(RenderingRuleStorageProperties.A_ENGINE_V1)) { continue; } String propertyName = SettingsActivity.getStringPropertyName(view.getContext(), p.getAttrName(), @@ -578,26 +620,29 @@ public class ConfigureMapMenu { if (p.isBoolean()) { final OsmandSettings.CommonPreference pref = view.getApplication().getSettings() .getCustomRenderBooleanProperty(p.getAttrName()); - adapter.item(propertyName).listen(new OnContextMenuClick() { + adapter.addItem(ContextMenuItem.createBuilder(propertyName) + .setListener(new OnContextMenuClick() { - @Override - public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { - pref.set(!pref.get()); - refreshMapComplete(activity); - return false; - } - }).selected(pref.get() ? 1 : 0).reg(); + @Override + public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { + pref.set(!pref.get()); + refreshMapComplete(activity); + return false; + } + }) + .setSelected(pref.get()) + .createItem()); } else { final OsmandSettings.CommonPreference pref = view.getApplication().getSettings() .getCustomRenderProperty(p.getAttrName()); String descr; - if(!Algorithms.isEmpty(pref.get())) { + if (!Algorithms.isEmpty(pref.get())) { descr = SettingsActivity.getStringPropertyValue(activity, pref.get()); } else { descr = SettingsActivity.getStringPropertyValue(view.getContext(), p.getDefaultValueDescription()); } - adapter.item(propertyName).listen(new OnContextMenuClick() { + adapter.addItem(ContextMenuItem.createBuilder(propertyName).setListener(new OnContextMenuClick() { @Override 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]; possibleValuesString[0] = SettingsActivity.getStringPropertyValue(view.getContext(), - p.getDefaultValueDescription()); + p.getDefaultValueDescription()); for (int j = 0; j < p.getPossibleValues().length; j++) { possibleValuesString[j + 1] = SettingsActivity.getStringPropertyValue(view.getContext(), @@ -624,7 +669,7 @@ public class ConfigureMapMenu { b.setSingleChoiceItems(possibleValuesString, i, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - if(which == 0) { + if (which == 0) { pref.set(""); } else { pref.set(p.getPossibleValues()[which - 1]); @@ -638,7 +683,7 @@ public class ConfigureMapMenu { b.show(); return false; } - }).description(descr).layout(R.layout.drawer_list_doubleitem).reg(); + }).setDescription(descr).setLayout(R.layout.drawer_list_doubleitem).createItem()); } } } diff --git a/OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java index e94a3f264e..13112fce97 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java @@ -5,6 +5,7 @@ import android.view.View; import android.widget.ArrayAdapter; import net.osmand.plus.ContextMenuAdapter; +import net.osmand.plus.ContextMenuItem; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; @@ -111,12 +112,17 @@ public class RasterMapMenu { return false; } }; - int selectedCode = selected ? 1 : 0; 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) { - contextMenuAdapter.item(mapTypeString).listen(l).layout(R.layout.two_line_list_item) - .description(mapTypeDescr).reg(); + contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(mapTypeString, mapActivity) + .setListener(l) + .setLayout(R.layout.two_line_list_item) + .setDescription(mapTypeDescr).createItem()); ContextMenuAdapter.OnIntegerValueChangedListener integerListener = new ContextMenuAdapter.OnIntegerValueChangedListener() { @Override @@ -127,20 +133,25 @@ public class RasterMapMenu { } }; // android:max="255" in layout is expected - contextMenuAdapter.item(mapTypeStringTransparency) - .layout(R.layout.progress_list_item) - .colorIcon(R.drawable.ic_action_opacity) - .progress(mapTransparencyPreference.get()) - .listen(l) - .listenInteger(integerListener).reg(); + contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(mapTypeStringTransparency, mapActivity) + .setLayout(R.layout.progress_list_item) + .setColorIcon(R.drawable.ic_action_opacity) + .setProgress(mapTransparencyPreference.get()) + .setListener(l) + .setIntegerListener(integerListener).createItem()); if (type == OsmandRasterMapsPlugin.RasterMapType.UNDERLAY) { - contextMenuAdapter.item(R.string.show_polygons).listen(l) - .selected(hidePolygonsPref.get() ? 0 : 1).reg(); + contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.show_polygons, mapActivity) + .setListener(l) + .setSelected(hidePolygonsPref.get()).createItem()); } Boolean transparencySwitchState = settings.SHOW_LAYER_TRANSPARENCY_SEEKBAR.get() && mapLayers.getMapControlsLayer().isTransparencyBarInitialized(); - contextMenuAdapter.item(R.string.show_transparency_seekbar).listen(l) - .selected(transparencySwitchState ? 1 : 0).reg(); + contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.show_transparency_seekbar, mapActivity) + .setListener(l) + .setSelected(transparencySwitchState).createItem()); } } diff --git a/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java b/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java index f3b7629a2e..65dbd05d88 100644 --- a/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java +++ b/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java @@ -34,6 +34,7 @@ import net.osmand.data.RotatedTileBox; import net.osmand.plus.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; +import net.osmand.plus.ContextMenuItem; import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.Route; @@ -640,7 +641,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin { } @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) { final WptPt p = (WptPt) o; boolean containsPoint = false; @@ -675,7 +676,10 @@ public class DistanceCalculatorPlugin extends OsmandPlugin { 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()); } } } diff --git a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java index 6b424e13ef..2b3f459ac2 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java @@ -40,6 +40,7 @@ import net.osmand.IndexConstants; import net.osmand.access.AccessibleToast; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; +import net.osmand.plus.ContextMenuItem; import net.osmand.plus.IconsCache; import net.osmand.plus.OsmandApplication; 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 || info.getType() == LocalIndexType.WIKI_DATA) { 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()) { - 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) { - 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) { @@ -588,16 +601,24 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement return true; } }; - optionsMenuAdapter.item(R.string.local_index_mi_reload) - .icon(R.drawable.ic_action_refresh_dark) - .listen(listener).position(1).reg(); - optionsMenuAdapter.item(R.string.shared_string_delete) - .icon(R.drawable.ic_action_delete_dark) - .listen(listener).position(2).reg(); - optionsMenuAdapter.item(R.string.local_index_mi_backup) - .listen(listener).position(3).reg(); - optionsMenuAdapter.item(R.string.local_index_mi_restore) - .listen(listener).position(4).reg(); + optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.local_index_mi_reload,getContext()) + .setIcon(R.drawable.ic_action_refresh_dark) + .setListener(listener) + .createItem()); + optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.shared_string_delete,getContext()) + .setIcon(R.drawable.ic_action_delete_dark) + .setListener(listener) + .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 //int max = getResources().getInteger(R.integer.abs__max_action_buttons); int max = 3; diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java index c94f636d1f..a49bc65601 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java @@ -23,6 +23,7 @@ import net.osmand.CallbackWithObject; import net.osmand.IndexConstants; import net.osmand.access.AccessibleToast; import net.osmand.plus.ContextMenuAdapter; +import net.osmand.plus.ContextMenuItem; import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXTrackAnalysis; @@ -207,8 +208,8 @@ public class GpxUiHelper { } s = s.replace('_', ' '); - adapter.item(s).selected(multipleChoice ? 0 : -1) - .colorIcon(R.drawable.ic_action_polygom_dark).reg(); + adapter.addItem(ContextMenuItem.createBuilder(s).setSelected(multipleChoice) + .setColorIcon(R.drawable.ic_action_polygom_dark).createItem()); //if there's some selected files - need to mark them as selected if (selectedGpxList != null) { @@ -223,12 +224,12 @@ public class GpxUiHelper { final ContextMenuAdapter adapter, int i, String fileName) { if (i == 0 && showCurrentTrack) { if (selectedGpxList.contains("")) { - adapter.setSelection(i, 1); + adapter.setSelection(i, true); } } else { for (String file : selectedGpxList) { if (file.endsWith(fileName)) { - adapter.setSelection(i, 1); + adapter.setSelection(i, true); break; } } @@ -303,15 +304,15 @@ public class GpxUiHelper { // } // tv.setCompoundDrawablePadding(padding); final CheckBox ch = ((CheckBox) v.findViewById(R.id.toggle_item)); - if (adapter.getSelection(position) == -1) { + if (adapter.getSelection(position) == null) { ch.setVisibility(View.INVISIBLE); } else { ch.setOnCheckedChangeListener(null); - ch.setChecked(adapter.getSelection(position) > 0); + ch.setChecked(adapter.getSelection(position)); ch.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override 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) { app.getSelectedGpxHelper().clearAllGpxFileToShow(); } - if (showCurrentGpx && adapter.getSelection(0) > 0) { + if (showCurrentGpx && adapter.getSelection(0)) { currentGPX = app.getSavingTrackHelper().getCurrentGpx(); } List s = new ArrayList<>(); for (int i = (showCurrentGpx ? 1 : 0); i < adapter.length(); i++) { - if (adapter.getSelection(i) > 0) { + if (adapter.getSelection(i)) { s.add(list.get(i)); } } @@ -360,7 +361,7 @@ public class GpxUiHelper { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { if (multipleChoice) { - adapter.setSelection(position, adapter.getSelection(position) > 0 ? 0 : 1); + adapter.setSelection(position, !adapter.getSelection(position)); listAdapter.notifyDataSetInvalidated(); } else { dlg.dismiss(); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index a3cb176297..7ba2ec92ca 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -555,7 +555,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL public void buttonMorePressed() { final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(mapActivity); 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); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java index 372ed6f84f..41eb776da9 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java @@ -23,6 +23,7 @@ import net.osmand.Location; import net.osmand.data.LatLon; import net.osmand.plus.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; +import net.osmand.plus.ContextMenuItem; import net.osmand.plus.GPXUtilities; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; @@ -215,7 +216,8 @@ public class RoutePreferencesMenu { String selectedValue = mapActivity.getMyApplication().getSettings().VOICE_PROVIDER.get(); entrieValues[k] = OsmandSettings.VOICE_PROVIDER_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)) { selected = k; } @@ -224,7 +226,7 @@ public class RoutePreferencesMenu { entries[k] = (s.contains("tts") ? mapActivity.getResources().getString(R.string.ttsvoice) + " " : "") + FileNameTranslationHelper.getVoiceName(mapActivity, s); entrieValues[k] = s; - adapter.item(entries[k]).reg(); + adapter.addItem(itemBuilder.setTitle(entries[k]).createItem()); if (s.equals(selectedValue)) { selected = k; } @@ -232,7 +234,7 @@ public class RoutePreferencesMenu { } entrieValues[k] = MORE_VALUE; 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); bld.setSingleChoiceItems(entries, selected, new DialogInterface.OnClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java index cf8fd160b6..2fa0154b5f 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java @@ -23,6 +23,7 @@ import net.osmand.ValueHolder; import net.osmand.plus.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; +import net.osmand.plus.ContextMenuItem; import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.NavigationService; import net.osmand.plus.OsmAndFormatter; @@ -140,13 +141,17 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { return true; } }; - adapter.item(R.string.context_menu_item_add_waypoint).colorIcon(R.drawable.ic_action_gnew_label_dark) - .listen(listener).reg(); + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.context_menu_item_add_waypoint, mapActivity) + .setColorIcon(R.drawable.ic_action_gnew_label_dark) + .setListener(listener).createItem()); if (selectedObj instanceof WptPt) { WptPt pt = (WptPt) selectedObj; if (app.getSelectedGpxHelper().getSelectedGPXFile(pt) != null) { - adapter.item(R.string.context_menu_item_edit_waypoint).colorIcon(R.drawable.ic_action_edit_dark) - .listen(listener).reg(); + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.context_menu_item_edit_waypoint, mapActivity) + .setColorIcon(R.drawable.ic_action_edit_dark) + .setListener(listener).createItem()); } } } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java index 83e468ba40..3cccf990d2 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java @@ -36,6 +36,7 @@ import net.osmand.IndexConstants; import net.osmand.access.AccessibleToast; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; +import net.osmand.plus.ContextMenuItem; import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXTrackAnalysis; @@ -348,12 +349,13 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { return true; } }; - optionsMenuAdapter.item(R.string.shared_string_show_on_map).icon(R.drawable.ic_show_on_map) - .listen(listener).reg(); - optionsMenuAdapter.item(R.string.shared_string_delete) - .icon(R.drawable.ic_action_delete_dark).listen(listener).reg(); - optionsMenuAdapter.item(R.string.local_index_mi_reload) - .icon(R.drawable.ic_action_refresh_dark).listen(listener).reg(); + optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_show_on_map, getActivity()) + .setIcon(R.drawable.ic_show_on_map) + .setListener(listener).createItem()); + optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_delete, getActivity()) + .setIcon(R.drawable.ic_action_delete_dark).setListener(listener).createItem()); + 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); for (int j = 0; j < optionsMenuAdapter.length(); j++) { final MenuItem item; diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index f7fa3c381a..68d6ca1746 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -21,6 +21,7 @@ import net.osmand.osm.PoiType; import net.osmand.osm.edit.Node; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; +import net.osmand.plus.ContextMenuItem; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; @@ -216,15 +217,32 @@ public class OsmEditingPlugin extends OsmandPlugin { isEditable = !amenity.getType().isWiki() && !poiType.isNotEditableOsm(); } if (isEditable) { - adapter.item(R.string.poi_context_menu_modify).colorIcon(R.drawable.ic_action_edit_dark).listen(listener).position(1).reg(); - adapter.item(R.string.poi_context_menu_delete).colorIcon(R.drawable.ic_action_delete_dark).listen(listener).position(2).reg(); + adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.poi_context_menu_modify, mapActivity) + .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) { - adapter.item(R.string.poi_context_menu_modify_osm_change) - .colorIcon(R.drawable.ic_action_edit_dark).listen(listener).position(1).reg(); + adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.poi_context_menu_modify_osm_change, mapActivity) + .setColorIcon(R.drawable.ic_action_edit_dark) + .setListener(listener) + .setPosition(1) + .createItem()); } 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 @@ -239,8 +257,10 @@ public class OsmEditingPlugin extends OsmandPlugin { @Override 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) - .colorIcon(R.drawable.ic_action_bug_dark).listen(new OnContextMenuClick() { + adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_osm_bugs, mapActivity) + .setSelected(settings.SHOW_OSM_BUGS.get()) + .setColorIcon(R.drawable.ic_action_bug_dark) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { @@ -250,7 +270,9 @@ public class OsmEditingPlugin extends OsmandPlugin { } return true; } - }).position(16).reg(); + }) + .setPosition(16) + .createItem()); } @@ -262,16 +284,16 @@ public class OsmEditingPlugin extends OsmandPlugin { @Override public void contextMenuFragment(final Activity la, final Fragment fragment, final Object info, ContextMenuAdapter adapter) { if (fragment instanceof AvailableGPXFragment) { - adapter.item(R.string.local_index_mi_upload_gpx) - .colorIcon(R.drawable.ic_action_export) - .listen(new OnContextMenuClick() { + adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_upload_gpx, la) + .setColorIcon(R.drawable.ic_action_export) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { sendGPXFiles(la, (AvailableGPXFragment) fragment, (GpxInfo) info); return true; } - }).reg(); + }).createItem()); } } @@ -279,9 +301,9 @@ public class OsmEditingPlugin extends OsmandPlugin { public void optionsMenuFragment(final Activity activity, final Fragment fragment, ContextMenuAdapter optionsMenuAdapter) { if (fragment instanceof AvailableGPXFragment) { final AvailableGPXFragment f = ((AvailableGPXFragment) fragment); - optionsMenuAdapter.item(R.string.local_index_mi_upload_gpx) - .icon(R.drawable.ic_action_export) - .listen(new OnContextMenuClick() { + optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_upload_gpx, activity) + .setIcon(R.drawable.ic_action_export) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { @@ -296,7 +318,9 @@ public class OsmEditingPlugin extends OsmandPlugin { }); return true; } - }).position(5).reg(); + }) + .setPosition(5) + .createItem()); } } diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java index d6cfc9403d..c681b18c93 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoPlugin.java @@ -13,6 +13,7 @@ import net.osmand.PlatformUtil; import net.osmand.plus.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; +import net.osmand.plus.ContextMenuItem; import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.WptPt; @@ -274,15 +275,18 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor { @Override public void registerOptionsMenuItems(final MapActivity mapActivity, ContextMenuAdapter helper) { - helper.item(R.string.osmo_groups).colorIcon(R.drawable.ic_osmo_dark).position(6) - .listen(new OnContextMenuClick() { + helper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.osmo_groups, mapActivity) + .setColorIcon(R.drawable.ic_osmo_dark) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { Intent intent = new Intent(mapActivity, OsMoGroupsActivity.class); mapActivity.startActivity(intent); return true; } - }).reg(); + }) + .setPosition(6) + .createItem()); } diff --git a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java index 6c81b908f6..19ad36e18b 100644 --- a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java +++ b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java @@ -19,6 +19,7 @@ import net.osmand.data.LatLon; import net.osmand.plus.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; +import net.osmand.plus.ContextMenuItem; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; @@ -226,9 +227,11 @@ public class ParkingPositionPlugin extends OsmandPlugin { return true; } }; - adapter.item(R.string.context_menu_item_add_parking_point) - .colorIcon(R.drawable.ic_action_parking_dark).listen(addListener).reg(); - + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.context_menu_item_add_parking_point, mapActivity) + .setColorIcon(R.drawable.ic_action_parking_dark) + .setListener(addListener) + .createItem()); } /** diff --git a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java index 8bf8c9395e..840ed58608 100644 --- a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java @@ -24,6 +24,7 @@ import net.osmand.map.TileSourceManager; import net.osmand.map.TileSourceManager.TileSourceTemplate; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; +import net.osmand.plus.ContextMenuItem; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; @@ -254,12 +255,22 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { String overlayMapDescr = settings.MAP_OVERLAY.get(); 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) - .colorIcon(R.drawable.ic_layer_top_dark).listen(listener).position(14).reg(); + adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_overlay, mapActivity) + .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(); 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) - .colorIcon(R.drawable.ic_layer_bottom_dark).listen(listener).position(15).reg(); + adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_underlay, mapActivity) + .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; } }; - adapter.item(R.string.context_menu_item_update_map).colorIcon(R.drawable.ic_action_refresh_dark) - .listen(listener).reg(); - adapter.item(R.string.shared_string_download_map).colorIcon(R.drawable.ic_action_import) - .listen(listener).reg(); + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.context_menu_item_update_map, mapActivity) + .setColorIcon(R.drawable.ic_action_refresh_dark) + .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()); } } diff --git a/OsmAnd/src/net/osmand/plus/routepointsnavigation/RoutePointsLayer.java b/OsmAnd/src/net/osmand/plus/routepointsnavigation/RoutePointsLayer.java index 59d315298e..9b9786f347 100644 --- a/OsmAnd/src/net/osmand/plus/routepointsnavigation/RoutePointsLayer.java +++ b/OsmAnd/src/net/osmand/plus/routepointsnavigation/RoutePointsLayer.java @@ -8,6 +8,7 @@ import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.RotatedTileBox; import net.osmand.plus.ContextMenuAdapter; +import net.osmand.plus.ContextMenuItem; import net.osmand.plus.GPXUtilities; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; @@ -83,7 +84,7 @@ public class RoutePointsLayer extends OsmandMapLayer implements ContextMenuLaye } @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){ final GPXUtilities.WptPt point = (GPXUtilities.WptPt) o; ContextMenuAdapter.OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() { @@ -109,23 +110,33 @@ public class RoutePointsLayer extends OsmandMapLayer implements ContextMenuLaye }; if (plugin.getCurrentRoute().getPointStatus(point)){ - adapter.item(R.string.mark_as_not_visited).colorIcon( - R.drawable.ic_action_gremove_dark).listen(listener).reg(); + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.mark_as_not_visited, mapActivity) + .setColorIcon(R.drawable.ic_action_gremove_dark) + .setListener(listener) + .createItem()); } else { - adapter.item(R.string.mark_as_visited).colorIcon( - R.drawable.ic_action_done).listen(listener).reg(); + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.mark_as_visited, mapActivity) + .setColorIcon(R.drawable.ic_action_done) + .setListener(listener) + .createItem()); } RoutePointsPlugin.RoutePoint routePoint = plugin.getCurrentRoute().getRoutePointFromWpt(point); if (routePoint != null) { if (routePoint.isNextNavigate) { - adapter.item(R.string.navigate_to_next) - .colorIcon(R.drawable.ic_action_gnext_dark).listen(listener) - .reg(); + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.navigate_to_next, mapActivity) + .setColorIcon(R.drawable.ic_action_gnext_dark) + .setListener(listener) + .createItem()); } else { - adapter.item(R.string.mark_as_current) - .colorIcon(R.drawable.ic_action_signpost_dark) - .listen(listener).reg(); + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.mark_as_current, mapActivity) + .setColorIcon(R.drawable.ic_action_signpost_dark) + .setListener(listener) + .createItem()); } } } diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java index 59c8b2ad55..8d14fc8e3b 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java @@ -6,6 +6,7 @@ import android.widget.ArrayAdapter; import net.osmand.plus.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; +import net.osmand.plus.ContextMenuItem; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; @@ -114,8 +115,14 @@ public class SRTMPlugin extends OsmandPlugin { return true; } }; - adapter.item(R.string.layer_hillshade).selected(HILLSHADE.get()? 1 : 0) - .colorIcon(R.drawable.ic_action_hillshade_dark).listen(listener).position(13).layout(R.layout.drawer_list_item).reg(); + adapter.addItem(new ContextMenuItem.ItemBuilder() + .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 diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index daf3283f5f..c6c681ba66 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -18,6 +18,7 @@ import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.RotatedTileBox; import net.osmand.plus.ContextMenuAdapter; +import net.osmand.plus.ContextMenuItem; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MapContextMenu; @@ -131,7 +132,7 @@ public class ContextMenuLayer extends OsmandMapLayer { } @Override - public void populateObjectContextMenu(LatLon latLon, Object o, ContextMenuAdapter adapter) { + public void populateObjectContextMenu(LatLon latLon, Object o, ContextMenuAdapter adapter, MapActivity mapActivity) { if (menu.hasHiddenBottomInfo()) { ContextMenuAdapter.OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() { @Override @@ -142,9 +143,10 @@ public class ContextMenuLayer extends OsmandMapLayer { return true; } }; - adapter.item(R.string.shared_string_show_description) - .colorIcon(R.drawable.ic_action_note_dark).listen(listener) - .reg(); + adapter.addItem(new ContextMenuItem.ItemBuilder() + .setTitleId(R.string.shared_string_show_description, activity) + .setColorIcon(R.drawable.ic_action_note_dark).setListener(listener) + .createItem()); } } diff --git a/OsmAnd/src/net/osmand/plus/views/ImpassableRoadsLayer.java b/OsmAnd/src/net/osmand/plus/views/ImpassableRoadsLayer.java index c24021d753..9e870f8d5e 100644 --- a/OsmAnd/src/net/osmand/plus/views/ImpassableRoadsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ImpassableRoadsLayer.java @@ -13,6 +13,7 @@ import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.RotatedTileBox; import net.osmand.plus.ContextMenuAdapter; +import net.osmand.plus.ContextMenuItem; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.routing.RoutingHelper; @@ -160,7 +161,7 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements ContextMenuL } @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 && (routingHelper.isRoutePlanningMode() || routingHelper.isFollowingMode())) { @@ -176,8 +177,10 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements ContextMenuL } }; - adapter.item(R.string.avoid_road).colorIcon( - R.drawable.ic_action_road_works_dark).listen(listener).reg(); + adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.avoid_road, activity) + .setColorIcon(R.drawable.ic_action_road_works_dark) + .setListener(listener) + .createItem()); } } } diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java index 2ca444ef8c..52ce57ee8e 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java @@ -12,6 +12,7 @@ import net.osmand.data.QuadRect; import net.osmand.data.QuadTree; import net.osmand.data.RotatedTileBox; import net.osmand.plus.ContextMenuAdapter; +import net.osmand.plus.activities.MapActivity; import net.osmand.util.MapAlgorithms; import java.util.ArrayList; @@ -37,7 +38,7 @@ public abstract class OsmandMapLayer { public void onRetainNonConfigurationInstance(Map 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) { diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java index 12087c52ea..7ea56c5711 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java @@ -11,6 +11,7 @@ import android.widget.LinearLayout; import net.osmand.plus.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; +import net.osmand.plus.ContextMenuItem; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.MapMarkersMode; 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); } if (settings.USE_MAP_MARKERS.get()) { - cm.item(R.string.map_markers).description(settings.MAP_MARKERS_MODE.get().toHumanString(map)).listen(new OnContextMenuClick() { - @Override - public boolean onContextMenuClick(final ArrayAdapter ad, int itemId, final int pos, boolean isChecked) { - 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() { + cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_markers, map) + .setDescription(settings.MAP_MARKERS_MODE.get().toHumanString(map)) + .setListener(new OnContextMenuClick() { @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()); + public boolean onContextMenuClick(final ArrayAdapter ad, int itemId, final int pos, boolean isChecked) { + 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 + 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(); - if (mil != null) { - mil.recreateControls(); - } - map.refreshMap(); - dialog.dismiss(); - cm.setItemDescription(pos, settings.MAP_MARKERS_MODE.get().toHumanString(map)); - ad.notifyDataSetChanged(); + }); + bld.show(); + return false; } - }); - bld.show(); - return false; - } - }).layout(R.layout.list_item_text_button).reg(); + }).setLayout(R.layout.list_item_text_button).createItem()); } } - private void addControlId(final MapActivity map, ContextMenuAdapter cm, int stringId, OsmandPreference pref) { - cm.item(stringId).selected(pref.get() ? 1 : 0) -// .icons(r.drawableDark, r.drawableLight) - .listen(new ApearanceOnContextMenuClick(pref, map)).reg(); + private void addControlId(final MapActivity map, ContextMenuAdapter cm, + @StringRes int stringId, OsmandPreference pref) { + cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(stringId, map) + .setSelected(pref.get()) + .setListener(new ApearanceOnContextMenuClick(pref, map)).createItem()); } class ApearanceOnContextMenuClick implements OnContextMenuClick { @@ -360,13 +364,16 @@ public class MapWidgetRegistry { 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); 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); } - 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); } @@ -393,11 +400,11 @@ public class MapWidgetRegistry { if ("map_marker_1st".equals(r.key) || "map_marker_2nd".equals(r.key)) { continue; } - adapter.item(r.messageId) - .selected(r.visibleCollapsed(mode) || r.visible(mode) ? 1 : 0) - .colorIcon(r.drawableMenu) - .secondaryIconColor(R.drawable.ic_action_additional_option) - .listen(new OnContextMenuClick() { + adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(r.messageId, map) + .setSelected(r.visibleCollapsed(mode) || r.visible(mode)) + .setColorIcon(r.drawableMenu) + .setSecondaryLightIcon(R.drawable.ic_action_additional_option) + .setListener(new OnContextMenuClick() { @Override public boolean onContextMenuClick(ArrayAdapter a, int itemId, int pos, boolean isChecked) { changeVisibility(r); @@ -406,12 +413,11 @@ public class MapWidgetRegistry { mil.recreateControls(); } 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(); return false; } - }) - .reg(); + }).createItem()); adapter.setItemName(adapter.length() - 1, getText(map, mode, r)); } } @@ -492,7 +498,8 @@ public class MapWidgetRegistry { public ContextMenuAdapter getViewConfigureMenuAdapter(final MapActivity map) { final ContextMenuAdapter cm = new ContextMenuAdapter(map); 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() { @Override