Implement search
This commit is contained in:
parent
1ab21d4033
commit
e864bee7cb
7 changed files with 39 additions and 34 deletions
|
@ -139,10 +139,10 @@ public class BinaryMapIndexReader {
|
|||
for(MapIndex map : mapIndexes){
|
||||
if(Algoritms.objectEquals(reg.name, map.name)){
|
||||
if(map.getRoots().size() > 0){
|
||||
MapRoot mapRoot = map.getRoots().get(0);
|
||||
MapRoot mapRoot = map.getRoots().get(map.getRoots().size() - 1);
|
||||
double cy = (MapUtils.get31LatitudeY(mapRoot.getBottom()) + MapUtils.get31LatitudeY(mapRoot.getTop())) / 2;
|
||||
double cx = (MapUtils.get31LongitudeX(mapRoot.getLeft()) + MapUtils.get31LongitudeX(mapRoot.getRight())) / 2;
|
||||
reg.calculatedCenter = new LatLon(cx, cy);
|
||||
reg.calculatedCenter = new LatLon(cy, cx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -864,8 +864,9 @@ public class OsmandSettings {
|
|||
}
|
||||
|
||||
public boolean setLastSearchedRegion(String region, LatLon l) {
|
||||
Editor edit = globalPreferences.edit().putString(LAST_SEARCHED_REGION, region).putLong(LAST_SEARCHED_CITY, -1)
|
||||
.putString(LAST_SEARCHED_CITY_NAME, "").putString(LAST_SEARCHED_STREET,"").putString(LAST_SEARCHED_BUILDING, ""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
Editor edit = globalPreferences.edit().putString(LAST_SEARCHED_REGION, region).putLong(LAST_SEARCHED_CITY, -1).
|
||||
putString(LAST_SEARCHED_CITY_NAME, "").putString(lAST_SEARCHED_POSTCODE, "").
|
||||
putString(LAST_SEARCHED_STREET,"").putString(LAST_SEARCHED_BUILDING, ""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
if (globalPreferences.contains(LAST_SEARCHED_INTERSECTED_STREET)) {
|
||||
edit.putString(LAST_SEARCHED_INTERSECTED_STREET, ""); //$NON-NLS-1$
|
||||
}
|
||||
|
@ -878,13 +879,15 @@ public class OsmandSettings {
|
|||
return globalPreferences.getString(lAST_SEARCHED_POSTCODE, null);
|
||||
}
|
||||
|
||||
public boolean setLastSearchedPostcode(String postcode){
|
||||
public boolean setLastSearchedPostcode(String postcode, LatLon point){
|
||||
Editor edit = globalPreferences.edit().putLong(LAST_SEARCHED_CITY, -1).putString(LAST_SEARCHED_STREET, "").putString( //$NON-NLS-1$
|
||||
LAST_SEARCHED_BUILDING, "").putString(lAST_SEARCHED_POSTCODE, postcode); //$NON-NLS-1$
|
||||
if(globalPreferences.contains(LAST_SEARCHED_INTERSECTED_STREET)){
|
||||
edit.putString(LAST_SEARCHED_INTERSECTED_STREET, ""); //$NON-NLS-1$
|
||||
}
|
||||
return edit.commit();
|
||||
boolean res = edit.commit();
|
||||
setLastSearchedPoint(point);
|
||||
return res;
|
||||
}
|
||||
|
||||
public Long getLastSearchedCity() {
|
||||
|
@ -895,34 +898,40 @@ public class OsmandSettings {
|
|||
return globalPreferences.getString(LAST_SEARCHED_CITY_NAME, "");
|
||||
}
|
||||
|
||||
public boolean setLastSearchedCity(Long cityId, String name) {
|
||||
public boolean setLastSearchedCity(Long cityId, String name, LatLon point) {
|
||||
Editor edit = globalPreferences.edit().putLong(LAST_SEARCHED_CITY, cityId).putString(LAST_SEARCHED_CITY_NAME, name).
|
||||
putString(LAST_SEARCHED_STREET, "").putString(LAST_SEARCHED_BUILDING, ""); //$NON-NLS-1$
|
||||
edit.remove(lAST_SEARCHED_POSTCODE);
|
||||
if(globalPreferences.contains(LAST_SEARCHED_INTERSECTED_STREET)){
|
||||
edit.putString(LAST_SEARCHED_INTERSECTED_STREET, ""); //$NON-NLS-1$
|
||||
}
|
||||
return edit.commit();
|
||||
boolean res = edit.commit();
|
||||
setLastSearchedPoint(point);
|
||||
return res;
|
||||
}
|
||||
|
||||
public String getLastSearchedStreet() {
|
||||
return globalPreferences.getString(LAST_SEARCHED_STREET, ""); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public boolean setLastSearchedStreet(String street) {
|
||||
public boolean setLastSearchedStreet(String street, LatLon point) {
|
||||
Editor edit = globalPreferences.edit().putString(LAST_SEARCHED_STREET, street).putString(LAST_SEARCHED_BUILDING, ""); //$NON-NLS-1$
|
||||
if (globalPreferences.contains(LAST_SEARCHED_INTERSECTED_STREET)) {
|
||||
edit.putString(LAST_SEARCHED_INTERSECTED_STREET, ""); //$NON-NLS-1$
|
||||
}
|
||||
return edit.commit();
|
||||
boolean res = edit.commit();
|
||||
setLastSearchedPoint(point);
|
||||
return res;
|
||||
}
|
||||
|
||||
public String getLastSearchedBuilding() {
|
||||
return globalPreferences.getString(LAST_SEARCHED_BUILDING, ""); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public boolean setLastSearchedBuilding(String building) {
|
||||
return globalPreferences.edit().putString(LAST_SEARCHED_BUILDING, building).remove(LAST_SEARCHED_INTERSECTED_STREET).commit();
|
||||
public boolean setLastSearchedBuilding(String building, LatLon point) {
|
||||
boolean res = globalPreferences.edit().putString(LAST_SEARCHED_BUILDING, building).remove(LAST_SEARCHED_INTERSECTED_STREET).commit();
|
||||
setLastSearchedPoint(point);
|
||||
return res;
|
||||
}
|
||||
|
||||
public String getLastSearchedIntersectedStreet() {
|
||||
|
@ -932,13 +941,11 @@ public class OsmandSettings {
|
|||
return globalPreferences.getString(LAST_SEARCHED_INTERSECTED_STREET, ""); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public boolean setLastSearchedIntersectedStreet(String street) {
|
||||
public boolean setLastSearchedIntersectedStreet(String street, LatLon l) {
|
||||
setLastSearchedPoint(l);
|
||||
return globalPreferences.edit().putString(LAST_SEARCHED_INTERSECTED_STREET, street).commit();
|
||||
}
|
||||
|
||||
public boolean removeLastSearchedIntersectedStreet() {
|
||||
return globalPreferences.edit().remove(LAST_SEARCHED_INTERSECTED_STREET).commit();
|
||||
}
|
||||
|
||||
public static final String SELECTED_POI_FILTER_FOR_MAP = "selected_poi_filter_for_map"; //$NON-NLS-1$
|
||||
|
||||
|
|
|
@ -91,10 +91,8 @@ public class SearchAddressActivity extends Activity {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
if(radioBuilding){
|
||||
osmandSettings.removeLastSearchedIntersectedStreet();
|
||||
startActivity(new Intent(SearchAddressActivity.this, SearchBuildingByNameActivity.class));
|
||||
} else {
|
||||
osmandSettings.setLastSearchedIntersectedStreet(""); //$NON-NLS-1$
|
||||
startActivity(new Intent(SearchAddressActivity.this, SearchStreet2ByNameActivity.class));
|
||||
}
|
||||
}
|
||||
|
@ -172,23 +170,23 @@ public class SearchAddressActivity extends Activity {
|
|||
}
|
||||
String historyName = null;
|
||||
int zoom = 12;
|
||||
if (street2 != null && street != null) {
|
||||
String cityName = postcode != null ? postcode : city;
|
||||
if (!Algoritms.isEmpty(street2) && !Algoritms.isEmpty(street)) {
|
||||
String cityName = !Algoritms.isEmpty(postcode) ? postcode : city;
|
||||
historyName = MessageFormat.format(getString(R.string.search_history_int_streets), street, street2,
|
||||
cityName);
|
||||
zoom = 16;
|
||||
} else if (building != null) {
|
||||
String cityName = postcode != null ? postcode : city;
|
||||
} else if (!Algoritms.isEmpty(building)) {
|
||||
String cityName = !Algoritms.isEmpty(postcode) ? postcode : city;
|
||||
historyName = MessageFormat.format(getString(R.string.search_history_building), building, street,
|
||||
cityName);
|
||||
zoom = 16;
|
||||
} else if (street != null) {
|
||||
} else if (!Algoritms.isEmpty(street)) {
|
||||
String cityName = postcode != null ? postcode : city;
|
||||
historyName = MessageFormat.format(getString(R.string.search_history_street), street, cityName);
|
||||
zoom = 14;
|
||||
} else if (city != null) {
|
||||
zoom = 15;
|
||||
} else if (!Algoritms.isEmpty(city)) {
|
||||
historyName = MessageFormat.format(getString(R.string.search_history_city), city);
|
||||
zoom = 12;
|
||||
zoom = 13;
|
||||
}
|
||||
if (navigateTo) {
|
||||
osmandSettings.setPointToNavigate(searchPoint.getLatitude(), searchPoint.getLongitude(), historyName);
|
||||
|
@ -226,7 +224,7 @@ public class SearchAddressActivity extends Activity {
|
|||
} else {
|
||||
countryButton.setText(region);
|
||||
}
|
||||
findViewById(R.id.ResetCity).setEnabled(postcode != null || city != null);
|
||||
findViewById(R.id.ResetCity).setEnabled(!Algoritms.isEmpty(city) || !Algoritms.isEmpty(postcode));
|
||||
if(Algoritms.isEmpty(city) && Algoritms.isEmpty(postcode)){
|
||||
cityButton.setText(R.string.choose_city);
|
||||
} else {
|
||||
|
@ -239,7 +237,7 @@ public class SearchAddressActivity extends Activity {
|
|||
cityButton.setEnabled(!Algoritms.isEmpty(region));
|
||||
|
||||
findViewById(R.id.ResetStreet).setEnabled(!Algoritms.isEmpty(street));
|
||||
if(street == null){
|
||||
if(Algoritms.isEmpty(street)){
|
||||
streetButton.setText(R.string.choose_street);
|
||||
} else {
|
||||
streetButton.setText(street);
|
||||
|
@ -269,7 +267,7 @@ public class SearchAddressActivity extends Activity {
|
|||
|
||||
if (!Algoritms.isEmpty(postcode) || !Algoritms.isEmpty(city)) {
|
||||
street = osmandSettings.getLastSearchedStreet();
|
||||
if (Algoritms.isEmpty(street)) {
|
||||
if (!Algoritms.isEmpty(street)) {
|
||||
String str = osmandSettings.getLastSearchedIntersectedStreet();
|
||||
radioBuilding = Algoritms.isEmpty(str);
|
||||
if (!radioBuilding) {
|
||||
|
|
|
@ -54,7 +54,7 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity<B
|
|||
|
||||
@Override
|
||||
public void itemSelected(Building obj) {
|
||||
settings.setLastSearchedBuilding(obj.getName(region.useEnglishNames()));
|
||||
settings.setLastSearchedBuilding(obj.getName(region.useEnglishNames()), obj.getLocation());
|
||||
finish();
|
||||
|
||||
}
|
||||
|
|
|
@ -53,12 +53,12 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<MapOb
|
|||
@Override
|
||||
public void itemSelected(MapObject obj) {
|
||||
if (obj instanceof City) {
|
||||
settings.setLastSearchedCity(obj.getId(), obj.getName(region.useEnglishNames()));
|
||||
settings.setLastSearchedCity(obj.getId(), obj.getName(region.useEnglishNames()), obj.getLocation());
|
||||
if (region.getCityById(obj.getId()) == null) {
|
||||
region.addCityToPreloadedList((City) obj);
|
||||
}
|
||||
} else if(obj instanceof PostCode){
|
||||
settings.setLastSearchedPostcode(obj.getName(region.useEnglishNames()));
|
||||
settings.setLastSearchedPostcode(obj.getName(region.useEnglishNames()), obj.getLocation());
|
||||
}
|
||||
finish();
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<St
|
|||
|
||||
@Override
|
||||
public void itemSelected(Street obj) {
|
||||
settings.setLastSearchedIntersectedStreet(obj.getName(region.useEnglishNames()));
|
||||
settings.setLastSearchedIntersectedStreet(obj.getName(region.useEnglishNames()), region.findStreetIntersection(street1, obj));
|
||||
finish();
|
||||
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Str
|
|||
|
||||
@Override
|
||||
public void itemSelected(Street obj) {
|
||||
settings.setLastSearchedStreet(obj.getName(region.useEnglishNames()));
|
||||
settings.setLastSearchedStreet(obj.getName(region.useEnglishNames()), obj.getLocation());
|
||||
finish();
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue