Initial commit
This commit is contained in:
364
sources/com/ubt/jimu/controller/manager/ActionManager.java
Normal file
364
sources/com/ubt/jimu/controller/manager/ActionManager.java
Normal file
@@ -0,0 +1,364 @@
|
||||
package com.ubt.jimu.controller.manager;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.util.SparseArray;
|
||||
import com.ubt.jimu.R;
|
||||
import com.ubt.jimu.base.entities.RobotLite;
|
||||
import com.ubt.jimu.base.util.PathHelper;
|
||||
import com.ubt.jimu.controller.data.action.Action;
|
||||
import com.ubt.jimu.controller.data.action.ActionIcon;
|
||||
import com.ubt.jimu.controller.data.action.ActionSequence;
|
||||
import com.ubt.jimu.controller.data.action.MotorData;
|
||||
import com.ubt.jimu.controller.data.action.TurnData;
|
||||
import com.ubt.jimu.controller.data.widget.ActionWidgetData;
|
||||
import com.ubt.jimu.controller.data.widget.JockstickDataConverter;
|
||||
import com.ubt.jimu.transport.model.TransportFile;
|
||||
import com.unity3d.ads.metadata.MediationMetaData;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class ActionManager {
|
||||
private static ActionManager e;
|
||||
private Context a;
|
||||
private List<ActionSequence> b = new CopyOnWriteArrayList();
|
||||
private final Map<String, ActionIcon> c = new HashMap();
|
||||
private RobotLite d;
|
||||
|
||||
private ActionManager(Context context) {
|
||||
this.a = context.getApplicationContext();
|
||||
d();
|
||||
}
|
||||
|
||||
public static synchronized ActionManager a(Context context) {
|
||||
ActionManager actionManager;
|
||||
synchronized (ActionManager.class) {
|
||||
if (e == null) {
|
||||
e = new ActionManager(context);
|
||||
}
|
||||
actionManager = e;
|
||||
}
|
||||
return actionManager;
|
||||
}
|
||||
|
||||
private void c() {
|
||||
List<ActionSequence> list = this.b;
|
||||
if (list != null) {
|
||||
list.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private void d() {
|
||||
String[] stringArray = this.a.getResources().getStringArray(R.array.action_icon_key);
|
||||
TypedArray obtainTypedArray = this.a.getResources().obtainTypedArray(R.array.action_icon_drawable);
|
||||
for (int i = 0; i < stringArray.length; i++) {
|
||||
this.c.put(stringArray[i], new ActionIcon(stringArray[i], obtainTypedArray.getResourceId(i, 0)));
|
||||
}
|
||||
}
|
||||
|
||||
public void b() {
|
||||
if (this.d != null) {
|
||||
c();
|
||||
a(this.d.isOfficial());
|
||||
}
|
||||
}
|
||||
|
||||
private void c(XmlPullParser xmlPullParser, Action action) {
|
||||
String attributeValue = xmlPullParser.getAttributeValue(null, TransportFile.TYPE_DIY_SHOW);
|
||||
if (TextUtils.isEmpty(attributeValue)) {
|
||||
return;
|
||||
}
|
||||
String[] split = attributeValue.split(";");
|
||||
if (split.length > 0) {
|
||||
ArrayList arrayList = new ArrayList(split.length);
|
||||
for (String str : split) {
|
||||
arrayList.add(Integer.valueOf(str.trim()));
|
||||
}
|
||||
action.a(arrayList);
|
||||
}
|
||||
}
|
||||
|
||||
public void a(RobotLite robotLite) {
|
||||
this.d = robotLite;
|
||||
b();
|
||||
}
|
||||
|
||||
public ActionIcon b(String str) {
|
||||
Map<String, ActionIcon> map = this.c;
|
||||
if (map == null || map.size() <= 0) {
|
||||
return null;
|
||||
}
|
||||
return this.c.get(str);
|
||||
}
|
||||
|
||||
private void b(boolean z) {
|
||||
File[] listFiles;
|
||||
File file = new File(PathHelper.getActionDir(this.a, this.d, z));
|
||||
if (!file.exists() || !file.isDirectory() || (listFiles = file.listFiles()) == null || listFiles.length <= 0) {
|
||||
return;
|
||||
}
|
||||
a(listFiles, z);
|
||||
}
|
||||
|
||||
private void d(XmlPullParser xmlPullParser, Action action) {
|
||||
String attributeValue = xmlPullParser.getAttributeValue(null, "turns");
|
||||
if (TextUtils.isEmpty(attributeValue)) {
|
||||
return;
|
||||
}
|
||||
String[] split = attributeValue.split(";");
|
||||
TreeMap treeMap = new TreeMap();
|
||||
for (String str : split) {
|
||||
String[] split2 = str.split("\\$");
|
||||
if (split2.length > 1) {
|
||||
String[] split3 = split2[1].split(",");
|
||||
int intValue = Integer.valueOf(split3[0].trim()).intValue();
|
||||
if (intValue == 2) {
|
||||
intValue = -1;
|
||||
}
|
||||
treeMap.put(Integer.valueOf(split2[0].trim()), new TurnData(intValue, Integer.valueOf(split3[1].trim()).intValue()));
|
||||
}
|
||||
}
|
||||
action.c(treeMap);
|
||||
}
|
||||
|
||||
public ActionSequence a(String str) {
|
||||
List<ActionSequence> list = this.b;
|
||||
if (list == null || list.size() <= 0) {
|
||||
return null;
|
||||
}
|
||||
for (ActionSequence actionSequence : this.b) {
|
||||
if (actionSequence.e().equals(str)) {
|
||||
return actionSequence;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void a(boolean z) {
|
||||
if (z) {
|
||||
b(false);
|
||||
b(true);
|
||||
} else {
|
||||
b(true);
|
||||
}
|
||||
List<ActionSequence> list = this.b;
|
||||
if (list == null || list.size() <= 1) {
|
||||
return;
|
||||
}
|
||||
a aVar = new Comparator() { // from class: com.ubt.jimu.controller.manager.a
|
||||
@Override // java.util.Comparator
|
||||
public final int compare(Object obj, Object obj2) {
|
||||
return ActionManager.a((ActionSequence) obj, (ActionSequence) obj2);
|
||||
}
|
||||
};
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
this.b.sort(aVar);
|
||||
return;
|
||||
}
|
||||
ArrayList arrayList = new ArrayList(this.b);
|
||||
Collections.sort(arrayList, aVar);
|
||||
this.b.clear();
|
||||
this.b.addAll(arrayList);
|
||||
}
|
||||
|
||||
private int c(String str) {
|
||||
if (!TextUtils.isEmpty(str)) {
|
||||
try {
|
||||
return Integer.valueOf(str.trim()).intValue();
|
||||
} catch (NumberFormatException e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void b(ActionSequence actionSequence, XmlPullParser xmlPullParser) {
|
||||
actionSequence.e(xmlPullParser.getAttributeValue(null, MediationMetaData.KEY_NAME));
|
||||
a(actionSequence, xmlPullParser.getAttributeValue(null, "showName"));
|
||||
actionSequence.f(xmlPullParser.getAttributeValue(null, "robotID"));
|
||||
actionSequence.c(xmlPullParser.getAttributeValue(null, JockstickDataConverter.ID));
|
||||
actionSequence.b(xmlPullParser.getAttributeValue(null, "icon"));
|
||||
actionSequence.a(Long.valueOf(xmlPullParser.getAttributeValue(null, "createTime")).longValue());
|
||||
}
|
||||
|
||||
private void b(XmlPullParser xmlPullParser, Action action) {
|
||||
String attributeValue = xmlPullParser.getAttributeValue(null, "rotas");
|
||||
if (TextUtils.isEmpty(attributeValue)) {
|
||||
return;
|
||||
}
|
||||
String[] split = attributeValue.split(";");
|
||||
TreeMap treeMap = new TreeMap();
|
||||
for (String str : split) {
|
||||
String[] split2 = str.split("\\$");
|
||||
if (split2.length > 1) {
|
||||
treeMap.put(Integer.valueOf(split2[0].trim()), Integer.valueOf(split2[1].trim()));
|
||||
}
|
||||
}
|
||||
action.b(treeMap);
|
||||
}
|
||||
|
||||
static /* synthetic */ int a(ActionSequence actionSequence, ActionSequence actionSequence2) {
|
||||
if (actionSequence.j() != actionSequence2.j()) {
|
||||
return actionSequence.j() ? 1 : -1;
|
||||
}
|
||||
long b = actionSequence2.b() - actionSequence.b();
|
||||
if (b > 0) {
|
||||
return 1;
|
||||
}
|
||||
return b < 0 ? -1 : 0;
|
||||
}
|
||||
|
||||
private void a(File[] fileArr, boolean z) {
|
||||
ActionSequence a;
|
||||
for (File file : fileArr) {
|
||||
if (file.isFile() && (a = a(file)) != null) {
|
||||
ActionIcon b = b(a.c());
|
||||
if (b != null) {
|
||||
a.a(b.a());
|
||||
}
|
||||
a.a(!z);
|
||||
String soundPath = PathHelper.getSoundPath(this.a, this.d, a);
|
||||
if (!TextUtils.isEmpty(soundPath)) {
|
||||
a.d(soundPath);
|
||||
}
|
||||
this.b.add(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ActionSequence a(File file) {
|
||||
try {
|
||||
FileInputStream fileInputStream = new FileInputStream(file);
|
||||
try {
|
||||
XmlPullParser newPullParser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
newPullParser.setInput(fileInputStream, "utf-8");
|
||||
ActionSequence actionSequence = null;
|
||||
for (int eventType = newPullParser.getEventType(); eventType != 1; eventType = newPullParser.next()) {
|
||||
if (eventType != 0) {
|
||||
if (eventType == 2 && "Root".equals(newPullParser.getName())) {
|
||||
String attributeValue = newPullParser.getAttributeValue(null, "nodeType");
|
||||
if ("head".equals(attributeValue)) {
|
||||
b(actionSequence, newPullParser);
|
||||
} else if ("body".equals(attributeValue)) {
|
||||
a(actionSequence, newPullParser);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
actionSequence = new ActionSequence();
|
||||
}
|
||||
}
|
||||
fileInputStream.close();
|
||||
return actionSequence;
|
||||
} catch (Throwable th) {
|
||||
try {
|
||||
throw th;
|
||||
} catch (Throwable th2) {
|
||||
try {
|
||||
fileInputStream.close();
|
||||
} catch (Throwable th3) {
|
||||
th.addSuppressed(th3);
|
||||
}
|
||||
throw th2;
|
||||
}
|
||||
}
|
||||
} catch (IOException | NumberFormatException | XmlPullParserException e2) {
|
||||
e2.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void a(ActionSequence actionSequence, XmlPullParser xmlPullParser) {
|
||||
Action action = new Action();
|
||||
action.a(c(xmlPullParser.getAttributeValue(null, "index")));
|
||||
int c = c(xmlPullParser.getAttributeValue(null, "sportTime"));
|
||||
if (c > -1) {
|
||||
action.b(c);
|
||||
}
|
||||
int c2 = c(xmlPullParser.getAttributeValue(null, "waitTime"));
|
||||
if (c2 > -1) {
|
||||
action.c(c2);
|
||||
}
|
||||
b(xmlPullParser, action);
|
||||
d(xmlPullParser, action);
|
||||
a(xmlPullParser, action);
|
||||
c(xmlPullParser, action);
|
||||
actionSequence.a(action);
|
||||
}
|
||||
|
||||
private void a(XmlPullParser xmlPullParser, Action action) {
|
||||
String attributeValue = xmlPullParser.getAttributeValue(null, "motors");
|
||||
if (TextUtils.isEmpty(attributeValue)) {
|
||||
return;
|
||||
}
|
||||
String[] split = attributeValue.split(";");
|
||||
TreeMap treeMap = new TreeMap();
|
||||
for (String str : split) {
|
||||
String[] split2 = str.split("\\$");
|
||||
if (split2.length > 1) {
|
||||
String[] split3 = split2[1].split(",");
|
||||
if (split3.length >= 3) {
|
||||
int intValue = Integer.valueOf(split3[0].trim()).intValue();
|
||||
if (intValue == 2) {
|
||||
intValue = -1;
|
||||
}
|
||||
treeMap.put(Integer.valueOf(split2[0].trim()), new MotorData(intValue, Integer.valueOf(split3[1].trim()).intValue(), Integer.valueOf(split3[2].trim()).intValue()));
|
||||
} else if (split3.length >= 2) {
|
||||
int intValue2 = Integer.valueOf(split3[0].trim()).intValue();
|
||||
if (intValue2 == 2) {
|
||||
intValue2 = -1;
|
||||
}
|
||||
treeMap.put(Integer.valueOf(split2[0].trim()), new MotorData(intValue2, Integer.valueOf(split3[1].trim()).intValue(), 6553500));
|
||||
} else if (split3.length <= 1) {
|
||||
treeMap.put(Integer.valueOf(split2[0].trim()), new MotorData(0, 0, 6553500));
|
||||
}
|
||||
}
|
||||
}
|
||||
action.a(treeMap);
|
||||
}
|
||||
|
||||
private void a(ActionSequence actionSequence, String str) {
|
||||
if (TextUtils.isEmpty(str)) {
|
||||
return;
|
||||
}
|
||||
String[] split = str.split(";");
|
||||
SparseArray<String> sparseArray = new SparseArray<>(split.length);
|
||||
for (String str2 : split) {
|
||||
String[] split2 = str2.split("\\$");
|
||||
if (split2.length > 1) {
|
||||
sparseArray.put(Integer.valueOf(split2[0]).intValue(), split2[1]);
|
||||
}
|
||||
}
|
||||
actionSequence.a(sparseArray);
|
||||
}
|
||||
|
||||
public List<ActionWidgetData> a() {
|
||||
List<ActionSequence> list = this.b;
|
||||
if (list == null || list.size() <= 0) {
|
||||
return null;
|
||||
}
|
||||
ArrayList arrayList = new ArrayList(this.b.size());
|
||||
for (ActionSequence actionSequence : this.b) {
|
||||
ActionWidgetData actionWidgetData = new ActionWidgetData();
|
||||
actionWidgetData.setActionID(actionSequence.e());
|
||||
actionWidgetData.setActionNm(actionSequence.h());
|
||||
actionWidgetData.setActionSequence(actionSequence);
|
||||
arrayList.add(actionWidgetData);
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
}
|
401
sources/com/ubt/jimu/controller/manager/CommandManager.java
Normal file
401
sources/com/ubt/jimu/controller/manager/CommandManager.java
Normal file
@@ -0,0 +1,401 @@
|
||||
package com.ubt.jimu.controller.manager;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.SystemClock;
|
||||
import com.ubt.jimu.base.EngineManager;
|
||||
import com.ubt.jimu.base.cache.Cache;
|
||||
import com.ubt.jimu.base.data.CtrlMotionType;
|
||||
import com.ubt.jimu.base.data.Engine;
|
||||
import com.ubt.jimu.base.data.Servo;
|
||||
import com.ubt.jimu.base.data.ServoMode;
|
||||
import com.ubt.jimu.controller.data.action.ActionSequence;
|
||||
import com.ubt.jimu.controller.data.action.MotorData;
|
||||
import com.ubt.jimu.controller.data.action.TurnData;
|
||||
import com.ubt.jimu.controller.data.command.ActionSequenceTask;
|
||||
import com.ubt.jimu.controller.data.command.MotorCommand;
|
||||
import com.ubt.jimu.controller.data.command.MoveCommand;
|
||||
import com.ubt.jimu.controller.data.command.MoveTask;
|
||||
import com.ubt.jimu.controller.data.command.TurnCommand;
|
||||
import com.ubt.jimu.utils.LogUtils;
|
||||
import com.ubtech.utils.XLog;
|
||||
import com.ubtrobot.jimu.exception.EngineProtectException;
|
||||
import com.ubtrobot.jimu.robotapi.BoardInfo;
|
||||
import com.ubtrobot.jimu.robotapi.JimuException;
|
||||
import com.ubtrobot.jimu.robotapi.JimuManager;
|
||||
import com.ubtrobot.jimu.robotapi.MotorException;
|
||||
import com.ubtrobot.jimu.robotapi.PeripheralType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class CommandManager implements ICommandExecutor {
|
||||
private static CommandManager i;
|
||||
private JimuManager a;
|
||||
private Handler b;
|
||||
private Handler c;
|
||||
private ActionSequenceTask d;
|
||||
private ActionSequenceTask e;
|
||||
private HandlerThread f;
|
||||
private HandlerThread g;
|
||||
private EngineManager h;
|
||||
|
||||
private CommandManager(Context context) {
|
||||
context.getApplicationContext();
|
||||
}
|
||||
|
||||
public static synchronized CommandManager a(Context context) {
|
||||
CommandManager commandManager;
|
||||
synchronized (CommandManager.class) {
|
||||
if (i == null) {
|
||||
i = new CommandManager(context);
|
||||
}
|
||||
commandManager = i;
|
||||
}
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
private void b() {
|
||||
ActionSequenceTask actionSequenceTask = this.e;
|
||||
if (actionSequenceTask != null) {
|
||||
actionSequenceTask.cancel();
|
||||
}
|
||||
ActionSequenceTask actionSequenceTask2 = this.d;
|
||||
if (actionSequenceTask2 != null) {
|
||||
actionSequenceTask2.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
private void d() {
|
||||
Handler handler = this.c;
|
||||
if (handler != null) {
|
||||
handler.removeCallbacksAndMessages("move");
|
||||
}
|
||||
}
|
||||
|
||||
private void e(List<Servo> list) {
|
||||
if (list == null || list.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
HashMap hashMap = new HashMap(list.size());
|
||||
Iterator<Servo> it = list.iterator();
|
||||
while (it.hasNext()) {
|
||||
hashMap.put(Integer.valueOf(it.next().getId()), new TurnData(0, 0));
|
||||
}
|
||||
a((MoveCommand) new TurnCommand(hashMap), true);
|
||||
}
|
||||
|
||||
private boolean f() {
|
||||
BoardInfo boardInfo = Cache.getInstance().getBoardInfo();
|
||||
return boardInfo != null && boardInfo.e() == 113;
|
||||
}
|
||||
|
||||
private void g() {
|
||||
if (this.a == null) {
|
||||
return;
|
||||
}
|
||||
if (this.c == null) {
|
||||
e();
|
||||
}
|
||||
this.c.post(new Runnable() { // from class: com.ubt.jimu.controller.manager.b
|
||||
@Override // java.lang.Runnable
|
||||
public final void run() {
|
||||
CommandManager.this.a();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void c(ActionSequence actionSequence) {
|
||||
ActionSequenceTask actionSequenceTask = this.e;
|
||||
if (actionSequenceTask != null) {
|
||||
if (this.d != actionSequenceTask) {
|
||||
this.d = actionSequenceTask;
|
||||
XLog.a("woo", "setLoop false");
|
||||
this.d.a(false);
|
||||
this.e = null;
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
ActionSequenceTask actionSequenceTask2 = this.d;
|
||||
if (actionSequenceTask2 == null || !actionSequenceTask2.a().equals(actionSequence) || this.d.g()) {
|
||||
return;
|
||||
}
|
||||
XLog.a("woo", "stopAction ");
|
||||
b(actionSequence);
|
||||
this.e = null;
|
||||
}
|
||||
|
||||
private void d(List<Engine> list) {
|
||||
if (list == null || list.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
HashMap hashMap = new HashMap(list.size());
|
||||
Iterator<Engine> it = list.iterator();
|
||||
while (it.hasNext()) {
|
||||
hashMap.put(Integer.valueOf(it.next().getId()), new MotorData(0, 0, 6553500));
|
||||
}
|
||||
a((MoveCommand) new MotorCommand(hashMap), true);
|
||||
}
|
||||
|
||||
public void a(JimuManager jimuManager) {
|
||||
this.a = jimuManager;
|
||||
}
|
||||
|
||||
public void a(ActionSequence actionSequence) {
|
||||
ActionSequenceTask actionSequenceTask = this.d;
|
||||
if (actionSequenceTask == null || !actionSequenceTask.a().equals(actionSequence) || this.d.g()) {
|
||||
b();
|
||||
if (this.b == null) {
|
||||
this.f = new HandlerThread("ActionThread");
|
||||
this.f.start();
|
||||
this.b = new Handler(this.f.getLooper());
|
||||
}
|
||||
LogUtils.c("playAction sequence" + actionSequence.a().get(0).c());
|
||||
ActionSequenceTask actionSequenceTask2 = new ActionSequenceTask(actionSequence, this);
|
||||
actionSequenceTask2.a(true);
|
||||
this.b.removeCallbacksAndMessages(null);
|
||||
this.b.post(actionSequenceTask2);
|
||||
this.e = actionSequenceTask2;
|
||||
}
|
||||
}
|
||||
|
||||
public void b(ActionSequence actionSequence) {
|
||||
if (actionSequence != null) {
|
||||
b();
|
||||
d(actionSequence.f());
|
||||
e(actionSequence.i());
|
||||
}
|
||||
}
|
||||
|
||||
private void e() {
|
||||
this.g = new HandlerThread("MoveThread");
|
||||
this.g.start();
|
||||
this.c = new Handler(this.g.getLooper());
|
||||
}
|
||||
|
||||
public void b(List<Engine> list) {
|
||||
b();
|
||||
c();
|
||||
d();
|
||||
g();
|
||||
d(c(list));
|
||||
}
|
||||
|
||||
private void c() {
|
||||
Handler handler = this.b;
|
||||
if (handler != null) {
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.controller.manager.ICommandExecutor
|
||||
public void b(Map<Integer, TurnData> map) {
|
||||
if (this.a == null) {
|
||||
return;
|
||||
}
|
||||
a(map, ServoMode.SERVO_MODE_TURN);
|
||||
if (map == null || map.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
Collections.sort(new ArrayList(map.entrySet()), new Comparator() { // from class: com.ubt.jimu.controller.manager.c
|
||||
@Override // java.util.Comparator
|
||||
public final int compare(Object obj, Object obj2) {
|
||||
return CommandManager.a((Map.Entry) obj, (Map.Entry) obj2);
|
||||
}
|
||||
});
|
||||
int[] iArr = new int[map.size()];
|
||||
int[] iArr2 = new int[map.size()];
|
||||
int i2 = 0;
|
||||
int i3 = -1;
|
||||
Iterator<Integer> it = map.keySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
int intValue = it.next().intValue();
|
||||
iArr[i2] = intValue;
|
||||
iArr2[i2] = map.get(Integer.valueOf(intValue)).a();
|
||||
if (i2 > 0) {
|
||||
int i4 = i2 - 1;
|
||||
if (iArr2[i2] != iArr2[i4]) {
|
||||
a(iArr, iArr2[i4], i2, i3);
|
||||
i3 = i4;
|
||||
}
|
||||
}
|
||||
i2++;
|
||||
}
|
||||
a(iArr, iArr2[i2 - 1], i2, i3);
|
||||
}
|
||||
|
||||
private List<Engine> c(List<? extends Engine> list) {
|
||||
ArrayList arrayList = new ArrayList();
|
||||
if (list != null && list.size() > 0) {
|
||||
for (Engine engine : list) {
|
||||
if (engine.getMotionType() == CtrlMotionType.motor) {
|
||||
arrayList.add(engine);
|
||||
}
|
||||
}
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
public void a(List<? extends Engine> list) {
|
||||
b();
|
||||
c();
|
||||
d();
|
||||
g();
|
||||
d(c(list));
|
||||
}
|
||||
|
||||
public void a(MoveCommand moveCommand, boolean z) {
|
||||
if (this.c == null) {
|
||||
e();
|
||||
}
|
||||
this.c.removeCallbacksAndMessages("move");
|
||||
this.c.postAtTime(new MoveTask(moveCommand, this), z ? "stop" : "move", SystemClock.uptimeMillis());
|
||||
}
|
||||
|
||||
public /* synthetic */ void a() {
|
||||
try {
|
||||
this.a.i();
|
||||
} catch (JimuException e) {
|
||||
e.printStackTrace();
|
||||
XLog.b("Exception", e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.controller.manager.ICommandExecutor
|
||||
public int a(Map<Integer, Integer> map, int i2, int i3) {
|
||||
if (this.a == null) {
|
||||
return 0;
|
||||
}
|
||||
a(map, ServoMode.SERVO_MODE_ANGLE);
|
||||
if (map != null && map.size() > 0) {
|
||||
int[] iArr = new int[map.size()];
|
||||
float[] fArr = new float[map.size()];
|
||||
Iterator<Integer> it = map.keySet().iterator();
|
||||
int i4 = 0;
|
||||
while (it.hasNext()) {
|
||||
iArr[i4] = it.next().intValue();
|
||||
fArr[i4] = map.get(Integer.valueOf(r5)).intValue();
|
||||
i4++;
|
||||
}
|
||||
XLog.a("woo", "run rotas ids.length: %d, servos.length: %d sportTime: %d, waitTime: %d", Integer.valueOf(iArr.length), Integer.valueOf(fArr.length), Integer.valueOf(i2), Integer.valueOf(i3));
|
||||
try {
|
||||
this.a.a(iArr, fArr, i2, i3);
|
||||
} catch (MotorException e) {
|
||||
e.printStackTrace();
|
||||
XLog.b("Controller", "RequestException: %s", e.toString());
|
||||
if (e.getCode() == -21 && f()) {
|
||||
EventBus.b().b(a(a(iArr, e.getFailIds()), 2, "Servo is protected", PeripheralType.SERVO));
|
||||
}
|
||||
return e.getCode();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private Integer[] a(int[] iArr, ArrayList<Integer> arrayList) {
|
||||
if (arrayList != null && arrayList.size() > 0) {
|
||||
Integer[] numArr = new Integer[arrayList.size()];
|
||||
arrayList.toArray(numArr);
|
||||
return numArr;
|
||||
}
|
||||
Integer[] numArr2 = new Integer[iArr.length];
|
||||
for (int i2 = 0; i2 < iArr.length; i2++) {
|
||||
numArr2[i2] = Integer.valueOf(iArr[i2]);
|
||||
}
|
||||
return numArr2;
|
||||
}
|
||||
|
||||
private EngineProtectException a(Integer[] numArr, int i2, String str, int i3) {
|
||||
HashMap hashMap = new HashMap(1);
|
||||
ArrayList arrayList = new ArrayList(numArr.length);
|
||||
arrayList.addAll(Arrays.asList(numArr));
|
||||
hashMap.put(32, arrayList);
|
||||
return new EngineProtectException(i2, str, i3, hashMap);
|
||||
}
|
||||
|
||||
private void a(Map<Integer, ?> map, ServoMode servoMode) {
|
||||
if (this.h == null || map == null || map.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
Integer[] numArr = new Integer[map.size()];
|
||||
map.keySet().toArray(numArr);
|
||||
for (Integer num : numArr) {
|
||||
int intValue = num.intValue();
|
||||
if (this.h.getServoMode(intValue) != servoMode) {
|
||||
map.remove(Integer.valueOf(intValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static /* synthetic */ int a(Map.Entry entry, Map.Entry entry2) {
|
||||
if (entry.getValue() == null && entry2.getValue() == null) {
|
||||
return 0;
|
||||
}
|
||||
if (entry.getValue() == null) {
|
||||
return -1;
|
||||
}
|
||||
if (entry2.getValue() == null) {
|
||||
return 1;
|
||||
}
|
||||
return Integer.compare(((TurnData) entry.getValue()).a(), ((TurnData) entry2.getValue()).a());
|
||||
}
|
||||
|
||||
private void a(int[] iArr, int i2, int i3, int i4) {
|
||||
int i5 = (i3 - 1) - i4;
|
||||
int[] iArr2 = new int[i5];
|
||||
System.arraycopy(iArr, i4 + 1, iArr2, 0, i5);
|
||||
XLog.a("woo", "runTurns ids.length: %s, speed: %d ", Integer.valueOf(iArr2.length), Integer.valueOf(i2));
|
||||
try {
|
||||
this.a.a(iArr2, i2);
|
||||
} catch (MotorException e) {
|
||||
e.printStackTrace();
|
||||
XLog.b("Controller", "RequestException: %s", e.toString());
|
||||
if (e.getCode() == -21 && f()) {
|
||||
EventBus.b().b(a(a(iArr, e.getFailIds()), 2, "Servo is protected", PeripheralType.SERVO));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.controller.manager.ICommandExecutor
|
||||
public void a(Map<Integer, MotorData> map) {
|
||||
if (this.a == null || map == null || map.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
int[] iArr = new int[map.size()];
|
||||
int[] iArr2 = new int[map.size()];
|
||||
int[] iArr3 = new int[map.size()];
|
||||
Iterator<Integer> it = map.keySet().iterator();
|
||||
int i2 = 0;
|
||||
while (it.hasNext()) {
|
||||
int intValue = it.next().intValue();
|
||||
iArr[i2] = intValue;
|
||||
MotorData motorData = map.get(Integer.valueOf(intValue));
|
||||
iArr2[i2] = motorData.a();
|
||||
iArr3[i2] = motorData.f();
|
||||
i2++;
|
||||
}
|
||||
XLog.a("woo", "runMotors ids: %s, speeds: %s, durations: %s", Arrays.toString(iArr), Arrays.toString(iArr2), Arrays.toString(iArr3));
|
||||
try {
|
||||
this.a.a(iArr, iArr2, iArr3);
|
||||
} catch (MotorException e) {
|
||||
e.printStackTrace();
|
||||
XLog.b("Controller", "RequestException: %s", e.toString());
|
||||
if (e.getCode() == -21 && f()) {
|
||||
EventBus.b().b(a(a(iArr, e.getFailIds()), 4, "Motor is protected", 10));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void a(EngineManager engineManager) {
|
||||
this.h = engineManager;
|
||||
}
|
||||
}
|
144
sources/com/ubt/jimu/controller/manager/CommandSendManager.java
Normal file
144
sources/com/ubt/jimu/controller/manager/CommandSendManager.java
Normal file
@@ -0,0 +1,144 @@
|
||||
package com.ubt.jimu.controller.manager;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import com.ubt.jimu.controller.data.widget.HSliderWidgetData;
|
||||
import com.ubt.jimu.controller.data.widget.ItemBaseData;
|
||||
import com.ubt.jimu.controller.data.widget.SliderWidgetData;
|
||||
import com.ubt.jimu.controller.manager.CommandSendManager;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class CommandSendManager<T extends ItemBaseData> {
|
||||
private float a;
|
||||
private T b;
|
||||
private Timer c;
|
||||
private CommandSendManager<T>.CommandTimerTask d;
|
||||
private boolean e;
|
||||
private int f = 100;
|
||||
private Handler g;
|
||||
private HSliderViewCommandSendListener h;
|
||||
private VSliderViewCommandSendListener i;
|
||||
|
||||
class CommandTimerTask extends TimerTask {
|
||||
CommandTimerTask() {
|
||||
}
|
||||
|
||||
public /* synthetic */ void a() {
|
||||
CommandSendManager.this.h.b(CommandSendManager.this.a, CommandSendManager.this.b);
|
||||
}
|
||||
|
||||
public /* synthetic */ void b() {
|
||||
CommandSendManager.this.i.a(CommandSendManager.this.a, CommandSendManager.this.b);
|
||||
}
|
||||
|
||||
@Override // java.util.TimerTask, java.lang.Runnable
|
||||
public void run() {
|
||||
if (CommandSendManager.this.b == null) {
|
||||
return;
|
||||
}
|
||||
if ((CommandSendManager.this.b instanceof HSliderWidgetData) && CommandSendManager.this.h != null) {
|
||||
CommandSendManager.this.g.post(new Runnable() { // from class: com.ubt.jimu.controller.manager.d
|
||||
@Override // java.lang.Runnable
|
||||
public final void run() {
|
||||
CommandSendManager.CommandTimerTask.this.a();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (!(CommandSendManager.this.b instanceof SliderWidgetData) || CommandSendManager.this.i == null) {
|
||||
return;
|
||||
}
|
||||
CommandSendManager.this.g.post(new Runnable() { // from class: com.ubt.jimu.controller.manager.e
|
||||
@Override // java.lang.Runnable
|
||||
public final void run() {
|
||||
CommandSendManager.CommandTimerTask.this.b();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface HSliderViewCommandSendListener<T> {
|
||||
void a(T t);
|
||||
|
||||
void b(float f, T t);
|
||||
}
|
||||
|
||||
public interface VSliderViewCommandSendListener<T> {
|
||||
void a(float f, T t);
|
||||
|
||||
void c(float f, T t);
|
||||
}
|
||||
|
||||
public CommandSendManager() {
|
||||
c();
|
||||
this.g = new Handler(Looper.getMainLooper());
|
||||
}
|
||||
|
||||
private void c() {
|
||||
this.c = new Timer();
|
||||
this.d = new CommandTimerTask();
|
||||
}
|
||||
|
||||
public void a(float f) {
|
||||
this.a = f;
|
||||
}
|
||||
|
||||
public void b() {
|
||||
VSliderViewCommandSendListener vSliderViewCommandSendListener;
|
||||
HSliderViewCommandSendListener hSliderViewCommandSendListener;
|
||||
if (this.e) {
|
||||
Timer timer = this.c;
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
}
|
||||
CommandSendManager<T>.CommandTimerTask commandTimerTask = this.d;
|
||||
if (commandTimerTask != null) {
|
||||
commandTimerTask.cancel();
|
||||
}
|
||||
this.c = null;
|
||||
this.d = null;
|
||||
this.e = false;
|
||||
T t = this.b;
|
||||
if (t == null) {
|
||||
return;
|
||||
}
|
||||
if ((t instanceof HSliderWidgetData) && (hSliderViewCommandSendListener = this.h) != null) {
|
||||
hSliderViewCommandSendListener.a(t);
|
||||
return;
|
||||
}
|
||||
T t2 = this.b;
|
||||
if (!(t2 instanceof SliderWidgetData) || (vSliderViewCommandSendListener = this.i) == null) {
|
||||
return;
|
||||
}
|
||||
vSliderViewCommandSendListener.c(this.a, t2);
|
||||
}
|
||||
}
|
||||
|
||||
public void a(T t) {
|
||||
this.b = t;
|
||||
}
|
||||
|
||||
public void a() {
|
||||
if (this.e) {
|
||||
return;
|
||||
}
|
||||
if (this.c == null) {
|
||||
this.c = new Timer();
|
||||
}
|
||||
if (this.d == null) {
|
||||
this.d = new CommandTimerTask();
|
||||
}
|
||||
this.c.schedule(this.d, 0L, this.f);
|
||||
this.e = true;
|
||||
}
|
||||
|
||||
public void a(HSliderViewCommandSendListener hSliderViewCommandSendListener) {
|
||||
this.h = hSliderViewCommandSendListener;
|
||||
}
|
||||
|
||||
public void a(VSliderViewCommandSendListener vSliderViewCommandSendListener) {
|
||||
this.i = vSliderViewCommandSendListener;
|
||||
}
|
||||
}
|
203
sources/com/ubt/jimu/controller/manager/ControllerManager.java
Normal file
203
sources/com/ubt/jimu/controller/manager/ControllerManager.java
Normal file
@@ -0,0 +1,203 @@
|
||||
package com.ubt.jimu.controller.manager;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Size;
|
||||
import com.ubt.jimu.base.db.diy.DiyDBModel;
|
||||
import com.ubt.jimu.base.db.diy.DiyHelper;
|
||||
import com.ubt.jimu.base.db.robot.RobotDbHandler;
|
||||
import com.ubt.jimu.base.entities.Robot;
|
||||
import com.ubt.jimu.base.entities.RobotLite;
|
||||
import com.ubt.jimu.base.util.FileUtil;
|
||||
import com.ubt.jimu.base.util.PathHelper;
|
||||
import com.ubt.jimu.controller.data.action.ActionSequence;
|
||||
import com.ubt.jimu.controller.data.config.WidgetConfig;
|
||||
import com.ubt.jimu.controller.data.widget.ActionWidgetData;
|
||||
import com.ubt.jimu.controller.data.widget.ControllerData;
|
||||
import com.ubt.jimu.controller.data.widget.MoveBaseData;
|
||||
import com.ubt.jimu.controller.data.widget.MoveWidgetData;
|
||||
import com.ubt.jimu.controller.util.ScreenUtil;
|
||||
import com.ubt.jimu.controller.util.XmlUtils;
|
||||
import com.ubt.jimu.transport3.UnityFileOperator;
|
||||
import com.ubtech.utils.XLog;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class ControllerManager {
|
||||
private static ControllerManager d;
|
||||
private Context a;
|
||||
private ControllerData b;
|
||||
private RobotLite c;
|
||||
|
||||
private ControllerManager(Context context) {
|
||||
this.a = context.getApplicationContext();
|
||||
}
|
||||
|
||||
public static synchronized ControllerManager a(Context context) {
|
||||
ControllerManager controllerManager;
|
||||
synchronized (ControllerManager.class) {
|
||||
if (d == null) {
|
||||
d = new ControllerManager(context);
|
||||
}
|
||||
controllerManager = d;
|
||||
}
|
||||
return controllerManager;
|
||||
}
|
||||
|
||||
private void b(ControllerData controllerData) {
|
||||
a(controllerData.getJockstickData());
|
||||
a(controllerData.getSliderData());
|
||||
a(controllerData.getHsliderData());
|
||||
a(controllerData.getAccumulatorData());
|
||||
}
|
||||
|
||||
private void c(ControllerData controllerData) {
|
||||
MoveWidgetData moveConfig = controllerData.getMoveConfig();
|
||||
if (moveConfig == null) {
|
||||
return;
|
||||
}
|
||||
List<WidgetConfig> configList = moveConfig.getConfigList();
|
||||
if (configList != null && configList.size() > 0) {
|
||||
Iterator<WidgetConfig> it = configList.iterator();
|
||||
while (it.hasNext()) {
|
||||
it.next().setConfigType(this.c.isOfficial() ? 1 : 2);
|
||||
}
|
||||
}
|
||||
XLog.a("woo", "MoveWidgetData: %s", moveConfig.toString());
|
||||
MoveConfigManager a = MoveConfigManager.a(this.a);
|
||||
if (a.a(controllerData)) {
|
||||
a(controllerData, true);
|
||||
a.a(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void a(RobotLite robotLite) {
|
||||
this.c = robotLite;
|
||||
ActionManager.a(this.a).a(robotLite);
|
||||
MoveConfigManager.a(this.a).a(robotLite);
|
||||
}
|
||||
|
||||
public ControllerData a() {
|
||||
String controllerDir = PathHelper.getControllerDir(this.a, this.c, true);
|
||||
String controllerPath = PathHelper.getControllerPath(controllerDir);
|
||||
if (TextUtils.isEmpty(controllerPath) && this.c.isOfficial()) {
|
||||
controllerPath = a(controllerDir, controllerPath);
|
||||
}
|
||||
if (TextUtils.isEmpty(controllerPath)) {
|
||||
return null;
|
||||
}
|
||||
this.b = (ControllerData) XmlUtils.a(ControllerData.class, controllerPath);
|
||||
ControllerData controllerData = this.b;
|
||||
if (controllerData == null) {
|
||||
return null;
|
||||
}
|
||||
b(controllerData);
|
||||
boolean clearEmptyWidget = this.b.clearEmptyWidget();
|
||||
boolean a = a(this.b);
|
||||
if (clearEmptyWidget || a) {
|
||||
a(this.b, false);
|
||||
}
|
||||
this.b.transform(ScreenUtil.c(this.a), new Size(this.b.getScreenWidth(), this.b.getScreenHeight()));
|
||||
c(this.b);
|
||||
return this.b;
|
||||
}
|
||||
|
||||
private String a(String str, String str2) {
|
||||
XLog.c("woo", "copy official controller file to user/default");
|
||||
String controllerPath = PathHelper.getControllerPath(PathHelper.getControllerDir(this.a, this.c, false));
|
||||
if (TextUtils.isEmpty(controllerPath)) {
|
||||
return str2;
|
||||
}
|
||||
File file = new File(controllerPath);
|
||||
if (!file.exists() || !file.isFile()) {
|
||||
return str2;
|
||||
}
|
||||
File file2 = new File(str, file.getName());
|
||||
File parentFile = file2.getParentFile();
|
||||
if (!parentFile.exists()) {
|
||||
parentFile.mkdirs();
|
||||
}
|
||||
FileUtil.copy(file, file2);
|
||||
return file2.getPath();
|
||||
}
|
||||
|
||||
private void a(List<? extends MoveBaseData> list) {
|
||||
WidgetConfig a;
|
||||
if (list == null || list.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
for (MoveBaseData moveBaseData : list) {
|
||||
if (!TextUtils.isEmpty(moveBaseData.getConfigID()) && (a = MoveConfigManager.a(this.a).a(moveBaseData.getConfigID())) != null) {
|
||||
moveBaseData.setConfig(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean a(ControllerData controllerData) {
|
||||
boolean z = false;
|
||||
if (controllerData != null && controllerData.hasAction()) {
|
||||
ArrayList<ActionWidgetData> arrayList = new ArrayList(controllerData.getActionData().size());
|
||||
arrayList.addAll(controllerData.getActionData());
|
||||
for (ActionWidgetData actionWidgetData : arrayList) {
|
||||
String actionID = actionWidgetData.getActionID();
|
||||
if (TextUtils.isEmpty(actionID)) {
|
||||
controllerData.removeActionData(actionWidgetData);
|
||||
} else {
|
||||
ActionSequence a = ActionManager.a(this.a).a(actionID);
|
||||
if (a == null) {
|
||||
controllerData.removeActionData(actionWidgetData);
|
||||
} else {
|
||||
actionWidgetData.setActionSequence(a);
|
||||
}
|
||||
}
|
||||
z = true;
|
||||
}
|
||||
}
|
||||
return z;
|
||||
}
|
||||
|
||||
public void a(ControllerData controllerData, boolean z) {
|
||||
String str;
|
||||
int i;
|
||||
if (controllerData == null || this.c == null) {
|
||||
return;
|
||||
}
|
||||
controllerData.transform(ScreenUtil.c(this.a), new Size(controllerData.getScreenWidth(), controllerData.getScreenHeight()));
|
||||
String controllerDir = PathHelper.getControllerDir(this.a, this.c, true);
|
||||
if (TextUtils.isEmpty(controllerDir)) {
|
||||
return;
|
||||
}
|
||||
String controllerPath = PathHelper.getControllerPath(controllerDir);
|
||||
if (TextUtils.isEmpty(controllerPath)) {
|
||||
File file = new File(controllerDir);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
str = controllerDir + PathHelper.newControllerFileName(this.c.getModelId());
|
||||
i = 1;
|
||||
} else {
|
||||
str = controllerPath;
|
||||
i = 2;
|
||||
}
|
||||
XLog.a("woo", "save : %s", controllerData.toString());
|
||||
XmlUtils.a(controllerData, str);
|
||||
if (z) {
|
||||
if (!this.c.isOfficial()) {
|
||||
DiyDBModel queryForUUid = DiyHelper.getInstance().queryForUUid(this.c.getModelId());
|
||||
if (queryForUUid != null) {
|
||||
new UnityFileOperator(queryForUUid.getModelId().intValue(), queryForUUid.getCustomModelId(), 1, str, i).operateFile();
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
Robot robotByModelName = RobotDbHandler.getRobotByModelName(this.c.getModelId());
|
||||
if (robotByModelName == null || robotByModelName.getModelId() <= 0) {
|
||||
return;
|
||||
}
|
||||
new UnityFileOperator((int) robotByModelName.getModelId(), this.c.getModelId(), 0, str, i).officialModelFileOperator();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package com.ubt.jimu.controller.manager;
|
||||
|
||||
import com.ubt.jimu.controller.data.action.MotorData;
|
||||
import com.ubt.jimu.controller.data.action.TurnData;
|
||||
import java.util.Map;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public interface ICommandExecutor {
|
||||
int a(Map<Integer, Integer> map, int i, int i2);
|
||||
|
||||
void a(Map<Integer, MotorData> map);
|
||||
|
||||
void b(Map<Integer, TurnData> map);
|
||||
}
|
173
sources/com/ubt/jimu/controller/manager/KeyMapManager.java
Normal file
173
sources/com/ubt/jimu/controller/manager/KeyMapManager.java
Normal file
@@ -0,0 +1,173 @@
|
||||
package com.ubt.jimu.controller.manager;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.ubt.jimu.base.entities.RobotLite;
|
||||
import com.ubt.jimu.base.util.PathHelper;
|
||||
import com.ubt.jimu.controller.data.keymap.KeyMap;
|
||||
import com.ubt.jimu.controller.data.keymap.entity.GameControllerConfigData;
|
||||
import com.ubt.jimu.controller.data.keymap.entity.Key;
|
||||
import com.ubt.jimu.controller.data.keymap.entity.KeyMapData;
|
||||
import com.ubt.jimu.controller.util.XmlUtils;
|
||||
import com.ubtrobot.log.ALog;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class KeyMapManager {
|
||||
private Context a;
|
||||
private RobotLite b;
|
||||
private GameControllerConfigData c = new GameControllerConfigData();
|
||||
private List<KeyMap> d = new ArrayList();
|
||||
private List<KeyMap> e = new ArrayList();
|
||||
|
||||
public KeyMapManager(Context context) {
|
||||
this.a = context.getApplicationContext();
|
||||
}
|
||||
|
||||
private synchronized void e() {
|
||||
this.d.clear();
|
||||
this.e.clear();
|
||||
}
|
||||
|
||||
public void a(RobotLite robotLite) {
|
||||
this.b = robotLite;
|
||||
}
|
||||
|
||||
public synchronized List<KeyMap> b() {
|
||||
return this.e;
|
||||
}
|
||||
|
||||
public synchronized void c() {
|
||||
String gameControllerKeyMapFilePath = PathHelper.getGameControllerKeyMapFilePath(this.a, this.b);
|
||||
if (!TextUtils.isEmpty(gameControllerKeyMapFilePath)) {
|
||||
Object a = XmlUtils.a(GameControllerConfigData.class, gameControllerKeyMapFilePath);
|
||||
if (a != null) {
|
||||
this.c = (GameControllerConfigData) a;
|
||||
if (this.c != null && this.c.a() != null) {
|
||||
List<KeyMapData> a2 = this.c.a();
|
||||
if (a2 != null && !a2.isEmpty()) {
|
||||
KeyMapData keyMapData = a2.get(0);
|
||||
this.d = keyMapData.a();
|
||||
this.e = keyMapData.b();
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
Log.w("KeyMapManagerDemo", "keymap.xml not exit!");
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void d() {
|
||||
ALog.a("KeyMapManagerDemo").d("save");
|
||||
if (this.c == null) {
|
||||
return;
|
||||
}
|
||||
KeyMapData keyMapData = new KeyMapData();
|
||||
keyMapData.a(this.d);
|
||||
keyMapData.b(this.e);
|
||||
ArrayList arrayList = new ArrayList();
|
||||
arrayList.add(keyMapData);
|
||||
this.c.a(arrayList);
|
||||
String gameControllerKeyMapFilePath = PathHelper.getGameControllerKeyMapFilePath(this.a, this.b);
|
||||
File parentFile = new File(gameControllerKeyMapFilePath).getParentFile();
|
||||
if (!parentFile.exists()) {
|
||||
parentFile.mkdirs();
|
||||
}
|
||||
XmlUtils.a(this.c, gameControllerKeyMapFilePath);
|
||||
for (KeyMap keyMap : this.e) {
|
||||
ALog.a("KeyMapManagerDemo").d("saved Joystick keymap:" + keyMap);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void b(KeyMap keyMap) {
|
||||
ALog.a("KeyMapManagerDemo").d("Add keymap -- " + keyMap);
|
||||
if (keyMap == null) {
|
||||
return;
|
||||
}
|
||||
if (keyMap.c() == 1) {
|
||||
this.d.add(keyMap);
|
||||
} else if (keyMap.c() == 2) {
|
||||
this.e.add(keyMap);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized List<KeyMap> a() {
|
||||
return this.d;
|
||||
}
|
||||
|
||||
public synchronized void a(KeyMap keyMap) {
|
||||
ALog.a("KeyMapManagerDemo").d("delete keyMap:" + keyMap);
|
||||
if (keyMap == null) {
|
||||
return;
|
||||
}
|
||||
if (keyMap.c() == 2) {
|
||||
this.e.remove(keyMap);
|
||||
} else if (keyMap.c() == 1) {
|
||||
this.d.remove(keyMap);
|
||||
}
|
||||
d();
|
||||
}
|
||||
|
||||
public synchronized KeyMap b(String str) {
|
||||
if (this.d != null) {
|
||||
for (KeyMap keyMap : this.d) {
|
||||
if (str.equals(keyMap.a())) {
|
||||
return keyMap;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.e != null) {
|
||||
for (KeyMap keyMap2 : this.e) {
|
||||
if (str.equals(keyMap2.a())) {
|
||||
return keyMap2;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void a(List<KeyMap> list) {
|
||||
Iterator<KeyMap> it = list.iterator();
|
||||
while (it.hasNext()) {
|
||||
b(it.next());
|
||||
}
|
||||
}
|
||||
|
||||
public void a(String str) {
|
||||
ALog.a("KeyMapManagerDemo").d("delete action:" + str);
|
||||
KeyMap b = b(str);
|
||||
if (b != null) {
|
||||
a(b);
|
||||
d();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized String a(Key key) {
|
||||
List<KeyMap> list;
|
||||
if (key.b() == 2) {
|
||||
list = this.e;
|
||||
} else {
|
||||
list = key.b() == 1 ? this.d : null;
|
||||
}
|
||||
if (list == null) {
|
||||
return null;
|
||||
}
|
||||
for (KeyMap keyMap : list) {
|
||||
if (key.a().equals(keyMap.b())) {
|
||||
return keyMap.a();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void b(List<KeyMap> list) {
|
||||
e();
|
||||
a(list);
|
||||
d();
|
||||
}
|
||||
}
|
260
sources/com/ubt/jimu/controller/manager/MoveConfigManager.java
Normal file
260
sources/com/ubt/jimu/controller/manager/MoveConfigManager.java
Normal file
@@ -0,0 +1,260 @@
|
||||
package com.ubt.jimu.controller.manager;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import com.ubt.jimu.base.cache.Cache;
|
||||
import com.ubt.jimu.base.db.diy.DiyDBModel;
|
||||
import com.ubt.jimu.base.db.diy.DiyHelper;
|
||||
import com.ubt.jimu.base.db.robot.RobotDbHandler;
|
||||
import com.ubt.jimu.base.entities.Robot;
|
||||
import com.ubt.jimu.base.entities.RobotLite;
|
||||
import com.ubt.jimu.base.util.FileUtil;
|
||||
import com.ubt.jimu.base.util.PathHelper;
|
||||
import com.ubt.jimu.controller.data.config.AccumulatorConfig;
|
||||
import com.ubt.jimu.controller.data.config.HSliderConfig;
|
||||
import com.ubt.jimu.controller.data.config.JockstickConfig;
|
||||
import com.ubt.jimu.controller.data.config.SliderConfig;
|
||||
import com.ubt.jimu.controller.data.config.WidgetConfig;
|
||||
import com.ubt.jimu.controller.data.widget.ControllerData;
|
||||
import com.ubt.jimu.controller.data.widget.MoveBaseData;
|
||||
import com.ubt.jimu.controller.data.widget.MoveWidgetData;
|
||||
import com.ubt.jimu.controller.util.XmlUtils;
|
||||
import com.ubt.jimu.transport.model.TransportFile;
|
||||
import com.ubt.jimu.transport3.UnityFileOperator;
|
||||
import com.ubt.jimu.transport3.dao.TransportFileDbHandler2;
|
||||
import com.ubt.jimu.utils.SystemUtils;
|
||||
import com.ubtech.utils.XLog;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class MoveConfigManager {
|
||||
private static MoveConfigManager d;
|
||||
private MoveWidgetData a;
|
||||
private RobotLite b;
|
||||
private Context c;
|
||||
|
||||
private MoveConfigManager(Context context) {
|
||||
this.c = context.getApplicationContext();
|
||||
}
|
||||
|
||||
public static synchronized MoveConfigManager a(Context context) {
|
||||
MoveConfigManager moveConfigManager;
|
||||
synchronized (MoveConfigManager.class) {
|
||||
if (d == null) {
|
||||
d = new MoveConfigManager(context);
|
||||
}
|
||||
moveConfigManager = d;
|
||||
}
|
||||
return moveConfigManager;
|
||||
}
|
||||
|
||||
public boolean b(SliderConfig sliderConfig) {
|
||||
MoveWidgetData moveWidgetData = this.a;
|
||||
return moveWidgetData == null || moveWidgetData.removeSliderconfig(sliderConfig);
|
||||
}
|
||||
|
||||
public List<HSliderConfig> c() {
|
||||
MoveWidgetData moveWidgetData = this.a;
|
||||
if (moveWidgetData != null) {
|
||||
return moveWidgetData.getHSliderConfigList();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<JockstickConfig> d() {
|
||||
MoveWidgetData moveWidgetData = this.a;
|
||||
if (moveWidgetData != null) {
|
||||
return moveWidgetData.getJockstickConfigList();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<MoveBaseData> e() {
|
||||
List<WidgetConfig> b = b();
|
||||
if (b == null || b.size() <= 0) {
|
||||
return null;
|
||||
}
|
||||
ArrayList arrayList = new ArrayList(b.size());
|
||||
Iterator<WidgetConfig> it = b.iterator();
|
||||
while (it.hasNext()) {
|
||||
arrayList.add(it.next().encapData());
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
public List<SliderConfig> f() {
|
||||
MoveWidgetData moveWidgetData = this.a;
|
||||
if (moveWidgetData != null) {
|
||||
return moveWidgetData.getSliderConfigList();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void g() {
|
||||
Object a;
|
||||
String moveConfigPath = PathHelper.getMoveConfigPath(this.c, this.b, true);
|
||||
File file = new File(moveConfigPath);
|
||||
if (this.b.isOfficial() && !file.exists()) {
|
||||
String moveConfigPath2 = PathHelper.getMoveConfigPath(this.c, this.b, false);
|
||||
if (!TextUtils.isEmpty(moveConfigPath2)) {
|
||||
File file2 = new File(moveConfigPath2);
|
||||
if (file2.exists() && file2.isFile()) {
|
||||
File parentFile = file.getParentFile();
|
||||
if (!parentFile.exists()) {
|
||||
parentFile.mkdirs();
|
||||
}
|
||||
FileUtil.copy(file2, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (TextUtils.isEmpty(moveConfigPath) || (a = XmlUtils.a(MoveWidgetData.class, moveConfigPath)) == null) {
|
||||
return;
|
||||
}
|
||||
this.a = (MoveWidgetData) a;
|
||||
}
|
||||
|
||||
public boolean b(HSliderConfig hSliderConfig) {
|
||||
MoveWidgetData moveWidgetData = this.a;
|
||||
return moveWidgetData == null || moveWidgetData.removeHSliderconfig(hSliderConfig);
|
||||
}
|
||||
|
||||
public boolean b(JockstickConfig jockstickConfig) {
|
||||
MoveWidgetData moveWidgetData = this.a;
|
||||
return moveWidgetData == null || moveWidgetData.removeJockstickConfig(jockstickConfig);
|
||||
}
|
||||
|
||||
public void a(RobotLite robotLite) {
|
||||
this.b = robotLite;
|
||||
this.a = null;
|
||||
g();
|
||||
}
|
||||
|
||||
public boolean b(AccumulatorConfig accumulatorConfig) {
|
||||
MoveWidgetData moveWidgetData = this.a;
|
||||
return moveWidgetData == null || moveWidgetData.removeAccumulatorConfig(accumulatorConfig);
|
||||
}
|
||||
|
||||
public List<WidgetConfig> b() {
|
||||
MoveWidgetData moveWidgetData = this.a;
|
||||
if (moveWidgetData != null) {
|
||||
return moveWidgetData.getConfigList();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean a(ControllerData controllerData) {
|
||||
if (controllerData == null) {
|
||||
return false;
|
||||
}
|
||||
MoveWidgetData moveWidgetData = this.a;
|
||||
if (moveWidgetData == null) {
|
||||
this.a = controllerData.getMoveConfig();
|
||||
return true;
|
||||
}
|
||||
return moveWidgetData.merge(controllerData);
|
||||
}
|
||||
|
||||
public void a(SliderConfig sliderConfig) {
|
||||
if (sliderConfig != null) {
|
||||
if (this.a == null) {
|
||||
this.a = new MoveWidgetData();
|
||||
}
|
||||
this.a.addSliderConfig(sliderConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public void a(HSliderConfig hSliderConfig) {
|
||||
if (hSliderConfig != null) {
|
||||
if (this.a == null) {
|
||||
this.a = new MoveWidgetData();
|
||||
}
|
||||
this.a.addHSliderConfig(hSliderConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public void a(JockstickConfig jockstickConfig) {
|
||||
if (jockstickConfig != null) {
|
||||
if (this.a == null) {
|
||||
this.a = new MoveWidgetData();
|
||||
}
|
||||
this.a.addJockstickConfig(jockstickConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public void a(AccumulatorConfig accumulatorConfig) {
|
||||
if (accumulatorConfig != null) {
|
||||
if (this.a == null) {
|
||||
this.a = new MoveWidgetData();
|
||||
}
|
||||
this.a.addAccumulatorConfig(accumulatorConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public void a(boolean z) {
|
||||
RobotLite robotLite;
|
||||
TransportFile transportModelFile;
|
||||
if (this.a == null || (robotLite = this.b) == null) {
|
||||
return;
|
||||
}
|
||||
String moveConfigPath = PathHelper.getMoveConfigPath(this.c, robotLite, true);
|
||||
File file = new File(moveConfigPath);
|
||||
int i = file.exists() ? 2 : 1;
|
||||
File parentFile = file.getParentFile();
|
||||
if (!parentFile.exists()) {
|
||||
parentFile.mkdirs();
|
||||
}
|
||||
XLog.c("woo", "save moveConfig to xml : %s", this.a.toString());
|
||||
XmlUtils.a(this.a, moveConfigPath);
|
||||
if (z) {
|
||||
if (!this.b.isOfficial()) {
|
||||
DiyDBModel queryForUUid = DiyHelper.getInstance().queryForUUid(this.b.getModelId());
|
||||
if (queryForUUid != null) {
|
||||
new UnityFileOperator(queryForUUid.getModelId().intValue(), queryForUUid.getCustomModelId(), 1, moveConfigPath, i).operateFile();
|
||||
String str = PathHelper.getControllerDir(this.c, this.b, true) + PathHelper.newControllerFileName(this.b.getModelId());
|
||||
if (!new File(str).exists() || (transportModelFile = TransportFileDbHandler2.getInstance().getTransportModelFile(Cache.getInstance().getUserId(), queryForUUid.getCustomModelId(), new File(str))) == null) {
|
||||
return;
|
||||
}
|
||||
long a = SystemUtils.a();
|
||||
transportModelFile.setModifyTime(a);
|
||||
transportModelFile.setLastUploadTime(a);
|
||||
transportModelFile.setUploaded(false);
|
||||
transportModelFile.setIsModify(true);
|
||||
TransportFileDbHandler2.getInstance().update(transportModelFile);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
String modelId = this.b.getModelId();
|
||||
Cache.getInstance().getUserId();
|
||||
Robot robotByModelName = RobotDbHandler.getRobotByModelName(modelId);
|
||||
long modelId2 = robotByModelName.getModelId();
|
||||
if (robotByModelName == null || modelId2 <= 0) {
|
||||
return;
|
||||
}
|
||||
new UnityFileOperator((int) modelId2, modelId, 1, moveConfigPath, i).officialModelFileOperator();
|
||||
}
|
||||
}
|
||||
|
||||
public List<AccumulatorConfig> a() {
|
||||
MoveWidgetData moveWidgetData = this.a;
|
||||
if (moveWidgetData != null) {
|
||||
return moveWidgetData.getAccumulatorConfigList();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public WidgetConfig a(String str) {
|
||||
List<WidgetConfig> b;
|
||||
if (!TextUtils.isEmpty(str) && (b = b()) != null && b.size() != 0) {
|
||||
for (WidgetConfig widgetConfig : b) {
|
||||
if (str.equals(widgetConfig.getConfigID())) {
|
||||
return widgetConfig;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user