diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index 5772dab983..6e2e4f8e83 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -15,6 +15,7 @@ + diff --git a/OsmAnd/res/menu/map_menu.xml b/OsmAnd/res/menu/map_menu.xml index f4ccf9ba99..d359e392a5 100644 --- a/OsmAnd/res/menu/map_menu.xml +++ b/OsmAnd/res/menu/map_menu.xml @@ -2,7 +2,7 @@ - + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 6bdb117716..ce51777e3b 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,5 +1,8 @@ + Select use native or english names + Use english names + Application settings Search address Choose building Choose street diff --git a/OsmAnd/res/xml/settings_pref.xml b/OsmAnd/res/xml/settings_pref.xml index 7b83190f72..66c5b4d141 100644 --- a/OsmAnd/res/xml/settings_pref.xml +++ b/OsmAnd/res/xml/settings_pref.xml @@ -12,4 +12,6 @@ + + diff --git a/OsmAnd/src/com/osmand/AmenityIndexRepository.java b/OsmAnd/src/com/osmand/AmenityIndexRepository.java index 9fc1c2a69a..34e630a295 100644 --- a/OsmAnd/src/com/osmand/AmenityIndexRepository.java +++ b/OsmAnd/src/com/osmand/AmenityIndexRepository.java @@ -54,8 +54,10 @@ public class AmenityIndexRepository { am.setLocation(query.getDouble(IndexPoiTable.LATITUDE.ordinal()), query.getDouble(IndexPoiTable.LONGITUDE.ordinal())); am.setName(query.getString(IndexPoiTable.NAME.ordinal() )); + am.setEnName(query.getString(IndexPoiTable.NAME_EN.ordinal())); am.setType(AmenityType.fromString(query.getString(IndexPoiTable.TYPE.ordinal()))); am.setSubType(query.getString(IndexPoiTable.SUBTYPE.ordinal())); + am.setOpeningHours(query.getString(IndexPoiTable.OPENING_HOURS.ordinal())); amenities.add(am); if(limit != -1 && amenities.size() >= limit){ break; diff --git a/OsmAnd/src/com/osmand/OsmandSettings.java b/OsmAnd/src/com/osmand/OsmandSettings.java index 2469f9ae69..6a7f3a9678 100644 --- a/OsmAnd/src/com/osmand/OsmandSettings.java +++ b/OsmAnd/src/com/osmand/OsmandSettings.java @@ -61,6 +61,18 @@ public class OsmandSettings { return prefs.getBoolean(MAP_VIEW_3D, false); } + // this value string is synchronized with settings_pref.xml preference name + public static final String USE_ENGLISH_NAMES = "use_english_names"; + public static boolean usingEnglishNames(Context ctx){ + SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + return prefs.getBoolean(USE_ENGLISH_NAMES, false); + } + + public static boolean setUseEnglishNames(Context ctx, boolean useEnglishNames){ + SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + return prefs.edit().putBoolean(USE_ENGLISH_NAMES, useEnglishNames).commit(); + } + // this value string is synchronized with settings_pref.xml preference name public static final String MAP_TILE_SOURCES = "map_tile_sources"; diff --git a/OsmAnd/src/com/osmand/RegionAddressRepository.java b/OsmAnd/src/com/osmand/RegionAddressRepository.java index bc5d5d6e93..b33b66c85f 100644 --- a/OsmAnd/src/com/osmand/RegionAddressRepository.java +++ b/OsmAnd/src/com/osmand/RegionAddressRepository.java @@ -3,10 +3,12 @@ package com.osmand; import java.io.File; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.EnumSet; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; -import java.util.TreeMap; +import java.util.Map; import org.apache.commons.logging.Log; @@ -15,6 +17,7 @@ import android.database.sqlite.SQLiteDatabase; import com.osmand.data.Building; import com.osmand.data.City; +import com.osmand.data.Region; import com.osmand.data.Street; import com.osmand.data.City.CityType; import com.osmand.data.index.IndexConstants; @@ -28,7 +31,9 @@ public class RegionAddressRepository { private SQLiteDatabase db; private String name; private LinkedHashMap cities = new LinkedHashMap(); - private TreeMap> cityTypes = new TreeMap>(); + private Map> cityTypes = new HashMap>(); + + private boolean useEnglishNames = false; public void initialize(final IProgress progress, File file) { long start = System.currentTimeMillis(); @@ -44,6 +49,7 @@ public class RegionAddressRepository { } public void close(){ + clearCities(); if(db != null){ db.close(); } @@ -83,13 +89,40 @@ public class RegionAddressRepository { preloadBuildings(street); } for(Building b : street.getBuildings()){ - if(b.getName().equals(name)){ + String bName = useEnglishNames ? b.getEnName() : b.getName(); + if(bName.equals(name)){ return b; } } return null; } + public boolean useEnglishNames(){ + return useEnglishNames; + } + + public void setUseEnglishNames(boolean useEnglishNames) { + this.useEnglishNames = useEnglishNames; + // sort streets + for (City c : cities.values()) { + if (!c.isEmptyWithStreets()) { + ArrayList list = new ArrayList(c.getStreets()); + c.removeAllStreets(); + for (Street s : list) { + c.registerStreet(s, useEnglishNames); + } + } + } + // sort cities + ArrayList list = new ArrayList(cities.values()); + Collections.sort(list, new Region.CityComparator(useEnglishNames)); + cities.clear(); + cityTypes.clear(); + for(City c : list){ + registerCity(c); + } + } + public void fillWithSuggestedBuildings(Street street, String name, List buildingsToFill){ preloadBuildings(street); name = name.toLowerCase(); @@ -99,7 +132,8 @@ public class RegionAddressRepository { return; } for (Building building : street.getBuildings()) { - String lowerCase = building.getName().toLowerCase(); + String bName = useEnglishNames ? building.getEnName() : building.getName(); + String lowerCase = bName.toLowerCase(); if (lowerCase.startsWith(name)) { buildingsToFill.add(ind, building); ind++; @@ -118,7 +152,8 @@ public class RegionAddressRepository { return; } for (Street s : c.getStreets()) { - String lowerCase = s.getName().toLowerCase(); + String sName = useEnglishNames ? s.getEnName() : s.getName(); + String lowerCase = sName.toLowerCase(); if (lowerCase.startsWith(name)) { streetsToFill.add(ind, s); ind++; @@ -138,7 +173,8 @@ public class RegionAddressRepository { } else { name = name.toLowerCase(); for (City c : cityTypes.get(t)) { - String lowerCase = c.getName().toLowerCase(); + String cName = useEnglishNames ? c.getEnName() : c.getName(); + String lowerCase = cName.toLowerCase(); if(lowerCase.startsWith(name)){ citiesToFill.add(c); } @@ -151,7 +187,8 @@ public class RegionAddressRepository { name = name.toLowerCase(); Collection src = cities.values(); for (City c : src) { - String lowerCase = c.getName().toLowerCase(); + String cName = useEnglishNames ? c.getEnName() : c.getName(); + String lowerCase = cName.toLowerCase(); if (lowerCase.startsWith(name)) { citiesToFill.add(ind, c); ind++; @@ -168,7 +205,7 @@ public class RegionAddressRepository { append(IndexCityTable.CITY_TYPE.toString()).append(" not in ("). append('\'').append(CityType.valueToString(CityType.CITY)).append('\'').append(", "). append('\'').append(CityType.valueToString(CityType.TOWN)).append('\'').append(") and "). - append(IndexCityTable.NAME.toString()).append(" LIKE '"+name+"%'"); + append(useEnglishNames ? IndexCityTable.NAME_EN.toString() : IndexCityTable.NAME.toString()).append(" LIKE '"+name+"%'"); Cursor query = db.query(IndexCityTable.getTable(), IndexConstants.generateColumnNames(IndexCityTable.values()), where.toString(), null, null, null, null); if (query.moveToFirst()) { @@ -195,6 +232,7 @@ public class RegionAddressRepository { building.setLocation(query.getDouble(IndexBuildingTable.LATITUDE.ordinal()), query.getDouble(IndexBuildingTable.LONGITUDE .ordinal())); building.setName(query.getString(IndexBuildingTable.NAME.ordinal())); + building.setEnName(query.getString(IndexBuildingTable.NAME_EN.ordinal())); street.registerBuilding(building); } while (query.moveToNext()); } @@ -215,7 +253,8 @@ public class RegionAddressRepository { street.setLocation(query.getDouble(IndexStreetTable.LATITUDE.ordinal()), query.getDouble(IndexStreetTable.LONGITUDE .ordinal())); street.setName(query.getString(IndexStreetTable.NAME.ordinal())); - city.registerStreet(street); + street.setEnName(query.getString(IndexStreetTable.NAME_EN.ordinal())); + city.registerStreet(street, useEnglishNames); } while (query.moveToNext()); } query.close(); @@ -240,6 +279,7 @@ public class RegionAddressRepository { city.setLocation(query.getDouble(IndexCityTable.LATITUDE.ordinal()), query.getDouble(IndexCityTable.LONGITUDE .ordinal())); city.setName(query.getString(IndexCityTable.NAME.ordinal())); + city.setEnName(query.getString(IndexCityTable.NAME_EN.ordinal())); return city; } return null; diff --git a/OsmAnd/src/com/osmand/ResourceManager.java b/OsmAnd/src/com/osmand/ResourceManager.java index e53c5ed15e..192ef96579 100644 --- a/OsmAnd/src/com/osmand/ResourceManager.java +++ b/OsmAnd/src/com/osmand/ResourceManager.java @@ -1,6 +1,7 @@ package com.osmand; import java.io.File; +import java.text.Collator; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashMap; @@ -59,7 +60,7 @@ public class ResourceManager { private MapTileDownloader downloader = MapTileDownloader.getInstance(); // Indexes - private Map addressMap = new TreeMap(); + private Map addressMap = new TreeMap(Collator.getInstance()); protected List amenityRepositories = new ArrayList(); @@ -253,8 +254,10 @@ public class ResourceManager { for(AmenityIndexRepository r : amenityRepositories){ r.clearCache(); } + for(RegionAddressRepository r : addressMap.values()){ + r.clearCities(); + } - // TODO clear addresses indexes System.gc(); } diff --git a/OsmAnd/src/com/osmand/activities/MapActivity.java b/OsmAnd/src/com/osmand/activities/MapActivity.java index 0d37e915d8..a0cf599231 100644 --- a/OsmAnd/src/com/osmand/activities/MapActivity.java +++ b/OsmAnd/src/com/osmand/activities/MapActivity.java @@ -1,7 +1,5 @@ package com.osmand.activities; -import java.text.MessageFormat; - import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; @@ -27,7 +25,6 @@ import android.view.View; import android.view.Window; import android.view.View.OnClickListener; import android.widget.ImageButton; -import android.widget.Toast; import android.widget.ZoomControls; import com.osmand.LogUtil; @@ -356,13 +353,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat @Override public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == R.id.map_show_location) { - float f = (Runtime.getRuntime().totalMemory()) / 1e6f; - String text = MessageFormat.format("Latitude : {0}, longitude : {1}, zoom : {2}, memory : {3}", mapView.getLatitude(), mapView - .getLongitude(), mapView.getZoom(), f); - Toast.makeText(this, text, Toast.LENGTH_SHORT).show(); - return true; - } else if (item.getItemId() == R.id.map_show_settings) { + if (item.getItemId() == R.id.map_show_settings) { final Intent settings = new Intent(MapActivity.this, SettingsActivity.class); startActivity(settings); return true; @@ -386,7 +377,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat } private void openChangeLocationDialog() { - NavigatePointDialog dlg = new NavigatePointDialog(this, mapView); + NavigatePointActivity dlg = new NavigatePointActivity(this, mapView); dlg.showDialog(); } diff --git a/OsmAnd/src/com/osmand/activities/NavigatePointDialog.java b/OsmAnd/src/com/osmand/activities/NavigatePointActivity.java similarity index 50% rename from OsmAnd/src/com/osmand/activities/NavigatePointDialog.java rename to OsmAnd/src/com/osmand/activities/NavigatePointActivity.java index 95dda2b814..ce3389e235 100644 --- a/OsmAnd/src/com/osmand/activities/NavigatePointDialog.java +++ b/OsmAnd/src/com/osmand/activities/NavigatePointActivity.java @@ -4,37 +4,78 @@ import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.Locale; +import android.app.Activity; import android.app.Dialog; import android.content.Context; +import android.content.Intent; import android.location.Location; +import android.os.Bundle; +import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.TextView; +import com.osmand.LogUtil; import com.osmand.OsmandSettings; import com.osmand.R; +import com.osmand.osm.LatLon; import com.osmand.views.OsmandMapTileView; -public class NavigatePointDialog { +public class NavigatePointActivity extends Activity { Dialog dlg; OsmandMapTileView view; int currentFormat = Location.FORMAT_DEGREES; - public NavigatePointDialog(Context ctx, OsmandMapTileView view){ + // dialog constructor + public NavigatePointActivity(Context ctx, OsmandMapTileView view){ this.view = view; dlg = new Dialog(ctx); + } + + public NavigatePointActivity() { + } + + public void showDialog(){ + dlg.setContentView(R.layout.navigate_point); + dlg.setTitle("Navigate to point"); initUI(view.getLatitude(), view.getLongitude()); + dlg.show(); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + LatLon loc = OsmandSettings.getLastKnownMapLocation(this); + setContentView(R.layout.navigate_point); + setTitle("Navigate to point"); + initUI(loc.getLatitude(), loc.getLongitude()); + ((Button) findViewById(R.id.Cancel)).setVisibility(View.INVISIBLE); + } + + @Override + public View findViewById(int id) { + if(dlg != null){ + return dlg.findViewById(id); + } + return super.findViewById(id); + } + + public void close(){ + if(dlg != null){ + dlg.dismiss(); + } else { + Intent newIntent = new Intent(this, MapActivity.class); + startActivity(newIntent); + } } public void initUI(double latitude, double longitude){ - dlg.setContentView(R.layout.navigate_point); - dlg.setTitle("Navigate to point"); - ((TextView)dlg.findViewById(R.id.LatitudeEdit)).setText(convert(latitude, Location.FORMAT_DEGREES)); - ((TextView)dlg.findViewById(R.id.LongitudeEdit)).setText(convert(longitude, Location.FORMAT_DEGREES)); - ((RadioButton)dlg.findViewById(R.id.Format1)).setChecked(true); - ((RadioGroup)dlg.findViewById(R.id.RadioGroup01)).setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){ + ((TextView)findViewById(R.id.LatitudeEdit)).setText(convert(latitude, Location.FORMAT_DEGREES)); + ((TextView)findViewById(R.id.LongitudeEdit)).setText(convert(longitude, Location.FORMAT_DEGREES)); + ((RadioButton)findViewById(R.id.Format1)).setChecked(true); + ((RadioGroup)findViewById(R.id.RadioGroup01)).setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){ @Override public void onCheckedChanged(RadioGroup group, int checkedId) { @@ -47,35 +88,39 @@ public class NavigatePointDialog { newFormat = Location.FORMAT_SECONDS; } try { - double lat = Location.convert(((TextView) dlg.findViewById(R.id.LatitudeEdit)).getText().toString()); - double lon = Location.convert(((TextView) dlg.findViewById(R.id.LongitudeEdit)).getText().toString()); - ((TextView)dlg.findViewById(R.id.LatitudeEdit)).setText(convert(lat, newFormat)); - ((TextView)dlg.findViewById(R.id.LongitudeEdit)).setText(convert(lon, newFormat)); + double lat = Location.convert(((TextView) findViewById(R.id.LatitudeEdit)).getText().toString()); + double lon = Location.convert(((TextView) findViewById(R.id.LongitudeEdit)).getText().toString()); + ((TextView)findViewById(R.id.LatitudeEdit)).setText(convert(lat, newFormat)); + ((TextView)findViewById(R.id.LongitudeEdit)).setText(convert(lon, newFormat)); } catch (RuntimeException e) { + ((TextView) findViewById(R.id.ValidateTextView)).setText("Locations are invalid"); + Log.w(LogUtil.TAG, "Convertion failed", e); } } }); - ((Button) dlg.findViewById(R.id.Cancel)).setOnClickListener(new View.OnClickListener() { + ((Button) findViewById(R.id.Cancel)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - dlg.dismiss(); + close(); } }); - ((Button) dlg.findViewById(R.id.ShowOnMap)).setOnClickListener(new View.OnClickListener() { + ((Button) findViewById(R.id.ShowOnMap)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { - double lat = Location.convert(((TextView) dlg.findViewById(R.id.LatitudeEdit)).getText().toString()); - double lon = Location.convert(((TextView) dlg.findViewById(R.id.LongitudeEdit)).getText().toString()); + // TODO there is a bug in that convert if min = 59.23 or sec = 59.32 or deg=179.3 + double lat = Location.convert(((TextView) findViewById(R.id.LatitudeEdit)).getText().toString()); + double lon = Location.convert(((TextView) findViewById(R.id.LongitudeEdit)).getText().toString()); if(view != null) { view.setLatLon(lat, lon); } else { - OsmandSettings.setLastKnownMapLocation(dlg.getContext(), lat, lon); + OsmandSettings.setLastKnownMapLocation(NavigatePointActivity.this, lat, lon); } - dlg.dismiss(); + close(); } catch (RuntimeException e) { - ((TextView) dlg.findViewById(R.id.ValidateTextView)).setText("Locations are invalid"); + ((TextView) findViewById(R.id.ValidateTextView)).setText("Locations are invalid"); + Log.w(LogUtil.TAG, "Convertion failed", e); } } }); @@ -122,8 +167,6 @@ public class NavigatePointDialog { return sb.toString(); } - public void showDialog(){ - dlg.show(); - } + } diff --git a/OsmAnd/src/com/osmand/activities/SettingsActivity.java b/OsmAnd/src/com/osmand/activities/SettingsActivity.java index 0e46cfdf77..adc6f156d3 100644 --- a/OsmAnd/src/com/osmand/activities/SettingsActivity.java +++ b/OsmAnd/src/com/osmand/activities/SettingsActivity.java @@ -26,6 +26,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference private CheckBoxPreference rotateMapToBearing; private CheckBoxPreference showViewAngle; private ListPreference positionOnMap; + private CheckBoxPreference useEnglishNames; @Override public void onCreate(Bundle savedInstanceState) { @@ -40,6 +41,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference rotateMapToBearing.setOnPreferenceChangeListener(this); showViewAngle =(CheckBoxPreference) screen.findPreference(OsmandSettings.SHOW_VIEW_ANGLE); showViewAngle.setOnPreferenceChangeListener(this); + useEnglishNames =(CheckBoxPreference) screen.findPreference(OsmandSettings.USE_ENGLISH_NAMES); + useEnglishNames.setOnPreferenceChangeListener(this); positionOnMap =(ListPreference) screen.findPreference(OsmandSettings.POSITION_ON_MAP); positionOnMap.setOnPreferenceChangeListener(this); @@ -56,6 +59,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference showPoiOnMap.setChecked(OsmandSettings.isShowingPoiOverMap(this)); rotateMapToBearing.setChecked(OsmandSettings.isRotateMapToBearing(this)); showViewAngle.setChecked(OsmandSettings.isShowingViewAngle(this)); + useEnglishNames.setChecked(OsmandSettings.usingEnglishNames(this)); String[] e = new String[] { "Center", "Bottom" }; positionOnMap.setEntryValues(e); positionOnMap.setEntries(e); @@ -89,6 +93,9 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference } else if(preference == rotateMapToBearing){ edit.putBoolean(OsmandSettings.ROTATE_MAP_TO_BEARING, (Boolean) newValue); edit.commit(); + } else if(preference == useEnglishNames){ + edit.putBoolean(OsmandSettings.USE_ENGLISH_NAMES, (Boolean) newValue); + edit.commit(); } else if(preference == showViewAngle){ edit.putBoolean(OsmandSettings.SHOW_VIEW_ANGLE, (Boolean) newValue); edit.commit(); diff --git a/OsmAnd/src/com/osmand/activities/search/SearchActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchActivity.java index 848a75bebf..4e94eaff0f 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchActivity.java @@ -3,6 +3,8 @@ */ package com.osmand.activities.search; +import com.osmand.activities.NavigatePointActivity; + import android.app.TabActivity; import android.content.Intent; import android.os.Bundle; @@ -23,6 +25,7 @@ public class SearchActivity extends TabActivity { TabHost host = getTabHost(); host.addTab(host.newTabSpec("Search_POI").setIndicator("Search POI").setContent(new Intent(this, SearchPOIListActivity.class))); host.addTab(host.newTabSpec("Search_Address").setIndicator("Search Address").setContent(new Intent(this, SearchAddressActivity.class))); + host.addTab(host.newTabSpec("Search_Location").setIndicator("Search Location").setContent(new Intent(this, NavigatePointActivity.class))); } } diff --git a/OsmAnd/src/com/osmand/activities/search/SearchAddressActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchAddressActivity.java index 8168d10ec9..c19bef5dc1 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchAddressActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchAddressActivity.java @@ -31,7 +31,6 @@ public class SearchAddressActivity extends Activity { private City city = null; private Street street = null; private Building building = null; - private ProgressDialog dlg; @Override protected void onCreate(Bundle savedInstanceState) { @@ -143,7 +142,7 @@ public class SearchAddressActivity extends Activity { if(city == null){ cityButton.setText(R.string.choose_city); } else { - cityButton.setText(city.getName()); + cityButton.setText(city.getName(region.useEnglishNames())); } cityButton.setEnabled(region != null); @@ -151,7 +150,7 @@ public class SearchAddressActivity extends Activity { if(street == null){ streetButton.setText(R.string.choose_street); } else { - streetButton.setText(street.getName()); + streetButton.setText(street.getName(region.useEnglishNames())); } streetButton.setEnabled(city != null); @@ -159,7 +158,7 @@ public class SearchAddressActivity extends Activity { if(building == null){ buildingButton.setText(R.string.choose_building); } else { - buildingButton.setText(building.getName()); + buildingButton.setText(building.getName(region.useEnglishNames())); } buildingButton.setEnabled(street != null); showOnMap.setEnabled(building != null || city != null || street != null); @@ -167,6 +166,9 @@ public class SearchAddressActivity extends Activity { public void loadData(){ if (region != null) { + if(region.useEnglishNames() != OsmandSettings.usingEnglishNames(this)){ + region.setUseEnglishNames(OsmandSettings.usingEnglishNames(this)); + } city = region.getCityById(OsmandSettings.getLastSearchedCity(SearchAddressActivity.this)); if (city != null) { street = region.getStreetByName(city, OsmandSettings.getLastSearchedStreet(SearchAddressActivity.this)); @@ -178,43 +180,51 @@ public class SearchAddressActivity extends Activity { } } + protected void startLoadDataInThread(String progressMsg){ + final ProgressDialog dlg = ProgressDialog.show(this, "Loading", progressMsg, true); + new Thread("Loader search data") { + @Override + public void run() { + try { + loadData(); + } finally { + dlg.dismiss(); + runOnUiThread(new Runnable() { + @Override + public void run() { + updateUI(); + } + }); + } + } + }.start(); + } + @Override protected void onResume() { super.onResume(); region = null; - String lastSearchedRegion = OsmandSettings.getLastSearchedRegion(SearchAddressActivity.this); region = ResourceManager.getResourceManager().getRegionRepository(lastSearchedRegion); String progressMsg = null; - // try to determine whether progress dialog & new thread needed - if(!region.areCitiesPreloaded()){ - progressMsg = "Loading cities..."; - } else if(city == null || city.getId() != OsmandSettings.getLastSearchedCity(this)){ - progressMsg = "Loading streets/buildings..."; + // try to determine whether progress dialog & new thread needed + if (region != null) { + Long cityId = OsmandSettings.getLastSearchedCity(this); + if (!region.areCitiesPreloaded()) { + progressMsg = "Loading cities..."; + } else if (cityId != -1 && region.getCityById(cityId).isEmptyWithStreets()) { + progressMsg = "Loading streets/buildings..."; + } else if (OsmandSettings.usingEnglishNames(this) != region.useEnglishNames()) { + progressMsg = "Converting native/english names..."; + } } city = null; street = null; building = null; if (progressMsg != null) { - dlg = ProgressDialog.show(this, "Loading", progressMsg, true); - new Thread("Loader search data") { - @Override - public void run() { - try { - loadData(); - } finally { - dlg.dismiss(); - runOnUiThread(new Runnable() { - @Override - public void run() { - updateUI(); - } - }); - } - } - }.start(); + startLoadDataInThread(progressMsg); } else { loadData(); updateUI(); @@ -224,15 +234,16 @@ public class SearchAddressActivity extends Activity { @Override protected void onPause() { - if(building == null && OsmandSettings.getLastSearchedBuilding(this).length() > 0){ - OsmandSettings.setLastSearchedBuilding(this, ""); - } - if(street == null && OsmandSettings.getLastSearchedStreet(this).length() > 0){ - OsmandSettings.setLastSearchedStreet(this, ""); - } - if(city == null && OsmandSettings.getLastSearchedCity(this) != -1){ - OsmandSettings.setLastSearchedCity(this, -1l); - } + // Do not reset settings (cause it is not so necessary) +// if(building == null && OsmandSettings.getLastSearchedBuilding(this).length() > 0){ +// OsmandSettings.setLastSearchedBuilding(this, ""); +// } +// if(street == null && OsmandSettings.getLastSearchedStreet(this).length() > 0){ +// OsmandSettings.setLastSearchedStreet(this, ""); +// } +// if(city == null && OsmandSettings.getLastSearchedCity(this) != -1){ +// OsmandSettings.setLastSearchedCity(this, -1l); +// } super.onPause(); } diff --git a/OsmAnd/src/com/osmand/activities/search/SearchBuildingByNameActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchBuildingByNameActivity.java index 77cea45736..2607415662 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchBuildingByNameActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchBuildingByNameActivity.java @@ -42,12 +42,12 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity @Override public void updateTextView(City obj, TextView txt) { if(getFilter().length() > 2){ - txt.setText(obj.getName() + " - " + MapUtils.getFormattedDistance((int) MapUtils.getDistance(obj.getLocation(), location))); + txt.setText(obj.getName(region.useEnglishNames()) + " - " + MapUtils.getFormattedDistance((int) MapUtils.getDistance(obj.getLocation(), location))); } else { - txt.setText(obj.getName()); + txt.setText(obj.getName(region.useEnglishNames())); } } diff --git a/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java index b5898abe4f..e13d5f1834 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java @@ -139,7 +139,7 @@ public class SearchPOIActivity extends ListActivity { LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(SearchPOIActivity.this); int dist = (int) (MapUtils.getDistance(anemity.getLocation(), lastKnownMapLocation.getLatitude(), lastKnownMapLocation .getLongitude())); - String str = anemity.getStringWithoutType(); + String str = anemity.getStringWithoutType(OsmandSettings.usingEnglishNames(SearchPOIActivity.this)); label.setText(str); icon.setImageResource(R.drawable.poi); distanceLabel.setText(" " + dist + " m "); diff --git a/OsmAnd/src/com/osmand/activities/search/SearchStreetByNameActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchStreetByNameActivity.java index a392dee998..a3acc03a9c 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchStreetByNameActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchStreetByNameActivity.java @@ -37,12 +37,12 @@ public class SearchStreetByNameActivity extends SearchByNameAbstractActivity