添加魔方的控制功能
This commit is contained in:
@@ -60,7 +60,7 @@ import me.jessyan.autosize.utils.AutoSizeUtils;
|
||||
* @author tongchenfei
|
||||
*/
|
||||
public class MainLauncherActivity extends MainActivity implements IMogoIntentListener, IMoGoSkinModeChangeListener {
|
||||
private static final String TAG = "liyz";
|
||||
private static final String TAG = "MainLauncherActivity";
|
||||
protected boolean mIsHomeKeyDown = false;
|
||||
private final static Handler handlerV2XEvent = new Handler();
|
||||
private static Runnable runnableV2XEvent;
|
||||
@@ -71,17 +71,6 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
|
||||
private BluetoothMonitorReceiver mBluetoothReceiver = null;
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
// private List<BluetoothDevice> mAreadlyConnectedList = new ArrayList<>();//已连接设备集合
|
||||
private int numberA = 0;
|
||||
private boolean isLongPressA = false;
|
||||
private int numberB = 0;
|
||||
private boolean isLongPressB = false;
|
||||
private int numberC = 0;
|
||||
private boolean isLongPressC = false;
|
||||
private int numberD = 0;
|
||||
private boolean isLongPressD = false;
|
||||
private int numberE = 0;
|
||||
private boolean isLongPressE = false;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -90,7 +79,6 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
DebugConfig.setNeedRequestUserInfo(true);
|
||||
EventBus.getDefault().register(this);
|
||||
CallerLogger.INSTANCE.i(M_HMI + TAG, "onCreate");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -222,8 +210,19 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
* 魔方按键分发 提测前注释 ToastUtils TODO
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
// Log.d(TAG, "dispatchKeyEvent code = " + event.getKeyCode() + "--action = " + event.getAction() + "----" + event);
|
||||
@@ -231,26 +230,24 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
if (!isPressEnd) {
|
||||
Log.e(TAG, "dispatchKeyEvent bluetoothName = " + bluetoothName);
|
||||
}
|
||||
|
||||
if (bluetoothName.equals("MINI_KEYBOARD")) {
|
||||
if (!isPressEnd) {
|
||||
isPressEnd = true;
|
||||
startPressTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
if (event.getKeyCode() == KeyEvent.KEYCODE_A) { //单击向左变道,长按-1
|
||||
if (event.getKeyCode() == KeyEvent.KEYCODE_A) { //单击 -1,长按无操作,AB组合-2
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
pressADownTime = System.currentTimeMillis();
|
||||
Log.d(TAG, "dispatchKeyEvent A down pressADownTime = " + pressADownTime + "---" + (pressADownTime - startPressTime) + "----isCombinationKey = " + isCombinationKey + "--pressBDownTime = " + pressBDownTime);
|
||||
if ((pressADownTime - startPressTime) > 550 && (pressADownTime - startPressTime) < 1900 && pressBDownTime > 0) {
|
||||
if ((pressADownTime - startPressTime) > 350 && (pressADownTime - startPressTime) < 1800 && pressBDownTime > 0) {
|
||||
ToastUtils.showShort("方块 A 按AB组合 -2 ");
|
||||
sendAcc(true, -2);
|
||||
isCombinationKey = true;
|
||||
}
|
||||
|
||||
if (!isCombinationKey) {
|
||||
if ((pressADownTime - startPressTime) > 2000) {
|
||||
ToastUtils.showShort("方块 长按A 无操作 ");
|
||||
if ((pressADownTime - startPressTime) > 1900) {
|
||||
ToastUtils.showShort("方块 长按A 无 操作 ");
|
||||
}
|
||||
}
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
@@ -258,7 +255,7 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
isPressEnd = false;
|
||||
isCombinationKey = false;
|
||||
Log.e(TAG, "dispatchKeyEvent A up pressAUpTime = " + pressAUpTime + "---" + (pressAUpTime - startPressTime) + "--pressBDownTime = " + pressBDownTime);
|
||||
if ((pressAUpTime - startPressTime) < 500) {
|
||||
if ((pressAUpTime - startPressTime) < 300) {
|
||||
ToastUtils.showShort("方块 单击A -1 ");
|
||||
sendAcc(true, -1);
|
||||
}
|
||||
@@ -266,79 +263,77 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (event.getKeyCode() == KeyEvent.KEYCODE_B) { //单击向右变道,长按-2
|
||||
} else if (event.getKeyCode() == KeyEvent.KEYCODE_B) {//单击复原,长按+1,AB组合-2
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
pressBDownTime = System.currentTimeMillis();
|
||||
Log.d(TAG, "dispatchKeyEvent B down pressBDownTime = " + pressBDownTime + "--差-" + (pressBDownTime - startPressTime) + "---isCombinationKey = " + isCombinationKey + "--pressADownTime = " + pressADownTime);
|
||||
if ((pressBDownTime - startPressTime) > 550 && (pressBDownTime - startPressTime) < 1900 && pressADownTime > 0) {
|
||||
if ((pressBDownTime - startPressTime) > 350 && (pressBDownTime - startPressTime) < 1800 && pressADownTime > 0) {
|
||||
ToastUtils.showShort("方块 B 按AB组合 ");
|
||||
sendAcc(true, -2);
|
||||
isCombinationKey = true;
|
||||
}
|
||||
|
||||
if (!isCombinationKey) {
|
||||
if ((pressBDownTime - startPressTime) > 2000) {
|
||||
if ((pressBDownTime - startPressTime) > 1900) {
|
||||
ToastUtils.showShort("方块 长按B =1 ");
|
||||
sendAcc(true, +1);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
pressBUpTime = System.currentTimeMillis();
|
||||
isPressEnd = false;
|
||||
isCombinationKey = false;
|
||||
Log.e(TAG, "dispatchKeyEvent B up pressBUpTime = " + pressBUpTime + "--差-" + (pressBUpTime - startPressTime) + "--pressADownTime = " + pressADownTime);
|
||||
if ((pressBUpTime - startPressTime) < 500) {
|
||||
if ((pressBUpTime - startPressTime) < 300) {
|
||||
ToastUtils.showShort("方块 单击B 0 ");
|
||||
sendAcc(false, 0.0);
|
||||
}
|
||||
|
||||
pressBDownTime = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (event.getKeyCode() == KeyEvent.KEYCODE_C) { //单击鸣笛,
|
||||
} else if (event.getKeyCode() == KeyEvent.KEYCODE_C) { //单击左变道,长按无操作
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
numberC++;
|
||||
if (numberC > 2) {
|
||||
if (!isLongPressC) {
|
||||
// ToastUtils.showShort("方块 长按C 无操作");
|
||||
isLongPressC = true;
|
||||
pressCDownTime = System.currentTimeMillis();
|
||||
if (!isCombinationKey) {
|
||||
if ((pressCDownTime - startPressTime) > 1900) {
|
||||
ToastUtils.showShort("方块 长按C 无操作 ");
|
||||
}
|
||||
}
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
if (numberC == 1) {
|
||||
// ToastUtils.showShort("方块 单击C ← 向左变道 ");
|
||||
pressCUpTime = System.currentTimeMillis();
|
||||
isPressEnd = false;
|
||||
isCombinationKey = false;
|
||||
if ((pressCUpTime - startPressTime) < 300) {
|
||||
ToastUtils.showShort("方块 单击C ← 向左变道 ");
|
||||
CallerAutoPilotManager.INSTANCE.sendOperatorChangeLaneLeft();
|
||||
}
|
||||
numberC = 0;
|
||||
isLongPressC = false;
|
||||
}
|
||||
return true;
|
||||
} else if (event.getKeyCode() == KeyEvent.KEYCODE_D) { //单击开启自动驾驶,
|
||||
} else if (event.getKeyCode() == KeyEvent.KEYCODE_D) { //单击向右变道,双击无操作
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
numberD++;
|
||||
if (numberD > 2) {
|
||||
if (!isLongPressD) {
|
||||
// ToastUtils.showShort("方块 长按D 无操作");
|
||||
isLongPressD = true;
|
||||
pressDDownTime = System.currentTimeMillis();
|
||||
if (!isCombinationKey) {
|
||||
if ((pressDDownTime - startPressTime) > 1900) {
|
||||
ToastUtils.showShort("方块 长按D 无操作 ");
|
||||
}
|
||||
}
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
if (numberD == 1) {
|
||||
// ToastUtils.showShort("方块 单击D → 向右变道 ");
|
||||
pressDUpTime = System.currentTimeMillis();
|
||||
isPressEnd = false;
|
||||
isCombinationKey = false;
|
||||
if ((pressDUpTime - startPressTime) < 300) {
|
||||
ToastUtils.showShort("方块 单击D → 向右变道 ");
|
||||
CallerAutoPilotManager.INSTANCE.sendOperatorChangeLaneRight();
|
||||
}
|
||||
numberD = 0;
|
||||
isLongPressD = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (event.getKeyCode() == KeyEvent.KEYCODE_E) { //单击复原,
|
||||
} else if (event.getKeyCode() == KeyEvent.KEYCODE_E) { //单击启动自驾,长按鸣笛
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
numberE++;
|
||||
if (numberE > 2) {
|
||||
if (!isLongPressE) {
|
||||
// ToastUtils.showShort("方块 长按E 鸣笛 ");
|
||||
pressEDownTime = System.currentTimeMillis();
|
||||
if (!isCombinationKey) {
|
||||
if ((pressEDownTime - startPressTime) > 1900) {
|
||||
ToastUtils.showShort("方块 长按E 鸣笛 ");
|
||||
CallerAutoPilotManager.INSTANCE.sendOperatorSetHorn(1);
|
||||
if (timerHorn == null) {
|
||||
timerHorn = new Timer();
|
||||
@@ -350,18 +345,18 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
timerHorn = null;
|
||||
}
|
||||
}, 500);
|
||||
isLongPressE = true;
|
||||
}
|
||||
}
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
if (numberE == 1) {
|
||||
// ToastUtils.showShort("方块 单击E 开启自动驾驶 ");
|
||||
// CallerAutoPilotManager.INSTANCE.setControlAutopilotCarAuto(true);
|
||||
pressEUpTime = System.currentTimeMillis();
|
||||
isPressEnd = false;
|
||||
isCombinationKey = false;
|
||||
if ((pressEUpTime - startPressTime) < 300) {
|
||||
ToastUtils.showShort("方块 单击E 开启自动驾驶 ");
|
||||
CallerAutoPilotManager.INSTANCE.startAutoPilot(CallerAutoPilotStatusListenerManager.INSTANCE.getAutoPilotStatusInfo().getAutopilotControlParameters());
|
||||
}
|
||||
numberE = 0;
|
||||
isLongPressE = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -416,7 +411,6 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
* 查找蓝牙连接过的蓝牙设备
|
||||
*/
|
||||
private void showBondedDevice(BluetoothAdapter bluetoothAdapter) {
|
||||
// mAreadlyConnectedList.clear();
|
||||
Set<BluetoothDevice> deviceList = bluetoothAdapter.getBondedDevices();
|
||||
for (BluetoothDevice device : deviceList) {
|
||||
try {
|
||||
@@ -424,27 +418,14 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
Method isConnectedMethod = BluetoothDevice.class.getDeclaredMethod("isConnected", (Class[]) null);
|
||||
isConnectedMethod.setAccessible(true);
|
||||
// boolean isConnected = (boolean) isConnectedMethod.invoke(device, (Object[]) null);
|
||||
// mAreadlyConnectedList.add(device);
|
||||
Log.d(TAG, "-- device.getName() = " + device.getName()); //device.getAddress()
|
||||
if (device.getName().equals("MINI_KEYBOARD")) {
|
||||
SharedPrefsMgr.getInstance(getContext()).putString("BLUETOOTH", device.getName());
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
// } catch (IllegalAccessException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (InvocationTargetException e) {
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onAutoConnection(ConnectBluetoothEvent event) {
|
||||
// connectBluetooth();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user