Merge branch 'dev_robotaxi-d_240705_6.5.0' of gitlab.zhidaoauto.com:SCA/L4HA/AndroidApp/MoGoEagleEye into dev_robotaxi-d_240705_6.5.0
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.mogo.eagle.core.function.hmi.ui.notice.traffic
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.os.Message
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@@ -12,8 +14,10 @@ import com.mogo.eagle.core.function.api.datacenter.union.IMoGoTrafficLightListen
|
||||
import com.mogo.eagle.core.function.call.v2x.CallerTrafficLightListenerManager
|
||||
import com.mogo.eagle.core.function.hmi.R
|
||||
import com.mogo.eagle.core.function.hmi.ui.widget.TypefaceTextView
|
||||
import com.mogo.eagle.core.utilcode.mogo.thread.WorkThreadHandler
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* 融合红绿灯变灯提示
|
||||
@@ -34,6 +38,8 @@ class TrafficLightPromptView @JvmOverloads constructor(
|
||||
private var tvPromptContent: TextView ?= null
|
||||
private var tvTrafficNum: TypefaceTextView ?= null
|
||||
private var tvTrafficNumDecimal: TypefaceTextView ?= null
|
||||
private val LIGHT_CHECK = 6501
|
||||
private var startTime: Long = 0L
|
||||
|
||||
init {
|
||||
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.TrafficLightPromptView)
|
||||
@@ -41,6 +47,31 @@ class TrafficLightPromptView @JvmOverloads constructor(
|
||||
typedArray.recycle()
|
||||
}
|
||||
|
||||
// 维护一个线程定时轮询数据进行地图绘制
|
||||
private val mLightHandler: Handler =
|
||||
object : Handler(WorkThreadHandler.newInstance("TrafficLightPromptView").looper){
|
||||
override fun handleMessage(msg: Message) {
|
||||
super.handleMessage(msg)
|
||||
when(msg.what){
|
||||
LIGHT_CHECK->{
|
||||
if(startTime == 0L){
|
||||
sendEmptyMessageDelayed(LIGHT_CHECK, 1000L)
|
||||
return
|
||||
}
|
||||
val endTime = System.nanoTime()
|
||||
val internal = TimeUnit.NANOSECONDS.toMillis(endTime - startTime)
|
||||
if(internal>1500){
|
||||
UiThreadHandler.post{
|
||||
this@TrafficLightPromptView.visibility = GONE
|
||||
}
|
||||
return
|
||||
}
|
||||
sendEmptyMessageDelayed(LIGHT_CHECK, 1000L)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
if(user == 0){
|
||||
@@ -80,7 +111,10 @@ class TrafficLightPromptView @JvmOverloads constructor(
|
||||
ThreadUtils.runOnUiThread {
|
||||
when(currentState){
|
||||
TrafficLightEnum.GREEN->{
|
||||
this@TrafficLightPromptView.visibility = View.VISIBLE
|
||||
if(this@TrafficLightPromptView.visibility == View.GONE){
|
||||
mLightHandler.sendEmptyMessageDelayed(LIGHT_CHECK, 1000L)
|
||||
this@TrafficLightPromptView.visibility = View.VISIBLE
|
||||
}
|
||||
if(user == 0){
|
||||
tvTrafficNum?.setTextColor(ContextCompat.getColor(context,R.color.light_prompt_green))
|
||||
tvTrafficNumDecimal?.setTextColor(ContextCompat.getColor(context,R.color.light_prompt_green))
|
||||
@@ -90,7 +124,10 @@ class TrafficLightPromptView @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
TrafficLightEnum.RED->{
|
||||
this@TrafficLightPromptView.visibility = View.VISIBLE
|
||||
if(this@TrafficLightPromptView.visibility == View.GONE){
|
||||
mLightHandler.sendEmptyMessageDelayed(LIGHT_CHECK, 1000L)
|
||||
this@TrafficLightPromptView.visibility = View.VISIBLE
|
||||
}
|
||||
if(user == 0){
|
||||
tvTrafficNum?.setTextColor(ContextCompat.getColor(context,R.color.light_prompt_red))
|
||||
tvTrafficNumDecimal?.setTextColor(ContextCompat.getColor(context,R.color.light_prompt_red))
|
||||
@@ -100,7 +137,10 @@ class TrafficLightPromptView @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
TrafficLightEnum.YELLOW->{
|
||||
this@TrafficLightPromptView.visibility = View.VISIBLE
|
||||
if(this@TrafficLightPromptView.visibility == View.GONE){
|
||||
mLightHandler.sendEmptyMessageDelayed(LIGHT_CHECK, 1000L)
|
||||
this@TrafficLightPromptView.visibility = View.VISIBLE
|
||||
}
|
||||
if(user == 0){
|
||||
tvTrafficNum?.setTextColor(ContextCompat.getColor(context,R.color.light_prompt_yellow))
|
||||
tvTrafficNumDecimal?.setTextColor(ContextCompat.getColor(context,R.color.light_prompt_yellow))
|
||||
@@ -113,6 +153,7 @@ class TrafficLightPromptView @JvmOverloads constructor(
|
||||
this@TrafficLightPromptView.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
startTime = System.nanoTime()
|
||||
if(currentDuration>0 && currentDuration<5){
|
||||
tvTrafficNum?.text = "${currentDuration.toInt()}."
|
||||
tvTrafficNumDecimal?.text = (currentDuration*100 - currentDuration.toInt()*100).toInt().toString()
|
||||
|
||||
Reference in New Issue
Block a user