Implement quick address search

This commit is contained in:
vshcherb 2013-08-17 01:42:37 +02:00
parent 8fb4fdcb7a
commit 64cab3f72d
6 changed files with 53 additions and 6 deletions

View file

@ -112,10 +112,10 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity<B
text = hno;
}
settings.setLastSearchedBuilding(text, loc);
finish();
quitActivity();
}
@Override
public boolean filterObject(Building obj, String filter){
if(super.filterObject(obj, filter)){

View file

@ -22,6 +22,10 @@ import net.osmand.plus.activities.OsmandListActivity;
import org.apache.commons.logging.Log;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.AsyncTask;
@ -79,6 +83,7 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
setContentView(R.layout.search_by_name);
getSupportActionBar().setTitle(R.string.search_activity);
getSupportActionBar().setIcon(R.drawable.tab_search_address_icon);
initializeTask = getInitializeTask();
uiHandler = new UIUpdateHandler();
@ -440,4 +445,34 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
return row;
}
}
protected void quitActivity() {
finish();
if(getNextActivity() != null) {
Intent intent = new Intent(this, getNextActivity());
startActivity(intent);
}
}
protected Class<? extends Activity> getNextActivity() {
return null;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == 1) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
createMenuItem(menu, 1, R.string.default_buttons_ok,
R.drawable.ic_action_ok_light, R.drawable.ic_action_ok_dark ,
MenuItem.SHOW_AS_ACTION_IF_ROOM);
return super.onCreateOptionsMenu(menu);
}
}

View file

@ -16,6 +16,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.resources.RegionAddressRepository;
import net.osmand.util.MapUtils;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Message;
import android.view.Gravity;
@ -169,7 +170,7 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<City>
if (region.getCityById(obj.getId(), obj.getName(region.useEnglishNames())) == null) {
region.addCityToPreloadedList((City) obj);
}
finish();
quitActivity();
}
private final class CityComparator implements Comparator<City> {
@ -218,5 +219,10 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<City>
return c1? 1 : -1;
}
}
@Override
protected Class<? extends Activity> getNextActivity() {
return SearchStreetByNameActivity.class;
}
}

View file

@ -9,6 +9,7 @@ import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.resources.RegionAddressRepository;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
@ -52,7 +53,12 @@ public class SearchRegionByNameActivity extends SearchByNameAbstractActivity<Reg
@Override
public void itemSelected(RegionAddressRepository obj) {
((OsmandApplication) getApplication()).getSettings().setLastSearchedRegion(obj.getName(), obj.getEstimatedRegionCenter());
finish();
quitActivity();
}
@Override
protected Class<? extends Activity> getNextActivity() {
return SearchCityByNameActivity.class;
}
}

View file

@ -64,6 +64,6 @@ public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<St
@Override
public void itemSelected(Street obj) {
settings.setLastSearchedIntersectedStreet(obj.getName(region.useEnglishNames()), obj.getLocation());
finish();
quitActivity();
}
}

View file

@ -216,7 +216,7 @@ public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Str
settings.setLastSearchedCity(obj.getCity().getId(), obj.getCity().getName(), obj.getLocation());
}
settings.setLastSearchedStreet(obj.getName(region.useEnglishNames()), obj.getLocation());
finish();
quitActivity();
}
}