Add quick access panel to search street/city activity

This commit is contained in:
vshcherb 2013-10-22 00:02:29 +02:00
parent d11086ca4f
commit d987aa427f
6 changed files with 202 additions and 37 deletions

View file

@ -13,6 +13,7 @@ import net.osmand.plus.activities.MapActivityActions;
import net.osmand.plus.resources.RegionAddressRepository; import net.osmand.plus.resources.RegionAddressRepository;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
@ -262,59 +263,96 @@ public class SearchAddressFragment extends SherlockFragment {
}); });
} }
public static class AddressInformation {
String historyName = null;
String objectName = "";
int zoom = 14;
public static AddressInformation build2StreetIntersection(Context ctx, OsmandSettings settings){
AddressInformation ai = new AddressInformation();
String postcode = settings.getLastSearchedPostcode();
String city = settings.getLastSearchedCityName();
String cityName = !Algorithms.isEmpty(postcode) ? postcode : city;
ai.objectName = settings.getLastSearchedStreet();
ai.historyName = MessageFormat.format(ctx. getString(R.string.search_history_int_streets), settings.getLastSearchedStreet(),
settings.getLastSearchedIntersectedStreet(), cityName);
ai.zoom = 17;
return ai;
}
public static AddressInformation buildStreet(Context ctx, OsmandSettings settings){
AddressInformation ai = new AddressInformation();
String postcode = settings.getLastSearchedPostcode();
String city = settings.getLastSearchedCityName();
String cityName = !Algorithms.isEmpty(postcode) ? postcode : city;
String street = settings.getLastSearchedStreet();
ai.objectName = street;
ai.historyName = MessageFormat.format(ctx.getString(R.string.search_history_street), street, cityName);
ai.zoom = 16;
return ai;
}
public static AddressInformation buildBuilding(Context ctx, OsmandSettings settings){
AddressInformation ai = new AddressInformation();
String postcode = settings.getLastSearchedPostcode();
String city = settings.getLastSearchedCityName();
String cityName = !Algorithms.isEmpty(postcode) ? postcode : city;
String street = settings.getLastSearchedStreet();
String building = settings.getLastSearchedBuilding();
ai.objectName = street + " " + building;
ai.historyName = MessageFormat.format(ctx.getString(R.string.search_history_building), building, street,
cityName);
ai.zoom = 17;
return ai;
}
public static AddressInformation buildCity(Context ctx, OsmandSettings settings){
AddressInformation ai = new AddressInformation();
String city = settings.getLastSearchedCityName();
ai.historyName = MessageFormat.format(ctx.getString(R.string.search_history_city), city);
ai.objectName = city;
ai.zoom = 14;
return ai;
}
}
public void select(int mode) { public void select(int mode) {
if (searchPoint == null) { if (searchPoint == null) {
AccessibleToast.makeText(getActivity(), R.string.please_select_address, Toast.LENGTH_SHORT).show(); AccessibleToast.makeText(getActivity(), R.string.please_select_address, Toast.LENGTH_SHORT).show();
return; return;
} }
String historyName = null; AddressInformation ai = new AddressInformation();
String objectName = "";
int zoom = 14;
if (!Algorithms.isEmpty(street2) && !Algorithms.isEmpty(street)) { if (!Algorithms.isEmpty(street2) && !Algorithms.isEmpty(street)) {
String cityName = !Algorithms.isEmpty(postcode) ? postcode : city; ai = AddressInformation.build2StreetIntersection(getActivity(), osmandSettings);
objectName = street;
historyName = MessageFormat.format(getString(R.string.search_history_int_streets), street, street2,
cityName);
zoom = 17;
} else if (!Algorithms.isEmpty(building)) { } else if (!Algorithms.isEmpty(building)) {
String cityName = !Algorithms.isEmpty(postcode) ? postcode : city; ai = AddressInformation.buildBuilding(getActivity(), osmandSettings);
objectName = street + " " + building;
historyName = MessageFormat.format(getString(R.string.search_history_building), building, street,
cityName);
zoom = 17;
} else if (!Algorithms.isEmpty(street)) { } else if (!Algorithms.isEmpty(street)) {
String cityName = postcode != null ? postcode : city; ai = AddressInformation.buildStreet(getActivity(), osmandSettings);
objectName = street; } else if(!Algorithms.isEmpty(city)) {
historyName = MessageFormat.format(getString(R.string.search_history_street), street, cityName); ai = AddressInformation.buildCity(getActivity(), osmandSettings);
zoom = 16;
} else if (!Algorithms.isEmpty(city)) {
historyName = MessageFormat.format(getString(R.string.search_history_city), city);
objectName = city;
zoom = 14;
} }
if(mode == ADD_TO_FAVORITE) { if(mode == ADD_TO_FAVORITE) {
Bundle b = new Bundle(); Bundle b = new Bundle();
Dialog dlg = MapActivityActions.createAddFavouriteDialog(getActivity(), b); Dialog dlg = MapActivityActions.createAddFavouriteDialog(getActivity(), b);
dlg.show(); dlg.show();
MapActivityActions.prepareAddFavouriteDialog(getActivity(), dlg, b, searchPoint.getLatitude(), searchPoint.getLongitude(), objectName); MapActivityActions.prepareAddFavouriteDialog(getActivity(), dlg, b, searchPoint.getLatitude(), searchPoint.getLongitude(), ai.objectName);
} else if(mode == SELECT_POINT ){ } else if(mode == SELECT_POINT ){
Intent intent = getActivity().getIntent(); Intent intent = getActivity().getIntent();
intent.putExtra(SELECT_ADDRESS_POINT_INTENT_KEY, objectName); intent.putExtra(SELECT_ADDRESS_POINT_INTENT_KEY, ai.objectName);
intent.putExtra(SELECT_ADDRESS_POINT_LAT, searchPoint.getLatitude()); intent.putExtra(SELECT_ADDRESS_POINT_LAT, searchPoint.getLatitude());
intent.putExtra(SELECT_ADDRESS_POINT_LON, searchPoint.getLongitude()); intent.putExtra(SELECT_ADDRESS_POINT_LON, searchPoint.getLongitude());
getActivity().setResult(SELECT_ADDRESS_POINT_RESULT_OK, intent); getActivity().setResult(SELECT_ADDRESS_POINT_RESULT_OK, intent);
getActivity().finish(); getActivity().finish();
} else { } else {
OsmandApplication ctx = (OsmandApplication) getActivity().getApplication();
if (mode == NAVIGATE_TO) { if (mode == NAVIGATE_TO) {
MapActivityActions.directionsToDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(), searchPoint.getLongitude(), historyName); MapActivityActions.directionsToDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(), searchPoint.getLongitude(), ai.historyName);
} else if (mode == ADD_WAYPOINT) { } else if (mode == ADD_WAYPOINT) {
MapActivityActions.addWaypointDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(), searchPoint.getLongitude(), historyName); MapActivityActions.addWaypointDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(), searchPoint.getLongitude(), ai.historyName);
} else if (mode == SHOW_ON_MAP) { } else if (mode == SHOW_ON_MAP) {
osmandSettings.setMapLocationToShow(searchPoint.getLatitude(), searchPoint.getLongitude(), zoom, historyName); osmandSettings.setMapLocationToShow(searchPoint.getLatitude(), searchPoint.getLongitude(), ai.zoom, ai.historyName);
MapActivity.launchMapActivityMoveToTop(getActivity()); MapActivity.launchMapActivityMoveToTop(getActivity());
} }
} }
} }

View file

@ -10,6 +10,7 @@ import net.osmand.data.LatLon;
import net.osmand.data.Street; import net.osmand.data.Street;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.search.SearchAddressFragment.AddressInformation;
import net.osmand.plus.resources.RegionAddressRepository; import net.osmand.plus.resources.RegionAddressRepository;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import android.os.AsyncTask; import android.os.AsyncTask;
@ -116,6 +117,11 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity<B
quitActivity(null); quitActivity(null);
} }
@Override
protected AddressInformation getAddressInformation() {
return AddressInformation.buildStreet(this, settings);
}
@Override @Override
public boolean filterObject(Building obj, String filter){ public boolean filterObject(Building obj, String filter){

View file

@ -18,17 +18,18 @@ import net.osmand.data.MapObject;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityActions;
import net.osmand.plus.activities.OsmandListActivity; import net.osmand.plus.activities.OsmandListActivity;
import net.osmand.plus.activities.search.SearchAddressFragment.AddressInformation;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import android.app.ActionBar; import android.app.ActionBar;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.AsyncTask.Status; import android.os.AsyncTask.Status;
@ -55,6 +56,10 @@ import android.widget.TextView;
import android.widget.TextView.BufferType; import android.widget.TextView.BufferType;
import android.widget.TextView.OnEditorActionListener; import android.widget.TextView.OnEditorActionListener;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener;
public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity { public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity {
@ -63,6 +68,7 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
protected static final int MESSAGE_CLEAR_LIST = 1; protected static final int MESSAGE_CLEAR_LIST = 1;
protected static final int MESSAGE_ADD_ENTITY = 2; protected static final int MESSAGE_ADD_ENTITY = 2;
protected static final String SEQUENTIAL_SEARCH = "SEQUENTIAL_SEARCH";
protected ProgressBar progress; protected ProgressBar progress;
protected LatLon locationToSearch; protected LatLon locationToSearch;
@ -78,6 +84,12 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
private StyleSpan previousSpan; private StyleSpan previousSpan;
private static final Log log = PlatformUtil.getLog(SearchByNameAbstractActivity.class); private static final Log log = PlatformUtil.getLog(SearchByNameAbstractActivity.class);
private static final int NAVIGATE_TO = 3;
private static final int ADD_WAYPOINT = 4;
private static final int SHOW_ON_MAP = 5;
private static final int ADD_TO_FAVORITE = 6;
protected void setActionBarSettings() { protected void setActionBarSettings() {
// getSherlock().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW); // getSherlock().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
@ -199,6 +211,7 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
private int MAX_VISIBLE_NAME = 18; private int MAX_VISIBLE_NAME = 18;
private boolean sequentialSearch;
public String getCurrentFilter() { public String getCurrentFilter() {
return currentFilter; return currentFilter;
@ -297,12 +310,14 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
Intent intent = getIntent(); Intent intent = getIntent();
sequentialSearch = false;
if(intent != null){ if(intent != null){
if(intent.hasExtra(SearchActivity.SEARCH_LAT) && intent.hasExtra(SearchActivity.SEARCH_LON)){ if(intent.hasExtra(SearchActivity.SEARCH_LAT) && intent.hasExtra(SearchActivity.SEARCH_LON)){
double lat = intent.getDoubleExtra(SearchActivity.SEARCH_LAT, 0); double lat = intent.getDoubleExtra(SearchActivity.SEARCH_LAT, 0);
double lon = intent.getDoubleExtra(SearchActivity.SEARCH_LON, 0); double lon = intent.getDoubleExtra(SearchActivity.SEARCH_LON, 0);
locationToSearch = new LatLon(lat, lon); locationToSearch = new LatLon(lat, lon);
} }
sequentialSearch = intent.hasExtra(SEQUENTIAL_SEARCH) && getAddressInformation() != null;
} }
if(locationToSearch == null){ if(locationToSearch == null){
locationToSearch = settings.getLastKnownMapLocation(); locationToSearch = settings.getLastKnownMapLocation();
@ -458,6 +473,14 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
finish(); finish();
if(next != null) { if(next != null) {
Intent intent = new Intent(this, next); Intent intent = new Intent(this, next);
if(getIntent() != null){
Intent cintent = getIntent();
if(cintent.hasExtra(SearchActivity.SEARCH_LAT) && cintent.hasExtra(SearchActivity.SEARCH_LON)){
intent.putExtra(SearchActivity.SEARCH_LAT, cintent.getDoubleExtra(SearchActivity.SEARCH_LAT, 0));
intent.putExtra(SearchActivity.SEARCH_LON, cintent.getDoubleExtra(SearchActivity.SEARCH_LON, 0));
intent.putExtra(SEQUENTIAL_SEARCH, true);
}
}
startActivity(intent); startActivity(intent);
} }
} }
@ -468,15 +491,104 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
if (item.getItemId() == 1) { if (item.getItemId() == 1) {
finish(); finish();
return true; return true;
} else {
select(item.getItemId());
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
createMenuItem(menu, 1, R.string.default_buttons_ok, if (sequentialSearch) {
R.drawable.ic_action_ok_light, R.drawable.ic_action_ok_dark , boolean light = ((OsmandApplication) getApplication()).getSettings().isLightActionBar();
MenuItem.SHOW_AS_ACTION_ALWAYS); com.actionbarsherlock.view.MenuItem menuItem = menu.add(0, NAVIGATE_TO, 0, R.string.get_directions)
.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_gdirections_light
: R.drawable.ic_action_gdirections_dark);
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
select(NAVIGATE_TO);
return true;
}
});
TargetPointsHelper targets = ((OsmandApplication) getApplication()).getTargetPointsHelper();
if (targets.getPointToNavigate() != null) {
menuItem = menu.add(0, ADD_WAYPOINT, 0, R.string.context_menu_item_intermediate_point)
.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_flage_light : R.drawable.ic_action_flage_dark);
} else {
menuItem = menu.add(0, ADD_WAYPOINT, 0, R.string.context_menu_item_destination_point)
.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_flag_light : R.drawable.ic_action_flag_dark);
}
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
select(ADD_WAYPOINT);
return true;
}
});
menuItem = menu.add(0, SHOW_ON_MAP, 0, R.string.search_shown_on_map).setShowAsActionFlags(
MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_marker_light : R.drawable.ic_action_marker_dark);
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
select(SHOW_ON_MAP);
return true;
}
});
menuItem = menu.add(0, ADD_TO_FAVORITE, 0, R.string.add_to_favourite).setShowAsActionFlags(
MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menuItem = menuItem.setIcon(light ? R.drawable.ic_action_fav_light : R.drawable.ic_action_fav_dark);
menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
select(ADD_TO_FAVORITE);
return true;
}
});
} else {
createMenuItem(menu, 1, R.string.default_buttons_ok, R.drawable.ic_action_ok_light,
R.drawable.ic_action_ok_dark, MenuItem.SHOW_AS_ACTION_ALWAYS);
}
return super.onCreateOptionsMenu(menu); return super.onCreateOptionsMenu(menu);
}
protected AddressInformation getAddressInformation() {
return null;
}
protected void select(int mode) {
LatLon searchPoint = settings.getLastSearchedPoint();
AddressInformation ai = getAddressInformation();
if (ai != null) {
if (mode == ADD_TO_FAVORITE) {
Bundle b = new Bundle();
Dialog dlg = MapActivityActions.createAddFavouriteDialog(getActivity(), b);
dlg.show();
MapActivityActions.prepareAddFavouriteDialog(getActivity(), dlg, b, searchPoint.getLatitude(),
searchPoint.getLongitude(), ai.objectName);
} else if (mode == NAVIGATE_TO) {
MapActivityActions.directionsToDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(),
searchPoint.getLongitude(), ai.historyName);
} else if (mode == ADD_WAYPOINT) {
MapActivityActions.addWaypointDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(),
searchPoint.getLongitude(), ai.historyName);
} else if (mode == SHOW_ON_MAP) {
settings.setMapLocationToShow(searchPoint.getLatitude(), searchPoint.getLongitude(), ai.zoom,
ai.historyName);
MapActivity.launchMapActivityMoveToTop(getActivity());
}
}
}
private Activity getActivity() {
return this;
} }
} }

View file

@ -14,9 +14,9 @@ import net.osmand.data.LatLon;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.search.SearchAddressFragment.AddressInformation;
import net.osmand.plus.resources.RegionAddressRepository; import net.osmand.plus.resources.RegionAddressRepository;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import android.app.Activity;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Message; import android.os.Message;
import android.view.Gravity; import android.view.Gravity;

View file

@ -8,6 +8,7 @@ import net.osmand.data.MapObject.MapObjectComparator;
import net.osmand.data.Street; import net.osmand.data.Street;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.search.SearchAddressFragment.AddressInformation;
import net.osmand.plus.resources.RegionAddressRepository; import net.osmand.plus.resources.RegionAddressRepository;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.view.View; import android.view.View;
@ -54,7 +55,10 @@ public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<St
}; };
} }
@Override
protected AddressInformation getAddressInformation() {
return AddressInformation.buildStreet(this, settings);
}
@Override @Override
public String getText(Street obj) { public String getText(Street obj) {

View file

@ -16,6 +16,7 @@ import net.osmand.data.Street;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.search.SearchAddressFragment.AddressInformation;
import net.osmand.plus.resources.RegionAddressRepository; import net.osmand.plus.resources.RegionAddressRepository;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
@ -223,4 +224,8 @@ public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Str
// } // }
} }
protected AddressInformation getAddressInformation() {
return AddressInformation.buildCity(this, settings);
}
} }