use of com.here.android.mpa.search.AutoSuggest 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.AutoSuggest in project here-android-sdk-examples by heremaps.
the class MapFragmentView method doSearch.
private void doSearch(String query) {
setSearchMode(true);
/*
Creates new TextAutoSuggestionRequest with current map position as search center
and selected collection size with applied filters and chosen locale.
For more details how to use TextAutoSuggestionRequest
please see documentation for HERE Mobile SDK for Android.
*/
TextAutoSuggestionRequest textAutoSuggestionRequest = new TextAutoSuggestionRequest(query);
textAutoSuggestionRequest.setSearchCenter(m_map.getCenter());
textAutoSuggestionRequest.setCollectionSize(Integer.parseInt(m_collectionSizeTextView.getText().toString()));
applyResultFiltersToRequest(textAutoSuggestionRequest);
Locale locale = getSelectedLocale();
if (locale != null) {
textAutoSuggestionRequest.setLocale(locale);
}
String countryCode = getSelectedCountryCode();
if (!TextUtils.isEmpty(countryCode)) {
AddressFilter addressFilter = new AddressFilter();
// Also available filtering by state code, county, district, city and zip code
addressFilter.setCountryCode(countryCode);
textAutoSuggestionRequest.setAddressFilter(addressFilter);
}
/*
The textAutoSuggestionRequest returns its results to non-UI thread.
So, we have to pass the UI update with returned results to UI thread.
*/
textAutoSuggestionRequest.execute(new ResultListener<List<AutoSuggest>>() {
@Override
public void onCompleted(final List<AutoSuggest> autoSuggests, ErrorCode errorCode) {
if (errorCode == errorCode.NONE) {
processSearchResults(autoSuggests);
} else {
handleError(errorCode);
}
}
});
}
use of com.here.android.mpa.search.AutoSuggest 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;
}
use of com.here.android.mpa.search.AutoSuggest in project here-android-sdk-examples by heremaps.
the class MapFragmentView method initControls.
private void initControls() {
m_searchView = m_activity.findViewById(R.id.search);
m_searchView.setOnQueryTextListener(m_searchListener);
m_localeSpinner = m_activity.findViewById(R.id.localeSpinner);
m_collectionSizeTextView = m_activity.findViewById(R.id.editText_collectionSize);
ArrayAdapter<CharSequence> localeAdapter = new ArrayAdapter<CharSequence>(m_activity, android.R.layout.simple_spinner_item, AVAILABLE_LOCALES);
localeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
m_localeSpinner.setAdapter(localeAdapter);
m_countryCodeSpinner = m_activity.findViewById(R.id.countryCodeSpinner);
ArrayAdapter<CharSequence> countryCodeAdapter = new ArrayAdapter<CharSequence>(m_activity, android.R.layout.simple_spinner_item, COUNTRY_CODES);
countryCodeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
m_countryCodeSpinner.setAdapter(countryCodeAdapter);
m_resultsListView = m_activity.findViewById(R.id.resultsListViev);
m_autoSuggestAdapter = new AutoSuggestAdapter(m_activity, android.R.layout.simple_list_item_1, m_autoSuggests);
m_resultsListView.setAdapter(m_autoSuggestAdapter);
m_resultsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
AutoSuggest item = (AutoSuggest) parent.getItemAtPosition(position);
handleSelectedAutoSuggest(item);
}
});
// Initialize filter options view
LinearLayout linearLayout = m_activity.findViewById(R.id.filterOptionsContainer);
m_filterOptionsContainer = new LinearLayout(m_activity);
linearLayout.setOrientation(LinearLayout.VERTICAL);
m_useFilteringCheckbox = new CheckBox(m_activity);
m_useFilteringCheckbox.setText("Use filter");
m_useFilteringCheckbox.setChecked(false);
m_useFilteringCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
m_filterOptionsContainer.setVisibility(isChecked ? View.VISIBLE : GONE);
}
});
m_filterOptionsContainer.setVisibility(GONE);
m_filterOptionsContainer.setOrientation(LinearLayout.VERTICAL);
m_filterOptionsContainer.setPadding(50, 0, 0, 0);
TextAutoSuggestionRequest.AutoSuggestFilterType[] filterOptions = TextAutoSuggestionRequest.AutoSuggestFilterType.values();
for (TextAutoSuggestionRequest.AutoSuggestFilterType filterOption : filterOptions) {
CheckBox curCB = new CheckBox(m_activity);
curCB.setChecked(false);
curCB.setText(filterOption.toString());
m_filterOptionsContainer.addView(curCB);
}
linearLayout.addView(m_useFilteringCheckbox);
linearLayout.addView(m_filterOptionsContainer);
}
Aggregations