Search in sources :

Example 31 with PoiType

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

the class AdvancedEditPoiFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_edit_poi_advanced, container, false);
    deleteDrawable = getPaintedContentIcon(R.drawable.ic_action_remove_dark, getActivity().getResources().getColor(R.color.dash_search_icon_dark));
    nameTextView = (TextView) view.findViewById(R.id.nameTextView);
    amenityTagTextView = (TextView) view.findViewById(R.id.amenityTagTextView);
    amenityTextView = (TextView) view.findViewById(R.id.amenityTextView);
    LinearLayout editTagsLineaLayout = (LinearLayout) view.findViewById(R.id.editTagsList);
    final MapPoiTypes mapPoiTypes = getMyApplication().getPoiTypes();
    mAdapter = new TagAdapterLinearLayoutHack(editTagsLineaLayout, getData());
    // It is possible to not restart initialization every time, and probably move initialization to appInit
    Map<String, PoiType> translatedTypes = getData().getAllTranslatedSubTypes();
    HashSet<String> tagKeys = new HashSet<>();
    HashSet<String> valueKeys = new HashSet<>();
    for (AbstractPoiType abstractPoiType : translatedTypes.values()) {
        addPoiToStringSet(abstractPoiType, tagKeys, valueKeys);
    }
    addPoiToStringSet(mapPoiTypes.getOtherMapCategory(), tagKeys, valueKeys);
    mAdapter.setTagData(tagKeys.toArray(new String[tagKeys.size()]));
    mAdapter.setValueData(valueKeys.toArray(new String[valueKeys.size()]));
    Button addTagButton = (Button) view.findViewById(R.id.addTagButton);
    addTagButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mAdapter.addTagView("", "");
        }
    });
    return view;
}
Also used : AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) AbstractPoiType(net.osmand.osm.AbstractPoiType) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) MapPoiTypes(net.osmand.osm.MapPoiTypes) ImageButton(android.widget.ImageButton) Button(android.widget.Button) LinearLayout(android.widget.LinearLayout) HashSet(java.util.HashSet) Nullable(android.support.annotation.Nullable)

Example 32 with PoiType

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

the class AdvancedEditPoiFragment method updatePoiType.

private void updatePoiType() {
    PoiType pt = getData().getPoiTypeDefined();
    if (pt != null) {
        amenityTagTextView.setText(pt.getOsmTag());
        amenityTextView.setText(pt.getOsmValue());
    } else {
        amenityTagTextView.setText(getData().getPoiCategory().getDefaultTag());
        amenityTextView.setText(getData().getPoiTypeString());
    }
}
Also used : AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType)

Example 33 with PoiType

use of net.osmand.osm.PoiType 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 34 with PoiType

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

the class OpenstreetmapRemoteUtil method loadNode.

@Override
public Node loadNode(Amenity n) {
    if (n.getId() % 2 == 1) {
        // that's way id
        return null;
    }
    long nodeId = n.getId() >> 1;
    try {
        String res = sendRequest(getSiteApi() + "api/0.6/node/" + nodeId, "GET", null, ctx.getString(R.string.loading_poi_obj) + nodeId, // $NON-NLS-1$ //$NON-NLS-2$
        false);
        if (res != null) {
            OsmBaseStorage st = new OsmBaseStorage();
            st.setConvertTagsToLC(false);
            // $NON-NLS-1$
            st.parseOSM(new ByteArrayInputStream(res.getBytes("UTF-8")), null, null, true);
            EntityId id = new Entity.EntityId(EntityType.NODE, nodeId);
            Node entity = (Node) st.getRegisteredEntities().get(id);
            entityInfo = st.getRegisteredEntityInfo().get(id);
            entityInfoId = id;
            // check whether this is node (because id of node could be the same as relation)
            if (entity != null && MapUtils.getDistance(entity.getLatLon(), n.getLocation()) < 50) {
                PoiType poiType = n.getType().getPoiTypeByKeyName(n.getSubType());
                if (poiType.getOsmValue().equals(entity.getTag(poiType.getOsmTag()))) {
                    entity.removeTag(poiType.getOsmTag());
                    entity.putTagNoLC(EditPoiData.POI_TYPE_TAG, poiType.getTranslation());
                } else {
                // later we could try to determine tags
                }
                return entity;
            }
            return null;
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        log.error("Loading node failed " + nodeId, e);
        ctx.runInUIThread(new Runnable() {

            @Override
            public void run() {
                Toast.makeText(ctx, ctx.getResources().getString(R.string.shared_string_io_error), Toast.LENGTH_LONG).show();
            }
        });
    }
    return null;
}
Also used : EntityId(net.osmand.osm.edit.Entity.EntityId) ByteArrayInputStream(java.io.ByteArrayInputStream) OsmBaseStorage(net.osmand.osm.io.OsmBaseStorage) Node(net.osmand.osm.edit.Node) PoiType(net.osmand.osm.PoiType) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 35 with PoiType

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

the class AmenityMenuBuilder method getPoiAdditionalCollapsableView.

private CollapsableView getPoiAdditionalCollapsableView(final Context context, boolean collapsed, @NonNull final List<PoiType> categoryTypes, AmenityInfoRow textCuisineRow) {
    final List<TextViewEx> buttons = new ArrayList<>();
    LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, true);
    for (final PoiType pt : categoryTypes) {
        TextViewEx button = buildButtonInCollapsableView(context, false, false);
        String name = pt.getTranslation();
        button.setText(name);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (amenity.getType() != null) {
                    PoiUIFilter filter = app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + amenity.getType().getKeyName());
                    if (filter != null) {
                        filter.clearFilter();
                        filter.setTypeToAccept(amenity.getType(), true);
                        filter.updateTypesToAccept(pt);
                        filter.setFilterByName(pt.getKeyName().replace('_', ':').toLowerCase());
                        getMapActivity().showQuickSearch(filter);
                    }
                }
            }
        });
        buttons.add(button);
        if (buttons.size() > 3 && categoryTypes.size() > 4) {
            button.setVisibility(View.GONE);
        }
        view.addView(button);
    }
    if (textCuisineRow != null) {
        TextViewEx button = buildButtonInCollapsableView(context, true, false, false);
        String name = textCuisineRow.textPrefix + ": " + textCuisineRow.text.toLowerCase();
        button.setText(name);
        view.addView(button);
    }
    if (categoryTypes.size() > 4) {
        final TextViewEx button = buildButtonInCollapsableView(context, false, true);
        button.setText(context.getString(R.string.shared_string_show_all));
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                for (TextViewEx b : buttons) {
                    if (b.getVisibility() != View.VISIBLE) {
                        b.setVisibility(View.VISIBLE);
                    }
                }
                button.setVisibility(View.GONE);
            }
        });
        view.addView(button);
    }
    return new CollapsableView(view, this, collapsed);
}
Also used : TextViewEx(net.osmand.plus.widgets.TextViewEx) ArrayList(java.util.ArrayList) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Aggregations

PoiType (net.osmand.osm.PoiType)49 AbstractPoiType (net.osmand.osm.AbstractPoiType)30 PoiCategory (net.osmand.osm.PoiCategory)11 MapPoiTypes (net.osmand.osm.MapPoiTypes)10 View (android.view.View)8 TextView (android.widget.TextView)8 Map (java.util.Map)8 Amenity (net.osmand.data.Amenity)8 ArrayList (java.util.ArrayList)7 LinkedHashMap (java.util.LinkedHashMap)7 AdapterView (android.widget.AdapterView)5 HashMap (java.util.HashMap)5 List (java.util.List)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)5 AutoCompleteTextView (android.widget.AutoCompleteTextView)4 LinkedHashSet (java.util.LinkedHashSet)4 LatLon (net.osmand.data.LatLon)4 PoiFilter (net.osmand.osm.PoiFilter)4 Node (net.osmand.osm.edit.Node)4