Merge pull request #9689 from osmandapp/configuring_context_menu
Fix #9533
This commit is contained in:
commit
904de1f7da
7 changed files with 42 additions and 35 deletions
|
@ -525,7 +525,7 @@ public abstract class OsmandPlugin {
|
|||
protected void registerLayerContextMenuActions(OsmandMapTileView mapView, ContextMenuAdapter adapter, MapActivity mapActivity) {
|
||||
}
|
||||
|
||||
protected void registerMapContextMenuActions(MapActivity mapActivity, double latitude, double longitude, ContextMenuAdapter adapter, Object selectedObj) {
|
||||
protected void registerMapContextMenuActions(MapActivity mapActivity, double latitude, double longitude, ContextMenuAdapter adapter, Object selectedObj, boolean configureMenu) {
|
||||
}
|
||||
|
||||
protected void registerOptionsMenuItems(MapActivity mapActivity, ContextMenuAdapter helper) {
|
||||
|
@ -791,9 +791,9 @@ public abstract class OsmandPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
public static void registerMapContextMenu(MapActivity map, double latitude, double longitude, ContextMenuAdapter adapter, Object selectedObj) {
|
||||
public static void registerMapContextMenu(MapActivity map, double latitude, double longitude, ContextMenuAdapter adapter, Object selectedObj, boolean configureMenu) {
|
||||
for (OsmandPlugin plugin : getEnabledPlugins()) {
|
||||
plugin.registerMapContextMenuActions(map, latitude, longitude, adapter, selectedObj);
|
||||
plugin.registerMapContextMenuActions(map, latitude, longitude, adapter, selectedObj, configureMenu);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -383,7 +383,7 @@ public class MapActivityActions implements DialogProvider {
|
|||
.setOrder(SEARCH_NEAR_ITEM_ORDER)
|
||||
.createItem());
|
||||
|
||||
OsmandPlugin.registerMapContextMenu(mapActivity, latitude, longitude, adapter, selectedObj);
|
||||
OsmandPlugin.registerMapContextMenu(mapActivity, latitude, longitude, adapter, selectedObj, configureMenu);
|
||||
|
||||
ItemClickListener listener = new ItemClickListener() {
|
||||
@Override
|
||||
|
|
|
@ -659,8 +659,8 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
|
|||
|
||||
@Override
|
||||
public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude,
|
||||
ContextMenuAdapter adapter, Object selectedObj) {
|
||||
if (isRecording()) {
|
||||
ContextMenuAdapter adapter, Object selectedObj, boolean configureMenu) {
|
||||
if (!configureMenu && isRecording()) {
|
||||
return;
|
||||
}
|
||||
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.recording_context_menu_arecord, app)
|
||||
|
|
|
@ -1070,8 +1070,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
for (OsmandMapLayer layer : mapActivity.getMapView().getLayers()) {
|
||||
layer.populateObjectContextMenu(latLon, getObject(), menuAdapter, mapActivity);
|
||||
}
|
||||
mapActivity.getMapActions().addActionsToAdapter(configure ? 0 : latLon.getLatitude(), configure ? 0 : latLon.getLongitude(), menuAdapter, getObject(), configure);
|
||||
}
|
||||
mapActivity.getMapActions().addActionsToAdapter(configure ? 0 : latLon.getLatitude(), configure ? 0 : latLon.getLongitude(), menuAdapter, configure ? null : getObject(), configure); }
|
||||
return menuAdapter;
|
||||
}
|
||||
|
||||
|
|
|
@ -219,7 +219,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
|
|||
final double latitude,
|
||||
final double longitude,
|
||||
ContextMenuAdapter adapter,
|
||||
final Object selectedObj) {
|
||||
final Object selectedObj, boolean configureMenu) {
|
||||
ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int resId, int pos, boolean isChecked, int[] viewCoordinates) {
|
||||
|
|
|
@ -230,7 +230,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
|
|||
@Override
|
||||
public void registerMapContextMenuActions(final MapActivity mapActivity,
|
||||
final double latitude, final double longitude,
|
||||
ContextMenuAdapter adapter, Object selectedObj) {
|
||||
ContextMenuAdapter adapter, Object selectedObj, boolean configureMenu) {
|
||||
|
||||
ItemClickListener addListener = new ItemClickListener() {
|
||||
@Override
|
||||
|
|
|
@ -400,37 +400,45 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
|
|||
@Override
|
||||
public void registerMapContextMenuActions(MapActivity mapActivity,
|
||||
final double latitude, final double longitude,
|
||||
ContextMenuAdapter adapter, Object selectedObj) {
|
||||
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
|
||||
if (mapActivity.getMapView().getMainLayer() instanceof MapTileLayer) {
|
||||
ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int resId, int pos, boolean isChecked, int[] viewCoordinates) {
|
||||
MapActivity mapActivity = mapActivityRef.get();
|
||||
if (mapActivity != null && !mapActivity.isFinishing()) {
|
||||
OsmandMapTileView mapView = mapActivity.getMapView();
|
||||
if (resId == R.string.context_menu_item_update_map) {
|
||||
mapActivity.getMapActions().reloadTile(mapView.getZoom(), latitude, longitude);
|
||||
} else if (resId == R.string.shared_string_download_map) {
|
||||
DownloadTilesDialog dlg = new DownloadTilesDialog(mapActivity, (OsmandApplication) mapActivity.getApplication(), mapView);
|
||||
dlg.openDialog();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
adapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||
ContextMenuAdapter adapter, Object selectedObj, boolean configureMenu) {
|
||||
boolean mapTileLayer = mapActivity.getMapView().getMainLayer() instanceof MapTileLayer;
|
||||
if (configureMenu || mapTileLayer) {
|
||||
ContextMenuItem.ItemBuilder updateMapItemBuilder = new ContextMenuItem.ItemBuilder()
|
||||
.setTitleId(R.string.context_menu_item_update_map, mapActivity)
|
||||
.setId(MAP_CONTEXT_MENU_UPDATE_MAP)
|
||||
.setIcon(R.drawable.ic_action_refresh_dark)
|
||||
.setOrder(UPDATE_MAP_ITEM_ORDER)
|
||||
.setListener(listener).createItem());
|
||||
adapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||
.setOrder(UPDATE_MAP_ITEM_ORDER);
|
||||
|
||||
ContextMenuItem.ItemBuilder downloadMapItemBuilder = new ContextMenuItem.ItemBuilder()
|
||||
.setTitleId(R.string.shared_string_download_map, mapActivity)
|
||||
.setId(MAP_CONTEXT_MENU_DOWNLOAD_MAP)
|
||||
.setIcon(R.drawable.ic_action_import)
|
||||
.setOrder(DOWNLOAD_MAP_ITEM_ORDER)
|
||||
.setListener(listener).createItem());
|
||||
.setOrder(DOWNLOAD_MAP_ITEM_ORDER);
|
||||
|
||||
if (mapTileLayer) {
|
||||
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
|
||||
ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int resId, int pos, boolean isChecked, int[] viewCoordinates) {
|
||||
MapActivity mapActivity = mapActivityRef.get();
|
||||
if (mapActivity != null && !mapActivity.isFinishing()) {
|
||||
OsmandMapTileView mapView = mapActivity.getMapView();
|
||||
if (resId == R.string.context_menu_item_update_map) {
|
||||
mapActivity.getMapActions().reloadTile(mapView.getZoom(), latitude, longitude);
|
||||
} else if (resId == R.string.shared_string_download_map) {
|
||||
DownloadTilesDialog dlg = new DownloadTilesDialog(mapActivity, (OsmandApplication) mapActivity.getApplication(), mapView);
|
||||
dlg.openDialog();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
updateMapItemBuilder.setListener(listener);
|
||||
downloadMapItemBuilder.setListener(listener);
|
||||
}
|
||||
|
||||
adapter.addItem(updateMapItemBuilder.createItem());
|
||||
adapter.addItem(downloadMapItemBuilder.createItem());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue