diff --git a/OCH/taxi/unmanned-driver/src/main/res/layout/unmanned_taxi_base_fragment.xml b/OCH/taxi/unmanned-driver/src/main/res/layout/unmanned_taxi_base_fragment.xml index 0ae4b7253b..5ef90cfb17 100644 --- a/OCH/taxi/unmanned-driver/src/main/res/layout/unmanned_taxi_base_fragment.xml +++ b/OCH/taxi/unmanned-driver/src/main/res/layout/unmanned_taxi_base_fragment.xml @@ -459,7 +459,7 @@ app:layout_constraintStart_toStartOf="parent" /> - () } + fun addStatusChangedListener(tag: String, listener: IStartAutoPilotStatusChanged) { + if (statusChangedListeners.containsKey(tag)) { + statusChangedListeners.remove(tag) + } + statusChangedListeners[tag] = listener + } + + fun removeStatusChangedListener(tag: String) { + statusChangedListeners.remove(tag) + } + } + + private val hasFSM by lazy { AtomicBoolean(false) } + + + init { + LayoutInflater.from(context).inflate(R.layout.view_start_autopilot_status, this, true) + initView() + } + + private fun initView() { + // 默认展示 有 FSM 的情况,未知状态 + changeStatusContainer(true) + handleFSM(FSMStatus(FSMStateCode.UnKnown, "未知")) + } + + /** + * 根据是否有 FSM 切换展示的容器 + */ + private fun changeStatusContainer(hasFSMModule: Boolean) { + CallerLogger.i(TAG, "changeStatusContainer 切换展示,hasFSM=$hasFSMModule") + if (hasFSMModule) { + fSMStatusLayout?.visibility = View.VISIBLE + withoutFSMStatusLayout?.visibility = View.GONE + } else { + fSMStatusLayout?.visibility = View.GONE + withoutFSMStatusLayout?.visibility = View.VISIBLE + } + } + + private fun handleFSM(status: FSMStatus) { + Logger.d(TAG, "--- handleFSM ---:${status.isException()}") + val lastHasFSM = hasFSM.get() + val newHasFSM = status.hasFSMModule() + hasFSM.set(newHasFSM) + if (lastHasFSM != newHasFSM) { + changeStatusContainer(status.hasFSMModule()) + } + + when (status.state) { + FSMStateCode.UnKnown -> { + fSMStatusLayout?.setOnClickListener(null) + fSMStatusLayout?.setImageDrawable( + ContextCompat.getDrawable( + context, + R.drawable.icon_fsm_status_bg_unknown + ) + ) + } + + FSMStateCode.NotExist -> { + fSMStatusLayout?.setOnClickListener(null) + fSMStatusLayout?.setImageDrawable( + ContextCompat.getDrawable( + context, + R.drawable.icon_fsm_status_bg_unknown + ) + ) + } + + FSMStateCode.ExistNormal -> { + fSMStatusLayout?.setOnClickListener(null) + fSMStatusLayout?.setImageDrawable( + ContextCompat.getDrawable( + context, + R.drawable.icon_fsm_status_bg_normal + ) + ) + } + + FSMStateCode.ExistError -> { + // TODO + fSMStatusLayout?.onClick { + ToastUtils.showLong("onClick") + } + fSMStatusLayout?.setImageDrawable( + ContextCompat.getDrawable( + context, + R.drawable.icon_fsm_status_bg_error + ) + ) + } + } + notifyStatus(status.isException()) + } + + private fun handleWithoutFSM(status: Status) { + val isError = + status.isException() && CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo().state != IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING + Logger.d(TAG, "--- handleWithoutFSM ---: $isError") + when (status) { + is GearStatus -> { + val position = try { + Chassis.GearPosition.valueOf(status.value) + } catch (ignore: Throwable) { + Chassis.GearPosition.GEAR_NONE + } + if (tv_gear?.isEnabled == true) { + tv_gear?.isEnabled = false + } + + when (position) { + Chassis.GearPosition.GEAR_N -> { + tv_gear.isEnabled = isError + tv_gear.text = "N" + } + + Chassis.GearPosition.GEAR_R -> { + tv_gear.isEnabled = isError + tv_gear.text = "R" + } + + Chassis.GearPosition.GEAR_P -> { + tv_gear.isEnabled = isError + tv_gear.text = "P" + } + + Chassis.GearPosition.GEAR_D -> { + tv_gear.isEnabled = isError + tv_gear.text = "D" + } + + Chassis.GearPosition.GEAR_NONE -> { + tv_gear.isEnabled = false + tv_gear.text = "" + } + + else -> {} + } + } + + is AcceleratorStatus -> { + iv_accelerator?.isSelected = isError + } + + is BrakeStatus -> { + iv_brake?.isSelected = isError + } + + is DoubleFlashStatus -> { + iv_double_flash?.isSelected = isError + } + + is SteerStatus -> { + iv_steer?.isSelected = isError + } + + is SpeedStatus -> { + // TODO + } + + else -> { + Logger.d(TAG, "other state: $status") + } + } + notifyStatus(isError) + } + + private fun notifyStatus(isError: Boolean) { + statusChangedListeners.values.forEach { itx -> + if (isError) { + itx.onStatusError() + } else { + itx.onStatusNormal() + } + } + } + + + override fun onAttachedToWindow() { + super.onAttachedToWindow() + StatusManager.addListener(TAG, this) + } + + override fun onDetachedFromWindow() { + super.onDetachedFromWindow() + StatusManager.removeListener(TAG) + } + + /** + * @param changed: 变化的数据 + * @param all: 所有状态数据 + */ + override fun onStatusChanged(changed: List, all: List) { + changed.filter { it is IAutopilotPreLaunchStatus }.forEach { status -> + when (status) { + is FSMStatus -> { + handleFSM(status) + } + + else -> { + handleWithoutFSM(status) + } + } + } + } + + interface IStartAutoPilotStatusChanged { + fun onStatusNormal() {} + fun onStatusError() {} + } +} \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/bone/tab/CarInfoTabView.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/bone/tab/CarInfoTabView.kt index 088e99a8c1..9c088e9e2a 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/bone/tab/CarInfoTabView.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/bone/tab/CarInfoTabView.kt @@ -15,4 +15,4 @@ class CarInfoTabView @JvmOverloads constructor( init { LayoutInflater.from(context).inflate(R.layout.view_car_info_tab, this, true) } -}x \ No newline at end of file +} \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/bg_top_status_layout_error.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/bg_top_status_layout_error.png new file mode 100644 index 0000000000..e6aca0cbac Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/bg_top_status_layout_error.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/bg_top_status_layout_normal.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/bg_top_status_layout_normal.png new file mode 100644 index 0000000000..98100cc9fe Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xhdpi/bg_top_status_layout_normal.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/bg_autopilot_status_gear.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/bg_autopilot_status_gear.xml index d706ab642c..e41543ee27 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/bg_autopilot_status_gear.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/bg_autopilot_status_gear.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_bone_container.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_bone_container.xml index 850c7eeb17..ebf8963334 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_bone_container.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_bone_container.xml @@ -12,6 +12,7 @@ app:layout_constraintTop_toTopOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" + android:layout_marginStart="@dimen/dp_19" android:elevation="10dp" android:layout_height="wrap_content"/> diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_bone_top_status.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_bone_top_status.xml index efd2bec56f..ce82045396 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_bone_top_status.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_bone_top_status.xml @@ -1,14 +1,16 @@ + android:layout_height="@dimen/dp_357" + android:background="@drawable/bg_top_status_layout_normal"> - - + app:layout_constraintLeft_toLeftOf="parent"/> + \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_start_autopilot_status.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_start_autopilot_status.xml index 881603c1f0..99c3791b45 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_start_autopilot_status.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_start_autopilot_status.xml @@ -6,15 +6,15 @@ android:layout_height="@dimen/dp_102">