use of net.osmand.plus.ContextMenuAdapter in project Osmand by osmandapp.
the class DashboardOnMap method updateListAdapter.
private void updateListAdapter() {
listEmptyTextView.setVisibility(View.GONE);
listView.setEmptyView(null);
ContextMenuAdapter cm = null;
if (DashboardType.WAYPOINTS == visibleType || DashboardType.WAYPOINTS_FLAT == visibleType) {
StableArrayAdapter listAdapter = waypointDialogHelper.getWaypointsDrawerAdapter(true, deletedPoints, mapActivity, running, DashboardType.WAYPOINTS_FLAT == visibleType, nightMode);
OnItemClickListener listener = waypointDialogHelper.getDrawerItemClickListener(mapActivity, running, listAdapter);
setDynamicListItems(listView, listAdapter);
updateListAdapter(listAdapter, listener);
if (listAdapter.getObjects().size() == 0) {
listEmptyTextView.setText(mapActivity.getString(R.string.no_waypoints_found));
if (landscape) {
listView.setEmptyView(listEmptyTextView);
} else {
listEmptyTextView.setVisibility(View.VISIBLE);
}
}
} else {
if (visibleType == DashboardType.CONFIGURE_SCREEN) {
cm = mapActivity.getMapLayers().getMapWidgetRegistry().getViewConfigureMenuAdapter(mapActivity);
} else if (visibleType == DashboardType.CONFIGURE_MAP) {
cm = new ConfigureMapMenu().createListAdapter(mapActivity);
} else if (visibleType == DashboardType.LIST_MENU) {
cm = mapActivity.getMapActions().createMainOptionsMenu();
} else if (visibleType == DashboardType.ROUTE_PREFERENCES) {
RoutePreferencesMenu routePreferencesMenu = new RoutePreferencesMenu(mapActivity);
ArrayAdapter<LocalRoutingParameter> listAdapter = routePreferencesMenu.getRoutePreferencesDrawerAdapter(nightMode);
OnItemClickListener listener = routePreferencesMenu.getItemClickListener(listAdapter);
updateListAdapter(listAdapter, listener);
} else if (visibleType == DashboardType.UNDERLAY_MAP) {
cm = RasterMapMenu.createListAdapter(mapActivity, OsmandRasterMapsPlugin.RasterMapType.UNDERLAY);
} else if (visibleType == DashboardType.OVERLAY_MAP) {
cm = RasterMapMenu.createListAdapter(mapActivity, OsmandRasterMapsPlugin.RasterMapType.OVERLAY);
} else if (visibleType == DashboardType.CONTOUR_LINES) {
cm = ContourLinesMenu.createListAdapter(mapActivity);
} else if (visibleType == DashboardType.HILLSHADE) {
cm = HillshadeMenu.createListAdapter(mapActivity);
} else if (visibleType == DashboardType.OSM_NOTES) {
cm = OsmNotesMenu.createListAdapter(mapActivity);
}
if (cm != null) {
updateListAdapter(cm);
}
}
}
use of net.osmand.plus.ContextMenuAdapter in project Osmand by osmandapp.
the class ShowHidePoiAction method showSingleChoicePoiFilterDialog.
private void showSingleChoicePoiFilterDialog(final OsmandApplication app, final MapActivity activity, final Adapter filtersAdapter) {
final PoiFiltersHelper poiFilters = app.getPoiFilters();
final ContextMenuAdapter adapter = new ContextMenuAdapter();
final List<PoiUIFilter> list = new ArrayList<>();
for (PoiUIFilter f : poiFilters.getTopDefinedPoiFilters()) {
addFilterToList(adapter, list, f);
}
for (PoiUIFilter f : poiFilters.getSearchPoiFilters()) {
addFilterToList(adapter, list, f);
}
final ArrayAdapter<ContextMenuItem> listAdapter = adapter.createListAdapter(activity, app.getSettings().isLightContent());
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setAdapter(listAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String oldTitle = getTitle(filtersAdapter.filters);
filtersAdapter.addItem(list.get(which));
if (oldTitle.equals(title.getText().toString()) || title.getText().toString().equals(getName(activity))) {
String newTitle = getTitle(filtersAdapter.filters);
title.setText(newTitle);
}
}
});
builder.setTitle(R.string.show_poi_over_map);
builder.setNegativeButton(R.string.shared_string_dismiss, null);
final AlertDialog alertDialog = builder.create();
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button neutralButton = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL);
Drawable drawable = app.getIconsCache().getThemedIcon(R.drawable.ic_action_multiselect);
neutralButton.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
}
});
alertDialog.show();
}
use of net.osmand.plus.ContextMenuAdapter in project Osmand by osmandapp.
the class OsmandRasterMapsPlugin method registerLayerContextMenuActions.
@Override
public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) {
ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
int[] viewCoordinates = AndroidUtils.getCenterViewCoordinates(view);
if (itemId == R.string.layer_overlay) {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.OVERLAY_MAP, viewCoordinates);
return false;
} else if (itemId == R.string.layer_underlay) {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.UNDERLAY_MAP, viewCoordinates);
return false;
}
return true;
}
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
switch(itemId) {
case R.string.layer_overlay:
toggleUnderlayState(mapActivity, RasterMapType.OVERLAY, new OnMapSelectedCallback() {
@Override
public void onMapSelected(boolean canceled) {
ContextMenuItem item = adapter.getItem(pos);
String overlayMapDescr = settings.MAP_OVERLAY.get();
boolean hasOverlayDescription = overlayMapDescr != null;
overlayMapDescr = hasOverlayDescription ? overlayMapDescr : mapActivity.getString(R.string.shared_string_none);
item.setDescription(overlayMapDescr);
item.setSelected(hasOverlayDescription);
item.setColorRes(hasOverlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
}
});
return false;
case R.string.layer_underlay:
toggleUnderlayState(mapActivity, RasterMapType.UNDERLAY, new OnMapSelectedCallback() {
@Override
public void onMapSelected(boolean canceled) {
ContextMenuItem item = adapter.getItem(pos);
String underlayMapDescr = settings.MAP_UNDERLAY.get();
boolean hasUnderlayDescription = underlayMapDescr != null;
underlayMapDescr = hasUnderlayDescription ? underlayMapDescr : mapActivity.getString(R.string.shared_string_none);
item.setDescription(underlayMapDescr);
item.setSelected(hasUnderlayDescription);
item.setColorRes(hasUnderlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
final OsmandSettings.CommonPreference<Boolean> hidePolygonsPref = mapActivity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
hidePolygonsPref.set(hasUnderlayDescription);
RasterMapMenu.refreshMapComplete(mapActivity);
}
});
return false;
}
return true;
}
};
if (overlayLayer.getMap() == null) {
settings.MAP_OVERLAY.set(null);
settings.MAP_OVERLAY_PREVIOUS.set(null);
}
if (underlayLayer.getMap() == null) {
settings.MAP_UNDERLAY.set(null);
settings.MAP_UNDERLAY_PREVIOUS.set(null);
}
String overlayMapDescr = settings.MAP_OVERLAY.get();
boolean hasOverlayDescription = overlayMapDescr != null;
overlayMapDescr = hasOverlayDescription ? overlayMapDescr : mapActivity.getString(R.string.shared_string_none);
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_overlay, mapActivity).setDescription(overlayMapDescr).setSelected(hasOverlayDescription).setColor(hasOverlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_layer_top_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(listener).setPosition(14).createItem());
String underlayMapDescr = settings.MAP_UNDERLAY.get();
boolean hasUnderlayDescription = underlayMapDescr != null;
underlayMapDescr = hasUnderlayDescription ? underlayMapDescr : mapActivity.getString(R.string.shared_string_none);
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_underlay, mapActivity).setDescription(underlayMapDescr).setSelected(hasUnderlayDescription).setColor(hasUnderlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_layer_bottom_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(listener).setPosition(15).createItem());
}
use of net.osmand.plus.ContextMenuAdapter in project Osmand by osmandapp.
the class ContextMenuLayer method populateObjectContextMenu.
@Override
public void populateObjectContextMenu(LatLon latLon, Object o, ContextMenuAdapter adapter, MapActivity mapActivity) {
ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
RotatedTileBox tileBox = activity.getMapView().getCurrentRotatedTileBox();
enterMovingMode(tileBox);
return true;
}
};
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());
}
use of net.osmand.plus.ContextMenuAdapter in project Osmand by osmandapp.
the class MapActivityActions method updateDrawerMenu.
protected void updateDrawerMenu() {
boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
final ListView menuItemsListView = (ListView) mapActivity.findViewById(R.id.menuItems);
if (nightMode) {
menuItemsListView.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.bg_color_dark));
} else {
menuItemsListView.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.bg_color_light));
}
menuItemsListView.setDivider(null);
final ContextMenuAdapter contextMenuAdapter = createMainOptionsMenu();
contextMenuAdapter.setDefaultLayoutId(R.layout.simple_list_menu_item);
final ArrayAdapter<ContextMenuItem> simpleListAdapter = contextMenuAdapter.createListAdapter(mapActivity, !nightMode);
menuItemsListView.setAdapter(simpleListAdapter);
menuItemsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mapActivity.dismissCardDialog();
ContextMenuItem item = contextMenuAdapter.getItem(position);
ContextMenuAdapter.ItemClickListener click = item.getItemClickListener();
if (click != null && click.onContextMenuClick(simpleListAdapter, item.getTitleId(), position, false, AndroidUtils.getCenterViewCoordinates(view))) {
mapActivity.closeDrawer();
}
}
});
}
Aggregations