完成了自动驾驶按钮的点击触发逻辑抽离

Signed-off-by: 董宏宇 <martindhy@gmail.com>
This commit is contained in:
董宏宇
2021-09-23 10:57:34 +08:00
committed by liujing
parent 36844ee704
commit 65640589fd
15 changed files with 210 additions and 186 deletions

View File

@@ -54,12 +54,13 @@ dependencies {
if (Boolean.valueOf(RELEASE)) {
} else {
api project(':services:mogo-service-api')
implementation project(':services:mogo-service-api')
implementation project(':modules:mogo-module-common')
implementation project(':core:mogo-core-data')
implementation project(':core:mogo-core-utils')
implementation project(':core:mogo-core-function-api')
implementation project(':core:mogo-core-function-call')
}
}

View File

@@ -1,12 +1,16 @@
package com.mogo.eagle.core.function.hmi.ui.widget
import android.content.Context
import android.content.res.TypedArray
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import com.mogo.eagle.core.data.autopilot.AdasOCHData
import com.mogo.eagle.core.function.call.hmi.CallerHmiListenerManager
import com.mogo.eagle.core.function.hmi.R
import com.mogo.eagle.core.utilcode.util.LogUtils
import com.mogo.module.common.MogoApisHandler
import com.mogo.service.adas.IMogoAdasOCHCallback
import kotlinx.android.synthetic.main.view_autopilot_status.view.*
/**
@@ -17,20 +21,13 @@ import kotlinx.android.synthetic.main.view_autopilot_status.view.*
class AutoPilotStatusView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet
) : ConstraintLayout(context, attrs) {
) : ConstraintLayout(context, attrs), View.OnClickListener, IMogoAdasOCHCallback {
private val TAG = "AutopilotStatusView"
private var mAutopilotStatus: Int = 0
init {
val typedArray: TypedArray =
context.obtainStyledAttributes(attrs, R.styleable.AutopilotStatusView)
mAutopilotStatus = typedArray.getInt(R.styleable.AutopilotStatusView_autopilotStatus, 0)
typedArray.recycle()
LogUtils.dTag(TAG, "autopilotStatus: $mAutopilotStatus")
initView(context)
}
@@ -40,16 +37,38 @@ class AutoPilotStatusView @JvmOverloads constructor(
val lp = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
layoutParams = lp
// 设置点击监听
setOnClickListener(this)
// 首次查询自动驾驶状态
mAutopilotStatus = MogoApisHandler.getInstance().apis.adasControllerApi.autopilotStatus
// 自动驾驶状态监听
MogoApisHandler.getInstance().apis.adasControllerApi.addAdasOCHCallback(this)
LogUtils.dTag(TAG, "autopilotStatus: $mAutopilotStatus")
setAutoPilotStatus(mAutopilotStatus)
}
override fun onClick(v: View?) {
when (mAutopilotStatus) {
0 -> {// 不可自动驾驶adas与工控机没有链接或工控机异常
LogUtils.eTag(TAG, "不可自动驾驶adas与工控机没有链接或工控机异常,请检查链路")
}
1 -> {// 可自动驾驶,目前处于人工干预状态
CallerHmiListenerManager.invokeCheckAutoPilotBtnListener(true)
}
2 -> {// 自动驾驶中
CallerHmiListenerManager.invokeCheckAutoPilotBtnListener(false)
}
}
}
/**
* 设置自动驾驶状态
* 0-// 不可自动驾驶adas与工控机没有链接或工控机异常
* 1-// 可自动驾驶,目前处于人工干预状态
* 2-// 自动驾驶中
*/
fun setAutoPilotStatus(autopilotStatus: Int) {
private fun setAutoPilotStatus(autopilotStatus: Int) {
mAutopilotStatus = autopilotStatus
when (autopilotStatus) {
0 -> {// 不可自动驾驶adas与工控机没有链接或工控机异常
@@ -67,4 +86,13 @@ class AutoPilotStatusView @JvmOverloads constructor(
}
}
override fun onArriveAt(data: AdasOCHData?) {
}
override fun onStateChanged(state: Int, reason: String?) {
setAutoPilotStatus(state)
}
}

View File

@@ -33,7 +33,6 @@
android:visibility="gone"
app:layout_constraintLeft_toLeftOf="@+id/flSpeedChartView"
app:layout_constraintTop_toBottomOf="@+id/flSpeedChartView"
tools:autopilotStatus="running"
tools:visibility="visible" />
<com.mogo.eagle.core.function.hmi.ui.widget.TrafficLightView