工具箱调整速度设置

This commit is contained in:
xuxinchao
2022-10-24 10:23:24 +08:00
parent 295300c54f
commit 49f6a5778e
4 changed files with 99 additions and 88 deletions

View File

@@ -59,15 +59,13 @@ class AutoPilotAndCheckView @JvmOverloads constructor(
companion object {
private var maxAcceleration: Double = 2.0
private var speedLimit: Double = 0.0
private var speedLimit: Int = 0
}
@SuppressLint("ClickableViewAccessibility")
private fun initView() {
background = ColorDrawable(Color.parseColor("#F0151D41"))
if (keyBoardUtil == null) {
keyBoardUtil = KeyBoardUtil(sKeyBoardView, etInputSpeed)
}
keyBoardUtil?.setActionListener { inputContent ->
inputContent.toIntOrNull()?.let { speed ->
when {
@@ -76,10 +74,6 @@ class AutoPilotAndCheckView @JvmOverloads constructor(
ToastUtils.showShort("超过最大限速值60设置失败")
}
else -> {
llSpeedPosition.background =
resources.getDrawable(R.drawable.pilot_speed_bg)
keyBoardUtil?.hideKeyboard()
etInputSpeed.clearFocus()
// 设置自动驾驶速度
val isSuccess = CallerAutoPilotManager.setAutoPilotSpeed(speed)
when {
@@ -94,7 +88,6 @@ class AutoPilotAndCheckView @JvmOverloads constructor(
}
}
}
KeyBoardUtil.hideSystemSoftKeyboard(context, etInputSpeed)
ivCloseIcon.setOnClickListener {
clickListener?.onClose(it)
}
@@ -113,49 +106,60 @@ class AutoPilotAndCheckView @JvmOverloads constructor(
ivDebugFeedback.onClick {
clickListener?.showFeedbackView()
}
etInputSpeed.setOnFocusChangeListener { v, hasFocus ->
when {
hasFocus -> {
llSpeedPosition.background =
resources.getDrawable(R.drawable.pilot_speed_high_light_bg)
if (keyBoardUtil == null) {
keyBoardUtil = KeyBoardUtil(sKeyBoardView, etInputSpeed)
}
keyBoardUtil?.showKeyboard()
}
else -> llSpeedPosition.background =
resources.getDrawable(R.drawable.pilot_speed_bg)
}
}
etInputSpeed.setOnTouchListener { v, event ->
var curTime = System.currentTimeMillis()
if (curTime - lastTime < 1000) {
return@setOnTouchListener true
}
if (!connectStatus) {
ToastUtils.showShort("设置车速失败,请启动域控制器")
keyBoardUtil?.hideKeyboard()
return@setOnTouchListener true
} else {
return@setOnTouchListener false
}
}
updateSpeedSettingViews()
if (AppConfigInfo.isConnectAutopilot) {
CallerAutoPilotManager.getCarConfig()
}
if (maxAcceleration > 0) {
tvAcceleration.text = "加速度 $maxAcceleration m/s²"
}
// if (maxAcceleration > 0) {
// tvAcceleration.text = "加速度 $maxAcceleration m/s²"
// }
tvAcceleration.text = "每次调整车速±5km/h"
if (speedLimit > 0) {
etInputSpeed.setText((speedLimit * 3.6).toInt().toString())
tvSpeed.text = speedLimit.toString()
}else{
tvSpeed.text = "0"
}
ivSpeedReduce.setOnClickListener {
if(speedLimit>=5){
speedLimit -= 5
//速度显示
val isSuccess = CallerAutoPilotManager.setAutoPilotSpeed(speedLimit)
when {
isSuccess -> {
//速度显示
tvSpeed.text = speedLimit.toString()
ToastUtils.showShort("车速设置成功,立即生效")
}
else -> {
ToastUtils.showShort("设置车速失败,请启动域控制器")
}
}
}else{
ToastUtils.showShort("车速不能再减了")
}
}
ivSpeedAdd.setOnClickListener {
if(speedLimit<=55){
speedLimit += 5
//速度显示
val isSuccess = CallerAutoPilotManager.setAutoPilotSpeed(speedLimit)
when {
isSuccess -> {
//速度显示
tvSpeed.text = speedLimit.toString()
ToastUtils.showShort("车速设置成功,立即生效")
}
else -> {
ToastUtils.showShort("设置车速失败,请启动域控制器")
}
}
}else{
ToastUtils.showShort("车速不能再加了")
}
}
initOchView()
// // 比如需要设置默认速度
// val speed = "30"
// etInputSpeed.setText(speed)
// etInputSpeed.setSelection(speed.length)
initOchView()
}
private fun initOchView() {
@@ -192,11 +196,6 @@ class AutoPilotAndCheckView @JvmOverloads constructor(
this.clickListener = clickListener
}
private fun updateSpeedSettingViews() {
tvSpeedTitle.visibility = View.VISIBLE
llSpeedPosition.visibility = View.VISIBLE
}
fun showAdUpgradeStatus(ipcUpgradeStateInfo: IPCUpgradeStateInfo) {
systemVersionView?.showAdUpgradeStatus(ipcUpgradeStateInfo)
}
@@ -228,12 +227,15 @@ class AutoPilotAndCheckView @JvmOverloads constructor(
override fun onAutopilotCarConfig(carConfigResp: MessagePad.CarConfigResp) {
UiThreadHandler.post {
tvAcceleration?.let {
maxAcceleration = carConfigResp.maxAcceleration
speedLimit = carConfigResp.speedLimit
tvAcceleration.text = "加速度 ${carConfigResp.maxAcceleration} m/s²"
etInputSpeed.setText((carConfigResp.speedLimit * 3.6).toInt().toString())
}
// tvAcceleration?.let {
// maxAcceleration = carConfigResp.maxAcceleration
// speedLimit = carConfigResp.speedLimit
//// tvAcceleration.text = "加速度 ${carConfigResp.maxAcceleration} m/s²"
// tvSpeed.text = (carConfigResp.speedLimit * 3.6).toInt().toString()
// }
maxAcceleration = carConfigResp.maxAcceleration
speedLimit = (carConfigResp.speedLimit * 3.6).toInt()
tvSpeed.text = speedLimit.toString()
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -43,6 +43,7 @@
android:gravity="center_vertical"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/tv_check_title"
app:layout_constraintTop_toBottomOf="@+id/v_second_group">
@@ -205,43 +206,51 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/sopLayout" />
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/llSpeedPosition"
android:layout_width="390px"
<ImageView
android:id="@+id/ivSpeedReduce"
android:layout_width="105px"
android:layout_height="140px"
android:layout_marginStart="113px"
android:layout_marginTop="40px"
android:background="@drawable/pilot_speed_bg"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal"
android:src="@drawable/icon_speed_reduce"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSpeedTitle">
app:layout_constraintTop_toBottomOf="@id/tvSpeedTitle"
/>
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/etInputSpeed"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="92px"
android:layout_weight="1"
android:background="@null"
android:gravity="center"
android:maxLength="3"
android:maxLines="1"
android:textColor="#FFFFFFFF"
android:textSize="80px"
tools:ignore="SpeakableTextPresentCheck" />
<TextView
android:id="@+id/tvSpeed"
android:layout_width="189px"
android:layout_height="140px"
app:layout_constraintTop_toTopOf="@id/ivSpeedReduce"
app:layout_constraintBottom_toBottomOf="@id/ivSpeedReduce"
app:layout_constraintLeft_toRightOf="@id/ivSpeedReduce"
android:background="#1E3062"
android:textColor="#FFFFFFFF"
android:textSize="80px"
android:gravity="center"
/>
<TextView
android:layout_width="93px"
android:layout_height="53px"
android:layout_gravity="center_vertical"
android:layout_marginEnd="28px"
android:text="km/h"
android:textColor="@color/color_B3FFFFFF"
android:textSize="38px" />
<ImageView
android:id="@+id/ivSpeedAdd"
android:layout_width="105px"
android:layout_height="140px"
app:layout_constraintTop_toTopOf="@id/tvSpeed"
app:layout_constraintBottom_toBottomOf="@id/tvSpeed"
app:layout_constraintLeft_toRightOf="@id/tvSpeed"
android:src="@drawable/icon_speed_add"
/>
</androidx.appcompat.widget.LinearLayoutCompat>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="km/h"
android:textColor="#FFFFFFFF"
android:textSize="38px"
app:layout_constraintTop_toTopOf="@id/ivSpeedAdd"
app:layout_constraintBottom_toBottomOf="@id/ivSpeedAdd"
app:layout_constraintLeft_toRightOf="@id/ivSpeedAdd"
android:layout_marginStart="40px"
/>x`
<TextView
android:id="@+id/tvAcceleration"
@@ -252,7 +261,7 @@
android:textColor="#A7B6F0"
android:textSize="32px"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/llSpeedPosition" />
app:layout_constraintTop_toBottomOf="@id/ivSpeedReduce" />
<View
android:layout_width="14px"