diff --git a/OsmAnd-java/src/net/osmand/router/GeneralRouter.java b/OsmAnd-java/src/net/osmand/router/GeneralRouter.java index ecaae2094a..d9204779a3 100644 --- a/OsmAnd-java/src/net/osmand/router/GeneralRouter.java +++ b/OsmAnd-java/src/net/osmand/router/GeneralRouter.java @@ -147,7 +147,10 @@ public class GeneralRouter implements VehicleRouter { public GeneralRouterProfile getProfile() { return profile; } - + + public boolean getHeightObstacles() { + return heightObstacles; + } public Map getParameters() { return parameters; diff --git a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java index 00738df442..2cea11d0dd 100644 --- a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java @@ -25,6 +25,7 @@ import net.osmand.osm.MapRenderingTypes; import net.osmand.router.BinaryRoutePlanner.FinalRouteSegment; import net.osmand.router.BinaryRoutePlanner.RouteSegment; import net.osmand.router.RoutePlannerFrontEnd.RouteCalculationMode; +import net.osmand.router.GeneralRouter.GeneralRouterProfile; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -108,6 +109,9 @@ public class RouteResultPreparation { } private void calculateTimeSpeed(RoutingContext ctx, List result) throws IOException { + //for Naismith + boolean usePedestrianHeight = ((((GeneralRouter) ctx.getRouter()).getProfile() == GeneralRouterProfile.PEDESTRIAN) && ((GeneralRouter) ctx.getRouter()).getHeightObstacles()); + for (int i = 0; i < result.size(); i++) { RouteSegmentResult rr = result.get(i); RouteDataObject road = rr.getObject(); @@ -125,6 +129,15 @@ public class RouteResultPreparation { boolean plus = rr.getStartPointIndex() < rr.getEndPointIndex(); int next; double distance = 0; + + //for Naismith + float prevHeight = -99999.0f; + float[] heightDistanceArray = null; + if (usePedestrianHeight) { + road.calculateHeightArray(); + heightDistanceArray = road.heightDistanceArray; + } + for (int j = rr.getStartPointIndex(); j != rr.getEndPointIndex(); j = next) { next = plus ? j + 1 : j - 1; double d = measuredDist(road.getPoint31XTile(j), road.getPoint31YTile(j), road.getPoint31XTile(next), @@ -134,9 +147,24 @@ public class RouteResultPreparation { if (obstacle < 0) { obstacle = 0; } - distOnRoadToPass += d / speed + obstacle; + distOnRoadToPass += d / speed + obstacle; //this is time in seconds + //for Naismith + if (usePedestrianHeight) { + int heightIndex = 2 * j + 1; + if (heightDistanceArray != null && heightIndex < heightDistanceArray.length) { + float height = heightDistanceArray[heightIndex]; + if (prevHeight != -99999.0f) { + float heightDiff = height - prevHeight; + if (heightDiff > 0) { //ascent only + distOnRoadToPass += heightDiff * 6.0f; //Naismith's rule: add 1 hour per every 600m of ascent + } + } + prevHeight = height; + } + } } + // last point turn time can be added // if(i + 1 < result.size()) { distOnRoadToPass += ctx.getRouter().calculateTurnTime(); } rr.setSegmentTime((float) distOnRoadToPass); diff --git a/OsmAnd/res/layout/search_more_list_item.xml b/OsmAnd/res/layout/search_more_list_item.xml index faa6e33c0c..30259e3576 100644 --- a/OsmAnd/res/layout/search_more_list_item.xml +++ b/OsmAnd/res/layout/search_more_list_item.xml @@ -47,6 +47,7 @@ osmand:typeface="@string/font_roboto_medium"/> + Modify the search query. Create or modify OSM objects Create or modify OSM POI, open or comment OSM Notes, and contribute recorded GPX files. Deleted diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index ac4ad2cebd..f8d3d6678b 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -761,7 +761,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC paused = false; hidden = false; if (interruptedSearch) { - addMoreButton(); + addMoreButton(true); interruptedSearch = false; } } @@ -1066,9 +1066,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } if (getResultCollection() != null) { updateSearchResult(getResultCollection(), false); - if (interruptedSearch || searchUICore.isSearchMoreAvailable(searchUICore.getPhrase())) { - addMoreButton(); - } + addMoreButton(searchUICore.isSearchMoreAvailable(searchUICore.getPhrase())); } break; } @@ -1537,9 +1535,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC searching = false; if (resultListener == null || resultListener.searchFinished(object.requiredSearchPhrase)) { hideProgressBar(); - if (searchUICore.isSearchMoreAvailable(object.requiredSearchPhrase)) { - addMoreButton(); - } + addMoreButton(searchUICore.isSearchMoreAvailable(object.requiredSearchPhrase)); } } }); @@ -1741,7 +1737,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } } - private void addMoreButton() { + private void addMoreButton(boolean searchMoreAvailable) { if (!paused && !cancelPrev && mainSearchFragment != null && !isTextEmpty()) { QuickSearchMoreListItem moreListItem = new QuickSearchMoreListItem(app, null, new SearchMoreItemOnClickListener() { @@ -1765,6 +1761,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC moreListItem.setInterruptedSearch(interruptedSearch); moreListItem.setEmptySearch(isResultEmpty()); moreListItem.setOnlineSearch(isOnlineSearch()); + moreListItem.setSearchMoreAvailable(searchMoreAvailable); mainSearchFragment.addListItem(moreListItem); } } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java index ab0982ffbd..4b211dbde1 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java @@ -20,16 +20,13 @@ import net.osmand.access.AccessibilityAssistant; import net.osmand.data.Amenity; import net.osmand.data.LatLon; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.dashboard.DashLocationFragment; -import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.search.listitems.QuickSearchHeaderListItem; import net.osmand.plus.search.listitems.QuickSearchListItem; import net.osmand.plus.search.listitems.QuickSearchListItemType; import net.osmand.plus.search.listitems.QuickSearchMoreListItem; import net.osmand.plus.search.listitems.QuickSearchSelectAllListItem; -import net.osmand.search.core.ObjectType; import net.osmand.search.core.SearchPhrase; import net.osmand.util.Algorithms; import net.osmand.util.OpeningHoursParser; @@ -215,10 +212,8 @@ public class QuickSearchListAdapter extends ArrayAdapter { LinearLayout view; if (type == QuickSearchListItemType.SEARCH_MORE) { if (convertView == null) { - LayoutInflater inflater = (LayoutInflater) app - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - view = (LinearLayout) inflater.inflate( - R.layout.search_more_list_item, null); + LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + view = (LinearLayout) inflater.inflate(R.layout.search_more_list_item, null); } else { view = (LinearLayout) convertView; } @@ -228,26 +223,32 @@ public class QuickSearchListAdapter extends ArrayAdapter { } else { ((TextView) view.findViewById(R.id.title)).setText(listItem.getName()); } - QuickSearchMoreListItem searchMoreListItem = (QuickSearchMoreListItem) listItem; - if (searchMoreListItem.isEmptySearch() && !searchMoreListItem.isInterruptedSearch()) { - view.findViewById(R.id.empty_search).setVisibility(View.VISIBLE); - view.findViewById(R.id.more_divider).setVisibility(View.VISIBLE); - } else { - view.findViewById(R.id.empty_search).setVisibility(View.GONE); - view.findViewById(R.id.more_divider).setVisibility(View.GONE); - } - view.findViewById(R.id.increase_radius_row).setOnClickListener(new View.OnClickListener() { + + final QuickSearchMoreListItem searchMoreItem = (QuickSearchMoreListItem) listItem; + int emptyDescId = searchMoreItem.isSearchMoreAvailable() ? R.string.nothing_found_descr : R.string.modify_the_search_query; + ((TextView) view.findViewById(R.id.empty_search_description)).setText(emptyDescId); + + boolean emptySearchVisible = searchMoreItem.isEmptySearch() && !searchMoreItem.isInterruptedSearch(); + boolean moreDividerVisible = emptySearchVisible && searchMoreItem.isSearchMoreAvailable(); + view.findViewById(R.id.empty_search).setVisibility(emptySearchVisible ? View.VISIBLE : View.GONE); + view.findViewById(R.id.more_divider).setVisibility(moreDividerVisible ? View.VISIBLE : View.GONE); + + View increaseRadiusRow = view.findViewById(R.id.increase_radius_row); + increaseRadiusRow.setVisibility(searchMoreItem.isSearchMoreAvailable() ? View.VISIBLE : View.GONE); + increaseRadiusRow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ((QuickSearchMoreListItem) listItem).increaseRadiusOnClick(); } }); - if (!searchMoreListItem.isOnlineSearch()) { - view.findViewById(R.id.online_search_row).setVisibility(View.VISIBLE); - view.findViewById(R.id.online_search_row).setOnClickListener(new View.OnClickListener() { + + if (!searchMoreItem.isOnlineSearch()) { + View onlineSearchRow = view.findViewById(R.id.online_search_row); + onlineSearchRow.setVisibility(View.VISIBLE); + onlineSearchRow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - ((QuickSearchMoreListItem) listItem).onlineSearchOnClick(); + searchMoreItem.onlineSearchOnClick(); } }); } diff --git a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchMoreListItem.java b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchMoreListItem.java index 141b0e3a5c..bf23afcb70 100644 --- a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchMoreListItem.java +++ b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchMoreListItem.java @@ -11,6 +11,7 @@ public class QuickSearchMoreListItem extends QuickSearchListItem { private SearchMoreItemOnClickListener onClickListener; private boolean emptySearch; private boolean onlineSearch; + private boolean searchMoreAvailable; private boolean interruptedSearch; private String findMore; private String restartSearch; @@ -68,6 +69,14 @@ public class QuickSearchMoreListItem extends QuickSearchListItem { this.onlineSearch = onlineSearch; } + public boolean isSearchMoreAvailable() { + return searchMoreAvailable; + } + + public void setSearchMoreAvailable(boolean searchMoreAvailable) { + this.searchMoreAvailable = searchMoreAvailable; + } + public void increaseRadiusOnClick() { if (onClickListener != null) { onClickListener.increaseRadiusOnClick();