From d987aa427f255b1f67c2f4251b69ed732a7b8c16 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Tue, 22 Oct 2013 00:02:29 +0200 Subject: [PATCH] Add quick access panel to search street/city activity --- .../search/SearchAddressFragment.java | 94 +++++++++---- .../search/SearchBuildingByNameActivity.java | 6 + .../search/SearchByNameAbstractActivity.java | 126 +++++++++++++++++- .../search/SearchCityByNameActivity.java | 2 +- .../search/SearchStreet2ByNameActivity.java | 6 +- .../search/SearchStreetByNameActivity.java | 5 + 6 files changed, 202 insertions(+), 37 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressFragment.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressFragment.java index 0229d67717..72ddc8fa23 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressFragment.java @@ -13,6 +13,7 @@ import net.osmand.plus.activities.MapActivityActions; import net.osmand.plus.resources.RegionAddressRepository; import net.osmand.util.Algorithms; import android.app.Dialog; +import android.content.Context; import android.content.Intent; import android.os.Bundle; 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) { if (searchPoint == null) { AccessibleToast.makeText(getActivity(), R.string.please_select_address, Toast.LENGTH_SHORT).show(); return; } - String historyName = null; - String objectName = ""; - int zoom = 14; + AddressInformation ai = new AddressInformation(); if (!Algorithms.isEmpty(street2) && !Algorithms.isEmpty(street)) { - String cityName = !Algorithms.isEmpty(postcode) ? postcode : city; - objectName = street; - historyName = MessageFormat.format(getString(R.string.search_history_int_streets), street, street2, - cityName); - zoom = 17; + ai = AddressInformation.build2StreetIntersection(getActivity(), osmandSettings); } else if (!Algorithms.isEmpty(building)) { - String cityName = !Algorithms.isEmpty(postcode) ? postcode : city; - objectName = street + " " + building; - historyName = MessageFormat.format(getString(R.string.search_history_building), building, street, - cityName); - zoom = 17; + ai = AddressInformation.buildBuilding(getActivity(), osmandSettings); } else if (!Algorithms.isEmpty(street)) { - String cityName = postcode != null ? postcode : city; - objectName = street; - historyName = MessageFormat.format(getString(R.string.search_history_street), street, cityName); - zoom = 16; - } else if (!Algorithms.isEmpty(city)) { - historyName = MessageFormat.format(getString(R.string.search_history_city), city); - objectName = city; - zoom = 14; + ai = AddressInformation.buildStreet(getActivity(), osmandSettings); + } else if(!Algorithms.isEmpty(city)) { + ai = AddressInformation.buildCity(getActivity(), osmandSettings); } 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(), objectName); + MapActivityActions.prepareAddFavouriteDialog(getActivity(), dlg, b, searchPoint.getLatitude(), searchPoint.getLongitude(), ai.objectName); } else if(mode == SELECT_POINT ){ 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_LON, searchPoint.getLongitude()); getActivity().setResult(SELECT_ADDRESS_POINT_RESULT_OK, intent); getActivity().finish(); } else { - OsmandApplication ctx = (OsmandApplication) getActivity().getApplication(); 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) { - MapActivityActions.addWaypointDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(), searchPoint.getLongitude(), historyName); + MapActivityActions.addWaypointDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(), searchPoint.getLongitude(), ai.historyName); } 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()); } - } } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchBuildingByNameActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchBuildingByNameActivity.java index 3b4aa13351..7177c2e3e9 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchBuildingByNameActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchBuildingByNameActivity.java @@ -10,6 +10,7 @@ import net.osmand.data.LatLon; import net.osmand.data.Street; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.activities.search.SearchAddressFragment.AddressInformation; import net.osmand.plus.resources.RegionAddressRepository; import net.osmand.util.Algorithms; import android.os.AsyncTask; @@ -116,6 +117,11 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity extends OsmandListActivity { @@ -63,6 +68,7 @@ public abstract class SearchByNameAbstractActivity extends OsmandListActivity protected static final int MESSAGE_CLEAR_LIST = 1; protected static final int MESSAGE_ADD_ENTITY = 2; + protected static final String SEQUENTIAL_SEARCH = "SEQUENTIAL_SEARCH"; protected ProgressBar progress; protected LatLon locationToSearch; @@ -78,6 +84,12 @@ public abstract class SearchByNameAbstractActivity extends OsmandListActivity private StyleSpan previousSpan; 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() { // getSherlock().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); @@ -199,6 +211,7 @@ public abstract class SearchByNameAbstractActivity extends OsmandListActivity private int MAX_VISIBLE_NAME = 18; + private boolean sequentialSearch; public String getCurrentFilter() { return currentFilter; @@ -297,12 +310,14 @@ public abstract class SearchByNameAbstractActivity extends OsmandListActivity protected void onResume() { super.onResume(); Intent intent = getIntent(); + sequentialSearch = false; 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); } + sequentialSearch = intent.hasExtra(SEQUENTIAL_SEARCH) && getAddressInformation() != null; } if(locationToSearch == null){ locationToSearch = settings.getLastKnownMapLocation(); @@ -458,6 +473,14 @@ public abstract class SearchByNameAbstractActivity extends OsmandListActivity finish(); if(next != null) { 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); } } @@ -468,15 +491,104 @@ public abstract class SearchByNameAbstractActivity extends OsmandListActivity if (item.getItemId() == 1) { finish(); return true; + } else { + select(item.getItemId()); } 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_ALWAYS); + if (sequentialSearch) { + boolean light = ((OsmandApplication) getApplication()).getSettings().isLightActionBar(); + 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); + } + + 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; } } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchCityByNameActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchCityByNameActivity.java index 4f430769b6..45c43096d0 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchCityByNameActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchCityByNameActivity.java @@ -14,9 +14,9 @@ import net.osmand.data.LatLon; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.activities.search.SearchAddressFragment.AddressInformation; 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; diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchStreet2ByNameActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchStreet2ByNameActivity.java index 87c4565fae..0cfaf282da 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchStreet2ByNameActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchStreet2ByNameActivity.java @@ -8,6 +8,7 @@ import net.osmand.data.MapObject.MapObjectComparator; import net.osmand.data.Street; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.activities.search.SearchAddressFragment.AddressInformation; import net.osmand.plus.resources.RegionAddressRepository; import android.os.AsyncTask; import android.view.View; @@ -54,7 +55,10 @@ public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity