use of net.osmand.plus.poi.PoiUIFilter in project Osmand by osmandapp.
the class SearchPOIActivity method showOptionsMenu.
private void showOptionsMenu(View v) {
// Show menu with search all, name finder, name finder poi
IconsCache iconsCache = getMyApplication().getIconsCache();
final PopupMenu optionsMenu = new PopupMenu(this, v);
final PoiUIFilter f = this.filter;
MenuItem item = optionsMenu.getMenu().add(R.string.shared_string_edit).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
PoiUIFilter custom = getMyApplication().getPoiFilters().getCustomPOIFilter();
custom.replaceWithPoiFilter(f);
showEditActivity(custom);
return true;
}
});
addFilter(optionsMenu, getString(R.string.shared_string_is_open));
addFilter(optionsMenu, getString(R.string.shared_string_is_open_24_7));
Map<String, PoiType> poiAdditionals = f.getPoiAdditionals();
if (poiAdditionals != null) {
TreeMap<String, PoiType> adds = new TreeMap<String, PoiType>();
for (PoiType vtype : poiAdditionals.values()) {
if (vtype.isTopVisible()) {
adds.put(vtype.getTranslation().replace(' ', ':').toLowerCase(), vtype);
}
}
for (String vtype : adds.keySet()) {
addFilter(optionsMenu, vtype);
}
}
optionsMenu.show();
}
use of net.osmand.plus.poi.PoiUIFilter in project Osmand by osmandapp.
the class SearchPOIActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RESULT_REQUEST_CODE && resultCode == EditPOIFilterActivity.EDIT_ACTIVITY_RESULT_OK) {
PoiUIFilter custom = app.getPoiFilters().getCustomPOIFilter();
if (this.filter.isStandardFilter()) {
this.filter = custom;
if (!Algorithms.isEmpty(searchFilter.getText().toString())) {
this.filter.setFilterByName(searchFilter.getText().toString());
} else {
this.filter.setFilterByName(null);
}
} else {
this.filter.replaceWithPoiFilter(custom);
}
filter.clearPreviousZoom();
// run query again
runNewSearchQuery(location, NEW_SEARCH_INIT);
}
if (filter == null || filter.isEmpty()) {
finish();
}
}
use of net.osmand.plus.poi.PoiUIFilter in project Osmand by osmandapp.
the class MapActivityLayers method showMultichoicePoiFilterDialog.
public void showMultichoicePoiFilterDialog(final OsmandMapTileView mapView, final DismissListener listener) {
final OsmandApplication app = getApplication();
final PoiFiltersHelper poiFilters = app.getPoiFilters();
final ContextMenuAdapter adapter = new ContextMenuAdapter();
final List<PoiUIFilter> list = new ArrayList<>();
for (PoiUIFilter f : poiFilters.getTopDefinedPoiFilters()) {
addFilterToList(adapter, list, f, true);
}
for (PoiUIFilter f : poiFilters.getSearchPoiFilters()) {
addFilterToList(adapter, list, f, true);
}
list.add(poiFilters.getCustomPOIFilter());
final ArrayAdapter<ContextMenuItem> listAdapter = adapter.createListAdapter(activity, app.getSettings().isLightContent());
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final ListView listView = new ListView(activity);
listView.setDivider(null);
listView.setClickable(true);
listView.setAdapter(listAdapter);
listView.setOnItemClickListener(new ListView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ContextMenuItem item = listAdapter.getItem(position);
item.setSelected(!item.getSelected());
item.getItemClickListener().onContextMenuClick(listAdapter, position, position, item.getSelected(), null);
listAdapter.notifyDataSetChanged();
}
});
builder.setView(listView).setTitle(R.string.show_poi_over_map).setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
for (int i = 0; i < listAdapter.getCount(); i++) {
ContextMenuItem item = listAdapter.getItem(i);
PoiUIFilter filter = list.get(i);
if (item.getSelected()) {
getApplication().getPoiFilters().addSelectedPoiFilter(filter);
} else {
getApplication().getPoiFilters().removeSelectedPoiFilter(filter);
}
}
mapView.refreshMap();
}
}).setNegativeButton(R.string.shared_string_cancel, null).setNeutralButton(" ", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showSingleChoicePoiFilterDialog(mapView, listener);
}
});
final AlertDialog alertDialog = builder.create();
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button neutralButton = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL);
Drawable drawable = app.getIconsCache().getThemedIcon(R.drawable.ic_action_singleselect);
neutralButton.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
neutralButton.setContentDescription(app.getString(R.string.shared_string_filters));
}
});
alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
listener.dismiss();
}
});
alertDialog.show();
}
use of net.osmand.plus.poi.PoiUIFilter in project Osmand by osmandapp.
the class MapActivityLayers method showSingleChoicePoiFilterDialog.
public void showSingleChoicePoiFilterDialog(final OsmandMapTileView mapView, final DismissListener listener) {
final OsmandApplication app = getApplication();
final PoiFiltersHelper poiFilters = app.getPoiFilters();
final ContextMenuAdapter adapter = new ContextMenuAdapter();
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_search, app).setIcon(R.drawable.ic_action_search_dark).createItem());
final List<PoiUIFilter> list = new ArrayList<>();
list.add(poiFilters.getCustomPOIFilter());
for (PoiUIFilter f : poiFilters.getTopDefinedPoiFilters()) {
addFilterToList(adapter, list, f, false);
}
for (PoiUIFilter f : poiFilters.getSearchPoiFilters()) {
addFilterToList(adapter, list, f, false);
}
final ArrayAdapter<ContextMenuItem> listAdapter = adapter.createListAdapter(activity, app.getSettings().isLightContent());
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setAdapter(listAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
PoiUIFilter pf = list.get(which);
String filterId = pf.getFilterId();
if (filterId.equals(PoiUIFilter.CUSTOM_FILTER_ID)) {
if (activity.getDashboard().isVisible()) {
activity.getDashboard().hideDashboard();
}
activity.showQuickSearch(ShowQuickSearchMode.NEW, true);
} else {
getApplication().getPoiFilters().clearSelectedPoiFilters();
getApplication().getPoiFilters().addSelectedPoiFilter(pf);
mapView.refreshMap();
}
}
});
builder.setTitle(R.string.show_poi_over_map);
builder.setNegativeButton(R.string.shared_string_dismiss, null);
builder.setNeutralButton(" ", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showMultichoicePoiFilterDialog(mapView, listener);
}
});
final AlertDialog alertDialog = builder.create();
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button neutralButton = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL);
Drawable drawable = app.getIconsCache().getThemedIcon(R.drawable.ic_action_multiselect);
neutralButton.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
neutralButton.setContentDescription(app.getString(R.string.apply_filters));
}
});
alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
listener.dismiss();
}
});
alertDialog.show();
}
use of net.osmand.plus.poi.PoiUIFilter in project Osmand by osmandapp.
the class SearchPoiFilterFragment method onListItemClick.
@Override
public void onListItemClick(ListView listView, View v, int position, long id) {
final Object item = getListAdapter().getItem(position);
ResourceManager rm = getApp().getResourceManager();
if (!rm.containsAmenityRepositoryToSearch(false)) {
Toast.makeText(getActivity(), R.string.data_to_search_poi_not_available, Toast.LENGTH_LONG);
return;
}
if (item instanceof PoiUIFilter) {
PoiUIFilter model = ((PoiUIFilter) item);
if (PoiUIFilter.BY_NAME_FILTER_ID.equals(model.getFilterId()) || model instanceof NominatimPoiFilter) {
model.setFilterByName(searchEditText.getText().toString());
} else {
model.setFilterByName(model.getSavedFilterByName());
}
showFilterActivity(model.getFilterId());
} else {
PoiUIFilter custom = getApp().getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + ((AbstractPoiType) item).getKeyName());
if (custom != null) {
if (item instanceof PoiType && ((PoiType) item).isAdditional()) {
// it is already set
} else {
custom.setFilterByName(null);
}
custom.clearFilter();
custom.updateTypesToAccept(((AbstractPoiType) item));
showFilterActivity(custom.getFilterId());
}
}
}
Aggregations