删除魔戒的实现,添加操作魔方的约束
This commit is contained in:
@@ -71,7 +71,7 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
|
||||
private BluetoothMonitorReceiver mBluetoothReceiver = null;
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
private List<BluetoothDevice> mAreadlyConnectedList = new ArrayList<>();//已连接设备集合
|
||||
// private List<BluetoothDevice> mAreadlyConnectedList = new ArrayList<>();//已连接设备集合
|
||||
private int numberA = 0;
|
||||
private boolean isLongPressA = false;
|
||||
private int numberB = 0;
|
||||
@@ -98,13 +98,11 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
super.onResume();
|
||||
|
||||
initBluetooth();
|
||||
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (!mBluetoothAdapter.isEnabled()) {
|
||||
mBluetoothAdapter.enable();
|
||||
}
|
||||
mBluetoothAdapter.startDiscovery();
|
||||
|
||||
showBondedDevice(mBluetoothAdapter);
|
||||
}
|
||||
|
||||
@@ -212,30 +210,6 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { //向上长按 开启自动驾驶
|
||||
long currentTime = System.currentTimeMillis() / (1000);
|
||||
long oldTime = SharedPrefsMgr.getInstance(getContext()).getLong("old_time_up", 0);
|
||||
if (currentTime - oldTime > 6) {
|
||||
SharedPrefsMgr.getInstance(getContext()).putLong("old_time_up", System.currentTimeMillis() / 1000);
|
||||
// ToastUtils.showShort("长按 ↑↑↑ 开启自动驾驶");
|
||||
// CallerAutoPilotManager.INSTANCE.setControlAutopilotCarAuto(true);
|
||||
CallerAutoPilotManager.INSTANCE.startAutoPilot(CallerAutoPilotStatusListenerManager.INSTANCE.getAutoPilotStatusInfo().getAutopilotControlParameters());
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { //下和中间键盘长按,减速为-2
|
||||
long currentTime = System.currentTimeMillis() / (1000);
|
||||
long oldTime = SharedPrefsMgr.getInstance(getContext()).getLong("old_time_down", 0);
|
||||
if (currentTime - oldTime > 6) {
|
||||
SharedPrefsMgr.getInstance(getContext()).putLong("old_time_down", System.currentTimeMillis() / 1000);
|
||||
// ToastUtils.showShort("长按 ↓↓↓ 减速 -2 ");
|
||||
sendAcc(true, -2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Log.e("liyz", "onKeyDown keyCode = " + keyCode + "--action = " + event.getAction() + "---" + event);
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@@ -243,109 +217,112 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
// Log.d("liyz", "dispatchKeyEvent code = " + event.getKeyCode() + "--action = " + event.getAction() + "----" + event);
|
||||
if (event.getKeyCode() == KeyEvent.KEYCODE_A) { //单击向左变道,长按-1
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
numberA++;
|
||||
if (numberA > 2) {
|
||||
if (!isLongPressA) {
|
||||
// ToastUtils.showShort("方块 长按A -2 ");
|
||||
sendAcc(true, -2);
|
||||
isLongPressA = true;
|
||||
}
|
||||
}
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
if (numberA == 1) {
|
||||
// ToastUtils.showShort("方块 点击A -1 ");
|
||||
sendAcc(true, -1);
|
||||
}
|
||||
numberA = 0;
|
||||
isLongPressA = false;
|
||||
}
|
||||
return true;
|
||||
} else if (event.getKeyCode() == KeyEvent.KEYCODE_B) { //单击向右变道,长按-2
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
numberB++;
|
||||
if (numberB > 2) {
|
||||
if (!isLongPressB) {
|
||||
// ToastUtils.showShort("方块 长按B 无操作 ");
|
||||
isLongPressB = true;
|
||||
}
|
||||
}
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
if (numberB == 1) {
|
||||
// ToastUtils.showShort("方块 单击B 复原 ");
|
||||
sendAcc(false, 0.0);
|
||||
}
|
||||
numberB = 0;
|
||||
isLongPressB = false;
|
||||
}
|
||||
return true;
|
||||
} else if (event.getKeyCode() == KeyEvent.KEYCODE_C) { //单击鸣笛,
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
numberC++;
|
||||
if (numberC > 2) {
|
||||
if (!isLongPressC) {
|
||||
// ToastUtils.showShort("方块 长按C 无操作");
|
||||
isLongPressC = true;
|
||||
}
|
||||
}
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
if (numberC == 1) {
|
||||
// ToastUtils.showShort("方块 单击C ← 向左变道 ");
|
||||
CallerAutoPilotManager.INSTANCE.sendOperatorChangeLaneLeft();
|
||||
}
|
||||
numberC = 0;
|
||||
isLongPressC = false;
|
||||
}
|
||||
return true;
|
||||
} else if (event.getKeyCode() == KeyEvent.KEYCODE_D) { //单击开启自动驾驶,
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
numberD++;
|
||||
if (numberD > 2) {
|
||||
if (!isLongPressD) {
|
||||
// ToastUtils.showShort("方块 长按D 无操作");
|
||||
isLongPressD = true;
|
||||
}
|
||||
}
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
if (numberD == 1) {
|
||||
// ToastUtils.showShort("方块 单击D → 向右变道 ");
|
||||
CallerAutoPilotManager.INSTANCE.sendOperatorChangeLaneRight();
|
||||
}
|
||||
numberD = 0;
|
||||
isLongPressD = false;
|
||||
}
|
||||
return true;
|
||||
} else if (event.getKeyCode() == KeyEvent.KEYCODE_E) { //单击复原,
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
numberE++;
|
||||
if (numberE > 2) {
|
||||
if (!isLongPressE) {
|
||||
// ToastUtils.showShort("方块 长按E 鸣笛 ");
|
||||
CallerAutoPilotManager.INSTANCE.sendOperatorSetHorn(1);
|
||||
if (timerHorn == null) {
|
||||
timerHorn = new Timer();
|
||||
String bluetoothName = SharedPrefsMgr.getInstance(getContext()).getString("BLUETOOTH");
|
||||
if (bluetoothName.equals("MINI_KEYBOARD")) {
|
||||
if (event.getKeyCode() == KeyEvent.KEYCODE_A) { //单击向左变道,长按-1
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
numberA++;
|
||||
if (numberA > 2) {
|
||||
if (!isLongPressA) {
|
||||
ToastUtils.showShort("方块 长按A -2 ");
|
||||
sendAcc(true, -2);
|
||||
isLongPressA = true;
|
||||
}
|
||||
timerHorn.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
CallerAutoPilotManager.INSTANCE.sendOperatorSetHorn(2);
|
||||
timerHorn = null;
|
||||
}
|
||||
}, 500);
|
||||
isLongPressE = true;
|
||||
}
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
if (numberA == 1) {
|
||||
ToastUtils.showShort("方块 点击A -1 ");
|
||||
sendAcc(true, -1);
|
||||
}
|
||||
numberA = 0;
|
||||
isLongPressA = false;
|
||||
}
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
if (numberE == 1) {
|
||||
// ToastUtils.showShort("方块 单击E 开启自动驾驶 ");
|
||||
return true;
|
||||
} else if (event.getKeyCode() == KeyEvent.KEYCODE_B) { //单击向右变道,长按-2
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
numberB++;
|
||||
if (numberB > 2) {
|
||||
if (!isLongPressB) {
|
||||
ToastUtils.showShort("方块 长按B 无操作 ");
|
||||
isLongPressB = true;
|
||||
}
|
||||
}
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
if (numberB == 1) {
|
||||
ToastUtils.showShort("方块 单击B 复原 ");
|
||||
sendAcc(false, 0.0);
|
||||
}
|
||||
numberB = 0;
|
||||
isLongPressB = false;
|
||||
}
|
||||
return true;
|
||||
} else if (event.getKeyCode() == KeyEvent.KEYCODE_C) { //单击鸣笛,
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
numberC++;
|
||||
if (numberC > 2) {
|
||||
if (!isLongPressC) {
|
||||
ToastUtils.showShort("方块 长按C 无操作");
|
||||
isLongPressC = true;
|
||||
}
|
||||
}
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
if (numberC == 1) {
|
||||
ToastUtils.showShort("方块 单击C ← 向左变道 ");
|
||||
CallerAutoPilotManager.INSTANCE.sendOperatorChangeLaneLeft();
|
||||
}
|
||||
numberC = 0;
|
||||
isLongPressC = false;
|
||||
}
|
||||
return true;
|
||||
} else if (event.getKeyCode() == KeyEvent.KEYCODE_D) { //单击开启自动驾驶,
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
numberD++;
|
||||
if (numberD > 2) {
|
||||
if (!isLongPressD) {
|
||||
ToastUtils.showShort("方块 长按D 无操作");
|
||||
isLongPressD = true;
|
||||
}
|
||||
}
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
if (numberD == 1) {
|
||||
ToastUtils.showShort("方块 单击D → 向右变道 ");
|
||||
CallerAutoPilotManager.INSTANCE.sendOperatorChangeLaneRight();
|
||||
}
|
||||
numberD = 0;
|
||||
isLongPressD = false;
|
||||
}
|
||||
return true;
|
||||
} else if (event.getKeyCode() == KeyEvent.KEYCODE_E) { //单击复原,
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
numberE++;
|
||||
if (numberE > 2) {
|
||||
if (!isLongPressE) {
|
||||
ToastUtils.showShort("方块 长按E 鸣笛 ");
|
||||
CallerAutoPilotManager.INSTANCE.sendOperatorSetHorn(1);
|
||||
if (timerHorn == null) {
|
||||
timerHorn = new Timer();
|
||||
}
|
||||
timerHorn.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
CallerAutoPilotManager.INSTANCE.sendOperatorSetHorn(2);
|
||||
timerHorn = null;
|
||||
}
|
||||
}, 500);
|
||||
isLongPressE = true;
|
||||
}
|
||||
}
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
if (numberE == 1) {
|
||||
ToastUtils.showShort("方块 单击E 开启自动驾驶 ");
|
||||
// CallerAutoPilotManager.INSTANCE.setControlAutopilotCarAuto(true);
|
||||
CallerAutoPilotManager.INSTANCE.startAutoPilot(CallerAutoPilotStatusListenerManager.INSTANCE.getAutoPilotStatusInfo().getAutopilotControlParameters());
|
||||
CallerAutoPilotManager.INSTANCE.startAutoPilot(CallerAutoPilotStatusListenerManager.INSTANCE.getAutoPilotStatusInfo().getAutopilotControlParameters());
|
||||
}
|
||||
numberE = 0;
|
||||
isLongPressE = false;
|
||||
}
|
||||
numberE = 0;
|
||||
isLongPressE = false;
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.dispatchKeyEvent(event);
|
||||
@@ -353,43 +330,6 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent event) {
|
||||
// Log.d("liyz", "dispatchTouchEvent event.getX() = " + event.getX() + "--event.getY() = " + event.getY() + "--action = " + event.getAction());
|
||||
if (event.getX() == -1469.6875 && event.getY() == 530.0) { //向左变道
|
||||
// ToastUtils.showShort("← 向左变道");
|
||||
CallerAutoPilotManager.INSTANCE.sendOperatorChangeLaneLeft();
|
||||
|
||||
return true;
|
||||
} else if (event.getX() == -1096.25 && event.getY() == 132.5) { //鸣笛
|
||||
// ToastUtils.showShort("↑ 鸣笛 ");
|
||||
CallerAutoPilotManager.INSTANCE.sendOperatorSetHorn(1);
|
||||
|
||||
if (timerHorn == null) {
|
||||
timerHorn = new Timer();
|
||||
}
|
||||
timerHorn.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
CallerAutoPilotManager.INSTANCE.sendOperatorSetHorn(2);
|
||||
timerHorn = null;
|
||||
}
|
||||
}, 500);
|
||||
|
||||
return true;
|
||||
} else if (event.getX() == -863.4375 && event.getY() == 690.0) { //向右变道
|
||||
CallerAutoPilotManager.INSTANCE.sendOperatorChangeLaneRight();
|
||||
// ToastUtils.showShort("→ 向右变道");
|
||||
return true;
|
||||
} else if (event.getX() == -1096.25 && event.getY() == 1099.0) { // -1减速
|
||||
sendAcc(true, -1);
|
||||
// ToastUtils.showShort("↓ 减速 -1 ");
|
||||
|
||||
return true;
|
||||
} else if (event.getX() == -1096.25 && event.getY() == 690.0) { //复原
|
||||
// ToastUtils.showShort("O 复原 ");
|
||||
sendAcc(false, 0.0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.dispatchTouchEvent(event);
|
||||
}
|
||||
@@ -444,10 +384,9 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
/**
|
||||
* 查找蓝牙连接过的蓝牙设备
|
||||
*
|
||||
* @param bluetoothAdapter
|
||||
*/
|
||||
private void showBondedDevice(BluetoothAdapter bluetoothAdapter) {
|
||||
mAreadlyConnectedList.clear();
|
||||
// mAreadlyConnectedList.clear();
|
||||
Set<BluetoothDevice> deviceList = bluetoothAdapter.getBondedDevices();
|
||||
for (BluetoothDevice device : deviceList) {
|
||||
try {
|
||||
@@ -455,14 +394,10 @@ 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);
|
||||
if (device.getName().equals("JX-05")) { //后面魔戒可能不使用了
|
||||
SharedPrefsMgr.getInstance(getContext()).putString("BT_MAC", device.getAddress());
|
||||
}
|
||||
if (!isConnected) {
|
||||
UiThreadHandler.postDelayed(() -> {
|
||||
connectBluetooth(); //主动连接一次
|
||||
}, 4000L);
|
||||
// mAreadlyConnectedList.add(device);
|
||||
// Log.d("liyz", "-- device.getName() = " + device.getName()); //device.getAddress()
|
||||
if (device.getName().equals("MINI_KEYBOARD")) {
|
||||
SharedPrefsMgr.getInstance(getContext()).putString("BLUETOOTH", device.getName());
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
@@ -474,41 +409,11 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onAutoConnection(ConnectBluetoothEvent event) {
|
||||
// connectBluetooth();
|
||||
}
|
||||
|
||||
/**
|
||||
* 主动连接最近的一次连接
|
||||
*/
|
||||
private void connectBluetooth() {
|
||||
if (mAreadlyConnectedList.size() > 0) {
|
||||
try {
|
||||
Method method = BluetoothDevice.class.getMethod("createBond");
|
||||
String macAddress = SharedPrefsMgr.getInstance(getContext()).getString("BT_MAC");
|
||||
int pos = -1;
|
||||
for (int i = 0; i < mAreadlyConnectedList.size(); i++) {
|
||||
if (macAddress.equals(mAreadlyConnectedList.get(i).getAddress())) {
|
||||
pos = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (mAreadlyConnectedList.size() > pos && (pos >= 0)) {
|
||||
method.invoke(mAreadlyConnectedList.get(pos));
|
||||
}
|
||||
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user