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);
}
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();
}
}
};
}
Aggregations