use of com.here.android.mpa.search.AutoSuggestSearch in project here-android-sdk-examples by heremaps.
the class MapFragmentView method handleSelectedAutoSuggest.
private void handleSelectedAutoSuggest(AutoSuggest autoSuggest) {
int collectionSize = Integer.parseInt(m_collectionSizeTextView.getText().toString());
switch(autoSuggest.getType()) {
case PLACE:
/*
Gets initialized PlaceRequest with location context that allows retrieving details
about the place on the selected location.
*/
AutoSuggestPlace autoSuggestPlace = (AutoSuggestPlace) autoSuggest;
PlaceRequest detailsRequest = autoSuggestPlace.getPlaceDetailsRequest();
detailsRequest.execute(new ResultListener<Place>() {
@Override
public void onCompleted(Place place, ErrorCode errorCode) {
if (errorCode == ErrorCode.NONE) {
handlePlace(place);
} else {
handleError(errorCode);
}
}
});
break;
case SEARCH:
/*
Gets initialized AutoSuggestSearch with location context that allows retrieving
DiscoveryRequest for further processing as it is described in
the official documentation.
Some example of how to handle DiscoveryResultPage you can see in
com.here.android.example.autosuggest.ResultListActivity
*/
AutoSuggestSearch autoSuggestSearch = (AutoSuggestSearch) autoSuggest;
DiscoveryRequest discoverRequest = autoSuggestSearch.getSuggestedSearchRequest();
discoverRequest.setCollectionSize(collectionSize);
discoverRequest.execute(new ResultListener<DiscoveryResultPage>() {
@Override
public void onCompleted(DiscoveryResultPage discoveryResultPage, ErrorCode errorCode) {
if (errorCode == ErrorCode.NONE) {
s_discoverResultList = discoveryResultPage.getItems();
Intent intent = new Intent(m_activity, ResultListActivity.class);
m_activity.startActivity(intent);
} else {
handleError(errorCode);
}
}
});
break;
case QUERY:
/*
Gets TextAutoSuggestionRequest with suggested autocomplete that retrieves
the collection of AutoSuggest objects which represent suggested.
*/
final AutoSuggestQuery autoSuggestQuery = (AutoSuggestQuery) autoSuggest;
TextAutoSuggestionRequest queryReqest = autoSuggestQuery.getRequest(getSelectedLocale());
queryReqest.setCollectionSize(collectionSize);
queryReqest.execute(new ResultListener<List<AutoSuggest>>() {
@Override
public void onCompleted(List<AutoSuggest> autoSuggests, ErrorCode errorCode) {
if (errorCode == ErrorCode.NONE) {
processSearchResults(autoSuggests);
m_searchView.setOnQueryTextListener(null);
m_searchView.setQuery(autoSuggestQuery.getQueryCompletion(), false);
m_searchView.setOnQueryTextListener(m_searchListener);
} else {
handleError(errorCode);
}
}
});
break;
// Do nothing.
case UNKNOWN:
default:
}
}
use of com.here.android.mpa.search.AutoSuggestSearch in project here-android-sdk-examples by heremaps.
the class AutoSuggestAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
AutoSuggest autoSuggest = getItem(position);
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.result_autosuggest_list_item, parent, false);
}
TextView tv = null;
tv = convertView.findViewById(R.id.header);
tv.setBackgroundColor(Color.DKGRAY);
// set title
tv = convertView.findViewById(R.id.title);
tv.setText(autoSuggest.getTitle());
// set highlightedTitle
tv = convertView.findViewById(R.id.highlightedTitle);
tv.setText(HtmlCompat.fromHtml(autoSuggest.getHighlightedTitle(), HtmlCompat.FROM_HTML_MODE_LEGACY));
// set request URL
tv = convertView.findViewById(R.id.url);
tv.setText("Url: " + autoSuggest.getUrl());
// set Type
tv = convertView.findViewById(R.id.type);
tv.setText("Type: " + autoSuggest.getType().name());
switch(autoSuggest.getType()) {
case PLACE:
AutoSuggestPlace autoSuggestPlace = (AutoSuggestPlace) autoSuggest;
// set vicinity
tv = convertView.findViewById(R.id.vicinity);
tv.setVisibility(View.VISIBLE);
if (autoSuggestPlace.getVicinity() != null) {
tv.setText("Vicinity: " + autoSuggestPlace.getVicinity());
} else {
tv.setText("Vicinity: nil");
}
// set category
tv = convertView.findViewById(R.id.category);
tv.setVisibility(View.VISIBLE);
if (autoSuggestPlace.getCategory() != null) {
tv.setText("Category: " + autoSuggestPlace.getCategory());
} else {
tv.setText("Category: nil");
}
// set position
tv = convertView.findViewById(R.id.position);
tv.setVisibility(View.VISIBLE);
if (autoSuggestPlace.getPosition() != null) {
tv.setText("Position: " + autoSuggestPlace.getPosition().toString());
} else {
tv.setText("Position: nil");
}
// set boundaryBox
tv = convertView.findViewById(R.id.boundaryBox);
tv.setVisibility(View.VISIBLE);
if (autoSuggestPlace.getBoundingBox() != null) {
tv.setText("BoundaryBox: " + ((AutoSuggestPlace) autoSuggest).getBoundingBox().toString());
} else {
tv.setText("BoundaryBox: nil");
}
break;
case QUERY:
AutoSuggestQuery autoSuggestQuery = (AutoSuggestQuery) autoSuggest;
// set completion
tv = convertView.findViewById(R.id.vicinity);
tv.setText("Completion: " + autoSuggestQuery.getQueryCompletion());
// set category
tv = convertView.findViewById(R.id.category);
tv.setVisibility(View.GONE);
// set position
tv = convertView.findViewById(R.id.position);
tv.setVisibility(View.GONE);
// set boundaryBox
tv = convertView.findViewById(R.id.boundaryBox);
tv.setVisibility(View.GONE);
break;
case SEARCH:
AutoSuggestSearch autoSuggestSearch = (AutoSuggestSearch) autoSuggest;
// set vicinity
tv = convertView.findViewById(R.id.vicinity);
tv.setVisibility(View.GONE);
// set category
tv = convertView.findViewById(R.id.category);
tv.setVisibility(View.VISIBLE);
if (autoSuggestSearch.getCategory() != null) {
tv.setText("Category: " + autoSuggestSearch.getCategory());
} else {
tv.setText("Category: nil");
}
// set position
tv = convertView.findViewById(R.id.position);
tv.setVisibility(View.VISIBLE);
if (autoSuggestSearch.getPosition() != null) {
tv.setText("Position: " + autoSuggestSearch.getPosition().toString());
} else {
tv.setText("Position: nil");
}
// set boundaryBox
tv = convertView.findViewById(R.id.boundaryBox);
tv.setVisibility(View.VISIBLE);
if (autoSuggestSearch.getBoundingBox() != null) {
tv.setText("BoundaryBox: " + autoSuggestSearch.getBoundingBox().toString());
} else {
tv.setText("BoundaryBox: nil");
}
break;
default:
}
return convertView;
}
Aggregations