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:
parent
ec0f5747bb
commit
3011d7eeba
15 changed files with 306 additions and 94 deletions
|
@ -25,6 +25,15 @@ public class ToDoConstants {
|
||||||
// 16. Support open street bugs api.
|
// 16. Support open street bugs api.
|
||||||
// 20. Implement save track/route to gpx (?)
|
// 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 :
|
// FIXME Bugs Android :
|
||||||
// 1. When firstly run osmand navigation (from notification bar) show map & go to menu shows desktop.
|
// 1. When firstly run osmand navigation (from notification bar) show map & go to menu shows desktop.
|
||||||
// No chance to close application
|
// No chance to close application
|
||||||
|
|
|
@ -10,15 +10,18 @@
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".activities.MapActivity" android:label="@string/app_name">
|
<activity android:name=".activities.MapActivity" android:label="@string/app_name"></activity>
|
||||||
</activity>
|
<activity android:name=".activities.SettingsActivity" android:label="@string/settings_activity"></activity>
|
||||||
<activity android:name=".activities.SettingsActivity"
|
<activity android:label="@string/search_activity" android:name=".activities.search.SearchActivity"></activity>
|
||||||
android:label="@string/settings_activity"></activity>
|
<activity android:name=".activities.search.SearchPOIActivity" android:label="@string/searchpoi_activity"></activity>
|
||||||
<activity android:label="@string/search_activity" android:name=".activities.search.SearchActivity"></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>
|
||||||
|
|
||||||
<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>
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,24 +3,27 @@
|
||||||
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: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"
|
<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">
|
android:layout_marginTop = "5dp">
|
||||||
</TextView>
|
</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">
|
<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">
|
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp">
|
||||||
<TextView android:text="Region" android:id="@+id/TextView">
|
<TextView android:text="Region" android:id="@+id/TextView">
|
||||||
</TextView>
|
</TextView>
|
||||||
<Button android:id="@+id/CountryButton" android:text="@string/ChooseCountry">
|
<Button android:id="@+id/CountryButton" android:text="@string/ChooseCountry">
|
||||||
</Button>
|
</Button>
|
||||||
<ImageButton android:id="@+id/ResetCountry" android:background="@drawable/icon">
|
<ImageButton android:id="@+id/ResetCountry" android:background="@drawable/icon" android:layout_marginRight = "5dp">
|
||||||
</ImageButton>
|
</ImageButton>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp">
|
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp" >
|
||||||
<TextView android:text="City" android:id="@+id/TextView">
|
<TextView android:text="City" android:id="@+id/TextView">
|
||||||
</TextView>
|
</TextView>
|
||||||
<Button android:id="@+id/CityButton" android:text="@string/choose_city">
|
<Button android:id="@+id/CityButton" android:text="@string/choose_city">
|
||||||
</Button>
|
</Button>
|
||||||
<ImageButton android:id="@+id/ResetCity" android:background="@drawable/icon">
|
<ImageButton android:id="@+id/ResetCity" android:background="@drawable/icon" android:layout_marginRight = "5dp">
|
||||||
</ImageButton>
|
</ImageButton>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp">
|
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp">
|
||||||
|
@ -28,7 +31,7 @@
|
||||||
</TextView>
|
</TextView>
|
||||||
<Button android:id="@+id/StreetButton" android:text="@string/choose_street">
|
<Button android:id="@+id/StreetButton" android:text="@string/choose_street">
|
||||||
</Button>
|
</Button>
|
||||||
<ImageButton android:id="@+id/ResetStreet" android:background="@drawable/icon">
|
<ImageButton android:id="@+id/ResetStreet" android:background="@drawable/icon" android:layout_marginRight = "5dp">
|
||||||
</ImageButton>
|
</ImageButton>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp">
|
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp">
|
||||||
|
@ -36,14 +39,15 @@
|
||||||
</TextView>
|
</TextView>
|
||||||
<Button android:id="@+id/BuildingButton" android:text="@string/choose_building">
|
<Button android:id="@+id/BuildingButton" android:text="@string/choose_building">
|
||||||
</Button>
|
</Button>
|
||||||
<ImageButton android:id="@+id/ResetBuilding" android:background="@drawable/icon">
|
<ImageButton android:id="@+id/ResetBuilding" android:background="@drawable/icon" android:layout_marginRight = "5dp">
|
||||||
</ImageButton>
|
</ImageButton>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableLayout>
|
</TableLayout>
|
||||||
|
</ScrollView>
|
||||||
<LinearLayout android:id="@+id/LinearLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"
|
<LinearLayout android:id="@+id/LinearLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"
|
||||||
android:gravity="right|bottom">
|
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 android:text="Show on map" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/ShowOnMap">
|
||||||
</Button>
|
</Button>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
|
@ -10,6 +10,6 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</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>
|
android:layout_marginLeft="3dp" android:layout_marginTop="3dp" android:layout_marginRight="3dp"></ListView>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -3,5 +3,5 @@
|
||||||
android:layout_width="fill_parent" android:layout_height="wrap_content"
|
android:layout_width="fill_parent" android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
<TextView android:id="@+id/NameLabel" android:layout_width="fill_parent"
|
<TextView android:id="@+id/NameLabel" android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"/>
|
android:layout_height="fill_parent" android:textSize="18dp"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -58,6 +58,10 @@ public class RegionAddressRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
public City getCityById(Long id){
|
public City getCityById(Long id){
|
||||||
|
if(id == -1){
|
||||||
|
// do not preload cities for that case
|
||||||
|
return null;
|
||||||
|
}
|
||||||
preloadCities();
|
preloadCities();
|
||||||
return cities.get(id);
|
return cities.get(id);
|
||||||
}
|
}
|
||||||
|
@ -81,6 +85,25 @@ public class RegionAddressRepository {
|
||||||
return null;
|
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){
|
public void fillWithSuggestedCities(String name, List<City> citiesToFill, List<City> source){
|
||||||
preloadCities();
|
preloadCities();
|
||||||
if(name.length() < 3){
|
if(name.length() < 3){
|
||||||
|
@ -139,8 +162,15 @@ public class RegionAddressRepository {
|
||||||
|
|
||||||
public void preloadCities(){
|
public void preloadCities(){
|
||||||
if (cities.isEmpty()) {
|
if (cities.isEmpty()) {
|
||||||
Cursor query = db.query(IndexCityTable.getTable(), IndexConstants.generateColumnNames(IndexCityTable.values()), null, null,
|
log.debug("Start loading cities for " +getName());
|
||||||
null, null, null);
|
// 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()){
|
if(query.moveToFirst()){
|
||||||
do {
|
do {
|
||||||
CityType type = CityType.valueFromString(query.getString(IndexCityTable.CITY_TYPE.ordinal()));
|
CityType type = CityType.valueFromString(query.getString(IndexCityTable.CITY_TYPE.ordinal()));
|
||||||
|
@ -160,6 +190,7 @@ public class RegionAddressRepository {
|
||||||
|
|
||||||
} while(query.moveToNext());
|
} while(query.moveToNext());
|
||||||
}
|
}
|
||||||
|
log.debug("Loaded " + cities.size() + " cities");
|
||||||
query.close();
|
query.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,8 +173,10 @@ public class ResourceManager {
|
||||||
if (file.exists() && file.canRead()) {
|
if (file.exists() && file.canRead()) {
|
||||||
for (File f : file.listFiles()) {
|
for (File f : file.listFiles()) {
|
||||||
if (f.getName().endsWith(IndexConstants.ADDRESS_INDEX_EXT)) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,9 +127,7 @@ public class MainMenuActivity extends Activity {
|
||||||
searchButton.setOnClickListener(new OnClickListener() {
|
searchButton.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
final Intent search = new Intent(MainMenuActivity.this,
|
final Intent search = new Intent(MainMenuActivity.this, SearchActivity.class);
|
||||||
SearchActivity.class);
|
|
||||||
// search.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
|
|
||||||
startActivity(search);
|
startActivity(search);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -20,19 +20,6 @@ public class SearchActivity extends TabActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(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();
|
TabHost host = getTabHost();
|
||||||
host.addTab(host.newTabSpec("Search_POI").setIndicator("Search POI").setContent(new Intent(this, SearchPOIListActivity.class)));
|
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)));
|
host.addTab(host.newTabSpec("Search_Adress").setIndicator("Search Address").setContent(new Intent(this, SearchAddressActivity.class)));
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.osmand.activities.search;
|
||||||
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
|
@ -34,12 +35,40 @@ public class SearchAddressActivity extends Activity {
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
setContentView(R.layout.search_address);
|
setContentView(R.layout.search_address);
|
||||||
|
|
||||||
showOnMap = (Button) findViewById(R.id.ShowOnMap);
|
showOnMap = (Button) findViewById(R.id.ShowOnMap);
|
||||||
streetButton = (Button) findViewById(R.id.StreetButton);
|
streetButton = (Button) findViewById(R.id.StreetButton);
|
||||||
cityButton = (Button) findViewById(R.id.CityButton);
|
cityButton = (Button) findViewById(R.id.CityButton);
|
||||||
countryButton = (Button) findViewById(R.id.CountryButton);
|
countryButton = (Button) findViewById(R.id.CountryButton);
|
||||||
buildingButton = (Button) findViewById(R.id.BuildingButton);
|
buildingButton = (Button) findViewById(R.id.BuildingButton);
|
||||||
findViewById(R.id.ResetBuilding).setOnClickListener(new View.OnClickListener(){
|
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
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
building = null;
|
building = null;
|
||||||
|
@ -73,6 +102,7 @@ public class SearchAddressActivity extends Activity {
|
||||||
updateUI();
|
updateUI();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateUI(){
|
protected void updateUI(){
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,16 +1,42 @@
|
||||||
package com.osmand.activities.search;
|
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.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
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
region = ResourceManager.getResourceManager().getRegionRepository(OsmandSettings.getLastSearchedRegion(this));
|
||||||
super.onCreate(savedInstanceState);
|
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();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,57 +1,30 @@
|
||||||
package com.osmand.activities.search;
|
package com.osmand.activities.search;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.widget.TextView;
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.Window;
|
|
||||||
|
|
||||||
import com.osmand.R;
|
import com.osmand.OsmandSettings;
|
||||||
import com.osmand.RegionAddressRepository;
|
import com.osmand.RegionAddressRepository;
|
||||||
import com.osmand.ResourceManager;
|
import com.osmand.ResourceManager;
|
||||||
|
|
||||||
public class SearchRegionByNameActivity extends Activity {
|
public class SearchRegionByNameActivity extends SearchByNameAbstractActivity<RegionAddressRepository> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
public List<RegionAddressRepository> getObjects() {
|
||||||
super.onCreate(savedInstanceState);
|
return new ArrayList<RegionAddressRepository>(ResourceManager.getResourceManager().getAddressRepositories());
|
||||||
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> {
|
@Override
|
||||||
NamesAdapter(Object list) {
|
public void updateTextView(RegionAddressRepository obj, TextView txt) {
|
||||||
super(SearchActivity.this, R.layout.searchlist, (List<?>) list);
|
txt.setText(obj.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public void itemSelected(RegionAddressRepository obj) {
|
||||||
int c = super.getCount();
|
OsmandSettings.setLastSearchedRegion(this, obj.getName());
|
||||||
return c > 20 ? 20 : c;
|
finish();
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (row);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue