【6.7.0][运营面板] 自驾速度值可以键盘输入

This commit is contained in:
renwj
2024-10-22 19:24:26 +08:00
parent 59e74a8e29
commit 304f67ad36
4 changed files with 117 additions and 7 deletions

View File

@@ -1,8 +1,13 @@
package com.mogo.eagle.core.function.hmi.ui.operate.preferences
import android.annotation.SuppressLint
import android.content.Context
import android.text.Editable
import android.util.AttributeSet
import android.widget.EditText
import android.widget.TextView
import androidx.core.widget.doBeforeTextChanged
import androidx.core.widget.doOnTextChanged
import androidx.preference.Preference
import androidx.preference.PreferenceViewHolder
import com.mogo.eagle.core.function.hmi.R
@@ -39,7 +44,7 @@ class PreferenceWithSpeedSetting : Preference {
notifyChanged()
}
override fun onBindViewHolder(holder: PreferenceViewHolder) {
@SuppressLint("SetTextI18n") override fun onBindViewHolder(holder: PreferenceViewHolder) {
super.onBindViewHolder(holder)
val speedData = mSpeedData ?: return
if (speedData !is List<*> || speedData.size != 5) {
@@ -67,7 +72,27 @@ class PreferenceWithSpeedSetting : Preference {
if (cache.containsKey(key)) {
cur = max(cur, cache[key] ?: 0.0)
}
speedLimit?.text = cur.toString()
if (speedLimit is EditText) {
speedLimit.setText(cur.toString())
speedLimit.doOnTextChanged { text, _, _, _ ->
val current = text?.let { runCatching { it.toString().toDouble() }.getOrNull() }
if (current == null) {
return@doOnTextChanged
}
if (current > max) {
ToastUtils.showShort("阈值最大为${BigDecimal.valueOf(max).setScale(1)}$unit")
return@doOnTextChanged
}
cur = current
btnOk.isEnabled = true
ll.isSelected = true
cache[key] = cur
enabled[key] = true
holder.itemView.isEnabled = false
}
} else {
speedLimit?.text = cur.toString()
}
val minus = holder.findViewById(R.id.iv_speed_minus)
btnOk.isEnabled = enabled[key] ?: false
holder.itemView.isEnabled = enabled[key] ?: false
@@ -85,7 +110,11 @@ class PreferenceWithSpeedSetting : Preference {
cache[key] = cur
enabled[key] = true
holder.itemView.isEnabled = false
speedLimit?.text = minusAfter.toString()
if (speedLimit is EditText) {
speedLimit.setText(minusAfter.toString())
} else {
speedLimit?.text = minusAfter.toString()
}
}
val add = holder.findViewById(R.id.iv_speed_add)
add.setOnClickListener(null)
@@ -101,7 +130,12 @@ class PreferenceWithSpeedSetting : Preference {
ll.isSelected = true
btnOk.isEnabled = true
enabled[key] = true
speedLimit?.text = addAfter.toString()
if (speedLimit is EditText) {
speedLimit.setText("")
speedLimit.setText(addAfter.toString())
} else {
speedLimit?.text = addAfter.toString()
}
}
btnOk.setOnClickListener(null)
btnOk.onClick {

View File

@@ -24,12 +24,15 @@
android:src="@drawable/icon_operate_panel_minus"
tools:ignore="ContentDescription,RtlSymmetry" />
<TextView
<EditText
android:id="@+id/tv_speed_limit"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:inputType="number"
android:digits="0123456789."
android:background="@null"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="@dimen/dp_32"

View File

@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="@dimen/dp_20"
tools:background="#83000000">
<LinearLayout
android:id="@+id/ll_speed"
android:layout_width="@dimen/dp_214"
android:layout_height="@dimen/dp_60"
android:background="@drawable/bg_operate_panel_edit"
android:layout_gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_speed_minus"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:paddingStart="@dimen/dp_15"
android:src="@drawable/icon_operate_panel_minus"
tools:ignore="ContentDescription,RtlSymmetry" />
<TextView
android:id="@+id/tv_speed_limit"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="@dimen/dp_32"
tools:ignore="SpUsage"
tools:text="65" />
<ImageView
android:id="@+id/iv_speed_add"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:paddingEnd="@dimen/dp_15"
android:src="@drawable/icon_operate_panel_add"
tools:ignore="ContentDescription,RtlSymmetry" />
</LinearLayout>
<TextView
android:id="@+id/tv_speed_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/dp_10"
tools:text="km/h"
android:textColor="#ffffff"
android:textSize="@dimen/dp_30"
tools:ignore="HardcodedText,SpUsage" />
<Space
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<Button
android:id="@+id/bt_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/bg_operate_panel_edit_button"
android:enabled="false" />
</LinearLayout>

View File

@@ -86,12 +86,12 @@
android:title="变道速度阈值"
android:persistent="false"
android:layout="@layout/layout_operate_panel_preference_with_title_above"
android:widgetLayout="@layout/layout_operate_panel_preference_widget_edit_with_button" />
android:widgetLayout="@layout/layout_operate_panel_preference_widget_text_with_button" />
<com.mogo.eagle.core.function.hmi.ui.operate.preferences.PreferenceWithSpeedSetting
android:key="overtake_speed_thresholds"
android:title="超车速度阈值"
android:persistent="false"
android:layout="@layout/layout_operate_panel_preference_with_title_above"
android:widgetLayout="@layout/layout_operate_panel_preference_widget_edit_with_button" />
android:widgetLayout="@layout/layout_operate_panel_preference_widget_text_with_button" />
</PreferenceCategory>
</androidx.preference.PreferenceScreen>