From 13b3e727a6c252887cea8aa6b0856c967f036731 Mon Sep 17 00:00:00 2001 From: zuoxiao <470321431@qq.com> Date: 星期五, 20 九月 2024 10:55:39 +0800 Subject: [PATCH] 登录功能、地图功能、首页table --- app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java | 81 ++++++++++++++++++++++++++++++++++------ 1 files changed, 68 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java b/app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java index d2bff28..e4c7378 100644 --- a/app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java +++ b/app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java @@ -1,7 +1,6 @@ package com.dayu.pipirrapp.fragment; import android.content.Context; -import android.content.Intent; import android.location.LocationManager; import android.os.Bundle; import android.util.Log; @@ -18,17 +17,28 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.dayu.pipirrapp.MyApplication; +import com.dayu.pipirrapp.bean.db.CenterPointBean; +import com.dayu.pipirrapp.bean.net.CenterPointResult; +import com.dayu.pipirrapp.dao.DaoSingleton; import com.dayu.pipirrapp.databinding.FragmentMapBinding; import com.dayu.pipirrapp.js.MyWebViewInterface; +import com.dayu.pipirrapp.net.ApiManager; +import com.dayu.pipirrapp.net.BaseResponse; +import com.dayu.pipirrapp.net.Constants; +import com.dayu.pipirrapp.net.subscribers.SubscriberListener; import com.dayu.pipirrapp.observer.MapFragmenObserver; -import com.dayu.pipirrapp.service.MyLocationService; +import com.dayu.pipirrapp.utils.CommonData; import com.dayu.pipirrapp.utils.MapJpgUtils; import com.dayu.pipirrapp.utils.MyLog; +import com.dayu.pipirrapp.utils.ToastUtil; import com.dayu.pipirrapp.utils.WebViewUtils; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.util.HashMap; +import java.util.Map; import java.util.Random; /** @@ -38,11 +48,14 @@ * 澶囨敞锛氬湴鍥鹃〉 */ public class MapFragment extends BaseFragment { + static String TAG = "MapFragment"; FragmentMapBinding binding; + //瀹氫綅鐩稿叧 LocationManager locationManager; WebView mWebView; + CenterPointBean centerPointBean; @Override public void onAttach(@NonNull Context context) { @@ -66,14 +79,22 @@ MyWebViewInterface myWebViewInterface = new MyWebViewInterface(MapFragment.this); mWebView.addJavascriptInterface(myWebViewInterface, "Android"); mWebView.loadUrl("file:///android_asset/index.html"); - + getCenterPoint(); initView(); //寮�鍚畾浣� - Intent location = new Intent(this.getActivity(), MyLocationService.class); - location.putExtra("isSingle", false); - this.getActivity().startService(location); +// Intent location = new Intent(this.getActivity(), MyLocationService.class); +// location.putExtra("isSingle", false); +// this.getActivity().startService(location); return binding.getRoot(); } + + private void initData() { + centerPointBean = DaoSingleton.getInstance(MapFragment.this.getContext()).centerPointDao().findFirst(); + if (centerPointBean!=null){ + + } + } + /** * 娣诲姞鏍囨敞鐐� @@ -144,22 +165,31 @@ }); mWebView.setWebViewClient(new WebViewClient() { @Override - public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { + public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { String url = request.getUrl().toString(); - // 妫�鏌ユ湰鍦扮紦瀛� - File cachedTile = MapJpgUtils.getInsatance(MapFragment.this.getContext()).getCachedTile(url); - if (cachedTile != null && cachedTile.exists()) { - // 鍒ゆ柇缂撳瓨鏄惁杩囨湡 - if (!MapJpgUtils.getInsatance(MapFragment.this.getContext()).isCacheExpired(cachedTile)) { + //鍒ゆ柇褰撳墠鏄惁涓哄姞杞界摝鐗� + if (MapJpgUtils.getInsatance().isTianDiTuTileRequest(url)) { + String androidUrl = url.replace(CommonData.webKey, CommonData.androidKey); + // 妫�鏌ユ湰鍦扮紦瀛� + File cachedTile = MapJpgUtils.getInsatance().getCachedTile(androidUrl); + if (cachedTile != null && cachedTile.exists()) { + Log.i(TAG, "鏈湴缂撳瓨>>>" + androidUrl); +// if (MapJpgUtils.getInsatance().validateImageFile(androidUrl,request.)) + // 鍒ゆ柇缂撳瓨鏄惁杩囨湡 +// if (!MapJpgUtils.getInsatance(MapFragment.this.getContext()).isCacheExpired(cachedTile)) { try { // 浠庣紦瀛樺姞杞界摝鐗� return new WebResourceResponse("image/jpg", "utf-8", new FileInputStream(cachedTile)); } catch (FileNotFoundException e) { e.printStackTrace(); } +// } + } else { + //涓嬭浇鐡︾墖 + ApiManager.getInstance().donwLoadTile(androidUrl); } + Log.i(TAG, "鍦ㄧ嚎鍔犺浇>>>" + url); } - return super.shouldInterceptRequest(view, request); } @@ -194,6 +224,31 @@ } + /** + * 鑾峰彇鍦板浘涓績鐐� + */ + private void getCenterPoint() { + Map<String, Object> data = new HashMap<>(); + data.put("token", MyApplication.myApplication.token); + + ApiManager.getInstance().requestGet(this.getContext(), Constants.SUCCESS + "8080/base/dict_item/map_center", CenterPointResult.class, data, new SubscriberListener<BaseResponse<CenterPointResult>>() { + @Override + public void onNext(BaseResponse<CenterPointResult> t) { + if (t.isSuccess()) { + if (centerPointBean == null) { + centerPointBean = new CenterPointBean(); + } + centerPointBean.setLat(t.getContent().getLat()); + centerPointBean.setLng(t.getContent().getLng()); + DaoSingleton.getInstance(MapFragment.this.getContext()).centerPointDao().update(centerPointBean); + } else { + ToastUtil.showToast(MapFragment.this.getContext(), t.getMsg()); + } + } + + }); + } + public void closeWaterIntakeDetail() { binding.bottomLL.setVisibility(View.GONE); } -- Gitblit v1.8.0