add pnc actions func

This commit is contained in:
zhongchao
2022-08-16 11:06:36 +08:00
parent e70223dcdc
commit a97f7f870a
18 changed files with 335 additions and 39 deletions

View File

@@ -0,0 +1,91 @@
package com.mogo.eagle.core.function.hmi.ui.pnc
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import com.mogo.eagle.core.data.autopilot.pnc.PncActionsHelper
import com.mogo.eagle.core.data.trafficlight.TrafficLightResult
import com.mogo.eagle.core.data.trafficlight.currentRoadTrafficLight
import com.mogo.eagle.core.data.trafficlight.isRed
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotPlanningActionsListener
import com.mogo.eagle.core.function.api.trafficlight.IMoGoTrafficLightListener
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotPlanningActionsListenerManager
import com.mogo.eagle.core.function.call.trafficlight.CallerTrafficLightListenerManager
import com.mogo.eagle.core.function.hmi.R
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
import kotlinx.android.synthetic.main.view_pnc_actions.view.*
import mogo.telematics.pad.MessagePad
class PncActionsView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr), IMoGoAutopilotPlanningActionsListener,
IMoGoTrafficLightListener {
companion object {
const val TAG = "PncActionsView"
}
@Volatile
private var mTrafficLightResult: TrafficLightResult? = null
init {
LayoutInflater.from(context).inflate(R.layout.view_pnc_actions, this, true)
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
CallerAutopilotPlanningActionsListenerManager.addListener(TAG, this)
CallerTrafficLightListenerManager.registerTrafficLightListener(TAG, this)
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
CallerAutopilotPlanningActionsListenerManager.removeListener(TAG)
CallerTrafficLightListenerManager.unRegisterTrafficLightListener(TAG)
}
override fun pncActions(planningActionMsg: MessagePad.PlanningActionMsg) {
UiThreadHandler.post {
var actions: String? = null
planningActionMsg.actionMsg?.let {
actions = PncActionsHelper.getAction(it.drivingState.number, it.drivingAction.number)
//如果是存在云端红绿灯数据条件下,设置云端数据
if (PncActionsHelper.isWaitingTrafficlight(
it.drivingState.number,
it.drivingAction.number
)
&& mTrafficLightResult != null
&& getWaitTrafficlightTime().isNotBlank()
) {
actions += ",预计${getWaitTrafficlightTime()}秒后通过"
} else {
mTrafficLightResult = null
}
}
// update view
actions?.let {
tvHmiPncActions.text = actions
}
}
}
override fun onTrafficLightStatus(trafficLightResult: TrafficLightResult) {
mTrafficLightResult = trafficLightResult
}
private fun getWaitTrafficlightTime(): String {
return if (mTrafficLightResult != null
&& mTrafficLightResult!!.currentRoadTrafficLight() != null
&& mTrafficLightResult!!.currentRoadTrafficLight()!!.isRed()
) {
mTrafficLightResult!!.currentRoadTrafficLight()!!.remain.toString()
} else {
""
}
}
}

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvHmiPncActions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/sp_30"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>