Search in sources :

Example 11 with ItemClickListener

use of net.osmand.plus.ContextMenuAdapter.ItemClickListener 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)

Example 12 with ItemClickListener

use of net.osmand.plus.ContextMenuAdapter.ItemClickListener in project Osmand by osmandapp.

the class ParkingPositionPlugin method registerMapContextMenuActions.

@Override
public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude, ContextMenuAdapter adapter, Object selectedObj) {
    ItemClickListener addListener = new ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int resId, int pos, boolean isChecked, int[] viewCoordinates) {
            if (resId == R.string.context_menu_item_add_parking_point) {
                showAddParkingDialog(mapActivity, latitude, longitude);
            }
            return true;
        }
    };
    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());
}
Also used : ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

ItemClickListener (net.osmand.plus.ContextMenuAdapter.ItemClickListener)12 ArrayAdapter (android.widget.ArrayAdapter)10 ContextMenuItem (net.osmand.plus.ContextMenuItem)9 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)6 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)4 DialogInterface (android.content.DialogInterface)3 OsmandApplication (net.osmand.plus.OsmandApplication)3 AppCompatCheckedTextView (android.support.v7.widget.AppCompatCheckedTextView)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 ImageView (android.widget.ImageView)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 LatLon (net.osmand.data.LatLon)2 ItemBuilder (net.osmand.plus.ContextMenuItem.ItemBuilder)2 RenderingRuleProperty (net.osmand.render.RenderingRuleProperty)2