Add progress bars to search activities
This commit is contained in:
parent
e864bee7cb
commit
3e0350a963
6 changed files with 203 additions and 127 deletions
|
@ -18,7 +18,7 @@ import android.widget.RadioButton;
|
||||||
import android.widget.RadioGroup;
|
import android.widget.RadioGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class SearchAddressActivity extends Activity {
|
public class SearchAddressActivity extends Activity {
|
||||||
|
|
||||||
private Button showOnMap;
|
private Button showOnMap;
|
||||||
private Button streetButton;
|
private Button streetButton;
|
||||||
|
@ -37,7 +37,6 @@ public class SearchAddressActivity extends Activity {
|
||||||
private Button searchOnline;
|
private Button searchOnline;
|
||||||
|
|
||||||
private OsmandSettings osmandSettings;
|
private OsmandSettings osmandSettings;
|
||||||
|
|
||||||
private LatLon searchPoint = null;
|
private LatLon searchPoint = null;
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,6 +57,27 @@ public class SearchAddressActivity extends Activity {
|
||||||
attachListeners();
|
attachListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Intent createIntent(Class<?> cl){
|
||||||
|
LatLon location = null;
|
||||||
|
Intent intent = getIntent();
|
||||||
|
if(intent != null){
|
||||||
|
double lat = intent.getDoubleExtra(SearchActivity.SEARCH_LAT, 0);
|
||||||
|
double lon = intent.getDoubleExtra(SearchActivity.SEARCH_LON, 0);
|
||||||
|
if(lat != 0 || lon != 0){
|
||||||
|
location = new LatLon(lat, lon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (location == null && getParent() instanceof SearchActivity) {
|
||||||
|
location = ((SearchActivity) getParent()).getSearchPoint();
|
||||||
|
}
|
||||||
|
Intent newIntent = new Intent(SearchAddressActivity.this, cl);
|
||||||
|
if (location != null) {
|
||||||
|
newIntent.putExtra(SearchActivity.SEARCH_LAT, location.getLatitude());
|
||||||
|
newIntent.putExtra(SearchActivity.SEARCH_LON, location.getLongitude());
|
||||||
|
}
|
||||||
|
return newIntent;
|
||||||
|
}
|
||||||
|
|
||||||
private void attachListeners() {
|
private void attachListeners() {
|
||||||
if (getParent() instanceof SearchActivity) {
|
if (getParent() instanceof SearchActivity) {
|
||||||
searchOnline.setOnClickListener(new View.OnClickListener() {
|
searchOnline.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@ -72,28 +92,28 @@ public class SearchAddressActivity extends Activity {
|
||||||
countryButton.setOnClickListener(new View.OnClickListener(){
|
countryButton.setOnClickListener(new View.OnClickListener(){
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
startActivity(new Intent(SearchAddressActivity.this, SearchRegionByNameActivity.class));
|
startActivity(createIntent(SearchRegionByNameActivity.class));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
cityButton.setOnClickListener(new View.OnClickListener(){
|
cityButton.setOnClickListener(new View.OnClickListener(){
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
startActivity(new Intent(SearchAddressActivity.this, SearchCityByNameActivity.class));
|
startActivity(createIntent(SearchCityByNameActivity.class));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
streetButton.setOnClickListener(new View.OnClickListener(){
|
streetButton.setOnClickListener(new View.OnClickListener(){
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
startActivity(new Intent(SearchAddressActivity.this, SearchStreetByNameActivity.class));
|
startActivity(createIntent(SearchStreetByNameActivity.class));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
buildingButton.setOnClickListener(new View.OnClickListener(){
|
buildingButton.setOnClickListener(new View.OnClickListener(){
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if(radioBuilding){
|
if(radioBuilding){
|
||||||
startActivity(new Intent(SearchAddressActivity.this, SearchBuildingByNameActivity.class));
|
startActivity(createIntent(SearchBuildingByNameActivity.class));
|
||||||
} else {
|
} else {
|
||||||
startActivity(new Intent(SearchAddressActivity.this, SearchStreet2ByNameActivity.class));
|
startActivity(createIntent(SearchStreet2ByNameActivity.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -113,6 +133,7 @@ public class SearchAddressActivity extends Activity {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
building = null;
|
building = null;
|
||||||
|
searchPoint = null;
|
||||||
updateUI();
|
updateUI();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -122,6 +143,7 @@ public class SearchAddressActivity extends Activity {
|
||||||
street = null;
|
street = null;
|
||||||
building = null;
|
building = null;
|
||||||
street2 = null;
|
street2 = null;
|
||||||
|
searchPoint = null;
|
||||||
updateUI();
|
updateUI();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -133,6 +155,7 @@ public class SearchAddressActivity extends Activity {
|
||||||
street = null;
|
street = null;
|
||||||
street2 = null;
|
street2 = null;
|
||||||
building = null;
|
building = null;
|
||||||
|
searchPoint = null;
|
||||||
updateUI();
|
updateUI();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -145,6 +168,7 @@ public class SearchAddressActivity extends Activity {
|
||||||
street = null;
|
street = null;
|
||||||
street2 = null;
|
street2 = null;
|
||||||
building = null;
|
building = null;
|
||||||
|
searchPoint = null;
|
||||||
updateUI();
|
updateUI();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -218,6 +242,8 @@ public class SearchAddressActivity extends Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateUI(){
|
protected void updateUI(){
|
||||||
|
showOnMap.setEnabled(searchPoint != null);
|
||||||
|
navigateTo.setEnabled(searchPoint != null);
|
||||||
findViewById(R.id.ResetCountry).setEnabled(!Algoritms.isEmpty(region));
|
findViewById(R.id.ResetCountry).setEnabled(!Algoritms.isEmpty(region));
|
||||||
if(Algoritms.isEmpty(region)){
|
if(Algoritms.isEmpty(region)){
|
||||||
countryButton.setText(R.string.ChooseCountry);
|
countryButton.setText(R.string.ChooseCountry);
|
||||||
|
@ -286,8 +312,6 @@ public class SearchAddressActivity extends Activity {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
searchPoint = osmandSettings.getLastSearchedPoint();
|
searchPoint = osmandSettings.getLastSearchedPoint();
|
||||||
showOnMap.setEnabled(searchPoint != null);
|
|
||||||
navigateTo.setEnabled(searchPoint != null);
|
|
||||||
|
|
||||||
region = null;
|
region = null;
|
||||||
postcode = null;
|
postcode = null;
|
||||||
|
@ -297,23 +321,6 @@ public class SearchAddressActivity extends Activity {
|
||||||
region = osmandSettings.getLastSearchedRegion();
|
region = osmandSettings.getLastSearchedRegion();
|
||||||
loadData();
|
loadData();
|
||||||
updateUI();
|
updateUI();
|
||||||
|
|
||||||
// TODO other can be moved to specific searches
|
|
||||||
// if (region != null) {
|
|
||||||
// Long cityId = osmandSettings.getLastSearchedCity();
|
|
||||||
// String postcode = osmandSettings.getLastSearchedPostcode();
|
|
||||||
// if (!region.areCitiesPreloaded()) {
|
|
||||||
// progressMsg = getString(R.string.loading_cities);
|
|
||||||
// } else if (postcode != null && !region.arePostcodesPreloaded()) {
|
|
||||||
// progressMsg = getString(R.string.loading_postcodes);
|
|
||||||
// } else if (cityId != -1 && region.getCityById(cityId) != null && region.getCityById(cityId).isEmptyWithStreets()) {
|
|
||||||
// progressMsg = getString(R.string.loading_streets_buildings);
|
|
||||||
// } else if (postcode != null && region.getPostcode(postcode) != null && region.getPostcode(postcode).isEmptyWithStreets()) {
|
|
||||||
// progressMsg = getString(R.string.loading_streets_buildings);
|
|
||||||
// } else if (osmandSettings.USE_ENGLISH_NAMES.get() != region.useEnglishNames()) {
|
|
||||||
// progressMsg = getString(R.string.converting_names);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,8 @@ import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.RegionAddressRepository;
|
import net.osmand.plus.RegionAddressRepository;
|
||||||
import net.osmand.plus.activities.OsmandApplication;
|
import net.osmand.plus.activities.OsmandApplication;
|
||||||
import android.os.Bundle;
|
import android.os.AsyncTask;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity<Building> {
|
public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity<Building> {
|
||||||
|
@ -19,23 +20,38 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity<B
|
||||||
private City city;
|
private City city;
|
||||||
private Street street;
|
private Street street;
|
||||||
private PostCode postcode;
|
private PostCode postcode;
|
||||||
private OsmandSettings settings;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
public AsyncTask<Object, ?, ?> getInitializeTask() {
|
||||||
settings = OsmandSettings.getOsmandSettings(this);
|
return new AsyncTask<Object, Void, Void>(){
|
||||||
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion());
|
@Override
|
||||||
if(region != null){
|
protected void onPostExecute(Void result) {
|
||||||
postcode = region.getPostcode(settings.getLastSearchedPostcode());
|
((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_building);
|
||||||
city = region.getCityById(settings.getLastSearchedCity());
|
progress.setVisibility(View.INVISIBLE);
|
||||||
if(postcode != null){
|
resetText();
|
||||||
street = region.getStreetByName(postcode, settings.getLastSearchedStreet());
|
|
||||||
} else if(city != null){
|
|
||||||
street = region.getStreetByName(city, settings.getLastSearchedStreet());
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
super.onCreate(savedInstanceState);
|
@Override
|
||||||
((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_building);
|
protected void onPreExecute() {
|
||||||
|
((TextView)findViewById(R.id.Label)).setText(R.string.loading_streets_buildings);
|
||||||
|
progress.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Object... params) {
|
||||||
|
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion());
|
||||||
|
if(region != null){
|
||||||
|
postcode = region.getPostcode(settings.getLastSearchedPostcode());
|
||||||
|
city = region.getCityById(settings.getLastSearchedCity());
|
||||||
|
if(postcode != null){
|
||||||
|
street = region.getStreetByName(postcode, settings.getLastSearchedStreet());
|
||||||
|
} else if(city != null){
|
||||||
|
street = region.getStreetByName(city, settings.getLastSearchedStreet());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,12 +2,17 @@ package net.osmand.plus.activities.search;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.osmand.osm.LatLon;
|
||||||
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
import android.os.AsyncTask.Status;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -26,11 +31,17 @@ public abstract class SearchByNameAbstractActivity<T> extends ListActivity {
|
||||||
|
|
||||||
private EditText searchText;
|
private EditText searchText;
|
||||||
private Handler handlerToLoop;
|
private Handler handlerToLoop;
|
||||||
private ProgressBar progress;
|
private AsyncTask<Object, ?, ?> initializeTask;
|
||||||
|
|
||||||
|
protected ProgressBar progress;
|
||||||
|
protected LatLon locationToSearch;
|
||||||
|
protected OsmandSettings settings;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
settings = OsmandSettings.getOsmandSettings(this);
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
|
|
||||||
setContentView(R.layout.search_by_name);
|
setContentView(R.layout.search_by_name);
|
||||||
|
@ -42,7 +53,9 @@ public abstract class SearchByNameAbstractActivity<T> extends ListActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
setText(s.toString());
|
if(initializeTask.getStatus() == Status.FINISHED){
|
||||||
|
setText(s.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
@ -56,16 +69,26 @@ public abstract class SearchByNameAbstractActivity<T> extends ListActivity {
|
||||||
|
|
||||||
progress.setVisibility(View.INVISIBLE);
|
progress.setVisibility(View.INVISIBLE);
|
||||||
findViewById(R.id.ResetButton).setOnClickListener(new View.OnClickListener(){
|
findViewById(R.id.ResetButton).setOnClickListener(new View.OnClickListener(){
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
searchText.setText(""); //$NON-NLS-1$
|
resetText();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||||
|
|
||||||
|
initializeTask = getInitializeTask();
|
||||||
|
if(initializeTask != null){
|
||||||
|
initializeTask.execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public AsyncTask<Object, ?, ?> getInitializeTask(){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isFilterableByDefault(){
|
public boolean isFilterableByDefault(){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -74,6 +97,10 @@ public abstract class SearchByNameAbstractActivity<T> extends ListActivity {
|
||||||
return searchText.getText();
|
return searchText.getText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resetText(){
|
||||||
|
setText("");
|
||||||
|
}
|
||||||
|
|
||||||
protected void updateUIList(final List<T> objects){
|
protected void updateUIList(final List<T> objects){
|
||||||
runOnUiThread(new Runnable(){
|
runOnUiThread(new Runnable(){
|
||||||
@Override
|
@Override
|
||||||
|
@ -140,6 +167,7 @@ public abstract class SearchByNameAbstractActivity<T> extends ListActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (handlerToLoop == null) {
|
if (handlerToLoop == null) {
|
||||||
new Thread("Filter data") { //$NON-NLS-1$
|
new Thread("Filter data") { //$NON-NLS-1$
|
||||||
|
@ -153,7 +181,18 @@ public abstract class SearchByNameAbstractActivity<T> extends ListActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
super.onResume();
|
Intent intent = getIntent();
|
||||||
|
if(intent != null){
|
||||||
|
if(intent.hasExtra(SearchActivity.SEARCH_LAT) && intent.hasExtra(SearchActivity.SEARCH_LON)){
|
||||||
|
double lat = intent.getDoubleExtra(SearchActivity.SEARCH_LAT, 0);
|
||||||
|
double lon = intent.getDoubleExtra(SearchActivity.SEARCH_LON, 0);
|
||||||
|
locationToSearch = new LatLon(lat, lon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(locationToSearch == null){
|
||||||
|
locationToSearch = settings.getLastKnownMapLocation();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,28 +13,43 @@ import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.RegionAddressRepository;
|
import net.osmand.plus.RegionAddressRepository;
|
||||||
import net.osmand.plus.activities.OsmandApplication;
|
import net.osmand.plus.activities.OsmandApplication;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class SearchCityByNameActivity extends SearchByNameAbstractActivity<MapObject> {
|
public class SearchCityByNameActivity extends SearchByNameAbstractActivity<MapObject> {
|
||||||
private RegionAddressRepository region;
|
private RegionAddressRepository region;
|
||||||
private LatLon location;
|
|
||||||
private OsmandSettings settings;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
public AsyncTask<Object, ?, ?> getInitializeTask() {
|
||||||
settings = ((OsmandApplication)getApplication()).getSettings();
|
return new AsyncTask<Object, Void, Void>(){
|
||||||
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion());
|
@Override
|
||||||
location = settings.getLastKnownMapLocation();
|
protected void onPostExecute(Void result) {
|
||||||
super.onCreate(savedInstanceState);
|
((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_city);
|
||||||
((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_city);
|
progress.setVisibility(View.INVISIBLE);
|
||||||
|
resetText();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
((TextView)findViewById(R.id.Label)).setText(R.string.loading_cities);
|
||||||
|
progress.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Object... params) {
|
||||||
|
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MapObject> getObjects(String filter) {
|
public List<MapObject> getObjects(String filter) {
|
||||||
List<MapObject> l = new ArrayList<MapObject>();
|
List<MapObject> l = new ArrayList<MapObject>();
|
||||||
if(region != null){
|
if(region != null){
|
||||||
region.fillWithSuggestedCities(filter, l, location);
|
region.fillWithSuggestedCities(filter, l, locationToSearch);
|
||||||
}
|
}
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
@ -42,9 +57,9 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<MapOb
|
||||||
@Override
|
@Override
|
||||||
public void updateTextView(MapObject obj, TextView txt) {
|
public void updateTextView(MapObject obj, TextView txt) {
|
||||||
LatLon l = obj.getLocation();
|
LatLon l = obj.getLocation();
|
||||||
if (getFilter().length() > 2 && location != null && l != null) {
|
if (getFilter().length() > 2 && locationToSearch != null && l != null) {
|
||||||
txt.setText(obj.getName(region.useEnglishNames()) + " - " + //$NON-NLS-1$
|
txt.setText(obj.getName(region.useEnglishNames()) + " - " + //$NON-NLS-1$
|
||||||
OsmAndFormatter.getFormattedDistance((int) MapUtils.getDistance(l, location), this));
|
OsmAndFormatter.getFormattedDistance((int) MapUtils.getDistance(l, locationToSearch), this));
|
||||||
} else {
|
} else {
|
||||||
txt.setText(obj.getName(region.useEnglishNames()));
|
txt.setText(obj.getName(region.useEnglishNames()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,9 @@ import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.RegionAddressRepository;
|
import net.osmand.plus.RegionAddressRepository;
|
||||||
import net.osmand.plus.activities.OsmandApplication;
|
import net.osmand.plus.activities.OsmandApplication;
|
||||||
import android.app.ProgressDialog;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<Street> {
|
public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<Street> {
|
||||||
|
@ -20,66 +21,50 @@ public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<St
|
||||||
private PostCode postcode;
|
private PostCode postcode;
|
||||||
private Street street1;
|
private Street street1;
|
||||||
private List<Street> initialList = new ArrayList<Street>();
|
private List<Street> initialList = new ArrayList<Street>();
|
||||||
private ProgressDialog progressDlg;
|
|
||||||
private OsmandSettings settings;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
public AsyncTask<Object, ?, ?> getInitializeTask() {
|
||||||
settings = OsmandSettings.getOsmandSettings(this);
|
return new AsyncTask<Object, Void, Void>(){
|
||||||
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion());
|
|
||||||
if(region != null){
|
|
||||||
postcode = region.getPostcode(settings.getLastSearchedPostcode());
|
|
||||||
city = region.getCityById(settings.getLastSearchedCity());
|
|
||||||
if(postcode != null){
|
|
||||||
street1 = region.getStreetByName(postcode, (settings.getLastSearchedStreet()));
|
|
||||||
if(street1 != null){
|
|
||||||
city = street1.getCity();
|
|
||||||
}
|
|
||||||
} else if(city != null){
|
|
||||||
street1 = region.getStreetByName(city, (settings.getLastSearchedStreet()));
|
|
||||||
}
|
|
||||||
if(city != null){
|
|
||||||
startLoadDataInThread(getString(R.string.loading_streets));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_street);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStop() {
|
|
||||||
if(progressDlg != null){
|
|
||||||
progressDlg.dismiss();
|
|
||||||
progressDlg = null;
|
|
||||||
}
|
|
||||||
super.onStop();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void startLoadDataInThread(String progressMsg){
|
|
||||||
progressDlg = ProgressDialog.show(this, getString(R.string.loading), progressMsg, true);
|
|
||||||
new Thread("Loader search data") { //$NON-NLS-1$
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
protected void onPostExecute(Void result) {
|
||||||
try {
|
((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_street);
|
||||||
List<Street> t = new ArrayList<Street>();
|
((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_building);
|
||||||
region.fillWithSuggestedStreetsIntersectStreets(city, street1, t);
|
progress.setVisibility(View.INVISIBLE);
|
||||||
initialList = t;
|
resetText();
|
||||||
} finally {
|
|
||||||
if(progressDlg != null){
|
|
||||||
progressDlg.dismiss();
|
|
||||||
progressDlg = null;
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
setText(getFilter().toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.start();
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
((TextView)findViewById(R.id.Label)).setText(R.string.loading_streets);
|
||||||
|
progress.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Object... params) {
|
||||||
|
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion());
|
||||||
|
if(region != null){
|
||||||
|
postcode = region.getPostcode(settings.getLastSearchedPostcode());
|
||||||
|
city = region.getCityById(settings.getLastSearchedCity());
|
||||||
|
if(postcode != null){
|
||||||
|
street1 = region.getStreetByName(postcode, (settings.getLastSearchedStreet()));
|
||||||
|
if(street1 != null){
|
||||||
|
city = street1.getCity();
|
||||||
|
}
|
||||||
|
} else if(city != null){
|
||||||
|
street1 = region.getStreetByName(city, (settings.getLastSearchedStreet()));
|
||||||
|
}
|
||||||
|
if(city != null){
|
||||||
|
List<Street> t = new ArrayList<Street>();
|
||||||
|
region.fillWithSuggestedStreetsIntersectStreets(city, street1, t);
|
||||||
|
initialList = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Street> getObjects(String filter) {
|
public List<Street> getObjects(String filter) {
|
||||||
int ind = 0;
|
int ind = 0;
|
||||||
|
@ -111,6 +96,5 @@ public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<St
|
||||||
public void itemSelected(Street obj) {
|
public void itemSelected(Street obj) {
|
||||||
settings.setLastSearchedIntersectedStreet(obj.getName(region.useEnglishNames()), region.findStreetIntersection(street1, obj));
|
settings.setLastSearchedIntersectedStreet(obj.getName(region.useEnglishNames()), region.findStreetIntersection(street1, obj));
|
||||||
finish();
|
finish();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,31 +6,46 @@ import java.util.List;
|
||||||
import net.osmand.data.City;
|
import net.osmand.data.City;
|
||||||
import net.osmand.data.PostCode;
|
import net.osmand.data.PostCode;
|
||||||
import net.osmand.data.Street;
|
import net.osmand.data.Street;
|
||||||
import net.osmand.plus.OsmandSettings;
|
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.RegionAddressRepository;
|
import net.osmand.plus.RegionAddressRepository;
|
||||||
import net.osmand.plus.activities.OsmandApplication;
|
import net.osmand.plus.activities.OsmandApplication;
|
||||||
import android.os.Bundle;
|
import android.os.AsyncTask;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Street> {
|
public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Street> {
|
||||||
private RegionAddressRepository region;
|
private RegionAddressRepository region;
|
||||||
private City city;
|
private City city;
|
||||||
private PostCode postcode;
|
private PostCode postcode;
|
||||||
private OsmandSettings settings;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
public AsyncTask<Object, ?, ?> getInitializeTask() {
|
||||||
settings = OsmandSettings.getOsmandSettings(this);
|
return new AsyncTask<Object, Void, Void>(){
|
||||||
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion());
|
@Override
|
||||||
if(region != null){
|
protected void onPostExecute(Void result) {
|
||||||
postcode = region.getPostcode(settings.getLastSearchedPostcode());
|
((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_street);
|
||||||
if (postcode == null) {
|
progress.setVisibility(View.INVISIBLE);
|
||||||
city = region.getCityById(settings.getLastSearchedCity());
|
resetText();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
super.onCreate(savedInstanceState);
|
@Override
|
||||||
((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_street);
|
protected void onPreExecute() {
|
||||||
|
((TextView)findViewById(R.id.Label)).setText(R.string.loading_streets);
|
||||||
|
progress.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Object... params) {
|
||||||
|
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion());
|
||||||
|
if(region != null){
|
||||||
|
postcode = region.getPostcode(settings.getLastSearchedPostcode());
|
||||||
|
if (postcode == null) {
|
||||||
|
city = region.getCityById(settings.getLastSearchedCity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue