Initial commit
This commit is contained in:
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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user