private void showEditActivity(PoiFilter poi) { if (!poi.isStandardFilter()) { Intent newIntent = new Intent(SearchPoiFilterActivity.this, EditPOIFilterActivity.class); // folder selected newIntent.putExtra(EditPOIFilterActivity.AMENITY_FILTER, poi.getFilterId()); updateIntentToLaunch(newIntent); startActivityForResult(newIntent, 0); } }
@Override public boolean onCreateOptionsMenu(Menu menu) { createMenuItem( menu, SAVE_FILTER, R.string.edit_filter_save_as_menu_item, R.drawable.ic_action_gsave_dark, R.drawable.ic_action_gsave_light, MenuItem.SHOW_AS_ACTION_IF_ROOM); createMenuItem( menu, FILTER, R.string.filter_current_poiButton, 0, 0, // R.drawable.a_1_navigation_accept_light, R.drawable.a_1_navigation_accept_dark, MenuItem.SHOW_AS_ACTION_WITH_TEXT | MenuItem.SHOW_AS_ACTION_ALWAYS); if (!filter.isStandardFilter()) { createMenuItem( menu, DELETE_FILTER, R.string.edit_filter_delete_menu_item, R.drawable.ic_action_gdiscard_dark, R.drawable.ic_action_gdiscard_light, MenuItem.SHOW_AS_ACTION_IF_ROOM); } return super.onCreateOptionsMenu(menu); }
@Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = getLayoutInflater(); View row = inflater.inflate(R.layout.searchpoifolder_list, parent, false); TextView label = (TextView) row.findViewById(R.id.folder_label); ImageView icon = (ImageView) row.findViewById(R.id.folder_icon); PoiFilter model = getItem(position); label.setText(model.getName()); if (model.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID)) { icon.setImageResource(android.R.drawable.ic_input_get); } else if (model.getFilterId().equals(PoiFilter.BY_NAME_FILTER_ID)) { // label.setTypeface(Typeface.DEFAULT, Typeface.ITALIC); icon.setImageResource(android.R.drawable.ic_search_category_default); } else { // label.setTypeface(Typeface.DEFAULT); icon.setImageResource( model.isStandardFilter() ? R.drawable.folder : R.drawable.tab_icon_favourite_menu); } return (row); }
@Override public void onListItemClick(ListView parent, View v, int position, long id) { final PoiFilter filter = ((AmenityAdapter) getListAdapter()).getItem(position); if (filter.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID)) { filter.clearFilter(); showEditActivity(filter); return; } if (!(filter instanceof NameFinderPoiFilter)) { ResourceManager rm = ((OsmandApplication) getApplication()).getResourceManager(); if (!rm.containsAmenityRepositoryToSearch(filter instanceof SearchByNameFilter)) { AccessibleToast.makeText( this, R.string.data_to_search_poi_not_available, Toast.LENGTH_LONG); return; } } final Intent newIntent = new Intent(SearchPoiFilterActivity.this, SearchPOIActivity.class); newIntent.putExtra(SearchPOIActivity.AMENITY_FILTER, filter.getFilterId()); updateIntentToLaunch(newIntent); startActivityForResult(newIntent, 0); }
@Override public void onCreate(final Bundle icicle) { Bundle bundle = this.getIntent().getExtras(); String filterId = bundle.getString(AMENITY_FILTER); helper = ((OsmandApplication) getApplication()).getPoiFilters(); filter = helper.getFilterById(filterId); super.onCreate(icicle); setContentView(R.layout.editing_poi_filter); getSupportActionBar().setTitle(R.string.filterpoi_activity); getSupportActionBar().setIcon(R.drawable.tab_search_poi_icon); getSupportActionBar().setSubtitle(filter.getName()); setListAdapter(new AmenityAdapter(AmenityType.getCategories())); }
private void filterPOI() { Bundle extras = getIntent().getExtras(); boolean searchNearBy = true; LatLon lastKnownMapLocation = ((OsmandApplication) getApplication()).getSettings().getLastKnownMapLocation(); double latitude = lastKnownMapLocation != null ? lastKnownMapLocation.getLatitude() : 0; double longitude = lastKnownMapLocation != null ? lastKnownMapLocation.getLongitude() : 0; final Intent newIntent = new Intent(EditPOIFilterActivity.this, SearchPOIActivity.class); if (extras != null && extras.containsKey(SEARCH_LAT) && extras.containsKey(SEARCH_LON)) { latitude = extras.getDouble(SEARCH_LAT); longitude = extras.getDouble(SEARCH_LON); searchNearBy = false; } final double lat = latitude; final double lon = longitude; newIntent.putExtra(SearchPOIActivity.AMENITY_FILTER, filter.getFilterId()); if (searchNearBy) { AlertDialog.Builder b = new AlertDialog.Builder(EditPOIFilterActivity.this); b.setItems( new String[] {getString(R.string.search_nearby), getString(R.string.search_near_map)}, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 1) { newIntent.putExtra(SearchPOIActivity.SEARCH_LAT, lat); newIntent.putExtra(SearchPOIActivity.SEARCH_LON, lon); } startActivity(newIntent); } }); b.show(); } else { newIntent.putExtra(SearchPOIActivity.SEARCH_LAT, lat); newIntent.putExtra(SearchPOIActivity.SEARCH_LON, lon); startActivity(newIntent); } }
private void showDialog(final AmenityType amenity) { ListView lv = EditPOIFilterActivity.this.getListView(); final int index = lv.getFirstVisiblePosition(); View v = lv.getChildAt(0); final int top = (v == null) ? 0 : v.getTop(); Builder builder = new AlertDialog.Builder(this); ScrollView scroll = new ScrollView(this); ListView listView = new ListView(this); final LinkedHashSet<String> subCategories = new LinkedHashSet<String>(MapRenderingTypes.getDefault().getAmenitySubCategories(amenity)); Set<String> acceptedCategories = filter.getAcceptedSubtypes(amenity); if (acceptedCategories != null) { for (String s : acceptedCategories) { if (!subCategories.contains(s)) { subCategories.add(s); } } } final String[] array = subCategories.toArray(new String[0]); final Collator cl = Collator.getInstance(); cl.setStrength(Collator.SECONDARY); Arrays.sort( array, 0, array.length, new Comparator<String>() { @Override public int compare(String object1, String object2) { String v1 = SpecialPhrases.getSpecialPhrase(object1).replace('_', ' '); String v2 = SpecialPhrases.getSpecialPhrase(object2).replace('_', ' '); return cl.compare(v1, v2); } }); final String[] visibleNames = new String[array.length]; final boolean[] selected = new boolean[array.length]; for (int i = 0; i < array.length; i++) { visibleNames[i] = SpecialPhrases.getSpecialPhrase(array[i]).replace('_', ' '); if (acceptedCategories == null) { selected[i] = true; } else { selected[i] = acceptedCategories.contains(array[i]); } } scroll.addView(listView); builder.setView(scroll); builder.setNeutralButton( EditPOIFilterActivity.this.getText(R.string.close), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { LinkedHashSet<String> accepted = new LinkedHashSet<String>(); for (int i = 0; i < selected.length; i++) { if (selected[i]) { accepted.add(array[i]); } } if (subCategories.size() == accepted.size()) { filter.selectSubTypesToAccept(amenity, null); } else if (accepted.size() == 0) { filter.setTypeToAccept(amenity, false); } else { filter.selectSubTypesToAccept(amenity, accepted); } helper.editPoiFilter(filter); ListView lv = EditPOIFilterActivity.this.getListView(); AmenityAdapter la = (AmenityAdapter) EditPOIFilterActivity.this.getListAdapter(); la.notifyDataSetInvalidated(); lv.setSelectionFromTop(index, top); } }); builder.setPositiveButton( EditPOIFilterActivity.this.getText(R.string.default_buttons_selectall), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { filter.selectSubTypesToAccept(amenity, null); helper.editPoiFilter(filter); ListView lv = EditPOIFilterActivity.this.getListView(); AmenityAdapter la = (AmenityAdapter) EditPOIFilterActivity.this.getListAdapter(); la.notifyDataSetInvalidated(); lv.setSelectionFromTop(index, top); } }); builder.setMultiChoiceItems( visibleNames, selected, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int item, boolean isChecked) { selected[item] = isChecked; } }); builder.show(); }