use of net.osmand.plus.poi.PoiUIFilter in project Osmand by osmandapp.
the class ShowHidePoiAction method getIconRes.
@Override
public int getIconRes(Context context) {
if (getParams().get(KEY_FILTERS) == null || getParams().get(KEY_FILTERS).isEmpty()) {
return super.getIconRes();
} else {
OsmandApplication app = (OsmandApplication) context.getApplicationContext();
List<String> filters = new ArrayList<>();
String filtersId = getParams().get(KEY_FILTERS);
Collections.addAll(filters, filtersId.split(","));
if (app.getPoiFilters() == null)
return super.getIconRes();
PoiUIFilter filter = app.getPoiFilters().getFilterById(filters.get(0));
if (filter == null)
return super.getIconRes();
Object res = filter.getIconResource();
if (res instanceof String && RenderingIcons.containsBigIcon(res.toString())) {
return RenderingIcons.getBigIconResourceId(res.toString());
} else
return super.getIconRes();
}
}
use of net.osmand.plus.poi.PoiUIFilter in project Osmand by osmandapp.
the class ShowHidePoiAction method savePoiFilters.
public void savePoiFilters(List<PoiUIFilter> poiFilters) {
List<String> filters = new ArrayList<>();
for (PoiUIFilter f : poiFilters) {
filters.add(f.getFilterId());
}
getParams().put(KEY_FILTERS, TextUtils.join(",", filters));
}
use of net.osmand.plus.poi.PoiUIFilter in project Osmand by osmandapp.
the class ShowHidePoiAction method loadPoiFilters.
private List<PoiUIFilter> loadPoiFilters(PoiFiltersHelper helper) {
List<String> filters = new ArrayList<>();
String filtersId = getParams().get(KEY_FILTERS);
if (filtersId != null && !filtersId.trim().isEmpty()) {
Collections.addAll(filters, filtersId.split(","));
}
List<PoiUIFilter> poiFilters = new ArrayList<>();
for (String f : filters) {
PoiUIFilter filter = helper.getFilterById(f);
if (filter != null) {
poiFilters.add(filter);
}
}
return poiFilters;
}
use of net.osmand.plus.poi.PoiUIFilter in project Osmand by osmandapp.
the class QuickSearchPoiFilterFragment method saveFilter.
private void saveFilter() {
final OsmandApplication app = getMyApplication();
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);
editText.setText(filter.getName());
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);
applyFilterFields();
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();
((QuickSearchDialogFragment) getParentFragment()).replaceQueryWithUiFilter(nFilter, "");
((QuickSearchDialogFragment) getParentFragment()).reloadCategories();
QuickSearchPoiFilterFragment.this.dismiss();
}
}
});
builder.create().show();
}
use of net.osmand.plus.poi.PoiUIFilter in project Osmand by osmandapp.
the class SearchPOIActivity method savePoiFilter.
public void savePoiFilter() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.edit_filter_save_as_menu_item);
final EditText editText = new EditText(this);
if (filter.isStandardFilter()) {
editText.setText((filter.getName() + " " + searchFilter.getText()).trim());
} else {
editText.setText(filter.getName());
}
LinearLayout ll = new LinearLayout(this);
ll.setPadding(5, 3, 5, 0);
ll.addView(editText, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
builder.setView(ll);
builder.setNegativeButton(R.string.shared_string_cancel, null);
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
PoiUIFilter nFilter = new PoiUIFilter(editText.getText().toString(), null, filter.getAcceptedTypes(), (OsmandApplication) getApplication());
if (searchFilter.getText().toString().length() > 0) {
nFilter.setSavedFilterByName(searchFilter.getText().toString());
}
if (app.getPoiFilters().createPoiFilter(nFilter)) {
Toast.makeText(SearchPOIActivity.this, MessageFormat.format(SearchPOIActivity.this.getText(R.string.edit_filter_create_message).toString(), editText.getText().toString()), Toast.LENGTH_SHORT).show();
}
SearchPOIActivity.this.finish();
}
});
builder.create().show();
}
Aggregations