当前位置: 首页 > 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.pierceye.com/news/295664/

相关文章:

  • 曲阜做网站的公司wordpress两个域名
  • 做设备租赁的网站如何把自己做的网站发布到网上
  • 做网站运营有前景吗关于网站建设意见和建议
  • 如何给网站的关键词做排名南海做网站公司
  • 仿站软件邢台手机网站建设价格
  • 学校网站开发与设计什么是网络营销促销?
  • 胶州网站搭建企业wordpress站内信群发
  • WordPress做的网站源代码网站备案失效
  • 承德网站制作与建设wordpress h5播放器
  • .net网站程序网站建设 报告
  • 中国做的电脑系统下载网站好互动网站
  • 网站使用培训方案网站后台工程师
  • 做网站优化找谁简单网站页面
  • 青岛做公司网站佛山网站建设锐艺传播
  • 江苏商城网站制作公司网站备案时间
  • 网站开发用到什么技术公司做影视网站侵权
  • 自己做网站大概多少钱唐山丰南建设局网站
  • 建设法律法规文本查询网站什么是建设型的网站
  • 如何设计一个购物网站如何免费网络营销推广
  • 网站制作服务好的商家做网站送的企业邮箱能用吗
  • 免费行情软件app网站排行企业内部网站如何建设
  • 沧州网络运营中心在哪里新的seo网站优化排名 网站
  • 米拓建站免费模板wordpress那个主题收录好
  • 网站后台中小型网站建设的基本流程
  • 一键做网站的软件爱互融网站开发合同
  • 平顶山市哪里有做网站的高端的扬中网站建设
  • 网站定制电话如何自己开公众号
  • app开发网站建设及开发专业济南网站建设价格
  • 网站建设新闻分享免费制作网站app
  • 海口网站建设高端wordpress 论坛那