Search in sources :

Example 11 with PoiUIFilter

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();
}
Also used : OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) PoiType(net.osmand.osm.PoiType) MenuItem(android.view.MenuItem) IconsCache(net.osmand.plus.IconsCache) TreeMap(java.util.TreeMap) PopupMenu(android.support.v7.widget.PopupMenu) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Example 12 with PoiUIFilter

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();
    }
}
Also used : PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Example 13 with PoiUIFilter

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();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) ContextMenuItem(net.osmand.plus.ContextMenuItem) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) PoiFiltersHelper(net.osmand.plus.poi.PoiFiltersHelper) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ListView(android.widget.ListView) Button(android.widget.Button)

Example 14 with PoiUIFilter

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();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) ContextMenuItem(net.osmand.plus.ContextMenuItem) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) PoiFiltersHelper(net.osmand.plus.poi.PoiFiltersHelper) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) Button(android.widget.Button)

Example 15 with PoiUIFilter

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());
        }
    }
}
Also used : NominatimPoiFilter(net.osmand.plus.poi.NominatimPoiFilter) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) ResourceManager(net.osmand.plus.resources.ResourceManager) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Aggregations

PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)28 ArrayList (java.util.ArrayList)12 PoiFiltersHelper (net.osmand.plus.poi.PoiFiltersHelper)8 TextView (android.widget.TextView)7 OsmandApplication (net.osmand.plus.OsmandApplication)7 DialogInterface (android.content.DialogInterface)6 AlertDialog (android.support.v7.app.AlertDialog)6 View (android.view.View)5 AbstractPoiType (net.osmand.osm.AbstractPoiType)5 PoiType (net.osmand.osm.PoiType)5 SearchResult (net.osmand.search.core.SearchResult)5 SpannableString (android.text.SpannableString)4 Button (android.widget.Button)4 LinearLayout (android.widget.LinearLayout)4 Drawable (android.graphics.drawable.Drawable)3 AdapterView (android.widget.AdapterView)3 EditText (android.widget.EditText)3 ImageView (android.widget.ImageView)3 ListView (android.widget.ListView)3 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)3