UI controls
Directory
SearchLayout is a component that provides an interactive search bar and list of results. It is part of both full and map versions of the SDK.
Integration
Adding SearchLayout to the layout is the same as with any other Android UI component:
<ru.dgis.sdk.directory.SearchLayout
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:dgis_pageSize="10"
app:dgis_searchType="online"
app:dgis_sortingType="relevance"
app:dgis_suggestorType="general" />
The dgis_*
attributes are for initial setup, see the documentation for SearchOptions for details.
In addition, SearchLayout
can also be created from code:
// For the example, let's create options and change the SearchType.
// Let's leave the rest of the parameters as default.
val options = SearchOptions(searchType = SearchType.Online)
val searchLayout = SearchLayout(this, options)
In addition to the configuration at creation, lifecycle configuration of parameters is also available. This is described in the next subsection.
Configuration
After creating SearchLayout, the [configureSearchEngine()](/en/android/sdk/reference/10.0/ru.dgis.sdk.directory. SearchLayout#nav-lvl1--configureSearchEngine) methods of the SearchViewConfigurator interface become available. The methods allow both changing the initial creation settings - search type, output size, etc. - and configuring other parameters such as geoposition provider, object type restrictions, etc.
val locationProvider: LocationService
val searchLayout = findViewById<SearchLayout>(R.id.search_layout)
searchLayout.configureSearchEngine { // this: SearchViewConfigurator
// Let's add LocationService to get the distance to the object, relative to the current geoposition.
setLocationProvider(LocationService)
// Let's change the maximum number of objects in the issue.
setPageSize(10)
}
Obtaining results
The addSearchViewCallback method allows you to add an instance of SearchViewCallback. Interface methods allow you to react to events occurring in SearchLayout
such as clearing the search box, completed search, etc.
searchLayout.addSearchViewCallback(object : SearchViewCallback {
// Called when the search bar is cleared.
override fun searchAborted() {
...
}
// Called when the user selects an item in the issue, which is a DirectoryObject.
override fun directoryObjectChosen(obj: DirectoryObject) {
...
}
// Called when the search has been successfully completed and the result is the following DirectoryObject list.
// The list can be empty.
override fun searchCompletedSuccessfully(items: List<DirectoryObject>) {
...
}
// Called when a search exception occurs.
override fun searchCompletedWithException(message: String) {
...
}
// Called when you click on the button to close the search. SearchLayout will be removed from the hierarchy
// regardless of whether the method is implemented.
override fun searchClosed() {
...
}
})
Both all and only the required methods can be implemented.
Theme
You can change the color scheme and some other parameters of SearchLayout by changing the theme attributes.
To change the style of the component, you must set the dgis_searchTheme
attribute, which will point the style to the theme of your application.
<resources>
<style name="AppTheme" ...>
...
<item name="dgis_searchTheme">@style/customSearchTheme</item>
...
</style>
</resources>
Available attributes:
Имя аттрибута | Описание |
---|---|
dgis_searchPrimaryBackgroundColor |
Main background color |
dgis_searchSecondaryBackgroundColor |
Additional background color |
dgis_searchIconTint |
Magnifier icon color |
dgis_searchInputActiveTextColor |
Text color |
dgis_searchInputTextSize |
Search box text size |
dgis_searchResultTitleTextSize |
Text size in the search result header |
dgis_searchResultAddressTextSize |
Text size in the search result subheading |
dgis_searchResultDistanceTextSize |
Text size in object distance |