214 lines
7.5 KiB
Java
214 lines
7.5 KiB
Java
package com.ubt.jimu.blockly.command;
|
|
|
|
import android.text.TextUtils;
|
|
import android.webkit.WebView;
|
|
import com.ubt.jimu.blockly.bean.BlocklyProject;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.net.URLDecoder;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class BlocklyCommandController {
|
|
public static final String ACTION = "action";
|
|
public static final String ADJUST_SERVO = "adjustServo";
|
|
public static final String BASE_REQUEST_URL = "jimu://";
|
|
public static final String GET_POSTURE = "getPosture";
|
|
public static final String QUERY = "query";
|
|
public static final String QUERY_ALL_SENSOR = "queryAllSensor";
|
|
public static final String QUERY_GYROSCOPE = "queryGyroscope";
|
|
public static final String QUERY_INFRARED = "queryInfrared";
|
|
public static final String QUERY_TOUCH_STATUS = "queryTouchStatus";
|
|
public static final String SERVO_POWER_OFF = "servoPowerOff";
|
|
public static final String SERVO_POWER_ON = "servoPowerOn";
|
|
public static final String SERVO_SET = "servoSet";
|
|
public static final String SERVO_SETBY_SPEED = "servoSetbySpeed";
|
|
public static final String SET_DIGITAL_TUBE = "setDigitalTube";
|
|
public static final String SET_EMOJI = "setEmoji";
|
|
public static final String SET_LEDS = "setLEDs";
|
|
public static final String SET_SERSOR_LED = "setSensorLED";
|
|
public static final String SET_SERVO_MODE = "setServoMode";
|
|
public static final String STOP_ROBOT = "stopRobot";
|
|
public static final String STOP_SERVO = "stopServo";
|
|
private JimuBlocklyCommand jsInterface;
|
|
private final String tag = BlocklyCommandController.class.getSimpleName();
|
|
public final String CONFIRM = "confirm";
|
|
public final String SAVE_XML = "SaveXml";
|
|
public final String READ_XML = "ReadXml";
|
|
public final String DELETE_XML = "DeleteXml";
|
|
public final String XML_LIST = "XmlList";
|
|
public final String CONNECT_BLE = JimuBlocklyCommand.CONNECT_BLE;
|
|
public final String DISCONNECT_BLE = "DisconnectBLE";
|
|
public final String CLOSE_WINDOW = "CloseWindow";
|
|
public final String BLE_STATE = JimuBlocklyCommand.BLE_STATE;
|
|
public final String OPEN_HEART_BEAT = "openHeartbeat";
|
|
public final String CLOSE_HEART_BEAT = "closeHeartbeat";
|
|
public final String START_SENSOR_TIMER = "startInfraredTimer";
|
|
public final String STOP_SENSOR_TIMER = "stopInfraredTimer";
|
|
|
|
public BlocklyCommandController(JimuBlocklyCommand jimuBlocklyCommand) {
|
|
this.jsInterface = jimuBlocklyCommand;
|
|
}
|
|
|
|
private void bleStateCommand(String str) {
|
|
this.jsInterface.bleState();
|
|
}
|
|
|
|
private void closeWindowCommand() {
|
|
this.jsInterface.closeWindow();
|
|
}
|
|
|
|
private void confirmCommand(String str) {
|
|
this.jsInterface.confirm(str);
|
|
}
|
|
|
|
private void connectedBLECommand() {
|
|
this.jsInterface.connectedBLE();
|
|
}
|
|
|
|
private void deleteXmlCommand(String str) {
|
|
BlocklyCommand blocklyCommand = new BlocklyCommand(str, BlocklyProject.class);
|
|
this.jsInterface.deleteXml(((BlocklyProject) blocklyCommand.getArg()).getXmlId(), blocklyCommand.getCallback());
|
|
}
|
|
|
|
private void disconnectBleCommand(String str) {
|
|
this.jsInterface.notifyBLEState("{\"blueState\":3}");
|
|
this.jsInterface.unityComm(str);
|
|
}
|
|
|
|
private void distribute(String str, String str2) {
|
|
if (str2.contains("confirm")) {
|
|
confirmCommand(str);
|
|
return;
|
|
}
|
|
if (str2.contains(JimuBlocklyCommand.CONNECT_BLE)) {
|
|
connectedBLECommand();
|
|
return;
|
|
}
|
|
if (str2.contains("CloseWindow")) {
|
|
closeWindowCommand();
|
|
return;
|
|
}
|
|
if (str2.contains("ReadXml")) {
|
|
readXmlCommand(str);
|
|
return;
|
|
}
|
|
if (str2.contains("SaveXml")) {
|
|
saveXmlCommand(str);
|
|
return;
|
|
}
|
|
if (str2.contains("DeleteXml")) {
|
|
deleteXmlCommand(str);
|
|
return;
|
|
}
|
|
if (str2.contains("XmlList")) {
|
|
xmlListCommand(str);
|
|
return;
|
|
}
|
|
if (str2.contains(JimuBlocklyCommand.BLE_STATE)) {
|
|
bleStateCommand(str);
|
|
return;
|
|
}
|
|
if (str2.contains("openHeartbeat")) {
|
|
heartBeatCommand("1");
|
|
return;
|
|
}
|
|
if (str2.contains("closeHeartbeat")) {
|
|
heartBeatCommand("0");
|
|
return;
|
|
}
|
|
if (str2.contains("startInfraredTimer")) {
|
|
startInfraredTimerCommand(str);
|
|
return;
|
|
}
|
|
if (str2.contains("stopInfraredTimer")) {
|
|
stopInfraredTimerCommand(str);
|
|
return;
|
|
}
|
|
if (str2.contains(QUERY_INFRARED)) {
|
|
queryInfraredCommand(str);
|
|
return;
|
|
}
|
|
if (str2.contains("DisconnectBLE")) {
|
|
disconnectBleCommand(str);
|
|
return;
|
|
}
|
|
if (str2.contains("setServoMode")) {
|
|
setServoMode();
|
|
} else if (str2.contains(SERVO_SET)) {
|
|
servoSet(str, str2);
|
|
} else {
|
|
unityCommand(str);
|
|
}
|
|
}
|
|
|
|
private void heartBeatCommand(String str) {
|
|
this.jsInterface.heartBeat(str);
|
|
}
|
|
|
|
private void queryInfraredCommand(String str) {
|
|
this.jsInterface.queryInfrared(str, new BlocklyCommand(str, null).getCallback());
|
|
}
|
|
|
|
private void readXmlCommand(String str) {
|
|
BlocklyCommand blocklyCommand = new BlocklyCommand(str, BlocklyProject.class);
|
|
BlocklyProject blocklyProject = (BlocklyProject) blocklyCommand.getArg();
|
|
if (blocklyProject != null) {
|
|
this.jsInterface.readXml(blocklyProject.getXmlId(), blocklyCommand.getCallback());
|
|
}
|
|
}
|
|
|
|
private void saveXmlCommand(String str) {
|
|
BlocklyCommand blocklyCommand = new BlocklyCommand(str, BlocklyProject.class);
|
|
this.jsInterface.saveXml(((BlocklyProject) blocklyCommand.getArg()).getXmlName(), ((BlocklyProject) blocklyCommand.getArg()).getXmlContent(), ((BlocklyProject) blocklyCommand.getArg()).getXmlId(), ((BlocklyProject) blocklyCommand.getArg()).getBlocklyVersion(), blocklyCommand.getCallback());
|
|
}
|
|
|
|
private void servoSet(String str, String str2) {
|
|
String[] split = str.split("\\|");
|
|
if (TextUtils.isEmpty(split[1])) {
|
|
this.jsInterface.servoSet(split[2]);
|
|
} else {
|
|
unityCommand(str);
|
|
}
|
|
}
|
|
|
|
private void setServoMode() {
|
|
this.jsInterface.setServoMode();
|
|
}
|
|
|
|
private void startInfraredTimerCommand(String str) {
|
|
this.jsInterface.startSensorTimer(str, new BlocklyCommand(str, BlocklyProject.class).getCallback());
|
|
}
|
|
|
|
private void stopInfraredTimerCommand(String str) {
|
|
this.jsInterface.stopSensorTimer(str);
|
|
}
|
|
|
|
private void unityCommand(String str) {
|
|
this.jsInterface.unityComm(str);
|
|
}
|
|
|
|
private void xmlListCommand(String str) {
|
|
this.jsInterface.xmlList(new BlocklyCommand(str, BlocklyProject.class).getCallback());
|
|
}
|
|
|
|
public JimuBlocklyCommand getJsInterface() {
|
|
return this.jsInterface;
|
|
}
|
|
|
|
public boolean onBlocklyCommand(WebView webView, String str) {
|
|
if (TextUtils.isEmpty(str)) {
|
|
return false;
|
|
}
|
|
try {
|
|
String decode = URLDecoder.decode(str, "UTF-8");
|
|
if (!decode.startsWith(BASE_REQUEST_URL)) {
|
|
return false;
|
|
}
|
|
distribute(decode, decode.split("\\|")[0]);
|
|
return true;
|
|
} catch (UnsupportedEncodingException e) {
|
|
e.printStackTrace();
|
|
return false;
|
|
}
|
|
}
|
|
}
|