diff --git a/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/base/CharterBaseFragment.kt b/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/base/CharterBaseFragment.kt index 04355d8e1d..51c1dd5405 100644 --- a/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/base/CharterBaseFragment.kt +++ b/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/base/CharterBaseFragment.kt @@ -12,6 +12,7 @@ import androidx.constraintlayout.widget.Group import com.magic.mogo.och.charter.R import com.magic.mogo.och.charter.constant.CharterConst import com.magic.mogo.och.charter.view.SlidePanelView +import com.magic.mogo.och.charter.view.autopilot.AutopilotStatusView import com.mogo.commons.mvp.IView import com.mogo.commons.mvp.MvpFragment import com.mogo.commons.mvp.Presenter @@ -54,16 +55,13 @@ abstract class CharterBaseFragment?>() : private val TAG = "BaseBusTabFragment" - private var ctvAutopilotStatus: RelativeLayout? = null - private var ctvAutopilotStatusIv: ImageView? = null - private var ctvAutopilotStatusTv: TextView? = null + private var ctvAutopilotStatus: AutopilotStatusView? = null protected var mSettingBtn: RelativeLayout? = null protected var mBadcaseBtn: RelativeLayout? = null protected var mAICollectBtn: RelativeLayout? = null private var flStationPanelContainer: FrameLayout? = null private var mapBizView: MapBizView? = null private var groupTestPanel: Group? = null - private var mTrafficDataView: TrafficDataView? = null protected var slidePanelView: SlidePanelView? = null //远景和中景的切换 private var mSwitchMapModeImage: ImageView? = null @@ -87,16 +85,13 @@ abstract class CharterBaseFragment?>() : override fun initViews() { mapBizView = findViewById(R.id.mapBizView) groupTestPanel = findViewById(R.id.groupTestPanel) - ctvAutopilotStatus = findViewById(R.id.module_mogo_och_autopilot_status) - ctvAutopilotStatusIv = findViewById(R.id.bus_autopilot_btn_iv) - ctvAutopilotStatusTv = findViewById(R.id.bus_autopolot_btn_tv) + ctvAutopilotStatus = findViewById(R.id.autopilot_status) flStationPanelContainer = findViewById(R.id.module_mogo_och_station_panel_container) slidePanelView = findViewById(R.id.charter_slide_panel) slidePanelView?.setText(resources.getString(R.string.charter_back_car)) slidePanelView?.setOnSlidePanelMoveToEndListener(onSlideToEndListener) - mTrafficDataView = findViewById(R.id.bus_arc) as TrafficDataView? LayoutInflater.from(context).inflate(getStationPanelViewId(), flStationPanelContainer) mSwitchMapModeLayout = findViewById(R.id.bus_switch_model_layout) mSwitchMapModeImage = findViewById(R.id.bus_switch_model_icon) @@ -122,12 +117,6 @@ abstract class CharterBaseFragment?>() : } }) initListener() - setAutopilotBtnStatus(getState()) - ctvAutopilotStatus!!.setOnClickListener(object : OnPreventFastClickListener() { - override fun onClickImpl(v: View) { - restartAutopilot() - } - }) // 模拟 不可自动驾驶,目前场景是刚开机,adas还未和工控机连接 findViewById(R.id.btnAutopilotDisable)!!.setOnClickListener { view: View? -> @@ -194,6 +183,11 @@ abstract class CharterBaseFragment?>() : } }) smallMapView = findViewById(R.id.smallMapView) + + ctvAutopilotStatus?.setOnLongClickListener { + debugTestBar() + true + } } override fun initViews(savedInstanceState: Bundle?) { @@ -308,90 +302,6 @@ abstract class CharterBaseFragment?>() : SoundPoolHelper.getSoundPoolHelper().playSoundWithRedId(context, R.raw.bus_di) } - /** - * 改变自动驾驶状态 - * - * @param autopilotStatus 0:不可用 1:可用状态 2:自动驾驶中 - */ - fun onAutopilotStatusChanged(autopilotStatus: Int) { - requireActivity().runOnUiThread { - changeAutopilotBtnView( - autopilotStatus, - isAnimateRunning - ) - } - } - - private fun setAutopilotBtnStatus(autopilotStatus: Int) { - if (IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE - == autopilotStatus - ) { //0不可用 - ctvAutopilotStatusTv!!.setTextColor(resources.getColor(R.color.charter_autopilot_text_color_disable)) - ctvAutopilotStatusTv!!.text = - resources.getString(R.string.charter_loading_autopilot_runnig_tv) - ctvAutopilotStatusIv!!.setImageResource(R.drawable.charter_disable_autopilot_icon) -// ctvAutopilotStatus!!.isSelected = false - ctvAutopilotStatus!!.isClickable = true - ctvAutopilotStatus!!.background = getDrawable(R.drawable.charter_autopilot_0_1_status_bg) - }else{ - ctvAutopilotStatusTv!!.setTextColor(resources.getColor(R.color.charter_autopilot_text_color_normal)) - ctvAutopilotStatusIv!!.setImageResource(R.drawable.charter_ic_autopilot) - ctvAutopilotStatusTv!!.text = - resources.getString(R.string.charter_loading_autopilot_runnig_tv) - ctvAutopilotStatus!!.isClickable = true - if (IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE == autopilotStatus) { //1可用 - ctvAutopilotStatus!!.background = getDrawable(R.drawable.charter_autopilot_0_1_status_bg) - } else if (IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING == autopilotStatus) { - ctvAutopilotStatus!!.background = getDrawable(R.drawable.charter_autopilot_2_status_bg) - } else if (IMoGoAutopilotStatusListener.STATUS_PARALLEL_DRIVING - == autopilotStatus){ - ctvAutopilotStatusTv!!.text = - resources.getString(R.string.charter_loading_autopilot_pingxing_tv) - ctvAutopilotStatus!!.isClickable = false - ctvAutopilotStatus!!.background = getDrawable(R.drawable.charter_pingxingjiashi) - } - } - } - - open fun updateAutopilotStatus(autopilotStatus: Int) { - if (IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING - == autopilotStatus - ) { //2 running - ctvAutopilotStatusIv!!.setImageResource(R.drawable.charter_right_autopilot_icon) - ctvAutopilotStatusTv!!.setTextColor(resources.getColor(R.color.charter_autopilot_text_color_normal)) - ctvAutopilotStatusTv!!.text = - resources.getString(R.string.charter_loading_autopilot_success_tv) -// ctvAutopilotStatus!!.isSelected = false - ctvAutopilotStatus!!.isClickable = false - } else { - ctvAutopilotStatusIv!!.setImageResource(R.drawable.charter_wrong_autopilot_icon) - ctvAutopilotStatusTv!!.setTextColor(resources.getColor(R.color.charter_autopilot_text_color_normal)) - ctvAutopilotStatusTv!!.text = - resources.getString(R.string.charter_loading_autopilot_failure_tv) - ctvAutopilotStatus!!.isClickable = false -// ctvAutopilotStatus!!.isSelected = false - } - UiThreadHandler.postDelayed({ setAutopilotBtnStatus(autopilotStatus) }, 1000) - } - - private fun changeAutopilotBtnView(autopilotStatus: Int, isAnimateRunning: Boolean) { - if (isAnimateRunning && IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING - != autopilotStatus - ) { - // 主动开启自动驾驶中,不为2(为0、1)则继续loading - return - } - if (isAnimateRunning) { - stopAnimAndUpdateBtnStatus() - } else { - setAutopilotBtnStatus(autopilotStatus) - } - } - - open fun stopAnimAndUpdateBtnStatus() { - stopAutopilotAnimation() - updateAutopilotStatus(getState()) - } /** @@ -408,74 +318,13 @@ abstract class CharterBaseFragment?>() : */ abstract fun getStationPanelViewId(): Int - /** - * 重新开启自动驾驶 - */ - abstract fun restartAutopilot() - /** * 模拟自动驾驶返回状态 * * @param status */ private fun debugAutoPilotStatus(status: Int){ - setAutopilotBtnStatus(status) - } - /** - * 开启自动驾驶中间动画 - */ - @SuppressLint("ObjectAnimatorBinding") - open fun startAutopilotAnimation() { - isAnimateRunning = true - ctvAutopilotStatusTv!!.text = resources.getString(R.string.charter_loading_autopilot_tv) - ctvAutopilotStatusTv!!.setTextColor(resources.getColor(R.color.charter_autopilot_text_color_normal)) -// ctvAutopilotStatus!!.isSelected = false - ctvAutopilotStatus!!.isClickable = true - ctvAutopilotStatusIv!!.setImageResource(R.drawable.charter_loading_autopilot_icon) - if (autopilotLoadingAnimator == null) { - autopilotLoadingAnimator = - ObjectAnimator.ofFloat(ctvAutopilotStatusIv, "rotation", 0f, 360f) - autopilotLoadingAnimator?.interpolator = LinearInterpolator() - autopilotLoadingAnimator?.repeatCount = -1 //无限循环 - autopilotLoadingAnimator?.duration = 1000 //设置持续时间 - } - autopilotLoadingAnimator!!.start() //动画开始 - startingAutoApilotCountDown() - } - - private fun startingAutoApilotCountDown() { - //10s 若自动驾驶没有开启,则结束动画 - UiThreadHandler.postDelayed({ - //未启动成功做处理 - if (isAnimateRunning) { // 只判断动画是否在进行,根据自动驾驶当前状态去设置自动驾驶状态 - stopAutopilotAnimation() - updateAutopilotStatus(getState()) - } - }, CharterConst.TIMER_START_AUTOPILOT_INTERVAL) - } - - /** - * 停止自动驾驶中间动画 - */ - protected open fun stopAutopilotAnimation() { - if (autopilotLoadingAnimator != null) { - autopilotLoadingAnimator!!.end() - ctvAutopilotStatusIv!!.clearAnimation() - autopilotLoadingAnimator = null - isAnimateRunning = false - } - } - - /** - * 迈速表实时更新 - * - * @param newSpeed - */ - open fun updateSpeedView(newSpeed: Float) { - val speed = (abs(newSpeed) * 3.6f).toInt() // 倒车时工控机反馈定位信息中speed为负值 - if (mTrafficDataView != null) { - mTrafficDataView!!.updateSpeedWithValue(speed) - } + ctvAutopilotStatus?.setAutopilotBtnStatus(status) } override fun onDestroy() { diff --git a/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/callback/IBeautifyModeCallback.kt b/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/callback/IBeautifyModeCallback.kt new file mode 100644 index 0000000000..2670f4c73b --- /dev/null +++ b/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/callback/IBeautifyModeCallback.kt @@ -0,0 +1,7 @@ +package com.magic.mogo.och.charter.callback + +import com.magic.mogo.och.charter.manager.BeautifyManager + +interface IBeautifyModeCallback { + fun dispatchStatus(typeEnum: BeautifyManager.ChangeTypeEnum) +} \ No newline at end of file diff --git a/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/fragment/DriverM1Fragment.kt b/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/fragment/DriverM1Fragment.kt index ecf8215f7a..c670bad905 100644 --- a/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/fragment/DriverM1Fragment.kt +++ b/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/fragment/DriverM1Fragment.kt @@ -168,13 +168,6 @@ class DriverM1Fragment : CharterBaseFragment() + + @Volatile + @JvmField + var isBeautifyMode = false + + init { + isBeautifyMode = FunctionBuildConfig.isDemoMode + BizLoopManager.setLoopFunction(TAG, LoopInfo(3, ::checkDemoMode)) + } + + private fun checkDemoMode() { + if(isBeautifyMode!=FunctionBuildConfig.isDemoMode){ + isBeautifyMode = FunctionBuildConfig.isDemoMode + notifyViewChange(ChangeTypeEnum.BEAUTIFY_TYPE) + } + } + + + fun setStatusChangeListener( + tag: String, + orderStatusChangeListener: IBeautifyModeCallback? + ) { + if (tag.isBlank()) return + if (orderStatusChangeListener == null) { + orderStatusChangeListeners.remove(tag) + return + } + orderStatusChangeListeners[tag] = orderStatusChangeListener + } + + + fun notifyViewChange(typeEnum: ChangeTypeEnum){ + CallerLogger.d(TAG,"美化模式变化原因:${typeEnum}") + orderStatusChangeListeners.forEach { + it.value.dispatchStatus(typeEnum) + } + } + +} \ No newline at end of file diff --git a/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/presenter/DriverM1Presenter.kt b/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/presenter/DriverM1Presenter.kt index ab5996a55f..6d8131217c 100644 --- a/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/presenter/DriverM1Presenter.kt +++ b/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/presenter/DriverM1Presenter.kt @@ -36,8 +36,7 @@ import mogo_msg.MogoReportMsg */ class DriverM1Presenter(view: DriverM1Fragment?) : Presenter(view),ILoginCallback, DriverM1OrderCallback, ChangeDestCallback, - IMoGoAutopilotStatusListener, OCHPlanningActionsCallback, - IDriverM1ControllerStatusCallback { + IMoGoAutopilotStatusListener, OCHPlanningActionsCallback{ companion object{ private const val TAG = "DriverM1Presenter" @@ -55,7 +54,6 @@ class DriverM1Presenter(view: DriverM1Fragment?) : StopSideManager.addListener(TAG,this) DriverM1Model.get().setDriverM1OrderCallback(this) DriverM1Model.get().setChangeDestCallback(this) - DriverM1Model.get().setControllerStatusCallback(this) } private fun releaseListener() { @@ -63,7 +61,6 @@ class DriverM1Presenter(view: DriverM1Fragment?) : CallerAutoPilotStatusListenerManager.removeListener(TAG) DriverM1Model.get().setDriverM1OrderCallback(null) DriverM1Model.get().setChangeDestCallback(null) - DriverM1Model.get().setControllerStatusCallback(null) } override fun onDestroy(owner: LifecycleOwner) { @@ -92,13 +89,6 @@ class DriverM1Presenter(view: DriverM1Fragment?) : DriverM1Model.get().logout() } - fun restartAutopilot() { - // todo 启动自驾必须有订单路线 - if (DriverM1Model.get().isHaveOrder()) { - DriverM1Model.get().restartAutopilot() - } - } - fun driverEndLease() { DriverM1Model.get().driverEndLease() } @@ -145,7 +135,6 @@ class DriverM1Presenter(view: DriverM1Fragment?) : } override fun onAutopilotStatusResponse(state: Int) { - mView?.onAutopilotStatusChanged(state) when(state){ // IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE -> { // // @@ -193,21 +182,4 @@ class DriverM1Presenter(view: DriverM1Fragment?) : } } - override fun startOpenAutopilot() { - ThreadUtils.runOnUiThread { - mView?.startAutopilotAnimation() - } - } - - override fun onStartAdasFailure() { - ThreadUtils.runOnUiThread { - mView?.stopAnimAndUpdateBtnStatus() - } - } - - override fun updateSpeed(gnssInfo: MogoLocation) { - ThreadUtils.runOnUiThread { - mView?.updateSpeedView(gnssInfo.gnssSpeed) - } - } } diff --git a/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/view/autopilot/AutopilotStatusView.kt b/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/view/autopilot/AutopilotStatusView.kt new file mode 100644 index 0000000000..3575f1593e --- /dev/null +++ b/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/view/autopilot/AutopilotStatusView.kt @@ -0,0 +1,189 @@ +package com.magic.mogo.och.charter.view.autopilot + +import android.animation.ObjectAnimator +import android.content.Context +import android.util.AttributeSet +import android.view.LayoutInflater +import android.view.animation.LinearInterpolator +import android.widget.RelativeLayout +import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.findViewTreeViewModelStoreOwner +import com.magic.mogo.och.charter.R +import com.magic.mogo.och.charter.constant.CharterConst +import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager +import com.mogo.eagle.core.utilcode.kotlin.onClick +import com.mogo.eagle.core.utilcode.util.ResourceUtils +import com.mogo.eagle.core.utilcode.util.UiThreadHandler +import kotlinx.android.synthetic.main.charter_autopilot_status.view.bus_autopilot_btn_iv +import kotlinx.android.synthetic.main.charter_autopilot_status.view.bus_autopolot_btn_tv + +/** + * 剩余时间和结束订单入口 + */ +class AutopilotStatusView : RelativeLayout,AutopilotStatusViewModel.IAutopilotStatusCallback { + + private val TAG = "AutopilotStatusView" + + constructor(context: Context) : super(context) + + constructor(context: Context, attributeSet: AttributeSet) : super(context, attributeSet) + + constructor(context: Context, attributeSet: AttributeSet, defStyleAttr: Int) : super( + context, + attributeSet, + defStyleAttr + ) + + var viewModel:AutopilotStatusViewModel?=null + + var isAnimateRunning = false + + private var autopilotLoadingAnimator: ObjectAnimator? = null + + private fun initView() { + LayoutInflater.from(context).inflate(R.layout.charter_autopilot_status, this, true) + onClick { + if (!isAnimateRunning) { + viewModel?.restartAutopilot() + } + } + } + + override fun startAutopilotAnimation() { + isAnimateRunning = true + bus_autopolot_btn_tv!!.text = resources.getString(R.string.charter_loading_autopilot_tv) + bus_autopolot_btn_tv!!.setTextColor(resources.getColor(R.color.charter_autopilot_text_color_normal)) +// ctvAutopilotStatus!!.isSelected = false + isClickable = true + bus_autopilot_btn_iv!!.setImageResource(R.drawable.charter_loading_autopilot_icon) + if (autopilotLoadingAnimator == null) { + autopilotLoadingAnimator = + ObjectAnimator.ofFloat(bus_autopilot_btn_iv, "rotation", 0f, 360f) + autopilotLoadingAnimator?.interpolator = LinearInterpolator() + autopilotLoadingAnimator?.repeatCount = -1 //无限循环 + autopilotLoadingAnimator?.duration = 1000 //设置持续时间 + } + autopilotLoadingAnimator!!.start() //动画开始 + startingAutoApilotCountDown() + } + + override fun stopAnimAndUpdateBtnStatus() { + stopAutopilotAnimation() + updateAutopilotStatus(CallerAutoPilotStatusListenerManager.getState()) + } + + override fun onAutopilotStatusChanged(autopilotStatus: Int) { + if (isAnimateRunning && IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING + != autopilotStatus + ) { + // 主动开启自动驾驶中,不为2(为0、1)则继续loading + return + } + if (isAnimateRunning) { + stopAnimAndUpdateBtnStatus() + } else { + setAutopilotBtnStatus(autopilotStatus) + } + } + + private fun startingAutoApilotCountDown() { + //10s 若自动驾驶没有开启,则结束动画 + UiThreadHandler.postDelayed({ + //未启动成功做处理 + if (isAnimateRunning) { // 只判断动画是否在进行,根据自动驾驶当前状态去设置自动驾驶状态 + stopAutopilotAnimation() + updateAutopilotStatus(CallerAutoPilotStatusListenerManager.getState()) + } + }, CharterConst.TIMER_START_AUTOPILOT_INTERVAL) + } + + fun updateAutopilotStatus(autopilotStatus: Int) { + if (IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING + == autopilotStatus + ) { //2 running + bus_autopilot_btn_iv!!.setImageResource(R.drawable.charter_right_autopilot_icon) + bus_autopolot_btn_tv!!.setTextColor(resources.getColor(R.color.charter_autopilot_text_color_normal)) + bus_autopolot_btn_tv!!.text = + resources.getString(R.string.charter_loading_autopilot_success_tv) +// ctvAutopilotStatus!!.isSelected = false + isClickable = false + } else { + bus_autopilot_btn_iv!!.setImageResource(R.drawable.charter_wrong_autopilot_icon) + bus_autopolot_btn_tv!!.setTextColor(resources.getColor(R.color.charter_autopilot_text_color_normal)) + bus_autopolot_btn_tv!!.text = + resources.getString(R.string.charter_loading_autopilot_failure_tv) + isClickable = false +// ctvAutopilotStatus!!.isSelected = false + } + UiThreadHandler.postDelayed({ setAutopilotBtnStatus(autopilotStatus) }, 1000) + } + + fun setAutopilotBtnStatus(autopilotStatus: Int) { + if (IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE + == autopilotStatus + ) { //0不可用 + bus_autopolot_btn_tv!!.setTextColor(resources.getColor(R.color.charter_autopilot_text_color_disable)) + bus_autopolot_btn_tv!!.text = + resources.getString(R.string.charter_loading_autopilot_runnig_tv) + bus_autopilot_btn_iv!!.setImageResource(R.drawable.charter_disable_autopilot_icon) +// ctvAutopilotStatus!!.isSelected = false + isClickable = true + background = ResourceUtils.getDrawable(R.drawable.charter_autopilot_0_1_status_bg) + }else{ + bus_autopolot_btn_tv!!.setTextColor(resources.getColor(R.color.charter_autopilot_text_color_normal)) + bus_autopilot_btn_iv!!.setImageResource(R.drawable.charter_ic_autopilot) + bus_autopolot_btn_tv!!.text = + resources.getString(R.string.charter_loading_autopilot_runnig_tv) + isClickable = true + if (IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE == autopilotStatus) { //1可用 + background = + ResourceUtils.getDrawable(R.drawable.charter_autopilot_0_1_status_bg) + } else if (IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING == autopilotStatus) { + background = + ResourceUtils.getDrawable(R.drawable.charter_autopilot_2_status_bg) + } else if (IMoGoAutopilotStatusListener.STATUS_PARALLEL_DRIVING == autopilotStatus){ + bus_autopolot_btn_tv!!.text = + resources.getString(R.string.charter_loading_autopilot_pingxing_tv) + isClickable = false + background = ResourceUtils.getDrawable(R.drawable.charter_pingxingjiashi) + } + } + } + + /** + * 停止自动驾驶中间动画 + */ + protected open fun stopAutopilotAnimation() { + if (autopilotLoadingAnimator != null) { + autopilotLoadingAnimator!!.end() + bus_autopilot_btn_iv!!.clearAnimation() + autopilotLoadingAnimator = null + isAnimateRunning = false + } + } + + override fun onAttachedToWindow() { + super.onAttachedToWindow() + viewModel = findViewTreeViewModelStoreOwner()?.let { + ViewModelProvider(it).get(AutopilotStatusViewModel::class.java) + } + viewModel?.setAutopilotStatusCallback(this) + setAutopilotBtnStatus(CallerAutoPilotStatusListenerManager.getState()) + } + + override fun onDetachedFromWindow() { + super.onDetachedFromWindow() + } + + + init { + try { + initView() + } catch (e: Exception) { + e.printStackTrace() + } + } + + +} \ No newline at end of file diff --git a/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/view/autopilot/AutopilotStatusViewModel.kt b/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/view/autopilot/AutopilotStatusViewModel.kt new file mode 100644 index 0000000000..8e398b6b57 --- /dev/null +++ b/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/view/autopilot/AutopilotStatusViewModel.kt @@ -0,0 +1,68 @@ +package com.magic.mogo.och.charter.view.autopilot + +import androidx.lifecycle.ViewModel +import com.magic.mogo.och.charter.callback.IDriverM1ControllerStatusCallback +import com.magic.mogo.och.charter.model.DriverM1Model +import com.mogo.eagle.core.data.map.MogoLocation +import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager +import com.mogo.eagle.core.utilcode.util.ThreadUtils + +class AutopilotStatusViewModel: ViewModel(), IDriverM1ControllerStatusCallback, + IMoGoAutopilotStatusListener { + + private val TAG = AutopilotStatusViewModel::class.java.simpleName + + private var viewCallback:IAutopilotStatusCallback?=null + + + init { + DriverM1Model.get().setControllerStatusCallback(this) + } + + override fun onCleared() { + super.onCleared() + this.viewCallback = null + CallerAutoPilotStatusListenerManager.removeListener(TAG) + } + + fun setAutopilotStatusCallback(viewCallback:IAutopilotStatusCallback){ + this.viewCallback = viewCallback + CallerAutoPilotStatusListenerManager.addListener(TAG, this) + } + + fun restartAutopilot() { + // todo 启动自驾必须有订单路线 + if (DriverM1Model.get().isHaveOrder()) { + DriverM1Model.get().restartAutopilot() + } + } + + interface IAutopilotStatusCallback{ + fun startAutopilotAnimation() + fun stopAnimAndUpdateBtnStatus() + fun onAutopilotStatusChanged(state: Int) + } + + override fun startOpenAutopilot() { + ThreadUtils.runOnUiThread( { + this.viewCallback?.startAutopilotAnimation() + },ThreadUtils.MODE.QUEUE) + } + + override fun onStartAdasFailure() { + ThreadUtils.runOnUiThread( { + this.viewCallback?.stopAnimAndUpdateBtnStatus() + },ThreadUtils.MODE.QUEUE) + } + + override fun updateSpeed(gnssInfo: MogoLocation) { + } + + override fun onAutopilotStatusResponse(state: Int) { + ThreadUtils.runOnUiThread( { + this.viewCallback?.onAutopilotStatusChanged(state) + },ThreadUtils.MODE.QUEUE) + } + +} \ No newline at end of file diff --git a/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/view/carstatus/CarStatusView.kt b/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/view/carstatus/CarStatusView.kt new file mode 100644 index 0000000000..3ea6d0e068 --- /dev/null +++ b/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/view/carstatus/CarStatusView.kt @@ -0,0 +1,40 @@ +package com.magic.mogo.och.charter.view.carstatus + +import android.content.Context +import android.util.AttributeSet +import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.findViewTreeViewModelStoreOwner +import com.mogo.eagle.core.function.hmi.ui.widget.TrafficDataView + +class CarStatusView : TrafficDataView, CarStatusViewModel.ICarStatusCallback { + + private val TAG = "CarStatusView" + + constructor(context: Context) : super(context) + + constructor(context: Context, attributeSet: AttributeSet) : super(context, attributeSet) + + constructor(context: Context, attributeSet: AttributeSet, defStyleAttr: Int) : super( + context, + attributeSet, + defStyleAttr + ) + + var viewModel:CarStatusViewModel?=null + + override fun onAttachedToWindow() { + super.onAttachedToWindow() + viewModel = findViewTreeViewModelStoreOwner()?.let { + ViewModelProvider(it).get(CarStatusViewModel::class.java) + } + viewModel?.setAutopilotStatusCallback(this) + } + + override fun onDetachedFromWindow() { + super.onDetachedFromWindow() + } + + override fun updateSpeedWithCurrentValue(speed: Int) { + updateSpeedWithValue(speed) + } +} \ No newline at end of file diff --git a/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/view/carstatus/CarStatusViewModel.kt b/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/view/carstatus/CarStatusViewModel.kt new file mode 100644 index 0000000000..c64e42e8b9 --- /dev/null +++ b/OCH/charter/driver/src/main/java/com/magic/mogo/och/charter/view/carstatus/CarStatusViewModel.kt @@ -0,0 +1,48 @@ +package com.magic.mogo.och.charter.view.carstatus + +import androidx.lifecycle.ViewModel +import com.magic.mogo.och.charter.model.DriverM1Model +import com.mogo.eagle.core.data.map.MogoLocation +import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener +import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener +import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager +import com.mogo.eagle.core.utilcode.util.ThreadUtils +import kotlin.math.abs + +class CarStatusViewModel: ViewModel(), IMoGoAutopilotStatusListener, + IMoGoChassisLocationGCJ02Listener { + + private val TAG = CarStatusViewModel::class.java.simpleName + + private var viewCallback:ICarStatusCallback?=null + + + init { + + } + + override fun onCleared() { + super.onCleared() + this.viewCallback = null + CallerChassisLocationGCJ02ListenerManager.removeListener(DriverM1Model.TAG) + } + + fun setAutopilotStatusCallback(viewCallback:ICarStatusCallback){ + this.viewCallback = viewCallback + CallerChassisLocationGCJ02ListenerManager.addListener(DriverM1Model.TAG, 10, this) + } + + interface ICarStatusCallback{ + fun updateSpeedWithCurrentValue(speed:Int) + } + + override fun onChassisLocationGCJ02(mogoLocation: MogoLocation?) { + mogoLocation?.let { + val speed = (abs(it.gnssSpeed) * 3.6f).toInt() // 倒车时工控机反馈定位信息中speed为负值 + ThreadUtils.runOnUiThread( { + viewCallback?.updateSpeedWithCurrentValue(speed) + },ThreadUtils.MODE.QUEUE) + } + } + +} \ No newline at end of file diff --git a/OCH/charter/driver/src/main/res/layout/charter_autopilot_status.xml b/OCH/charter/driver/src/main/res/layout/charter_autopilot_status.xml new file mode 100644 index 0000000000..ae9faef3d4 --- /dev/null +++ b/OCH/charter/driver/src/main/res/layout/charter_autopilot_status.xml @@ -0,0 +1,30 @@ + + + + + + + \ No newline at end of file diff --git a/OCH/charter/driver/src/main/res/layout/charter_base_fragment.xml b/OCH/charter/driver/src/main/res/layout/charter_base_fragment.xml index 8497b888f8..b34a7b46ba 100644 --- a/OCH/charter/driver/src/main/res/layout/charter_base_fragment.xml +++ b/OCH/charter/driver/src/main/res/layout/charter_base_fragment.xml @@ -29,7 +29,7 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" /> - + app:layout_constraintTop_toTopOf="parent"/> - - - - - + tools:visibility="visible" + android:layout_marginLeft="@dimen/dp_13"/> - - - - - diff --git a/OCH/charter/passenger/src/main/java/com/mogo/och/charter/passenger/utils/BeautifyManager.kt b/OCH/charter/passenger/src/main/java/com/mogo/och/charter/passenger/utils/BeautifyManager.kt index 071c5de7ab..aab0b204bb 100644 --- a/OCH/charter/passenger/src/main/java/com/mogo/och/charter/passenger/utils/BeautifyManager.kt +++ b/OCH/charter/passenger/src/main/java/com/mogo/och/charter/passenger/utils/BeautifyManager.kt @@ -52,7 +52,7 @@ object BeautifyManager { fun notifyViewChange(typeEnum: ChangeTypeEnum){ - CallerLogger.d(StatusBarView.TAG,"美化模式变化原因:${typeEnum}") + CallerLogger.d(TAG,"美化模式变化原因:${typeEnum}") orderStatusChangeListeners.forEach { it.value.dispatchStatus(typeEnum) }