jimu-decompiled/sources/com/ubt/jimu/controller/data/command/ActionSequenceTask.java
2025-05-13 19:24:51 +02:00

150 lines
4.9 KiB
Java

package com.ubt.jimu.controller.data.command;
import android.media.MediaPlayer;
import android.os.SystemClock;
import android.text.TextUtils;
import com.ubt.jimu.base.data.CtrlMotionType;
import com.ubt.jimu.controller.data.action.Action;
import com.ubt.jimu.controller.data.action.ActionSequence;
import com.ubt.jimu.controller.data.action.MotorData;
import com.ubt.jimu.controller.data.action.RunningData;
import com.ubt.jimu.controller.data.action.RunningItem;
import com.ubt.jimu.controller.data.action.TurnData;
import com.ubt.jimu.controller.manager.ICommandExecutor;
import com.ubtech.utils.XLog;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
/* loaded from: classes.dex */
public class ActionSequenceTask implements Runnable {
private ActionSequence a;
private ICommandExecutor b;
private MediaPlayer c;
private volatile boolean e = false;
private volatile boolean f = false;
private volatile boolean g = true;
private RunningData d = new RunningData();
public ActionSequenceTask(ActionSequence actionSequence, ICommandExecutor iCommandExecutor) {
this.a = actionSequence;
this.b = iCommandExecutor;
}
private void a(Map<Integer, ? extends TurnData> map) {
if (map == null || map.size() <= 0) {
return;
}
long elapsedRealtime = SystemClock.elapsedRealtime();
Iterator<Integer> it = map.keySet().iterator();
while (it.hasNext()) {
int intValue = it.next().intValue();
TurnData turnData = map.get(Integer.valueOf(intValue));
CtrlMotionType ctrlMotionType = CtrlMotionType.servo;
long j = Long.MAX_VALUE;
if (turnData instanceof MotorData) {
ctrlMotionType = CtrlMotionType.motor;
j = ((MotorData) turnData).f();
}
if (turnData.d()) {
this.d.b(new RunningItem(intValue, ctrlMotionType, j, elapsedRealtime));
} else {
this.d.a(new RunningItem(intValue, ctrlMotionType, j, elapsedRealtime));
}
}
}
private synchronized void b() {
if (this.c != null) {
this.c.stop();
this.c.release();
this.c = null;
}
}
public void cancel() {
this.g = false;
this.f = true;
b();
this.d.a();
}
public boolean g() {
boolean a = this.d.a(SystemClock.elapsedRealtime());
XLog.a("Controller", "mIsComplete:%b, mIsCancel:%b, runningData.isAllComplete:%b ", Boolean.valueOf(this.e), Boolean.valueOf(this.f), Boolean.valueOf(a));
return this.f || (this.e && a);
}
@Override // java.lang.Runnable
public void run() {
while (!this.f) {
if (!TextUtils.isEmpty(this.a.g())) {
a(this.a.g());
}
List<Action> a = this.a.a();
if (a != null && a.size() > 0) {
Iterator<Action> it = a.iterator();
while (true) {
if (!it.hasNext()) {
break;
}
Action next = it.next();
if (!this.f) {
Map<Integer, MotorData> b = next.b();
if (b != null && b.size() > 0) {
a(b);
this.b.a(new TreeMap(b));
}
Map<Integer, TurnData> e = next.e();
if (e != null && e.size() > 0) {
a(e);
this.b.b(new TreeMap(e));
}
Map<Integer, Integer> c = next.c();
if (c != null && c.size() > 0 && this.b.a(new TreeMap(c), next.d(), next.f()) == -1) {
this.f = true;
this.g = false;
break;
} else {
try {
Thread.sleep(next.a());
} catch (InterruptedException e2) {
e2.printStackTrace();
this.f = true;
Thread.currentThread().interrupt();
}
}
} else {
break;
}
}
}
if (!this.g) {
break;
}
}
this.e = true;
}
private synchronized void a(String str) {
this.c = new MediaPlayer();
try {
this.c.setDataSource(str);
this.c.prepare();
this.c.start();
} catch (IOException e) {
e.printStackTrace();
}
}
public void a(boolean z) {
this.g = z;
}
public ActionSequence a() {
return this.a;
}
}