Search in sources :

Example 16 with PoiCategory

use of net.osmand.osm.PoiCategory in project Osmand by osmandapp.

the class EditPoiDialogFragment method setAdapterForPoiTypeEditText.

private void setAdapterForPoiTypeEditText() {
    final Map<String, PoiType> subCategories = new LinkedHashMap<>();
    PoiCategory ct = editPoiData.getPoiCategory();
    if (ct != null) {
        for (PoiType s : ct.getPoiTypes()) {
            if (!s.isReference() && !s.isNotEditableOsm() && s.getBaseLangType() == null) {
                addMapEntryAdapter(subCategories, s.getTranslation(), s);
                if (!s.getKeyName().contains("osmand")) {
                    addMapEntryAdapter(subCategories, s.getKeyName().replace('_', ' '), s);
                }
            }
        }
    }
    for (Map.Entry<String, PoiType> s : editPoiData.getAllTranslatedSubTypes().entrySet()) {
        addMapEntryAdapter(subCategories, s.getKey(), s.getValue());
    }
    final ArrayAdapter<Object> adapter;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        adapter = new ArrayAdapter<>(getActivity(), R.layout.list_textview, subCategories.keySet().toArray());
    } else {
        TypedValue typedValue = new TypedValue();
        Resources.Theme theme = getActivity().getTheme();
        theme.resolveAttribute(android.R.attr.textColorSecondary, typedValue, true);
        final int textColor = typedValue.data;
        adapter = new ArrayAdapter<Object>(getActivity(), R.layout.list_textview, subCategories.keySet().toArray()) {

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                final View view = super.getView(position, convertView, parent);
                ((TextView) view.findViewById(R.id.textView)).setTextColor(textColor);
                return view;
            }
        };
    }
    adapter.sort(new Comparator<Object>() {

        @Override
        public int compare(Object lhs, Object rhs) {
            return lhs.toString().compareTo(rhs.toString());
        }
    });
    poiTypeEditText.setAdapter(adapter);
    poiTypeEditText.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Object item = parent.getAdapter().getItem(position);
            poiTypeEditText.setText(item.toString());
            setAdapterForPoiTypeEditText();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
}
Also used : ViewGroup(android.view.ViewGroup) PoiType(net.osmand.osm.PoiType) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) LinkedHashMap(java.util.LinkedHashMap) PoiCategory(net.osmand.osm.PoiCategory) CallbackWithObject(net.osmand.CallbackWithObject) AdapterView(android.widget.AdapterView) Resources(android.content.res.Resources) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TypedValue(android.util.TypedValue)

Example 17 with PoiCategory

use of net.osmand.osm.PoiCategory in project Osmand by osmandapp.

the class FavouritePointMenuBuilder method findAmenity.

private Amenity findAmenity(String nameStringEn, double lat, double lon) {
    QuadRect rect = MapUtils.calculateLatLonBbox(lat, lon, 15);
    List<Amenity> amenities = app.getResourceManager().searchAmenities(new BinaryMapIndexReader.SearchPoiTypeFilter() {

        @Override
        public boolean accept(PoiCategory type, String subcategory) {
            return true;
        }

        @Override
        public boolean isEmpty() {
            return false;
        }
    }, rect.top, rect.left, rect.bottom, rect.right, -1, null);
    for (Amenity amenity : amenities) {
        String stringEn = amenity.toStringEn();
        if (stringEn.equals(nameStringEn)) {
            return amenity;
        }
    }
    return null;
}
Also used : Amenity(net.osmand.data.Amenity) PoiCategory(net.osmand.osm.PoiCategory) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) QuadRect(net.osmand.data.QuadRect)

Example 18 with PoiCategory

use of net.osmand.osm.PoiCategory in project Osmand by osmandapp.

the class AmenityMenuController method addTypeMenuItem.

public static void addTypeMenuItem(Amenity amenity, MenuBuilder builder) {
    String typeStr = getTypeStr(amenity);
    if (!Algorithms.isEmpty(typeStr)) {
        int resId = getRightIconId(amenity);
        if (resId == 0) {
            PoiCategory pc = amenity.getType();
            resId = RenderingIcons.getBigIconResourceId(pc.getIconKeyName());
        }
        if (resId == 0) {
            resId = R.drawable.ic_action_folder_stroke;
        }
        builder.addPlainMenuItem(resId, typeStr, false, false, null);
    }
}
Also used : PoiCategory(net.osmand.osm.PoiCategory)

Example 19 with PoiCategory

use of net.osmand.osm.PoiCategory in project Osmand by osmandapp.

the class AmenityMenuController method getTypeStr.

public static String getTypeStr(Amenity amenity) {
    PoiCategory pc = amenity.getType();
    PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType());
    String typeStr = amenity.getSubType();
    if (pt != null) {
        typeStr = pt.getTranslation();
    } else if (typeStr != null) {
        typeStr = Algorithms.capitalizeFirstLetterAndLowercase(typeStr.replace('_', ' '));
    }
    return typeStr;
}
Also used : PoiCategory(net.osmand.osm.PoiCategory) PoiType(net.osmand.osm.PoiType)

Example 20 with PoiCategory

use of net.osmand.osm.PoiCategory in project Osmand by osmandapp.

the class QuickSearchCustomPoiFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final OsmandApplication app = getMyApplication();
    helper = app.getPoiFilters();
    if (getArguments() != null) {
        filterId = getArguments().getString(QUICK_SEARCH_CUSTOM_POI_FILTER_ID_KEY);
    } else if (savedInstanceState != null) {
        filterId = savedInstanceState.getString(QUICK_SEARCH_CUSTOM_POI_FILTER_ID_KEY);
    }
    if (filterId != null) {
        filter = helper.getFilterById(filterId);
    }
    if (filter == null) {
        filter = helper.getCustomPOIFilter();
        filter.clearFilter();
    }
    editMode = !filterId.equals(helper.getCustomPOIFilter().getFilterId());
    view = inflater.inflate(R.layout.search_custom_poi, container, false);
    Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    toolbar.setNavigationIcon(app.getIconsCache().getIcon(R.drawable.ic_action_remove_dark));
    toolbar.setNavigationContentDescription(R.string.shared_string_close);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    TextView title = (TextView) view.findViewById(R.id.title);
    if (editMode) {
        title.setText(filter.getName());
    }
    listView = (ListView) view.findViewById(android.R.id.list);
    listView.setBackgroundColor(getResources().getColor(app.getSettings().isLightContent() ? R.color.ctx_menu_info_view_bg_light : R.color.ctx_menu_info_view_bg_dark));
    View header = getLayoutInflater(savedInstanceState).inflate(R.layout.list_shadow_header, null);
    listView.addHeaderView(header, null, false);
    View footer = inflater.inflate(R.layout.list_shadow_footer, listView, false);
    listView.addFooterView(footer, null, false);
    listAdapter = new CategoryListAdapter(app, app.getPoiTypes().getCategories(false));
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            PoiCategory category = listAdapter.getItem(position - listView.getHeaderViewsCount());
            showDialog(category, false);
        }
    });
    bottomBarShadow = view.findViewById(R.id.bottomBarShadow);
    bottomBar = view.findViewById(R.id.bottomBar);
    barTitle = (TextView) view.findViewById(R.id.barTitle);
    barButton = (TextView) view.findViewById(R.id.barButton);
    bottomBar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
            QuickSearchDialogFragment quickSearchDialogFragment = getQuickSearchDialogFragment();
            if (quickSearchDialogFragment != null) {
                quickSearchDialogFragment.showFilter(filterId);
            }
        }
    });
    return view;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) View(android.view.View) AdapterView(android.widget.AdapterView) AppCompatImageView(android.support.v7.widget.AppCompatImageView) AppCompatTextView(android.support.v7.widget.AppCompatTextView) TextView(android.widget.TextView) ListView(android.widget.ListView) PoiCategory(net.osmand.osm.PoiCategory) AppCompatTextView(android.support.v7.widget.AppCompatTextView) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

PoiCategory (net.osmand.osm.PoiCategory)29 PoiType (net.osmand.osm.PoiType)11 Amenity (net.osmand.data.Amenity)9 AbstractPoiType (net.osmand.osm.AbstractPoiType)9 MapPoiTypes (net.osmand.osm.MapPoiTypes)6 View (android.view.View)5 NonNull (android.support.annotation.NonNull)4 AdapterView (android.widget.AdapterView)4 TextView (android.widget.TextView)4 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)4 QuadRect (net.osmand.data.QuadRect)4 OsmandApplication (net.osmand.plus.OsmandApplication)4 DialogInterface (android.content.DialogInterface)3 AlertDialog (android.support.v7.app.AlertDialog)3 AutoCompleteTextView (android.widget.AutoCompleteTextView)3 Button (android.widget.Button)3 PoiFilter (net.osmand.osm.PoiFilter)3 CustomSearchPoiFilter (net.osmand.search.core.CustomSearchPoiFilter)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2