Merge branch 'master' of https://gitlab.navinfo.com/CollectVehicle/OneMapQS
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
package com.navinfo.omqs.ui.activity.map
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.PersistableBundle
|
||||
import android.speech.tts.TextToSpeech
|
||||
import android.util.Log
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.activity.viewModels
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.view.WindowCompat
|
||||
@@ -29,7 +34,10 @@ import com.navinfo.omqs.util.FlowEventBus
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.launch
|
||||
import com.navinfo.omqs.ui.widget.RecyclerViewSpacesItemDecoration
|
||||
import com.navinfo.omqs.util.SpeakMode
|
||||
import org.videolan.vlc.Util
|
||||
import java.math.BigDecimal
|
||||
import java.math.RoundingMode
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
@@ -43,6 +51,17 @@ class MainActivity : BaseActivity() {
|
||||
|
||||
var switchFragment = false
|
||||
|
||||
|
||||
private val someActivityResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
val data: Intent? = result.data
|
||||
Log.e("jingo", "MainActivity someActivityResultLauncher RESULT_OK")
|
||||
} else {
|
||||
Log.e("jingo", "MainActivity someActivityResultLauncher ${result.resultCode}")
|
||||
}
|
||||
}
|
||||
|
||||
//注入地图控制器
|
||||
@Inject
|
||||
lateinit var mapController: NIMapController
|
||||
@@ -88,6 +107,13 @@ class MainActivity : BaseActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val checkIntent = Intent()
|
||||
checkIntent.action = TextToSpeech.Engine.ACTION_CHECK_TTS_DATA
|
||||
someActivityResultLauncher.launch(checkIntent)
|
||||
|
||||
|
||||
|
||||
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
|
||||
|
||||
//初始化地图
|
||||
@@ -98,6 +124,7 @@ class MainActivity : BaseActivity() {
|
||||
Constant.MAP_PATH,
|
||||
Constant.USER_DATA_PATH + "/trace.sqlite"
|
||||
)
|
||||
viewModel.speakMode = SpeakMode(this)
|
||||
// 在mapController初始化前获取当前OMDB图层显隐
|
||||
viewModel.refreshOMDBLayer(LayerConfigUtils.getLayerConfigList())
|
||||
mapController.mMapView.vtmMap.viewport().maxZoomLevel = 25
|
||||
@@ -144,8 +171,7 @@ class MainActivity : BaseActivity() {
|
||||
|
||||
//道路属性面板
|
||||
binding.mainActivityTopSignRecyclerview.layoutManager = LinearLayoutManager(
|
||||
this,
|
||||
RecyclerView.HORIZONTAL, false
|
||||
this, RecyclerView.HORIZONTAL, false
|
||||
)
|
||||
// binding.mainActivityTopSignRecyclerview.addItemDecoration(
|
||||
// RecycleViewDivider(this, LinearLayoutManager.HORIZONTAL)
|
||||
@@ -164,19 +190,28 @@ class MainActivity : BaseActivity() {
|
||||
)
|
||||
)
|
||||
)
|
||||
//监听要素面板变化
|
||||
viewModel.liveDataSignList.observe(this) {
|
||||
signAdapter.refreshData(it)
|
||||
}
|
||||
|
||||
//监听道路信息变化
|
||||
viewModel.liveDataTopSignList.observe(this) {
|
||||
topSignAdapter.refreshData(it)
|
||||
}
|
||||
//监听地图中点变化
|
||||
viewModel.liveDataCenterPoint.observe(this) {
|
||||
binding.mainActivityGeometry.text = "经纬度:${
|
||||
BigDecimal(it.longitude).setScale(
|
||||
6,
|
||||
RoundingMode.HALF_UP
|
||||
)
|
||||
},${BigDecimal(it.latitude).setScale(6, RoundingMode.HALF_UP)}"
|
||||
}
|
||||
|
||||
lifecycleScope.launch {
|
||||
// 初始化地图图层控制接收器
|
||||
FlowEventBus.subscribe<List<ImportConfig>>(
|
||||
lifecycle,
|
||||
Constant.EVENT_LAYER_MANAGER_CHANGE
|
||||
lifecycle, Constant.EVENT_LAYER_MANAGER_CHANGE
|
||||
) {
|
||||
viewModel.refreshOMDBLayer(it)
|
||||
}
|
||||
@@ -201,6 +236,7 @@ class MainActivity : BaseActivity() {
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
viewModel.speakMode?.shutdown()
|
||||
mapController.mMapView.onDestroy()
|
||||
mapController.locationLayerHandler.stopLocation()
|
||||
}
|
||||
|
||||
@@ -45,7 +45,10 @@ import io.realm.RealmSet
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.oscim.core.GeoPoint
|
||||
import org.oscim.core.MapPosition
|
||||
import org.oscim.map.Map
|
||||
import org.videolan.libvlc.LibVlcUtil
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
@@ -59,7 +62,7 @@ import javax.inject.Inject
|
||||
class MainViewModel @Inject constructor(
|
||||
private val mapController: NIMapController,
|
||||
private val traceDataBase: TraceDataBase,
|
||||
private val realmOperateHelper: RealmOperateHelper
|
||||
private val realmOperateHelper: RealmOperateHelper,
|
||||
) : ViewModel() {
|
||||
|
||||
private var mCameraDialog: CommonDialog? = null
|
||||
@@ -78,7 +81,7 @@ class MainViewModel @Inject constructor(
|
||||
//语音窗体
|
||||
private var pop: PopupWindow? = null
|
||||
|
||||
private var mSpeakMode: SpeakMode? = null
|
||||
var speakMode: SpeakMode? = null
|
||||
|
||||
//录音图标
|
||||
var volume: ImageView? = null
|
||||
@@ -88,12 +91,28 @@ class MainViewModel @Inject constructor(
|
||||
|
||||
val liveDataMenuState = MutableLiveData<Boolean>()
|
||||
|
||||
val liveDataCenterPoint = MutableLiveData<MapPosition>()
|
||||
|
||||
/**
|
||||
* 是不是线选择模式
|
||||
*/
|
||||
private var bSelectRoad = false
|
||||
|
||||
init {
|
||||
mapController.mMapView.vtmMap.events.bind(Map.UpdateListener { e, mapPosition ->
|
||||
when (e) {
|
||||
Map.SCALE_EVENT, Map.MOVE_EVENT, Map.ROTATE_EVENT ->
|
||||
if (liveDataCenterPoint.value == null
|
||||
|| liveDataCenterPoint.value!!.x != mapPosition.x
|
||||
|| liveDataCenterPoint.value!!.y != mapPosition.y
|
||||
) {
|
||||
liveDataCenterPoint.value = mapPosition
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
//处理质检数据点击事件
|
||||
mapController.markerHandle.setOnQsRecordItemClickListener(object :
|
||||
OnQsRecordItemClickListener {
|
||||
override fun onQsRecordList(list: MutableList<String>) {
|
||||
@@ -101,9 +120,11 @@ class MainViewModel @Inject constructor(
|
||||
}
|
||||
})
|
||||
initLocation()
|
||||
//处理地图点击操作
|
||||
viewModelScope.launch {
|
||||
mapController.onMapClickFlow.collectLatest {
|
||||
// testPoint = it
|
||||
//线选择状态
|
||||
if (bSelectRoad) {
|
||||
captureLink(it)
|
||||
}
|
||||
@@ -223,10 +244,10 @@ class MainViewModel @Inject constructor(
|
||||
)
|
||||
|
||||
when (element.code) {
|
||||
2041, 2008, 2010 -> topSignList.add(
|
||||
2002, 2008, 2010, 2041 -> topSignList.add(
|
||||
signBean
|
||||
)
|
||||
else -> signList.add(
|
||||
4002, 4003, 4004, 4006, 4022 -> signList.add(
|
||||
signBean
|
||||
)
|
||||
}
|
||||
@@ -237,6 +258,10 @@ class MainViewModel @Inject constructor(
|
||||
}
|
||||
liveDataTopSignList.postValue(topSignList.distinctBy { it.elementCode })
|
||||
liveDataSignList.postValue(signList.distinctBy { it.elementCode })
|
||||
val speechText = SignUtil.getRoadSpeechText(topSignList)
|
||||
withContext(Dispatchers.Main) {
|
||||
speakMode?.speakText(speechText)
|
||||
}
|
||||
Log.e("jingo", "自动捕捉数据 共${signList.size}条")
|
||||
}
|
||||
}
|
||||
@@ -303,10 +328,6 @@ class MainViewModel @Inject constructor(
|
||||
|
||||
fun startSoundMetter(context: Context, v: View) {
|
||||
|
||||
if (mSpeakMode == null) {
|
||||
mSpeakMode = SpeakMode(context as Activity?)
|
||||
}
|
||||
|
||||
//语音识别动画
|
||||
if (pop == null) {
|
||||
pop = PopupWindow()
|
||||
@@ -340,12 +361,12 @@ class MainViewModel @Inject constructor(
|
||||
if (!TextUtils.isEmpty(filePath) && File(filePath).exists()) {
|
||||
if (File(filePath) == null || File(filePath).length() < 1600) {
|
||||
ToastUtils.showLong("语音时间太短,无效!")
|
||||
mSpeakMode!!.speakText("语音时间太短,无效")
|
||||
speakMode?.speakText("语音时间太短,无效")
|
||||
stopSoundMeter()
|
||||
return
|
||||
}
|
||||
}
|
||||
mSpeakMode!!.speakText("结束录音")
|
||||
speakMode?.speakText("结束录音")
|
||||
//获取右侧fragment容器
|
||||
val naviController =
|
||||
(context as Activity).findNavController(R.id.main_activity_right_fragment)
|
||||
@@ -357,14 +378,14 @@ class MainViewModel @Inject constructor(
|
||||
@RequiresApi(api = Build.VERSION_CODES.Q)
|
||||
override fun onfaild(message: String?) {
|
||||
ToastUtils.showLong("录制失败!")
|
||||
mSpeakMode!!.speakText("录制失败")
|
||||
speakMode?.speakText("录制失败")
|
||||
stopSoundMeter()
|
||||
}
|
||||
})
|
||||
|
||||
mSoundMeter!!.start(Constant.USER_DATA_ATTACHEMNT_PATH + name)
|
||||
ToastUtils.showLong("开始录音")
|
||||
mSpeakMode!!.speakText("开始录音")
|
||||
speakMode?.speakText("开始录音")
|
||||
}
|
||||
|
||||
//停止语音录制
|
||||
|
||||
Reference in New Issue
Block a user