fix small issues
git-svn-id: https://osmand.googlecode.com/svn/trunk@197 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
77f68ca6ee
commit
968b18cfc5
3 changed files with 73 additions and 50 deletions
|
@ -17,10 +17,6 @@ public class ToDoConstants {
|
|||
// 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).
|
||||
|
||||
// 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
|
||||
// 54. Invent screen to update index from internet (from osmand.googlecode.com)
|
||||
|
@ -57,6 +53,7 @@ public class ToDoConstants {
|
|||
// BUGS Swing
|
||||
|
||||
// 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,
|
||||
// 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)
|
||||
|
|
|
@ -6,12 +6,13 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.osmand.data.AmenityType;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.database.sqlite.SQLiteStatement;
|
||||
|
||||
import com.osmand.data.AmenityType;
|
||||
|
||||
public class PoiFiltersHelper {
|
||||
|
||||
|
@ -127,41 +128,40 @@ public class PoiFiltersHelper {
|
|||
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)){
|
||||
return false;
|
||||
}
|
||||
PoiFilterDbHelper helper = new PoiFilterDbHelper(ctx);
|
||||
boolean res = helper.deleteFilter(filter);
|
||||
if(res){
|
||||
cacheUserDefinedFilters.remove(filter);
|
||||
}
|
||||
helper.close();
|
||||
return res;
|
||||
}
|
||||
|
||||
public static boolean createPoiFilter(Context ctx, PoiFilter filter){
|
||||
PoiFilterDbHelper helper = new PoiFilterDbHelper(ctx);
|
||||
public static boolean createPoiFilter(PoiFilterDbHelper helper, PoiFilter filter){
|
||||
boolean res = helper.addFilter(filter, helper.getWritableDatabase(), false);
|
||||
if(res){
|
||||
cacheUserDefinedFilters.add(filter);
|
||||
}
|
||||
helper.close();
|
||||
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)){
|
||||
return false;
|
||||
}
|
||||
PoiFilterDbHelper helper = new PoiFilterDbHelper(ctx);
|
||||
boolean res = helper.editFilter(filter);
|
||||
helper.close();
|
||||
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$
|
||||
private static final int DATABASE_VERSION = 1;
|
||||
|
@ -198,29 +198,35 @@ public class PoiFiltersHelper {
|
|||
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(!addOnlyCategories){
|
||||
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();
|
||||
SQLiteStatement insertCategories = db.compileStatement("INSERT INTO " + CATEGORIES_NAME + " VALUES (?, ?, ?)"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
for(AmenityType a : types.keySet()){
|
||||
if(types.get(a) == null){
|
||||
db.execSQL("INSERT INTO " + CATEGORIES_NAME + " VALUES (?, ?, ?)", //$NON-NLS-1$ //$NON-NLS-2$
|
||||
new Object[]{p.getFilterId(), AmenityType.valueToString(a), null});
|
||||
insertCategories.bindString(1, p.getFilterId());
|
||||
insertCategories.bindString(2, AmenityType.valueToString(a));
|
||||
insertCategories.bindNull(3);
|
||||
insertCategories.execute();
|
||||
} else {
|
||||
for(String s : types.get(a)){
|
||||
db.execSQL("INSERT INTO " + CATEGORIES_NAME + " VALUES (?, ?, ?)", //$NON-NLS-1$ //$NON-NLS-2$
|
||||
new Object[]{p.getFilterId(), AmenityType.valueToString(a), s});
|
||||
insertCategories.bindString(1, p.getFilterId());
|
||||
insertCategories.bindString(2, AmenityType.valueToString(a));
|
||||
insertCategories.bindString(3, s);
|
||||
insertCategories.execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
insertCategories.close();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<PoiFilter> getFilters(){
|
||||
protected List<PoiFilter> getFilters(){
|
||||
SQLiteDatabase db = getReadableDatabase();
|
||||
ArrayList<PoiFilter> list = new ArrayList<PoiFilter>();
|
||||
if(db != null){
|
||||
|
@ -265,7 +271,7 @@ public class PoiFiltersHelper {
|
|||
return list;
|
||||
}
|
||||
|
||||
public boolean editFilter(PoiFilter filter) {
|
||||
protected boolean editFilter(PoiFilter filter) {
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
if (db != null) {
|
||||
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;
|
||||
}
|
||||
|
||||
public boolean deleteFilter(PoiFilter p){
|
||||
protected boolean deleteFilter(PoiFilter p){
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
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$
|
||||
|
|
|
@ -30,10 +30,10 @@ 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;
|
||||
import com.osmand.PoiFiltersHelper.PoiFilterDbHelper;
|
||||
import com.osmand.activities.search.SearchPOIActivity;
|
||||
import com.osmand.data.AmenityType;
|
||||
|
||||
|
@ -45,6 +45,7 @@ public class EditPOIFilterActivity extends ListActivity {
|
|||
|
||||
private Button filterLevel;
|
||||
private PoiFilter filter;
|
||||
private PoiFilterDbHelper helper;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
|
@ -55,9 +56,10 @@ public class EditPOIFilterActivity extends ListActivity {
|
|||
filterLevel.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
OsmandSettings.setPoiFilterForMap(EditPOIFilterActivity.this, filter.getFilterId());
|
||||
OsmandSettings.setShowPoiOverMap(EditPOIFilterActivity.this, true);
|
||||
Intent newIntent = new Intent(EditPOIFilterActivity.this, MapActivity.class);
|
||||
Intent newIntent = new Intent(EditPOIFilterActivity.this, SearchPOIActivity.class);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(SearchPOIActivity.AMENITY_FILTER, filter.getFilterId());
|
||||
newIntent.putExtras(bundle);
|
||||
startActivity(newIntent);
|
||||
}
|
||||
});
|
||||
|
@ -68,6 +70,18 @@ public class EditPOIFilterActivity extends ListActivity {
|
|||
|
||||
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) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
|
@ -85,7 +99,7 @@ public class EditPOIFilterActivity extends ListActivity {
|
|||
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (PoiFiltersHelper.removePoiFilter(EditPOIFilterActivity.this, filter)) {
|
||||
if (PoiFiltersHelper.removePoiFilter(helper, filter)) {
|
||||
Toast.makeText(
|
||||
EditPOIFilterActivity.this,
|
||||
MessageFormat.format(EditPOIFilterActivity.this.getText(R.string.edit_filter_delete_message).toString(),
|
||||
|
@ -106,7 +120,7 @@ public class EditPOIFilterActivity extends ListActivity {
|
|||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
PoiFilter nFilter = new PoiFilter(editText.getText().toString(), null, filter.getAcceptedTypes());
|
||||
if (PoiFiltersHelper.createPoiFilter(EditPOIFilterActivity.this, nFilter)) {
|
||||
if (PoiFiltersHelper.createPoiFilter(helper, nFilter)) {
|
||||
Toast.makeText(
|
||||
EditPOIFilterActivity.this,
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
private void showDialog(final AmenityType amenity) {
|
||||
Builder builder = new AlertDialog.Builder(this);
|
||||
ScrollView scroll = new ScrollView(this);
|
||||
ListView listView = new ListView(this);
|
||||
final List<String> accepted = new ArrayList<String>();
|
||||
|
||||
final LinkedHashSet<String> subCategories = new LinkedHashSet<String>(AmenityType.getSubCategories(amenity));
|
||||
List<String> subtypes = filter.getAcceptedSubtypes(amenity);
|
||||
boolean allSubTypesAccepted = subtypes == null;
|
||||
|
@ -139,40 +153,42 @@ public class EditPOIFilterActivity extends ListActivity {
|
|||
}
|
||||
|
||||
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++) {
|
||||
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(EditPOIFilterActivity.this.getText(R.string.default_buttons_cancel), new DialogInterface.OnClickListener() {
|
||||
builder.setNeutralButton(EditPOIFilterActivity.this.getText(R.string.close), new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
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()) {
|
||||
filter.selectSubTypesToAccept(amenity, null);
|
||||
} else {
|
||||
filter.selectSubTypesToAccept(amenity, accepted);
|
||||
}
|
||||
PoiFiltersHelper.editPoiFilter(EditPOIFilterActivity.this, filter);
|
||||
PoiFiltersHelper.editPoiFilter(helper, filter);
|
||||
((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
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
filter.selectSubTypesToAccept(amenity, null);
|
||||
PoiFiltersHelper.editPoiFilter(EditPOIFilterActivity.this, filter);
|
||||
PoiFiltersHelper.editPoiFilter(helper, filter);
|
||||
((AmenityAdapter) EditPOIFilterActivity.this.getListAdapter()).notifyDataSetInvalidated();
|
||||
}
|
||||
});
|
||||
|
@ -181,17 +197,23 @@ public class EditPOIFilterActivity extends ListActivity {
|
|||
|
||||
@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]);
|
||||
}
|
||||
|
||||
selected[item] = isChecked;
|
||||
}
|
||||
});
|
||||
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> {
|
||||
AmenityAdapter(AmenityType[] amenityTypes) {
|
||||
|
@ -217,7 +239,6 @@ public class EditPOIFilterActivity extends ListActivity {
|
|||
|
||||
private void addRowListener(final AmenityType model, final TextView text, final CheckBox check) {
|
||||
text.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showDialog(model);
|
||||
|
@ -225,7 +246,6 @@ public class EditPOIFilterActivity extends ListActivity {
|
|||
});
|
||||
|
||||
check.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (check.isChecked()) {
|
||||
|
@ -233,7 +253,7 @@ public class EditPOIFilterActivity extends ListActivity {
|
|||
showDialog(model);
|
||||
} else {
|
||||
filter.setTypeToAccept(model, false);
|
||||
PoiFiltersHelper.editPoiFilter(EditPOIFilterActivity.this, filter);
|
||||
PoiFiltersHelper.editPoiFilter(helper, filter);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue