fix small issues

git-svn-id: https://osmand.googlecode.com/svn/trunk@197 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-06-22 19:08:34 +00:00
parent 77f68ca6ee
commit 968b18cfc5
3 changed files with 73 additions and 50 deletions

View file

@ -17,10 +17,6 @@ public class ToDoConstants {
// 42. Revise UI (icons/layouts). Support different devices. Add inactive/focus(!) icon versions. // 42. Revise UI (icons/layouts). Support different devices. Add inactive/focus(!) icon versions.
// Some icons are not fine (as back menu from map - it is blured). // Some icons are not fine (as back menu from map - it is blured).
// 32. Introduce POI predefined filters (car filter(other-fuel, transportation-car_wash, show-car) and others)
// DONE : back end (POI filter object, save, delete, read)
// TODO : activity to create/edit new index, activity to read both user defined/osm standard, add actions to remove/create
// FUTURE RELEASES // FUTURE RELEASES
// 54. Invent screen to update index from internet (from osmand.googlecode.com) // 54. Invent screen to update index from internet (from osmand.googlecode.com)
@ -57,6 +53,7 @@ public class ToDoConstants {
// BUGS Swing // BUGS Swing
// DONE ANDROID : // DONE ANDROID :
// 32. Introduce POI predefined filters (car filter(other-fuel, transportation-car_wash, show-car) and others)
// 48. Enable change favorite point : (for example fav - "car") means last point you left car. It is not static point, // 48. Enable change favorite point : (for example fav - "car") means last point you left car. It is not static point,
// you can always use the same name for different locations. // you can always use the same name for different locations.
// 52. Make good distribution of POI on map (when POI a lot they are coupling in one place on the south) // 52. Make good distribution of POI on map (when POI a lot they are coupling in one place on the south)

View file

@ -6,12 +6,13 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.osmand.data.AmenityType;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteStatement;
import com.osmand.data.AmenityType;
public class PoiFiltersHelper { public class PoiFiltersHelper {
@ -127,41 +128,40 @@ public class PoiFiltersHelper {
return Collections.unmodifiableList(cacheOsmDefinedFilters); return Collections.unmodifiableList(cacheOsmDefinedFilters);
} }
public static boolean removePoiFilter(Context ctx, PoiFilter filter){ public static PoiFilterDbHelper getPoiDbHelper(Context ctx){
return new PoiFilterDbHelper(ctx);
}
public static boolean removePoiFilter(PoiFilterDbHelper helper, PoiFilter filter){
if(filter.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID)){ if(filter.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID)){
return false; return false;
} }
PoiFilterDbHelper helper = new PoiFilterDbHelper(ctx);
boolean res = helper.deleteFilter(filter); boolean res = helper.deleteFilter(filter);
if(res){ if(res){
cacheUserDefinedFilters.remove(filter); cacheUserDefinedFilters.remove(filter);
} }
helper.close();
return res; return res;
} }
public static boolean createPoiFilter(Context ctx, PoiFilter filter){ public static boolean createPoiFilter(PoiFilterDbHelper helper, PoiFilter filter){
PoiFilterDbHelper helper = new PoiFilterDbHelper(ctx);
boolean res = helper.addFilter(filter, helper.getWritableDatabase(), false); boolean res = helper.addFilter(filter, helper.getWritableDatabase(), false);
if(res){ if(res){
cacheUserDefinedFilters.add(filter); cacheUserDefinedFilters.add(filter);
} }
helper.close();
return res; return res;
} }
public static boolean editPoiFilter(Context ctx, PoiFilter filter){ public static boolean editPoiFilter(PoiFilterDbHelper helper, PoiFilter filter){
if(filter.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID)){ if(filter.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID)){
return false; return false;
} }
PoiFilterDbHelper helper = new PoiFilterDbHelper(ctx);
boolean res = helper.editFilter(filter); boolean res = helper.editFilter(filter);
helper.close();
return res; return res;
} }
protected static class PoiFilterDbHelper extends SQLiteOpenHelper { public static class PoiFilterDbHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "poi_filters"; //$NON-NLS-1$ public static final String DATABASE_NAME = "poi_filters"; //$NON-NLS-1$
private static final int DATABASE_VERSION = 1; private static final int DATABASE_VERSION = 1;
@ -198,29 +198,35 @@ public class PoiFiltersHelper {
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
} }
public boolean addFilter(PoiFilter p, SQLiteDatabase db, boolean addOnlyCategories){ protected boolean addFilter(PoiFilter p, SQLiteDatabase db, boolean addOnlyCategories){
if(db != null){ if(db != null){
if(!addOnlyCategories){ if(!addOnlyCategories){
db.execSQL("INSERT INTO " + FILTER_NAME + " VALUES (?, ?, ?)",new Object[]{p.getName(), p.getFilterId(), p.getFilterByName()}); //$NON-NLS-1$ //$NON-NLS-2$ db.execSQL("INSERT INTO " + FILTER_NAME + " VALUES (?, ?, ?)",new Object[]{p.getName(), p.getFilterId(), p.getFilterByName()}); //$NON-NLS-1$ //$NON-NLS-2$
} }
Map<AmenityType, List<String>> types = p.getAcceptedTypes(); Map<AmenityType, List<String>> types = p.getAcceptedTypes();
SQLiteStatement insertCategories = db.compileStatement("INSERT INTO " + CATEGORIES_NAME + " VALUES (?, ?, ?)"); //$NON-NLS-1$ //$NON-NLS-2$
for(AmenityType a : types.keySet()){ for(AmenityType a : types.keySet()){
if(types.get(a) == null){ if(types.get(a) == null){
db.execSQL("INSERT INTO " + CATEGORIES_NAME + " VALUES (?, ?, ?)", //$NON-NLS-1$ //$NON-NLS-2$ insertCategories.bindString(1, p.getFilterId());
new Object[]{p.getFilterId(), AmenityType.valueToString(a), null}); insertCategories.bindString(2, AmenityType.valueToString(a));
insertCategories.bindNull(3);
insertCategories.execute();
} else { } else {
for(String s : types.get(a)){ for(String s : types.get(a)){
db.execSQL("INSERT INTO " + CATEGORIES_NAME + " VALUES (?, ?, ?)", //$NON-NLS-1$ //$NON-NLS-2$ insertCategories.bindString(1, p.getFilterId());
new Object[]{p.getFilterId(), AmenityType.valueToString(a), s}); insertCategories.bindString(2, AmenityType.valueToString(a));
insertCategories.bindString(3, s);
insertCategories.execute();
} }
} }
} }
insertCategories.close();
return true; return true;
} }
return false; return false;
} }
public List<PoiFilter> getFilters(){ protected List<PoiFilter> getFilters(){
SQLiteDatabase db = getReadableDatabase(); SQLiteDatabase db = getReadableDatabase();
ArrayList<PoiFilter> list = new ArrayList<PoiFilter>(); ArrayList<PoiFilter> list = new ArrayList<PoiFilter>();
if(db != null){ if(db != null){
@ -265,7 +271,7 @@ public class PoiFiltersHelper {
return list; return list;
} }
public boolean editFilter(PoiFilter filter) { protected boolean editFilter(PoiFilter filter) {
SQLiteDatabase db = getWritableDatabase(); SQLiteDatabase db = getWritableDatabase();
if (db != null) { if (db != null) {
db.execSQL("DELETE FROM " + CATEGORIES_NAME + " WHERE " + CATEGORIES_FILTER_ID + " = ?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ db.execSQL("DELETE FROM " + CATEGORIES_NAME + " WHERE " + CATEGORIES_FILTER_ID + " = ?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@ -278,7 +284,7 @@ public class PoiFiltersHelper {
return false; return false;
} }
public boolean deleteFilter(PoiFilter p){ protected boolean deleteFilter(PoiFilter p){
SQLiteDatabase db = getWritableDatabase(); SQLiteDatabase db = getWritableDatabase();
if(db != null){ if(db != null){
db.execSQL("DELETE FROM " + FILTER_NAME + " WHERE " +FILTER_COL_ID + " = ?",new Object[]{p.getFilterId()}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ db.execSQL("DELETE FROM " + FILTER_NAME + " WHERE " +FILTER_COL_ID + " = ?",new Object[]{p.getFilterId()}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

View file

@ -30,10 +30,10 @@ import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.osmand.OsmandSettings;
import com.osmand.PoiFilter; import com.osmand.PoiFilter;
import com.osmand.PoiFiltersHelper; import com.osmand.PoiFiltersHelper;
import com.osmand.R; import com.osmand.R;
import com.osmand.PoiFiltersHelper.PoiFilterDbHelper;
import com.osmand.activities.search.SearchPOIActivity; import com.osmand.activities.search.SearchPOIActivity;
import com.osmand.data.AmenityType; import com.osmand.data.AmenityType;
@ -45,6 +45,7 @@ public class EditPOIFilterActivity extends ListActivity {
private Button filterLevel; private Button filterLevel;
private PoiFilter filter; private PoiFilter filter;
private PoiFilterDbHelper helper;
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
@ -55,9 +56,10 @@ public class EditPOIFilterActivity extends ListActivity {
filterLevel.setOnClickListener(new OnClickListener() { filterLevel.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
OsmandSettings.setPoiFilterForMap(EditPOIFilterActivity.this, filter.getFilterId()); Intent newIntent = new Intent(EditPOIFilterActivity.this, SearchPOIActivity.class);
OsmandSettings.setShowPoiOverMap(EditPOIFilterActivity.this, true); Bundle bundle = new Bundle();
Intent newIntent = new Intent(EditPOIFilterActivity.this, MapActivity.class); bundle.putString(SearchPOIActivity.AMENITY_FILTER, filter.getFilterId());
newIntent.putExtras(bundle);
startActivity(newIntent); startActivity(newIntent);
} }
}); });
@ -68,6 +70,18 @@ public class EditPOIFilterActivity extends ListActivity {
setListAdapter(new AmenityAdapter(AmenityType.getCategories())); setListAdapter(new AmenityAdapter(AmenityType.getCategories()));
} }
@Override
protected void onResume() {
super.onResume();
helper = PoiFiltersHelper.getPoiDbHelper(this);
}
@Override
protected void onPause() {
super.onPause();
helper.close();
}
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
@ -85,7 +99,7 @@ public class EditPOIFilterActivity extends ListActivity {
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() { builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (PoiFiltersHelper.removePoiFilter(EditPOIFilterActivity.this, filter)) { if (PoiFiltersHelper.removePoiFilter(helper, filter)) {
Toast.makeText( Toast.makeText(
EditPOIFilterActivity.this, EditPOIFilterActivity.this,
MessageFormat.format(EditPOIFilterActivity.this.getText(R.string.edit_filter_delete_message).toString(), MessageFormat.format(EditPOIFilterActivity.this.getText(R.string.edit_filter_delete_message).toString(),
@ -106,7 +120,7 @@ public class EditPOIFilterActivity extends ListActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
PoiFilter nFilter = new PoiFilter(editText.getText().toString(), null, filter.getAcceptedTypes()); PoiFilter nFilter = new PoiFilter(editText.getText().toString(), null, filter.getAcceptedTypes());
if (PoiFiltersHelper.createPoiFilter(EditPOIFilterActivity.this, nFilter)) { if (PoiFiltersHelper.createPoiFilter(helper, nFilter)) {
Toast.makeText( Toast.makeText(
EditPOIFilterActivity.this, EditPOIFilterActivity.this,
MessageFormat.format(EditPOIFilterActivity.this.getText(R.string.edit_filter_create_message).toString(), MessageFormat.format(EditPOIFilterActivity.this.getText(R.string.edit_filter_create_message).toString(),
@ -120,12 +134,12 @@ public class EditPOIFilterActivity extends ListActivity {
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
private void showDialog(final AmenityType amenity) { private void showDialog(final AmenityType amenity) {
Builder builder = new AlertDialog.Builder(this); Builder builder = new AlertDialog.Builder(this);
ScrollView scroll = new ScrollView(this); ScrollView scroll = new ScrollView(this);
ListView listView = new ListView(this); ListView listView = new ListView(this);
final List<String> accepted = new ArrayList<String>();
final LinkedHashSet<String> subCategories = new LinkedHashSet<String>(AmenityType.getSubCategories(amenity)); final LinkedHashSet<String> subCategories = new LinkedHashSet<String>(AmenityType.getSubCategories(amenity));
List<String> subtypes = filter.getAcceptedSubtypes(amenity); List<String> subtypes = filter.getAcceptedSubtypes(amenity);
boolean allSubTypesAccepted = subtypes == null; boolean allSubTypesAccepted = subtypes == null;
@ -139,40 +153,42 @@ public class EditPOIFilterActivity extends ListActivity {
} }
final String[] array = subCategories.toArray(new String[0]); final String[] array = subCategories.toArray(new String[0]);
boolean[] selected = new boolean[array.length]; final boolean[] selected = new boolean[array.length];
for (int i = 0; i < selected.length; i++) { for (int i = 0; i < selected.length; i++) {
if (allSubTypesAccepted) { if (allSubTypesAccepted) {
selected[i] = true; selected[i] = true;
accepted.add(array[i]);
} else { } else {
selected[i] = acceptedCategories.contains(array[i]); selected[i] = acceptedCategories.contains(array[i]);
if (selected[i]) {
accepted.add(array[i]);
}
} }
} }
scroll.addView(listView); scroll.addView(listView);
builder.setView(scroll); builder.setView(scroll);
builder.setNegativeButton(EditPOIFilterActivity.this.getText(R.string.default_buttons_cancel), new DialogInterface.OnClickListener() { builder.setNeutralButton(EditPOIFilterActivity.this.getText(R.string.close), new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
List<String> accepted = new ArrayList<String>();
for (int i = 0; i < selected.length; i++) {
if(selected[i]){
accepted.add(array[i]);
}
}
if (subCategories.size() == accepted.size()) { if (subCategories.size() == accepted.size()) {
filter.selectSubTypesToAccept(amenity, null); filter.selectSubTypesToAccept(amenity, null);
} else { } else {
filter.selectSubTypesToAccept(amenity, accepted); filter.selectSubTypesToAccept(amenity, accepted);
} }
PoiFiltersHelper.editPoiFilter(EditPOIFilterActivity.this, filter); PoiFiltersHelper.editPoiFilter(helper, filter);
((AmenityAdapter) EditPOIFilterActivity.this.getListAdapter()).notifyDataSetInvalidated(); ((AmenityAdapter) EditPOIFilterActivity.this.getListAdapter()).notifyDataSetInvalidated();
} }
}); });
builder.setNeutralButton(EditPOIFilterActivity.this.getText(R.string.default_buttons_selectall), new DialogInterface.OnClickListener() { builder.setPositiveButton(EditPOIFilterActivity.this.getText(R.string.default_buttons_selectall), new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
filter.selectSubTypesToAccept(amenity, null); filter.selectSubTypesToAccept(amenity, null);
PoiFiltersHelper.editPoiFilter(EditPOIFilterActivity.this, filter); PoiFiltersHelper.editPoiFilter(helper, filter);
((AmenityAdapter) EditPOIFilterActivity.this.getListAdapter()).notifyDataSetInvalidated(); ((AmenityAdapter) EditPOIFilterActivity.this.getListAdapter()).notifyDataSetInvalidated();
} }
}); });
@ -181,17 +197,23 @@ public class EditPOIFilterActivity extends ListActivity {
@Override @Override
public void onClick(DialogInterface dialog, int item, boolean isChecked) { public void onClick(DialogInterface dialog, int item, boolean isChecked) {
if (isChecked && !accepted.contains(array[item])) { selected[item] = isChecked;
accepted.add(array[item]);
} else if (!isChecked && accepted.contains(array[item])) {
accepted.remove(array[item]);
}
} }
}); });
builder.show(); builder.show();
} }
@Override
public AmenityAdapter getListAdapter() {
return (AmenityAdapter) super.getListAdapter();
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
showDialog(getListAdapter().getItem(position));
}
class AmenityAdapter extends ArrayAdapter<AmenityType> { class AmenityAdapter extends ArrayAdapter<AmenityType> {
AmenityAdapter(AmenityType[] amenityTypes) { AmenityAdapter(AmenityType[] amenityTypes) {
@ -217,7 +239,6 @@ public class EditPOIFilterActivity extends ListActivity {
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() { text.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
showDialog(model); showDialog(model);
@ -225,7 +246,6 @@ public class EditPOIFilterActivity extends ListActivity {
}); });
check.setOnClickListener(new OnClickListener() { check.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (check.isChecked()) { if (check.isChecked()) {
@ -233,7 +253,7 @@ public class EditPOIFilterActivity extends ListActivity {
showDialog(model); showDialog(model);
} else { } else {
filter.setTypeToAccept(model, false); filter.setTypeToAccept(model, false);
PoiFiltersHelper.editPoiFilter(EditPOIFilterActivity.this, filter); PoiFiltersHelper.editPoiFilter(helper, filter);
} }
} }
}); });