[6.7.0][车速] 车速UI改版

This commit is contained in:
renwj
2024-09-18 12:05:17 +08:00
parent f65112e051
commit c8d13b4e45
6 changed files with 87 additions and 1 deletions

View File

@@ -7,12 +7,16 @@ import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import com.mogo.eagle.core.function.hmi.R
import com.mogo.eagle.core.function.hmi.bone.status.StartAutoPilotStatusView
import com.zhjt.mogo_core_function_devatools.status.StatusManager
import com.zhjt.mogo_core_function_devatools.status.entity.SpeedStatus
import com.zhjt.mogo_core_function_devatools.status.entity.Status
import kotlinx.android.synthetic.main.view_bone_top_status.view.speed_custom
import kotlinx.android.synthetic.main.view_bone_top_status.view.topStatusContainer
class BoneTopStatusLayout @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr),
StartAutoPilotStatusView.IStartAutoPilotStatusChanged {
StartAutoPilotStatusView.IStartAutoPilotStatusChanged, StatusManager.IStatusListener {
companion object {
const val TAG = "BoneTopStatusLayout"
@@ -25,11 +29,20 @@ class BoneTopStatusLayout @JvmOverloads constructor(
override fun onAttachedToWindow() {
super.onAttachedToWindow()
StartAutoPilotStatusView.addStatusChangedListener(TAG, this)
StatusManager.addListener(TAG, this)
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
StartAutoPilotStatusView.removeStatusChangedListener(TAG)
StatusManager.removeListener(TAG)
}
override fun onStatusChanged(changed: List<Status>, all: List<Status>) {
changed.find { it is SpeedStatus }?.also {
val speed = it as SpeedStatus
speed_custom?.updateSpeed(speed.speed)
}
}
override fun onStatusError() {

View File

@@ -0,0 +1,38 @@
package com.mogo.eagle.core.function.hmi.bone.status.speed
import android.content.Context
import android.graphics.Color
import android.graphics.LinearGradient
import android.graphics.Shader
import android.graphics.Shader.TileMode.CLAMP
import android.util.AttributeSet
import android.util.Log
import android.view.LayoutInflater
import android.widget.LinearLayout
import com.mogo.eagle.core.function.hmi.R
import com.mogo.eagle.core.utilcode.kotlin.scope
import kotlinx.android.synthetic.main.layout_speed_view.view.tv_speed
import kotlinx.coroutines.launch
class SpeedView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) :
LinearLayout(context, attrs, defStyleAttr) {
companion object {
private const val TAG = "SpeedView"
}
init {
LayoutInflater.from(context).inflate(R.layout.layout_speed_view, this, true)
}
fun updateSpeed(speed: Int) {
tv_speed?.post {
tv_speed?.also {
Log.d(TAG, "--- (${it.width},${it.height})")
it.paint.shader = LinearGradient(it.width.toFloat() / 2.0f, 0f, it.width.toFloat() / 2.0f, it.height.toFloat(), Color.parseColor("#19FFCB"), Color.parseColor("#1970FF"), CLAMP)
it.text = "$speed"
}
}
}
}

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:parentTag="android.widget.LinearLayout"
tools:orientation="horizontal"
tools:layout_width="wrap_content"
tools:layout_height="@dimen/dp_175">
<TextView
android:id="@+id/tv_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/dp_150"
android:fontFamily="@font/font_din"
tools:text="60"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/dp_36"
android:textColor="#cccccc"
android:layout_marginStart="@dimen/dp_16"
android:text="km/h" />
</merge>

View File

@@ -6,6 +6,15 @@
android:layout_height="@dimen/dp_357"
android:background="@drawable/bg_top_status_layout_normal">
<com.mogo.eagle.core.function.hmi.bone.status.speed.SpeedView
android:id="@+id/speed_custom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="@dimen/dp_10"
android:layout_marginStart="@dimen/dp_79" />
<com.mogo.eagle.core.function.hmi.bone.status.StartAutoPilotStatusView
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@@ -2,6 +2,7 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:layout_height="@dimen/dp_86"
android:layout_width="@dimen/dp_865"
android:layout_height="@dimen/dp_102">