This library provides a fragment similar to the Google Places AutocompleteSupportFragment, for the HMS Site kit Shows suggestions when searching for places
WARNING: Before you can start using the HMS Platform APIs and SDKs, you must register your app in the AppGallery and configure your project, this step cannot be skipped.
See configuration Instructions.
add jitpack repo to your project level build.gradle
file:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
add the library to your app level 'build.bradle' file:
dependencies {
implementation 'com.github.megaacheyounes:siteautocomoplete:1.0.5'
}
see MainActivity and MainActivityJava for complete example
add the fragment tag with the name attribute:
<fragment
android:id="@+id/fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.megaache.siteautocomplete.SiteAutocompleteFragment">
</fragment>
Initialize the fragment:
val autocompleteFragment = supportFragmentManager.findFragmentById(R.id.fragment) as SiteAutocompleteFragment
declare the fragment container:
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</FrameLayout>
then add SiteAutocompleteFragment
fragment dynamically using the supportFragmentManager
:
val autocompleteFragment = SiteAutocompleteFragment()
supportFragmentManager.beginTransaction().replace(R.id.fragment_container, fragment)
.commit()
supportFragmentManager.executePendingTransactions()
- Fullscreen mode:
autocompleteFragment.setActivityMode(SiteAutocompleteMode.FULLSCREEN)
- Overlay mode:
autocompleteFragment.setActivityMode(SiteAutocompleteMode.OVERLAY)
autocompleteFragment.setOnSiteSelectListener(
object : SiteSelectionListener {
override fun onSiteSelected(site: Site) {
Log.d("onSiteSelected", site.name)
}
override fun onError(error: Error) {
Log.d("onError", error.toString())
}
}
)
if you call this method, when the user select a site (place), the name and the address of that place will replace the placeholder "search sites..." in search view (autocomplete EditText ), if false passed then only the name of the selected site will be shown
autocompleteFragment.showSelectedSiteOnSearchView(true)
The fragment supports 8 languages: English, Arabic, Chinese, French, Hindi, German, Russian, Spanish
To run the example app you must create an app in huawei console, then add the config file 'agconnect-config.json' into the project and update the package name according to package name in config file
All kinds of contributions are welcome
learn more about HMS: here
Copyright (C) 2020 Younes Megaache
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.