Fix compilation problems for rebasing
This commit is contained in:
parent
ed10e42a39
commit
aec4273cf1
6 changed files with 364 additions and 364 deletions
|
@ -26,11 +26,11 @@ public class PostCode extends MapObject {
|
||||||
return streets.values();
|
return streets.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAllStreets()
|
public void removeAllStreets()
|
||||||
{
|
{
|
||||||
streets.clear();
|
streets.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Street registerStreet(Street street, boolean useEnglishNames){
|
public Street registerStreet(Street street, boolean useEnglishNames){
|
||||||
String name = street.getName(useEnglishNames);
|
String name = street.getName(useEnglishNames);
|
||||||
streets.put(name, street);
|
streets.put(name, street);
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent" android:orientation="vertical">
|
android:layout_height="fill_parent" android:orientation="vertical">
|
||||||
<TextView android:id="@+id/TextView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"
|
<TextView android:id="@+id/TextView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"
|
||||||
android:layout_marginTop = "5dp" android:text="@string/search_osm_offline"/>
|
android:layout_marginTop = "5dp" android:text="@string/search_osm_offline"/>
|
||||||
|
|
||||||
<ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="wrap_content"></ListView>
|
<ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="wrap_content"></ListView>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -1,337 +1,337 @@
|
||||||
package net.osmand.activities.search;
|
package net.osmand.activities.search;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import net.osmand.OsmandSettings;
|
import net.osmand.OsmandSettings;
|
||||||
import net.osmand.R;
|
import net.osmand.R;
|
||||||
import net.osmand.RegionAddressRepository;
|
import net.osmand.RegionAddressRepository;
|
||||||
import net.osmand.ResourceManager;
|
import net.osmand.ResourceManager;
|
||||||
import net.osmand.activities.MapActivity;
|
import net.osmand.activities.MapActivity;
|
||||||
import net.osmand.activities.OsmandApplication;
|
import net.osmand.activities.OsmandApplication;
|
||||||
import net.osmand.data.City;
|
import net.osmand.data.City;
|
||||||
import net.osmand.data.MapObject;
|
import net.osmand.data.MapObject;
|
||||||
import net.osmand.data.PostCode;
|
import net.osmand.data.PostCode;
|
||||||
import net.osmand.data.Street;
|
import net.osmand.data.Street;
|
||||||
import net.osmand.osm.LatLon;
|
import net.osmand.osm.LatLon;
|
||||||
import net.osmand.osm.MapUtils;
|
import net.osmand.osm.MapUtils;
|
||||||
import net.osmand.osm.Node;
|
import net.osmand.osm.Node;
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.DialogInterface.OnCancelListener;
|
import android.content.DialogInterface.OnCancelListener;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class GeoIntentActivity extends ListActivity {
|
public class GeoIntentActivity extends ListActivity {
|
||||||
|
|
||||||
private ProgressDialog progressDlg;
|
private ProgressDialog progressDlg;
|
||||||
private LatLon location;
|
private LatLon location;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.search_address_offline);
|
setContentView(R.layout.search_address_offline);
|
||||||
location = OsmandSettings.getLastKnownMapLocation(OsmandSettings
|
location = OsmandSettings.getLastKnownMapLocation(OsmandSettings
|
||||||
.getPrefs(this));
|
.getPrefs(this));
|
||||||
final Intent intent = getIntent();
|
final Intent intent = getIntent();
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
progressDlg = ProgressDialog.show(this,
|
progressDlg = ProgressDialog.show(this,
|
||||||
getString(R.string.searching),
|
getString(R.string.searching),
|
||||||
getString(R.string.searching_address));
|
getString(R.string.searching_address));
|
||||||
final Thread searcher = new Thread(new Runnable() {
|
final Thread searcher = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Collection<MapObject> results = extract(
|
Collection<MapObject> results = extract(
|
||||||
intent.getData()).execute();
|
intent.getData()).execute();
|
||||||
// show the first result on map, and populate the list!
|
// show the first result on map, and populate the list!
|
||||||
if (!results.isEmpty()) {
|
if (!results.isEmpty()) {
|
||||||
showResult(0, new ArrayList<MapObject>(results));
|
showResult(0, new ArrayList<MapObject>(results));
|
||||||
} else {
|
} else {
|
||||||
showResult(R.string.search_nothing_found, null);
|
showResult(R.string.search_nothing_found, null);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
showResult(R.string.error_doing_search, null);
|
showResult(R.string.error_doing_search, null);
|
||||||
} finally {
|
} finally {
|
||||||
progressDlg.dismiss();
|
progressDlg.dismiss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, "SearchingAddress");
|
}, "SearchingAddress");
|
||||||
searcher.start();
|
searcher.start();
|
||||||
progressDlg.setOnCancelListener(new OnCancelListener() {
|
progressDlg.setOnCancelListener(new OnCancelListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCancel(DialogInterface dialog) {
|
public void onCancel(DialogInterface dialog) {
|
||||||
searcher.interrupt();
|
searcher.interrupt();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
progressDlg.setCancelable(true);
|
progressDlg.setCancelable(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
// finish();
|
// finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showResult(final int warning, final List<MapObject> places) {
|
private void showResult(final int warning, final List<MapObject> places) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (places == null) {
|
if (places == null) {
|
||||||
Toast.makeText(GeoIntentActivity.this, getString(warning),
|
Toast.makeText(GeoIntentActivity.this, getString(warning),
|
||||||
Toast.LENGTH_LONG).show();
|
Toast.LENGTH_LONG).show();
|
||||||
} else {
|
} else {
|
||||||
setListAdapter(new MapObjectAdapter(places));
|
setListAdapter(new MapObjectAdapter(places));
|
||||||
if (places.size() == 1) {
|
if (places.size() == 1) {
|
||||||
onListItemClick(getListView(), getListAdapter()
|
onListItemClick(getListView(), getListAdapter()
|
||||||
.getView(0, null, null), 0, getListAdapter()
|
.getView(0, null, null), 0, getListAdapter()
|
||||||
.getItemId(0));
|
.getItemId(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class MapObjectAdapter extends ArrayAdapter<MapObject> {
|
class MapObjectAdapter extends ArrayAdapter<MapObject> {
|
||||||
|
|
||||||
public MapObjectAdapter(List<MapObject> places) {
|
public MapObjectAdapter(List<MapObject> places) {
|
||||||
super(GeoIntentActivity.this,
|
super(GeoIntentActivity.this,
|
||||||
R.layout.search_address_offline_list_item, places);
|
R.layout.search_address_offline_list_item, places);
|
||||||
}
|
}
|
||||||
|
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
View row = convertView;
|
View row = convertView;
|
||||||
if (row == null) {
|
if (row == null) {
|
||||||
LayoutInflater inflater = getLayoutInflater();
|
LayoutInflater inflater = getLayoutInflater();
|
||||||
row = inflater.inflate(
|
row = inflater.inflate(
|
||||||
R.layout.search_address_offline_list_item, parent,
|
R.layout.search_address_offline_list_item, parent,
|
||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
MapObject model = getItem(position);
|
MapObject model = getItem(position);
|
||||||
TextView label = (TextView) row.findViewById(R.id.label);
|
TextView label = (TextView) row.findViewById(R.id.label);
|
||||||
TextView distanceLabel = (TextView) row
|
TextView distanceLabel = (TextView) row
|
||||||
.findViewById(R.id.distance_label);
|
.findViewById(R.id.distance_label);
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
int dist = (int) (MapUtils.getDistance(location, model
|
int dist = (int) (MapUtils.getDistance(location, model
|
||||||
.getLocation().getLatitude(), model.getLocation()
|
.getLocation().getLatitude(), model.getLocation()
|
||||||
.getLongitude()));
|
.getLongitude()));
|
||||||
distanceLabel.setText(MapUtils.getFormattedDistance(dist));
|
distanceLabel.setText(MapUtils.getFormattedDistance(dist));
|
||||||
} else {
|
} else {
|
||||||
distanceLabel.setText(""); //$NON-NLS-1$
|
distanceLabel.setText(""); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
label.setText(model.toString());
|
label.setText(model.toString());
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||||
super.onListItemClick(l, v, position, id);
|
super.onListItemClick(l, v, position, id);
|
||||||
MapObject item = ((MapObjectAdapter) getListAdapter())
|
MapObject item = ((MapObjectAdapter) getListAdapter())
|
||||||
.getItem(position);
|
.getItem(position);
|
||||||
OsmandSettings.setMapLocationToShow(this, item.getLocation()
|
OsmandSettings.setMapLocationToShow(this, item.getLocation()
|
||||||
.getLatitude(), item.getLocation().getLongitude(),
|
.getLatitude(), item.getLocation().getLongitude(),
|
||||||
getString(R.string.address) + " : " + item.toString()); //$NON-NLS-1$
|
getString(R.string.address) + " : " + item.toString()); //$NON-NLS-1$
|
||||||
startActivity(new Intent(this, MapActivity.class));
|
startActivity(new Intent(this, MapActivity.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
dismiss();
|
dismiss();
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dismiss() {
|
private void dismiss() {
|
||||||
if (progressDlg != null) {
|
if (progressDlg != null) {
|
||||||
progressDlg.dismiss();
|
progressDlg.dismiss();
|
||||||
progressDlg = null;
|
progressDlg = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* geo:latitude,longitude<BR>
|
* geo:latitude,longitude<BR>
|
||||||
* geo:latitude,longitude?z=zoom<BR>
|
* geo:latitude,longitude?z=zoom<BR>
|
||||||
* geo:0,0?q=my+street+address<BR>
|
* geo:0,0?q=my+street+address<BR>
|
||||||
* geo:0,0?q=business+near+city
|
* geo:0,0?q=business+near+city
|
||||||
*
|
*
|
||||||
* @param data
|
* @param data
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private MyService extract(Uri data) {
|
private MyService extract(Uri data) {
|
||||||
// it is 0,0? that means a search
|
// it is 0,0? that means a search
|
||||||
if (data.getSchemeSpecificPart().indexOf("0,0?") != -1) {
|
if (data.getSchemeSpecificPart().indexOf("0,0?") != -1) {
|
||||||
return new GeoAddressSearch(data.getQuery());
|
return new GeoAddressSearch(data.getQuery());
|
||||||
} else {
|
} else {
|
||||||
return new GeoPointSearch(data.getSchemeSpecificPart());
|
return new GeoPointSearch(data.getSchemeSpecificPart());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class GeoAddressSearch implements MyService {
|
private final class GeoAddressSearch implements MyService {
|
||||||
private List<String> elements;
|
private List<String> elements;
|
||||||
|
|
||||||
public GeoAddressSearch(String query) {
|
public GeoAddressSearch(String query) {
|
||||||
StringTokenizer s = new StringTokenizer(query.substring(query
|
StringTokenizer s = new StringTokenizer(query.substring(query
|
||||||
.indexOf("q=") + 2), ",");
|
.indexOf("q=") + 2), ",");
|
||||||
elements = new ArrayList<String>(s.countTokens());
|
elements = new ArrayList<String>(s.countTokens());
|
||||||
while (s.hasMoreTokens()) {
|
while (s.hasMoreTokens()) {
|
||||||
elements.add(s.nextToken().replace('+', ' ').trim());
|
elements.add(s.nextToken().replace('+', ' ').trim());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<MapObject> execute() {
|
public Collection<MapObject> execute() {
|
||||||
if (elements.isEmpty()) {
|
if (elements.isEmpty()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// now try to search the City, Street, Etc.. if Street is not found,
|
// now try to search the City, Street, Etc.. if Street is not found,
|
||||||
// try to search POI
|
// try to search POI
|
||||||
ResourceManager resourceManager = resourceManager();
|
ResourceManager resourceManager = resourceManager();
|
||||||
List<RegionAddressRepository> foundCountries = new ArrayList<RegionAddressRepository>();
|
List<RegionAddressRepository> foundCountries = new ArrayList<RegionAddressRepository>();
|
||||||
RegionAddressRepository country;
|
RegionAddressRepository country;
|
||||||
for (String maybeCountry : elements) {
|
for (String maybeCountry : elements) {
|
||||||
country = resourceManager.getRegionRepository(maybeCountry);
|
country = resourceManager.getRegionRepository(maybeCountry);
|
||||||
if (country != null) {
|
if (country != null) {
|
||||||
foundCountries.add(country);
|
foundCountries.add(country);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collection<RegionAddressRepository> countriesToSearch = foundCountries;
|
Collection<RegionAddressRepository> countriesToSearch = foundCountries;
|
||||||
if (foundCountries.isEmpty()) {
|
if (foundCountries.isEmpty()) {
|
||||||
// there is no country, we have to search each country
|
// there is no country, we have to search each country
|
||||||
countriesToSearch = resourceManager.getAddressRepositories();
|
countriesToSearch = resourceManager.getAddressRepositories();
|
||||||
}
|
}
|
||||||
|
|
||||||
// search cities for found countries
|
// search cities for found countries
|
||||||
Map<RegionAddressRepository, List<MapObject>> citiesForRegion = new HashMap<RegionAddressRepository, List<MapObject>>();
|
Map<RegionAddressRepository, List<MapObject>> citiesForRegion = new HashMap<RegionAddressRepository, List<MapObject>>();
|
||||||
for (RegionAddressRepository rar : countriesToSearch) {
|
for (RegionAddressRepository rar : countriesToSearch) {
|
||||||
List<MapObject> citiesFound = new ArrayList<MapObject>();
|
List<MapObject> citiesFound = new ArrayList<MapObject>();
|
||||||
for (String maybeCity : elements) {
|
for (String maybeCity : elements) {
|
||||||
rar.fillWithSuggestedCities(maybeCity, citiesFound, null);
|
rar.fillWithSuggestedCities(maybeCity, citiesFound, null);
|
||||||
}
|
}
|
||||||
if (!citiesFound.isEmpty()) {
|
if (!citiesFound.isEmpty()) {
|
||||||
citiesForRegion.put(rar, citiesFound);
|
citiesForRegion.put(rar, citiesFound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// no cities found, we should locate the country only
|
// no cities found, we should locate the country only
|
||||||
Map<MapObject, List<Street>> streetsForCity = new HashMap<MapObject, List<Street>>();
|
Map<MapObject, List<Street>> streetsForCity = new HashMap<MapObject, List<Street>>();
|
||||||
if (citiesForRegion.isEmpty()) {
|
if (citiesForRegion.isEmpty()) {
|
||||||
for (RegionAddressRepository rar : countriesToSearch) {
|
for (RegionAddressRepository rar : countriesToSearch) {
|
||||||
ArrayList<MapObject> allcities = new ArrayList<MapObject>();
|
ArrayList<MapObject> allcities = new ArrayList<MapObject>();
|
||||||
rar.fillWithSuggestedCities("", allcities, location);
|
rar.fillWithSuggestedCities("", allcities, location);
|
||||||
findStreetsForCities(streetsForCity, rar, allcities);
|
findStreetsForCities(streetsForCity, rar, allcities);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// we have cities, now search for streets?
|
// we have cities, now search for streets?
|
||||||
for (RegionAddressRepository rar : citiesForRegion.keySet()) {
|
for (RegionAddressRepository rar : citiesForRegion.keySet()) {
|
||||||
findStreetsForCities(streetsForCity, rar,
|
findStreetsForCities(streetsForCity, rar,
|
||||||
citiesForRegion.get(rar));
|
citiesForRegion.get(rar));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't go deeper, now populate result list
|
// don't go deeper, now populate result list
|
||||||
Set<MapObject> results = new HashSet<MapObject>();
|
Set<MapObject> results = new HashSet<MapObject>();
|
||||||
// add all found lists
|
// add all found lists
|
||||||
for (List<Street> streets : streetsForCity.values()) {
|
for (List<Street> streets : streetsForCity.values()) {
|
||||||
results.addAll(streets);
|
results.addAll(streets);
|
||||||
}
|
}
|
||||||
// add all found cities for which street was not found
|
// add all found cities for which street was not found
|
||||||
for (List<MapObject> cities : citiesForRegion.values()) {
|
for (List<MapObject> cities : citiesForRegion.values()) {
|
||||||
cities.removeAll(streetsForCity.keySet());
|
cities.removeAll(streetsForCity.keySet());
|
||||||
results.addAll(cities);
|
results.addAll(cities);
|
||||||
}
|
}
|
||||||
// TODO add all regions for which city was not found
|
// TODO add all regions for which city was not found
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void findStreetsForCities(
|
private void findStreetsForCities(
|
||||||
Map<MapObject, List<Street>> streetsForCity,
|
Map<MapObject, List<Street>> streetsForCity,
|
||||||
RegionAddressRepository rar, List<MapObject> allcities) {
|
RegionAddressRepository rar, List<MapObject> allcities) {
|
||||||
for (MapObject city : allcities) {
|
for (MapObject city : allcities) {
|
||||||
List<Street> streets = new ArrayList<Street>();
|
List<Street> streets = new ArrayList<Street>();
|
||||||
rar.fillWithSuggestedStreets(city, streets,
|
rar.fillWithSuggestedStreets(city, streets,
|
||||||
elements.toArray(new String[] {}));
|
elements.toArray(new String[] {}));
|
||||||
// we must do this, or we will fill up the whole memory (streets
|
// we must do this, or we will fill up the whole memory (streets
|
||||||
// are preloaded...)
|
// are preloaded...)
|
||||||
// TODO some street iterator would be better, is it possible to
|
// TODO some street iterator would be better, is it possible to
|
||||||
// create one?
|
// create one?
|
||||||
if (city instanceof City) {
|
if (city instanceof City) {
|
||||||
((City) city).removeAllStreets();
|
((City) city).removeAllStreets();
|
||||||
} else if (city instanceof PostCode) {
|
} else if (city instanceof PostCode) {
|
||||||
((PostCode) city).removeAllStreets();
|
((PostCode) city).removeAllStreets();
|
||||||
}
|
}
|
||||||
if (!streets.isEmpty()) {
|
if (!streets.isEmpty()) {
|
||||||
streetsForCity.put(city, streets);
|
streetsForCity.put(city, streets);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResourceManager resourceManager() {
|
private ResourceManager resourceManager() {
|
||||||
return ((OsmandApplication) getApplication()).getResourceManager();
|
return ((OsmandApplication) getApplication()).getResourceManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class GeoPointSearch implements MyService {
|
private class GeoPointSearch implements MyService {
|
||||||
|
|
||||||
private MapObject point;
|
private MapObject point;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* geo:latitude,longitude geo:latitude,longitude?z=zoom
|
* geo:latitude,longitude geo:latitude,longitude?z=zoom
|
||||||
*/
|
*/
|
||||||
public GeoPointSearch(final String geo) {
|
public GeoPointSearch(final String geo) {
|
||||||
int latIndex = geo.indexOf(',');
|
int latIndex = geo.indexOf(',');
|
||||||
int lonIndex = geo.indexOf('?');
|
int lonIndex = geo.indexOf('?');
|
||||||
lonIndex = lonIndex > 0 ? lonIndex : geo.length();
|
lonIndex = lonIndex > 0 ? lonIndex : geo.length();
|
||||||
if (latIndex > 0) {
|
if (latIndex > 0) {
|
||||||
try {
|
try {
|
||||||
double latitude = Double.parseDouble(geo.substring(0,
|
double latitude = Double.parseDouble(geo.substring(0,
|
||||||
latIndex));
|
latIndex));
|
||||||
double longitude = Double.parseDouble(geo.substring(
|
double longitude = Double.parseDouble(geo.substring(
|
||||||
latIndex + 1, lonIndex));
|
latIndex + 1, lonIndex));
|
||||||
// TODO zoom is omited for now
|
// TODO zoom is omited for now
|
||||||
point = new MapObject(new Node(latitude, longitude, -1)) {
|
point = new MapObject(new Node(latitude, longitude, -1)) {
|
||||||
};
|
};
|
||||||
point.setName("Lat: " + latitude + ",Lon:" + longitude);
|
point.setName("Lat: " + latitude + ",Lon:" + longitude);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
Toast.makeText(GeoIntentActivity.this,
|
Toast.makeText(GeoIntentActivity.this,
|
||||||
getString(R.string.search_offline_geo_error, geo),
|
getString(R.string.search_offline_geo_error, geo),
|
||||||
Toast.LENGTH_LONG);
|
Toast.LENGTH_LONG);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<MapObject> execute() {
|
public Collection<MapObject> execute() {
|
||||||
if (point != null) {
|
if (point != null) {
|
||||||
return Collections.singletonList(point);
|
return Collections.singletonList(point);
|
||||||
} else {
|
} else {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private interface MyService {
|
private interface MyService {
|
||||||
|
|
||||||
public Collection<MapObject> execute();
|
public Collection<MapObject> execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ public interface RegionAddressRepository {
|
||||||
|
|
||||||
public void fillWithSuggestedStreetsIntersectStreets(City city, Street st, List<Street> streetsToFill);
|
public void fillWithSuggestedStreetsIntersectStreets(City city, Street st, List<Street> streetsToFill);
|
||||||
|
|
||||||
public void fillWithSuggestedStreets(MapObject cityOrPostcode, List<Street> streetsToFill, String... name);
|
public void fillWithSuggestedStreets(MapObject cityOrPostcode, List<Street> streetsToFill, String... name);
|
||||||
|
|
||||||
public void fillWithSuggestedCities(String name, List<MapObject> citiesToFill, LatLon currentLocation);
|
public void fillWithSuggestedCities(String name, List<MapObject> citiesToFill, LatLon currentLocation);
|
||||||
|
|
||||||
|
|
|
@ -85,22 +85,22 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillWithSuggestedStreets(MapObject o, List<Street> streetsToFill, String... names) {
|
public void fillWithSuggestedStreets(MapObject o, List<Street> streetsToFill, String... names) {
|
||||||
assert o instanceof PostCode || o instanceof City;
|
assert o instanceof PostCode || o instanceof City;
|
||||||
City city = (City) (o instanceof City ? o : null);
|
City city = (City) (o instanceof City ? o : null);
|
||||||
PostCode post = (PostCode) (o instanceof PostCode ? o : null);
|
PostCode post = (PostCode) (o instanceof PostCode ? o : null);
|
||||||
preloadStreets(o);
|
preloadStreets(o);
|
||||||
Collection<Street> streets = post == null ? city.getStreets() : post.getStreets() ;
|
Collection<Street> streets = post == null ? city.getStreets() : post.getStreets() ;
|
||||||
|
|
||||||
if(names.length == 0){
|
if(names.length == 0){
|
||||||
streetsToFill.addAll(streets);
|
streetsToFill.addAll(streets);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ind = 0;
|
int ind = 0;
|
||||||
for (Street s : streets) {
|
for (Street s : streets) {
|
||||||
String sName = useEnglishNames ? s.getEnName() : s.getName(); //lower case not needed, collator ensures that
|
String sName = useEnglishNames ? s.getEnName() : s.getName(); //lower case not needed, collator ensures that
|
||||||
for (String name : names) {
|
for (String name : names) {
|
||||||
if (cstartsWith(collator,sName,name)) {
|
if (cstartsWith(collator,sName,name)) {
|
||||||
streetsToFill.add(ind, s);
|
streetsToFill.add(ind, s);
|
||||||
ind++;
|
ind++;
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Str
|
||||||
public List<Street> getObjects(String filter) {
|
public List<Street> getObjects(String filter) {
|
||||||
List<Street> l = new ArrayList<Street>();
|
List<Street> l = new ArrayList<Street>();
|
||||||
if (city != null || postcode != null) {
|
if (city != null || postcode != null) {
|
||||||
region.fillWithSuggestedStreets(postcode == null ? city : postcode, l, filter);
|
region.fillWithSuggestedStreets(postcode == null ? city : postcode, l, filter);
|
||||||
}
|
}
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue