implement draft version of search by address activity

git-svn-id: https://osmand.googlecode.com/svn/trunk@105 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-05-31 18:48:18 +00:00
parent ec0f5747bb
commit 3011d7eeba
15 changed files with 306 additions and 94 deletions

View file

@ -25,6 +25,15 @@ public class ToDoConstants {
// 16. Support open street bugs api.
// 20. Implement save track/route to gpx (?)
// TODO search story :
// 1) Implement loading villages when user types more than 2 symbols
// 2) Find intersection of streets
// 3) Shows progress dialog (?)
// 4) Implement finding buildings
// 5) Show on map
// 6) Show street on map
// 7) Show distance to the village (to distinguish)
// FIXME Bugs Android :
// 1. When firstly run osmand navigation (from notification bar) show map & go to menu shows desktop.
// No chance to close application

View file

@ -10,15 +10,18 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activities.MapActivity" android:label="@string/app_name">
</activity>
<activity android:name=".activities.SettingsActivity"
android:label="@string/settings_activity"></activity>
<activity android:name=".activities.MapActivity" android:label="@string/app_name"></activity>
<activity android:name=".activities.SettingsActivity" android:label="@string/settings_activity"></activity>
<activity android:label="@string/search_activity" android:name=".activities.search.SearchActivity"></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.SearchAddressActivity"></activity>
<activity android:name=".activities.search.SearchCityByNameActivity"></activity>
<activity android:name=".activities.search.SearchRegionByNameActivity"></activity>
<activity android:name=".activities.search.SearchStreetByNameActivity"></activity>
<activity android:name=".activities.search.SearchBuildingByNameActivity"></activity>
</application>

View file

@ -3,16 +3,19 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<TextView android:text="Select city or street or building" android:id="@+id/TextView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"
android:layout_marginTop = "5dp">
</TextView>
<ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content">
<TableLayout android:id="@+id/TableLayout" android:stretchColumns="1" android:layout_width="fill_parent" android:layout_height="wrap_content">
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp">
<TextView android:text="Region" android:id="@+id/TextView">
</TextView>
<Button android:id="@+id/CountryButton" android:text="@string/ChooseCountry">
</Button>
<ImageButton android:id="@+id/ResetCountry" android:background="@drawable/icon">
<ImageButton android:id="@+id/ResetCountry" android:background="@drawable/icon" android:layout_marginRight = "5dp">
</ImageButton>
</TableRow>
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp" >
@ -20,7 +23,7 @@
</TextView>
<Button android:id="@+id/CityButton" android:text="@string/choose_city">
</Button>
<ImageButton android:id="@+id/ResetCity" android:background="@drawable/icon">
<ImageButton android:id="@+id/ResetCity" android:background="@drawable/icon" android:layout_marginRight = "5dp">
</ImageButton>
</TableRow>
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp">
@ -28,7 +31,7 @@
</TextView>
<Button android:id="@+id/StreetButton" android:text="@string/choose_street">
</Button>
<ImageButton android:id="@+id/ResetStreet" android:background="@drawable/icon">
<ImageButton android:id="@+id/ResetStreet" android:background="@drawable/icon" android:layout_marginRight = "5dp">
</ImageButton>
</TableRow>
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp">
@ -36,14 +39,15 @@
</TextView>
<Button android:id="@+id/BuildingButton" android:text="@string/choose_building">
</Button>
<ImageButton android:id="@+id/ResetBuilding" android:background="@drawable/icon">
<ImageButton android:id="@+id/ResetBuilding" android:background="@drawable/icon" android:layout_marginRight = "5dp">
</ImageButton>
</TableRow>
</TableLayout>
</ScrollView>
<LinearLayout android:id="@+id/LinearLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"
android:gravity="right|bottom">
<Button android:text="Show on map" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/ShowOnMap">
</Button>
</LinearLayout>
</LinearLayout>

View file

@ -10,6 +10,6 @@
</LinearLayout>
<ListView android:id="@+id/ListView" android:layout_width="fill_parent" android:layout_height="fill_parent"
<ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_marginLeft="3dp" android:layout_marginTop="3dp" android:layout_marginRight="3dp"></ListView>
</LinearLayout>

View file

@ -3,5 +3,5 @@
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:id="@+id/NameLabel" android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
android:layout_height="fill_parent" android:textSize="18dp"/>
</LinearLayout>

View file

@ -58,6 +58,10 @@ public class RegionAddressRepository {
}
public City getCityById(Long id){
if(id == -1){
// do not preload cities for that case
return null;
}
preloadCities();
return cities.get(id);
}
@ -81,6 +85,25 @@ public class RegionAddressRepository {
return null;
}
public void fillWithSuggestedStreets(City c, String name, List<Street> streetsToFill){
preloadStreets(c);
name = name.toLowerCase();
int ind = 0;
if(name.length() == 0){
streetsToFill.addAll(c.getStreets());
return;
}
for (Street s : c.getStreets()) {
String lowerCase = s.getName().toLowerCase();
if (lowerCase.startsWith(name)) {
streetsToFill.add(ind, s);
ind++;
} else if (lowerCase.contains(name)) {
streetsToFill.add(s);
}
}
}
public void fillWithSuggestedCities(String name, List<City> citiesToFill, List<City> source){
preloadCities();
if(name.length() < 3){
@ -139,8 +162,15 @@ public class RegionAddressRepository {
public void preloadCities(){
if (cities.isEmpty()) {
Cursor query = db.query(IndexCityTable.getTable(), IndexConstants.generateColumnNames(IndexCityTable.values()), null, null,
null, null, null);
log.debug("Start loading cities for " +getName());
// TODO allow cities of all types
StringBuilder where = new StringBuilder();
where.append(IndexCityTable.CITY_TYPE.toString()).append('=').
append('\'').append(CityType.valueToString(CityType.CITY)).append('\'').append(" or ").
append(IndexCityTable.CITY_TYPE.toString()).append('=').
append('\'').append(CityType.valueToString(CityType.TOWN)).append('\'');
Cursor query = db.query(IndexCityTable.getTable(), IndexConstants.generateColumnNames(IndexCityTable.values()),
where.toString(), null, null, null, null);
if(query.moveToFirst()){
do {
CityType type = CityType.valueFromString(query.getString(IndexCityTable.CITY_TYPE.ordinal()));
@ -160,6 +190,7 @@ public class RegionAddressRepository {
} while(query.moveToNext());
}
log.debug("Loaded " + cities.size() + " cities");
query.close();
}
}

View file

@ -173,8 +173,10 @@ public class ResourceManager {
if (file.exists() && file.canRead()) {
for (File f : file.listFiles()) {
if (f.getName().endsWith(IndexConstants.ADDRESS_INDEX_EXT)) {
// TODO fill in address index
RegionAddressRepository repository = new RegionAddressRepository();
progress.startTask("Indexing address" + f.getName(), -1);
repository.initialize(progress, f);
addressMap.put(repository.getName(), repository);
}
}
}

View file

@ -127,9 +127,7 @@ public class MainMenuActivity extends Activity {
searchButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final Intent search = new Intent(MainMenuActivity.this,
SearchActivity.class);
// search.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
final Intent search = new Intent(MainMenuActivity.this, SearchActivity.class);
startActivity(search);
}
});

View file

@ -20,19 +20,6 @@ public class SearchActivity extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//
// setContentView(R.layout.search);
//
// searchPOIButton = (Button) findViewById(R.id.SearchPOIButton);
// searchPOIButton.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// final Intent search = new Intent(SearchActivity.this, SearchPOIListActivity.class);
// search.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
// startActivity(search);
//
// }
// });
TabHost host = getTabHost();
host.addTab(host.newTabSpec("Search_POI").setIndicator("Search POI").setContent(new Intent(this, SearchPOIListActivity.class)));
host.addTab(host.newTabSpec("Search_Adress").setIndicator("Search Address").setContent(new Intent(this, SearchAddressActivity.class)));

View file

@ -2,6 +2,7 @@ package com.osmand.activities.search;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
@ -39,6 +40,34 @@ public class SearchAddressActivity extends Activity {
cityButton = (Button) findViewById(R.id.CityButton);
countryButton = (Button) findViewById(R.id.CountryButton);
buildingButton = (Button) findViewById(R.id.BuildingButton);
attachListeners();
}
private void attachListeners() {
countryButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
startActivity(new Intent(SearchAddressActivity.this, SearchRegionByNameActivity.class));
}
});
cityButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
startActivity(new Intent(SearchAddressActivity.this, SearchCityByNameActivity.class));
}
});
streetButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
startActivity(new Intent(SearchAddressActivity.this, SearchStreetByNameActivity.class));
}
});
buildingButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
startActivity(new Intent(SearchAddressActivity.this, SearchBuildingByNameActivity.class));
}
});
findViewById(R.id.ResetBuilding).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
@ -73,6 +102,7 @@ public class SearchAddressActivity extends Activity {
updateUI();
}
});
}
protected void updateUI(){

View file

@ -0,0 +1,47 @@
package com.osmand.activities.search;
import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.widget.TextView;
import com.osmand.OsmandSettings;
import com.osmand.RegionAddressRepository;
import com.osmand.ResourceManager;
import com.osmand.data.City;
import com.osmand.data.Street;
public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity<Street> {
private RegionAddressRepository region;
private City city;
@Override
protected void onCreate(Bundle savedInstanceState) {
region = ResourceManager.getResourceManager().getRegionRepository(OsmandSettings.getLastSearchedRegion(this));
if(region != null){
city = region.getCityById(OsmandSettings.getLastSearchedCity(this));
}
super.onCreate(savedInstanceState);
}
@Override
public List<Street> getObjects() {
List<Street> l = new ArrayList<Street>();
if(city != null){
region.fillWithSuggestedStreets(city, "", l);
}
return l;
}
@Override
public void updateTextView(Street obj, TextView txt) {
txt.setText(obj.getName());
}
@Override
public void itemSelected(Street obj) {
OsmandSettings.setLastSearchedStreet(this, obj.getName());
finish();
}
}

View file

@ -0,0 +1,55 @@
package com.osmand.activities.search;
import java.util.List;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.osmand.R;
public abstract class SearchByNameAbstractActivity<T> extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.search_by_name);
NamesAdapter namesAdapter = new NamesAdapter(getObjects());
setListAdapter(namesAdapter);
}
public abstract List<T> getObjects();
public abstract void updateTextView(T obj, TextView txt);
public abstract void itemSelected(T obj);
@SuppressWarnings("unchecked")
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
T repo = (T) getListAdapter().getItem(position);
itemSelected(repo);
}
class NamesAdapter extends ArrayAdapter<T> {
NamesAdapter(List<T> list) {
super(SearchByNameAbstractActivity.this, R.layout.searchbyname_list, list);
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(R.layout.searchbyname_list, parent, false);
TextView label = (TextView) row.findViewById(R.id.NameLabel);
updateTextView(getItem(position), label);
return row;
}
}
}

View file

@ -1,16 +1,42 @@
package com.osmand.activities.search;
import com.osmand.R;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.widget.TextView;
public class SearchCityByNameActivity extends Activity {
import com.osmand.OsmandSettings;
import com.osmand.RegionAddressRepository;
import com.osmand.ResourceManager;
import com.osmand.data.City;
public class SearchCityByNameActivity extends SearchByNameAbstractActivity<City> {
private RegionAddressRepository region;
@Override
protected void onCreate(Bundle savedInstanceState) {
region = ResourceManager.getResourceManager().getRegionRepository(OsmandSettings.getLastSearchedRegion(this));
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.search_by_name);
}
@Override
public List<City> getObjects() {
List<City> l = new ArrayList<City>();
if(region != null){
region.fillWithSuggestedCities("", l, null);
}
return l;
}
@Override
public void updateTextView(City obj, TextView txt) {
txt.setText(obj.getName());
}
@Override
public void itemSelected(City obj) {
OsmandSettings.setLastSearchedCity(this, obj.getId());
finish();
}
}

View file

@ -1,57 +1,30 @@
package com.osmand.activities.search;
import java.util.Collection;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.widget.TextView;
import com.osmand.R;
import com.osmand.OsmandSettings;
import com.osmand.RegionAddressRepository;
import com.osmand.ResourceManager;
public class SearchRegionByNameActivity extends Activity {
public class SearchRegionByNameActivity extends SearchByNameAbstractActivity<RegionAddressRepository> {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.search_by_name);
Collection<RegionAddressRepository> repos = ResourceManager.getResourceManager().getAddressRepositories();
// setListAdapter(new ArrayAdapter<T>);
}
/*class NamesAdapter extends ArrayAdapter<Object> {
NamesAdapter(Object list) {
super(SearchActivity.this, R.layout.searchlist, (List<?>) list);
public List<RegionAddressRepository> getObjects() {
return new ArrayList<RegionAddressRepository>(ResourceManager.getResourceManager().getAddressRepositories());
}
@Override
public int getCount() {
int c = super.getCount();
return c > 20 ? 20 : c;
public void updateTextView(RegionAddressRepository obj, TextView txt) {
txt.setText(obj.getName());
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(R.layout.searchlist, parent, false);
TextView label = (TextView) row.findViewById(R.id.label);
ImageView icon = (ImageView) row.findViewById(R.id.icon);
Object model = getModel(position);
if (model instanceof String) {
label.setText((String) model);
icon.setImageResource(R.drawable.folder);
} else if (model instanceof Amenity) {
Amenity anemity = (Amenity) model;
if (anemity != null) {
LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(SearchActivity.this);
int dist = (int) (MapUtils.getDistance(anemity.getLocation(), lastKnownMapLocation.getLatitude(), lastKnownMapLocation
.getLongitude()));
String str = anemity.getStringWithoutType() + " [" + dist + " m ]";
label.setText(str);
icon.setImageResource(R.drawable.poi);
@Override
public void itemSelected(RegionAddressRepository obj) {
OsmandSettings.setLastSearchedRegion(this, obj.getName());
finish();
}
}
return (row);
}*/
}

View file

@ -0,0 +1,47 @@
package com.osmand.activities.search;
import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.widget.TextView;
import com.osmand.OsmandSettings;
import com.osmand.RegionAddressRepository;
import com.osmand.ResourceManager;
import com.osmand.data.City;
import com.osmand.data.Street;
public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Street> {
private RegionAddressRepository region;
private City city;
@Override
protected void onCreate(Bundle savedInstanceState) {
region = ResourceManager.getResourceManager().getRegionRepository(OsmandSettings.getLastSearchedRegion(this));
if(region != null){
city = region.getCityById(OsmandSettings.getLastSearchedCity(this));
}
super.onCreate(savedInstanceState);
}
@Override
public List<Street> getObjects() {
List<Street> l = new ArrayList<Street>();
if(city != null){
region.fillWithSuggestedStreets(city, "", l);
}
return l;
}
@Override
public void updateTextView(Street obj, TextView txt) {
txt.setText(obj.getName());
}
@Override
public void itemSelected(Street obj) {
OsmandSettings.setLastSearchedStreet(this, obj.getName());
finish();
}
}