Search in sources :

Example 1 with AdditionalActionsBottomSheetDialogFragment

use of net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment in project Osmand by osmandapp.

the class MapActivityActions method contextMenuPoint.

public void contextMenuPoint(final double latitude, final double longitude, final ContextMenuAdapter iadapter, Object selectedObj) {
    final ContextMenuAdapter adapter = iadapter == null ? new ContextMenuAdapter() : iadapter;
    ItemBuilder itemBuilder = new ItemBuilder();
    adapter.addItem(itemBuilder.setTitleId(R.string.context_menu_item_directions_from, mapActivity).setIcon(R.drawable.ic_action_route_direction_from_here).setOrder(DIRECTIONS_FROM_ITEM_ORDER).createItem());
    adapter.addItem(itemBuilder.setTitleId(R.string.context_menu_item_search, mapActivity).setIcon(R.drawable.ic_action_search_dark).setOrder(SEARCH_NEAR_ITEM_ORDER).createItem());
    OsmandPlugin.registerMapContextMenu(mapActivity, latitude, longitude, adapter, selectedObj);
    ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int resId, int pos, boolean isChecked, int[] viewCoordinates) {
            if (resId == R.string.context_menu_item_add_waypoint) {
                mapActivity.getContextMenu().addWptPt();
            } else if (resId == R.string.context_menu_item_edit_waypoint) {
                mapActivity.getContextMenu().editWptPt();
            }
            return true;
        }
    };
    if (selectedObj instanceof WptPt && getMyApplication().getSelectedGpxHelper().getSelectedGPXFile((WptPt) selectedObj) != null) {
        adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_edit_waypoint, mapActivity).setIcon(R.drawable.ic_action_edit_dark).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).setOrder(ADD_GPX_WAYPOINT_ITEM_ORDER).setListener(listener).createItem());
    }
    adapter.sortItemsByOrder();
    final ArrayAdapter<ContextMenuItem> listAdapter = adapter.createListAdapter(mapActivity, getMyApplication().getSettings().isLightContent());
    AdditionalActionsBottomSheetDialogFragment actionsBottomSheetDialogFragment = new AdditionalActionsBottomSheetDialogFragment();
    actionsBottomSheetDialogFragment.setAdapter(adapter, new AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener() {

        @Override
        public void onItemClick(int position) {
            ContextMenuItem item = adapter.getItem(position);
            int standardId = item.getTitleId();
            ItemClickListener click = item.getItemClickListener();
            if (click != null) {
                click.onContextMenuClick(listAdapter, standardId, position, false, null);
            } else if (standardId == R.string.context_menu_item_search) {
                mapActivity.showQuickSearch(latitude, longitude);
            } else if (standardId == R.string.context_menu_item_directions_from) {
                mapActivity.getContextMenu().hide();
                if (getMyApplication().getTargetPointsHelper().getPointToNavigate() == null) {
                    setFirstMapMarkerAsTarget();
                }
                if (!mapActivity.getRoutingHelper().isFollowingMode() && !mapActivity.getRoutingHelper().isRoutePlanningMode()) {
                    enterRoutePlanningMode(new LatLon(latitude, longitude), mapActivity.getContextMenu().getPointDescription());
                } else {
                    getMyApplication().getTargetPointsHelper().setStartPoint(new LatLon(latitude, longitude), true, mapActivity.getContextMenu().getPointDescription());
                }
            }
        }
    });
    actionsBottomSheetDialogFragment.show(mapActivity.getSupportFragmentManager(), AdditionalActionsBottomSheetDialogFragment.TAG);
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) AdditionalActionsBottomSheetDialogFragment(net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) ContextMenuItem(net.osmand.plus.ContextMenuItem) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) LatLon(net.osmand.data.LatLon) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder) ArrayAdapter(android.widget.ArrayAdapter) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder)

Aggregations

ArrayAdapter (android.widget.ArrayAdapter)1 LatLon (net.osmand.data.LatLon)1 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)1 ItemClickListener (net.osmand.plus.ContextMenuAdapter.ItemClickListener)1 ContextMenuItem (net.osmand.plus.ContextMenuItem)1 ItemBuilder (net.osmand.plus.ContextMenuItem.ItemBuilder)1 WptPt (net.osmand.plus.GPXUtilities.WptPt)1 AdditionalActionsBottomSheetDialogFragment (net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment)1