Search in sources :

Example 6 with PoiUIFilter

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();
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) ArrayList(java.util.ArrayList) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Example 7 with PoiUIFilter

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));
}
Also used : ArrayList(java.util.ArrayList) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Example 8 with PoiUIFilter

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;
}
Also used : ArrayList(java.util.ArrayList) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Example 9 with PoiUIFilter

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();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 10 with PoiUIFilter

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();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) LayoutParams(android.widget.LinearLayout.LayoutParams) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) LinearLayout(android.widget.LinearLayout) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Aggregations

PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)28 ArrayList (java.util.ArrayList)12 PoiFiltersHelper (net.osmand.plus.poi.PoiFiltersHelper)8 TextView (android.widget.TextView)7 OsmandApplication (net.osmand.plus.OsmandApplication)7 DialogInterface (android.content.DialogInterface)6 AlertDialog (android.support.v7.app.AlertDialog)6 View (android.view.View)5 AbstractPoiType (net.osmand.osm.AbstractPoiType)5 PoiType (net.osmand.osm.PoiType)5 SearchResult (net.osmand.search.core.SearchResult)5 SpannableString (android.text.SpannableString)4 Button (android.widget.Button)4 LinearLayout (android.widget.LinearLayout)4 Drawable (android.graphics.drawable.Drawable)3 AdapterView (android.widget.AdapterView)3 EditText (android.widget.EditText)3 ImageView (android.widget.ImageView)3 ListView (android.widget.ListView)3 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)3