use of net.osmand.search.core.SearchPhrase in project Osmand by osmandapp.
the class QuickSearchDialogFragment method showInstance.
public static boolean showInstance(@NonNull MainActivity mainActivity, @NonNull String searchQuery, @Nullable Object object, boolean showCategories, @Nullable LatLon latLon) {
try {
Bundle bundle = new Bundle();
if (object != null) {
bundle.putBoolean(QUICK_SEARCH_RUN_SEARCH_FIRST_TIME_KEY, true);
String objectLocalizedName = searchQuery;
if (object instanceof PoiCategory) {
PoiCategory c = (PoiCategory) object;
objectLocalizedName = c.getTranslation();
SearchUICore searchUICore = mainActivity.getMyApplication().getSearchUICore().getCore();
SearchPhrase phrase = searchUICore.resetPhrase(objectLocalizedName + " ");
SearchResult sr = new SearchResult(phrase);
sr.localeName = objectLocalizedName;
sr.object = c;
sr.priority = SEARCH_AMENITY_TYPE_PRIORITY;
sr.priorityDistance = 0;
sr.objectType = ObjectType.POI_TYPE;
searchUICore.selectSearchResult(sr);
bundle.putBoolean(QUICK_SEARCH_PHRASE_DEFINED_KEY, true);
}
searchQuery = objectLocalizedName.trim() + " ";
} else if (!Algorithms.isEmpty(searchQuery)) {
bundle.putBoolean(QUICK_SEARCH_RUN_SEARCH_FIRST_TIME_KEY, true);
}
bundle.putString(QUICK_SEARCH_QUERY_KEY, searchQuery);
bundle.putBoolean(QUICK_SEARCH_SHOW_CATEGORIES_KEY, showCategories);
if (latLon != null) {
bundle.putDouble(QUICK_SEARCH_LAT_KEY, latLon.getLatitude());
bundle.putDouble(QUICK_SEARCH_LON_KEY, latLon.getLongitude());
}
QuickSearchDialogFragment fragment = new QuickSearchDialogFragment();
fragment.setArguments(bundle);
fragment.show(mainActivity.getSupportFragmentManager(), TAG);
return true;
} catch (RuntimeException e) {
return false;
}
}
use of net.osmand.search.core.SearchPhrase in project Osmand by osmandapp.
the class QuickSearchDialogFragment method showInstance.
public static boolean showInstance(@NonNull MapActivity mapActivity, @NonNull String searchQuery, @Nullable Object object, QuickSearchType searchType, QuickSearchTab showSearchTab, @Nullable LatLon latLon) {
try {
if (mapActivity.isActivityDestroyed()) {
return false;
}
mapActivity.getMyApplication().logEvent(mapActivity, "search_open");
Bundle bundle = new Bundle();
if (object != null) {
bundle.putBoolean(QUICK_SEARCH_RUN_SEARCH_FIRST_TIME_KEY, true);
String objectLocalizedName = searchQuery;
if (object instanceof PoiCategory) {
PoiCategory c = (PoiCategory) object;
objectLocalizedName = c.getTranslation();
SearchUICore searchUICore = mapActivity.getMyApplication().getSearchUICore().getCore();
SearchPhrase phrase = searchUICore.resetPhrase(objectLocalizedName + " ");
SearchResult sr = new SearchResult(phrase);
sr.localeName = objectLocalizedName;
sr.object = c;
sr.priority = SEARCH_AMENITY_TYPE_PRIORITY;
sr.priorityDistance = 0;
sr.objectType = ObjectType.POI_TYPE;
searchUICore.selectSearchResult(sr);
bundle.putBoolean(QUICK_SEARCH_PHRASE_DEFINED_KEY, true);
} else if (object instanceof PoiUIFilter) {
PoiUIFilter filter = (PoiUIFilter) object;
objectLocalizedName = filter.getName();
SearchUICore searchUICore = mapActivity.getMyApplication().getSearchUICore().getCore();
SearchPhrase phrase = searchUICore.resetPhrase();
SearchResult sr = new SearchResult(phrase);
sr.localeName = objectLocalizedName;
sr.object = filter;
sr.priority = SEARCH_AMENITY_TYPE_PRIORITY;
sr.priorityDistance = 0;
sr.objectType = ObjectType.POI_TYPE;
searchUICore.selectSearchResult(sr);
bundle.putBoolean(QUICK_SEARCH_PHRASE_DEFINED_KEY, true);
}
searchQuery = objectLocalizedName.trim() + " ";
} else if (!Algorithms.isEmpty(searchQuery)) {
bundle.putBoolean(QUICK_SEARCH_RUN_SEARCH_FIRST_TIME_KEY, true);
}
bundle.putString(QUICK_SEARCH_QUERY_KEY, searchQuery);
bundle.putString(QUICK_SEARCH_SHOW_TAB_KEY, showSearchTab.name());
bundle.putString(QUICK_SEARCH_TYPE_KEY, searchType.name());
if (latLon != null) {
bundle.putDouble(QUICK_SEARCH_LAT_KEY, latLon.getLatitude());
bundle.putDouble(QUICK_SEARCH_LON_KEY, latLon.getLongitude());
}
QuickSearchDialogFragment fragment = new QuickSearchDialogFragment();
fragment.setArguments(bundle);
fragment.show(mapActivity.getSupportFragmentManager(), TAG);
return true;
} catch (RuntimeException e) {
return false;
}
}
use of net.osmand.search.core.SearchPhrase in project Osmand by osmandapp.
the class QuickSearchListAdapter method getView.
@NonNull
@Override
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
final QuickSearchListItem listItem = getItem(position);
QuickSearchListItemType type = listItem.getType();
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);
} else {
view = (LinearLayout) convertView;
}
if (listItem.getSpannableName() != null) {
((TextView) view.findViewById(R.id.title)).setText(listItem.getSpannableName());
} else {
((TextView) view.findViewById(R.id.title)).setText(listItem.getName());
}
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);
SearchUICore searchUICore = app.getSearchUICore().getCore();
String textTitle = app.getString(R.string.nothing_found_in_radius) + " " + OsmAndFormatter.getFormattedDistance(searchUICore.getMinimalSearchRadius(searchUICore.getPhrase()), app);
((TextView) view.findViewById(R.id.empty_search_title)).setText(textTitle);
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 (!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) {
searchMoreItem.onlineSearchOnClick();
}
});
}
} else if (type == QuickSearchListItemType.BUTTON) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = (LinearLayout) inflater.inflate(R.layout.search_custom_list_item, null);
} else {
view = (LinearLayout) convertView;
}
((ImageView) view.findViewById(R.id.imageView)).setImageDrawable(listItem.getIcon());
if (listItem.getSpannableName() != null) {
((TextView) view.findViewById(R.id.title)).setText(listItem.getSpannableName());
} else {
((TextView) view.findViewById(R.id.title)).setText(listItem.getName());
}
} else if (type == QuickSearchListItemType.SELECT_ALL) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = (LinearLayout) inflater.inflate(R.layout.select_all_list_item, null);
} else {
view = (LinearLayout) convertView;
}
final CheckBox ch = (CheckBox) view.findViewById(R.id.toggle_item);
ch.setVisibility(View.VISIBLE);
ch.setChecked(selectAll);
ch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
toggleCheckbox(position, ch);
}
});
} else if (type == QuickSearchListItemType.HEADER) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = (LinearLayout) inflater.inflate(R.layout.search_header_list_item, null);
} else {
view = (LinearLayout) convertView;
}
view.findViewById(R.id.top_divider).setVisibility(((QuickSearchHeaderListItem) listItem).isShowTopDivider() ? View.VISIBLE : View.GONE);
if (listItem.getSpannableName() != null) {
((TextView) view.findViewById(R.id.title)).setText(listItem.getSpannableName());
} else {
((TextView) view.findViewById(R.id.title)).setText(listItem.getName());
}
} else if (type == QuickSearchListItemType.TOP_SHADOW) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = (LinearLayout) inflater.inflate(R.layout.list_shadow_header, null);
} else {
view = (LinearLayout) convertView;
}
return view;
} else if (type == QuickSearchListItemType.BOTTOM_SHADOW) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = (LinearLayout) inflater.inflate(R.layout.list_shadow_footer, null);
} else {
view = (LinearLayout) convertView;
}
return view;
} else {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = (LinearLayout) inflater.inflate(R.layout.search_list_item, null);
} else {
view = (LinearLayout) convertView;
}
final CheckBox ch = (CheckBox) view.findViewById(R.id.toggle_item);
if (selectionMode) {
ch.setVisibility(View.VISIBLE);
ch.setChecked(selectedItems.contains(listItem));
ch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
toggleCheckbox(position, ch);
}
});
} else {
ch.setVisibility(View.GONE);
}
ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
TextView title = (TextView) view.findViewById(R.id.title);
TextView subtitle = (TextView) view.findViewById(R.id.subtitle);
imageView.setImageDrawable(listItem.getIcon());
String name = listItem.getName();
if (listItem.getSpannableName() != null) {
title.setText(listItem.getSpannableName());
} else {
title.setText(name);
}
String desc = listItem.getTypeName();
Object searchResultObject = listItem.getSearchResult().object;
if (searchResultObject instanceof AbstractPoiType) {
AbstractPoiType abstractPoiType = (AbstractPoiType) searchResultObject;
String[] synonyms = abstractPoiType.getSynonyms().split(";");
QuickSearchHelper searchHelper = app.getSearchUICore();
SearchUICore searchUICore = searchHelper.getCore();
String searchPhrase = searchUICore.getPhrase().getText(true);
SearchPhrase.NameStringMatcher nm = new SearchPhrase.NameStringMatcher(searchPhrase, CollatorStringMatcher.StringMatcherMode.CHECK_STARTS_FROM_SPACE);
if (!searchPhrase.isEmpty() && !nm.matches(abstractPoiType.getTranslation())) {
if (nm.matches(abstractPoiType.getEnTranslation())) {
desc = listItem.getTypeName() + " (" + abstractPoiType.getEnTranslation() + ")";
} else {
for (String syn : synonyms) {
if (nm.matches(syn)) {
desc = listItem.getTypeName() + " (" + syn + ")";
break;
}
}
}
}
}
boolean hasDesc = false;
if (!Algorithms.isEmpty(desc) && !desc.equals(name)) {
subtitle.setText(desc);
subtitle.setVisibility(View.VISIBLE);
hasDesc = true;
} else {
subtitle.setVisibility(View.GONE);
}
Drawable typeIcon = listItem.getTypeIcon();
ImageView group = (ImageView) view.findViewById(R.id.type_name_icon);
if (typeIcon != null && hasDesc) {
group.setImageDrawable(typeIcon);
group.setVisibility(View.VISIBLE);
} else {
group.setVisibility(View.GONE);
}
LinearLayout timeLayout = (LinearLayout) view.findViewById(R.id.time_layout);
TextView timeText = (TextView) view.findViewById(R.id.time);
ImageView timeIcon = (ImageView) view.findViewById(R.id.time_icon);
if (listItem.getSearchResult().object instanceof Amenity && ((Amenity) listItem.getSearchResult().object).getOpeningHours() != null) {
Amenity amenity = (Amenity) listItem.getSearchResult().object;
OpeningHoursParser.OpeningHours rs = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours());
if (rs != null) {
Calendar inst = Calendar.getInstance();
inst.setTimeInMillis(System.currentTimeMillis());
boolean worksNow = rs.isOpenedForTime(inst);
// 30 minutes later
inst.setTimeInMillis(System.currentTimeMillis() + 30 * 60 * 1000);
boolean worksLater = rs.isOpenedForTime(inst);
int colorId = worksNow ? worksLater ? R.color.color_ok : R.color.color_intermediate : R.color.color_warning;
timeLayout.setVisibility(View.VISIBLE);
timeIcon.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_small_time, colorId));
timeText.setTextColor(app.getResources().getColor(colorId));
String rt = rs.getCurrentRuleTime(inst);
timeText.setText(rt == null ? "" : rt);
} else {
timeLayout.setVisibility(View.GONE);
}
} else {
timeLayout.setVisibility(View.GONE);
}
updateCompassVisibility(view, listItem);
}
view.setBackgroundColor(app.getResources().getColor(app.getSettings().isLightContent() ? R.color.bg_color_light : R.color.bg_color_dark));
View divider = view.findViewById(R.id.divider);
if (divider != null) {
if (position == getCount() - 1 || getItem(position + 1).getType() == QuickSearchListItemType.HEADER || getItem(position + 1).getType() == QuickSearchListItemType.BOTTOM_SHADOW) {
divider.setVisibility(View.GONE);
} else {
divider.setVisibility(View.VISIBLE);
if (getItem(position + 1).getType() == QuickSearchListItemType.SEARCH_MORE || type == QuickSearchListItemType.SELECT_ALL) {
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp1);
p.setMargins(0, 0, 0, 0);
divider.setLayoutParams(p);
} else {
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp1);
p.setMargins(dp56, 0, 0, 0);
divider.setLayoutParams(p);
}
}
}
ViewCompat.setAccessibilityDelegate(view, accessibilityAssistant);
return view;
}
Aggregations