From 5a0718e1c40d54ad50e61546f4d938bfd2f1b503 Mon Sep 17 00:00:00 2001 From: xuxinchao Date: Thu, 13 Apr 2023 19:15:22 +0800 Subject: [PATCH] =?UTF-8?q?[dev=5Frobotaxi-d=5F230412=5F2.15.0]=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=AE=B1=E8=BD=A6=E9=80=9F=E8=AE=BE=E7=BD=AE=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=89=8B=E5=8A=A8=E8=BE=93=E5=85=A5=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmi/ui/tools/AutoPilotAndCheckView.kt | 117 ++++++++++++++---- .../function/hmi/ui/utils/KeyBoardUtil.java | 8 ++ .../main/res/layout/view_auto_pilot_check.xml | 17 +-- 3 files changed, 109 insertions(+), 33 deletions(-) diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/tools/AutoPilotAndCheckView.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/tools/AutoPilotAndCheckView.kt index 4410ea8827..a2713a6c12 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/tools/AutoPilotAndCheckView.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/tools/AutoPilotAndCheckView.kt @@ -70,29 +70,60 @@ internal class AutoPilotAndCheckView @JvmOverloads constructor( @SuppressLint("ClickableViewAccessibility") private fun initView() { background = ColorDrawable(Color.parseColor("#F0151D41")) - - keyBoardUtil?.setActionListener { inputContent -> - inputContent.toIntOrNull()?.let { speed -> - when { - speed > 60 -> { - // 设置失败键盘不消失,让用户直接修改 - ToastUtils.showShort("超过最大限速值60,设置失败") - } - else -> { - // 设置自动驾驶速度 - val isSuccess = CallerAutoPilotControlManager.setAutoPilotSpeed(speed) - when { - isSuccess -> { - ToastUtils.showShort("车速设置成功,立即生效") - } - else -> { - ToastUtils.showShort("设置车速失败,请启动域控制器") + if (keyBoardUtil == null) { + keyBoardUtil = KeyBoardUtil(sKeyBoardView, etInputSpeed) + } + keyBoardUtil?.setActionListener(object: KeyBoardUtil.ActionListener{ + override fun onComplete(inputContent: String?) { + inputContent?.toIntOrNull()?.let { speed -> + when { + speed > 60 -> { + // 设置失败键盘不消失,让用户直接修改 + ToastUtils.showShort("超过最大限速值60,设置失败") + } + else -> { + keyBoardUtil?.hideKeyboard() + etInputSpeed.clearFocus() + // 设置自动驾驶速度 + val isSuccess = CallerAutoPilotControlManager.setAutoPilotSpeed(speed) + when { + isSuccess -> { + ToastUtils.showShort("车速设置成功,立即生效") + } + else -> { + ToastUtils.showShort("设置车速失败,请启动域控制器") + } } } } } } - } + + override fun onUpdate(inputContent: String?) { + if (inputContent != null) { + try { + if(inputContent.isEmpty()){ + speedLimit = 0 + }else{ + speedLimit = inputContent.toInt() + if(speedLimit>60){ + speedLimit = 60 + ToastUtils.showShort("最大限速60") + } + } + }catch (t: Exception){ + ToastUtils.showShort("最大限速60") + speedLimit = 60 + + } + etInputSpeed.setText(speedLimit.toString()) + etInputSpeed.setSelection(speedLimit.toString().length) + } + } + + }) + + KeyBoardUtil.hideSystemSoftKeyboard(context, etInputSpeed) ivCloseIcon.setOnClickListener { clickListener?.onClose(it) } @@ -123,16 +154,42 @@ internal class AutoPilotAndCheckView @JvmOverloads constructor( // } tvAcceleration.text = "每次调整车速±5km/h,点击确定生效" if (speedLimit > 0) { - tvSpeed.text = speedLimit.toString() + etInputSpeed.setText(speedLimit.toString()) }else{ - tvSpeed.text = "0" + etInputSpeed.setText("0") + } + + etInputSpeed.setOnTouchListener { _, _ -> + val curTime = System.currentTimeMillis() + if (curTime - lastTime < 1000) { + return@setOnTouchListener true + } + etInputSpeed.isFocusableInTouchMode = true + if (keyBoardUtil == null) { + keyBoardUtil = KeyBoardUtil(sKeyBoardView, etInputSpeed) + } + keyBoardUtil?.showKeyboard() + //滑动滚动条 + svLayout.post { + svLayout.fullScroll(View.FOCUS_DOWN) + } + if (!connectStatus) { + ToastUtils.showShort("设置车速失败,请启动域控制器") + keyBoardUtil?.hideKeyboard() + return@setOnTouchListener true + } else { + return@setOnTouchListener false + } } ivSpeedReduce.setOnClickListener { if(speedLimit>=5){ speedLimit -= 5 - tvSpeed.text = speedLimit.toString() - }else{ + etInputSpeed.setText(speedLimit.toString()) + }else if(speedLimit in 1..4){ + speedLimit = 0 + etInputSpeed.setText(speedLimit.toString()) + } else{ ToastUtils.showShort("车速不能再减了") } } @@ -140,19 +197,27 @@ internal class AutoPilotAndCheckView @JvmOverloads constructor( ivSpeedAdd.setOnClickListener { if(speedLimit<=55){ speedLimit += 5 - tvSpeed.text = speedLimit.toString() - }else{ + etInputSpeed.setText(speedLimit.toString()) + }else if(speedLimit in 56..59){ + speedLimit = 60 + etInputSpeed.setText(speedLimit.toString()) + } else{ ToastUtils.showShort("车速不能再加了") } } //速度确认 tvSureModify.setOnClickListener { + if(speedLimit>60){ + // 设置失败键盘不消失,让用户直接修改 + ToastUtils.showShort("超过最大限速值60,设置失败") + return@setOnClickListener + } val isSuccess = CallerAutoPilotControlManager.setAutoPilotSpeed(speedLimit) when { isSuccess -> { //速度显示 - tvSpeed.text = speedLimit.toString() + etInputSpeed.setText(speedLimit.toString()) ToastUtils.showShort("车速设置成功,立即生效") } else -> { @@ -243,7 +308,7 @@ internal class AutoPilotAndCheckView @JvmOverloads constructor( // } maxAcceleration = carConfigResp.maxAcceleration speedLimit = (carConfigResp.speedLimit * 3.6).toInt() - tvSpeed.text = speedLimit.toString() + etInputSpeed.setText(speedLimit.toString()) } } } \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/utils/KeyBoardUtil.java b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/utils/KeyBoardUtil.java index 8b826a2255..b06500228f 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/utils/KeyBoardUtil.java +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/utils/KeyBoardUtil.java @@ -6,6 +6,7 @@ import android.inputmethodservice.KeyboardView; import android.os.Build; import android.text.Editable; import android.text.InputType; +import android.util.Log; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; @@ -78,6 +79,9 @@ public class KeyBoardUtil { editable.delete(start - 1, start); } } + if(actionListener != null){ + actionListener.onUpdate(editText.getText().toString()); + } break; case Keyboard.KEYCODE_DONE: if (actionListener != null) { @@ -86,6 +90,9 @@ public class KeyBoardUtil { break; default: editable.insert(start, Character.toString((char) primaryCode)); + if(actionListener != null){ + actionListener.onUpdate(editText.getText().toString()); + } break; } } @@ -133,5 +140,6 @@ public class KeyBoardUtil { public interface ActionListener { void onComplete(String inputContent); + void onUpdate(String inputContent); } } diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_auto_pilot_check.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_auto_pilot_check.xml index 0c2efda5b6..00d935bb03 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_auto_pilot_check.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_auto_pilot_check.xml @@ -6,6 +6,7 @@ android:layout_height="match_parent"> - @@ -297,8 +300,8 @@ android:textColor="@android:color/white" android:textSize="42dp" android:layout_marginLeft="50dp" - app:layout_constraintTop_toTopOf="@id/tvSpeed" - app:layout_constraintBottom_toBottomOf="@id/tvSpeed" + app:layout_constraintTop_toTopOf="@id/ivSpeedAdd" + app:layout_constraintBottom_toBottomOf="@id/ivSpeedAdd" app:layout_constraintLeft_toRightOf="@id/tvUnit" tools:visibility="visible" />