Compare commits
4 commits
master
...
poi_search
Author | SHA1 | Date | |
---|---|---|---|
|
d9437f89df | ||
|
d61718cdfc | ||
|
63e1ffbf1d | ||
|
62313cc468 |
5 changed files with 61 additions and 38 deletions
|
@ -12,6 +12,7 @@
|
|||
|
||||
-->
|
||||
|
||||
<string name="search_more">Search more…</string>
|
||||
<string name="map_quick_action_pattern">%1$s → …</string>
|
||||
<string name="output">Output</string>
|
||||
<string name="user_points">User points</string>
|
||||
|
|
|
@ -98,9 +98,13 @@ public class MenuBuilder {
|
|||
private static final int PICK_IMAGE = 1231;
|
||||
public static final float SHADOW_HEIGHT_TOP_DP = 17f;
|
||||
public static final int TITLE_LIMIT = 60;
|
||||
protected static final String[] arrowChars = new String[] {"=>", " - "};
|
||||
protected static final String[] arrowChars = new String[]{"=>", " - "};
|
||||
protected final String NEAREST_WIKI_KEY = "nearest_wiki_key";
|
||||
protected final String NEAREST_POI_KEY = "nearest_poi_key";
|
||||
private static final int POI_COUNT = 10;
|
||||
private static final int MINIMUM_RADIUS = 100;
|
||||
private static final int MAXIMUM_RADIUS = 1000;
|
||||
private static final int FACTOR = 2;
|
||||
|
||||
protected MapActivity mapActivity;
|
||||
protected MapContextMenu mapContextMenu;
|
||||
|
@ -573,29 +577,29 @@ public class MenuBuilder {
|
|||
}
|
||||
|
||||
public View buildRow(View view, int iconId, String buttonText, String text, int textColor,
|
||||
boolean collapsable, final CollapsableView collapsableView,
|
||||
boolean needLinks, int textLinesLimit, boolean isUrl, OnClickListener onClickListener, boolean matchWidthDivider) {
|
||||
boolean collapsable, final CollapsableView collapsableView,
|
||||
boolean needLinks, int textLinesLimit, boolean isUrl, OnClickListener onClickListener, boolean matchWidthDivider) {
|
||||
return buildRow(view, iconId == 0 ? null : getRowIcon(iconId), buttonText, text, textColor, null, collapsable, collapsableView,
|
||||
needLinks, textLinesLimit, isUrl, onClickListener, matchWidthDivider);
|
||||
}
|
||||
|
||||
public View buildRow(final View view, Drawable icon, final String buttonText, final String text, int textColor, String secondaryText,
|
||||
boolean collapsable, final CollapsableView collapsableView, boolean needLinks,
|
||||
int textLinesLimit, boolean isUrl, OnClickListener onClickListener, boolean matchWidthDivider) {
|
||||
boolean collapsable, final CollapsableView collapsableView, boolean needLinks,
|
||||
int textLinesLimit, boolean isUrl, OnClickListener onClickListener, boolean matchWidthDivider) {
|
||||
return buildRow(view, icon, buttonText, null, text, textColor, secondaryText, collapsable, collapsableView,
|
||||
needLinks, textLinesLimit, isUrl, false, false, onClickListener, matchWidthDivider);
|
||||
}
|
||||
|
||||
public View buildRow(View view, int iconId, String buttonText, String text, int textColor,
|
||||
boolean collapsable, final CollapsableView collapsableView,
|
||||
boolean needLinks, int textLinesLimit, boolean isUrl, boolean isNumber, boolean isEmail, OnClickListener onClickListener, boolean matchWidthDivider) {
|
||||
boolean collapsable, final CollapsableView collapsableView,
|
||||
boolean needLinks, int textLinesLimit, boolean isUrl, boolean isNumber, boolean isEmail, OnClickListener onClickListener, boolean matchWidthDivider) {
|
||||
return buildRow(view, iconId == 0 ? null : getRowIcon(iconId), buttonText, null, text, textColor, null, collapsable, collapsableView,
|
||||
needLinks, textLinesLimit, isUrl, isNumber, isEmail, onClickListener, matchWidthDivider);
|
||||
}
|
||||
|
||||
public View buildRow(final View view, Drawable icon, final String buttonText, final String textPrefix, final String text,
|
||||
int textColor, String secondaryText, boolean collapsable, final CollapsableView collapsableView, boolean needLinks,
|
||||
int textLinesLimit, boolean isUrl, boolean isNumber, boolean isEmail, OnClickListener onClickListener, boolean matchWidthDivider) {
|
||||
int textColor, String secondaryText, boolean collapsable, final CollapsableView collapsableView, boolean needLinks,
|
||||
int textLinesLimit, boolean isUrl, boolean isNumber, boolean isEmail, OnClickListener onClickListener, boolean matchWidthDivider) {
|
||||
|
||||
if (!isFirstRow()) {
|
||||
buildRowDivider(view);
|
||||
|
@ -1041,8 +1045,8 @@ public class MenuBuilder {
|
|||
}
|
||||
|
||||
public void addPlainMenuItem(int iconId, String text, boolean needLinks, boolean isUrl,
|
||||
boolean collapsable, CollapsableView collapsableView,
|
||||
OnClickListener onClickListener) {
|
||||
boolean collapsable, CollapsableView collapsableView,
|
||||
OnClickListener onClickListener) {
|
||||
plainMenuItems.add(new PlainMenuItem(iconId, null, text, needLinks, isUrl, collapsable, collapsableView, onClickListener));
|
||||
}
|
||||
|
||||
|
@ -1222,32 +1226,35 @@ public class MenuBuilder {
|
|||
|
||||
for (final Amenity poi : nearestAmenities) {
|
||||
TextViewEx button = buildButtonInCollapsableView(context, false, false);
|
||||
String name = poi.getName(preferredMapAppLang, transliterateNames);
|
||||
final PointDescription pointDescription = mapActivity.getMapLayers().getPoiMapLayer().getObjectName(poi);
|
||||
String name = pointDescription.getName();
|
||||
if (Algorithms.isBlank(name)) {
|
||||
name = AmenityMenuController.getTypeStr(poi);
|
||||
}
|
||||
float dist = (float) MapUtils.getDistance(latLon, poi.getLocation());
|
||||
name += " (" + OsmAndFormatter.getFormattedDistance(dist, app) + ")";
|
||||
button.setText(name);
|
||||
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
LatLon latLon = new LatLon(poi.getLocation().getLatitude(), poi.getLocation().getLongitude());
|
||||
PointDescription pointDescription = mapActivity.getMapLayers().getPoiMapLayer().getObjectName(poi);
|
||||
mapActivity.getContextMenu().show(latLon, pointDescription, poi);
|
||||
mapActivity.setMapLocation(poi.getLocation().getLatitude(), poi.getLocation().getLongitude());
|
||||
}
|
||||
});
|
||||
view.addView(button);
|
||||
|
||||
}
|
||||
|
||||
PoiUIFilter filter = getPoiFilterForType(nearestPoiType);
|
||||
if (filter != null) {
|
||||
view.addView(createShowAllButton(context, filter));
|
||||
if (filter != null && nearestAmenities.size() == POI_COUNT) {
|
||||
view.addView(createShowOnMap(context, filter));
|
||||
}
|
||||
view.addView(createSearchMoreButton(context, filter));
|
||||
return new CollapsableView(view, this, collapsed);
|
||||
}
|
||||
|
||||
private View createShowAllButton(Context context, final PoiUIFilter filter) {
|
||||
private View createShowOnMap(Context context, final PoiUIFilter filter) {
|
||||
TextViewEx buttonShowAll = buildButtonInCollapsableView(context, false, false);
|
||||
buttonShowAll.setText(app.getString(R.string.shared_string_show_on_map));
|
||||
buttonShowAll.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -1288,6 +1295,18 @@ public class MenuBuilder {
|
|||
return buttonShowAll;
|
||||
}
|
||||
|
||||
private View createSearchMoreButton(Context context, final PoiUIFilter filter) {
|
||||
TextViewEx buttonShowAll = buildButtonInCollapsableView(context, false, false);
|
||||
buttonShowAll.setText(app.getString(R.string.search_more));
|
||||
buttonShowAll.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mapActivity.showQuickSearch(filter);
|
||||
}
|
||||
});
|
||||
return buttonShowAll;
|
||||
}
|
||||
|
||||
protected LinearLayout buildCollapsableContentView(Context context, boolean collapsed, boolean needMargin) {
|
||||
final LinearLayout view = new LinearLayout(context);
|
||||
view.setOrientation(LinearLayout.VERTICAL);
|
||||
|
@ -1381,9 +1400,14 @@ public class MenuBuilder {
|
|||
}
|
||||
|
||||
private List<Amenity> getSortedAmenities(PoiUIFilter filter, final LatLon latLon) {
|
||||
QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), 250);
|
||||
QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), MINIMUM_RADIUS);
|
||||
|
||||
List<Amenity> nearestAmenities = getAmenities(rect, filter);
|
||||
|
||||
for (int radius = MINIMUM_RADIUS; nearestAmenities.size() - 1 <= POI_COUNT && radius <= MAXIMUM_RADIUS; radius *= FACTOR) {
|
||||
rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), radius);
|
||||
nearestAmenities = getAmenities(rect, filter);
|
||||
}
|
||||
nearestAmenities.remove(amenity);
|
||||
|
||||
Collections.sort(nearestAmenities, new Comparator<Amenity>() {
|
||||
|
@ -1396,7 +1420,7 @@ public class MenuBuilder {
|
|||
}
|
||||
});
|
||||
|
||||
return nearestAmenities;
|
||||
return nearestAmenities.subList(0, Math.min(POI_COUNT, nearestAmenities.size()));
|
||||
}
|
||||
|
||||
private List<Amenity> getAmenities(QuadRect rect, PoiUIFilter filter) {
|
||||
|
|
|
@ -28,6 +28,7 @@ import net.osmand.plus.OsmandPlugin;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.search.SearchActivity;
|
||||
import net.osmand.plus.helpers.enums.MetricsConstants;
|
||||
import net.osmand.plus.mapcontextmenu.CollapsableView;
|
||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||
|
@ -68,7 +69,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
|||
private static final String WIKI_LINK = ".wikipedia.org/w";
|
||||
public final static Log LOG = PlatformUtil.getLog(AmenityMenuBuilder.class);
|
||||
private final static DecimalFormat DF = new DecimalFormat("#.##");
|
||||
private MetricsConstants metricSystem;
|
||||
private final MetricsConstants metricSystem;
|
||||
private final Amenity amenity;
|
||||
|
||||
|
||||
|
@ -417,7 +418,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
|||
} else if (Amenity.OPENING_HOURS.equals(key)) {
|
||||
iconId = R.drawable.ic_action_time;
|
||||
collapsableView = getCollapsableTextView(view.getContext(), true,
|
||||
amenity.getAdditionalInfo(key).replace("; ", "\n").replace(",", ", "));
|
||||
amenity.getAdditionalInfo(key).replace("; ", "\n").replace(",", ", "));
|
||||
collapsable = true;
|
||||
OpeningHoursParser.OpeningHours rs = OpeningHoursParser.parseOpenedHours(amenity.getAdditionalInfo(key));
|
||||
if (rs != null) {
|
||||
|
@ -459,7 +460,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
|||
vl = sb.toString();
|
||||
} else if (key.contains(Amenity.ROUTE)
|
||||
|| key.equals(Amenity.WIKIDATA)
|
||||
|| key.equals(Amenity.WIKIMEDIA_COMMONS)) {
|
||||
|| key.equals(Amenity.WIKIMEDIA_COMMONS)) {
|
||||
continue;
|
||||
} else {
|
||||
if (key.contains(Amenity.DESCRIPTION)) {
|
||||
|
@ -661,7 +662,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
|||
buildAmenityRow(view, wikiInfo);
|
||||
}
|
||||
|
||||
if (processNearestPoi() && nearestPoi.size() > 0) {
|
||||
if (processNearestPoi()) {
|
||||
AmenityInfoRow poiInfo = new AmenityInfoRow(
|
||||
NEAREST_POI_KEY, AmenityMenuController.getRightIconId(amenity), null,
|
||||
app.getString(R.string.speak_poi) + " \"" + AmenityMenuController.getTypeStr(amenity) + "\" (" + nearestPoi.size() + ")",
|
||||
|
@ -725,35 +726,35 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
|||
}
|
||||
break;
|
||||
case "distance":
|
||||
if(Algorithms.isFloat(value)) {
|
||||
if (Algorithms.isFloat(value)) {
|
||||
float valueAsFloatInMeters = Float.parseFloat(value) * 1000;
|
||||
if (metricSystem == MetricsConstants.KILOMETERS_AND_METERS) {
|
||||
formattedValue =
|
||||
value + " " + mapActivity.getResources().getString(R.string.km);
|
||||
value + " " + mapActivity.getResources().getString(R.string.km);
|
||||
} else {
|
||||
formattedValue = OsmAndFormatter.getFormattedDistance(valueAsFloatInMeters,
|
||||
mapActivity.getMyApplication());
|
||||
mapActivity.getMyApplication());
|
||||
}
|
||||
formattedPrefix = formatPrefix(prefix,
|
||||
mapActivity.getResources().getString(R.string.distance));
|
||||
mapActivity.getResources().getString(R.string.distance));
|
||||
break;
|
||||
}
|
||||
case "capacity":
|
||||
if (amenity.getSubType().equals("water_tower") || amenity.getSubType().equals("storage_tank")) {
|
||||
if(Algorithms.isFloat(value)) {
|
||||
if (Algorithms.isFloat(value)) {
|
||||
formattedValue = value + " " + mapActivity.getResources().getString(R.string.cubic_m);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "maxweight":
|
||||
if(Algorithms.isInt(value)) {
|
||||
if (Algorithms.isInt(value)) {
|
||||
formattedValue = value + " " + mapActivity.getResources().getString(R.string.metric_ton);
|
||||
}
|
||||
break;
|
||||
case "students":
|
||||
case "spots":
|
||||
case "seats":
|
||||
if(Algorithms.isInt(value)) {
|
||||
if (Algorithms.isInt(value)) {
|
||||
formattedPrefix = formatPrefix(prefix, mapActivity.getResources().getString(R.string.shared_string_capacity));
|
||||
}
|
||||
break;
|
||||
|
@ -764,7 +765,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
|||
}
|
||||
|
||||
private String formatPrefix(String prefix, String units) {
|
||||
return (!prefix.isEmpty()) ? (prefix + ", " + units): units;
|
||||
return (!prefix.isEmpty()) ? (prefix + ", " + units) : units;
|
||||
}
|
||||
|
||||
public void buildAmenityRow(View view, AmenityInfoRow info) {
|
||||
|
|
|
@ -313,7 +313,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
|||
|
||||
public List<Amenity> searchAmenities(double top, double left, double bottom, double right, int zoom,
|
||||
ResultMatcher<Amenity> matcher) {
|
||||
List<Amenity> results = new ArrayList<Amenity>();
|
||||
List<Amenity> results = new ArrayList<>();
|
||||
List<Amenity> tempResults = currentSearchResult;
|
||||
if (tempResults != null) {
|
||||
for (Amenity a : tempResults) {
|
||||
|
|
|
@ -604,9 +604,6 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
|
|||
selectedItems.clear();
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
if (selectionListener != null) {
|
||||
selectionListener.onUpdateSelectionMode(selectedItems);
|
||||
}
|
||||
} else {
|
||||
QuickSearchListItem listItem = getItem(position);
|
||||
if (ch.isChecked()) {
|
||||
|
@ -614,9 +611,9 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
|
|||
} else {
|
||||
selectedItems.remove(listItem);
|
||||
}
|
||||
if (selectionListener != null) {
|
||||
selectionListener.onUpdateSelectionMode(selectedItems);
|
||||
}
|
||||
}
|
||||
if (selectionListener != null) {
|
||||
selectionListener.onUpdateSelectionMode(selectedItems);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue