diff --git a/app/src/main/java/com/casic/detector/view/MainActivity.kt b/app/src/main/java/com/casic/detector/view/MainActivity.kt index 836b6f6..052bd42 100644 --- a/app/src/main/java/com/casic/detector/view/MainActivity.kt +++ b/app/src/main/java/com/casic/detector/view/MainActivity.kt @@ -124,6 +124,7 @@ private val installDialog by lazy { InstallMarkerDialog(this) } private val searchNewDialog by lazy { SearchMarkerNewDialog(this) } private val detailDialog by lazy { MarkerDetailDialog(this) } + private val locationHub by lazy { LocationHub(this) } private val sensorMessageCode = 2024022301 private val rotationMatrix = FloatArray(9)//旋转矩阵缓存 private val valueArray = FloatArray(3)//方位角数值 @@ -147,7 +148,6 @@ /***inner class 需要用到*****start*/ private val gpioManager by lazy { GpioManager() } - private val locationHub by lazy { LocationHub(this) } private val taskViewModel by lazy { ViewModelProvider(this)[TaskViewModel::class.java] } private val attr = AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_ALARM) .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).build() @@ -1015,6 +1015,7 @@ private val realPaths = ArrayList() //真实图片路径 private lateinit var imageAdapter: EditableImageAdapter private lateinit var countDownTimer: CountDownTimer + private lateinit var locationManager: LocationHub var isReadMarker = false var isInstallMarker = false @@ -1239,6 +1240,21 @@ } } + override fun show() { + super.show() + locationManager = LocationHub(context) + locationManager.getCurrentLocation(true, object : OnGetLocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + binding.identifierInclude.lngView.text = location.longitude.toString() + binding.identifierInclude.latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + } + fun bindingValue(markerId: String) { this.markerId = markerId LoadingDialogHub.dismiss() @@ -1258,6 +1274,7 @@ gpioManager.setGpioLow("18") soundPool.autoPause() isInstallMarker = false + locationManager.stopLocation() super.dismiss() } @@ -1346,16 +1363,6 @@ binding.identifierInclude.installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() - locationHub.getCurrentLocation(true, object : OnGetLocationListener { - override fun onAMapLocationGet(location: AMapLocation?) { - if (location != null) { - binding.identifierInclude.lngView.text = location.longitude.toString() - binding.identifierInclude.latView.text = location.latitude.toString() - } else { - "当前位置信号差,无法获取定位".show(context) - } - } - }) binding.identifierInclude.colorSpinner.show( this@MainActivity, LocaleConstant.COLOR_ARRAY, 0 @@ -1486,7 +1493,7 @@ private lateinit var signalTask: TimerTask private lateinit var energyTask: TimerTask private lateinit var countDownTimer: CountDownTimer - + private lateinit var locationManager: LocationHub var isDetectMarker = false override fun onCreate(savedInstanceState: Bundle?) { @@ -1541,11 +1548,16 @@ context.navigatePageTo(markerId) } } + } + override fun show() { + super.show() + locationManager = LocationHub(context) //点位渲染,每次定位都计算当前位置与符合条件的点距离 - locationHub.getCurrentLocation(false, object : OnGetLocationListener { + locationManager.getCurrentLocation(false, object : OnGetLocationListener { override fun onAMapLocationGet(location: AMapLocation?) { location?.apply { + "[${longitude}, ${latitude}]".show(context) renderDataPoint(this) } } @@ -1554,34 +1566,30 @@ /** * 计算并渲染数据点。点太多采用协程计算,不然会有点卡顿 + * @param location 定位点(天宝RTK获取) * */ private fun renderDataPoint(location: AMapLocation) { lifecycleScope.launch(Dispatchers.IO) { val dataPoints = ArrayList() DataBaseManager.get.loadMarkers().forEach { - //单位:米 + //单位:米。计算出探测仪(定位点)与标识器距离 val distance = AMapUtils.calculateLineDistance( LatLng(latitude, longitude), LatLng(it.lat.toDouble(), it.lng.toDouble()) ) if (distance <= LocaleConstant.MAX_DISTANCE) { - var angle = location.calculateAngle( + //计算出探测仪(定位点)与标识器的方位角 + val angle = location.calculateAngle( LatLng(it.lat.toDouble(), it.lng.toDouble()) ) - //TODO - angle = if (true) { - angle - 90 - } else { - angle + 90 - } val formatDistance = String.format("%.2f", distance) dataPoints.add(RadarScanView.DataPoint(angle, formatDistance.toFloat())) } } withContext(Dispatchers.Main) { - binding.radarScanView.renderPointData( - dataPoints, object : RadarScanView.OnGetNearestPointCallback { + binding.radarScanView.renderPointData(dataPoints, + object : RadarScanView.OnGetNearestPointCallback { override fun getNearestPoint(point: RadarScanView.DataPoint?) { if (point == null) { binding.distanceValueView.text = "大于550cm" @@ -1597,8 +1605,7 @@ binding.distancePgBar.progress = progress.toInt() } } - } - ) + }) } } } @@ -1746,7 +1753,7 @@ gpioManager.setGpioLow("18") isDetectMarker = false soundPool.autoPause() - locationHub.stopLocation() + locationManager.stopLocation() super.dismiss() } } diff --git a/app/src/main/java/com/casic/detector/view/MainActivity.kt b/app/src/main/java/com/casic/detector/view/MainActivity.kt index 836b6f6..052bd42 100644 --- a/app/src/main/java/com/casic/detector/view/MainActivity.kt +++ b/app/src/main/java/com/casic/detector/view/MainActivity.kt @@ -124,6 +124,7 @@ private val installDialog by lazy { InstallMarkerDialog(this) } private val searchNewDialog by lazy { SearchMarkerNewDialog(this) } private val detailDialog by lazy { MarkerDetailDialog(this) } + private val locationHub by lazy { LocationHub(this) } private val sensorMessageCode = 2024022301 private val rotationMatrix = FloatArray(9)//旋转矩阵缓存 private val valueArray = FloatArray(3)//方位角数值 @@ -147,7 +148,6 @@ /***inner class 需要用到*****start*/ private val gpioManager by lazy { GpioManager() } - private val locationHub by lazy { LocationHub(this) } private val taskViewModel by lazy { ViewModelProvider(this)[TaskViewModel::class.java] } private val attr = AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_ALARM) .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).build() @@ -1015,6 +1015,7 @@ private val realPaths = ArrayList() //真实图片路径 private lateinit var imageAdapter: EditableImageAdapter private lateinit var countDownTimer: CountDownTimer + private lateinit var locationManager: LocationHub var isReadMarker = false var isInstallMarker = false @@ -1239,6 +1240,21 @@ } } + override fun show() { + super.show() + locationManager = LocationHub(context) + locationManager.getCurrentLocation(true, object : OnGetLocationListener { + override fun onAMapLocationGet(location: AMapLocation?) { + if (location != null) { + binding.identifierInclude.lngView.text = location.longitude.toString() + binding.identifierInclude.latView.text = location.latitude.toString() + } else { + "当前位置信号差,无法获取定位".show(context) + } + } + }) + } + fun bindingValue(markerId: String) { this.markerId = markerId LoadingDialogHub.dismiss() @@ -1258,6 +1274,7 @@ gpioManager.setGpioLow("18") soundPool.autoPause() isInstallMarker = false + locationManager.stopLocation() super.dismiss() } @@ -1346,16 +1363,6 @@ binding.identifierInclude.installTimeView.text = System.currentTimeMillis().timestampToCompleteDate() - locationHub.getCurrentLocation(true, object : OnGetLocationListener { - override fun onAMapLocationGet(location: AMapLocation?) { - if (location != null) { - binding.identifierInclude.lngView.text = location.longitude.toString() - binding.identifierInclude.latView.text = location.latitude.toString() - } else { - "当前位置信号差,无法获取定位".show(context) - } - } - }) binding.identifierInclude.colorSpinner.show( this@MainActivity, LocaleConstant.COLOR_ARRAY, 0 @@ -1486,7 +1493,7 @@ private lateinit var signalTask: TimerTask private lateinit var energyTask: TimerTask private lateinit var countDownTimer: CountDownTimer - + private lateinit var locationManager: LocationHub var isDetectMarker = false override fun onCreate(savedInstanceState: Bundle?) { @@ -1541,11 +1548,16 @@ context.navigatePageTo(markerId) } } + } + override fun show() { + super.show() + locationManager = LocationHub(context) //点位渲染,每次定位都计算当前位置与符合条件的点距离 - locationHub.getCurrentLocation(false, object : OnGetLocationListener { + locationManager.getCurrentLocation(false, object : OnGetLocationListener { override fun onAMapLocationGet(location: AMapLocation?) { location?.apply { + "[${longitude}, ${latitude}]".show(context) renderDataPoint(this) } } @@ -1554,34 +1566,30 @@ /** * 计算并渲染数据点。点太多采用协程计算,不然会有点卡顿 + * @param location 定位点(天宝RTK获取) * */ private fun renderDataPoint(location: AMapLocation) { lifecycleScope.launch(Dispatchers.IO) { val dataPoints = ArrayList() DataBaseManager.get.loadMarkers().forEach { - //单位:米 + //单位:米。计算出探测仪(定位点)与标识器距离 val distance = AMapUtils.calculateLineDistance( LatLng(latitude, longitude), LatLng(it.lat.toDouble(), it.lng.toDouble()) ) if (distance <= LocaleConstant.MAX_DISTANCE) { - var angle = location.calculateAngle( + //计算出探测仪(定位点)与标识器的方位角 + val angle = location.calculateAngle( LatLng(it.lat.toDouble(), it.lng.toDouble()) ) - //TODO - angle = if (true) { - angle - 90 - } else { - angle + 90 - } val formatDistance = String.format("%.2f", distance) dataPoints.add(RadarScanView.DataPoint(angle, formatDistance.toFloat())) } } withContext(Dispatchers.Main) { - binding.radarScanView.renderPointData( - dataPoints, object : RadarScanView.OnGetNearestPointCallback { + binding.radarScanView.renderPointData(dataPoints, + object : RadarScanView.OnGetNearestPointCallback { override fun getNearestPoint(point: RadarScanView.DataPoint?) { if (point == null) { binding.distanceValueView.text = "大于550cm" @@ -1597,8 +1605,7 @@ binding.distancePgBar.progress = progress.toInt() } } - } - ) + }) } } } @@ -1746,7 +1753,7 @@ gpioManager.setGpioLow("18") isDetectMarker = false soundPool.autoPause() - locationHub.stopLocation() + locationManager.stopLocation() super.dismiss() } } diff --git a/app/src/main/res/layout/dialog_search_marker_new.xml b/app/src/main/res/layout/dialog_search_marker_new.xml index 7349134..e9a97a0 100644 --- a/app/src/main/res/layout/dialog_search_marker_new.xml +++ b/app/src/main/res/layout/dialog_search_marker_new.xml @@ -64,7 +64,7 @@ app:radar_border="@dimen/dp_1" app:radar_borderColor="#8000FFF0" app:radar_circleCount="4" - app:radar_radius="124dp" /> + app:radar_radius="120dp" />