[2.13.0-arch-opt] turn light view opt and fix noop fragment bug

This commit is contained in:
zhongchao
2023-02-14 20:27:25 +08:00
parent 32991f784d
commit 7a44fc53b4
9 changed files with 63 additions and 80 deletions

View File

@@ -35,10 +35,6 @@ class SteeringBrakeView(context: Context, attrs: AttributeSet?) : ConstraintLayo
init {
LayoutInflater.from(context).inflate(R.layout.view_steering_brake, this, true)
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.SteeringBrakeView)
val dayLight = typedArray.getBoolean(R.styleable.SteeringBrakeView_day_light_mode, false)
turnLightView.dayLightMode(dayLight)
typedArray.recycle()
}
override fun onAttachedToWindow() {
@@ -85,8 +81,6 @@ class SteeringBrakeView(context: Context, attrs: AttributeSet?) : ConstraintLayo
brakeView.visibility = View.GONE
isShowTurnLight = false
}
turnLightView.visibility = View.VISIBLE
turnLightView.setTurnLight(lightSwitch)
}
}

View File

@@ -11,9 +11,12 @@ import android.view.animation.Animation
import android.widget.ImageView
import androidx.constraintlayout.widget.ConstraintLayout
import chassis.Chassis
import com.mogo.eagle.core.function.api.map.angle.*
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLamplightListener
import com.mogo.eagle.core.function.api.map.angle.Turning
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLamplightListenerManager
import com.mogo.eagle.core.function.call.map.CallerVisualAngleManager
import com.mogo.eagle.core.function.hmi.R
import kotlinx.android.synthetic.main.view_steering_brake.view.*
import kotlinx.android.synthetic.main.view_turn_light_status.view.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
@@ -29,29 +32,58 @@ class TurnLightViewStatus @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
) : ConstraintLayout(context, attrs, defStyleAttr), IMoGoChassisLamplightListener {
private var init: Boolean = false
companion object {
private const val TAG = "TurnLightViewStatus"
}
fun dayLightMode(dayLight: Boolean) {
private val visible: Boolean
init {
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.TurnLightView)
val dayLight = typedArray.getBoolean(R.styleable.TurnLightView_day_light_mode, false)
if (dayLight) {
LayoutInflater.from(context)
.inflate(R.layout.view_turn_light_status_daytime, this, true)
} else {
LayoutInflater.from(context).inflate(R.layout.view_turn_light_status, this, true)
}
invalidate()
init = true
visible = typedArray.getBoolean(R.styleable.TurnLightView_visible, true)
if (visible) {
turn_light_layout.visibility = View.VISIBLE
} else {
turn_light_layout.visibility = View.GONE
}
typedArray.recycle()
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
CallerChassisLamplightListenerManager.addListener(TAG, this)
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
CallerChassisLamplightListenerManager.removeListener(TAG)
}
override fun onAutopilotLightSwitchData(lightSwitch: Chassis.LightSwitch?) {
super.onAutopilotLightSwitchData(lightSwitch)
lightSwitch?.let {
turnLightView.visibility = View.VISIBLE
setTurnLight(it)
}
}
/**
* 转向灯动画
*/
fun setTurnLight(directionLight: Chassis.LightSwitch) {
private fun setTurnLight(directionLight: Chassis.LightSwitch) {
if (!isAttachedToWindow) {
return
}
GlobalScope.launch(Dispatchers.Main) {
if (!init) {
return@launch
}
//根据左右进行显示和隐藏,实际要判断每个来的时间和频度
when (directionLight) {
Chassis.LightSwitch.LIGHT_LEFT -> { //左转向
@@ -135,7 +167,9 @@ class TurnLightViewStatus @JvmOverloads constructor(
}
override fun onAnimationEnd(p0: Animation?) {
turn_light_layout.visibility = View.GONE
if (visible) {
turn_light_layout.visibility = View.GONE
}
stopAnimate()
}
})

View File

@@ -69,9 +69,9 @@
<item name="android:borderlessButtonStyle">@android:color/transparent</item>
</style>
<declare-styleable name="SteeringBrakeView">
<declare-styleable name="TurnLightView">
<attr name="day_light_mode" format="boolean"/>
<attr name="brakeView" format="boolean"/>
<attr name="visible" format="boolean"/>
</declare-styleable>
<declare-styleable name="PncActionsView">