[Update]调整交互和修复键盘Bug

This commit is contained in:
chenfufeng
2021-12-11 22:34:10 +08:00
parent d4a9ccede9
commit 113cc80c2d
16 changed files with 399 additions and 46 deletions

View File

@@ -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)
}
}

View File

@@ -87,7 +87,8 @@ class MoGoHmiFragment : MvpFragment<MoGoWarningContract.View?, WaringPresenter?>
showCameraList(CallerMonitorManager.getCameraList())
}
}
viewCheckStatus?.setOnClickListener {
ivToolsIcon?.setOnClickListener {
if (toolsViewFloat == null) {
showToolsFloat()
}
@@ -256,7 +257,7 @@ class MoGoHmiFragment : MvpFragment<MoGoWarningContract.View?, WaringPresenter?>
}
override fun setCheckStatusViewVisibility(visibility: Int) {
viewCheckStatus?.visibility = visibility
// viewCheckStatus?.visibility = visibility
}
/**

View File

@@ -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 {

View File

@@ -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
)
}
}
}
}
}

View File

@@ -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<EditText> 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);
}
}

View File

@@ -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() {

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#2966EC" />
</shape>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#263869" />
</shape>

View File

@@ -83,16 +83,20 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<com.mogo.eagle.core.function.hmi.ui.widget.CheckStatusView
android:id="@+id/viewCheckStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<ImageView
android:id="@+id/ivToolsIcon"
android:layout_width="102px"
android:layout_height="102px"
android:layout_marginLeft="25px"
android:layout_marginBottom="40px"
android:elevation="@dimen/dp_10"
android:background="@drawable/module_ext_check"
android:src="@drawable/icon_tools_nor"
android:scaleType="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/viewPerspectiveSwitch"
app:layout_goneMarginStart="50px" />
app:layout_goneMarginStart="50px"
/>
<ImageView
android:id="@+id/ivCameraIcon"

View File

@@ -3,7 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="960px"
android:layout_height="1600px"
android:layout_height="1528px"
android:background="@color/notice_check_dialog_bg_color"
>
@@ -30,15 +30,15 @@
app:layout_constraintTop_toTopOf="parent"
/>
<ImageView
android:id="@+id/ivCheckIcon"
<com.mogo.eagle.core.function.hmi.ui.widget.CheckStatusView
android:id="@+id/viewCheckStatus"
android:layout_width="150px"
android:layout_height="150px"
android:layout_marginTop="266px"
android:layout_marginStart="113px"
android:background="@drawable/check_car_nor"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
/>
<TextView
android:id="@+id/tvCheck"
@@ -50,7 +50,7 @@
android:layout_marginStart="124px"
android:layout_marginTop="23px"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/ivCheckIcon"
app:layout_constraintTop_toBottomOf="@id/viewCheckStatus"
/>
<View
@@ -86,16 +86,19 @@
android:background="@drawable/pilot_speed_bg"
android:layout_marginTop="40px"
android:layout_marginStart="113px"
android:focusable="true"
android:focusableInTouchMode="true"
>
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/etInputSpeed"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginStart="92px"
android:textColor="#FFFFFFFF"
android:text="30"
android:textSize="80px"
android:background="@null"
android:gravity="center"
/>
@@ -106,10 +109,23 @@
android:textColor="#B3FFFFFF"
android:textSize="38px"
android:layout_marginEnd="28px"
android:layout_gravity="center_vertical"
/>
</androidx.appcompat.widget.LinearLayoutCompat>
<com.mogo.eagle.core.function.hmi.ui.tools.SpeedKeyboardView
android:id="@+id/sKeyBoardView"
android:layout_width="match_parent"
android:layout_height="500px"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:background="#5375D6"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone"
/>
<ImageView
android:id="@+id/ivCloseIcon"
android:layout_width="107px"
@@ -120,11 +136,4 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:layout_width="match_parent"
android:layout_height="500px"
app:layout_constraintBottom_toBottomOf="parent"
android:background="@color/notice_blue"
/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -6,15 +6,25 @@
android:layout_height="wrap_content">
<!--车辆检测入口-->
<TextView
android:id="@+id/moduleHmiCheck"
android:layout_width="@dimen/module_hmi_check_size"
android:layout_height="@dimen/module_hmi_check_size"
android:background="@drawable/module_ext_check"
android:gravity="center"
android:text="检测"
android:textColor="#fff"
android:textSize="@dimen/module_switch_text_size"
<!-- <TextView-->
<!-- android:id="@+id/moduleHmiCheck"-->
<!-- android:layout_width="@dimen/module_hmi_check_size"-->
<!-- android:layout_height="@dimen/module_hmi_check_size"-->
<!-- android:background="@drawable/module_ext_check"-->
<!-- android:gravity="center"-->
<!-- android:text="检测"-->
<!-- android:textColor="#fff"-->
<!-- android:textSize="@dimen/module_switch_text_size"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- app:layout_constraintRight_toRightOf="parent"-->
<!-- android:visibility="gone"-->
<!-- />-->
<ImageView
android:id="@+id/ivCheckIcon"
android:layout_width="150px"
android:layout_height="150px"
android:background="@drawable/check_car_nor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
@@ -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" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -26,5 +26,10 @@
<enum name="repeat" value="1" />
<enum name="mirror" value="2" />
</attr>
<declare-styleable name="keyboard">
<attr name="keyTextSize" format="string" />
<attr name="keyTextStyle" format="string" />
<attr name="keyBackground" format="reference" />
</declare-styleable>
</declare-styleable>
</resources>

View File

@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<!--android:keyHeight="122px"
android:keyWidth="237px"-->
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:keyboard="http://schemas.android.com/apk/res-auto"
android:keyHeight="122px"
android:keyWidth="239px"
android:horizontalGap="1px"
android:verticalGap="1px">
<Row>
<Key
android:codes="49"
android:keyLabel="1" />
<Key
android:codes="50"
android:keyLabel="2" />
<Key
android:codes="51"
android:keyLabel="3" />
<Key
android:codes="-5"
android:keyLabel="删除" />
</Row>
<Row>
<Key
android:codes="52"
android:keyLabel="4" />
<Key
android:codes="53"
android:keyLabel="5" />
<Key
android:codes="54"
android:keyLabel="6" />
<Key
android:codes="-4"
keyboard:keyBackground="@drawable/keyboard_blue"
android:keyHeight="368px"
android:keyLabel="确定"/>
</Row>
<Row>
<Key
android:codes="55"
android:keyLabel="7" />
<Key
android:codes="56"
android:keyLabel="8" />
<Key
android:codes="57"
android:keyLabel="9" />
</Row>
<Row>
<Key
android:keyWidth="719px"
android:codes="48"
android:keyLabel="0" />
</Row>
</Keyboard>