use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class QuickSearchDialogFragment method completeQueryWithObject.
public void completeQueryWithObject(SearchResult sr) {
if (sr.object instanceof PoiType && ((PoiType) sr.object).isAdditional()) {
PoiType additional = (PoiType) sr.object;
AbstractPoiType parent = additional.getParentType();
if (parent != null) {
PoiUIFilter custom = app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + parent.getKeyName());
if (custom != null) {
custom.clearFilter();
custom.updateTypesToAccept(parent);
custom.setFilterByName(additional.getKeyName().replace('_', ':').toLowerCase());
SearchPhrase phrase = searchUICore.getPhrase();
sr = new SearchResult(phrase);
sr.localeName = custom.getName();
sr.object = custom;
sr.priority = SEARCH_AMENITY_TYPE_PRIORITY;
sr.priorityDistance = 0;
sr.objectType = ObjectType.POI_TYPE;
}
}
}
searchUICore.selectSearchResult(sr);
if (addressSearch) {
startAddressSearch();
if (sr.objectType == ObjectType.CITY) {
if (sr.relatedObject != null && sr.relatedObject instanceof BinaryMapIndexReader) {
File f = ((BinaryMapIndexReader) sr.relatedObject).getFile();
if (f != null) {
RegionAddressRepository region = app.getResourceManager().getRegionRepository(f.getName());
if (region != null) {
app.getSettings().setLastSearchedRegion(region.getFileName(), region.getEstimatedRegionCenter());
City city = (City) sr.object;
app.getSettings().setLastSearchedCity(city.getId(), sr.localeName, city.getLocation());
}
}
}
}
}
String txt = searchUICore.getPhrase().getText(true);
replaceQueryWithText(txt);
if (sr.objectType == ObjectType.CITY) {
openKeyboard();
}
}
use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class QuickSearchPoiFilterFragment method getListItems.
private List<PoiFilterListItem> getListItems() {
OsmandApplication app = getMyApplication();
MapPoiTypes poiTypes = app.getPoiTypes();
int groupId = 0;
List<PoiFilterListItem> items = new ArrayList<>();
Map<String, PoiType> poiAdditionals = filter.getPoiAdditionals();
Set<String> excludedPoiAdditionalCategories = getExcludedPoiAdditionalCategories();
List<PoiType> otherAdditionalCategories = poiTypes.getOtherMapCategory().getPoiAdditionalsCategorized();
if (!excludedPoiAdditionalCategories.contains("opening_hours")) {
items.add(new PoiFilterListItem(PoiFilterListItemType.DIVIDER, 0, null, -1, false, false, false, null, null));
String keyNameOpen = app.getString(R.string.shared_string_is_open).replace(' ', '_').toLowerCase();
items.add(new PoiFilterListItem(PoiFilterListItemType.SWITCH_ITEM, R.drawable.ic_action_time, app.getString(R.string.shared_string_is_open), ++groupId, false, false, selectedPoiAdditionals.contains(keyNameOpen), null, keyNameOpen));
String keyNameOpen24 = app.getString(R.string.shared_string_is_open_24_7).replace(' ', '_').toLowerCase();
items.add(new PoiFilterListItem(PoiFilterListItemType.SWITCH_ITEM, 0, app.getString(R.string.shared_string_is_open_24_7), groupId, false, false, selectedPoiAdditionals.contains(keyNameOpen24), null, keyNameOpen24));
}
if (poiAdditionals != null) {
Map<String, List<PoiType>> additionalsMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
extractPoiAdditionals(poiAdditionals.values(), additionalsMap, excludedPoiAdditionalCategories, false);
extractPoiAdditionals(otherAdditionalCategories, additionalsMap, excludedPoiAdditionalCategories, false);
if (additionalsMap.size() > 0) {
for (Entry<String, List<PoiType>> entry : additionalsMap.entrySet()) {
String category = entry.getKey();
String categoryLocalizedName = poiTypes.getPoiTranslation(category);
boolean expanded = !collapsedCategories.contains(category);
boolean showAll = showAllCategories.contains(category);
items.add(new PoiFilterListItem(PoiFilterListItemType.DIVIDER, 0, null, -1, false, false, false, null, null));
String categoryIconStr = poiTypes.getPoiAdditionalCategoryIconName(category);
int categoryIconId = 0;
if (!Algorithms.isEmpty(categoryIconStr)) {
categoryIconId = RenderingIcons.getBigIconResourceId(categoryIconStr);
}
if (categoryIconId == 0) {
categoryIconId = getResources().getIdentifier("mx_" + category, "drawable", app.getPackageName());
}
if (categoryIconId == 0) {
categoryIconId = R.drawable.ic_action_folder_stroke;
}
items.add(new PoiFilterListItem(PoiFilterListItemType.GROUP_HEADER, categoryIconId, categoryLocalizedName, ++groupId, true, expanded, false, category, null));
List<PoiType> categoryPoiAdditionals = new ArrayList<>(entry.getValue());
Collections.sort(categoryPoiAdditionals, new Comparator<PoiType>() {
@Override
public int compare(PoiType p1, PoiType p2) {
String firstPoiTypeTranslation = poiAdditionalsTranslations.get(p1);
String secondPoiTypeTranslation = poiAdditionalsTranslations.get(p2);
if (firstPoiTypeTranslation != null && secondPoiTypeTranslation != null) {
return firstPoiTypeTranslation.compareTo(secondPoiTypeTranslation);
} else {
return 0;
}
}
});
for (PoiType poiType : categoryPoiAdditionals) {
String keyName = poiType.getKeyName().replace('_', ':').toLowerCase();
String translation = poiAdditionalsTranslations.get(poiType);
items.add(new PoiFilterListItem(PoiFilterListItemType.CHECKBOX_ITEM, 0, translation, groupId, false, false, selectedPoiAdditionals.contains(keyName), category, keyName));
}
if (!showAll && categoryPoiAdditionals.size() > 0) {
items.add(new PoiFilterListItem(PoiFilterListItemType.BUTTON_ITEM, 0, app.getString(R.string.shared_string_show_all).toUpperCase(), groupId, false, false, false, category, null));
}
}
}
}
return items;
}
use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class AddPOIAction method setUpAdapterForPoiTypeEditText.
private void setUpAdapterForPoiTypeEditText(final MapActivity activity, final Map<String, PoiType> allTranslatedNames, final AutoCompleteTextView poiTypeEditText) {
final Map<String, PoiType> subCategories = new LinkedHashMap<>();
// }
for (Map.Entry<String, PoiType> s : allTranslatedNames.entrySet()) {
addMapEntryAdapter(subCategories, s.getKey(), s.getValue());
}
final ArrayAdapter<Object> adapter;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
adapter = new ArrayAdapter<>(activity, R.layout.list_textview, subCategories.keySet().toArray());
} else {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = activity.getTheme();
theme.resolveAttribute(android.R.attr.textColorSecondary, typedValue, true);
final int textColor = typedValue.data;
adapter = new ArrayAdapter<Object>(activity, 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());
setUpAdapterForPoiTypeEditText(activity, allTranslatedNames, poiTypeEditText);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class AddPOIAction method execute.
@Override
public void execute(final MapActivity activity) {
LatLon latLon = activity.getMapView().getCurrentRotatedTileBox().getCenterLatLon();
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (plugin == null)
return;
Node node = new Node(latLon.getLatitude(), latLon.getLongitude(), -1);
node.replaceTags(getTagsFromParams());
EditPoiData editPoiData = new EditPoiData(node, activity.getMyApplication());
if (Boolean.valueOf(getParams().get(KEY_DIALOG))) {
Node newNode = editPoiData.getEntity();
EditPoiDialogFragment editPoiDialogFragment = EditPoiDialogFragment.createInstance(newNode, true, getTagsFromParams());
editPoiDialogFragment.show(activity.getSupportFragmentManager(), EditPoiDialogFragment.TAG);
} else {
OpenstreetmapUtil mOpenstreetmapUtil;
if (activity.getMyApplication().getSettings().OFFLINE_EDITION.get() || !activity.getMyApplication().getSettings().isInternetConnectionAvailable(true)) {
mOpenstreetmapUtil = plugin.getPoiModificationLocalUtil();
} else {
mOpenstreetmapUtil = plugin.getPoiModificationRemoteUtil();
}
final boolean offlineEdit = mOpenstreetmapUtil instanceof OpenstreetmapLocalUtil;
Node newNode = new Node(node.getLatitude(), node.getLongitude(), node.getId());
OsmPoint.Action action = newNode.getId() < 0 ? OsmPoint.Action.CREATE : OsmPoint.Action.MODIFY;
for (Map.Entry<String, String> tag : editPoiData.getTagValues().entrySet()) {
if (tag.getKey().equals(EditPoiData.POI_TYPE_TAG)) {
final PoiType poiType = editPoiData.getAllTranslatedSubTypes().get(tag.getValue().trim().toLowerCase());
if (poiType != null) {
newNode.putTagNoLC(poiType.getOsmTag(), poiType.getOsmValue());
if (poiType.getOsmTag2() != null) {
newNode.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
}
} else if (!Algorithms.isEmpty(tag.getValue())) {
newNode.putTagNoLC(editPoiData.getPoiCategory().getDefaultTag(), tag.getValue());
}
if (offlineEdit && !Algorithms.isEmpty(tag.getValue())) {
newNode.putTagNoLC(tag.getKey(), tag.getValue());
}
} else if (!Algorithms.isEmpty(tag.getKey()) && !Algorithms.isEmpty(tag.getValue())) {
newNode.putTagNoLC(tag.getKey(), tag.getValue());
}
}
EditPoiDialogFragment.commitNode(action, newNode, mOpenstreetmapUtil.getEntityInfo(newNode.getId()), "", false, new CallbackWithObject<Node>() {
@Override
public boolean processResult(Node result) {
if (result != null) {
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (plugin != null && offlineEdit) {
List<OpenstreetmapPoint> points = plugin.getDBPOI().getOpenstreetmapPoints();
if (activity instanceof MapActivity && points.size() > 0) {
OsmPoint point = points.get(points.size() - 1);
activity.getContextMenu().showOrUpdate(new LatLon(point.getLatitude(), point.getLongitude()), plugin.getOsmEditsLayer(activity).getObjectName(point), point);
}
}
if (activity instanceof MapActivity) {
activity.getMapView().refreshMap(true);
}
} else {
// OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
// mOpenstreetmapUtil = plugin.getPoiModificationLocalUtil();
// Button saveButton = (Button) view.findViewById(R.id.saveButton);
// saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil
// ? R.string.shared_string_upload : R.string.shared_string_save);
}
return false;
}
}, activity, mOpenstreetmapUtil, null);
}
}
use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class AddPOIAction method drawUI.
@Override
public void drawUI(final ViewGroup parent, final MapActivity activity) {
final View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.quick_action_add_poi_layout, parent, false);
final OsmandApplication application = activity.getMyApplication();
Drawable deleteDrawable = application.getIconsCache().getPaintedIcon(R.drawable.ic_action_remove_dark, activity.getResources().getColor(R.color.dash_search_icon_dark));
final LinearLayout editTagsLineaLayout = (LinearLayout) view.findViewById(R.id.editTagsList);
final MapPoiTypes poiTypes = application.getPoiTypes();
final Map<String, PoiType> allTranslatedNames = poiTypes.getAllTranslatedNames(true);
final TagAdapterLinearLayoutHack mAdapter = new TagAdapterLinearLayoutHack(editTagsLineaLayout, getTagsFromParams(), deleteDrawable);
// It is possible to not restart initialization every time, and probably move initialization to appInit
Map<String, PoiType> translatedTypes = poiTypes.getAllTranslatedNames(true);
HashSet<String> tagKeys = new HashSet<>();
HashSet<String> valueKeys = new HashSet<>();
for (AbstractPoiType abstractPoiType : translatedTypes.values()) {
addPoiToStringSet(abstractPoiType, tagKeys, valueKeys);
}
addPoiToStringSet(poiTypes.getOtherMapCategory(), tagKeys, valueKeys);
tagKeys.addAll(EditPoiDialogFragment.BASIC_TAGS);
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) {
for (int i = 0; i < editTagsLineaLayout.getChildCount(); i++) {
View item = editTagsLineaLayout.getChildAt(i);
if (((EditText) item.findViewById(R.id.tagEditText)).getText().toString().isEmpty() && ((EditText) item.findViewById(R.id.valueEditText)).getText().toString().isEmpty())
return;
}
mAdapter.addTagView("", "");
}
});
mAdapter.updateViews();
final TextInputLayout poiTypeTextInputLayout = (TextInputLayout) view.findViewById(R.id.poiTypeTextInputLayout);
final AutoCompleteTextView poiTypeEditText = (AutoCompleteTextView) view.findViewById(R.id.poiTypeEditText);
final SwitchCompat showDialog = (SwitchCompat) view.findViewById(R.id.saveButton);
// showDialog.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
// @Override
// public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// getParams().put(KEY_DIALOG, Boolean.toString(isChecked));
// }
// });
showDialog.setChecked(Boolean.valueOf(getParams().get(KEY_DIALOG)));
final String text = getTagsFromParams().get(POI_TYPE_TAG);
poiTypeEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
String tp = s.toString();
putTagIntoParams(POI_TYPE_TAG, tp);
PoiCategory category = getCategory(allTranslatedNames);
if (category != null) {
poiTypeTextInputLayout.setHint(category.getTranslation());
}
String add = application.getString(R.string.shared_string_add);
if (title != null) {
if (prevType.equals(title.getText().toString()) || title.getText().toString().equals(activity.getString(getNameRes())) || title.getText().toString().equals((add + " "))) {
if (!tp.isEmpty()) {
title.setText(add + " " + tp);
prevType = title.getText().toString();
}
}
}
}
});
poiTypeEditText.setText(text != null ? text : "");
poiTypeEditText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(final View v, MotionEvent event) {
final EditText editText = (EditText) v;
final int DRAWABLE_RIGHT = 2;
if (event.getAction() == MotionEvent.ACTION_UP) {
if (event.getX() >= (editText.getRight() - editText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width() - editText.getPaddingRight())) {
PoiCategory category = getCategory(allTranslatedNames);
PoiCategory tempPoiCategory = (category != null) ? category : poiTypes.getOtherPoiCategory();
PoiSubTypeDialogFragment f = PoiSubTypeDialogFragment.createInstance(tempPoiCategory);
f.setOnItemSelectListener(new PoiSubTypeDialogFragment.OnItemSelectListener() {
@Override
public void select(String category) {
poiTypeEditText.setText(category);
}
});
CreateEditActionDialog parentFragment = (CreateEditActionDialog) activity.getSupportFragmentManager().findFragmentByTag(CreateEditActionDialog.TAG);
f.show(activity.getSupportFragmentManager(), "PoiSubTypeDialogFragment");
return true;
}
}
return false;
}
});
setUpAdapterForPoiTypeEditText(activity, allTranslatedNames, poiTypeEditText);
ImageButton onlineDocumentationButton = (ImageButton) view.findViewById(R.id.onlineDocumentationButton);
onlineDocumentationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://wiki.openstreetmap.org/wiki/Map_Features")));
}
});
boolean isLightTheme = activity.getMyApplication().getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
final int colorId = isLightTheme ? R.color.inactive_item_orange : R.color.dash_search_icon_dark;
final int color = activity.getResources().getColor(colorId);
onlineDocumentationButton.setImageDrawable(activity.getMyApplication().getIconsCache().getPaintedIcon(R.drawable.ic_action_help, color));
// poiTypeEditText.setCompoundDrawables(null, null, activity.getMyApplication().getIconsCache().getPaintedIcon(R.drawable.ic_action_arrow_drop_down, color), null);
// Button addTypeButton = (Button) view.findViewById(R.id.addTypeButton);
// addTypeButton.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// PoiSubTypeDialogFragment f = PoiSubTypeDialogFragment.createInstance(poiTypes.getOtherPoiCategory());
// f.setOnItemSelectListener(new PoiSubTypeDialogFragment.OnItemSelectListener() {
// @Override
// public void select(String category) {
// putTagIntoParams(POI_TYPE_TAG, category);
// }
// });
//
// CreateEditActionDialog parentFragment = (CreateEditActionDialog) activity.getSupportFragmentManager().findFragmentByTag(CreateEditActionDialog.TAG);
// f.show(parentFragment.getChildFragmentManager(), "PoiSubTypeDialogFragment");
// }
// });
parent.addView(view);
}
Aggregations