Search in sources :

Example 21 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class PoiUIFilter method searchAmenities.

public List<Amenity> searchAmenities(double top, double left, double bottom, double right, int zoom, ResultMatcher<Amenity> matcher) {
    List<Amenity> results = new ArrayList<Amenity>();
    List<Amenity> tempResults = currentSearchResult;
    if (tempResults != null) {
        for (Amenity a : tempResults) {
            LatLon l = a.getLocation();
            if (l != null && l.getLatitude() <= top && l.getLatitude() >= bottom && l.getLongitude() >= left && l.getLongitude() <= right) {
                if (matcher == null || matcher.publish(a)) {
                    results.add(a);
                }
            }
        }
    }
    List<Amenity> amenities = searchAmenitiesInternal(top / 2 + bottom / 2, left / 2 + right / 2, top, bottom, left, right, zoom, matcher);
    results.addAll(amenities);
    return results;
}
Also used : Amenity(net.osmand.data.Amenity) LatLon(net.osmand.data.LatLon) ArrayList(java.util.ArrayList)

Example 22 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class PoiUIFilter method getNameFilter.

public AmenityNameFilter getNameFilter(String filter) {
    if (Algorithms.isEmpty(filter)) {
        return new AmenityNameFilter() {

            @Override
            public boolean accept(Amenity a) {
                return true;
            }
        };
    }
    StringBuilder nmFilter = new StringBuilder();
    String[] items = filter.split(" ");
    boolean allTime = false;
    boolean open = false;
    List<PoiType> poiAdditionalsFilter = null;
    for (String s : items) {
        s = s.trim();
        if (!Algorithms.isEmpty(s)) {
            if (getNameToken24H().equalsIgnoreCase(s)) {
                allTime = true;
            } else if (getNameTokenOpen().equalsIgnoreCase(s)) {
                open = true;
            } else if (poiAdditionals.containsKey(s.toLowerCase())) {
                if (poiAdditionalsFilter == null) {
                    poiAdditionalsFilter = new ArrayList<>();
                }
                PoiType pt = poiAdditionals.get(s.toLowerCase());
                if (pt != null) {
                    poiAdditionalsFilter.add(pt);
                }
            } else {
                nmFilter.append(s).append(" ");
            }
        }
    }
    return getNameFilterInternal(nmFilter, allTime, open, poiAdditionalsFilter);
}
Also used : Amenity(net.osmand.data.Amenity) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType)

Example 23 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class PoiUIFilter method updateFilterResults.

public void updateFilterResults() {
    List<Amenity> prev = currentSearchResult;
    if (prev != null) {
        AmenityNameFilter nameFilter = getNameFilter(filterByName);
        List<Amenity> newResults = new ArrayList<Amenity>();
        for (Amenity a : prev) {
            if (nameFilter.accept(a)) {
                newResults.add(a);
            }
        }
        currentSearchResult = newResults;
    }
}
Also used : Amenity(net.osmand.data.Amenity) ArrayList(java.util.ArrayList)

Example 24 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class OsmEditingPlugin method registerMapContextMenuActions.

@Override
public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude, ContextMenuAdapter adapter, final Object 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_create_poi) {
                // getPoiActions(mapActivity).showCreateDialog(latitude, longitude);
                EditPoiDialogFragment editPoiDialogFragment = EditPoiDialogFragment.createAddPoiInstance(latitude, longitude, mapActivity.getMyApplication());
                editPoiDialogFragment.show(mapActivity.getSupportFragmentManager(), EditPoiDialogFragment.TAG);
            } else if (resId == R.string.context_menu_item_open_note) {
                openOsmNote(mapActivity, latitude, longitude);
            } else if (resId == R.string.context_menu_item_modify_note) {
                modifyOsmNote(mapActivity, (OsmNotesPoint) selectedObj);
            } else if (resId == R.string.poi_context_menu_modify) {
                EditPoiDialogFragment.showEditInstance((Amenity) selectedObj, mapActivity);
            } else if (resId == R.string.poi_context_menu_modify_osm_change) {
                final Node entity = ((OpenstreetmapPoint) selectedObj).getEntity();
                EditPoiDialogFragment.createInstance(entity, false).show(mapActivity.getSupportFragmentManager(), EditPoiDialogFragment.TAG);
            }
            return true;
        }
    };
    boolean isEditable = false;
    if (selectedObj instanceof Amenity) {
        Amenity amenity = (Amenity) selectedObj;
        final PoiType poiType = amenity.getType().getPoiTypeByKeyName(amenity.getSubType());
        isEditable = !amenity.getType().isWiki() && poiType != null && !poiType.isNotEditableOsm();
    }
    if (isEditable) {
        adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.poi_context_menu_modify, mapActivity).setIcon(R.drawable.ic_action_edit_dark).setOrder(MODIFY_POI_ITEM_ORDER).setListener(listener).createItem());
    } else if (selectedObj instanceof OpenstreetmapPoint && ((OpenstreetmapPoint) selectedObj).getAction() != Action.DELETE) {
        adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.poi_context_menu_modify_osm_change, mapActivity).setIcon(R.drawable.ic_action_edit_dark).setOrder(MODIFY_OSM_CHANGE_ITEM_ORDER).setListener(listener).createItem());
    } else {
        adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_create_poi, mapActivity).setIcon(R.drawable.ic_action_plus_dark).setOrder(CREATE_POI_ITEM_ORDER).setListener(listener).createItem());
    }
    if (selectedObj instanceof OsmNotesPoint) {
        adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_modify_note, mapActivity).setIcon(R.drawable.ic_action_edit_dark).setOrder(MODIFY_OSM_NOTE_ITEM_ORDER).setListener(listener).createItem());
    } else {
        adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_open_note, mapActivity).setIcon(R.drawable.ic_action_bug_dark).setOrder(OPEN_OSM_NOTE_ITEM_ORDER).setListener(listener).createItem());
    }
}
Also used : Amenity(net.osmand.data.Amenity) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) ContextMenuItem(net.osmand.plus.ContextMenuItem) Node(net.osmand.osm.edit.Node) PoiType(net.osmand.osm.PoiType) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ArrayAdapter(android.widget.ArrayAdapter)

Example 25 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class MenuBuilder method getCollapsableWikiView.

protected View getCollapsableWikiView(Context context, boolean collapsed) {
    final LinearLayout view = new LinearLayout(context);
    view.setOrientation(LinearLayout.VERTICAL);
    view.setVisibility(collapsed ? View.GONE : View.VISIBLE);
    LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    llParams.setMargins(dpToPx(68f), 0, dpToPx(12f), dpToPx(13f));
    view.setLayoutParams(llParams);
    for (final Amenity wiki : nearestWiki) {
        AppCompatButton wikiButton = new AppCompatButton(new ContextThemeWrapper(view.getContext(), R.style.AppTheme));
        LinearLayout.LayoutParams llWikiButtonParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        wikiButton.setLayoutParams(llWikiButtonParams);
        wikiButton.setPadding(dpToPx(14f), 0, dpToPx(14f), 0);
        wikiButton.setTextColor(app.getResources().getColor(light ? R.color.color_dialog_buttons_light : R.color.color_dialog_buttons_dark));
        wikiButton.setText(wiki.getName());
        wikiButton.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
        wikiButton.setSingleLine(true);
        wikiButton.setEllipsize(TextUtils.TruncateAt.END);
        wikiButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                PointDescription pointDescription = MenuController.getObjectName(wiki);
                mainActivity.getContextMenu().show(new LatLon(wiki.getLocation().getLatitude(), wiki.getLocation().getLongitude()), pointDescription, wiki);
            }
        });
        view.addView(wikiButton);
    }
    return view;
}
Also used : Amenity(net.osmand.data.Amenity) LatLon(net.osmand.data.LatLon) ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) PointDescription(net.osmand.core.samples.android.sample1.data.PointDescription) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout) AppCompatButton(android.support.v7.widget.AppCompatButton)

Aggregations

Amenity (net.osmand.data.Amenity)53 LatLon (net.osmand.data.LatLon)17 ArrayList (java.util.ArrayList)11 PoiCategory (net.osmand.osm.PoiCategory)9 AbstractPoiType (net.osmand.osm.AbstractPoiType)8 PoiType (net.osmand.osm.PoiType)8 PointDescription (net.osmand.data.PointDescription)7 Paint (android.graphics.Paint)6 View (android.view.View)6 ImageView (android.widget.ImageView)6 HashMap (java.util.HashMap)6 FavouritePoint (net.osmand.data.FavouritePoint)6 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)5 File (java.io.File)5 Map (java.util.Map)5 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)5 QuadRect (net.osmand.data.QuadRect)5 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 LinearLayout (android.widget.LinearLayout)4