use of net.osmand.plus.ContextMenuAdapter in project Osmand by osmandapp.
the class AudioVideoNotesPlugin method registerMapContextMenuActions.
@Override
public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude, ContextMenuAdapter adapter, Object selectedObj) {
if (isRecording()) {
return;
}
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.recording_context_menu_arecord, app).setIcon(R.drawable.ic_action_micro_dark).setOrder(TAKE_AUDIO_NOTE_ITEM_ORDER).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
recordAudio(latitude, longitude, mapActivity);
return true;
}
}).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.recording_context_menu_vrecord, app).setIcon(R.drawable.ic_action_video_dark).setOrder(TAKE_VIDEO_NOTE_ITEM_ORDER).setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
recordVideo(latitude, longitude, mapActivity, false);
return true;
}
}).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.recording_context_menu_precord, app).setIcon(R.drawable.ic_action_photo_dark).setOrder(TAKE_PHOTO_NOTE_ITEM_ORDER).setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
takePhoto(latitude, longitude, mapActivity, false, false);
return true;
}
}).createItem());
}
use of net.osmand.plus.ContextMenuAdapter in project Osmand by osmandapp.
the class ConfigureMapMenu method createListAdapter.
public ContextMenuAdapter createListAdapter(final MapActivity ma) {
ContextMenuAdapter adapter = new ContextMenuAdapter();
adapter.setDefaultLayoutId(R.layout.list_item_icon_and_menu);
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.app_modes_choose, ma).setLayout(R.layout.mode_toggles).createItem());
adapter.setChangeAppModeListener(new OnClickListener() {
@Override
public void onClick() {
ma.getDashboard().updateListAdapter(createListAdapter(ma));
}
});
RenderingRulesStorage renderer = ma.getMyApplication().getRendererRegistry().getCurrentSelectedRenderer();
List<RenderingRuleProperty> customRules = new ArrayList<>();
boolean hasDepthContours = ma.getMyApplication().getResourceManager().hasDepthContours();
if (renderer != null) {
for (RenderingRuleProperty p : renderer.PROPS.getCustomRules()) {
if (!RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(p.getCategory()) && (hasDepthContours || !p.getAttrName().equals("depthContours"))) {
customRules.add(p);
}
}
}
createLayersItems(customRules, adapter, ma);
createRenderingAttributeItems(customRules, adapter, ma);
return adapter;
}
use of net.osmand.plus.ContextMenuAdapter in project Osmand by osmandapp.
the class ConfigureMapMenu method createRenderingProperty.
private ContextMenuItem createRenderingProperty(final ContextMenuAdapter adapter, final MapActivity activity, @DrawableRes final int icon, final RenderingRuleProperty p) {
final OsmandMapTileView view = activity.getMapView();
String propertyName = SettingsActivity.getStringPropertyName(view.getContext(), p.getAttrName(), p.getName());
final String propertyDescr = SettingsActivity.getStringPropertyDescription(view.getContext(), p.getAttrName(), p.getName());
if (p.isBoolean()) {
final OsmandSettings.CommonPreference<Boolean> pref = view.getApplication().getSettings().getCustomRenderBooleanProperty(p.getAttrName());
return ContextMenuItem.createBuilder(propertyName).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
pref.set(!pref.get());
refreshMapComplete(activity);
return false;
}
}).setSelected(pref.get()).createItem();
} else {
final OsmandSettings.CommonPreference<String> pref = view.getApplication().getSettings().getCustomRenderProperty(p.getAttrName());
final String descr;
if (!Algorithms.isEmpty(pref.get())) {
descr = SettingsActivity.getStringPropertyValue(activity, pref.get());
} else {
descr = SettingsActivity.getStringPropertyValue(view.getContext(), p.getDefaultValueDescription());
}
ContextMenuItem.ItemBuilder builder = ContextMenuItem.createBuilder(propertyName).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, final int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
// test old descr as title
b.setTitle(propertyDescr);
int i = Arrays.asList(p.getPossibleValues()).indexOf(pref.get());
if (i >= 0) {
i++;
} else if (Algorithms.isEmpty(pref.get())) {
i = 0;
}
String[] possibleValuesString = new String[p.getPossibleValues().length + 1];
possibleValuesString[0] = SettingsActivity.getStringPropertyValue(view.getContext(), p.getDefaultValueDescription());
for (int j = 0; j < p.getPossibleValues().length; j++) {
possibleValuesString[j + 1] = SettingsActivity.getStringPropertyValue(view.getContext(), p.getPossibleValues()[j]);
}
b.setSingleChoiceItems(possibleValuesString, i, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
pref.set("");
} else {
pref.set(p.getPossibleValues()[which - 1]);
}
refreshMapComplete(activity);
String description = SettingsActivity.getStringPropertyValue(activity, pref.get());
adapter.getItem(pos).setDescription(description);
dialog.dismiss();
}
});
b.setNegativeButton(R.string.shared_string_dismiss, null);
b.show();
return false;
}
}).setDescription(descr).setLayout(R.layout.list_item_single_line_descrition_narrow);
if (icon != 0) {
builder.setIcon(icon);
}
return builder.createItem();
}
}
use of net.osmand.plus.ContextMenuAdapter in project Osmand by osmandapp.
the class RasterMapMenu method createLayersItems.
private static void createLayersItems(final ContextMenuAdapter contextMenuAdapter, final MapActivity mapActivity, final RasterMapType type) {
final OsmandApplication app = mapActivity.getMyApplication();
final OsmandSettings settings = app.getSettings();
final OsmandRasterMapsPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class);
assert plugin != null;
final OsmandSettings.CommonPreference<Integer> mapTransparencyPreference;
final OsmandSettings.CommonPreference<String> mapTypePreference;
final OsmandSettings.CommonPreference<String> exMapTypePreference;
final LayerTransparencySeekbarMode currentMapTypeSeekbarMode = type == RasterMapType.OVERLAY ? LayerTransparencySeekbarMode.OVERLAY : LayerTransparencySeekbarMode.UNDERLAY;
@StringRes final int mapTypeString;
@StringRes final int mapTypeStringTransparency;
if (type == RasterMapType.OVERLAY) {
mapTransparencyPreference = settings.MAP_OVERLAY_TRANSPARENCY;
mapTypePreference = settings.MAP_OVERLAY;
exMapTypePreference = settings.MAP_OVERLAY_PREVIOUS;
mapTypeString = R.string.map_overlay;
mapTypeStringTransparency = R.string.overlay_transparency;
} else if (type == RasterMapType.UNDERLAY) {
mapTransparencyPreference = settings.MAP_TRANSPARENCY;
mapTypePreference = settings.MAP_UNDERLAY;
exMapTypePreference = settings.MAP_UNDERLAY_PREVIOUS;
mapTypeString = R.string.map_underlay;
mapTypeStringTransparency = R.string.map_transparency;
} else {
throw new RuntimeException("Unexpected raster map type");
}
final OsmandSettings.CommonPreference<Boolean> hidePolygonsPref = mapActivity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
String mapTypeDescr = mapTypePreference.get();
final boolean selected = mapTypeDescr != null;
final int toggleActionStringId = selected ? R.string.shared_string_enabled : R.string.shared_string_disabled;
final OnMapSelectedCallback onMapSelectedCallback = new OnMapSelectedCallback() {
@Override
public void onMapSelected(boolean canceled) {
if (type == RasterMapType.UNDERLAY && !canceled && !selected) {
hidePolygonsPref.set(true);
refreshMapComplete(mapActivity);
} else if (type == RasterMapType.UNDERLAY && !canceled && mapTypePreference.get() == null) {
hidePolygonsPref.set(false);
refreshMapComplete(mapActivity);
}
mapActivity.getDashboard().refreshContent(true);
}
};
final MapActivityLayers mapLayers = mapActivity.getMapLayers();
ContextMenuAdapter.OnRowItemClick l = new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int pos) {
if (itemId == mapTypeString) {
if (selected) {
plugin.selectMapOverlayLayer(mapActivity.getMapView(), mapTypePreference, exMapTypePreference, true, mapActivity, onMapSelectedCallback);
}
return false;
}
return super.onRowItemClick(adapter, view, itemId, pos);
}
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, final int itemId, final int pos, final boolean isChecked, int[] viewCoordinates) {
if (itemId == toggleActionStringId) {
app.runInUIThread(new Runnable() {
@Override
public void run() {
plugin.toggleUnderlayState(mapActivity, type, onMapSelectedCallback);
refreshMapComplete(mapActivity);
}
});
} else if (itemId == R.string.show_polygons) {
hidePolygonsPref.set(!isChecked);
refreshMapComplete(mapActivity);
} else if (itemId == R.string.show_transparency_seekbar) {
settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.set(isChecked ? currentMapTypeSeekbarMode : LayerTransparencySeekbarMode.OFF);
if (isChecked) {
mapLayers.getMapControlsLayer().showTransparencyBar(mapTransparencyPreference);
} else {
mapLayers.getMapControlsLayer().hideTransparencyBar(mapTransparencyPreference);
}
mapLayers.getMapControlsLayer().setTransparencyBarEnabled(isChecked);
}
return false;
}
};
mapTypeDescr = selected ? mapTypeDescr : mapActivity.getString(R.string.shared_string_none);
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(toggleActionStringId, mapActivity).hideDivider(true).setListener(l).setSelected(selected).createItem());
if (selected) {
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(mapTypeString, mapActivity).hideDivider(true).setListener(l).setLayout(R.layout.list_item_icon_and_menu_wide).setDescription(mapTypeDescr).createItem());
ContextMenuAdapter.OnIntegerValueChangedListener integerListener = new ContextMenuAdapter.OnIntegerValueChangedListener() {
@Override
public boolean onIntegerValueChangedListener(int newValue) {
mapTransparencyPreference.set(newValue);
mapActivity.getMapView().refreshMap();
return false;
}
};
// android:max="255" in layout is expected
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(mapTypeStringTransparency, mapActivity).hideDivider(true).setLayout(R.layout.list_item_progress).setIcon(R.drawable.ic_action_opacity).setProgress(mapTransparencyPreference.get()).setListener(l).setIntegerListener(integerListener).createItem());
if (type == RasterMapType.UNDERLAY) {
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.show_polygons, mapActivity).hideDivider(true).setListener(l).setSelected(!hidePolygonsPref.get()).createItem());
}
Boolean transparencySwitchState = isSeekbarVisible(app, type);
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.show_transparency_seekbar, mapActivity).hideDivider(true).setListener(l).setSelected(transparencySwitchState).createItem());
}
}
use of net.osmand.plus.ContextMenuAdapter in project Osmand by osmandapp.
the class DashboardOnMap method getOptionsMenuOnClickListener.
private OnItemClickListener getOptionsMenuOnClickListener(final ContextMenuAdapter cm, final ArrayAdapter<ContextMenuItem> listAdapter) {
return new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int which, long id) {
ContextMenuItem item = cm.getItem(which);
ContextMenuAdapter.ItemClickListener click = item.getItemClickListener();
if (click instanceof OnRowItemClick) {
boolean cl = ((OnRowItemClick) click).onRowItemClick(listAdapter, view, item.getTitleId(), which);
if (cl) {
hideDashboard();
}
} else if (click != null) {
CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item);
if (btn != null && btn.getVisibility() == View.VISIBLE) {
btn.setChecked(!btn.isChecked());
} else {
if (click.onContextMenuClick(listAdapter, item.getTitleId(), which, false, null)) {
hideDashboard();
}
}
} else {
if (!item.isCategory()) {
hideDashboard();
}
}
}
};
}
Aggregations