use of net.osmand.plus.poi.PoiUIFilter in project Osmand by osmandapp.
the class SearchPoiFilterFragment method getFilters.
public List<Object> getFilters(String s) {
List<Object> filters = new ArrayList<Object>();
OsmandApplication app = getApp();
if (app == null) {
return filters;
}
PoiFiltersHelper poiFilters = app.getPoiFilters();
if (Algorithms.isEmpty(s)) {
filters.addAll(poiFilters.getTopDefinedPoiFilters());
} else {
for (PoiUIFilter pf : poiFilters.getTopDefinedPoiFilters()) {
if (!pf.isStandardFilter() && pf.getName().toLowerCase().startsWith(s.toLowerCase())) {
filters.add(pf);
}
}
List<AbstractPoiType> res = app.getPoiTypes().getAllTypesTranslatedNames(new CollatorStringMatcher(s, StringMatcherMode.CHECK_STARTS_FROM_SPACE));
final Collator inst = Collator.getInstance();
Collections.sort(res, new Comparator<AbstractPoiType>() {
@Override
public int compare(AbstractPoiType lhs, AbstractPoiType rhs) {
return inst.compare(lhs.getTranslation(), rhs.getTranslation());
}
});
for (AbstractPoiType p : res) {
filters.add(p);
}
filters.add(poiFilters.getSearchByNamePOIFilter());
if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) != null) {
filters.add(poiFilters.getNominatimPOIFilter());
filters.add(poiFilters.getNominatimAddressFilter());
}
}
return filters;
}
use of net.osmand.plus.poi.PoiUIFilter in project Osmand by osmandapp.
the class QuickSearchDialogFragment method showInstance.
public static boolean showInstance(@NonNull MapActivity mapActivity, @NonNull String searchQuery, @Nullable Object object, QuickSearchType searchType, QuickSearchTab showSearchTab, @Nullable LatLon latLon) {
try {
if (mapActivity.isActivityDestroyed()) {
return false;
}
mapActivity.getMyApplication().logEvent(mapActivity, "search_open");
Bundle bundle = new Bundle();
if (object != null) {
bundle.putBoolean(QUICK_SEARCH_RUN_SEARCH_FIRST_TIME_KEY, true);
String objectLocalizedName = searchQuery;
if (object instanceof PoiCategory) {
PoiCategory c = (PoiCategory) object;
objectLocalizedName = c.getTranslation();
SearchUICore searchUICore = mapActivity.getMyApplication().getSearchUICore().getCore();
SearchPhrase phrase = searchUICore.resetPhrase(objectLocalizedName + " ");
SearchResult sr = new SearchResult(phrase);
sr.localeName = objectLocalizedName;
sr.object = c;
sr.priority = SEARCH_AMENITY_TYPE_PRIORITY;
sr.priorityDistance = 0;
sr.objectType = ObjectType.POI_TYPE;
searchUICore.selectSearchResult(sr);
bundle.putBoolean(QUICK_SEARCH_PHRASE_DEFINED_KEY, true);
} else if (object instanceof PoiUIFilter) {
PoiUIFilter filter = (PoiUIFilter) object;
objectLocalizedName = filter.getName();
SearchUICore searchUICore = mapActivity.getMyApplication().getSearchUICore().getCore();
SearchPhrase phrase = searchUICore.resetPhrase();
SearchResult sr = new SearchResult(phrase);
sr.localeName = objectLocalizedName;
sr.object = filter;
sr.priority = SEARCH_AMENITY_TYPE_PRIORITY;
sr.priorityDistance = 0;
sr.objectType = ObjectType.POI_TYPE;
searchUICore.selectSearchResult(sr);
bundle.putBoolean(QUICK_SEARCH_PHRASE_DEFINED_KEY, true);
}
searchQuery = objectLocalizedName.trim() + " ";
} else if (!Algorithms.isEmpty(searchQuery)) {
bundle.putBoolean(QUICK_SEARCH_RUN_SEARCH_FIRST_TIME_KEY, true);
}
bundle.putString(QUICK_SEARCH_QUERY_KEY, searchQuery);
bundle.putString(QUICK_SEARCH_SHOW_TAB_KEY, showSearchTab.name());
bundle.putString(QUICK_SEARCH_TYPE_KEY, searchType.name());
if (latLon != null) {
bundle.putDouble(QUICK_SEARCH_LAT_KEY, latLon.getLatitude());
bundle.putDouble(QUICK_SEARCH_LON_KEY, latLon.getLongitude());
}
QuickSearchDialogFragment fragment = new QuickSearchDialogFragment();
fragment.setArguments(bundle);
fragment.show(mapActivity.getSupportFragmentManager(), TAG);
return true;
} catch (RuntimeException e) {
return false;
}
}
use of net.osmand.plus.poi.PoiUIFilter in project Osmand by osmandapp.
the class QuickSearchDialogFragment method updateToolbarButton.
private void updateToolbarButton() {
SearchWord word = searchUICore.getPhrase().getLastSelectedWord();
if (foundPartialLocation) {
buttonToolbarText.setText(app.getString(R.string.advanced_coords_search).toUpperCase());
} else if (searchEditText.getText().length() > 0) {
if (searchType == QuickSearchType.START_POINT || searchType == QuickSearchType.DESTINATION || searchType == QuickSearchType.INTERMEDIATE) {
if (word != null && word.getResult() != null) {
buttonToolbarText.setText(app.getString(R.string.shared_string_select).toUpperCase() + " " + word.getResult().localeName.toUpperCase());
} else {
buttonToolbarText.setText(app.getString(R.string.shared_string_select).toUpperCase());
}
} else {
if (word != null && word.getResult() != null) {
buttonToolbarText.setText(app.getString(R.string.show_something_on_map, word.getResult().localeName).toUpperCase());
} else {
buttonToolbarText.setText(app.getString(R.string.shared_string_show_on_map).toUpperCase());
}
}
} else {
buttonToolbarText.setText(app.getString(R.string.shared_string_show_on_map).toUpperCase());
}
boolean filterButtonVisible = word != null && word.getType() != null && word.getType().equals(POI_TYPE);
buttonToolbarFilter.setVisibility(filterButtonVisible ? View.VISIBLE : View.GONE);
if (filterButtonVisible) {
if (word.getResult().object instanceof PoiUIFilter) {
buttonToolbarFilter.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_filter, app.getSettings().isLightContent() ? R.color.color_dialog_buttons_light : R.color.color_dialog_buttons_dark));
} else {
buttonToolbarFilter.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_filter));
}
}
}
use of net.osmand.plus.poi.PoiUIFilter in project Osmand by osmandapp.
the class QuickSearchDialogFragment method saveCustomFilter.
public void saveCustomFilter() {
final OsmandApplication app = getMyApplication();
final PoiUIFilter filter = app.getPoiFilters().getCustomPOIFilter();
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(R.string.access_hint_enter_name);
final EditText editText = new EditText(getContext());
editText.setHint(R.string.new_filter);
final TextView textView = new TextView(getContext());
textView.setText(app.getString(R.string.new_filter_desc));
textView.setTextAppearance(getContext(), R.style.TextAppearance_ContextMenuSubtitle);
LinearLayout ll = new LinearLayout(getContext());
ll.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
ll.setOrientation(LinearLayout.VERTICAL);
ll.setPadding(AndroidUtils.dpToPx(getContext(), 20f), AndroidUtils.dpToPx(getContext(), 12f), AndroidUtils.dpToPx(getContext(), 20f), AndroidUtils.dpToPx(getContext(), 12f));
ll.addView(editText, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
textView.setPadding(AndroidUtils.dpToPx(getContext(), 4f), AndroidUtils.dpToPx(getContext(), 6f), AndroidUtils.dpToPx(getContext(), 4f), AndroidUtils.dpToPx(getContext(), 4f));
ll.addView(textView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
builder.setView(ll);
builder.setNegativeButton(R.string.shared_string_cancel, null);
builder.setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
PoiUIFilter nFilter = new PoiUIFilter(editText.getText().toString(), null, filter.getAcceptedTypes(), app);
if (!Algorithms.isEmpty(filter.getFilterByName())) {
nFilter.setSavedFilterByName(filter.getFilterByName());
}
if (app.getPoiFilters().createPoiFilter(nFilter)) {
Toast.makeText(getContext(), MessageFormat.format(getContext().getText(R.string.edit_filter_create_message).toString(), editText.getText().toString()), Toast.LENGTH_SHORT).show();
app.getSearchUICore().refreshCustomPoiFilters();
replaceQueryWithUiFilter(nFilter, "");
reloadCategories();
fabVisible = false;
updateFab();
}
}
});
builder.create().show();
}
use of net.osmand.plus.poi.PoiUIFilter in project Osmand by osmandapp.
the class QuickSearchDialogFragment method showFilter.
public void showFilter(@NonNull String filterId) {
PoiUIFilter filter = app.getPoiFilters().getFilterById(filterId);
boolean isCustomFilter = filterId.equals(app.getPoiFilters().getCustomPOIFilter().getFilterId());
if (isCustomFilter) {
fabVisible = true;
poiFilterApplied = true;
updateFab();
}
SearchResult sr = new SearchResult(searchUICore.getPhrase());
sr.localeName = filter.getName();
sr.object = filter;
sr.priority = 0;
sr.objectType = ObjectType.POI_TYPE;
searchUICore.selectSearchResult(sr);
String txt = filter.getName() + " ";
searchQuery = txt;
searchEditText.setText(txt);
searchEditText.setSelection(txt.length());
updateToolbarButton();
SearchSettings settings = searchUICore.getSearchSettings();
if (settings.getRadiusLevel() != 1) {
searchUICore.updateSettings(settings.setRadiusLevel(1));
}
runCoreSearch(txt, false, false);
}
Aggregations