From a7ede024913256977010bec9fff9ac6e1f4fe0da Mon Sep 17 00:00:00 2001 From: chenfufeng Date: Wed, 20 Sep 2023 11:52:19 +0800 Subject: [PATCH] =?UTF-8?q?[6.1.0][Opt=E6=96=B0=E5=A2=9E=E5=B9=B3=E8=A1=8C?= =?UTF-8?q?=E9=A9=BE=E9=A9=B6=E8=AF=B7=E6=B1=82=E4=B8=AD=E5=8A=A8=E7=94=BB?= =?UTF-8?q?=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmi/ui/widget/ParallelDriveView.kt | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/ParallelDriveView.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/ParallelDriveView.kt index 0d5c9d93b4..79b85ef6d7 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/ParallelDriveView.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/ParallelDriveView.kt @@ -1,16 +1,18 @@ package com.mogo.eagle.core.function.hmi.ui.widget +import android.animation.ObjectAnimator +import android.animation.ValueAnimator import android.annotation.SuppressLint import android.content.Context import android.graphics.Color import android.util.AttributeSet import android.view.LayoutInflater +import android.view.animation.LinearInterpolator import android.widget.ImageView import android.widget.TextView import androidx.constraintlayout.widget.ConstraintLayout import com.mogo.cloud.passport.MoGoAiCloudClientConfig import com.mogo.commons.voice.AIAssist -import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotActionsListener import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener import com.mogo.eagle.core.function.api.autopilot.IMoGoParallelDrivingActionsListener import com.mogo.eagle.core.function.api.autopilot.IMoGoParallelDrivingStatusListener @@ -22,7 +24,6 @@ import com.mogo.eagle.core.function.hmi.R import com.mogo.eagle.core.utilcode.util.ThreadUtils import com.mogo.eagle.core.utilcode.util.ToastUtils import com.zhjt.mogo.adas.data.bean.UnableLaunchReason -import com.zhjt.mogo.adas.data.bean.UnableLaunchReason.SourceType import mogo.yycp.paralleldriving.protocol.ParallelDrivingRequest.ParallelRequest import mogo.yycp.paralleldriving.protocol.ParallelTaskProcessNoticeOuterClass @@ -50,6 +51,7 @@ class ParallelDriveView @JvmOverloads constructor( //1:ready, 2:自动驾驶中, 7:平行驾驶中 @Volatile private var autopilotState: Int = 1 + @Volatile private var isAutoDriving: Boolean = false @@ -60,6 +62,7 @@ class ParallelDriveView @JvmOverloads constructor( private lateinit var statusIcon: ImageView private lateinit var statusTitle: TextView private var listener: ClickEventListener? = null + private var animator: ObjectAnimator? = null init { LayoutInflater.from(context).inflate(R.layout.view_parallel_drive, this, true) @@ -115,11 +118,13 @@ class ParallelDriveView @JvmOverloads constructor( }, ThreadUtils.MODE.QUEUE) } } + 2 -> { if (this.autopilotState != state) { isAutoDriving = true } } + else -> { if (this.autopilotState != state) { isAutoDriving = false @@ -161,30 +166,37 @@ class ParallelDriveView @JvmOverloads constructor( state = SYNCHRONIZING updateUI(SYNCHRONIZING) } + "EXCEPTION_EXIT_SYNC" -> {// 同步异常结束 state = ONE_EXCEPTION updateUI(ONE_EXCEPTION) } + "TASK_REJECTED" -> {// 任务已被拒绝 state = FAILURE updateUI(FAILURE) AIAssist.getInstance(context).speakTTSVoice("请求已被拒绝") } + "PARALLEL_EXCEPTION_MANUAL_DRIVING" -> {// 异常请人工驾驶 state = TWO_EXCEPTION updateUI(TWO_EXCEPTION) } + "EXCEPTION_EXIT_PARALLEL_DRIVING" -> {// 平行驾驶异常结束 state = ONE_EXCEPTION updateUI(ONE_EXCEPTION) } + "EXIT_SYNC" -> {// 同步结束 checkAvailableAndUpdateUI() } + "UNABLE_TAKEOVER" -> {// 无法接管 state = ONE_EXCEPTION updateUI(ONE_EXCEPTION) } + "VEHICLE_IN_TROUBLE_PARALLEL_REQUESTED" -> {// 车辆遇困请求平行驾驶 state = AD_REQUESTING updateUI(AD_REQUESTING) @@ -198,6 +210,7 @@ class ParallelDriveView @JvmOverloads constructor( private fun updateUI(state: Int) { when (state) { 0 -> { + stopRotateAnimation() rootLayout.isEnabled = true rootLayout.alpha = 1f statusIcon.background = @@ -215,6 +228,7 @@ class ParallelDriveView @JvmOverloads constructor( resources.getDrawable(R.drawable.icon_para_requesting, null) statusTitle.setTextColor(Color.parseColor("#FFFFFF")) statusIcon.alpha = 1f + startRotateAnimation() statusTitle.text = context.getString(R.string.parallel_drive_requesting) rootLayout.background = resources.getDrawable(R.drawable.bg_auto_pilot, null) } @@ -226,11 +240,13 @@ class ParallelDriveView @JvmOverloads constructor( resources.getDrawable(R.drawable.icon_para_requesting, null) statusTitle.setTextColor(Color.parseColor("#FFFFFF")) statusIcon.alpha = 1f + startRotateAnimation() statusTitle.text = context.getString(R.string.parallel_drive_requesting) rootLayout.background = resources.getDrawable(R.drawable.bg_auto_pilot, null) } SYNCHRONIZING -> { + stopRotateAnimation() rootLayout.isEnabled = false rootLayout.alpha = 1f statusIcon.background = @@ -242,6 +258,7 @@ class ParallelDriveView @JvmOverloads constructor( } PARALLEL_DRIVING -> { + stopRotateAnimation() rootLayout.isEnabled = false rootLayout.alpha = 1f statusIcon.background = @@ -254,6 +271,7 @@ class ParallelDriveView @JvmOverloads constructor( } FAILURE -> { + stopRotateAnimation() rootLayout.isEnabled = false rootLayout.alpha = 1f rootLayout.postDelayed({ @@ -268,6 +286,7 @@ class ParallelDriveView @JvmOverloads constructor( } ONE_EXCEPTION -> { + stopRotateAnimation() rootLayout.isEnabled = false rootLayout.alpha = 1f rootLayout.postDelayed({ @@ -282,6 +301,7 @@ class ParallelDriveView @JvmOverloads constructor( } TWO_EXCEPTION -> { + stopRotateAnimation() rootLayout.isEnabled = false rootLayout.alpha = 1f rootLayout.postDelayed({ @@ -296,6 +316,7 @@ class ParallelDriveView @JvmOverloads constructor( } UNAVAILABLE -> { + stopRotateAnimation() rootLayout.isEnabled = false rootLayout.alpha = 0.4f statusIcon.background = @@ -351,6 +372,27 @@ class ParallelDriveView @JvmOverloads constructor( } } + @SuppressLint("Recycle") + private fun startRotateAnimation() { + if (animator == null) { + animator = ObjectAnimator.ofFloat(statusIcon, "rotation", 0f, 360f).apply { + duration = 1500 + repeatMode = ValueAnimator.RESTART + repeatCount = ValueAnimator.INFINITE + interpolator = LinearInterpolator() + } + } + animator?.start() + } + + private fun stopRotateAnimation() { + animator?.let { + if (it.isRunning) { + it.cancel() + } + } + } + override fun onDetachedFromWindow() { super.onDetachedFromWindow() CallerAutoPilotStatusListenerManager.removeListener(TAG)