Implement POI search by name

This commit is contained in:
Victor Shcherb 2011-09-29 18:03:49 +02:00
parent dd95a862ee
commit e770138e5b
11 changed files with 31 additions and 32 deletions

View file

@ -555,9 +555,8 @@ public class IndexPoiCreator extends AbstractIndexPartCreator {
}
public static void main(String[] args) throws SQLException, FileNotFoundException, IOException {
// TODO support multiple reading amenity types! +/-
// TODO support proper POI editing
// TODO support cancelling poi search request! Do it in another thread (Check is cancelled()!!!)
// TODO implement activity searching by name
long time = System.currentTimeMillis();
IndexPoiCreator poiCreator = new IndexPoiCreator();
// String fileSqlte = "/home/victor/projects/OsmAnd/data/osm-gen/POI/Ru-mow.poi.odb";

View file

@ -1,10 +1,12 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
<string name="button_upgrade_osmandplus">Upgrade Osmand+</string>
<string name="map_version_changed_info">On server are map files incompatible with your current version of application. To download and use them, please upgrade the application to newer version.</string>
<string name="poi_filter_by_name">Search by name</string>
<string name="old_poi_file_should_be_deleted">The poi data file \'%1$s\' is deprecated and can be deleted.</string>
<string name="update_poi_file_not_found">Local file to maintain poi changes not found and could not be created.</string>
<string name="update_poi_does_not_change_indexes">Changing poi inside application doesn\'t affect map files you downloaded but collects all changes in local file.</string>
<string name="button_upgrade_osmandplus">Upgrade Osmand+</string>
<string name="map_version_changed_info">On server are map files incompatible with your current version of application. To download and use them, please upgrade the application to newer version.</string>
<string name="local_index_mi_rename">Rename</string>
<string name="show_gpx_route">Show on map</string>

View file

@ -205,10 +205,10 @@ public class AmenityIndexRepositoryOdb extends BaseLocationIndexRepository<Ameni
stat.bindLong(1, a.getId());
stat.bindDouble(2, MapUtils.get31TileNumberX(a.getLocation().getLongitude()));
stat.bindDouble(3, MapUtils.get31TileNumberY(a.getLocation().getLatitude()));
dataBottomLatitude = Math.min(a.getLocation().getLatitude(), dataBottomLatitude);
dataTopLatitude = Math.max(a.getLocation().getLatitude(), dataTopLatitude);
dataLeftLongitude = Math.min(a.getLocation().getLongitude(), dataLeftLongitude);
dataRightLongitude = Math.max(a.getLocation().getLongitude(), dataRightLongitude);
dataBottomLatitude = Math.min(a.getLocation().getLatitude() - 0.5, dataBottomLatitude);
dataTopLatitude = Math.max(a.getLocation().getLatitude() + 0.5, dataTopLatitude);
dataLeftLongitude = Math.min(a.getLocation().getLongitude() - 0.5, dataLeftLongitude);
dataRightLongitude = Math.max(a.getLocation().getLongitude() + 0.5, dataRightLongitude);
bindString(stat, 4, a.getEnName());
bindString(stat, 5, a.getName());
bindString(stat, 6, AmenityType.valueToString(a.getType()));

View file

@ -15,7 +15,6 @@ public class IndexFileList implements Serializable {
private static final long serialVersionUID = 1L;
TreeMap<String, IndexItem> indexFiles = new TreeMap<String, IndexItem>(new Comparator<String>(){
@SuppressWarnings("unused")
private static final long serialVersionUID = 1L;
@Override

View file

@ -19,6 +19,7 @@ public class PoiFilter {
public final static String STD_PREFIX = "std_"; //$NON-NLS-1$
public final static String USER_PREFIX = "user_"; //$NON-NLS-1$
public final static String CUSTOM_FILTER_ID = USER_PREFIX + "custom_id"; //$NON-NLS-1$
public final static String BY_NAME_FILTER_ID = USER_PREFIX + "by_name"; //$NON-NLS-1$
private Map<AmenityType, LinkedHashSet<String>> acceptedTypes = new LinkedHashMap<AmenityType, LinkedHashSet<String>>();
private String filterByName = null;

View file

@ -125,6 +125,8 @@ public class PoiFiltersHelper {
cacheUserDefinedFilters = new ArrayList<PoiFilter>();
PoiFilter filter = new PoiFilter(application.getString(R.string.poi_filter_custom_filter), PoiFilter.CUSTOM_FILTER_ID, new LinkedHashMap<AmenityType, LinkedHashSet<String>>(), application); //$NON-NLS-1$
cacheUserDefinedFilters.add(filter);
filter = new PoiFilter(application.getString(R.string.poi_filter_by_name), PoiFilter.BY_NAME_FILTER_ID, new LinkedHashMap<AmenityType, LinkedHashSet<String>>(), application); //$NON-NLS-1$
cacheUserDefinedFilters.add(filter);
PoiFilterDbHelper helper = openDbHelper();
cacheUserDefinedFilters.addAll(helper.getFilters());
helper.close();
@ -153,7 +155,8 @@ public class PoiFiltersHelper {
}
public boolean removePoiFilter(PoiFilter filter){
if(filter.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID)){
if(filter.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID) ||
filter.getFilterId().equals(PoiFilter.BY_NAME_FILTER_ID)){
return false;
}
PoiFilterDbHelper helper = openDbHelper();
@ -184,7 +187,8 @@ public class PoiFiltersHelper {
public boolean editPoiFilter(PoiFilter filter) {
if (filter.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID)) {
if (filter.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID) ||
filter.getFilterId().equals(PoiFilter.BY_NAME_FILTER_ID)) {
return false;
}
PoiFilterDbHelper helper = openDbHelper();

View file

@ -512,15 +512,8 @@ public class ResourceManager {
}
}
File updatablePoiDbFile = context.getSettings().extendOsmandPath(MINE_POI_DB);
if(updatablePoiDbFile.exists() && file.canRead()){
try {
AmenityIndexRepositoryOdb odb = new AmenityIndexRepositoryOdb();
boolean initialize = odb.initialize(progress, updatablePoiDbFile);
if(initialize){
this.updatablePoiDb = odb;
}
} catch (SQLiteException e) {
}
if(updatablePoiDbFile.exists() && updatablePoiDbFile.canRead()){
tryToOpenUpdatablePoiDb(updatablePoiDbFile);
}
return warnings;
}

View file

@ -614,10 +614,10 @@ public class EditingPOIActivity {
@Override
public void run() {
if (repo == null) {
Toast.makeText(app, app.getString(R.string.update_poi_no_offline_poi_index), Toast.LENGTH_SHORT).show();
Toast.makeText(app, app.getString(R.string.update_poi_no_offline_poi_index), Toast.LENGTH_LONG).show();
return;
} else {
Toast.makeText(app, app.getString(R.string.update_poi_does_not_change_indexes), Toast.LENGTH_SHORT).show();
Toast.makeText(app, app.getString(R.string.update_poi_does_not_change_indexes), Toast.LENGTH_LONG).show();
}
}
});

View file

@ -210,10 +210,10 @@ public class MapActivityActions {
final AmenityIndexRepositoryOdb repo = ((OsmandApplication) mapActivity.getApplication()).
getResourceManager().getUpdatablePoiDb();
if(repo == null){
Toast.makeText(mapActivity, getString(R.string.update_poi_no_offline_poi_index), Toast.LENGTH_SHORT).show();
Toast.makeText(mapActivity, getString(R.string.update_poi_no_offline_poi_index), Toast.LENGTH_LONG).show();
return;
} else {
Toast.makeText(mapActivity, getString(R.string.update_poi_does_not_change_indexes), Toast.LENGTH_SHORT).show();
Toast.makeText(mapActivity, getString(R.string.update_poi_does_not_change_indexes), Toast.LENGTH_LONG).show();
}
final OsmandMapTileView mapView = mapActivity.getMapView();
Rect pixRect = new Rect(-mapView.getWidth()/2, -mapView.getHeight()/2, 3*mapView.getWidth()/2, 3*mapView.getHeight()/2);

View file

@ -423,8 +423,10 @@ public class MapActivityLayers {
final PoiFiltersHelper poiFilters = ((OsmandApplication)getApplication()).getPoiFilters();
for (PoiFilter f : poiFilters.getUserDefinedPoiFilters()) {
userDefined.add(f);
list.add(f.getName());
if(!f.getFilterId().equals(PoiFilter.BY_NAME_FILTER_ID)){
userDefined.add(f);
list.add(f.getName());
}
}
for(AmenityType t : AmenityType.values()){
list.add(OsmAndFormatter.toPublicString(t, activity));

View file

@ -13,9 +13,7 @@ import net.osmand.plus.PoiFiltersHelper;
import net.osmand.plus.R;
import net.osmand.plus.activities.EditPOIFilterActivity;
import net.osmand.plus.activities.OsmandApplication;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
@ -35,7 +33,6 @@ import android.widget.TextView;
*/
public class SearchPoiFilterActivity extends ListActivity {
private Typeface typeFace;
public static final String SEARCH_LAT = SearchActivity.SEARCH_LAT;
public static final String SEARCH_LON = SearchActivity.SEARCH_LON;
@ -46,7 +43,6 @@ public class SearchPoiFilterActivity extends ListActivity {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.searchpoilist);
typeFace = Typeface.create((String)null, Typeface.ITALIC);
// ListActivity has a ListView, which you can get with:
ListView lv = getListView();
@ -133,8 +129,11 @@ public class SearchPoiFilterActivity extends ListActivity {
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)){
label.setTypeface(typeFace);
if(model.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID) ||
model.getFilterId().equals(PoiFilter.BY_NAME_FILTER_ID)){
label.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
} else {
label.setTypeface(Typeface.DEFAULT);
}
icon.setImageResource(model.isStandardFilter() ? R.drawable.folder : R.drawable.favorites);
return (row);