Search in sources :

Example 1 with ContextMenuItemClickListener

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

the class MapContextMenuFragment method updateActionButtons.

private void updateActionButtons(MapActivity mapActivity) {
    LinearLayout buttons = view.findViewById(R.id.context_menu_buttons);
    buttons.setBackgroundColor(ContextCompat.getColor(mapActivity, nightMode ? R.color.list_background_color_dark : R.color.activity_background_color_light));
    buttons.setVisibility(menu.buttonsVisible() ? View.VISIBLE : View.GONE);
    // Action buttons
    ContextMenuAdapter adapter = menu.getActionsContextMenuAdapter(false);
    List<ContextMenuItem> items = adapter.getVisibleItems();
    List<String> mainIds = ((MainContextMenuItemsSettings) mapActivity.getMyApplication().getSettings().CONTEXT_MENU_ACTIONS_ITEMS.get()).getMainIds();
    ContextMenuAdapter mainAdapter = new ContextMenuAdapter(requireMyApplication());
    ContextMenuAdapter additionalAdapter = new ContextMenuAdapter(requireMyApplication());
    if (!mainIds.isEmpty()) {
        for (ContextMenuItem item : items) {
            if (mainIds.contains(item.getId())) {
                mainAdapter.addItem(item);
            } else {
                additionalAdapter.addItem(item);
            }
        }
    } else {
        for (int i = 0; i < items.size(); i++) {
            if (i < MAIN_BUTTONS_QUANTITY) {
                mainAdapter.addItem(items.get(i));
            } else {
                additionalAdapter.addItem(items.get(i));
            }
        }
    }
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1f);
    buttons.removeAllViews();
    ContextMenuItemClickListener mainListener = menu.getContextMenuItemClickListener(mainAdapter);
    ContextMenuItemClickListener additionalListener = menu.getContextMenuItemClickListener(additionalAdapter);
    if (!mainIds.isEmpty()) {
        for (ContextMenuItem item : mainAdapter.getItems()) {
            buttons.addView(getActionView(item, mainAdapter.getItems().indexOf(item), mainAdapter, additionalAdapter, mainListener, additionalListener), params);
        }
    } else {
        int mainButtonsQuantity = Math.min(MAIN_BUTTONS_QUANTITY, items.size());
        for (int i = 0; i < mainButtonsQuantity; i++) {
            buttons.addView(getActionView(items.get(i), i, mainAdapter, additionalAdapter, mainListener, additionalListener), params);
        }
    }
    buttons.setGravity(Gravity.CENTER);
}
Also used : ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ContextMenuItem(net.osmand.plus.ContextMenuItem) MainContextMenuItemsSettings(net.osmand.plus.settings.backend.menuitems.MainContextMenuItemsSettings) ContextMenuItemClickListener(net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener) LinearLayout(android.widget.LinearLayout) QuadPoint(net.osmand.data.QuadPoint)

Example 2 with ContextMenuItemClickListener

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

the class MapActivityActions method getContextMenuItemClickListener.

public ContextMenuItemClickListener getContextMenuItemClickListener(final double latitude, final double longitude, final ContextMenuAdapter adapter) {
    final ArrayAdapter<ContextMenuItem> listAdapter = adapter.createListAdapter(mapActivity, settings.isLightContent());
    return 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) {
                // if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
                enterDirectionsFromPoint(latitude, longitude);
            // } else {
            // ActivityCompat.requestPermissions(mapActivity,
            // new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
            // REQUEST_LOCATION_FOR_DIRECTIONS_NAVIGATION_PERMISSION);
            // }
            } else if (standardId == R.string.plan_route) {
                mapActivity.getContextMenu().close();
                MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), new LatLon(latitude, longitude));
            } else if (standardId == R.string.avoid_road) {
                app.getAvoidSpecificRoads().addImpassableRoad(mapActivity, new LatLon(latitude, longitude), true, false, null);
            } else if (standardId == R.string.shared_string_add || standardId == R.string.favourites_context_menu_edit) {
                mapActivity.getContextMenu().hide();
                mapActivity.getContextMenu().buttonFavoritePressed();
            } else if (standardId == R.string.shared_string_marker || standardId == R.string.shared_string_edit) {
                mapActivity.getContextMenu().buttonWaypointPressed();
            } else if (standardId == R.string.shared_string_share) {
                mapActivity.getContextMenu().buttonSharePressed();
            }
        }
    };
}
Also used : LatLon(net.osmand.data.LatLon) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) ContextMenuItemClickListener(net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener) ContextMenuItem(net.osmand.plus.ContextMenuItem) ContextMenuItemClickListener(net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener) FavouritePoint(net.osmand.data.FavouritePoint)

Aggregations

ContextMenuItem (net.osmand.plus.ContextMenuItem)2 ContextMenuItemClickListener (net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener)2 LinearLayout (android.widget.LinearLayout)1 FavouritePoint (net.osmand.data.FavouritePoint)1 LatLon (net.osmand.data.LatLon)1 QuadPoint (net.osmand.data.QuadPoint)1 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)1 ItemClickListener (net.osmand.plus.ContextMenuAdapter.ItemClickListener)1 MainContextMenuItemsSettings (net.osmand.plus.settings.backend.menuitems.MainContextMenuItemsSettings)1