[6.2.6]
[shuttle-jl] [灯UI och]
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package com.mogo.och.common.module.manager.lightmanager
|
||||
|
||||
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLamplightListener
|
||||
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLamplightListenerManager
|
||||
|
||||
object BreakLightManager : IMoGoChassisLamplightListener {
|
||||
private const val TAG = "BreakLightManager"
|
||||
init {
|
||||
CallerChassisLamplightListenerManager.addListener(TAG, this)
|
||||
}
|
||||
|
||||
// 刹车灯
|
||||
override fun onAutopilotBrakeLightData(brakeLight: Boolean) {
|
||||
super.onAutopilotBrakeLightData(brakeLight)
|
||||
}
|
||||
|
||||
enum class BreakLightStatus{
|
||||
BREAK_LIGHT,
|
||||
BREAK_NONE,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.mogo.och.common.module.manager.lightmanager
|
||||
|
||||
import chassis.Chassis
|
||||
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLamplightListener
|
||||
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLamplightListenerManager
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
object TurnLightManager : IMoGoChassisLamplightListener {
|
||||
private const val TAG = "TurnLightManager"
|
||||
|
||||
private val lightStatusChange: ConcurrentHashMap<String, TurnLightListener> =
|
||||
ConcurrentHashMap()
|
||||
|
||||
private var turnLightStatus:TurnLightStatus by Delegates.observable(TurnLightStatus.TURN_LIGHT_NONE) { _, oldValue, newValue ->
|
||||
if (oldValue != newValue) {
|
||||
if(lightStatusChange.size>0){
|
||||
lightStatusChange.forEach {
|
||||
it.value.statusChange(newValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
CallerChassisLamplightListenerManager.addListener(TAG, this)
|
||||
}
|
||||
|
||||
fun addTurnLightStatusChangeListener(tag: String, listener: TurnLightListener) {
|
||||
if (lightStatusChange.containsKey(tag)) {
|
||||
return
|
||||
}
|
||||
lightStatusChange[tag] = listener
|
||||
listener.statusChange(turnLightStatus)
|
||||
}
|
||||
|
||||
|
||||
// 转向灯
|
||||
override fun onAutopilotLightSwitchData(lightSwitch: Chassis.LightSwitch?) {
|
||||
super.onAutopilotLightSwitchData(lightSwitch)
|
||||
lightSwitch?.let {
|
||||
when (it.number) {
|
||||
Chassis.LightSwitch.LIGHT_LEFT_VALUE -> {
|
||||
turnLightStatus = TurnLightStatus.TURN_LIGHT_LEFT
|
||||
}
|
||||
Chassis.LightSwitch.LIGHT_RIGHT_VALUE -> {
|
||||
turnLightStatus = TurnLightStatus.TURN_LIGHT_RIGHT
|
||||
}
|
||||
Chassis.LightSwitch.LIGHT_NONE_VALUE -> {
|
||||
turnLightStatus = TurnLightStatus.TURN_LIGHT_NONE
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface TurnLightListener{
|
||||
fun statusChange(newStatus: TurnLightStatus)
|
||||
}
|
||||
|
||||
enum class TurnLightStatus{
|
||||
TURN_LIGHT_LEFT,
|
||||
TURN_LIGHT_RIGHT,
|
||||
TURN_LIGHT_NONE,
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,199 @@
|
||||
package com.mogo.och.shuttle.passenger.ui.widget
|
||||
|
||||
import android.animation.AnimatorSet
|
||||
import android.animation.ObjectAnimator
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import com.mogo.eagle.core.function.hmi.ui.vehicle.TurnLightViewStatus
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.animation.AlphaAnimation
|
||||
import android.view.animation.Animation
|
||||
import android.widget.ImageView
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import com.mogo.eagle.core.function.api.datacenter.union.IMoGoTurnLightListener
|
||||
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLamplightListenerManager
|
||||
import com.mogo.eagle.core.function.call.v2x.CallerTurnLightListenerManager
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.och.bus.passenger.R
|
||||
import com.mogo.och.common.module.manager.lightmanager.TurnLightManager
|
||||
import kotlinx.android.synthetic.main.shuttle_p_jl_turn_light_status.view.left_nor_image
|
||||
import kotlinx.android.synthetic.main.shuttle_p_jl_turn_light_status.view.left_select_image
|
||||
import kotlinx.android.synthetic.main.shuttle_p_jl_turn_light_status.view.right_nor_image
|
||||
import kotlinx.android.synthetic.main.shuttle_p_jl_turn_light_status.view.right_select_image
|
||||
import kotlinx.android.synthetic.main.shuttle_p_jl_turn_light_status.view.turn_light_layout
|
||||
|
||||
/**
|
||||
* @author: wangmingjun
|
||||
* @date: 2023/2/13
|
||||
*/
|
||||
class BusPTurnLightView @JvmOverloads constructor(
|
||||
context: Context, attrs: AttributeSet? = null
|
||||
) : TurnLightViewStatus(context, attrs) {
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : ConstraintLayout(context, attrs, defStyleAttr),
|
||||
IMoGoTurnLightListener, TurnLightManager.TurnLightListener {
|
||||
|
||||
|
||||
companion object {
|
||||
private const val TAG = "TurnLightViewStatus"
|
||||
}
|
||||
|
||||
private var isLeftLight: Boolean = false
|
||||
private var isRightLight: Boolean = false
|
||||
private var isDisappear: Boolean = false
|
||||
|
||||
init {
|
||||
LayoutInflater.from(context)
|
||||
.inflate(R.layout.shuttle_p_jl_turn_light_status, this, true)
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
CallerTurnLightListenerManager.addListener(TAG,this)
|
||||
|
||||
TurnLightManager.addTurnLightStatusChangeListener(TAG,this)
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
CallerChassisLamplightListenerManager.removeListener(TAG)
|
||||
CallerTurnLightListenerManager.removeListener(TAG)
|
||||
}
|
||||
|
||||
override fun hideTurnLightView() {
|
||||
ThreadUtils.runOnUiThread{
|
||||
if (!isDisappear) {
|
||||
isDisappear = true
|
||||
isLeftLight = false
|
||||
isRightLight = false
|
||||
animationDisappear()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun statusChange(newStatus: TurnLightManager.TurnLightStatus) {
|
||||
ThreadUtils.runOnUiThread {
|
||||
setTurnLight(newStatus)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转向灯动画
|
||||
*/
|
||||
private fun setTurnLight(directionLight: TurnLightManager.TurnLightStatus) {
|
||||
if (!isAttachedToWindow) {
|
||||
return
|
||||
}
|
||||
//根据左右进行显示和隐藏,实际要判断每个来的时间和频度
|
||||
when (directionLight) {
|
||||
TurnLightManager.TurnLightStatus.TURN_LIGHT_LEFT -> { //左转向
|
||||
if (!isLeftLight) {
|
||||
isLeftLight = true
|
||||
isRightLight = false
|
||||
isDisappear = false
|
||||
showNormalAnimation()
|
||||
left_select_image.visibility = View.VISIBLE
|
||||
right_select_image.visibility = View.GONE
|
||||
right_select_image.clearAnimation()
|
||||
setAnimation(left_select_image)
|
||||
}
|
||||
}
|
||||
TurnLightManager.TurnLightStatus.TURN_LIGHT_RIGHT -> { //右转向
|
||||
if (!isRightLight) {
|
||||
isRightLight = true
|
||||
isLeftLight = false
|
||||
isDisappear = false
|
||||
showNormalAnimation()
|
||||
left_select_image.visibility = View.GONE
|
||||
right_select_image.visibility = View.VISIBLE
|
||||
left_select_image.clearAnimation()
|
||||
setAnimation(right_select_image)
|
||||
}
|
||||
}
|
||||
TurnLightManager.TurnLightStatus.TURN_LIGHT_NONE -> { //消失
|
||||
if (!isDisappear) {
|
||||
isDisappear = true
|
||||
isLeftLight = false
|
||||
isRightLight = false
|
||||
animationDisappear()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//显示背景
|
||||
private fun showNormalAnimation() {
|
||||
val appearAnimation = AlphaAnimation(0f, 1.0f)
|
||||
appearAnimation.duration = 300
|
||||
val appearAnimationImage = AlphaAnimation(0f, 1.0f)
|
||||
appearAnimation.duration = 500
|
||||
turn_light_layout.startAnimation(appearAnimation)
|
||||
left_nor_image.startAnimation(appearAnimationImage)
|
||||
right_nor_image.startAnimation(appearAnimationImage)
|
||||
|
||||
turn_light_layout.visibility = View.VISIBLE
|
||||
left_nor_image.visibility = View.VISIBLE
|
||||
right_nor_image.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
//消失动画,当转向等数据为空时候
|
||||
private fun animationDisappear() {
|
||||
left_select_image.visibility = View.GONE
|
||||
right_select_image.visibility = View.GONE
|
||||
left_select_image.clearAnimation()
|
||||
right_select_image.clearAnimation()
|
||||
|
||||
left_nor_image.clearAnimation()
|
||||
right_nor_image.clearAnimation()
|
||||
turn_light_layout.clearAnimation()
|
||||
|
||||
val disappearAnimationLeft = AlphaAnimation(1.0f, 0f)
|
||||
disappearAnimationLeft.duration = 300
|
||||
|
||||
val disappearAnimationBg = AlphaAnimation(1.0f, 0f)
|
||||
disappearAnimationBg.duration = 500
|
||||
|
||||
left_nor_image.startAnimation(disappearAnimationLeft)
|
||||
right_nor_image.startAnimation(disappearAnimationLeft)
|
||||
turn_light_layout.startAnimation(disappearAnimationBg)
|
||||
|
||||
disappearAnimationLeft.setAnimationListener(object : Animation.AnimationListener {
|
||||
override fun onAnimationRepeat(p0: Animation?) {
|
||||
}
|
||||
|
||||
override fun onAnimationStart(p0: Animation?) {
|
||||
}
|
||||
|
||||
override fun onAnimationEnd(p0: Animation?) {
|
||||
left_nor_image.visibility = View.GONE
|
||||
right_nor_image.visibility = View.GONE
|
||||
}
|
||||
})
|
||||
|
||||
disappearAnimationBg.setAnimationListener(object : Animation.AnimationListener {
|
||||
override fun onAnimationRepeat(p0: Animation?) {
|
||||
}
|
||||
|
||||
override fun onAnimationStart(p0: Animation?) {
|
||||
}
|
||||
|
||||
override fun onAnimationEnd(p0: Animation?) {
|
||||
turn_light_layout.visibility = View.GONE
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//实现图片闪烁效果
|
||||
private fun setAnimation(imageView: ImageView) {
|
||||
val animationSet = AnimatorSet()
|
||||
val valueAnimator = ObjectAnimator.ofFloat(imageView, "alpha", 0f, 1.0f)
|
||||
val valueAnimatorDisappear = ObjectAnimator.ofFloat(imageView, "alpha", 1.0f, 0f)
|
||||
valueAnimator.duration = 1000
|
||||
valueAnimatorDisappear.duration = 800
|
||||
valueAnimator.repeatCount = -1
|
||||
valueAnimatorDisappear.repeatCount = -1
|
||||
animationSet.playTogether(valueAnimatorDisappear, valueAnimator)
|
||||
animationSet.start()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -114,11 +114,9 @@
|
||||
android:layout_width="@dimen/dp_104"
|
||||
android:layout_height="@dimen/dp_58"
|
||||
android:layout_marginLeft="@dimen/dp_20"
|
||||
app:day_light_mode="true"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/auto_status_iv"
|
||||
app:layout_constraintLeft_toRightOf="@+id/auto_status_iv"
|
||||
app:layout_constraintTop_toTopOf="@+id/auto_status_iv"
|
||||
app:visible="false" />
|
||||
app:layout_constraintTop_toTopOf="@+id/auto_status_iv" />
|
||||
|
||||
<View
|
||||
android:id="@+id/dividing_line_1"
|
||||
|
||||
Reference in New Issue
Block a user