first cut for search address functionality
git-svn-id: https://osmand.googlecode.com/svn/trunk@104 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
6867c31a2d
commit
ec0f5747bb
22 changed files with 534 additions and 48 deletions
|
@ -34,6 +34,10 @@ public class ToDoConstants {
|
||||||
// 8. Introduce activity search by location (unify with existing dialog)
|
// 8. Introduce activity search by location (unify with existing dialog)
|
||||||
// 9. When all features will be ready we can remove show location from context menu
|
// 9. When all features will be ready we can remove show location from context menu
|
||||||
|
|
||||||
|
// Performance improvements Android :
|
||||||
|
// 1. Introducing one place where refreshMap will be called using postMessage mechanism (delay more than > 50 ? ms)
|
||||||
|
// 2. Introducing cache of file names that are on disk (creating new File() consumes a lot of memory)
|
||||||
|
|
||||||
// TODO SWING:
|
// TODO SWING:
|
||||||
// 2. Configure file log & see log from file (add uncaught exception handling)
|
// 2. Configure file log & see log from file (add uncaught exception handling)
|
||||||
// 5. Implement suppress warning for duplicate id
|
// 5. Implement suppress warning for duplicate id
|
||||||
|
|
|
@ -55,6 +55,9 @@ public class City extends MapObject {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isEmptyWithStreets(){
|
||||||
|
return streets.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
public Street registerStreet(String street){
|
public Street registerStreet(String street){
|
||||||
if(!streets.containsKey(street.toLowerCase())){
|
if(!streets.containsKey(street.toLowerCase())){
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
<activity android:name=".activities.search.SearchPOIActivity" android:label="@string/searchpoi_activity"></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.SearchPOIListActivity"></activity>
|
||||||
<activity android:name=".activities.search.SearchAddress"></activity>
|
<activity android:name=".activities.search.SearchAddressActivity"></activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
|
||||||
|
|
49
OsmAnd/res/layout/search_address.xml
Normal file
49
OsmAnd/res/layout/search_address.xml
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
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>
|
||||||
|
<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>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp">
|
||||||
|
<TextView android:text="City" android:id="@+id/TextView">
|
||||||
|
</TextView>
|
||||||
|
<Button android:id="@+id/CityButton" android:text="@string/choose_city">
|
||||||
|
</Button>
|
||||||
|
<ImageButton android:id="@+id/ResetCity" android:background="@drawable/icon">
|
||||||
|
</ImageButton>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp">
|
||||||
|
<TextView android:text="Street" android:id="@+id/TextView">
|
||||||
|
</TextView>
|
||||||
|
<Button android:id="@+id/StreetButton" android:text="@string/choose_street">
|
||||||
|
</Button>
|
||||||
|
<ImageButton android:id="@+id/ResetStreet" android:background="@drawable/icon">
|
||||||
|
</ImageButton>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow android:id="@+id/TableRow" android:layout_marginLeft = "5dp">
|
||||||
|
<TextView android:text="Bulding" android:id="@+id/TextView">
|
||||||
|
</TextView>
|
||||||
|
<Button android:id="@+id/BuildingButton" android:text="@string/choose_building">
|
||||||
|
</Button>
|
||||||
|
<ImageButton android:id="@+id/ResetBuilding" android:background="@drawable/icon">
|
||||||
|
</ImageButton>
|
||||||
|
</TableRow>
|
||||||
|
</TableLayout>
|
||||||
|
|
||||||
|
<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>
|
15
OsmAnd/res/layout/search_by_name.xml
Normal file
15
OsmAnd/res/layout/search_by_name.xml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
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="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="3dp" android:layout_marginRight="3dp">
|
||||||
|
<EditText android:text="" android:id="@+id/SearchText" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
|
||||||
|
<Button android:text="Reset" android:id="@+id/ResetButton" android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="0"></Button>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ListView android:id="@+id/ListView" android:layout_width="fill_parent" android:layout_height="fill_parent"
|
||||||
|
android:layout_marginLeft="3dp" android:layout_marginTop="3dp" android:layout_marginRight="3dp"></ListView>
|
||||||
|
</LinearLayout>
|
|
@ -1,6 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
</LinearLayout>
|
|
7
OsmAnd/res/layout/searchbyname_list.xml
Normal file
7
OsmAnd/res/layout/searchbyname_list.xml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
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"/>
|
||||||
|
</LinearLayout>
|
|
@ -2,10 +2,10 @@
|
||||||
<!-- This file is at /res/layout/list.xml -->
|
<!-- This file is at /res/layout/list.xml -->
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:orientation="vertical" android:layout_width="fill_parent"
|
android:orientation="vertical" android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="fill_parent">
|
||||||
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:text="@string/search_POI_level_btn" android:id="@+id/SearchPOILevelButton"></Button><ListView android:id="@android:id/list" android:layout_width="fill_parent"
|
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:text="@string/search_POI_level_btn" android:id="@+id/SearchPOILevelButton"></Button>
|
||||||
android:layout_height="0dip" android:layout_weight="1"
|
<ListView android:id="@android:id/list" android:layout_width="fill_parent"
|
||||||
android:stackFromBottom="true" android:transcriptMode="normal" ></ListView>
|
android:layout_height="fill_parent"></ListView>
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
|
@ -2,10 +2,9 @@
|
||||||
<!-- This file is at /res/layout/list.xml -->
|
<!-- This file is at /res/layout/list.xml -->
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:orientation="vertical" android:layout_width="fill_parent"
|
android:orientation="vertical" android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="fill_parent">
|
||||||
<ListView android:id="@android:id/list" android:layout_width="fill_parent"
|
<ListView android:id="@android:id/list" android:layout_width="fill_parent"
|
||||||
android:layout_height="0dip" android:layout_weight="1"
|
android:layout_height="fill_parent" ></ListView>
|
||||||
android:stackFromBottom="true" android:transcriptMode="normal" ></ListView>
|
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
|
@ -1,5 +1,10 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
<string name="search_address">Search address</string>
|
||||||
|
<string name="choose_building">Choose building</string>
|
||||||
|
<string name="choose_street">Choose street</string>
|
||||||
|
<string name="choose_city">Choose city</string>
|
||||||
|
<string name="ChooseCountry">Choose country</string>
|
||||||
<string name="position_on_map_descr">Choose postion on the map</string>
|
<string name="position_on_map_descr">Choose postion on the map</string>
|
||||||
<string name="position_on_map">Position on the map</string>
|
<string name="position_on_map">Position on the map</string>
|
||||||
<string name="map_specify_point">Specify point</string>
|
<string name="map_specify_point">Specify point</string>
|
||||||
|
|
|
@ -133,15 +133,19 @@ public class AmenityIndexRepository {
|
||||||
dataBottomLatitude = query.getDouble(2);
|
dataBottomLatitude = query.getDouble(2);
|
||||||
dataLeftLongitude = query.getDouble(3);
|
dataLeftLongitude = query.getDouble(3);
|
||||||
}
|
}
|
||||||
|
query.close();
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Initializing db " + file.getAbsolutePath() + " " + (System.currentTimeMillis() - start) + "ms");
|
log.debug("Initializing db " + file.getAbsolutePath() + " " + (System.currentTimeMillis() - start) + "ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close(){
|
public synchronized void close(){
|
||||||
if(db != null){
|
if(db != null){
|
||||||
db.close();
|
db.close();
|
||||||
|
dataRightLongitude = dataLeftLongitude = dataBottomLatitude= dataTopLatitude = 0;
|
||||||
|
cachedAmenities.clear();
|
||||||
|
cTopLatitude = cBottomLatitude = cLeftLongitude = cRightLongitude = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,4 +118,39 @@ public class OsmandSettings {
|
||||||
edit.commit();
|
edit.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final String LAST_SEARCHED_REGION = "last_searched_region";
|
||||||
|
public static final String LAST_SEARCHED_CITY = "last_searched_city";
|
||||||
|
public static final String LAST_SEARCHED_STREET = "last_searched_street";
|
||||||
|
|
||||||
|
public static String getLastSearchedRegion(Context ctx){
|
||||||
|
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
|
||||||
|
return prefs.getString(LAST_SEARCHED_REGION, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean setLastSearchedRegion(Context ctx, String region){
|
||||||
|
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
|
||||||
|
return prefs.edit().putString(LAST_SEARCHED_REGION, region).commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Long getLastSearchedCity(Context ctx){
|
||||||
|
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
|
||||||
|
return prefs.getLong(LAST_SEARCHED_CITY, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean setLastSearchedCity(Context ctx, Long cityId){
|
||||||
|
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
|
||||||
|
return prefs.edit().putLong(LAST_SEARCHED_CITY, cityId).commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getLastSearchedStreet(Context ctx){
|
||||||
|
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
|
||||||
|
return prefs.getString(LAST_SEARCHED_STREET, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean setLastSearchedStreet(Context ctx, String street){
|
||||||
|
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
|
||||||
|
return prefs.edit().putString(LAST_SEARCHED_STREET, street).commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
166
OsmAnd/src/com/osmand/RegionAddressRepository.java
Normal file
166
OsmAnd/src/com/osmand/RegionAddressRepository.java
Normal file
|
@ -0,0 +1,166 @@
|
||||||
|
package com.osmand;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
|
||||||
|
import com.osmand.data.Building;
|
||||||
|
import com.osmand.data.City;
|
||||||
|
import com.osmand.data.Street;
|
||||||
|
import com.osmand.data.City.CityType;
|
||||||
|
import com.osmand.data.index.IndexConstants;
|
||||||
|
import com.osmand.data.index.IndexConstants.IndexCityTable;
|
||||||
|
import com.osmand.data.index.IndexConstants.IndexStreetTable;
|
||||||
|
|
||||||
|
|
||||||
|
public class RegionAddressRepository {
|
||||||
|
private static final Log log = LogUtil.getLog(RegionAddressRepository.class);
|
||||||
|
private SQLiteDatabase db;
|
||||||
|
private String name;
|
||||||
|
private LinkedHashMap<Long, City> cities = new LinkedHashMap<Long, City>();
|
||||||
|
private TreeMap<CityType, List<City>> cityTypes = new TreeMap<CityType, List<City>>();
|
||||||
|
|
||||||
|
public void initialize(final IProgress progress, File file) {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
if(db != null){
|
||||||
|
// close previous db
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
db = SQLiteDatabase.openOrCreateDatabase(file, null);
|
||||||
|
name = file.getName().substring(0, file.getName().indexOf('.'));
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Initializing address db " + file.getAbsolutePath() + " " + (System.currentTimeMillis() - start) + "ms");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close(){
|
||||||
|
if(db != null){
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearCities(){
|
||||||
|
cities.clear();
|
||||||
|
cityTypes.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public City getCityById(Long id){
|
||||||
|
preloadCities();
|
||||||
|
return cities.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Street getStreetByName(City city, String name){
|
||||||
|
if(city.isEmptyWithStreets()){
|
||||||
|
preloadStreets(city);
|
||||||
|
}
|
||||||
|
return city.getStreet(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Building getBuildingByName(Street street, String name){
|
||||||
|
if(street.getBuildings().isEmpty()){
|
||||||
|
preloadBuildings(street);
|
||||||
|
}
|
||||||
|
for(Building b : street.getBuildings()){
|
||||||
|
if(b.getName().equals(name)){
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillWithSuggestedCities(String name, List<City> citiesToFill, List<City> source){
|
||||||
|
preloadCities();
|
||||||
|
if(name.length() < 3){
|
||||||
|
EnumSet<CityType> set = EnumSet.of(CityType.CITY, CityType.TOWN);
|
||||||
|
for(CityType t : set){
|
||||||
|
if(name.length() == 0){
|
||||||
|
citiesToFill.addAll(cityTypes.get(t));
|
||||||
|
} else {
|
||||||
|
name = name.toLowerCase();
|
||||||
|
for (City c : cityTypes.get(t)) {
|
||||||
|
String lowerCase = c.getName().toLowerCase();
|
||||||
|
if(lowerCase.startsWith(name)){
|
||||||
|
citiesToFill.add(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// essentially index is created that cities towns are first in cities map
|
||||||
|
name = name.toLowerCase();
|
||||||
|
int ind = 0;
|
||||||
|
Collection<City> src = source == null ? cities.values() : source;
|
||||||
|
for (City c : src) {
|
||||||
|
String lowerCase = c.getName().toLowerCase();
|
||||||
|
if (lowerCase.startsWith(name)) {
|
||||||
|
citiesToFill.add(ind, c);
|
||||||
|
ind++;
|
||||||
|
} else if (lowerCase.contains(name)) {
|
||||||
|
citiesToFill.add(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void preloadBuildings(Street str){
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
public void preloadStreets(City city){
|
||||||
|
if (city.isEmptyWithStreets()) {
|
||||||
|
Cursor query = db.query(IndexStreetTable.getTable(), IndexConstants.generateColumnNames(IndexStreetTable.values()), "? = city",
|
||||||
|
new String[] { city.getId() + "" }, null, null, null);
|
||||||
|
if (query.moveToFirst()) {
|
||||||
|
do {
|
||||||
|
Street street = new Street(city);
|
||||||
|
street.setId(query.getLong(IndexStreetTable.ID.ordinal()));
|
||||||
|
street.setLocation(query.getDouble(IndexStreetTable.LATITUDE.ordinal()), query.getDouble(IndexStreetTable.LONGITUDE
|
||||||
|
.ordinal()));
|
||||||
|
street.setName(query.getString(IndexStreetTable.NAME.ordinal()));
|
||||||
|
city.registerStreet(street);
|
||||||
|
} while (query.moveToNext());
|
||||||
|
}
|
||||||
|
query.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void preloadCities(){
|
||||||
|
if (cities.isEmpty()) {
|
||||||
|
Cursor query = db.query(IndexCityTable.getTable(), IndexConstants.generateColumnNames(IndexCityTable.values()), null, null,
|
||||||
|
null, null, null);
|
||||||
|
if(query.moveToFirst()){
|
||||||
|
do {
|
||||||
|
CityType type = CityType.valueFromString(query.getString(IndexCityTable.CITY_TYPE.ordinal()));
|
||||||
|
if (type != null) {
|
||||||
|
City city = new City(type);
|
||||||
|
city.setId(query.getLong(IndexCityTable.ID.ordinal()));
|
||||||
|
city.setLocation(query.getDouble(IndexCityTable.LATITUDE.ordinal()), query.getDouble(IndexCityTable.LONGITUDE
|
||||||
|
.ordinal()));
|
||||||
|
city.setName(query.getString(IndexCityTable.NAME.ordinal()));
|
||||||
|
cities.put(city.getId(), city);
|
||||||
|
|
||||||
|
if(!cityTypes.containsKey(type)){
|
||||||
|
cityTypes.put(type, new ArrayList<City>());
|
||||||
|
}
|
||||||
|
cityTypes.get(type).add(city);
|
||||||
|
}
|
||||||
|
|
||||||
|
} while(query.moveToNext());
|
||||||
|
}
|
||||||
|
query.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package com.osmand;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -15,7 +16,6 @@ import android.graphics.BitmapFactory;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
|
||||||
import com.osmand.data.Amenity;
|
import com.osmand.data.Amenity;
|
||||||
import com.osmand.data.Region;
|
|
||||||
import com.osmand.data.index.IndexConstants;
|
import com.osmand.data.index.IndexConstants;
|
||||||
import com.osmand.data.preparation.MapTileDownloader;
|
import com.osmand.data.preparation.MapTileDownloader;
|
||||||
import com.osmand.data.preparation.MapTileDownloader.DownloadRequest;
|
import com.osmand.data.preparation.MapTileDownloader.DownloadRequest;
|
||||||
|
@ -58,11 +58,10 @@ public class ResourceManager {
|
||||||
private MapTileDownloader downloader = MapTileDownloader.getInstance();
|
private MapTileDownloader downloader = MapTileDownloader.getInstance();
|
||||||
|
|
||||||
// Indexes
|
// Indexes
|
||||||
private Map<String, Region> addressMap = new TreeMap<String, Region>();
|
private Map<String, RegionAddressRepository> addressMap = new TreeMap<String, RegionAddressRepository>();
|
||||||
|
|
||||||
protected List<AmenityIndexRepository> amenityRepositories = new ArrayList<AmenityIndexRepository>();
|
protected List<AmenityIndexRepository> amenityRepositories = new ArrayList<AmenityIndexRepository>();
|
||||||
|
|
||||||
|
|
||||||
public AsyncLoadingThread asyncLoadingTiles = new AsyncLoadingThread();
|
public AsyncLoadingThread asyncLoadingTiles = new AsyncLoadingThread();
|
||||||
|
|
||||||
|
|
||||||
|
@ -154,7 +153,7 @@ public class ResourceManager {
|
||||||
// POI INDEX //
|
// POI INDEX //
|
||||||
public void indexingPoi(final IProgress progress) {
|
public void indexingPoi(final IProgress progress) {
|
||||||
File file = new File(Environment.getExternalStorageDirectory(), POI_PATH);
|
File file = new File(Environment.getExternalStorageDirectory(), POI_PATH);
|
||||||
clearAmenities();
|
closeAmenities();
|
||||||
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.POI_INDEX_EXT)) {
|
if (f.getName().endsWith(IndexConstants.POI_INDEX_EXT)) {
|
||||||
|
@ -170,7 +169,7 @@ public class ResourceManager {
|
||||||
|
|
||||||
public void indexingAddresses(final IProgress progress){
|
public void indexingAddresses(final IProgress progress){
|
||||||
File file = new File(Environment.getExternalStorageDirectory(), ADDRESS_PATH);
|
File file = new File(Environment.getExternalStorageDirectory(), ADDRESS_PATH);
|
||||||
clearAddresses();
|
closeAddresses();
|
||||||
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)) {
|
||||||
|
@ -212,23 +211,35 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////// Working with amenities ////////////////////////////////////////////////
|
////////////////////////////////////////////// Working with address ///////////////////////////////////////////
|
||||||
|
|
||||||
public void clearAmenities(){
|
public RegionAddressRepository getRegionRepository(String name){
|
||||||
|
return addressMap.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<RegionAddressRepository> getAddressRepositories(){
|
||||||
|
return addressMap.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////// Closing methods ////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public void closeAmenities(){
|
||||||
for(AmenityIndexRepository r : amenityRepositories){
|
for(AmenityIndexRepository r : amenityRepositories){
|
||||||
r.close();
|
r.close();
|
||||||
}
|
}
|
||||||
amenityRepositories.clear();
|
amenityRepositories.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearAddresses(){
|
public void closeAddresses(){
|
||||||
// TODO close db connections
|
for(RegionAddressRepository r : addressMap.values()){
|
||||||
|
r.close();
|
||||||
|
}
|
||||||
addressMap.clear();
|
addressMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void close(){
|
public synchronized void close(){
|
||||||
clearAmenities();
|
closeAmenities();
|
||||||
clearAddresses();
|
closeAddresses();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// On low memory method ///
|
/// On low memory method ///
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class SearchActivity extends TabActivity {
|
||||||
// });
|
// });
|
||||||
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, SearchAddress.class)));
|
host.addTab(host.newTabSpec("Search_Adress").setIndicator("Search Address").setContent(new Intent(this, SearchAddressActivity.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
package com.osmand.activities.search;
|
|
||||||
|
|
||||||
|
|
||||||
import com.osmand.R;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
public class SearchAddress extends Activity {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.searchaddress);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,131 @@
|
||||||
|
package com.osmand.activities.search;
|
||||||
|
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.Window;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
import com.osmand.OsmandSettings;
|
||||||
|
import com.osmand.R;
|
||||||
|
import com.osmand.RegionAddressRepository;
|
||||||
|
import com.osmand.ResourceManager;
|
||||||
|
import com.osmand.data.Building;
|
||||||
|
import com.osmand.data.City;
|
||||||
|
import com.osmand.data.Street;
|
||||||
|
|
||||||
|
public class SearchAddressActivity extends Activity {
|
||||||
|
|
||||||
|
private Button showOnMap;
|
||||||
|
private Button streetButton;
|
||||||
|
private Button cityButton;
|
||||||
|
private Button countryButton;
|
||||||
|
private Button buildingButton;
|
||||||
|
|
||||||
|
private RegionAddressRepository region = null;
|
||||||
|
private City city = null;
|
||||||
|
private Street street = null;
|
||||||
|
private Building building = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
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(){
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
building = null;
|
||||||
|
updateUI();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
findViewById(R.id.ResetStreet).setOnClickListener(new View.OnClickListener(){
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
street = null;
|
||||||
|
building = null;
|
||||||
|
updateUI();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
findViewById(R.id.ResetCity).setOnClickListener(new View.OnClickListener(){
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
city = null;
|
||||||
|
street = null;
|
||||||
|
building = null;
|
||||||
|
updateUI();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
findViewById(R.id.ResetCountry).setOnClickListener(new View.OnClickListener(){
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
region = null;
|
||||||
|
city = null;
|
||||||
|
street = null;
|
||||||
|
building = null;
|
||||||
|
updateUI();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateUI(){
|
||||||
|
findViewById(R.id.ResetCountry).setEnabled(region != null);
|
||||||
|
if(region == null){
|
||||||
|
countryButton.setText(R.string.ChooseCountry);
|
||||||
|
} else {
|
||||||
|
countryButton.setText(region.getName());
|
||||||
|
}
|
||||||
|
findViewById(R.id.ResetCity).setEnabled(city != null);
|
||||||
|
if(city == null){
|
||||||
|
cityButton.setText(R.string.choose_city);
|
||||||
|
} else {
|
||||||
|
cityButton.setText(city.getName());
|
||||||
|
}
|
||||||
|
cityButton.setEnabled(region != null);
|
||||||
|
|
||||||
|
findViewById(R.id.ResetStreet).setEnabled(street != null);
|
||||||
|
if(street == null){
|
||||||
|
streetButton.setText(R.string.choose_street);
|
||||||
|
} else {
|
||||||
|
streetButton.setText(street.getName());
|
||||||
|
}
|
||||||
|
streetButton.setEnabled(city != null);
|
||||||
|
|
||||||
|
findViewById(R.id.ResetBuilding).setEnabled(building != null);
|
||||||
|
if(building == null){
|
||||||
|
buildingButton.setText(R.string.choose_building);
|
||||||
|
} else {
|
||||||
|
buildingButton.setText(building.getName());
|
||||||
|
}
|
||||||
|
buildingButton.setEnabled(street != null);
|
||||||
|
showOnMap.setEnabled(building != null || city != null || street != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
region = null;
|
||||||
|
city = null;
|
||||||
|
street = null;
|
||||||
|
building = null;
|
||||||
|
String lastSearchedRegion = OsmandSettings.getLastSearchedRegion(this);
|
||||||
|
region = ResourceManager.getResourceManager().getRegionRepository(lastSearchedRegion);
|
||||||
|
if(region != null){
|
||||||
|
city = region.getCityById(OsmandSettings.getLastSearchedCity(this));
|
||||||
|
if(city != null){
|
||||||
|
street = region.getStreetByName(city, OsmandSettings.getLastSearchedStreet(this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.osmand.activities.search;
|
||||||
|
|
||||||
|
import com.osmand.R;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.Window;
|
||||||
|
|
||||||
|
public class SearchCityByNameActivity extends Activity {
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
|
setContentView(R.layout.search_by_name);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.osmand.activities.search;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.Window;
|
||||||
|
|
||||||
|
import com.osmand.R;
|
||||||
|
import com.osmand.RegionAddressRepository;
|
||||||
|
import com.osmand.ResourceManager;
|
||||||
|
|
||||||
|
public class SearchRegionByNameActivity extends Activity {
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
int c = super.getCount();
|
||||||
|
return c > 20 ? 20 : c;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}*/
|
||||||
|
}
|
|
@ -113,7 +113,7 @@ public class MapInfoLayer implements OsmandMapLayer {
|
||||||
}
|
}
|
||||||
if(cachedSpeed > 0){
|
if(cachedSpeed > 0){
|
||||||
canvas.drawRoundRect(boundsForSpeed, 3, 3, paintAlphaGray);
|
canvas.drawRoundRect(boundsForSpeed, 3, 3, paintAlphaGray);
|
||||||
canvas.drawText(cachedSpeedString, boundsForSpeed.left + 5, boundsForSpeed.bottom - 9, paintBlack);
|
canvas.drawText(cachedSpeedString, boundsForSpeed.left + 15, boundsForSpeed.bottom - 9, paintBlack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(cachedDistString != null){
|
if(cachedDistString != null){
|
||||||
|
|
|
@ -530,7 +530,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDifferenceSmallToDrag(PointF point, MotionEvent event){
|
public boolean isDifferenceSmallToDrag(PointF point, MotionEvent event){
|
||||||
return Math.abs(point.x - event.getX()) + Math.abs(point.y - event.getY()) <= 10;
|
return Math.abs(point.x - event.getX()) <= 8 && Math.abs(point.y - event.getY()) <= 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -594,6 +594,9 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
||||||
PointF point = startDragging;
|
PointF point = startDragging;
|
||||||
if (point != null) {
|
if (point != null) {
|
||||||
startDragging = null;
|
startDragging = null;
|
||||||
|
if(log.isDebugEnabled()){
|
||||||
|
log.debug("On long click event "+ point.x + " " + point.y);
|
||||||
|
}
|
||||||
for (int i = layers.size() - 1; i >= 0; i--) {
|
for (int i = layers.size() - 1; i >= 0; i--) {
|
||||||
if (layers.get(i).onLongPressEvent(point)) {
|
if (layers.get(i).onLongPressEvent(point)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -608,6 +611,9 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
||||||
PointF point = startDragging;
|
PointF point = startDragging;
|
||||||
if (point != null) {
|
if (point != null) {
|
||||||
startDragging = null;
|
startDragging = null;
|
||||||
|
if(log.isDebugEnabled()){
|
||||||
|
log.debug("On click event "+ point.x + " " + point.y);
|
||||||
|
}
|
||||||
for (int i = layers.size() - 1; i >= 0; i--) {
|
for (int i = layers.size() - 1; i >= 0; i--) {
|
||||||
if (layers.get(i).onTouchEvent(point)) {
|
if (layers.get(i).onTouchEvent(point)) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -75,11 +75,11 @@ public class POIMapLayer implements OsmandMapLayer {
|
||||||
if(zoom < startZoom){
|
if(zoom < startZoom){
|
||||||
return 0;
|
return 0;
|
||||||
} else if(zoom == 16){
|
} else if(zoom == 16){
|
||||||
return 6;
|
|
||||||
} else if(zoom == 17){
|
|
||||||
return 10;
|
return 10;
|
||||||
} else {
|
} else if(zoom == 17){
|
||||||
return 14;
|
return 14;
|
||||||
|
} else {
|
||||||
|
return 18;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue