diff --git a/OsmAnd/res/layout/editing_poi_filter_list.xml b/OsmAnd/res/layout/editing_poi_filter_list.xml
index 1cf11d0ed5..4fef32fa4c 100644
--- a/OsmAnd/res/layout/editing_poi_filter_list.xml
+++ b/OsmAnd/res/layout/editing_poi_filter_list.xml
@@ -10,6 +10,6 @@
\ No newline at end of file
diff --git a/OsmAnd/res/menu/edit_filter_menu.xml b/OsmAnd/res/menu/edit_filter_menu.xml
new file mode 100644
index 0000000000..9c81b72aff
--- /dev/null
+++ b/OsmAnd/res/menu/edit_filter_menu.xml
@@ -0,0 +1,8 @@
+
+
diff --git a/OsmAnd/res/menu/map_menu.xml b/OsmAnd/res/menu/map_menu.xml
index ea044f1fe2..e092dcb5c7 100644
--- a/OsmAnd/res/menu/map_menu.xml
+++ b/OsmAnd/res/menu/map_menu.xml
@@ -10,4 +10,5 @@
+
diff --git a/OsmAnd/res/values-ru-rRU/strings.xml b/OsmAnd/res/values-ru-rRU/strings.xml
index deb439d96a..1b5fd60045 100644
--- a/OsmAnd/res/values-ru-rRU/strings.xml
+++ b/OsmAnd/res/values-ru-rRU/strings.xml
@@ -216,4 +216,10 @@
Сохранить
Сброс
Фильтровать
+Удалить
+Сохранить как
+Вы действительно хотите удалить текущий фильтр?
+Фильтр {0} удален
+Фильтр {0} создан
+Выделить все
diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index d88cba5a9f..9c2addc117 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -218,4 +218,10 @@
Commit
Reset
Filter
+Delete
+Save As
+Are you sure about deleting selected filter?
+Filter {0} has been deleted
+Filter {0} has been created
+Select All
diff --git a/OsmAnd/src/com/osmand/PoiFilter.java b/OsmAnd/src/com/osmand/PoiFilter.java
index 269a258b50..7ddb7391bc 100644
--- a/OsmAnd/src/com/osmand/PoiFilter.java
+++ b/OsmAnd/src/com/osmand/PoiFilter.java
@@ -1,5 +1,6 @@
package com.osmand;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
@@ -107,7 +108,7 @@ public class PoiFilter {
* @return null if all subtypes are accepted/ empty list if type is not accepted at all
*/
public List getAcceptedSubtypes(AmenityType type){
- if(acceptedTypes.containsKey(type)){
+ if(!acceptedTypes.containsKey(type)){
return Collections.emptyList();
}
return acceptedTypes.get(type);
@@ -136,7 +137,7 @@ public class PoiFilter {
public void setTypeToAccept(AmenityType type, boolean accept){
if(accept){
- acceptedTypes.put(type, null);
+ acceptedTypes.put(type, new ArrayList());
} else {
acceptedTypes.remove(type);
}
@@ -177,7 +178,6 @@ public class PoiFilter {
}
b.append(")"); //$NON-NLS-1$
}
-
b.append(")"); //$NON-NLS-1$
return b.toString();
}
diff --git a/OsmAnd/src/com/osmand/PoiFiltersHelper.java b/OsmAnd/src/com/osmand/PoiFiltersHelper.java
index ba54fc570c..093b85dd81 100644
--- a/OsmAnd/src/com/osmand/PoiFiltersHelper.java
+++ b/OsmAnd/src/com/osmand/PoiFiltersHelper.java
@@ -128,10 +128,13 @@ public class PoiFiltersHelper {
}
public static boolean removePoiFilter(Context ctx, PoiFilter filter){
+ if(filter.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID)){
+ return false;
+ }
PoiFilterDbHelper helper = new PoiFilterDbHelper(ctx);
boolean res = helper.deleteFilter(filter);
if(res){
- getUserDefinedPoiFilters(ctx).remove(filter);
+ cacheUserDefinedFilters.remove(filter);
}
helper.close();
return res;
@@ -141,13 +144,16 @@ public class PoiFiltersHelper {
PoiFilterDbHelper helper = new PoiFilterDbHelper(ctx);
boolean res = helper.addFilter(filter, helper.getWritableDatabase(), false);
if(res){
- getUserDefinedPoiFilters(ctx).add(filter);
+ cacheUserDefinedFilters.add(filter);
}
helper.close();
return res;
}
public static boolean editPoiFilter(Context ctx, PoiFilter filter){
+ if(filter.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID)){
+ return false;
+ }
PoiFilterDbHelper helper = new PoiFilterDbHelper(ctx);
boolean res = helper.editFilter(filter);
helper.close();
diff --git a/OsmAnd/src/com/osmand/activities/EditPOIFilterActivity.java b/OsmAnd/src/com/osmand/activities/EditPOIFilterActivity.java
index 04c39d17c9..8fb4ccddac 100644
--- a/OsmAnd/src/com/osmand/activities/EditPOIFilterActivity.java
+++ b/OsmAnd/src/com/osmand/activities/EditPOIFilterActivity.java
@@ -3,23 +3,34 @@
*/
package com.osmand.activities;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
+
import android.app.AlertDialog;
import android.app.ListActivity;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
+import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
-import android.widget.ImageView;
+import android.widget.EditText;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;
+import android.widget.Toast;
+import com.osmand.OsmandSettings;
import com.osmand.PoiFilter;
import com.osmand.PoiFiltersHelper;
import com.osmand.R;
@@ -44,8 +55,10 @@ public class EditPOIFilterActivity extends ListActivity {
filterLevel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
- // TODO
-
+ OsmandSettings.setPoiFilterForMap(EditPOIFilterActivity.this, filter.getFilterId());
+ OsmandSettings.setShowPoiOverMap(EditPOIFilterActivity.this, true);
+ Intent newIntent = new Intent(EditPOIFilterActivity.this, MapActivity.class);
+ startActivity(newIntent);
}
});
@@ -56,19 +69,129 @@ public class EditPOIFilterActivity extends ListActivity {
setListAdapter(new AmenityAdapter(AmenityType.getCategories()));
}
- private void showDialog(AmenityType amenity) {
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.edit_filter_menu, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == R.id.edit_filter_delete) {
+ EditPOIFilterActivity.this.finish();
+ Builder builder = new AlertDialog.Builder(this);
+ builder.setMessage(R.string.edit_filter_delete_dialog_title);
+ builder.setNegativeButton(R.string.default_buttons_no, null);
+ builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (PoiFiltersHelper.removePoiFilter(EditPOIFilterActivity.this, filter)) {
+ Toast.makeText(
+ EditPOIFilterActivity.this,
+ MessageFormat.format(EditPOIFilterActivity.this.getText(R.string.edit_filter_delete_message).toString(),
+ filter.getName()), Toast.LENGTH_SHORT).show();
+ }
+
+ }
+ });
+ builder.create().show();
+ return true;
+ } else if (item.getItemId() == R.id.edit_filter_save_as) {
+ Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.edit_filter_save_as_menu_item);
+ final EditText editText = new EditText(this);
+ builder.setView(editText);
+ builder.setNegativeButton(R.string.default_buttons_cancel, null);
+ builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ PoiFilter nFilter = new PoiFilter(editText.getText().toString(), null, filter.getAcceptedTypes());
+ if (PoiFiltersHelper.createPoiFilter(EditPOIFilterActivity.this, nFilter)) {
+ Toast.makeText(
+ EditPOIFilterActivity.this,
+ MessageFormat.format(EditPOIFilterActivity.this.getText(R.string.edit_filter_create_message).toString(),
+ editText.getText().toString()), Toast.LENGTH_SHORT).show();
+ }
+ EditPOIFilterActivity.this.finish();
+ }
+ });
+ builder.create().show();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ private void showDialog(final AmenityType amenity) {
Builder builder = new AlertDialog.Builder(this);
ScrollView scroll = new ScrollView(this);
ListView listView = new ListView(this);
+ final List accepted = new ArrayList();
+ final LinkedHashSet subCategories = new LinkedHashSet(AmenityType.getSubCategories(amenity));
+ List subtypes = filter.getAcceptedSubtypes(amenity);
+ boolean allSubTypesAccepted = subtypes == null;
+ LinkedHashSet acceptedCategories = subtypes == null ? null : new LinkedHashSet(subtypes);
+ if (subtypes != null) {
+ for (String s : acceptedCategories) {
+ if (!subCategories.contains(s)) {
+ subCategories.add(s);
+ }
+ }
+ }
+
+ final String[] array = subCategories.toArray(new String[0]);
+ boolean[] selected = new boolean[array.length];
+ for (int i = 0; i < selected.length; i++) {
+ if (allSubTypesAccepted) {
+ selected[i] = true;
+ accepted.add(array[i]);
+ } else {
+ selected[i] = acceptedCategories.contains(array[i]);
+ if (selected[i]) {
+ accepted.add(array[i]);
+ }
+ }
+ }
+
scroll.addView(listView);
builder.setView(scroll);
- builder.setNegativeButton("Close", null);
- builder.setNeutralButton("Select all", null);
- builder.setMultiChoiceItems(AmenityType.getSubCategories(amenity).toArray(new String[0]), null, null);
+ builder.setNegativeButton(EditPOIFilterActivity.this.getText(R.string.default_buttons_cancel), new DialogInterface.OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (subCategories.size() == accepted.size()) {
+ filter.selectSubTypesToAccept(amenity, null);
+ } else {
+ filter.selectSubTypesToAccept(amenity, accepted);
+ }
+ PoiFiltersHelper.editPoiFilter(EditPOIFilterActivity.this, filter);
+ ((AmenityAdapter) EditPOIFilterActivity.this.getListAdapter()).notifyDataSetInvalidated();
+ }
+ });
+
+ builder.setNeutralButton(EditPOIFilterActivity.this.getText(R.string.default_buttons_selectall), new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ filter.selectSubTypesToAccept(amenity, null);
+ PoiFiltersHelper.editPoiFilter(EditPOIFilterActivity.this, filter);
+ ((AmenityAdapter) EditPOIFilterActivity.this.getListAdapter()).notifyDataSetInvalidated();
+ }
+ });
+
+ builder.setMultiChoiceItems(array, selected, new DialogInterface.OnMultiChoiceClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int item, boolean isChecked) {
+ if (isChecked && !accepted.contains(array[item])) {
+ accepted.add(array[item]);
+ } else if (!isChecked && accepted.contains(array[item])) {
+ accepted.remove(array[item]);
+ }
+
+ }
+ });
builder.show();
}
-
class AmenityAdapter extends ArrayAdapter {
AmenityAdapter(AmenityType[] amenityTypes) {
@@ -92,7 +215,7 @@ public class EditPOIFilterActivity extends ListActivity {
return (row);
}
- private void addRowListener(final AmenityType model,final TextView text, final CheckBox check) {
+ private void addRowListener(final AmenityType model, final TextView text, final CheckBox check) {
text.setOnClickListener(new OnClickListener() {
@Override
@@ -105,10 +228,12 @@ public class EditPOIFilterActivity extends ListActivity {
@Override
public void onClick(View v) {
- if(check.isChecked()) {
+ if (check.isChecked()) {
+ filter.setTypeToAccept(model, true);
showDialog(model);
} else {
- filter.setTypeToAccept(model,false);
+ filter.setTypeToAccept(model, false);
+ PoiFiltersHelper.editPoiFilter(EditPOIFilterActivity.this, filter);
}
}
});
diff --git a/OsmAnd/src/com/osmand/activities/search/SearchPoiFilterActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchPoiFilterActivity.java
index c581067ad0..7a35a966a9 100644
--- a/OsmAnd/src/com/osmand/activities/search/SearchPoiFilterActivity.java
+++ b/OsmAnd/src/com/osmand/activities/search/SearchPoiFilterActivity.java
@@ -39,9 +39,7 @@ public class SearchPoiFilterActivity extends ListActivity {
super.onCreate(icicle);
setContentView(R.layout.searchpoilist);
- List filters = new ArrayList(PoiFiltersHelper.getUserDefinedPoiFilters(this)) ;
- filters.addAll(PoiFiltersHelper.getOsmDefinedPoiFilters(this));
- setListAdapter(new AmenityAdapter(filters));
+
typeFace = Typeface.create((String)null, Typeface.ITALIC);
// ListActivity has a ListView, which you can get with:
@@ -52,22 +50,35 @@ public class SearchPoiFilterActivity extends ListActivity {
@Override
public boolean onItemLongClick(AdapterView> av, View v, int pos, long id) {
PoiFilter poi = ((AmenityAdapter) getListAdapter()).getItem(pos);
- if(!poi.isStandardFilter()) {
- Bundle bundle = new Bundle();
- Intent newIntent = new Intent(SearchPoiFilterActivity.this, EditPOIFilterActivity.class);
- // folder selected
- bundle.putString(SearchPOIActivity.AMENITY_FILTER, poi.getFilterId());
- newIntent.putExtras(bundle);
- startActivityForResult(newIntent, 0);
- }
+ showEditActivity(poi);
return true;
}
});
}
+ @Override
+ protected void onResume() {
+ super.onResume();
+ List filters = new ArrayList(PoiFiltersHelper.getUserDefinedPoiFilters(this)) ;
+ filters.addAll(PoiFiltersHelper.getOsmDefinedPoiFilters(this));
+ setListAdapter(new AmenityAdapter(filters));
+ }
-
+ private void showEditActivity(PoiFilter poi) {
+ if(!poi.isStandardFilter()) {
+ Bundle bundle = new Bundle();
+ Intent newIntent = new Intent(SearchPoiFilterActivity.this, EditPOIFilterActivity.class);
+ // folder selected
+ bundle.putString(SearchPOIActivity.AMENITY_FILTER, poi.getFilterId());
+ newIntent.putExtras(bundle);
+ startActivityForResult(newIntent, 0);
+ }
+ }
public void onListItemClick(ListView parent, View v, int position, long id) {
PoiFilter filter = ((AmenityAdapter) getListAdapter()).getItem(position);
+ if(filter.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID)){
+ showEditActivity(filter);
+ return;
+ }
Bundle bundle = new Bundle();
Intent newIntent = new Intent(SearchPoiFilterActivity.this, SearchPOIActivity.class);
bundle.putString(SearchPOIActivity.AMENITY_FILTER, filter.getFilterId());
@@ -76,6 +87,7 @@ public class SearchPoiFilterActivity extends ListActivity {
}
+
class AmenityAdapter extends ArrayAdapter {
AmenityAdapter(List list) {
super(SearchPoiFilterActivity.this, R.layout.searchpoi_list, list);