refactoring poi filter usage
git-svn-id: https://osmand.googlecode.com/svn/trunk@152 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
efa35f6a16
commit
2304e94369
13 changed files with 210 additions and 181 deletions
|
@ -51,6 +51,9 @@ public class ToDoConstants {
|
|||
// 5. Improvement : Implement caching files existing on FS, implement specific method in RM
|
||||
// Introducing cache of file names that are on disk (creating new File() consumes a lot of memory)
|
||||
|
||||
// BUGS Swing
|
||||
// 1. Bug renaming region
|
||||
|
||||
|
||||
// TODO swing
|
||||
// 4. Fix issues with big files (such as netherlands) - save memory (!)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.osmand.data;
|
||||
|
||||
import com.osmand.Algoritms;
|
||||
import com.osmand.osm.Entity;
|
||||
import com.osmand.osm.OSMSettings.OSMTagKey;
|
||||
|
||||
|
@ -98,8 +97,7 @@ public class Amenity extends MapObject {
|
|||
|
||||
|
||||
public String getSimpleFormat(boolean en){
|
||||
return Algoritms.capitalizeFirstLetterAndLowercase(getType().toString()) +
|
||||
" : " + getStringWithoutType(en);
|
||||
return AmenityType.toPublicString(type) + " : " + getStringWithoutType(en);
|
||||
}
|
||||
|
||||
public String getStringWithoutType(boolean en){
|
||||
|
|
|
@ -5,6 +5,8 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.osmand.Algoritms;
|
||||
|
||||
// http://wiki.openstreetmap.org/wiki/Amenity
|
||||
// POI tags : amenity, leisure, shop, sport, tourism, historic; accessories (internet-access), natural ?
|
||||
public enum AmenityType {
|
||||
|
@ -23,7 +25,11 @@ public enum AmenityType {
|
|||
;
|
||||
|
||||
public static AmenityType fromString(String s){
|
||||
return AmenityType.valueOf(s.toUpperCase());
|
||||
try {
|
||||
return AmenityType.valueOf(s.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return AmenityType.OTHER;
|
||||
}
|
||||
}
|
||||
|
||||
public static String valueToString(AmenityType t){
|
||||
|
@ -44,6 +50,10 @@ public enum AmenityType {
|
|||
return list;
|
||||
}
|
||||
|
||||
public static String toPublicString(AmenityType t){
|
||||
return Algoritms.capitalizeFirstLetterAndLowercase(t.toString().replace('_', ' '));
|
||||
}
|
||||
|
||||
|
||||
protected static Map<String, AmenityType> amenityMap = new LinkedHashMap<String, AmenityType>();
|
||||
static {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<activity android:name=".activities.FavouritesActivity" android:label="@string/favourites_activity"></activity>
|
||||
|
||||
<activity android:name=".activities.search.SearchPOIActivity" android:label="@string/searchpoi_activity"></activity>
|
||||
<activity android:name=".activities.search.SearchPOIListActivity"></activity>
|
||||
<activity android:name=".activities.search.SearchPoiFilterActivity"></activity>
|
||||
<activity android:name=".activities.search.SearchAddressActivity"></activity>
|
||||
<activity android:name=".activities.search.SearchCityByNameActivity"></activity>
|
||||
<activity android:name=".activities.search.SearchRegionByNameActivity"></activity>
|
||||
|
|
|
@ -34,15 +34,20 @@ public class AmenityIndexRepository {
|
|||
private double cBottomLatitude;
|
||||
private double cLeftLongitude;
|
||||
private double cRightLongitude;
|
||||
private String cFilterId;
|
||||
|
||||
|
||||
|
||||
private final String[] columns = IndexConstants.generateColumnNames(IndexPoiTable.values());
|
||||
public List<Amenity> searchAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int limit, AmenityType type, List<Amenity> amenities){
|
||||
public List<Amenity> searchAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int limit, PoiFilter filter, List<Amenity> amenities){
|
||||
long now = System.currentTimeMillis();
|
||||
String squery = "? < latitude AND latitude < ? AND ? < longitude AND longitude < ?";
|
||||
if(type != null){
|
||||
squery += " AND type = " + "'" +AmenityType.valueToString(type)+ "'";
|
||||
|
||||
if(filter != null){
|
||||
String sql = filter.buildSqlWhereFilter();
|
||||
if(sql != null){
|
||||
squery += " AND " + sql;
|
||||
}
|
||||
}
|
||||
Cursor query = db.query(IndexPoiTable.getTable(), columns, squery,
|
||||
new String[]{Double.toString(bottomLatitude),
|
||||
|
@ -80,32 +85,34 @@ public class AmenityIndexRepository {
|
|||
cBottomLatitude = 0;
|
||||
cRightLongitude = 0;
|
||||
cLeftLongitude = 0;
|
||||
cFilterId = null;
|
||||
}
|
||||
|
||||
public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, List<Amenity> toFill){
|
||||
public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, PoiFilter filter, List<Amenity> toFill){
|
||||
cachedAmenities.clear();
|
||||
cTopLatitude = topLatitude + (topLatitude -bottomLatitude);
|
||||
cBottomLatitude = bottomLatitude - (topLatitude -bottomLatitude);
|
||||
cLeftLongitude = leftLongitude - (rightLongitude - leftLongitude);
|
||||
cRightLongitude = rightLongitude + (rightLongitude - leftLongitude);
|
||||
cFilterId = filter == null? null :filter.getFilterId();
|
||||
// first of all put all entities in temp list in order to not freeze other read threads
|
||||
ArrayList<Amenity> tempList = new ArrayList<Amenity>();
|
||||
searchAmenities(cTopLatitude, cLeftLongitude, cBottomLatitude, cRightLongitude, -1, null, tempList);
|
||||
searchAmenities(cTopLatitude, cLeftLongitude, cBottomLatitude, cRightLongitude, -1, filter, tempList);
|
||||
synchronized (this) {
|
||||
cachedAmenities.clear();
|
||||
cachedAmenities.addAll(tempList);
|
||||
}
|
||||
|
||||
checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, toFill);
|
||||
checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, filter.getFilterId(), toFill);
|
||||
}
|
||||
|
||||
public synchronized boolean checkCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, List<Amenity> toFill, boolean fillFound){
|
||||
public synchronized boolean checkCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, String filterId, List<Amenity> toFill, boolean fillFound){
|
||||
if (db == null) {
|
||||
return true;
|
||||
}
|
||||
boolean inside = cTopLatitude >= topLatitude && cLeftLongitude <= leftLongitude && cRightLongitude >= rightLongitude
|
||||
&& cBottomLatitude <= bottomLatitude;
|
||||
if((inside || fillFound) && toFill != null){
|
||||
if((inside || fillFound) && toFill != null && Algoritms.objectEquals(filterId, cFilterId)){
|
||||
for(Amenity a : cachedAmenities){
|
||||
LatLon location = a.getLocation();
|
||||
if (location.getLatitude() <= topLatitude && location.getLongitude() >= leftLongitude && location.getLongitude() <= rightLongitude
|
||||
|
@ -116,8 +123,8 @@ public class AmenityIndexRepository {
|
|||
}
|
||||
return inside;
|
||||
}
|
||||
public boolean checkCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, List<Amenity> toFill){
|
||||
return checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, toFill, false);
|
||||
public boolean checkCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, String filterId, List<Amenity> toFill){
|
||||
return checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, filterId, toFill, false);
|
||||
}
|
||||
|
||||
public void initialize(final IProgress progress, File file) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.Map;
|
|||
|
||||
import com.osmand.data.Amenity;
|
||||
import com.osmand.data.AmenityType;
|
||||
import com.osmand.data.index.IndexConstants.IndexPoiTable;
|
||||
|
||||
public class PoiFilter {
|
||||
|
||||
|
@ -14,6 +15,8 @@ public class PoiFilter {
|
|||
public static String USER_PREFIX = "user_";
|
||||
|
||||
private Map<AmenityType, List<String>> acceptedTypes = new LinkedHashMap<AmenityType, List<String>>();
|
||||
private String filterByName = null;
|
||||
|
||||
private String filterId;
|
||||
private String name;
|
||||
private final boolean isStandardFilter;
|
||||
|
@ -96,6 +99,56 @@ public class PoiFilter {
|
|||
}
|
||||
}
|
||||
|
||||
public String buildSqlWhereFilter(){
|
||||
if(AmenityType.values().length == acceptedTypes.size()){
|
||||
boolean wildcard = true;
|
||||
for(AmenityType a : acceptedTypes.keySet()){
|
||||
if(acceptedTypes.get(a) != null){
|
||||
wildcard = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(wildcard){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if(acceptedTypes.size() == 0){
|
||||
return "1 > 1";
|
||||
}
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("(");
|
||||
boolean first = true;
|
||||
for(AmenityType a : acceptedTypes.keySet()){
|
||||
if(first){
|
||||
first = false;
|
||||
} else {
|
||||
b.append(" OR ");
|
||||
}
|
||||
b.append("(");
|
||||
b.append(IndexPoiTable.TYPE.name().toLowerCase()).append(" = '").append(AmenityType.valueToString(a)).append("'");
|
||||
if(acceptedTypes.get(a) != null){
|
||||
List<String> list = acceptedTypes.get(a);
|
||||
b.append(" AND ");
|
||||
b.append(IndexPoiTable.SUBTYPE.name().toLowerCase()).append(" IN (");
|
||||
boolean bfirst = true;
|
||||
for(String s : list){
|
||||
if(bfirst){
|
||||
bfirst = false;
|
||||
} else {
|
||||
b.append(", ");
|
||||
}
|
||||
b.append("'").append(s).append("'");
|
||||
}
|
||||
b.append(")");
|
||||
}
|
||||
b.append(")");
|
||||
}
|
||||
|
||||
b.append(")");
|
||||
return b.toString();
|
||||
|
||||
}
|
||||
|
||||
public void selectSubTypesToAccept(AmenityType t, List<String> accept){
|
||||
acceptedTypes.put(t, accept);
|
||||
}
|
||||
|
@ -104,6 +157,14 @@ public class PoiFilter {
|
|||
return filterId;
|
||||
}
|
||||
|
||||
public String getFilterByName() {
|
||||
return filterByName;
|
||||
}
|
||||
|
||||
public void setFilterByName(String filterByName) {
|
||||
this.filterByName = filterByName;
|
||||
}
|
||||
|
||||
public boolean isStandardFilter(){
|
||||
return isStandardFilter;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class PoiFiltersHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static List<PoiFilter> cacheUserDefinedFilters = new ArrayList<PoiFilter>();
|
||||
private static List<PoiFilter> cacheUserDefinedFilters;
|
||||
public static List<PoiFilter> getUserDefinedPoiFilters(Context ctx){
|
||||
if(cacheUserDefinedFilters == null){
|
||||
cacheUserDefinedFilters = new ArrayList<PoiFilter>();
|
||||
|
@ -37,7 +37,7 @@ public class PoiFiltersHelper {
|
|||
return cacheUserDefinedFilters;
|
||||
}
|
||||
|
||||
private static List<PoiFilter> cacheOsmDefinedFilters = new ArrayList<PoiFilter>();
|
||||
private static List<PoiFilter> cacheOsmDefinedFilters;
|
||||
public static List<PoiFilter> getOsmDefinedPoiFilters(Context ctx){
|
||||
if(cacheOsmDefinedFilters == null){
|
||||
cacheOsmDefinedFilters = new ArrayList<PoiFilter>();
|
||||
|
|
|
@ -17,7 +17,6 @@ import android.graphics.BitmapFactory;
|
|||
import android.os.Environment;
|
||||
|
||||
import com.osmand.data.Amenity;
|
||||
import com.osmand.data.AmenityType;
|
||||
import com.osmand.data.index.IndexConstants;
|
||||
import com.osmand.data.preparation.MapTileDownloader;
|
||||
import com.osmand.data.preparation.MapTileDownloader.DownloadRequest;
|
||||
|
@ -205,9 +204,8 @@ public class ResourceManager {
|
|||
}
|
||||
}
|
||||
|
||||
// //////////////////////////////////////////// Working with amenities
|
||||
// ////////////////////////////////////////////////
|
||||
public List<Amenity> searchAmenities(AmenityType type, double latitude, double longitude, int zoom, int limit) {
|
||||
// //////////////////////////////////////////// Working with amenities ////////////////////////////////////////////////
|
||||
public List<Amenity> searchAmenities(PoiFilter filter, double latitude, double longitude, int zoom, int limit) {
|
||||
double tileNumberX = Math.floor(MapUtils.getTileNumberX(zoom, longitude));
|
||||
double tileNumberY = Math.floor(MapUtils.getTileNumberY(zoom, latitude));
|
||||
double topLatitude = MapUtils.getLatitudeFromTile(zoom, tileNumberY);
|
||||
|
@ -217,8 +215,8 @@ public class ResourceManager {
|
|||
List<Amenity> amenities = new ArrayList<Amenity>();
|
||||
for (AmenityIndexRepository index : amenityRepositories) {
|
||||
if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) {
|
||||
if (!index.checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, amenities)) {
|
||||
index.searchAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, limit, type, amenities);
|
||||
if (!index.checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, filter.getFilterId(), amenities)) {
|
||||
index.searchAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, limit, filter, amenities);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -226,12 +224,13 @@ public class ResourceManager {
|
|||
return amenities;
|
||||
}
|
||||
|
||||
public void searchAmenitiesAsync(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, List<Amenity> toFill){
|
||||
public void searchAmenitiesAsync(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, PoiFilter filter, List<Amenity> toFill){
|
||||
String filterId = filter == null ? null : filter.getFilterId();
|
||||
for(AmenityIndexRepository index : amenityRepositories){
|
||||
if(index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)){
|
||||
if(!index.checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, toFill, true)){
|
||||
if(!index.checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, filterId, toFill, true)){
|
||||
asyncLoadingTiles.requestToLoadAmenities(
|
||||
new AmenityLoadRequest(index, topLatitude, leftLongitude, bottomLatitude, rightLongitude));
|
||||
new AmenityLoadRequest(index, topLatitude, leftLongitude, bottomLatitude, rightLongitude, filter));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -317,15 +316,17 @@ public class ResourceManager {
|
|||
public final double bottomLatitude;
|
||||
public final double leftLongitude;
|
||||
public final double rightLongitude;
|
||||
public final PoiFilter filter;
|
||||
|
||||
public AmenityLoadRequest(AmenityIndexRepository repository, double topLatitude, double leftLongitude,
|
||||
double bottomLatitude, double rightLongitude) {
|
||||
double bottomLatitude, double rightLongitude, PoiFilter filter) {
|
||||
super();
|
||||
this.bottomLatitude = bottomLatitude;
|
||||
this.leftLongitude = leftLongitude;
|
||||
this.repository = repository;
|
||||
this.rightLongitude = rightLongitude;
|
||||
this.topLatitude = topLatitude;
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
|
||||
|
@ -348,21 +349,21 @@ public class ResourceManager {
|
|||
boolean amenityLoaded = false;
|
||||
while(!requests.isEmpty()){
|
||||
Object req = requests.pop();
|
||||
if(req instanceof TileLoadDownloadRequest){
|
||||
if (req instanceof TileLoadDownloadRequest) {
|
||||
TileLoadDownloadRequest r = (TileLoadDownloadRequest) req;
|
||||
if(cacheOfImages.get(r.fileToLoad) == null) {
|
||||
update |= getRequestedImageTile(r) != null;
|
||||
}
|
||||
if (cacheOfImages.get(r.fileToLoad) == null) {
|
||||
update |= getRequestedImageTile(r) != null;
|
||||
}
|
||||
} else if(req instanceof AmenityLoadRequest){
|
||||
if(!amenityLoaded){
|
||||
AmenityLoadRequest r = (AmenityLoadRequest) req;
|
||||
r.repository.evaluateCachedAmenities(r.topLatitude, r.leftLongitude,
|
||||
r.bottomLatitude, r.rightLongitude, null);
|
||||
r.bottomLatitude, r.rightLongitude, r.filter, null);
|
||||
amenityLoaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(update){
|
||||
if(update || amenityLoaded){
|
||||
// use downloader callback
|
||||
for(IMapDownloaderCallback c : downloader.getDownloaderCallbacks()){
|
||||
c.tileDownloaded(null);
|
||||
|
|
|
@ -23,7 +23,7 @@ public class SearchActivity extends TabActivity {
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
TabHost host = getTabHost();
|
||||
host.addTab(host.newTabSpec("Search_POI").setIndicator("POI").setContent(new Intent(this, SearchPOIListActivity.class)));
|
||||
host.addTab(host.newTabSpec("Search_POI").setIndicator("POI").setContent(new Intent(this, SearchPoiFilterActivity.class)));
|
||||
host.addTab(host.newTabSpec("Search_Address").setIndicator("Address").setContent(new Intent(this, SearchAddressActivity.class)));
|
||||
host.addTab(host.newTabSpec("Search_Location").setIndicator("Location").setContent(new Intent(this, NavigatePointActivity.class)));
|
||||
}
|
||||
|
|
|
@ -21,13 +21,13 @@ import android.widget.ListView;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.osmand.Algoritms;
|
||||
import com.osmand.OsmandSettings;
|
||||
import com.osmand.PoiFilter;
|
||||
import com.osmand.PoiFiltersHelper;
|
||||
import com.osmand.R;
|
||||
import com.osmand.ResourceManager;
|
||||
import com.osmand.activities.MapActivity;
|
||||
import com.osmand.data.Amenity;
|
||||
import com.osmand.data.AmenityType;
|
||||
import com.osmand.osm.LatLon;
|
||||
import com.osmand.osm.MapUtils;
|
||||
|
||||
|
@ -37,7 +37,7 @@ import com.osmand.osm.MapUtils;
|
|||
*/
|
||||
public class SearchPOIActivity extends ListActivity {
|
||||
|
||||
public static final String AMENITY_TYPE = "amenity_type";
|
||||
public static final String AMENITY_FILTER = "amenity_filter";
|
||||
|
||||
private List<Amenity> amenityList;
|
||||
|
||||
|
@ -47,7 +47,7 @@ public class SearchPOIActivity extends ListActivity {
|
|||
private final static int limitOfClosest = 30;
|
||||
private int zoom = 13;
|
||||
|
||||
private AmenityType amenityType;
|
||||
private PoiFilter filter;
|
||||
|
||||
private AmenityAdapter amenityAdapter;
|
||||
|
||||
|
@ -65,7 +65,7 @@ public class SearchPOIActivity extends ListActivity {
|
|||
if (zoom > finalZoom) {
|
||||
--zoom;
|
||||
}
|
||||
amenityList = resourceManager.searchAmenities(amenityType, lastKnownMapLocation.getLatitude(), lastKnownMapLocation
|
||||
amenityList = resourceManager.searchAmenities(filter, lastKnownMapLocation.getLatitude(), lastKnownMapLocation
|
||||
.getLongitude(), zoom, -1);
|
||||
if (amenityList != null) {
|
||||
MapUtils.sortListOfMapObject(amenityList, lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude());
|
||||
|
@ -77,22 +77,18 @@ public class SearchPOIActivity extends ListActivity {
|
|||
});
|
||||
|
||||
Bundle bundle = this.getIntent().getExtras();
|
||||
String anemity = bundle.getString(AMENITY_TYPE);
|
||||
if (anemity != null) {
|
||||
String filterId = bundle.getString(AMENITY_FILTER);
|
||||
if (filterId != null) {
|
||||
ResourceManager resourceManager = ResourceManager.getResourceManager();
|
||||
lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(this);
|
||||
amenityType = findAmenityType(anemity);
|
||||
if (amenityType != null) {
|
||||
amenityList = resourceManager.searchAmenities(amenityType, lastKnownMapLocation.getLatitude(), lastKnownMapLocation
|
||||
filter = PoiFiltersHelper.getFilterById(this, filterId);
|
||||
amenityList = resourceManager.searchAmenities(filter, lastKnownMapLocation.getLatitude(), lastKnownMapLocation
|
||||
.getLongitude(), zoom, maxCount);
|
||||
} else {
|
||||
amenityList = resourceManager.searchAmenities(amenityType, lastKnownMapLocation.getLatitude(), lastKnownMapLocation
|
||||
.getLongitude(), zoom + 2, maxCount);
|
||||
}
|
||||
|
||||
if (amenityList != null) {
|
||||
MapUtils.sortListOfMapObject(amenityList, lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude());
|
||||
if(amenityType == null){
|
||||
// TODO filter closest pois
|
||||
if(filter.isStandardFilter()){
|
||||
while (amenityList.size() > limitOfClosest) {
|
||||
amenityList.remove(amenityList.size() - 1);
|
||||
}
|
||||
|
@ -129,27 +125,16 @@ public class SearchPOIActivity extends ListActivity {
|
|||
}
|
||||
}
|
||||
|
||||
private AmenityType findAmenityType(String string) {
|
||||
for (AmenityType type : AmenityType.values()) {
|
||||
if (string.equals(Algoritms.capitalizeFirstLetterAndLowercase(type.toString()))) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
class AmenityAdapter extends ArrayAdapter {
|
||||
AmenityAdapter(Object list) {
|
||||
super(SearchPOIActivity.this, R.layout.searchpoi_list, (List<?>) list);
|
||||
class AmenityAdapter extends ArrayAdapter<Amenity> {
|
||||
AmenityAdapter(List<Amenity> list) {
|
||||
super(SearchPOIActivity.this, R.layout.searchpoi_list, list);
|
||||
this.setNotifyOnChange(false);
|
||||
}
|
||||
|
||||
public void setNewModel(List<?> amenityList) {
|
||||
public void setNewModel(List<Amenity> amenityList) {
|
||||
setNotifyOnChange(false);
|
||||
((AmenityAdapter) getListAdapter()).clear();
|
||||
for (Object obj : amenityList) {
|
||||
for (Amenity obj : amenityList) {
|
||||
this.add(obj);
|
||||
}
|
||||
this.notifyDataSetChanged();
|
||||
|
@ -165,29 +150,20 @@ public class SearchPOIActivity extends ListActivity {
|
|||
TextView label = (TextView) row.findViewById(R.id.poi_label);
|
||||
TextView distanceLabel = (TextView) row.findViewById(R.id.poidistance_label);
|
||||
ImageView icon = (ImageView) row.findViewById(R.id.poi_icon);
|
||||
Object model = getModel(position);
|
||||
if (model instanceof Amenity) {
|
||||
Amenity anemity = (Amenity) model;
|
||||
if (anemity != null) {
|
||||
LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(SearchPOIActivity.this);
|
||||
int dist = (int) (MapUtils.getDistance(anemity.getLocation(), lastKnownMapLocation.getLatitude(), lastKnownMapLocation
|
||||
.getLongitude()));
|
||||
String str = anemity.getStringWithoutType(OsmandSettings.usingEnglishNames(SearchPOIActivity.this));
|
||||
label.setText(str);
|
||||
if(anemity.getOpeningHours() != null) {
|
||||
icon.setImageResource(R.drawable.poi);
|
||||
} else{
|
||||
icon.setImageResource(R.drawable.closed_poi);
|
||||
}
|
||||
distanceLabel.setText(" " + dist + " m ");
|
||||
}
|
||||
Amenity amenity = getItem(position);
|
||||
LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(SearchPOIActivity.this);
|
||||
int dist = (int) (MapUtils.getDistance(amenity.getLocation(), lastKnownMapLocation.getLatitude(), lastKnownMapLocation
|
||||
.getLongitude()));
|
||||
String str = amenity.getStringWithoutType(OsmandSettings.usingEnglishNames(SearchPOIActivity.this));
|
||||
label.setText(str);
|
||||
if (amenity.getOpeningHours() != null) {
|
||||
icon.setImageResource(R.drawable.poi);
|
||||
} else {
|
||||
icon.setImageResource(R.drawable.closed_poi);
|
||||
}
|
||||
distanceLabel.setText(" " + dist + " m ");
|
||||
return (row);
|
||||
}
|
||||
|
||||
private Object getModel(int position) {
|
||||
return (((AmenityAdapter) getListAdapter()).getItem(position));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package com.osmand.activities.search;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import android.app.ListActivity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.osmand.Algoritms;
|
||||
import com.osmand.R;
|
||||
import com.osmand.data.AmenityType;
|
||||
|
||||
/**
|
||||
* @author Maxim Frolov
|
||||
*
|
||||
*/
|
||||
public class SearchPOIListActivity extends ListActivity {
|
||||
|
||||
List<String> amenityList = new ArrayList<String>();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
setContentView(R.layout.searchpoilist);
|
||||
createAmenityTypeList();
|
||||
setListAdapter(new AmenityAdapter(amenityList));
|
||||
|
||||
}
|
||||
|
||||
private void createAmenityTypeList() {
|
||||
amenityList.add(getResources().getString(R.string.Closest_Amenities));
|
||||
for (AmenityType type : AmenityType.values()) {
|
||||
amenityList.add(Algoritms.capitalizeFirstLetterAndLowercase(type.toString()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void onListItemClick(ListView parent, View v, int position, long id) {
|
||||
AmenityType amenityType = findAmenityType(amenityList.get(position));
|
||||
Bundle bundle = new Bundle();
|
||||
Intent newIntent = new Intent(SearchPOIListActivity.this, SearchPOIActivity.class);
|
||||
// folder selected
|
||||
if (amenityType != null) {
|
||||
bundle.putString(SearchPOIActivity.AMENITY_TYPE, amenityList.get(position));
|
||||
} else {
|
||||
bundle.putString(SearchPOIActivity.AMENITY_TYPE, "Closest_Amenities");
|
||||
}
|
||||
newIntent.putExtras(bundle);
|
||||
startActivityForResult(newIntent, 0);
|
||||
}
|
||||
|
||||
private AmenityType findAmenityType(String string) {
|
||||
for (AmenityType type : AmenityType.values()) {
|
||||
if (string.equals(Algoritms.capitalizeFirstLetterAndLowercase(type.toString()))) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
class AmenityAdapter extends ArrayAdapter {
|
||||
AmenityAdapter(Object list) {
|
||||
super(SearchPOIListActivity.this, R.layout.searchpoi_list, (List<?>) list);
|
||||
}
|
||||
|
||||
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);
|
||||
Object model = getModel(position);
|
||||
label.setText((String) model);
|
||||
icon.setImageResource(R.drawable.folder);
|
||||
return (row);
|
||||
}
|
||||
|
||||
private Object getModel(int position) {
|
||||
return (((AmenityAdapter) getListAdapter()).getItem(position));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package com.osmand.activities.search;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import android.app.ListActivity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.osmand.PoiFilter;
|
||||
import com.osmand.PoiFiltersHelper;
|
||||
import com.osmand.R;
|
||||
|
||||
/**
|
||||
* @author Maxim Frolov
|
||||
*
|
||||
*/
|
||||
public class SearchPoiFilterActivity extends ListActivity {
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
setContentView(R.layout.searchpoilist);
|
||||
List<PoiFilter> filters = PoiFiltersHelper.getOsmDefinedPoiFilters(this);
|
||||
setListAdapter(new AmenityAdapter(filters));
|
||||
}
|
||||
|
||||
|
||||
public void onListItemClick(ListView parent, View v, int position, long id) {
|
||||
PoiFilter filter = ((AmenityAdapter) getListAdapter()).getItem(position);
|
||||
Bundle bundle = new Bundle();
|
||||
Intent newIntent = new Intent(SearchPoiFilterActivity.this, SearchPOIActivity.class);
|
||||
// folder selected
|
||||
bundle.putString(SearchPOIActivity.AMENITY_FILTER, filter.getFilterId());
|
||||
newIntent.putExtras(bundle);
|
||||
startActivityForResult(newIntent, 0);
|
||||
}
|
||||
|
||||
|
||||
class AmenityAdapter extends ArrayAdapter<PoiFilter> {
|
||||
AmenityAdapter(List<PoiFilter> list) {
|
||||
super(SearchPoiFilterActivity.this, R.layout.searchpoi_list, list);
|
||||
}
|
||||
|
||||
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());
|
||||
icon.setImageResource(R.drawable.folder);
|
||||
return (row);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -105,7 +105,7 @@ public class POIMapLayer implements OsmandMapLayer {
|
|||
double rightLongitude = MapUtils.getLongitudeFromTile(view.getZoom(), tileRect.right);
|
||||
|
||||
objects.clear();
|
||||
resourceManager.searchAmenitiesAsync(topLatitude, leftLongitude, bottomLatitude, rightLongitude, objects);
|
||||
resourceManager.searchAmenitiesAsync(topLatitude, leftLongitude, bottomLatitude, rightLongitude, null, objects);
|
||||
for (Amenity o : objects) {
|
||||
int x = view.getMapXForPoint(o.getLocation().getLongitude());
|
||||
int y = view.getMapYForPoint(o.getLocation().getLatitude());
|
||||
|
|
Loading…
Reference in a new issue