Search in sources :

Example 21 with PoiUIFilter

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;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) ArrayList(java.util.ArrayList) PoiFiltersHelper(net.osmand.plus.poi.PoiFiltersHelper) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) Collator(java.text.Collator) CollatorStringMatcher(net.osmand.CollatorStringMatcher) OsmandRasterMapsPlugin(net.osmand.plus.rastermaps.OsmandRasterMapsPlugin)

Example 22 with PoiUIFilter

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;
    }
}
Also used : Bundle(android.os.Bundle) PoiCategory(net.osmand.osm.PoiCategory) SearchUICore(net.osmand.search.SearchUICore) SearchResult(net.osmand.search.core.SearchResult) SpannableString(android.text.SpannableString) SearchPhrase(net.osmand.search.core.SearchPhrase) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Example 23 with PoiUIFilter

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));
        }
    }
}
Also used : SearchWord(net.osmand.search.core.SearchWord) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Example 24 with PoiUIFilter

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

Example 25 with PoiUIFilter

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);
}
Also used : SearchSettings(net.osmand.search.core.SearchSettings) SearchResult(net.osmand.search.core.SearchResult) SpannableString(android.text.SpannableString) 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