[VisualAngle]实现地图sdk路口相关回调;处理十字路口视角切换逻辑
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package com.mogo.eagle.core.function.call.map
|
||||
|
||||
import com.mogo.eagle.core.data.map.MapRoadInfo.StopLine
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
object CallerMapRoadListenerManager {
|
||||
|
||||
interface OnRoadListener {
|
||||
|
||||
fun onRoadIdInfo(roadId: String)
|
||||
|
||||
fun onStopLineInfo(info: StopLine)
|
||||
}
|
||||
|
||||
private val listeners by lazy {
|
||||
ConcurrentHashMap<String, OnRoadListener>()
|
||||
}
|
||||
|
||||
fun registerRoadListener(tag: String, listener: OnRoadListener) {
|
||||
if (listeners.contains(tag)) {
|
||||
return
|
||||
}
|
||||
listeners[tag] = listener
|
||||
}
|
||||
|
||||
fun unRegisterRoadListener(tag: String) {
|
||||
if (!listeners.contains(tag)) {
|
||||
return
|
||||
}
|
||||
listeners.remove(tag)
|
||||
}
|
||||
|
||||
|
||||
fun invokeListenersOnRoadIdGet(roadId: String) {
|
||||
listeners.forEach { entry ->
|
||||
entry.value.onRoadIdInfo(roadId)
|
||||
}
|
||||
}
|
||||
|
||||
fun invokeListenersOnStopLineGet(stopLine: StopLine) {
|
||||
listeners.forEach { entry ->
|
||||
entry.value.onStopLineInfo(stopLine)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,10 @@ import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.SystemClock
|
||||
import android.util.Log
|
||||
import com.mogo.eagle.core.data.map.MapRoadInfo.StopLine
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng
|
||||
import com.mogo.eagle.core.function.call.map.CallerMapRoadListenerManager.OnRoadListener
|
||||
import com.mogo.eagle.core.function.call.map.CallerVisualAngleManager.Scene.CrossRoad
|
||||
import com.mogo.eagle.core.function.call.map.CallerVisualAngleManager.Scene.Default
|
||||
import com.mogo.eagle.core.function.call.map.CallerVisualAngleManager.Scene.LowSpeed
|
||||
import com.mogo.eagle.core.utilcode.kotlin.safeCancel
|
||||
@@ -23,7 +26,11 @@ object CallerVisualAngleManager {
|
||||
|
||||
private const val TAG = "VisualAngle"
|
||||
|
||||
private const val MaxDisplayThreshold = 20_000 //最大展示阈值
|
||||
private const val MaxDisplayThreshold = 30_000 //最大展示阈值
|
||||
|
||||
@Volatile
|
||||
private var hasCrossRoad = false
|
||||
|
||||
|
||||
private var scope: CoroutineScope = acquireScope()
|
||||
@Synchronized
|
||||
@@ -47,6 +54,30 @@ object CallerVisualAngleManager {
|
||||
val priority: Int
|
||||
}
|
||||
|
||||
init {
|
||||
CallerMapRoadListenerManager.registerRoadListener("VisualAngleChange", object : OnRoadListener {
|
||||
|
||||
private var roadId = ""
|
||||
|
||||
override fun onRoadIdInfo(roadId: String) {}
|
||||
|
||||
override fun onStopLineInfo(info: StopLine) {
|
||||
if (!hasCrossRoad && info.distanceOfCarToStopLine <= 30.0) {
|
||||
hasCrossRoad = true
|
||||
changeVisualAngle(CrossRoad)
|
||||
}
|
||||
val oldRoadId = this.roadId
|
||||
if (oldRoadId != roadId) {
|
||||
if (hasCrossRoad) {
|
||||
hasCrossRoad = false
|
||||
changeVisualAngle(Default())
|
||||
}
|
||||
}
|
||||
this.roadId = info.roadId
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
sealed class Scene private constructor(): IAttach {
|
||||
|
||||
/**
|
||||
@@ -146,16 +177,14 @@ object CallerVisualAngleManager {
|
||||
|
||||
@OptIn(InternalCoroutinesApi::class)
|
||||
fun changeVisualAngle(scene: Scene) {
|
||||
val triggerTime = SystemClock.elapsedRealtime()
|
||||
val triggerTime = TimeUnit.MILLISECONDS.toSeconds(SystemClock.elapsedRealtime())
|
||||
scope.launch {
|
||||
val displayed = getDisplayed()
|
||||
if (displayed == null) {
|
||||
val top = getTop() //堆顶
|
||||
if (top != null && top.target.priority > scene.priority) {
|
||||
doChangeAngle(top)
|
||||
synchronized(heap) {
|
||||
heap += Record(scene, triggerTime = triggerTime)
|
||||
}
|
||||
heap += Record(scene, triggerTime = triggerTime)
|
||||
} else {
|
||||
doChangeAngle(Record(scene, triggerTime = triggerTime))
|
||||
}
|
||||
@@ -167,9 +196,7 @@ object CallerVisualAngleManager {
|
||||
}
|
||||
if (scene is Default) {
|
||||
Log.d(TAG, "恢复到默认视图,之前展示的视图:$displayed")
|
||||
synchronized(heap) {
|
||||
heap -= displayed
|
||||
}
|
||||
heap -= displayed
|
||||
launch {
|
||||
val delay = scene.unit.toMillis(scene.delay)
|
||||
Log.d(TAG, "默认视图开启延时倒计时, 倒计时时间:${delay} ms.")
|
||||
|
||||
Reference in New Issue
Block a user