From 512a178655ff2c636485a0b306e78a57d1423e80 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 23 Feb 2018 18:26:52 +0200 Subject: [PATCH] Revert plugins reordering; add "order" field to context menu item for sorting; create right order for items in the additional actions context menu --- .../net/osmand/plus/ContextMenuAdapter.java | 17 ++++++++++ .../src/net/osmand/plus/ContextMenuItem.java | 18 ++++++++-- OsmAnd/src/net/osmand/plus/OsmandPlugin.java | 10 +++--- .../plus/activities/MapActivityActions.java | 33 ++++++++++--------- .../audionotes/AudioVideoNotesPlugin.java | 10 ++++++ .../osmand/plus/osmedit/OsmEditingPlugin.java | 20 +++++++++-- .../parkingpoint/ParkingPositionPlugin.java | 6 ++++ .../rastermaps/OsmandRasterMapsPlugin.java | 8 +++++ .../osmand/plus/views/ContextMenuLayer.java | 2 ++ 9 files changed, 99 insertions(+), 25 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java index b011f05e68..ba2a6d89b0 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java @@ -30,6 +30,8 @@ import net.osmand.plus.dialogs.HelpArticleDialogFragment; import org.apache.commons.logging.Log; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -79,6 +81,21 @@ public class ContextMenuAdapter { this.changeAppModeListener = changeAppModeListener; } + public void sortItemsByOrder() { + Collections.sort(items, new Comparator() { + @Override + public int compare(ContextMenuItem item1, ContextMenuItem item2) { + int order1 = item1.getOrder(); + int order2 = item2.getOrder(); + if (order1 < order2) { + return -1; + } else if (order1 == order2) { + return 0; + } + return 1; + } + }); + } public ArrayAdapter createListAdapter(final Activity activity, final boolean lightTheme) { final int layoutId = DEFAULT_LAYOUT_ID; diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuItem.java b/OsmAnd/src/net/osmand/plus/ContextMenuItem.java index 2cc8373199..f8f4c92fc6 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuItem.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuItem.java @@ -30,6 +30,7 @@ public class ContextMenuItem { private final boolean clickable; private final boolean skipPaintingWithoutColor; private final int pos; + private final int order; private String description; private final ContextMenuAdapter.ItemClickListener itemClickListener; private final ContextMenuAdapter.OnIntegerValueChangedListener integerListener; @@ -49,7 +50,9 @@ public class ContextMenuItem { boolean loading, boolean category, boolean clickable, - boolean skipPaintingWithoutColor, int pos, + boolean skipPaintingWithoutColor, + int pos, + int order, String description, ContextMenuAdapter.ItemClickListener itemClickListener, ContextMenuAdapter.OnIntegerValueChangedListener integerListener, @@ -70,6 +73,7 @@ public class ContextMenuItem { this.clickable = clickable; this.skipPaintingWithoutColor = skipPaintingWithoutColor; this.pos = pos; + this.order = order; this.description = description; this.itemClickListener = itemClickListener; this.integerListener = integerListener; @@ -146,6 +150,10 @@ public class ContextMenuItem { return pos; } + public int getOrder() { + return order; + } + public String getDescription() { return description; } @@ -232,6 +240,7 @@ public class ContextMenuItem { private boolean mIsCategory = false; private boolean mIsClickable = true; private int mPosition = -1; + private int mOrder = -1; private String mDescription = null; private ContextMenuAdapter.ItemClickListener mItemClickListener = null; private ContextMenuAdapter.OnIntegerValueChangedListener mIntegerListener = null; @@ -305,6 +314,11 @@ public class ContextMenuItem { return this; } + public ItemBuilder setOrder(int order) { + mOrder = order; + return this; + } + public ItemBuilder setDescription(String description) { mDescription = description; return this; @@ -352,7 +366,7 @@ public class ContextMenuItem { public ContextMenuItem createItem() { return new ContextMenuItem(mTitleId, mTitle, mIcon, mColorRes, mSecondaryIcon, mSelected, mProgress, mLayout, mLoading, mIsCategory, mIsClickable, mSkipPaintingWithoutColor, - mPosition, mDescription, mItemClickListener, mIntegerListener, mProgressListener, + mPosition, mOrder, mDescription, mItemClickListener, mIntegerListener, mProgressListener, mHideDivider, mMinHeight, mTag); } } diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index 43532cc2a0..4b6c4ac09e 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -134,22 +134,20 @@ public abstract class OsmandPlugin { allPlugins.add(new MapillaryPlugin(app)); enabledPlugins.add(MapillaryPlugin.ID); - // plugins with additional actions for context menu in right order: - allPlugins.add(new AudioVideoNotesPlugin(app)); - allPlugins.add(new OsmEditingPlugin(app)); - checkMarketPlugin(app, new ParkingPositionPlugin(app), false, ParkingPositionPlugin.PARKING_PLUGIN_COMPONENT, null); allPlugins.add(new OsmandRasterMapsPlugin(app)); - allPlugins.add(new OsmandMonitoringPlugin(app)); // allPlugins.add(new OsMoPlugin(app)); checkMarketPlugin(app, new SRTMPlugin(app), true, SRTM_PLUGIN_COMPONENT_PAID, SRTM_PLUGIN_COMPONENT); - // ? questionable - definitely not market plugin + // ? questionable - definitely not market plugin // checkMarketPlugin(app, new TouringViewPlugin(app), false, TouringViewPlugin.COMPONENT, null); checkMarketPlugin(app, new NauticalMapsPlugin(app), false, NauticalMapsPlugin.COMPONENT, null); checkMarketPlugin(app, new SkiMapsPlugin(app), false, SkiMapsPlugin.COMPONENT, null); + allPlugins.add(new AudioVideoNotesPlugin(app)); + checkMarketPlugin(app, new ParkingPositionPlugin(app), false, ParkingPositionPlugin.PARKING_PLUGIN_COMPONENT, null); allPlugins.add(new AccessibilityPlugin(app)); + allPlugins.add(new OsmEditingPlugin(app)); allPlugins.add(new OsmandDevelopmentPlugin(app)); activatePlugins(app, enabledPlugins); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 849bec45d9..57d55c01da 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -80,6 +80,18 @@ public class MapActivityActions implements DialogProvider { public static final String KEY_ZOOM = "zoom"; + // Constants for determining the order of items in the additional actions context menu + // In the case of changing values boundaries for plugin, change them in the plugin too + public static final int DIRECTIONS_FROM_ITEM_ORDER = 1000; + public static final int SEARCH_NEAR_ITEM_ORDER = 2000; + public static final int CHANGE_POSITION_ITEM_ORDER = 3000; + // Orders from 4000 to 4999 are for AudioVideoNotesPlugin + // Orders from 7000 to 7999 are for OsmEditingPlugin + public static final int EDIT_GPX_WAYPOINT_ITEM_ORDER = 9000; + public static final int ADD_GPX_WAYPOINT_ITEM_ORDER = 9000; + // Orders from 10000 to 10999 are for ParkingPositionPlugin + // Orders from 12000 to 12999 are for OsmAndRasterMapsPlugin + private static final int DIALOG_ADD_FAVORITE = 100; private static final int DIALOG_REPLACE_FAVORITE = 101; private static final int DIALOG_ADD_WAYPOINT = 102; @@ -277,12 +289,12 @@ public class MapActivityActions implements DialogProvider { adapter.addItem(itemBuilder .setTitleId(R.string.context_menu_item_directions_from, mapActivity) .setIcon(R.drawable.ic_action_route_direction_from_here) - .setPosition(0) + .setOrder(DIRECTIONS_FROM_ITEM_ORDER) .createItem()); adapter.addItem(itemBuilder .setTitleId(R.string.context_menu_item_search, mapActivity) .setIcon(R.drawable.ic_action_search_dark) - .setPosition(1) + .setOrder(SEARCH_NEAR_ITEM_ORDER) .createItem()); OsmandPlugin.registerMapContextMenu(mapActivity, latitude, longitude, adapter, selectedObj); @@ -304,17 +316,19 @@ public class MapActivityActions implements DialogProvider { adapter.addItem(new ContextMenuItem.ItemBuilder() .setTitleId(R.string.context_menu_item_edit_waypoint, mapActivity) .setIcon(R.drawable.ic_action_edit_dark) - .setPosition(getPositionForGpxAction(adapter)) + .setOrder(EDIT_GPX_WAYPOINT_ITEM_ORDER) .setListener(listener).createItem()); } else if (!getMyApplication().getSelectedGpxHelper().getSelectedGPXFiles().isEmpty() || (OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null)) { adapter.addItem(new ContextMenuItem.ItemBuilder() .setTitleId(R.string.context_menu_item_add_waypoint, mapActivity) .setIcon(R.drawable.ic_action_gnew_label_dark) - .setPosition(getPositionForGpxAction(adapter)) + .setOrder(ADD_GPX_WAYPOINT_ITEM_ORDER) .setListener(listener).createItem()); } + adapter.sortItemsByOrder(); + final ArrayAdapter listAdapter = adapter.createListAdapter(mapActivity, getMyApplication().getSettings().isLightContent()); @@ -348,17 +362,6 @@ public class MapActivityActions implements DialogProvider { actionsBottomSheetDialogFragment.show(mapActivity.getSupportFragmentManager(), AdditionalActionsBottomSheetDialogFragment.TAG); } - private int getPositionForGpxAction(ContextMenuAdapter adapter) { - for (int i = 0; i < adapter.length(); i++) { - int titleId = adapter.getItem(i).getTitleId(); - if (titleId == R.string.context_menu_item_add_parking_point - || titleId == R.string.context_menu_item_update_map) { - return i; - } - } - return adapter.length(); - } - public void setGPXRouteParams(GPXFile result) { if (result == null) { mapActivity.getRoutingHelper().setGpxParams(null); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index f811b6abc6..18936e44bc 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -103,6 +103,13 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { public static final int CAMERA_FOR_VIDEO_REQUEST_CODE = 101; public static final int CAMERA_FOR_PHOTO_REQUEST_CODE = 102; public static final int AUDIO_REQUEST_CODE = 103; + + // Constants for determining the order of items in the additional actions context menu + // Values boundaries: [4000; 4999] + private static final int TAKE_AUDIO_NOTE_ITEM_ORDER = 4100; + private static final int TAKE_VIDEO_NOTE_ITEM_ORDER = 4300; + private static final int TAKE_PHOTO_NOTE_ITEM_ORDER = 4500; + private static Method mRegisterMediaButtonEventReceiver; private static Method mUnregisterMediaButtonEventReceiver; private OsmandApplication app; @@ -661,6 +668,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.recording_context_menu_arecord, app) .setIcon(R.drawable.ic_action_micro_dark) + .setOrder(TAKE_AUDIO_NOTE_ITEM_ORDER) .setListener(new ContextMenuAdapter.ItemClickListener() { @Override @@ -672,6 +680,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { .createItem()); adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.recording_context_menu_vrecord, app) .setIcon(R.drawable.ic_action_video_dark) + .setOrder(TAKE_VIDEO_NOTE_ITEM_ORDER) .setListener(new ItemClickListener() { @Override @@ -683,6 +692,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { .createItem()); adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.recording_context_menu_precord, app) .setIcon(R.drawable.ic_action_photo_dark) + .setOrder(TAKE_PHOTO_NOTE_ITEM_ORDER) .setListener(new ItemClickListener() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index 9ae8f1160f..1e7ec0757d 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -48,6 +48,15 @@ import java.util.List; public class OsmEditingPlugin extends OsmandPlugin { private static final Log LOG = PlatformUtil.getLog(OsmEditingPlugin.class); private static final String ID = "osm.editing"; + + // Constants for determining the order of items in the additional actions context menu + // Values boundaries: [7000; 7999] + private static final int CREATE_POI_ITEM_ORDER = 7300; + private static final int MODIFY_POI_ITEM_ORDER = 7300; + private static final int MODIFY_OSM_CHANGE_ITEM_ORDER = 7300; + private static final int OPEN_OSM_NOTE_ITEM_ORDER = 7600; + private static final int MODIFY_OSM_NOTE_ITEM_ORDER = 7600; + private OsmandSettings settings; private OsmandApplication app; private OpenstreetmapsDbHelper dbpoi; @@ -205,27 +214,34 @@ public class OsmEditingPlugin extends OsmandPlugin { if (isEditable) { adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.poi_context_menu_modify, mapActivity) .setIcon(R.drawable.ic_action_edit_dark) + .setOrder(MODIFY_POI_ITEM_ORDER) .setListener(listener) .createItem()); } else if (selectedObj instanceof OpenstreetmapPoint && ((OpenstreetmapPoint) selectedObj).getAction() != Action.DELETE) { adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.poi_context_menu_modify_osm_change, mapActivity) .setIcon(R.drawable.ic_action_edit_dark) + .setOrder(MODIFY_OSM_CHANGE_ITEM_ORDER) .setListener(listener) .createItem()); } else { adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_create_poi, mapActivity) .setIcon(R.drawable.ic_action_plus_dark) + .setOrder(CREATE_POI_ITEM_ORDER) .setListener(listener) .createItem()); } if (selectedObj instanceof OsmNotesPoint) { adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_modify_note, mapActivity) .setIcon(R.drawable.ic_action_edit_dark) - .setListener(listener).createItem()); + .setOrder(MODIFY_OSM_NOTE_ITEM_ORDER) + .setListener(listener) + .createItem()); } else { adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_open_note, mapActivity) .setIcon(R.drawable.ic_action_bug_dark) - .setListener(listener).createItem()); + .setOrder(OPEN_OSM_NOTE_ITEM_ORDER) + .setListener(listener) + .createItem()); } } diff --git a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java index fcdff4b15c..c0b1c93986 100644 --- a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java +++ b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java @@ -51,6 +51,11 @@ public class ParkingPositionPlugin extends OsmandPlugin { public final static String PARKING_TIME = "parking_limit_time"; //$//$NON-NLS-1$ public final static String PARKING_START_TIME = "parking_time"; //$//$NON-NLS-1$ public final static String PARKING_EVENT_ADDED = "parking_event_added"; //$//$NON-NLS-1$ + + // Constants for determining the order of items in the additional actions context menu + // Values boundaries: [10000; 10999] + private static final int MARK_AS_PARKING_POS_ITEM_ORDER = 10500; + private LatLon parkingPosition; private OsmandApplication app; @@ -228,6 +233,7 @@ public class ParkingPositionPlugin extends OsmandPlugin { adapter.addItem(new ContextMenuItem.ItemBuilder() .setTitleId(R.string.context_menu_item_add_parking_point, mapActivity) .setIcon(R.drawable.ic_action_parking_dark) + .setOrder(MARK_AS_PARKING_POS_ITEM_ORDER) .setListener(addListener) .createItem()); } diff --git a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java index 513f0f2a91..e080e8dfac 100644 --- a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java @@ -48,6 +48,12 @@ import java.util.Map; public class OsmandRasterMapsPlugin extends OsmandPlugin { public static final String ID = "osmand.rastermaps"; + + // Constants for determining the order of items in the additional actions context menu + // Values boundaries: [12000; 12999] + private static final int UPDATE_MAP_ITEM_ORDER = 12300; + private static final int DOWNLOAD_MAP_ITEM_ORDER = 12600; + private OsmandSettings settings; private OsmandApplication app; @@ -361,10 +367,12 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { adapter.addItem(new ContextMenuItem.ItemBuilder() .setTitleId(R.string.context_menu_item_update_map, mapActivity) .setIcon(R.drawable.ic_action_refresh_dark) + .setOrder(UPDATE_MAP_ITEM_ORDER) .setListener(listener).createItem()); adapter.addItem(new ContextMenuItem.ItemBuilder() .setTitleId(R.string.shared_string_download_map, mapActivity) .setIcon(R.drawable.ic_action_import) + .setOrder(DOWNLOAD_MAP_ITEM_ORDER) .setListener(listener).createItem()); } } diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index b4a2bd7eca..8403db1b71 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -34,6 +34,7 @@ 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.activities.MapActivityActions; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu; import net.osmand.plus.render.MapRenderRepositories; @@ -247,6 +248,7 @@ public class ContextMenuLayer extends OsmandMapLayer { adapter.addItem(new ContextMenuItem.ItemBuilder() .setTitleId(R.string.change_markers_position, activity) .setIcon(R.drawable.ic_show_on_map) + .setOrder(MapActivityActions.CHANGE_POSITION_ITEM_ORDER) .setClickable(isObjectMoveable(o)) .setListener(listener) .createItem());