diff --git a/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/MoGoAutopilotProvider.kt b/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/MoGoAutopilotProvider.kt index f626fe2720..e51c6d550f 100644 --- a/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/MoGoAutopilotProvider.kt +++ b/core/function-impl/mogo-core-function-autopilot/src/main/java/com/mogo/eagle/core/function/autopilot/MoGoAutopilotProvider.kt @@ -72,7 +72,7 @@ class MoGoAutopilotProvider : } - override fun setAutoPilotSpeed(speed: Int) { - AdasManager.getInstance().setSpeed(speed) + override fun setAutoPilotSpeed(speed: Int): Boolean { + return AdasManager.getInstance().setSpeed(speed) } } \ 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/MoGoHmiFragment.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoHmiFragment.kt index 8fcfef0aee..542266a80b 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoHmiFragment.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/MoGoHmiFragment.kt @@ -87,7 +87,8 @@ class MoGoHmiFragment : MvpFragment showCameraList(CallerMonitorManager.getCameraList()) } } - viewCheckStatus?.setOnClickListener { + + ivToolsIcon?.setOnClickListener { if (toolsViewFloat == null) { showToolsFloat() } @@ -256,7 +257,7 @@ class MoGoHmiFragment : MvpFragment } override fun setCheckStatusViewVisibility(visibility: Int) { - viewCheckStatus?.visibility = visibility +// viewCheckStatus?.visibility = visibility } /** 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 f079337f1e..557ed1de2e 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 @@ -1,23 +1,34 @@ package com.mogo.eagle.core.function.hmi.ui.tools +import android.annotation.SuppressLint import android.content.Context import android.util.AttributeSet import android.view.LayoutInflater import android.view.View import android.widget.FrameLayout +import com.mogo.eagle.core.data.autopilot.AutopilotGuardianStatusInfo +import com.mogo.eagle.core.data.autopilot.AutopilotStationInfo +import com.mogo.eagle.core.data.autopilot.AutopilotStatusInfo +import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotManager +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager import com.mogo.eagle.core.function.call.check.CallerCheckManager import com.mogo.eagle.core.function.hmi.R +import com.mogo.eagle.core.function.hmi.ui.utils.KeyBoardUtil +import com.mogo.eagle.core.utilcode.util.ToastUtils import kotlinx.android.synthetic.main.view_auto_pilot_check.view.* /** * @author ChenFufeng * 设置自动驾驶速度和检测页入口 */ -class AutoPilotAndCheckView : FrameLayout { +class AutoPilotAndCheckView : FrameLayout, IMoGoAutopilotStatusListener { private val TAG = "AutoPilotAndCheckView" private var clickListener: ClickListener? = null + private var keyBoardUtil: KeyBoardUtil? = null + private var connectStatus = false @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : super( @@ -31,13 +42,58 @@ class AutoPilotAndCheckView : FrameLayout { initView() } + @SuppressLint("ClickableViewAccessibility") private fun initView() { + if (keyBoardUtil == null) { + keyBoardUtil = KeyBoardUtil(sKeyBoardView, etInputSpeed) + } + keyBoardUtil?.setActionListener { inputContent -> + inputContent.toIntOrNull()?.let { speed -> + when { + !connectStatus -> { + ToastUtils.showShort("域控制器连接异常,请先启动") + } + speed > 60 -> { + ToastUtils.showShort("超过最大限速值60,设置失败") + } + else -> { + // 设置自动驾驶速度 + var isSuccess = CallerAutoPilotManager.setAutoPilotSpeed(speed) + when { + isSuccess -> { + ToastUtils.showShort("车速设置成功,立即生效") + } + else -> { + ToastUtils.showShort("车速设置失败,请稍后重试") + } + } + } + } + } + } + KeyBoardUtil.hideSystemSoftKeyboard(context, etInputSpeed) ivCloseIcon.setOnClickListener { clickListener?.onClose(it) } - ivCheckIcon.setOnClickListener { + viewCheckStatus.setOnClickListener { clickListener?.go2CheckPage() } + etInputSpeed.setOnTouchListener { v, _ -> + if (etInputSpeed.hasFocusable()) { + if (keyBoardUtil == null) { + keyBoardUtil = KeyBoardUtil(sKeyBoardView, etInputSpeed) + } + keyBoardUtil?.showKeyboard() + } + if (!etInputSpeed.hasFocus()) { + etInputSpeed.requestFocus() + } + return@setOnTouchListener false + } +// // 比如需要设置默认速度 +// val speed = "30" +// etInputSpeed.setText(speed) +// etInputSpeed.setSelection(speed.length) } fun setClickListener(clickListener: ClickListener) { @@ -46,10 +102,24 @@ class AutoPilotAndCheckView : FrameLayout { override fun onAttachedToWindow() { super.onAttachedToWindow() + CallerAutoPilotStatusListenerManager.addListener(TAG, this) } override fun onDetachedFromWindow() { super.onDetachedFromWindow() + CallerAutoPilotStatusListenerManager.removeListener(TAG) + } + + override fun onAutopilotStatusResponse(autoPilotStatusInfo: AutopilotStatusInfo) { + connectStatus = autoPilotStatusInfo.connectStatus + } + + override fun onAutopilotArriveAtStation(autopilotWayArrive: AutopilotStationInfo?) { + + } + + override fun onAutopilotGuardian(guardianInfo: AutopilotGuardianStatusInfo?) { + } interface ClickListener { diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/tools/SpeedKeyboardView.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/tools/SpeedKeyboardView.kt new file mode 100644 index 0000000000..9f1ec2b75f --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/tools/SpeedKeyboardView.kt @@ -0,0 +1,58 @@ +package com.mogo.eagle.core.function.hmi.ui.tools + +import android.content.Context +import android.graphics.* +import android.inputmethodservice.KeyboardView +import android.util.AttributeSet +import com.mogo.eagle.core.function.hmi.R + +class SpeedKeyboardView @JvmOverloads constructor( + context: Context, attrs: AttributeSet? = null +) : KeyboardView(context, attrs) { + override fun onDraw(canvas: Canvas?) { + super.onDraw(canvas) + val keyboard = keyboard ?: return + val keys = keyboard.keys + if (keys != null && keys.size > 0) { + val paint = Paint() + paint.textAlign = Paint.Align.CENTER + val font = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD) + paint.typeface = font + paint.isAntiAlias = true + for (key in keys) { + if (key.codes[0] == -4) {// 确定 + val dr = context.resources.getDrawable(R.drawable.keyboard_blue) + dr.setBounds(key.x, key.y, key.x + key.width, key.y + key.height) + dr.draw(canvas!!) + } else { + val dr = context.resources.getDrawable(R.drawable.keyboard_white) + dr.setBounds(key.x, key.y, key.x + key.width, key.y + key.height) + dr.draw(canvas!!) + } + if (key.label != null) { + // 确定和删除按键字体 + if (key.codes[0] == -4 || + key.codes[0] == -5 + ) { + paint.textSize = 36f + } else { + paint.textSize = 45f + } + paint.color = Color.parseColor("#FFFFFF") + val rect = Rect(key.x, key.y, key.x + key.width, key.y + key.height) + val fontMetrics = paint.fontMetricsInt + val baseline = + (rect.bottom + rect.top - fontMetrics.bottom - fontMetrics.top) / 2 + // 下面这行是实现水平居中,drawText对应改为传入targetRect.centerX() + paint.textAlign = Paint.Align.CENTER + canvas!!.drawText( + key.label.toString(), + rect.centerX().toFloat(), + baseline.toFloat(), + paint + ) + } + } + } + } +} \ 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 new file mode 100644 index 0000000000..af17983435 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/utils/KeyBoardUtil.java @@ -0,0 +1,134 @@ +package com.mogo.eagle.core.function.hmi.ui.utils; + +import android.content.Context; +import android.inputmethodservice.Keyboard; +import android.inputmethodservice.KeyboardView; +import android.os.Build; +import android.text.Editable; +import android.text.InputType; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; + +import com.mogo.eagle.core.function.hmi.R; + +import java.lang.reflect.Method; + +public class KeyBoardUtil { + + private KeyboardView keyboardView; + private EditText editText; + private Keyboard keyboard;// 键盘 + private ActionListener actionListener; + + public KeyBoardUtil(KeyboardView keyboardView, EditText editText) { + this.keyboardView = keyboardView; + this.editText = editText; + + this.keyboard = new Keyboard(editText.getContext(), R.xml.key); + this.keyboardView.setOnKeyboardActionListener(listener); + this.keyboardView.setKeyboard(keyboard); + this.keyboardView.setEnabled(true); + this.keyboardView.setPreviewEnabled(false); + } + + public void setActionListener(ActionListener actionListener) { + this.actionListener = actionListener; + } + + private KeyboardView.OnKeyboardActionListener listener = new KeyboardView.OnKeyboardActionListener() { + + @Override + public void swipeUp() { + } + + @Override + public void swipeRight() { + + } + + @Override + public void swipeLeft() { + } + + @Override + public void swipeDown() { + } + + @Override + public void onText(CharSequence text) { + } + + @Override + public void onRelease(int primaryCode) { + } + + @Override + public void onPress(int primaryCode) { + } + + @Override + public void onKey(int primaryCode, int[] keyCodes) { + Editable editable = editText.getText(); + int start = editText.getSelectionStart(); + switch (primaryCode) { + case Keyboard.KEYCODE_DELETE: + if (editable != null && editable.length() > 0) { + if (start > 0) { + editable.delete(start - 1, start); + } + } + break; + case Keyboard.KEYCODE_DONE: + keyboardView.setVisibility(View.GONE); + if (actionListener != null) { + actionListener.onComplete(editText.getText().toString()); + } + break; + default: + editable.insert(start, Character.toString((char) primaryCode)); + break; + } + } + }; + + public static void hideSystemSoftKeyboard(Context context, EditText editText) { + int sdkInt = Build.VERSION.SDK_INT; + if (sdkInt >= Build.VERSION_CODES.HONEYCOMB && sdkInt < Build.VERSION_CODES.LOLLIPOP) { + try { + Class cls = EditText.class; + Method setShowSoftInputOnFocus; + setShowSoftInputOnFocus = cls.getMethod("setShowSoftInputOnFocus", boolean.class); + setShowSoftInputOnFocus.setAccessible(true); + setShowSoftInputOnFocus.invoke(editText, false); + + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } else if (sdkInt >= Build.VERSION_CODES.LOLLIPOP) { + editText.setShowSoftInputOnFocus(false); + } else { + // 不会弹出系统键盘,同时不显示光标 + editText.setInputType(InputType.TYPE_NULL); + } + // 如果软键盘已经显示,则隐藏 + InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(editText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); + } + + // Activity中获取焦点时调用,显示出键盘 + public void showKeyboard() { + int visibility = keyboardView.getVisibility(); + if (visibility == View.GONE || visibility == View.INVISIBLE) { + keyboardView.setVisibility(View.VISIBLE); + } + } + + public interface ActionListener { + void onComplete(String inputContent); + } +} diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/CheckStatusView.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/CheckStatusView.kt index 50315d1323..96a62ac937 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/CheckStatusView.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/widget/CheckStatusView.kt @@ -24,13 +24,6 @@ class CheckStatusView @JvmOverloads constructor( init { LayoutInflater.from(context).inflate(R.layout.view_check_status, this, true) - - setBackgroundResource(R.drawable.module_ext_check) - -// setOnClickListener { -// // 启动检测页面 -// CallerCheckManager.startCheckActivity(getContext()) -// } } private fun showErrorIcon() { diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/icon_tools_nor.png b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/icon_tools_nor.png new file mode 100644 index 0000000000..ba41bf3a53 Binary files /dev/null and b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable-xxhdpi/icon_tools_nor.png differ diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/keyboard_blue.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/keyboard_blue.xml new file mode 100644 index 0000000000..c68f9f36c6 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/keyboard_blue.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/keyboard_white.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/keyboard_white.xml new file mode 100644 index 0000000000..3d9f532bc9 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/keyboard_white.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/fragment_hmi.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/fragment_hmi.xml index 599d5fc18c..7f8775e20d 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/fragment_hmi.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/fragment_hmi.xml @@ -83,16 +83,20 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" /> - + app:layout_goneMarginStart="50px" + /> @@ -30,15 +30,15 @@ app:layout_constraintTop_toTopOf="parent" /> - + app:layout_constraintTop_toTopOf="parent" + /> @@ -106,10 +109,23 @@ android:textColor="#B3FFFFFF" android:textSize="38px" android:layout_marginEnd="28px" + android:layout_gravity="center_vertical" /> + + - - \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_check_status.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_check_status.xml index 811aec84da..c16930b902 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_check_status.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/view_check_status.xml @@ -6,15 +6,25 @@ android:layout_height="wrap_content"> - + + + + + + + + + + + + + + @@ -24,8 +34,8 @@ android:layout_height="@dimen/dp_40" android:src="@drawable/check_error_image" android:visibility="invisible" - app:layout_constraintRight_toRightOf="@+id/moduleHmiCheck" - app:layout_constraintTop_toTopOf="@+id/moduleHmiCheck" /> + app:layout_constraintRight_toRightOf="@+id/ivCheckIcon" + app:layout_constraintTop_toTopOf="@+id/ivCheckIcon" /> \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/values/attr.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/values/attr.xml index 8972302147..4827806e98 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/values/attr.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/values/attr.xml @@ -26,5 +26,10 @@ + + + + + \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/xml/key.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/xml/key.xml new file mode 100644 index 0000000000..05d655ef9d --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/xml/key.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/autopilot/IMoGoAutopilotProvider.java b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/autopilot/IMoGoAutopilotProvider.java index fecf0f428f..0d92a933c9 100644 --- a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/autopilot/IMoGoAutopilotProvider.java +++ b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/autopilot/IMoGoAutopilotProvider.java @@ -56,5 +56,5 @@ public interface IMoGoAutopilotProvider extends IMoGoFunctionServerProvider { */ void setIsWriteLog(boolean isWriteLog); - void setAutoPilotSpeed(int speed); + Boolean setAutoPilotSpeed(int speed); } diff --git a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/autopilot/CallerAutoPilotManager.kt b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/autopilot/CallerAutoPilotManager.kt index 896afd89a1..ff4200135e 100644 --- a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/autopilot/CallerAutoPilotManager.kt +++ b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/autopilot/CallerAutoPilotManager.kt @@ -63,7 +63,7 @@ object CallerAutoPilotManager { providerApi.setIsWriteLog(isWriteLog) } - fun setAutoPilotSpeed(speed: Int) { - providerApi.setAutoPilotSpeed(speed) + fun setAutoPilotSpeed(speed: Int): Boolean { + return providerApi.setAutoPilotSpeed(speed) } } \ No newline at end of file