From 1b1724668c9cbbe90ecfdcdc46c0810e1d3518f4 Mon Sep 17 00:00:00 2001 From: lixiaopeng Date: Tue, 21 Feb 2023 18:33:27 +0800 Subject: [PATCH] =?UTF-8?q?[dev=5Farch=5Fopt=5F3.0]=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=AD=94=E6=96=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../function/biz/v2x/v2n/consts/V2XConst.java | 2 +- .../mofang/MoFangManager.kt | 233 +++++++++++++++++- .../function/hmi/ui/setting/SOPSettingView.kt | 1 - .../function/main/MainLauncherActivity.java | 228 +---------------- .../api/mofang/IMoGoMoFangListener.kt | 17 ++ .../mofang/CallerMofangListenerManager.kt | 21 ++ 6 files changed, 275 insertions(+), 227 deletions(-) create mode 100644 core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/mofang/IMoGoMoFangListener.kt create mode 100644 core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/mofang/CallerMofangListenerManager.kt diff --git a/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/consts/V2XConst.java b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/consts/V2XConst.java index c2f4fd35d5..049d25ada1 100644 --- a/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/consts/V2XConst.java +++ b/core/function-impl/mogo-core-function-biz/src/main/java/com/mogo/eagle/function/biz/v2x/v2n/consts/V2XConst.java @@ -20,6 +20,6 @@ public class V2XConst { /** * V2X预警日志tag */ - public static final String LOG_NAME_WARN = "liyz"; + public static final String LOG_NAME_WARN = "PersonWarn"; } diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/mofang/MoFangManager.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/mofang/MoFangManager.kt index 23a07755f4..2d2f43601e 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/mofang/MoFangManager.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/mofang/MoFangManager.kt @@ -7,18 +7,33 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter +import android.view.KeyEvent +import com.mogo.commons.context.ContextHolderUtil import com.mogo.eagle.core.data.mofang.MfConstants +import com.mogo.eagle.core.function.api.mofang.IMoGoMoFangListener +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager.sendOperatorChangeLaneLeft +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager.sendOperatorChangeLaneRight +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager.sendOperatorSetAcceleratedSpeed +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager.sendOperatorSetHorn +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager.startAutoPilot +import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsListenerManager.invokeMoFangStatus +import com.mogo.eagle.core.function.call.mofang.CallerMofangListenerManager import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger +import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d +import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.e import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_F import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr +import com.mogo.eagle.core.utilcode.util.ToastUtils +import com.mogo.eagle.core.utilcode.util.UiThreadHandler +import java.util.* /** * 魔方连接状态和设备管理 */ @SuppressLint("StaticFieldLeak") -class MoFangManager private constructor() { +class MoFangManager private constructor() : IMoGoMoFangListener{ companion object { val moFangManager: MoFangManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { @@ -31,6 +46,29 @@ class MoFangManager private constructor() { private lateinit var mBluetoothAdapter: BluetoothAdapter private var isMfConnect: Boolean = false //添加状态判断 + private val isShowToast = false //toast 控制,自测使用 + private var startPressTime: Long = 0 //开始按键时间 + private var isPressEnd = false //按键是否结束 + @Volatile + private var isCombinationKey = 0 //是否是组合按键 1单击,2长按,3组合 + private var pressADownTime: Long = 0 + private var pressAUpTime: Long = 0 + private var pressBDownTime: Long = 0 + private var pressBUpTime: Long = 0 + private var pressCDownTime: Long = 0 + private var pressCUpTime: Long = 0 + private var pressDDownTime: Long = 0 + private var pressDUpTime: Long = 0 + private var pressEDownTime: Long = 0 + private var pressEUpTime: Long = 0 + + private val clickTime = 300 //单击 + private val clickTimeInterval = 330 + private val longPressTime = 670 + private val longPressTimeInterval = 700 + private var timerHorn: Timer? = null + private var timerAcc: Timer? = null + fun init(context: Context) { mContext = context @@ -41,6 +79,12 @@ class MoFangManager private constructor() { } mBluetoothAdapter.startDiscovery() showBondedDevice(mBluetoothAdapter) + + CallerMofangListenerManager.addListener(TAG, this) + } + + fun release() { + CallerMofangListenerManager.removeListener(TAG) } /** @@ -89,7 +133,7 @@ class MoFangManager private constructor() { private val bluetoothMonitorReceiver: BroadcastReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { when (intent.action) { - BluetoothAdapter.ACTION_STATE_CHANGED -> { //中间状态 TODO + BluetoothAdapter.ACTION_STATE_CHANGED -> { //中间状态 CallerLogger.d("$M_F${TAG}","bluetoothMonitorReceiver ACTION_STATE_CHANGED action = ${intent.action}") } @@ -115,5 +159,190 @@ class MoFangManager private constructor() { } } + /** + * 魔方按键处理 + */ + override fun onMofangHandle(keyCode: Int, action: Int): Boolean { + val bluetoothName = SharedPrefsMgr.getInstance(ContextHolderUtil.getContext()).getString(MfConstants.BLUETOOTH_NAME) + if (bluetoothName == "MINI_KEYBOARD") { + if (!isPressEnd) { + isPressEnd = true + startPressTime = System.currentTimeMillis() + } + e(M_F + "MoFangManager", + "dispatchKeyEvent ------ bluetoothName = $bluetoothName ---code = $keyCode -----action = $action ") + if (keyCode == KeyEvent.KEYCODE_A) { //单击 -1,长按无操作,AB组合-2 + if (action == KeyEvent.ACTION_DOWN) { + pressADownTime = System.currentTimeMillis() + d(M_F + "MoFangManager", + "dispatchKeyEvent A down pressADownTime = " + pressADownTime + "---" + (pressADownTime - startPressTime) + "----isCombinationKey = " + isCombinationKey + "--pressBDownTime = " + pressBDownTime) + if (pressADownTime - startPressTime in (clickTimeInterval + 1) until longPressTime && pressBDownTime > 0) { + if (isShowToast) { + ToastUtils.showShort("方块 A 按AB组合 +1 ") + } + sendAcc(true, +1.0) + isCombinationKey = 3 + } + if (isCombinationKey != 3 && isCombinationKey != 1) { + if (pressADownTime - startPressTime > longPressTimeInterval) { + if (isShowToast) { + ToastUtils.showShort("方块 长按A -2 ") + } + sendAcc(true, -2.0) + isCombinationKey = 2 + } + } + } else if (action == KeyEvent.ACTION_UP) { + pressAUpTime = System.currentTimeMillis() + d(M_F + "MoFangManager", + "dispatchKeyEvent A up pressAUpTime = " + pressAUpTime + "---" + (pressAUpTime - startPressTime) + "--pressBDownTime = " + pressBDownTime + "---isCombinationKey = $isCombinationKey") + if (pressAUpTime - startPressTime < clickTime && isCombinationKey != 3) { + isCombinationKey = 1 + if (isShowToast) { + ToastUtils.showShort("方块 单击A -1 ") + } + sendAcc(true, -1.0) + } + pressADownTime = 0 + isPressEnd = false + UiThreadHandler.postDelayed({ isCombinationKey = 0 }, 300) + } + } else if (keyCode == KeyEvent.KEYCODE_B) { //单击复原,长按+1,AB组合-2 + if (action == KeyEvent.ACTION_DOWN) { + pressBDownTime = System.currentTimeMillis() + d(M_F + "MoFangManager", + "dispatchKeyEvent B down pressBDownTime = " + pressBDownTime + "--差-" + (pressBDownTime - startPressTime) + "---isCombinationKey = " + isCombinationKey + "--pressADownTime = " + pressADownTime + ) + if (pressBDownTime - startPressTime > clickTimeInterval && pressBDownTime - startPressTime < longPressTime && pressADownTime > 0) { + if (isShowToast) { + ToastUtils.showShort("方块 B 按AB组合 +1 ") + } + sendAcc(true, +1.0) + isCombinationKey = 3 + } + if (isCombinationKey != 3 && isCombinationKey != 1) { + if (pressBDownTime - startPressTime > longPressTimeInterval) { + if (isShowToast) { + ToastUtils.showShort("方块 长按B 无操作 ") + } + isCombinationKey = 2 + } + } + } else if (action == KeyEvent.ACTION_UP) { + pressBUpTime = System.currentTimeMillis() + d(M_F + "MoFangManager", + "dispatchKeyEvent B up pressBUpTime = " + pressBUpTime + "--差-" + (pressBUpTime - startPressTime) + "--pressADownTime = " + pressADownTime + "----isCombinationKey = $isCombinationKey") + if (pressBUpTime - startPressTime < clickTime && isCombinationKey != 3) { + if (isShowToast) { + ToastUtils.showShort("方块 单击B 0 ") + } + sendAcc(false, 0.0) + isCombinationKey = 1 + } + pressBDownTime = 0 + isPressEnd = false + UiThreadHandler.postDelayed({ isCombinationKey = 0 }, 300) + } + } else if (keyCode == KeyEvent.KEYCODE_C) { //单击左变道,长按无操作 + if (action == KeyEvent.ACTION_DOWN) { + pressCDownTime = System.currentTimeMillis() + d(M_F + "MoFangManager", + "dispatchKeyEvent 方块 长按C 无操作 time dif = " + (pressCDownTime - startPressTime)) + if (pressCDownTime - startPressTime > longPressTimeInterval) { + if (isShowToast) { + ToastUtils.showShort("方块 长按C 无操作 ") + } + } + } else if (action == KeyEvent.ACTION_UP) { + pressCUpTime = System.currentTimeMillis() + isPressEnd = false + d(M_F + "MoFangManager", + "dispatchKeyEvent 方块 单击C ← 向左变道 time dif = " + (pressCUpTime - startPressTime)) + if (pressCUpTime - startPressTime < clickTime) { + if (isShowToast) { + ToastUtils.showShort("方块 单击C ← 向左变道 ") + } + sendOperatorChangeLaneLeft() + } + } + } else if (keyCode == KeyEvent.KEYCODE_D) { //单击向右变道,双击无操作 + if (action == KeyEvent.ACTION_DOWN) { + pressDDownTime = System.currentTimeMillis() + d(M_F + "MoFangManager", + "dispatchKeyEvent 方块 长按D 无操作 time dif = " + (pressDDownTime - startPressTime)) + if (pressDDownTime - startPressTime > longPressTimeInterval) { + if (isShowToast) { + ToastUtils.showShort("方块 长按D 无操作 ") + } + } + } else if (action == KeyEvent.ACTION_UP) { + pressDUpTime = System.currentTimeMillis() + isPressEnd = false + d(M_F + "MoFangManager", + "dispatchKeyEvent 方块 单击D → 向右变道 time dif = " + (pressDUpTime - startPressTime)) + if (pressDUpTime - startPressTime < clickTime) { + if (isShowToast) { + ToastUtils.showShort("方块 单击D → 向右变道 ") + } + sendOperatorChangeLaneRight() + } + } + } else if (keyCode == KeyEvent.KEYCODE_E) { //单击启动自驾,长按鸣笛 + if (action == KeyEvent.ACTION_DOWN) { + pressEDownTime = System.currentTimeMillis() + d(M_F + "MoFangManager", + "dispatchKeyEvent 方块 长按E 鸣笛 time dif = " + (pressEDownTime - startPressTime)) + if (pressEDownTime - startPressTime > longPressTimeInterval) { + if (isShowToast) { + ToastUtils.showShort("方块 长按E 鸣笛 ") + } + sendOperatorSetHorn(1.0) + if (timerHorn == null) { + timerHorn = Timer() + } + timerHorn!!.schedule(object : TimerTask() { + override fun run() { + sendOperatorSetHorn(2.0) + timerHorn = null + } + }, 500) + } + } else if (action == KeyEvent.ACTION_UP) { + pressEUpTime = System.currentTimeMillis() + isPressEnd = false + d(M_F + "MoFangManager", + "方块 单击E 开启自动驾驶 time dif = " + (pressEUpTime - startPressTime)) + if (pressEUpTime - startPressTime < clickTime) { + if (isShowToast) { + ToastUtils.showShort("方块 单击E 开启自动驾驶 ") + } + startAutoPilot(getAutoPilotStatusInfo().autopilotControlParameters) + } + } + } + } + return true + } + + @Synchronized + private fun sendAcc(isSend: Boolean, acc: Double) { + if (isSend) { + if (timerAcc == null) { + timerAcc = Timer() + timerAcc!!.schedule(object : TimerTask() { + override fun run() { + sendOperatorSetAcceleratedSpeed(acc) + } + }, 0, 500) + } + } else { + if (timerAcc != null) { + timerAcc!!.cancel() + timerAcc = null + } + sendOperatorSetAcceleratedSpeed(acc) + } + } + } diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/setting/SOPSettingView.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/setting/SOPSettingView.kt index 2b6dadfb77..d7f34d5901 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/setting/SOPSettingView.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/setting/SOPSettingView.kt @@ -117,7 +117,6 @@ internal class SOPSettingView @JvmOverloads constructor( tbObuToDcView.setOnCheckedChangeListener { _, isChecked -> // 默认开启 HmiBuildConfig.isShowObuToDcV2iView = !isChecked -// Log.d("liyz", "HmiBuildConfig.isShowObuToDcV2iView = " + HmiBuildConfig.isShowObuToDcV2iView) } //红绿灯标识 diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/main/MainLauncherActivity.java b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/main/MainLauncherActivity.java index a80465d6a3..7049008ae7 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/main/MainLauncherActivity.java +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/main/MainLauncherActivity.java @@ -3,7 +3,6 @@ package com.mogo.eagle.core.function.main; import static com.mogo.eagle.core.data.deva.chain.ChainConstant.CHAIN_ALIAS_CODE_START_UP; import static com.mogo.eagle.core.data.deva.chain.ChainConstant.CHAIN_LINK_INIT; import static com.mogo.eagle.core.data.deva.chain.ChainConstant.CHAIN_LINK_LOG_CONNECT_STATUS; -import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_F; import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_HMI; import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_MAIN; @@ -21,20 +20,15 @@ import com.mogo.commons.debug.DebugConfig; import com.mogo.commons.module.intent.IMogoIntentListener; import com.mogo.commons.module.intent.IntentManager; import com.mogo.eagle.core.data.config.FunctionBuildConfig; -import com.mogo.eagle.core.data.mofang.MfConstants; import com.mogo.eagle.core.function.api.base.IMoGoFunctionProvider; import com.mogo.eagle.core.function.api.setting.IMoGoSkinModeChangeListener; -import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager; -import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager; +import com.mogo.eagle.core.function.call.mofang.CallerMofangListenerManager; import com.mogo.eagle.core.function.call.setting.CallerSkinModeListenerManager; import com.mogo.eagle.core.function.hmi.R; import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils; import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger; -import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr; import com.mogo.eagle.core.utilcode.util.ActivityUtils; import com.mogo.eagle.core.utilcode.util.MultiDisplayUtils; -import com.mogo.eagle.core.utilcode.util.ToastUtils; -import com.mogo.eagle.core.utilcode.util.UiThreadHandler; import com.rousetime.android_startup.model.CostTimesModel; import com.zhjt.service.chain.ChainLog; import com.zhjt.service.chain.TracingConstants; @@ -43,8 +37,6 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import java.util.List; -import java.util.Timer; -import java.util.TimerTask; /** * 针对作为Launcher的情况,做个性化操作 @@ -57,31 +49,6 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis private final static Handler handlerV2XEvent = new Handler(); private static Runnable runnableV2XEvent; - private volatile double accelerated;//加速度 - private Timer timerHorn; - private Timer timerAcc; - - private boolean isShowToast = false; //toast 控制 - private long startPressTime = 0; //开始按减时间 - private boolean isPressEnd = false; //按键是否结束 - private volatile int isCombinationKey = 0; //是否是组合按键 1单击,2长按,3组合 - private long pressADownTime = 0; - private long pressAUpTime = 0; - private long pressBDownTime = 0; - private long pressBUpTime = 0; - private long pressCDownTime = 0; - private long pressCUpTime = 0; - private long pressDDownTime = 0; - private long pressDUpTime = 0; - private long pressEDownTime = 0; - private long pressEUpTime = 0; - - private int clickTime = 300; //单击 - private int clickTimeInterval = 330; - private int longPressTime = 670; - private int longPressTimeInterval = 700; - - @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -240,200 +207,15 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis */ @Override public boolean dispatchKeyEvent(KeyEvent event) { - CallerLogger.INSTANCE.d(M_F + "MoFangManager", "dispatchKeyEvent code = " + event.getKeyCode() + "--action = " + event.getAction() + "----" + event); - String bluetoothName = SharedPrefsMgr.getInstance(getContext()).getString(MfConstants.BLUETOOTH_NAME); - if (!isPressEnd) { - CallerLogger.INSTANCE.d(M_F + "MoFangManager","dispatchKeyEvent ---1--- bluetoothName = " + bluetoothName); + if(CallerMofangListenerManager.INSTANCE.invokeMofangHandle(event.getKeyCode(), event.getAction())) { + return true; + } else { + return super.dispatchKeyEvent(event); } - if (bluetoothName.equals("MINI_KEYBOARD")) { - if (!isPressEnd) { - isPressEnd = true; - startPressTime = System.currentTimeMillis(); - } - CallerLogger.INSTANCE.d(M_F + "MoFangManager","dispatchKeyEvent ---2--- bluetoothName = " + bluetoothName + "--- code = " + event.getKeyCode() + "--action = " + event.getAction()); - if (event.getKeyCode() == KeyEvent.KEYCODE_A) { //单击 -1,长按无操作,AB组合-2 - if (event.getAction() == KeyEvent.ACTION_DOWN) { - pressADownTime = System.currentTimeMillis(); - CallerLogger.INSTANCE.d(M_F + "MoFangManager", "dispatchKeyEvent A down pressADownTime = " + pressADownTime + "---" + (pressADownTime - startPressTime) + "----isCombinationKey = " + isCombinationKey + "--pressBDownTime = " + pressBDownTime); - if ((pressADownTime - startPressTime) > clickTimeInterval && (pressADownTime - startPressTime) < longPressTime && pressBDownTime > 0) { - if (isShowToast) { - ToastUtils.showShort("方块 A 按AB组合 +1 "); - } - sendAcc(true, +1); - isCombinationKey = 3; - } - - if (isCombinationKey != 3 && isCombinationKey != 1) { - if ((pressADownTime - startPressTime) > longPressTimeInterval) { - if (isShowToast) { - ToastUtils.showShort("方块 长按A -2 "); - } - sendAcc(true, -2); - isCombinationKey = 2; - } - } - } else if (event.getAction() == KeyEvent.ACTION_UP) { - pressAUpTime = System.currentTimeMillis(); - CallerLogger.INSTANCE.d(M_F + "MoFangManager", "dispatchKeyEvent A up pressAUpTime = " + pressAUpTime + "---" + (pressAUpTime - startPressTime) + "--pressBDownTime = " + pressBDownTime); - if ((pressAUpTime - startPressTime) < clickTime && isCombinationKey != 3) { - isCombinationKey = 1; - if (isShowToast) { - ToastUtils.showShort("方块 单击A -1 "); - } - sendAcc(true, -1); - } - pressADownTime = 0; - isPressEnd = false; - UiThreadHandler.postDelayed(new Runnable() { - @Override - public void run() { - isCombinationKey = 0; - } - }, 300); - } - return true; - } else if (event.getKeyCode() == KeyEvent.KEYCODE_B) { //单击复原,长按+1,AB组合-2 - if (event.getAction() == KeyEvent.ACTION_DOWN) { - pressBDownTime = System.currentTimeMillis(); - CallerLogger.INSTANCE.d(M_F + "MoFangManager", "dispatchKeyEvent B down pressBDownTime = " + pressBDownTime + "--差-" + (pressBDownTime - startPressTime) + "---isCombinationKey = " + isCombinationKey + "--pressADownTime = " + pressADownTime); - if ((pressBDownTime - startPressTime) > clickTimeInterval && (pressBDownTime - startPressTime) < longPressTime && pressADownTime > 0) { - if (isShowToast) { - ToastUtils.showShort("方块 B 按AB组合 +1 "); - } - sendAcc(true, +1); - isCombinationKey = 3; - } - if (isCombinationKey != 3 && isCombinationKey != 1) { - if ((pressBDownTime - startPressTime) > longPressTimeInterval) { - if (isShowToast) { - ToastUtils.showShort("方块 长按B 无操作 "); - } - isCombinationKey = 2; - } - } - } else if (event.getAction() == KeyEvent.ACTION_UP) { - pressBUpTime = System.currentTimeMillis(); - CallerLogger.INSTANCE.d(M_F + "MoFangManager", "dispatchKeyEvent B up pressBUpTime = " + pressBUpTime + "--差-" + (pressBUpTime - startPressTime) + "--pressADownTime = " + pressADownTime); - if ((pressBUpTime - startPressTime) < clickTime && isCombinationKey != 3) { - if (isShowToast) { - ToastUtils.showShort("方块 单击B 0 "); - } - sendAcc(false, 0.0); - isCombinationKey = 1; - } - pressBDownTime = 0; - isPressEnd = false; - - UiThreadHandler.postDelayed(new Runnable() { - @Override - public void run() { - isCombinationKey = 0; - } - }, 300); - } - return true; - } else if (event.getKeyCode() == KeyEvent.KEYCODE_C) { //单击左变道,长按无操作 - if (event.getAction() == KeyEvent.ACTION_DOWN) { - pressCDownTime = System.currentTimeMillis(); - CallerLogger.INSTANCE.d(M_F + "MoFangManager", "dispatchKeyEvent 方块 长按C 无操作 time dif = " + (pressCDownTime - startPressTime)); - if ((pressCDownTime - startPressTime) > longPressTimeInterval) { - if (isShowToast) { - ToastUtils.showShort("方块 长按C 无操作 "); - } - } - } else if (event.getAction() == KeyEvent.ACTION_UP) { - pressCUpTime = System.currentTimeMillis(); - isPressEnd = false; - CallerLogger.INSTANCE.d(M_F + "MoFangManager", "dispatchKeyEvent 方块 单击C ← 向左变道 time dif = " + (pressCUpTime - startPressTime)); - if ((pressCUpTime - startPressTime) < clickTime) { - if (isShowToast) { - ToastUtils.showShort("方块 单击C ← 向左变道 "); - } - CallerAutoPilotControlManager.INSTANCE.sendOperatorChangeLaneLeft(); - } - } - return true; - } else if (event.getKeyCode() == KeyEvent.KEYCODE_D) { //单击向右变道,双击无操作 - if (event.getAction() == KeyEvent.ACTION_DOWN) { - pressDDownTime = System.currentTimeMillis(); - CallerLogger.INSTANCE.d(M_F + "MoFangManager", "dispatchKeyEvent 方块 长按D 无操作 time dif = " + (pressDDownTime - startPressTime)); - if ((pressDDownTime - startPressTime) > longPressTimeInterval) { - if (isShowToast) { - ToastUtils.showShort("方块 长按D 无操作 "); - } - } - } else if (event.getAction() == KeyEvent.ACTION_UP) { - pressDUpTime = System.currentTimeMillis(); - isPressEnd = false; - CallerLogger.INSTANCE.d(M_F + "MoFangManager", "dispatchKeyEvent 方块 单击D → 向右变道 time dif = " + (pressDUpTime - startPressTime)); - if ((pressDUpTime - startPressTime) < clickTime) { - if (isShowToast) { - ToastUtils.showShort("方块 单击D → 向右变道 "); - } - CallerAutoPilotControlManager.INSTANCE.sendOperatorChangeLaneRight(); - } - } - return true; - } else if (event.getKeyCode() == KeyEvent.KEYCODE_E) { //单击启动自驾,长按鸣笛 - if (event.getAction() == KeyEvent.ACTION_DOWN) { - pressEDownTime = System.currentTimeMillis(); - CallerLogger.INSTANCE.d(M_F + "MoFangManager", "dispatchKeyEvent 方块 长按E 鸣笛 time dif = " + (pressEDownTime - startPressTime)); - if ((pressEDownTime - startPressTime) > longPressTimeInterval) { - if (isShowToast) { - ToastUtils.showShort("方块 长按E 鸣笛 "); - } - CallerAutoPilotControlManager.INSTANCE.sendOperatorSetHorn(1); - if (timerHorn == null) { - timerHorn = new Timer(); - } - timerHorn.schedule(new TimerTask() { - @Override - public void run() { - CallerAutoPilotControlManager.INSTANCE.sendOperatorSetHorn(2); - timerHorn = null; - } - }, 500); - } - } else if (event.getAction() == KeyEvent.ACTION_UP) { - pressEUpTime = System.currentTimeMillis(); - isPressEnd = false; - CallerLogger.INSTANCE.d(M_F + "MoFangManager", "方块 单击E 开启自动驾驶 time dif = " + (pressEUpTime - startPressTime)); - if ((pressEUpTime - startPressTime) < clickTime) { - if (isShowToast) { - ToastUtils.showShort("方块 单击E 开启自动驾驶 "); - } - CallerAutoPilotControlManager.INSTANCE.startAutoPilot(CallerAutoPilotStatusListenerManager.INSTANCE.getAutoPilotStatusInfo().getAutopilotControlParameters()); - } - } - return true; - } - } - return super.dispatchKeyEvent(event); } @Override public void onSkinModeChange(int skinMode) { } - private synchronized void sendAcc(boolean isSend, double acc) { - if (isSend) { - accelerated = acc; - if (timerAcc == null) { - timerAcc = new Timer(); - timerAcc.schedule(new TimerTask() { - @Override - public void run() { - CallerAutoPilotControlManager.INSTANCE.sendOperatorSetAcceleratedSpeed(accelerated); - } - }, 0, 500); - } - } else { - if (timerAcc != null) { - timerAcc.cancel(); - timerAcc = null; - } - CallerAutoPilotControlManager.INSTANCE.sendOperatorSetAcceleratedSpeed(acc); - } - } - } diff --git a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/mofang/IMoGoMoFangListener.kt b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/mofang/IMoGoMoFangListener.kt new file mode 100644 index 0000000000..802113f5dc --- /dev/null +++ b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/mofang/IMoGoMoFangListener.kt @@ -0,0 +1,17 @@ +package com.mogo.eagle.core.function.api.mofang + + +/** + * 魔方数据的数据处理 + * @author lixiaopeng + * @date 2023-02-20 + */ +interface IMoGoMoFangListener { + /** + * 魔方数据的数据处理 + * @param keyCode 按键类型 + * @param action 按键状态 + */ + fun onMofangHandle(keyCode: Int, action: Int): Boolean + +} \ No newline at end of file diff --git a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/mofang/CallerMofangListenerManager.kt b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/mofang/CallerMofangListenerManager.kt new file mode 100644 index 0000000000..0464d323e1 --- /dev/null +++ b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/mofang/CallerMofangListenerManager.kt @@ -0,0 +1,21 @@ +package com.mogo.eagle.core.function.call.mofang + +import com.mogo.eagle.core.function.api.mofang.IMoGoMoFangListener +import com.mogo.eagle.core.function.call.base.CallerBase + +/** + * 魔方按键的处理 + */ +object CallerMofangListenerManager : CallerBase() { + fun invokeMofangHandle(keyCode: Int, action: Int): Boolean { + var isConsume = false + M_LISTENERS.forEach { + val tag = it.key + val listener = it.value + if (listener.onMofangHandle(keyCode, action)) + isConsume = true + } + return isConsume + } + +} \ No newline at end of file