当前位置: 首页 > news >正文

招聘网站开发兼职网页设计教程ppt封面图片

招聘网站开发兼职,网页设计教程ppt封面图片,wordpress循环插件,做海鱼的网站一、前言 在进行海外开发时候需要使用google地图#xff0c;这里对其中的地点自动补全功能开发进行记录。这里着重于代码开发#xff0c;对于key的申请和配置不予记录。 二、基础配置 app文件夹下面的build.gradle plugins {// ...id com.google.android.libraries.mapsp…一、前言 在进行海外开发时候需要使用google地图这里对其中的地点自动补全功能开发进行记录。这里着重于代码开发对于key的申请和配置不予记录。 二、基础配置 app文件夹下面的build.gradle plugins {// ...id com.google.android.libraries.mapsplatform.secrets-gradle-plugin } implementation com.google.android.libraries.places:places:3.0.0项目根目录build.gradle buildscript {dependencies {classpath com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1} }在项目级目录中打开 secrets.properties然后添加以下代码。将 YOUR_API_KEY 替换为您的 API 密钥 MAPS_API_KEYYOUR_API_KEY 在 AndroidManifest.xml 文件中定位到 com.google.android.geo.API_KEY 并按如下所示更新 android:value attribute meta-dataandroid:namecom.google.android.geo.API_KEYandroid:value${MAPS_API_KEY} /在Application中初始化 // Initialize the SDKPlaces.initialize(getApplicationContext(), apiKey);// Create a new PlacesClient instance//在实际使用的时候调用初始化时候可以不用这个PlacesClient placesClient Places.createClient(this);三、产品需求 这里需要实现一个在搜索框中输入内容然后将结果展示出来的功能。如果有内容展示内容如果没有内容显示空UI网络错误显示错误UI。删除内容后将搜索结果的UI隐藏展示另外一种UI。点击搜索结果获取地理位置的经纬度 四、编码如下 程序由Fragment、ViewModel、xml组成。为了节约文章内容只给出核心代码布局文件不再给出 SearchViewModel.kt class SearchViewModel: ViewModel(){val predictions MutableLiveDataMutableListAutocompletePrediction()val placeLiveData MutableLiveDataPlace()val errorLiveData MutableLiveDataApiException()private val cancelTokenSource CancellationTokenSource()private var placesClient: PlacesClient ? nullprivate val TAG SearchViewModelenum class QueryState{LOADING,EMPTY,NET_ERROR,SUCCESS} fun createPlaceClient(context: Context){try {placesClient Places.createClient(context)}catch (e: Exception){}}private var token: AutocompleteSessionToken ? nullfun searchCity(query: String){//参考代码: https://developers.google.com/android/reference/com/google/android/gms/tasks/CancellationToken//参考代码: https://developers.google.com/maps/documentation/places/android-sdk/place-details?hlzh-cn//参考代码: https://developers.google.com/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/net/PlacesClient//ApiException: https://developers.google.com/android/reference/com/google/android/gms/common/api/ApiExceptionif(null placesClient){errorLiveData.postValue(ApiException(Status.RESULT_INTERNAL_ERROR))return}token AutocompleteSessionToken.newInstance()val request FindAutocompletePredictionsRequest.builder().setTypesFilter(listOf(PlaceTypes.CITIES)).setSessionToken(token).setCancellationToken(cancelTokenSource.token).setQuery(query).build()placesClient?.findAutocompletePredictions(request)?.addOnSuccessListener { response: FindAutocompletePredictionsResponse - // for (prediction in response.autocompletePredictions) { // Log.i(TAG, prediction.placeId) // Log.i(TAG, prediction.getPrimaryText(null).toString()) // }predictions.postValue(response.autocompletePredictions.toMutableList())}?.addOnFailureListener { exception: Exception? -if (exception is ApiException) { // Log.e(TAG, Place not found:code-- ${exception.statusCode}--message:${exception.message})exception?.let {errorLiveData.postValue(it)}}else{errorLiveData.postValue(ApiException(Status.RESULT_INTERNAL_ERROR))}}}//搜索城市详情fun requestCityDetails(position: Int){if(null placesClient){errorLiveData.postValue(ApiException(Status.RESULT_INTERNAL_ERROR))return}val prediction predictions.value?.get(position)if(null prediction){errorLiveData.postValue(ApiException(Status.RESULT_INTERNAL_ERROR))return}val placeId prediction.placeIdval placeFields listOf(Place.Field.LAT_LNG, Place.Field.NAME)val request FetchPlaceRequest.builder(placeId, placeFields).setCancellationToken(cancelTokenSource.token).setSessionToken(token).build()placesClient?.fetchPlace(request)?.addOnSuccessListener { response: FetchPlaceResponse -val place response.place // Log.i(TAG, Place found: ${place.name}--latitude:${place.latLng?.latitude}---longitude:${place.latLng?.longitude})placeLiveData.postValue(place)}?.addOnFailureListener { exception: Exception -if (exception is ApiException) { // Log.e(TAG, Place not found: ${exception.message})exception?.let {errorLiveData.postValue(it)}}else{errorLiveData.postValue(ApiException(Status.RESULT_INTERNAL_ERROR))}}}fun cancelQuery(){cancelTokenSource.cancel()}override fun onCleared() {super.onCleared()cancelQuery()} }SearchFragment.kt class SearchFragment: Fragment(){ private val searchCityResultAdapter SearchCityResultAdapter()private val textWatch CustomTextWatch()private val handler object : Handler(Looper.getMainLooper()){override fun handleMessage(msg: Message) {super.handleMessage(msg)when(msg.what){customEditActionListener.msgAction - {val actionContent msg.obj as? CharSequence ?: returnval query actionContent.toString()if(TextUtils.isEmpty(query)){return}switchSearchUi(true)viewModel.searchCity(query)}textWatch.msgAction - {val actionContent msg.obj as? Editableif (TextUtils.isEmpty(actionContent)){switchSearchUi(false)viewModel.cancelQuery()}}}}}private fun initRecycleView(){....searchCityResultAdapter.setOnItemClickListener { _, _, position -viewModel.requestCityDetails(position)switchSearchUi(false)}} private fun initListener(){customEditActionListener.bindHandler(handler)binding.etSearchInput.setOnEditorActionListener(customEditActionListener)textWatch.bindHandler(handler)binding.etSearchInput.addTextChangedListener(textWatch)....}private fun switchSearchUi(isShowSearchUi: Boolean){if (isShowSearchUi){searchStateUi(RecommendViewModel.QueryState.LOADING)binding.nsvRecommend.visibility View.GONE}else{binding.layoutSearchResult.root.visibility View.GONEbinding.nsvRecommend.visibility View.VISIBLE}} private fun initObserver() { ... viewModel.predictions.observe(this){if (it.isEmpty()){searchStateUi(RecommendViewModel.QueryState.EMPTY)}else{searchStateUi(RecommendViewModel.QueryState.SUCCESS)searchCityResultAdapter.setNewInstance(it)}}viewModel.placeLiveData.observe(this){addCity(it)}viewModel.errorLiveData.observe(this){AddCityFailedUtils.trackLocationFailure(search,it.message.toString())Log.i(TAG, it.message ?: )if(it.status Status.RESULT_TIMEOUT){searchStateUi(RecommendViewModel.QueryState.NET_ERROR)}else{searchStateUi(RecommendViewModel.QueryState.EMPTY)}}... }//查询结果状态private fun searchStateUi(state: RecommendViewModel.QueryState){val searchResultBinding binding.layoutSearchResultsearchResultBinding.root.visibility View.VISIBLEwhen(state){RecommendViewModel.QueryState.LOADING - {searchResultBinding.lottieLoading.visibility View.VISIBLEsearchResultBinding.rvSearchResult.visibility View.GONEsearchResultBinding.ivError.visibility View.GONE}RecommendViewModel.QueryState.EMPTY - {searchResultBinding.ivError.setImageResource(R.drawable.no_positioning)searchResultBinding.lottieLoading.visibility View.GONEsearchResultBinding.rvSearchResult.visibility View.GONEsearchResultBinding.ivError.visibility View.VISIBLE}RecommendViewModel.QueryState.NET_ERROR - {searchResultBinding.ivError.setImageResource(R.drawable.no_network)searchResultBinding.lottieLoading.visibility View.GONEsearchResultBinding.rvSearchResult.visibility View.GONEsearchResultBinding.ivError.visibility View.VISIBLE}RecommendViewModel.QueryState.SUCCESS - {searchResultBinding.lottieLoading.visibility View.VISIBLEsearchResultBinding.rvSearchResult.visibility View.GONEsearchResultBinding.ivError.visibility View.GONE}else - {}}}override fun onDestroy() {super.onDestroy()binding.etSearchInput.removeTextChangedListener(textWatch)handler.removeCallbacksAndMessages(null)}inner class CustomEditTextActionListener: TextView.OnEditorActionListener{private var mHandler: Handler ? nullval msgAction 10fun bindHandler(handler: Handler){mHandler handler}override fun onEditorAction(v: TextView, actionId: Int, event: KeyEvent?): Boolean {if(actionId EditorInfo.IME_ACTION_SEARCH){hiddenImme(v)val message Message.obtain()message.what msgActionmessage.obj v.textmHandler?.sendMessage(message)return true}return false}private fun hiddenImme(view: View){//隐藏软键盘val imm view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManagerif (imm.isActive) {imm.hideSoftInputFromWindow(view.applicationWindowToken, 0)}}}inner class CustomTextWatch: TextWatcher{private var mHandler: Handler ? nullval msgAction 11fun bindHandler(handler: Handler){mHandler handler}override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}override fun afterTextChanged(s: Editable?) {val message Message.obtain()message.what msgActionmessage.obj smHandler?.sendMessage(message)}} }四、参考链接 Place Sdk for Android:CancellationTokenPlacesClientApiExceptionplace-details
http://www.zqtcl.cn/news/295664/

相关文章:

  • 哪些网站有搜索引擎作弊的社群营销平台有哪些
  • 建地方的网站前景苏州做视频网站广告公司
  • 制作网站的主题海口网站自助建站
  • dede二手车网站源码网络工程师
  • 吴桥网站新网站优化怎么做
  • 做网站要求什么条件0资本建设网站
  • 免费做网站排名洛阳软件开发公司有哪些
  • 网站搜索优化方法东莞seo全网营销
  • 广州微网站建设哪家好wordpress怎样将小工具放到左侧
  • 汕头网站搜索优化嘉兴网络项目建站公司
  • 怎么查询网站是什么时候做的网站app的意义
  • 曹妃甸网站建设合肥的房产网站建设
  • 怎么做网站前台二级区域网站名
  • 服务器租用相关网站一个空间怎么放两个网站吗
  • 每个城市建设规划在哪个网站南宁seo怎么做优化团队
  • 做资讯类网站ccd设计公司官网
  • 写作网站5妙不写就删除抚州建设网站
  • 沙田网站建设公司网站风格设计原则
  • 安徽省建设监理网站黑群晖可以做网站吗
  • 手机百度seo快速排名搜索引擎优化目标
  • 长春 房地产网站建设网站建设 合同
  • 电商专业培训网站建设wordpress内置播放器
  • 创意网站设计模板点击器免费版
  • 做的不错的h5高端网站网站是怎么优化的
  • 淄博做网站优化佛山 做网站公司
  • 设计网站的步骤网站开发怎么学习
  • 提供网站技术国内外电子政务网站建设差距
  • 阜新建设网站物流网站建设的小结
  • 个人可以网站备案吗建设多用户网站
  • 平面设计素材库淄博网站优化价格