use of net.osmand.plus.ContextMenuAdapter in project Osmand by osmandapp.
the class GpxUiHelper method createGpxContextMenuAdapter.
private static ContextMenuAdapter createGpxContextMenuAdapter(List<GPXInfo> allGpxList, List<String> selectedGpxList, boolean showCurrentTrack) {
final ContextMenuAdapter adapter = new ContextMenuAdapter();
// element position in adapter
int i = 0;
for (GPXInfo gpxInfo : allGpxList) {
String s = gpxInfo.getFileName();
String fileName = s;
if (s.endsWith(".gpx")) {
s = s.substring(0, s.length() - ".gpx".length());
}
s = s.replace('_', ' ');
adapter.addItem(ContextMenuItem.createBuilder(s).setSelected(false).setIcon(R.drawable.ic_action_polygom_dark).createItem());
// if there's some selected files - need to mark them as selected
if (selectedGpxList != null) {
updateSelection(selectedGpxList, showCurrentTrack, adapter, i, fileName);
}
i++;
}
return adapter;
}
use of net.osmand.plus.ContextMenuAdapter in project Osmand by osmandapp.
the class GpxUiHelper method selectSingleGPXFile.
public static AlertDialog selectSingleGPXFile(final Activity activity, boolean showCurrentGpx, final CallbackWithObject<GPXFile[]> callbackWithObject) {
OsmandApplication app = (OsmandApplication) activity.getApplication();
int gpxDirLength = app.getAppPath(IndexConstants.GPX_INDEX_DIR).getAbsolutePath().length();
List<SelectedGpxFile> selectedGpxFiles = app.getSelectedGpxHelper().getSelectedGPXFiles();
final List<GPXInfo> list = new ArrayList<>(selectedGpxFiles.size() + 1);
if (OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) == null) {
showCurrentGpx = false;
}
if (!selectedGpxFiles.isEmpty() || showCurrentGpx) {
if (showCurrentGpx) {
list.add(new GPXInfo(activity.getString(R.string.shared_string_currently_recording_track), 0, 0));
}
for (SelectedGpxFile selectedGpx : selectedGpxFiles) {
if (!selectedGpx.getGpxFile().showCurrentTrack) {
list.add(new GPXInfo(selectedGpx.getGpxFile().path.substring(gpxDirLength + 1), selectedGpx.getGpxFile().modifiedTime, 0));
}
}
final ContextMenuAdapter adapter = createGpxContextMenuAdapter(list, null, showCurrentGpx);
return createSingleChoiceDialog(activity, showCurrentGpx, callbackWithObject, list, adapter);
}
return null;
}
use of net.osmand.plus.ContextMenuAdapter in project Osmand by osmandapp.
the class SettingsNavigationActivity method onPreferenceClick.
@SuppressWarnings("unchecked")
@Override
public boolean onPreferenceClick(Preference preference) {
if (preference == avoidRouting || preference == preferRouting) {
List<RoutingParameter> prms = preference == avoidRouting ? avoidParameters : preferParameters;
String[] vals = new String[prms.size()];
OsmandPreference[] bls = new OsmandPreference[prms.size()];
for (int i = 0; i < prms.size(); i++) {
RoutingParameter p = prms.get(i);
vals[i] = SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName());
bls[i] = settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean());
}
showBooleanSettings(vals, bls, preference.getTitle());
return true;
} else if (preference == autoZoom) {
final ApplicationMode am = settings.getApplicationMode();
final ContextMenuAdapter adapter = new ContextMenuAdapter();
int i = 0;
int selectedIndex = -1;
adapter.addItem(ContextMenuItem.createBuilder(getString(R.string.auto_zoom_none)).setSelected(false).createItem());
if (!settings.AUTO_ZOOM_MAP.get()) {
selectedIndex = 0;
}
i++;
for (AutoZoomMap autoZoomMap : AutoZoomMap.values()) {
adapter.addItem(ContextMenuItem.createBuilder(getString(autoZoomMap.name)).setSelected(false).createItem());
if (selectedIndex == -1 && settings.AUTO_ZOOM_MAP_SCALE.get() == autoZoomMap) {
selectedIndex = i;
}
i++;
}
if (selectedIndex == -1) {
selectedIndex = 0;
}
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final int layout = R.layout.list_menu_item_native_singlechoice;
final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, layout, R.id.text1, adapter.getItemNames()) {
@NonNull
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View
View v = convertView;
if (v == null) {
v = SettingsNavigationActivity.this.getLayoutInflater().inflate(layout, null);
}
final ContextMenuItem item = adapter.getItem(position);
TextView tv = (TextView) v.findViewById(R.id.text1);
tv.setText(item.getTitle());
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f);
return v;
}
};
final int[] selectedPosition = { selectedIndex };
builder.setSingleChoiceItems(listAdapter, selectedIndex, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int position) {
selectedPosition[0] = position;
}
});
builder.setTitle(R.string.auto_zoom_map).setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int position = selectedPosition[0];
if (position == 0) {
settings.AUTO_ZOOM_MAP.set(false);
} else {
settings.AUTO_ZOOM_MAP.set(true);
settings.AUTO_ZOOM_MAP_SCALE.set(AutoZoomMap.values()[position - 1]);
}
}
}).setNegativeButton(R.string.shared_string_cancel, null);
builder.create().show();
return true;
} else if (preference == reliefFactorRouting) {
final ApplicationMode am = settings.getApplicationMode();
final ContextMenuAdapter adapter = new ContextMenuAdapter();
int i = 0;
int selectedIndex = -1;
for (RoutingParameter p : reliefFactorParameters) {
adapter.addItem(ContextMenuItem.createBuilder(getRoutinParameterTitle(this, p)).setSelected(false).createItem());
if (isRoutingParameterSelected(settings, am, p)) {
selectedIndex = i;
}
i++;
}
if (selectedIndex == -1) {
selectedIndex = 0;
}
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final int layout = R.layout.list_menu_item_native_singlechoice;
final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, layout, R.id.text1, adapter.getItemNames()) {
@NonNull
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View
View v = convertView;
if (v == null) {
v = SettingsNavigationActivity.this.getLayoutInflater().inflate(layout, null);
}
final ContextMenuItem item = adapter.getItem(position);
TextView tv = (TextView) v.findViewById(R.id.text1);
tv.setText(item.getTitle());
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f);
return v;
}
};
final int[] selectedPosition = { selectedIndex };
builder.setSingleChoiceItems(listAdapter, selectedIndex, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int position) {
selectedPosition[0] = position;
}
});
builder.setTitle(SettingsBaseActivity.getRoutingStringPropertyName(this, reliefFactorParameters.get(0).getGroup(), Algorithms.capitalizeFirstLetterAndLowercase(reliefFactorParameters.get(0).getGroup().replace('_', ' ')))).setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int position = selectedPosition[0];
if (position >= 0 && position < reliefFactorParameters.size()) {
for (int i = 0; i < reliefFactorParameters.size(); i++) {
setRoutingParameterSelected(settings, am, reliefFactorParameters.get(i), i == position);
}
// mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
// updateParameters();
}
}
}).setNegativeButton(R.string.shared_string_cancel, null);
builder.create().show();
return true;
} else if (preference == showAlarms) {
showBooleanSettings(new String[] { getString(R.string.show_traffic_warnings), getString(R.string.show_pedestrian_warnings), getString(R.string.show_cameras), getString(R.string.show_lanes), getString(R.string.show_tunnels) }, new OsmandPreference[] { settings.SHOW_TRAFFIC_WARNINGS, settings.SHOW_PEDESTRIAN, settings.SHOW_CAMERAS, settings.SHOW_LANES, settings.SHOW_TUNNELS }, preference.getTitle());
return true;
} else if (preference == speakAlarms) {
AlertDialog dlg = showBooleanSettings(new String[] { getString(R.string.speak_street_names), getString(R.string.speak_traffic_warnings), getString(R.string.speak_pedestrian), getString(R.string.speak_speed_limit), getString(R.string.speak_cameras), getString(R.string.announce_gpx_waypoints), getString(R.string.speak_favorites), getString(R.string.speak_poi) }, new OsmandPreference[] { settings.SPEAK_STREET_NAMES, settings.SPEAK_TRAFFIC_WARNINGS, settings.SPEAK_PEDESTRIAN, settings.SPEAK_SPEED_LIMIT, settings.SPEAK_SPEED_CAMERA, settings.ANNOUNCE_WPT, settings.ANNOUNCE_NEARBY_FAVORITES, settings.ANNOUNCE_NEARBY_POI }, preference.getTitle());
final boolean initialSpeedCam = settings.SPEAK_SPEED_CAMERA.get();
final boolean initialFavorites = settings.ANNOUNCE_NEARBY_FAVORITES.get();
final boolean initialPOI = settings.ANNOUNCE_NEARBY_POI.get();
// final boolean initialWpt = settings.ANNOUNCE_WPT.get();
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (settings.ANNOUNCE_NEARBY_POI.get() != initialPOI) {
settings.SHOW_NEARBY_POI.set(settings.ANNOUNCE_NEARBY_POI.get());
}
if (settings.ANNOUNCE_NEARBY_FAVORITES.get() != initialFavorites) {
settings.SHOW_NEARBY_FAVORITES.set(settings.ANNOUNCE_NEARBY_FAVORITES.get());
}
if (settings.ANNOUNCE_WPT.get()) {
settings.SHOW_WPT.set(settings.ANNOUNCE_WPT.get());
}
if (!initialSpeedCam) {
if (settings.SPEAK_SPEED_CAMERA.get()) {
settings.SPEAK_SPEED_CAMERA.set(false);
confirmSpeedCamerasDlg();
}
}
}
});
return true;
}
return false;
}
use of net.osmand.plus.ContextMenuAdapter 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);
}
use of net.osmand.plus.ContextMenuAdapter in project Osmand by osmandapp.
the class MapWidgetRegistry method addControls.
private void addControls(final MapActivity mapActivity, final ContextMenuAdapter contextMenuAdapter, Set<MapWidgetRegInfo> groupTitle, final ApplicationMode mode) {
for (final MapWidgetRegInfo r : groupTitle) {
if (!mode.isWidgetAvailable(r.key)) {
continue;
}
final boolean selected = r.visibleCollapsed(mode) || r.visible(mode);
final String desc = mapActivity.getString(R.string.shared_string_collapse);
ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder().setIcon(r.getDrawableMenu()).setSelected(selected).setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setSecondaryIcon(r.widget != null ? R.drawable.ic_action_additional_option : ContextMenuItem.INVALID_ID).setDescription(r.visibleCollapsed(mode) ? desc : null).setListener(new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onRowItemClick(final ArrayAdapter<ContextMenuItem> adapter, final View view, final int itemId, final int pos) {
if (r.widget == null) {
setVisibility(adapter, pos, !r.visible(mode), false);
return false;
}
View textWrapper = view.findViewById(R.id.text_wrapper);
IconPopupMenu popup = new IconPopupMenu(view.getContext(), textWrapper);
MenuInflater inflater = popup.getMenuInflater();
final Menu menu = popup.getMenu();
inflater.inflate(R.menu.widget_visibility_menu, menu);
IconsCache ic = mapActivity.getMyApplication().getIconsCache();
menu.findItem(R.id.action_show).setIcon(ic.getThemedIcon(R.drawable.ic_action_view));
menu.findItem(R.id.action_hide).setIcon(ic.getThemedIcon(R.drawable.ic_action_hide));
menu.findItem(R.id.action_collapse).setIcon(ic.getThemedIcon(R.drawable.ic_action_widget_collapse));
final int[] menuIconIds = r.getDrawableMenuIds();
final int[] menuTitleIds = r.getMessageIds();
final int[] menuItemIds = r.getItemIds();
int checkedId = r.getItemId();
boolean selected = r.visibleCollapsed(mode) || r.visible(mode);
if (menuIconIds != null && menuTitleIds != null && menuItemIds != null && menuIconIds.length == menuTitleIds.length && menuIconIds.length == menuItemIds.length) {
for (int i = 0; i < menuIconIds.length; i++) {
int iconId = menuIconIds[i];
int titleId = menuTitleIds[i];
int id = menuItemIds[i];
MenuItem menuItem = menu.add(R.id.single_selection_group, id, i, titleId).setChecked(id == checkedId);
menuItem.setIcon(menuItem.isChecked() && selected ? ic.getIcon(iconId, R.color.osmand_orange) : ic.getThemedIcon(iconId));
}
menu.setGroupCheckable(R.id.single_selection_group, true, true);
menu.setGroupVisible(R.id.single_selection_group, true);
}
popup.setOnMenuItemClickListener(new IconPopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch(menuItem.getItemId()) {
case R.id.action_show:
setVisibility(adapter, pos, true, false);
return true;
case R.id.action_hide:
setVisibility(adapter, pos, false, false);
return true;
case R.id.action_collapse:
setVisibility(adapter, pos, true, true);
return true;
default:
if (menuItemIds != null) {
for (int menuItemId : menuItemIds) {
if (menuItem.getItemId() == menuItemId) {
r.changeState(menuItemId);
MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer();
if (mil != null) {
mil.recreateControls();
}
ContextMenuItem item = adapter.getItem(pos);
item.setIcon(r.getDrawableMenu());
if (r.getMessage() != null) {
item.setTitle(r.getMessage());
} else {
item.setTitle(mapActivity.getResources().getString(r.getMessageId()));
}
adapter.notifyDataSetChanged();
return true;
}
}
}
}
return false;
}
});
popup.show();
return false;
}
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> a, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
setVisibility(a, pos, isChecked, false);
return false;
}
private void setVisibility(ArrayAdapter<ContextMenuItem> adapter, int position, boolean visible, boolean collapsed) {
MapWidgetRegistry.this.setVisibility(r, visible, collapsed);
MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer();
if (mil != null) {
mil.recreateControls();
}
ContextMenuItem item = adapter.getItem(position);
item.setSelected(visible);
item.setColorRes(visible ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
item.setDescription(visible && collapsed ? desc : null);
adapter.notifyDataSetChanged();
}
});
if (r.getMessage() != null) {
itemBuilder.setTitle(r.getMessage());
} else {
itemBuilder.setTitleId(r.getMessageId(), mapActivity);
}
contextMenuAdapter.addItem(itemBuilder.createItem());
}
}
Aggregations