use of net.osmand.osm.PoiCategory in project Osmand by osmandapp.
the class QuickSearchListItem method getTypeName.
public static String getTypeName(SampleApplication app, SearchResult searchResult) {
switch(searchResult.objectType) {
case CITY:
City city = (City) searchResult.object;
return getCityTypeStr(app, city.getType());
case POSTCODE:
return app.getString("postcode");
case VILLAGE:
city = (City) searchResult.object;
if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
if (searchResult.distRelatedObjectName > 0) {
return getCityTypeStr(app, city.getType()) + " • " + SampleFormatter.getFormattedDistance((float) searchResult.distRelatedObjectName, app) + " " + app.getString("shared_string_from") + " " + searchResult.localeRelatedObjectName;
} else {
return getCityTypeStr(app, city.getType()) + ", " + searchResult.localeRelatedObjectName;
}
} else {
return getCityTypeStr(app, city.getType());
}
case STREET:
StringBuilder streetBuilder = new StringBuilder();
if (searchResult.localeName.endsWith(")")) {
int i = searchResult.localeName.indexOf('(');
if (i > 0) {
streetBuilder.append(searchResult.localeName.substring(i + 1, searchResult.localeName.length() - 1));
}
}
if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
if (streetBuilder.length() > 0) {
streetBuilder.append(", ");
}
streetBuilder.append(searchResult.localeRelatedObjectName);
}
return streetBuilder.toString();
case HOUSE:
if (searchResult.relatedObject != null) {
Street relatedStreet = (Street) searchResult.relatedObject;
if (relatedStreet.getCity() != null) {
return searchResult.localeRelatedObjectName + ", " + relatedStreet.getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
} else {
return searchResult.localeRelatedObjectName;
}
}
return "";
case STREET_INTERSECTION:
Street street = (Street) searchResult.object;
if (street.getCity() != null) {
return street.getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
}
return "";
case POI_TYPE:
String res = "";
if (searchResult.object instanceof AbstractPoiType) {
AbstractPoiType abstractPoiType = (AbstractPoiType) searchResult.object;
if (abstractPoiType instanceof PoiCategory) {
res = "";
} else if (abstractPoiType instanceof PoiFilter) {
PoiFilter poiFilter = (PoiFilter) abstractPoiType;
res = poiFilter.getPoiCategory() != null ? poiFilter.getPoiCategory().getTranslation() : "";
} else if (abstractPoiType instanceof PoiType) {
PoiType poiType = (PoiType) abstractPoiType;
res = poiType.getParentType() != null ? poiType.getParentType().getTranslation() : null;
if (res == null) {
res = poiType.getCategory() != null ? poiType.getCategory().getTranslation() : null;
}
if (res == null) {
res = "";
}
} else {
res = "";
}
} else if (searchResult.object instanceof CustomSearchPoiFilter) {
res = ((CustomSearchPoiFilter) searchResult.object).getName();
}
return res;
case POI:
Amenity amenity = (Amenity) searchResult.object;
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;
case LOCATION:
LatLon latLon = searchResult.location;
if (searchResult.localeRelatedObjectName == null) {
String locationCountry = app.getRegions().getCountryName(latLon);
searchResult.localeRelatedObjectName = locationCountry == null ? "" : locationCountry;
}
return searchResult.localeRelatedObjectName;
case REGION:
BinaryMapIndexReader binaryMapIndexReader = (BinaryMapIndexReader) searchResult.object;
System.out.println(binaryMapIndexReader.getFile().getAbsolutePath() + " " + binaryMapIndexReader.getCountryName());
break;
case UNKNOWN_NAME_FILTER:
break;
}
return searchResult.objectType.name();
}
use of net.osmand.osm.PoiCategory in project Osmand by osmandapp.
the class BinaryMapPoiReaderAdapter method checkCategories.
private boolean checkCategories(SearchRequest<Amenity> req, PoiRegion region) throws IOException {
StringBuilder subType = new StringBuilder();
while (true) {
int t = codedIS.readTag();
int tag = WireFormat.getTagFieldNumber(t);
switch(tag) {
case 0:
return false;
// break;
case OsmandOdb.OsmAndPoiCategories.CATEGORIES_FIELD_NUMBER:
PoiCategory type = poiTypes.getOtherPoiCategory();
String subtype = "";
int cat = codedIS.readUInt32();
int subcatId = cat >> SHIFT_BITS_CATEGORY;
int catId = cat & CATEGORY_MASK;
if (catId < region.categoriesType.size()) {
type = region.categoriesType.get(catId);
List<String> subcats = region.subcategories.get(catId);
if (subcatId < subcats.size()) {
subtype = subcats.get(subcatId);
}
}
subtype = poiTypes.replaceDeprecatedSubtype(type, subtype);
if (req.poiTypeFilter.accept(type, subtype)) {
codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
return true;
}
break;
default:
skipUnknownField(t);
break;
}
}
}
use of net.osmand.osm.PoiCategory in project Osmand by osmandapp.
the class BinaryMapPoiReaderAdapter method readPoiPoint.
private Amenity readPoiPoint(int left31, int right31, int top31, int bottom31, int px, int py, int zoom, SearchRequest<Amenity> req, PoiRegion region, boolean checkBounds) throws IOException {
Amenity am = null;
int x = 0;
int y = 0;
StringBuilder retValue = new StringBuilder();
PoiCategory amenityType = null;
LinkedList<String> textTags = null;
while (true) {
int t = codedIS.readTag();
int tag = WireFormat.getTagFieldNumber(t);
if (amenityType == null && (tag > OsmandOdb.OsmAndPoiBoxDataAtom.CATEGORIES_FIELD_NUMBER || tag == 0)) {
codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
return null;
}
switch(tag) {
case 0:
req.numberOfAcceptedObjects++;
if (req.radius > 0) {
LatLon loc = am.getLocation();
List<Location> locs = req.tiles.get(req.getTileHashOnPath(loc.getLatitude(), loc.getLongitude()));
if (locs == null) {
return null;
}
AmenityRoutePoint arp = dist(am.getLocation(), locs, req.radius);
if (arp == null) {
return null;
} else {
am.setRoutePoint(arp);
}
}
return am;
case OsmandOdb.OsmAndPoiBoxDataAtom.DX_FIELD_NUMBER:
x = (codedIS.readSInt32() + (px << (24 - zoom))) << 7;
break;
case OsmandOdb.OsmAndPoiBoxDataAtom.DY_FIELD_NUMBER:
y = (codedIS.readSInt32() + (py << (24 - zoom))) << 7;
req.numberOfVisitedObjects++;
if (checkBounds) {
if (left31 > x || right31 < x || top31 > y || bottom31 < y) {
codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
return null;
}
}
am = new Amenity();
am.setLocation(MapUtils.get31LatitudeY(y), MapUtils.get31LongitudeX(x));
break;
case OsmandOdb.OsmAndPoiBoxDataAtom.SUBCATEGORIES_FIELD_NUMBER:
int subtypev = codedIS.readUInt32();
retValue.setLength(0);
PoiSubType st = region.getSubtypeFromId(subtypev, retValue);
if (st != null) {
am.setAdditionalInfo(st.name, retValue.toString());
}
break;
case OsmandOdb.OsmAndPoiBoxDataAtom.TEXTCATEGORIES_FIELD_NUMBER:
int texttypev = codedIS.readUInt32();
retValue.setLength(0);
PoiSubType textt = region.getSubtypeFromId(texttypev, retValue);
if (textt != null && textt.text) {
if (textTags == null) {
textTags = new LinkedList<String>();
}
textTags.add(textt.name);
}
break;
case OsmandOdb.OsmAndPoiBoxDataAtom.TEXTVALUES_FIELD_NUMBER:
String str = codedIS.readString();
if (textTags != null && !textTags.isEmpty()) {
am.setAdditionalInfo(textTags.poll(), str);
}
break;
case OsmandOdb.OsmAndPoiBoxDataAtom.CATEGORIES_FIELD_NUMBER:
int cat = codedIS.readUInt32();
int subcatId = cat >> SHIFT_BITS_CATEGORY;
int catId = cat & CATEGORY_MASK;
PoiCategory type = poiTypes.getOtherPoiCategory();
String subtype = "";
if (catId < region.categoriesType.size()) {
type = region.categoriesType.get(catId);
List<String> subcats = region.subcategories.get(catId);
if (subcatId < subcats.size()) {
subtype = subcats.get(subcatId);
}
}
subtype = poiTypes.replaceDeprecatedSubtype(type, subtype);
if (req.poiTypeFilter == null || req.poiTypeFilter.accept(type, subtype)) {
if (amenityType == null) {
amenityType = type;
am.setSubType(subtype);
am.setType(amenityType);
} else {
am.setSubType(am.getSubType() + ";" + subtype);
}
}
break;
case OsmandOdb.OsmAndPoiBoxDataAtom.ID_FIELD_NUMBER:
am.setId(codedIS.readUInt64());
break;
case OsmandOdb.OsmAndPoiBoxDataAtom.NAME_FIELD_NUMBER:
am.setName(codedIS.readString());
break;
case OsmandOdb.OsmAndPoiBoxDataAtom.NAMEEN_FIELD_NUMBER:
am.setEnName(codedIS.readString());
break;
case OsmandOdb.OsmAndPoiBoxDataAtom.OPENINGHOURS_FIELD_NUMBER:
am.setOpeningHours(codedIS.readString());
break;
case OsmandOdb.OsmAndPoiBoxDataAtom.SITE_FIELD_NUMBER:
am.setSite(codedIS.readString());
break;
case OsmandOdb.OsmAndPoiBoxDataAtom.PHONE_FIELD_NUMBER:
am.setPhone(codedIS.readString());
break;
case OsmandOdb.OsmAndPoiBoxDataAtom.NOTE_FIELD_NUMBER:
am.setDescription(codedIS.readString());
break;
default:
skipUnknownField(t);
break;
}
}
}
use of net.osmand.osm.PoiCategory in project Osmand by osmandapp.
the class PoiSubTypeDialogFragment method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
MapPoiTypes poiTypes = ((OsmandApplication) getActivity().getApplication()).getPoiTypes();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final PoiCategory a = poiTypes.getPoiCategoryByName((String) getArguments().getSerializable(KEY_POI_CATEGORY));
Set<String> strings = new TreeSet<>();
if (a == poiTypes.getOtherPoiCategory()) {
for (PoiCategory category : poiTypes.getCategories(false)) {
if (!category.isNotEditableOsm()) {
addCategory(category, strings);
}
}
} else {
addCategory(a, strings);
}
final String[] subCats = strings.toArray(new String[strings.size()]);
builder.setItems(subCats, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
onItemSelectListener.select(subCats[which]);
dismiss();
}
});
return builder.create();
}
use of net.osmand.osm.PoiCategory in project Osmand by osmandapp.
the class EditPoiDialogFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_edit_poi, container, false);
boolean isLightTheme = getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
if (savedInstanceState != null) {
@SuppressWarnings("unchecked") Map<String, String> mp = (Map<String, String>) savedInstanceState.getSerializable(TAGS_LIST);
editPoiData.updateTags(mp);
}
boolean isAddingPoi = getArguments().getBoolean(IS_ADDING_POI);
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
toolbar.setTitle(isAddingPoi ? R.string.poi_create_title : R.string.poi_edit_title);
toolbar.setNavigationIcon(R.drawable.ic_arrow_back);
toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismissCheckForChanges();
}
});
viewPager = (ViewPager) view.findViewById(R.id.viewpager);
String basicTitle = getResources().getString(R.string.tab_title_basic);
String extendedTitle = getResources().getString(R.string.tab_title_advanced);
final MyAdapter pagerAdapter = new MyAdapter(getChildFragmentManager(), basicTitle, extendedTitle);
viewPager.setAdapter(pagerAdapter);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int i, float v, int i1) {
}
@Override
public void onPageSelected(int i) {
((OnFragmentActivatedListener) pagerAdapter.getItem(i)).onFragmentActivated();
}
@Override
public void onPageScrollStateChanged(int i) {
}
});
final TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tab_layout);
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
// TODO remove in new version
if (Build.VERSION.SDK_INT >= 11) {
if (ViewCompat.isLaidOut(tabLayout)) {
tabLayout.setupWithViewPager(viewPager);
} else {
tabLayout.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
tabLayout.setupWithViewPager(viewPager);
tabLayout.removeOnLayoutChangeListener(this);
}
});
}
} else {
ViewTreeObserver vto = view.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
ViewTreeObserver obs = view.getViewTreeObserver();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
obs.removeGlobalOnLayoutListener(this);
}
if (getActivity() != null) {
tabLayout.setupWithViewPager(viewPager);
}
}
});
}
ImageButton onlineDocumentationButton = (ImageButton) view.findViewById(R.id.onlineDocumentationButton);
onlineDocumentationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://wiki.openstreetmap.org/wiki/Map_Features")));
}
});
final int colorId = isLightTheme ? R.color.inactive_item_orange : R.color.dash_search_icon_dark;
final int color = getResources().getColor(colorId);
onlineDocumentationButton.setImageDrawable(getPaintedContentIcon(R.drawable.ic_action_help, color));
final ImageButton poiTypeButton = (ImageButton) view.findViewById(R.id.poiTypeButton);
poiTypeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PoiTypeDialogFragment fragment = PoiTypeDialogFragment.createInstance();
fragment.setOnItemSelectListener(new PoiTypeDialogFragment.OnItemSelectListener() {
@Override
public void select(PoiCategory poiCategory) {
setPoiCategory(poiCategory);
}
});
fragment.show(getChildFragmentManager(), "PoiTypeDialogFragment");
}
});
EditText poiNameEditText = (EditText) view.findViewById(R.id.poiNameEditText);
poiNameEditText.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) {
if (!getEditPoiData().isInEdit()) {
if (!TextUtils.isEmpty(s)) {
getEditPoiData().putTag(OSMSettings.OSMTagKey.NAME.getValue(), s.toString());
} else {
getEditPoiData().removeTag(OSMSettings.OSMTagKey.NAME.getValue());
}
}
}
});
poiNameEditText.setText(editPoiData.getTag(OSMSettings.OSMTagKey.NAME.getValue()));
poiTypeTextInputLayout = (TextInputLayout) view.findViewById(R.id.poiTypeTextInputLayout);
poiTypeEditText = (AutoCompleteTextView) view.findViewById(R.id.poiTypeEditText);
poiTypeEditText.setText(editPoiData.getPoiTypeString());
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) {
if (!getEditPoiData().isInEdit()) {
getEditPoiData().updateTypeTag(s.toString(), true);
if (!getMyApplication().isApplicationInitializing()) {
poiTypeTextInputLayout.setHint(editPoiData.getPoiCategory().getTranslation());
}
}
}
});
poiNameEditText.setOnEditorActionListener(mOnEditorActionListener);
poiTypeEditText.setOnEditorActionListener(mOnEditorActionListener);
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())) {
if (editPoiData.getPoiCategory() != null) {
PoiSubTypeDialogFragment dialogFragment = PoiSubTypeDialogFragment.createInstance(editPoiData.getPoiCategory());
dialogFragment.setOnItemSelectListener(new PoiSubTypeDialogFragment.OnItemSelectListener() {
@Override
public void select(String category) {
setSubCategory(category);
}
});
dialogFragment.show(getChildFragmentManager(), "PoiSubTypeDialogFragment");
}
return true;
}
}
return false;
}
});
if (!isAddingPoi) {
Button deleteButton = (Button) view.findViewById(R.id.deleteButton);
deleteButton.setVisibility(View.VISIBLE);
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DeletePoiHelper deletePoiHelper = new DeletePoiHelper(getMyActivity());
deletePoiHelper.setCallback(new DeletePoiHelper.DeletePoiCallback() {
@Override
public void poiDeleted() {
dismiss();
}
});
deletePoiHelper.deletePoiWithDialog(getEditPoiData().getEntity());
}
});
}
Button saveButton = (Button) view.findViewById(R.id.saveButton);
saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil ? R.string.shared_string_upload : R.string.shared_string_save);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
trySave();
}
});
Button cancelButton = (Button) view.findViewById(R.id.cancelButton);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismissCheckForChanges();
}
});
setAdapterForPoiTypeEditText();
setCancelable(false);
return view;
}
Aggregations