diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index 8a9793b224..e5fff66046 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -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 diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index 4a5e267f2b..5772dab983 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -10,15 +10,18 @@ - - - - - - - - + + + + + + + + + + + + diff --git a/OsmAnd/res/layout/search_address.xml b/OsmAnd/res/layout/search_address.xml index 075b15d863..7143dc160a 100644 --- a/OsmAnd/res/layout/search_address.xml +++ b/OsmAnd/res/layout/search_address.xml @@ -3,24 +3,27 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> + + + - + - + - + @@ -28,7 +31,7 @@ - + @@ -36,14 +39,15 @@ - + - + + \ No newline at end of file diff --git a/OsmAnd/res/layout/search_by_name.xml b/OsmAnd/res/layout/search_by_name.xml index ebea9b3654..802c8fa56e 100644 --- a/OsmAnd/res/layout/search_by_name.xml +++ b/OsmAnd/res/layout/search_by_name.xml @@ -10,6 +10,6 @@ - diff --git a/OsmAnd/res/layout/searchbyname_list.xml b/OsmAnd/res/layout/searchbyname_list.xml index 2e53e2a7ab..d48d874080 100644 --- a/OsmAnd/res/layout/searchbyname_list.xml +++ b/OsmAnd/res/layout/searchbyname_list.xml @@ -3,5 +3,5 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> + android:layout_height="fill_parent" android:textSize="18dp"/> diff --git a/OsmAnd/src/com/osmand/RegionAddressRepository.java b/OsmAnd/src/com/osmand/RegionAddressRepository.java index ec5627f79d..04bd834c63 100644 --- a/OsmAnd/src/com/osmand/RegionAddressRepository.java +++ b/OsmAnd/src/com/osmand/RegionAddressRepository.java @@ -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 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 citiesToFill, List 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(); } } diff --git a/OsmAnd/src/com/osmand/ResourceManager.java b/OsmAnd/src/com/osmand/ResourceManager.java index 40c7db2d34..bb9b30ec17 100644 --- a/OsmAnd/src/com/osmand/ResourceManager.java +++ b/OsmAnd/src/com/osmand/ResourceManager.java @@ -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); } } } diff --git a/OsmAnd/src/com/osmand/activities/MainMenuActivity.java b/OsmAnd/src/com/osmand/activities/MainMenuActivity.java index 68467f93c4..8fe50658a6 100644 --- a/OsmAnd/src/com/osmand/activities/MainMenuActivity.java +++ b/OsmAnd/src/com/osmand/activities/MainMenuActivity.java @@ -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); } }); diff --git a/OsmAnd/src/com/osmand/activities/search/SearchActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchActivity.java index 1d886716e9..153723dbf5 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchActivity.java @@ -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))); diff --git a/OsmAnd/src/com/osmand/activities/search/SearchAddressActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchAddressActivity.java index e50ebcbb78..fed275e201 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchAddressActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchAddressActivity.java @@ -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; @@ -34,12 +35,40 @@ public class SearchAddressActivity extends Activity { requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.search_address); - showOnMap = (Button) findViewById(R.id.ShowOnMap); - streetButton = (Button) findViewById(R.id.StreetButton); - cityButton = (Button) findViewById(R.id.CityButton); - countryButton = (Button) findViewById(R.id.CountryButton); - buildingButton = (Button) findViewById(R.id.BuildingButton); - findViewById(R.id.ResetBuilding).setOnClickListener(new View.OnClickListener(){ + showOnMap = (Button) findViewById(R.id.ShowOnMap); + streetButton = (Button) findViewById(R.id.StreetButton); + 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) { building = null; @@ -73,8 +102,9 @@ public class SearchAddressActivity extends Activity { updateUI(); } }); + } - + protected void updateUI(){ findViewById(R.id.ResetCountry).setEnabled(region != null); if(region == null){ diff --git a/OsmAnd/src/com/osmand/activities/search/SearchBuildingByNameActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchBuildingByNameActivity.java new file mode 100644 index 0000000000..88b985fe9d --- /dev/null +++ b/OsmAnd/src/com/osmand/activities/search/SearchBuildingByNameActivity.java @@ -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 { + 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 getObjects() { + List l = new ArrayList(); + 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(); + + } +} diff --git a/OsmAnd/src/com/osmand/activities/search/SearchByNameAbstractActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchByNameAbstractActivity.java new file mode 100644 index 0000000000..ffb3931afb --- /dev/null +++ b/OsmAnd/src/com/osmand/activities/search/SearchByNameAbstractActivity.java @@ -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 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 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 { + NamesAdapter(List 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; + } + } +} diff --git a/OsmAnd/src/com/osmand/activities/search/SearchCityByNameActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchCityByNameActivity.java index f3c9a217c8..62414a7614 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchCityByNameActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchCityByNameActivity.java @@ -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 { + 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 getObjects() { + List l = new ArrayList(); + 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(); + } } diff --git a/OsmAnd/src/com/osmand/activities/search/SearchRegionByNameActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchRegionByNameActivity.java index 0e65f83bbc..8672bfbf14 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchRegionByNameActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchRegionByNameActivity.java @@ -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 { @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - requestWindowFeature(Window.FEATURE_NO_TITLE); - setContentView(R.layout.search_by_name); - Collection repos = ResourceManager.getResourceManager().getAddressRepositories(); -// setListAdapter(new ArrayAdapter); + public List getObjects() { + return new ArrayList(ResourceManager.getResourceManager().getAddressRepositories()); } - /*class NamesAdapter extends ArrayAdapter { - NamesAdapter(Object list) { - super(SearchActivity.this, R.layout.searchlist, (List) list); - } - - @Override - public int getCount() { - int c = super.getCount(); - return c > 20 ? 20 : c; - } + @Override + 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); - } - } - return (row); - }*/ + @Override + public void itemSelected(RegionAddressRepository obj) { + OsmandSettings.setLastSearchedRegion(this, obj.getName()); + finish(); + + } } diff --git a/OsmAnd/src/com/osmand/activities/search/SearchStreetByNameActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchStreetByNameActivity.java new file mode 100644 index 0000000000..ae56a99a30 --- /dev/null +++ b/OsmAnd/src/com/osmand/activities/search/SearchStreetByNameActivity.java @@ -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 { + 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 getObjects() { + List l = new ArrayList(); + 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(); + + } +}