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;
}
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());
}
}
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) {
}
});
}
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;
}
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);
}
Aggregations