From 5373acaa80c7fc761df835078a71c358b19958f7 Mon Sep 17 00:00:00 2001 From: yezhiqiu <983577727@qq.com> Date: Thu, 5 Feb 2026 15:31:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8E=86=E5=8F=B2=E8=BD=A8?= =?UTF-8?q?=E8=BF=B9=E6=8B=96=E5=8A=A8=E6=BB=9A=E5=8A=A8=E6=9D=A1=E5=AE=A0?= =?UTF-8?q?=E7=89=A9=E5=A4=B4=E5=83=8F=E4=B8=8D=E4=BC=9A=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E5=9B=9E=E5=88=B0=E5=B1=8F=E5=B9=95=E4=B8=AD=E5=BF=83bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compile-file-map.properties | 2 +- .../tracker/ui/common/map/HomeMapCommon.kt | 194 ----------- .../ui/fragment/data/RouteV2Fragment.kt | 8 - .../map/googlemap/BaseGoogleMapFragment.kt | 2 +- .../googlemap/HistoryDataGoogleMapFragment.kt | 10 +- .../map/googlemap/HomeMapGoogleMapFragment.kt | 313 ------------------ 6 files changed, 9 insertions(+), 520 deletions(-) delete mode 100644 app/src/main/java/com/abbidot/tracker/ui/common/map/HomeMapCommon.kt delete mode 100644 app/src/main/java/com/abbidot/tracker/ui/fragment/map/googlemap/HomeMapGoogleMapFragment.kt diff --git a/FastBleLib/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties b/FastBleLib/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties index 54e2e3e..49037e6 100644 --- a/FastBleLib/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +++ b/FastBleLib/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties @@ -1 +1 @@ -#Wed Feb 04 14:33:32 CST 2026 +#Thu Feb 05 15:21:25 CST 2026 diff --git a/app/src/main/java/com/abbidot/tracker/ui/common/map/HomeMapCommon.kt b/app/src/main/java/com/abbidot/tracker/ui/common/map/HomeMapCommon.kt deleted file mode 100644 index 271e72c..0000000 --- a/app/src/main/java/com/abbidot/tracker/ui/common/map/HomeMapCommon.kt +++ /dev/null @@ -1,194 +0,0 @@ -package com.abbidot.tracker.ui.common.map - -import android.content.Context -import androidx.fragment.app.Fragment -import com.abbidot.baselibrary.constant.MMKVKey -import com.abbidot.baselibrary.util.AppUtils -import com.abbidot.baselibrary.util.MMKVUtil -import com.abbidot.tracker.base.BaseMapCommon -import com.abbidot.tracker.bean.HistoryDataBean -import com.abbidot.tracker.bean.MapDeviceBean -import com.abbidot.tracker.constant.ConstantInt -import com.abbidot.tracker.ui.fragment.map.baidumap.HomeMapBaiduMapFragment -import com.abbidot.tracker.ui.fragment.map.googlemap.HomeMapGoogleMapFragment -import com.abbidot.tracker.widget.MapDeviceNetView -import com.abbidot.tracker.widget.MapMarkerInfoView -import com.google.android.gms.maps.model.LatLng -import javax.inject.Inject - -/** - *Created by .yzq on 2022/7/5/005. - * @link - * @description: - */ -class HomeMapCommon @Inject constructor() : BaseMapCommon() { - - private var mHomeMapGoogleMapFragment: HomeMapGoogleMapFragment? = null - private var mHomeMapBaiduMapFragment: HomeMapBaiduMapFragment? = null - - fun getMapFragment( - context: Context, - markerInfoView: MapMarkerInfoView, - mapDeviceNetView: MapDeviceNetView, - mapLoadOk: () -> Unit - ): Fragment { - return if (AppUtils.isChina(AppUtils.SWITCH_MAP_TYPE)) { - mHomeMapBaiduMapFragment = HomeMapBaiduMapFragment.newInstance(context, mapLoadOk) - mHomeMapBaiduMapFragment!! - } else { - mHomeMapGoogleMapFragment = HomeMapGoogleMapFragment.newInstance( - context, markerInfoView, mapDeviceNetView, mapLoadOk - ) - mHomeMapGoogleMapFragment!! - } - } - - fun setMapDeviceBean(mapDeviceBean: MapDeviceBean?) { - if (null != mHomeMapBaiduMapFragment) { - mHomeMapBaiduMapFragment!!.setMapDeviceBean(mapDeviceBean) - } else if (null != mHomeMapGoogleMapFragment) { - mHomeMapGoogleMapFragment!!.setMapDeviceBean(mapDeviceBean) - } - } - - /** - * 开始每隔几秒刷新用户位置 - */ - fun startRefreshUserLocation() { - if (isMapLoadOk()) startRefreshUserLocation( - mHomeMapBaiduMapFragment, mHomeMapGoogleMapFragment - ) - } - - /** - * 获取宠物反编译好的位置信息 - */ - fun getDecPetAddressData(): HistoryDataBean? { - if (null != mHomeMapBaiduMapFragment) { - return mHomeMapBaiduMapFragment!!.mDecPetAddressData - } else if (null != mHomeMapGoogleMapFragment) { - return mHomeMapGoogleMapFragment!!.mDecPetAddressData - } - return null - } - - fun clearMarker() { - if (null != mHomeMapBaiduMapFragment) { - mHomeMapBaiduMapFragment!!.mBaiduMap?.clear() - } else if (null != mHomeMapGoogleMapFragment) { - mHomeMapGoogleMapFragment!!.clearAllMarker() - } - } - - fun refreshPetCurrentLocation(latitude: Double, longitude: Double, isMoveCamera: Boolean) { - if (null != mHomeMapBaiduMapFragment) { - mHomeMapBaiduMapFragment?.apply { - refreshPetCurrentLocation( - latitude, longitude, isMoveCamera - ) - } - } else if (null != mHomeMapGoogleMapFragment) { - MMKVUtil.putDouble(MMKVKey.MapShowDefaultLat, latitude) - MMKVUtil.putDouble(MMKVKey.MapShowDefaultLon, longitude) - mHomeMapGoogleMapFragment?.apply { - refreshPetCurrentLocation( - LatLng(latitude, longitude), needMoveCamera = isMoveCamera - ) - } - } - } - - /** - * 重新设置宠物头像 - */ - fun setPetHeadIcon(imageUrl: String, petType: Int) { - if (null != mHomeMapBaiduMapFragment) { - mHomeMapBaiduMapFragment!!.setPetHeadIconUrl(imageUrl) - } else if (null != mHomeMapGoogleMapFragment) { - mHomeMapGoogleMapFragment!!.setPetHeadIconUrl(imageUrl, petType) - } - } - - /** - * 地图是否加载好了,准备好了 - */ - fun isMapLoadOk() = isMapLoadOk(mHomeMapBaiduMapFragment, mHomeMapGoogleMapFragment) - - /** - * 切换地图类型 - */ - fun switchSatelliteAndNormalMapType() { - switchSatelliteAndNormalMapType(mHomeMapBaiduMapFragment, mHomeMapGoogleMapFragment) - } - - /** - * 切换用户和宠物的位置居中显示 - */ - fun switchShowLocation(@ConstantInt type: Int) { - switchShowLocationType(type, mHomeMapBaiduMapFragment, mHomeMapGoogleMapFragment) - } - - /** - * 画轨迹线 - */ - fun addTrackLine(latitude: Double, longitude: Double) { - if (null != mHomeMapBaiduMapFragment) { - mHomeMapBaiduMapFragment!!.addLine(latitude, longitude) - } else if (null != mHomeMapGoogleMapFragment) { - mHomeMapGoogleMapFragment!!.addLine(LatLng(latitude, longitude)) - } - } - - /** - * 画轨迹线 - */ - fun addTrackLines(trackList: MutableList) { - if (null != mHomeMapBaiduMapFragment) { - } else if (null != mHomeMapGoogleMapFragment) { - mHomeMapGoogleMapFragment!!.addLines(trackList) - } - } - - /** - * 计算用户和宠物的距离 - */ - fun getUserAndPetDistance(): Double { - var distance = 0.0 - if (null != mHomeMapBaiduMapFragment) { - distance = mHomeMapBaiduMapFragment!!.getUserAndPetDistance() - } else if (null != mHomeMapGoogleMapFragment) { - distance = mHomeMapGoogleMapFragment!!.getUserAndPetDistance() - } - return distance - } - - /** - * 开始水波纹动画 - */ - fun startRippleCircleAnim() { - if (null != mHomeMapBaiduMapFragment) { - } else if (null != mHomeMapGoogleMapFragment) { - mHomeMapGoogleMapFragment!!.startRippleCircleAnim() - } - } - - fun greenRippleCircleAnim() { - mHomeMapGoogleMapFragment?.greenRippleCircleAnim() - } - - fun setMarkerInfoViewOffset() { - if (null != mHomeMapBaiduMapFragment) { - } else if (null != mHomeMapGoogleMapFragment) { - mHomeMapGoogleMapFragment!!.setMarkerInfoViewOffset() - } - } - -// fun getAddressShowMarkerInfoWindow(historyDataBean: HistoryDataBean) { -// if (null != mHomeMapBaiduMapFragment) { -// mHomeMapBaiduMapFragment!!.showMarkerInfoWindow(historyDataBean) -// } else if (null != mHomeMapGoogleMapFragment) { -// mHomeMapGoogleMapFragment!!.showMarkerInfoWindow(historyDataBean) -// } -// } - -} \ No newline at end of file diff --git a/app/src/main/java/com/abbidot/tracker/ui/fragment/data/RouteV2Fragment.kt b/app/src/main/java/com/abbidot/tracker/ui/fragment/data/RouteV2Fragment.kt index 6135faf..e19c46f 100644 --- a/app/src/main/java/com/abbidot/tracker/ui/fragment/data/RouteV2Fragment.kt +++ b/app/src/main/java/com/abbidot/tracker/ui/fragment/data/RouteV2Fragment.kt @@ -180,15 +180,7 @@ class RouteV2Fragment : BaseFragment(FragmentRouteV2Bind } override fun onStopChanged(progress: Int) { -// val historyDataBean = mHistoryDataList[progress] - -// val address = historyDataBean.address mHistoryDataMapCommon.slideStopChanged(progress) -// if (TextUtils.isEmpty(address)) { -// mHistoryDataMapCommon.slideStopChanged(progress) -// } else { -// mHistoryDataMapCommon.showInfoWindow(historyDataBean) -// } } }) diff --git a/app/src/main/java/com/abbidot/tracker/ui/fragment/map/googlemap/BaseGoogleMapFragment.kt b/app/src/main/java/com/abbidot/tracker/ui/fragment/map/googlemap/BaseGoogleMapFragment.kt index c27aa11..6cec842 100644 --- a/app/src/main/java/com/abbidot/tracker/ui/fragment/map/googlemap/BaseGoogleMapFragment.kt +++ b/app/src/main/java/com/abbidot/tracker/ui/fragment/map/googlemap/BaseGoogleMapFragment.kt @@ -87,7 +87,7 @@ abstract class BaseGoogleMapFragment : private var mGoogleMapZoom = 17f //地图摄像机移动动画时间 毫秒 - private val mAnimMoveDurationMs = 1000 + private val mAnimMoveDurationMs = 800 //自定显示宠物头像地点信息图层 var mMarker: Marker? = null diff --git a/app/src/main/java/com/abbidot/tracker/ui/fragment/map/googlemap/HistoryDataGoogleMapFragment.kt b/app/src/main/java/com/abbidot/tracker/ui/fragment/map/googlemap/HistoryDataGoogleMapFragment.kt index e77bd02..51431b7 100644 --- a/app/src/main/java/com/abbidot/tracker/ui/fragment/map/googlemap/HistoryDataGoogleMapFragment.kt +++ b/app/src/main/java/com/abbidot/tracker/ui/fragment/map/googlemap/HistoryDataGoogleMapFragment.kt @@ -92,6 +92,10 @@ class HistoryDataGoogleMapFragment : BaseGoogleMapFragment() { //点击地图任意地方都不消失自定义头部地点布局 googleMap.apply { setOnCameraMoveListener { + //监听地图放大缩小操作 + if (getGoogleMapZoom() != cameraPosition.zoom) { + setGoogleMapZoom(cameraPosition.zoom) + } mCurLatLng?.let { if (mMarkerInfoView.isVisible) setMarkerInfoViewOffset(mMarkerInfoView, it) } @@ -195,9 +199,9 @@ class HistoryDataGoogleMapFragment : BaseGoogleMapFragment() { */ fun slideStopChanged(progress: Int) { if (mLatLngList.size > 0) { -// moveCameraLocation( -// mLatLngList[progress].latitude, mLatLngList[progress].longitude, false -// ) + moveCameraLocation( + mLatLngList[progress].latitude, mLatLngList[progress].longitude, true + ) mGeoCoderViewModel.getLatLonAddress( mLatLngList[progress].latitude, mLatLngList[progress].longitude, false ) diff --git a/app/src/main/java/com/abbidot/tracker/ui/fragment/map/googlemap/HomeMapGoogleMapFragment.kt b/app/src/main/java/com/abbidot/tracker/ui/fragment/map/googlemap/HomeMapGoogleMapFragment.kt deleted file mode 100644 index 8a2ee70..0000000 --- a/app/src/main/java/com/abbidot/tracker/ui/fragment/map/googlemap/HomeMapGoogleMapFragment.kt +++ /dev/null @@ -1,313 +0,0 @@ -package com.abbidot.tracker.ui.fragment.map.googlemap - -import android.animation.ValueAnimator -import android.content.Context -import android.view.animation.LinearInterpolator -import androidx.core.content.ContextCompat -import androidx.core.view.isVisible -import androidx.fragment.app.viewModels -import com.abbidot.baselibrary.util.AppUtils -import com.abbidot.baselibrary.util.Utils -import com.abbidot.tracker.R -import com.abbidot.tracker.bean.HistoryDataBean -import com.abbidot.tracker.bean.MapDeviceBean -import com.abbidot.tracker.util.Util -import com.abbidot.tracker.util.ViewUtil -import com.abbidot.tracker.vm.GeoCoderViewModel -import com.abbidot.tracker.widget.MapDeviceNetView -import com.abbidot.tracker.widget.MapMarkerInfoView -import com.google.android.gms.maps.GoogleMap -import com.google.android.gms.maps.model.Circle -import com.google.android.gms.maps.model.CircleOptions -import com.google.android.gms.maps.model.LatLng -import com.google.android.gms.maps.model.Polyline -import com.google.android.gms.maps.model.PolylineOptions -import kotlin.math.pow - -/** - *Created by .yzq on 2022/1/13/013. - * @link - * @description:首页map谷歌地图 - */ -class HomeMapGoogleMapFragment : BaseGoogleMapFragment() { - - private val mGeoCoderViewModel: GeoCoderViewModel by viewModels() - - private lateinit var mMarkerInfoView: MapMarkerInfoView - private lateinit var mMapDeviceNetView: MapDeviceNetView - - //宠物当前反地理位置信息 - var mDecPetAddressData: HistoryDataBean? = null - private var mMapDeviceBean: MapDeviceBean? = null - private lateinit var mMapLoadOk: () -> Unit - - //启动动画移动地图摄像机 - private var isMoveCamera = true - private var mPolyline: Polyline? = null - private var mRippleCircle: Circle? = null - private var mValueAnimator: ValueAnimator? = null - - // private var mAnimatorDuration=2000L - private var mRippleCirclePercent = 0.0 - private var mRippleCircleRadius = 200 - - companion object { - @JvmStatic - fun newInstance( - context: Context, - markerInfoView: MapMarkerInfoView, - mapDeviceNetView: MapDeviceNetView, - mapLoadOk: () -> Unit - ) = HomeMapGoogleMapFragment().apply { - mContext = context - mMarkerInfoView = markerInfoView - mMapDeviceNetView = mapDeviceNetView - mMapLoadOk = mapLoadOk - } - } - - fun setMapDeviceBean(mapDeviceBean: MapDeviceBean?) { - mMapDeviceBean = mapDeviceBean - } - - override fun liveDataObserve() { - //反地理编码成功返回 - mGeoCoderViewModel.mLatLonAddressLiveData.observe(viewLifecycleOwner) { - //保存地理信息,方便传参给导航页面 - if (null == mDecPetAddressData) mDecPetAddressData = HistoryDataBean() - - mMapDeviceBean?.apply { -// val timeString = String.format( -// getString(R.string.map_current_update_time), -// DateUtils.getRelativeTimeSpanString( -// updateTime * 1000 -// ) -// ) - val timeString = - Utils.formatTime(latLonUpdateTime * 1000, Utils.DATE_FORMAT_PATTERN_EN6) - mDecPetAddressData?.let { history -> - //更新位置时间 - history.dayTime = timeString - //详细位置 - history.address = it - //传递位置信息给InfoWindowAdapter窗口 -// mMarker?.tag = history - -// showMarkerInfoWindow(history) - ViewUtil.instance.viewShow(mMarkerInfoView) - mMarkerInfoView.setShowText(timeString, it) - } - } - } - } - - override fun onMapLoadOk(googleMap: GoogleMap) { -// initFenceList() - //设置自定义头部地点布局 - mGoogleMap?.apply { - setOnCameraMoveListener { - if (mMarkerInfoView.isVisible) setMarkerInfoViewOffset() - } - getLastLocation() - } - - //变量是否初始化 - if (::mMapLoadOk.isInitialized) mMapLoadOk() - } - - - override fun onRefreshPetCurrentLocationOk(googleMap: GoogleMap) { - if (null == mMarker) return - else startReverseGeocode() - } - - /** - * 刚开始的反编译地理位置 - */ - private fun startReverseGeocode() { - mMapDeviceBean?.apply { - mGeoCoderViewModel.getLatLonAddress(latitude, longitude, false) - setMarkerInfoViewOffset() - -// val time = System.currentTimeMillis() - mReverseGeocodeTime -// //判断有没有超过设置的刷新时间 -// if (time > mMapFragment.mMapDeviceBean!!.gnssInterval * 60 * 1000) { -// mGeoCoderViewModel.getLatLonAddress(mMapFragment.mMapDeviceBean!!.latitude, -// mMapFragment.mMapDeviceBean!!.longitude) -// } else { -// //传递位置信息给InfoWindowAdapter窗口 -// mMarker?.tag = mMapFragment.mHistoryDataBean -// showMarkerInfoWindow() -// } -// } - } - } - - fun setMarkerInfoViewOffset() { - mPetLatLng?.apply { - setMarkerInfoViewOffset(mMarkerInfoView, LatLng(latitude, longitude)) - setMapNetTypeViewOffset(mMapDeviceNetView, LatLng(latitude, longitude)) - } - } - - /** - * 点击大头针开始更新反地理编码 - */ - private fun reverseGeocode() { -// val time = System.currentTimeMillis() - mReverseGeocodeTime - //判断有没有超过设置的刷新时间 -// if (time > mMapFragment.mMapDeviceBean!!.gnssInterval * 60 * 1000) { -// mGeoCoderViewModel.getLatLonAddress(mMapFragment.mMapDeviceBean!!.latitude, -// mMapFragment.mMapDeviceBean!!.longitude) -// } - } - - /** - * 计算用户和宠物的距离 - */ - fun getUserAndPetDistance(): Double { - var distance = 0.0 - mUserLatLng?.apply { - mPetLatLng?.let { - distance = - Util.measureLatLonDistance(latitude, longitude, it.latitude, it.longitude) - } - } - return distance - } - - /** - * 画用户和宠物之间的虚线 - */ - private fun addUserAndPetLine(petLatLng: LatLng) { - mUserLatLng?.apply { - mGoogleMap?.let { - if (null == mPolyline) { - val polylineOptions = - PolylineOptions().clickable(false).width(AppUtils.dpToPx(1.5f)) - .color(ContextCompat.getColor(mContext!!, R.color.blue_color9)) - .geodesic(false) - mPolyline = it.addPolyline(polylineOptions) - mPolyline?.pattern = getDashedPatternStyle(18f) - } - mPolyline?.let { pLine -> - val latList = mutableListOf() - latList.add(petLatLng) - latList.add(this) - pLine.points = latList - } - } - } - } - - /** - * 初始化并添加水波纹圆 - */ - private fun addRippleCircle() { - mPetLatLng?.apply { - mGoogleMap?.let { - if (null == mRippleCircle) { - mRippleCircle = it.addCircle( - CircleOptions().center(this) - .radius(mRippleCircleRadius * mRippleCirclePercent) - .strokeWidth(AppUtils.dpToPx(2).toFloat()) - .fillColor(ContextCompat.getColor(mContext!!, R.color.black10)) - .strokeColor(ContextCompat.getColor(mContext!!, R.color.black10)) - ) - - setRippleCircleAnim() - } - } - } - } - - /** - * 设置水波纹动画 - */ - private fun setRippleCircleAnim() { - if (null == mValueAnimator) { - mValueAnimator = ViewUtil.instance.setValueAnimator( - 0.0, 100.0, 1500, LinearInterpolator() - ) { - mRippleCirclePercent = it.animatedValue as Float / 100.0 - mRippleCircle?.apply { - mPetLatLng?.let { petLatLng -> - center = petLatLng - radius = mRippleCircleRadius * mRippleCirclePercent - } - } - }?.apply { - repeatMode = ValueAnimator.RESTART - repeatCount = ValueAnimator.INFINITE - } - } - } - - /** - * 画线 - */ - fun addLine(latLng: LatLng) { -// addPolyline(mGoogleMap!!, latLng) -// addUserAndPetLine(latLng) - refreshPetCurrentLocation(latLng, needMoveCamera = isMoveCamera) - -// mRippleCircle?.apply { -// //一像素对应几米 -// val pxDis = 2.0.pow(15.5 - getGoogleMapZoom()) -// mRippleCircleRadius = (pxDis * 150).toInt() -// fillColor = (ContextCompat.getColor(mContext!!, R.color.select_color5)) -// strokeColor = (ContextCompat.getColor(mContext!!, R.color.select_color5)) -// mValueAnimator?.duration = 2000 -// } - } - - /** - * 画多条线 - */ - fun addLines(trackList: MutableList) { - val latLngList = mutableListOf() - for (i in 0 until trackList.size) { - trackList[i].apply { - val latLng = LatLng(latitude, longitude) - latLngList.add(latLng) - if (i == trackList.size - 1) { -// addUserAndPetLine(latLng) - refreshPetCurrentLocation(latLng, needMoveCamera = isMoveCamera) - } - } - } -// addPolyLines(mGoogleMap!!, latLngList) - } - - /** - * 开始水波纹动画 - */ - fun startRippleCircleAnim() { - mPetLatLng?.apply { - //一像素对应几米 - val pxDis = 2.0.pow(15.5 - getGoogleMapZoom()) - mRippleCircleRadius = (pxDis * 150).toInt() -// addUserAndPetLine(this) - addRippleCircle() - } - } - - /** - * 直播开始之后,改变绿色波纹动画 - */ - fun greenRippleCircleAnim() { - mRippleCircle?.apply { - //一像素对应几米 - val pxDis = 2.0.pow(15.5 - getGoogleMapZoom()) - mRippleCircleRadius = (pxDis * 150).toInt() - fillColor = (ContextCompat.getColor(mContext!!, R.color.select_color5)) - strokeColor = (ContextCompat.getColor(mContext!!, R.color.select_color5)) - mValueAnimator?.duration = 2000 - } - } - - override fun onDetach() { - super.onDetach() - mValueAnimator?.cancel() - } -} \ No newline at end of file