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