Initial commit

This commit is contained in:
2025-05-13 19:24:51 +02:00
commit a950f49678
10604 changed files with 932663 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
package com.ubt.jimu.blockly.feature.sensor;
import com.ubt.jimu.transport.model.TransportFile;
/* loaded from: classes.dex */
public enum DeviceDirection {
NONE(TransportFile.TYPE_NONE, 0),
LEFT("left", 1),
RIGHT("right", 2),
UP("up", 3),
DOWN("down", 4),
SWING("swing", 5);
private int type;
private String value;
DeviceDirection(String str, int i) {
this.value = str;
this.type = i;
}
public int getType() {
return this.type;
}
public String getValue() {
return this.value;
}
}

View File

@@ -0,0 +1,134 @@
package com.ubt.jimu.blockly.feature.sensor;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import com.ubt.jimu.blockly.command.result.QueryResult;
import com.ubt.jimu.blockly.feature.blockly.JimuSensor;
import java.util.ArrayList;
/* loaded from: classes.dex */
public class DirectionSensorEventListener implements SensorEventListener {
private long currentUpdateTime;
private long lastUpdateTime;
private IShakeListener shakeListener;
private long timeInterval;
private final String TAG = DirectionSensorEventListener.class.getSimpleName();
private float[] accelerometerValues = new float[3];
private float[] magneticFieldValues = new float[3];
private final int SPEED_SHRESHOLD = 17;
private final int UPTATE_INTERVAL_TIME = 100;
private float xAcceleration = 0.0f;
private float yAcceleration = 0.0f;
private boolean shake = false;
private float radios = 0.5f;
public interface IShakeListener {
void onShake(long j, float[] fArr);
}
public DirectionSensorEventListener(IShakeListener iShakeListener) {
this.shakeListener = iShakeListener;
}
private void calculateOrientation() {
float[] fArr = new float[3];
float[] fArr2 = new float[9];
SensorManager.getRotationMatrix(fArr2, null, this.accelerometerValues, this.magneticFieldValues);
SensorManager.getOrientation(fArr2, fArr);
this.xAcceleration = fArr[1];
this.yAcceleration = fArr[2];
getDeviceDirection();
}
private void notifyDirectionChange(int i) {
QueryResult queryResult = new QueryResult();
ArrayList arrayList = new ArrayList();
arrayList.add(new JimuSensor(JimuSensor.SensorType.Phone, 1, i));
queryResult.setPhone(arrayList);
SensorObservable.getInstance().setData(queryResult);
}
public boolean directionNotChange() {
float f = this.xAcceleration;
float f2 = this.radios;
if (f > (-f2) && f < f2) {
float f3 = this.yAcceleration;
if (f3 > (-f2) && f3 < f2 && !this.shake) {
return true;
}
}
return false;
}
public synchronized DeviceDirection getDeviceDirection() {
DeviceDirection deviceDirection = DeviceDirection.NONE;
if (this.xAcceleration == 0.0f && this.yAcceleration == 0.0f) {
return deviceDirection;
}
if (Math.abs(this.xAcceleration) > Math.abs(this.yAcceleration)) {
if (this.xAcceleration < (-this.radios)) {
notifyDirectionChange(DeviceDirection.RIGHT.getType());
deviceDirection = DeviceDirection.RIGHT;
} else if (this.xAcceleration > this.radios) {
notifyDirectionChange(DeviceDirection.LEFT.getType());
deviceDirection = DeviceDirection.LEFT;
}
} else if (this.yAcceleration >= this.radios) {
notifyDirectionChange(DeviceDirection.UP.getType());
deviceDirection = DeviceDirection.UP;
} else if (this.yAcceleration < (-this.radios)) {
notifyDirectionChange(DeviceDirection.DOWN.getType());
deviceDirection = DeviceDirection.DOWN;
}
return deviceDirection;
}
public float getxAcceleration() {
return this.xAcceleration;
}
public float getyAcceleration() {
return this.yAcceleration;
}
public boolean isShake() {
return this.shake;
}
@Override // android.hardware.SensorEventListener
public void onAccuracyChanged(Sensor sensor, int i) {
}
@Override // android.hardware.SensorEventListener
public void onSensorChanged(SensorEvent sensorEvent) {
this.currentUpdateTime = System.currentTimeMillis();
long j = this.currentUpdateTime;
this.timeInterval = j - this.lastUpdateTime;
if (this.timeInterval < 100) {
return;
}
this.lastUpdateTime = j;
if (sensorEvent.sensor.getType() == 2) {
this.magneticFieldValues = sensorEvent.values;
}
if (sensorEvent.sensor.getType() == 1) {
float[] fArr = sensorEvent.values;
this.accelerometerValues = fArr;
if (this.shakeListener != null) {
float f = fArr[0];
float f2 = fArr[1];
float f3 = fArr[2];
if (Math.abs(f) >= 17.0f || Math.abs(f2) >= 17.0f || Math.abs(f3) >= 17.0f) {
notifyDirectionChange(DeviceDirection.SWING.getType());
this.shakeListener.onShake(this.currentUpdateTime, sensorEvent.values);
this.shake = true;
} else {
this.shake = false;
}
}
}
calculateOrientation();
}
}

View File

@@ -0,0 +1,223 @@
package com.ubt.jimu.blockly.feature.sensor;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.view.WindowManager;
import com.ubt.jimu.JimuApplication;
import com.ubt.jimu.blockly.command.result.QueryResult;
import com.ubt.jimu.blockly.feature.blockly.JimuSensor;
import com.ubtrobot.log.ALog;
import java.util.ArrayList;
/* loaded from: classes.dex */
public class DirectionSensorEventListerCompact implements SensorEventListener {
private static final float CHANGE_RADIO = 2.5f;
private static final int INTERVAL_TIME = 100;
private static final float SHAKE_RADIO = 1.5f;
private static final int SPEED_SHRESHOLD = 12;
private static final double mDegress = 20.0d;
private static final float mGravity = 9.80665f;
private long currentUpdateTime;
private boolean isShaking;
private long lastUpdateTime;
private ActionListener listener;
private int rotation;
private final String TAG = DirectionSensorEventListerCompact.class.getSimpleName();
private DeviceDirection dd = DeviceDirection.NONE;
public interface ActionListener {
void onBottomUp();
void onChange(float[] fArr);
void onLeftUp();
void onNormal();
void onRightUp();
void onShake(long j, float[] fArr);
void onTopUp();
}
public DirectionSensorEventListerCompact(ActionListener actionListener) {
this.listener = actionListener;
}
private void bottom() {
log("下倾斜");
DeviceDirection deviceDirection = DeviceDirection.DOWN;
this.dd = deviceDirection;
notifyDirectionChange(deviceDirection);
ActionListener actionListener = this.listener;
if (actionListener != null) {
actionListener.onBottomUp();
}
}
private void left() {
log("左倾斜");
DeviceDirection deviceDirection = DeviceDirection.LEFT;
this.dd = deviceDirection;
notifyDirectionChange(deviceDirection);
ActionListener actionListener = this.listener;
if (actionListener != null) {
actionListener.onLeftUp();
}
}
private void log(String str) {
ALog.a(this.TAG).d(str);
}
private void normal() {
log("normal");
DeviceDirection deviceDirection = DeviceDirection.NONE;
this.dd = deviceDirection;
notifyDirectionChange(deviceDirection);
ActionListener actionListener = this.listener;
if (actionListener != null) {
actionListener.onNormal();
}
}
private void notifyDirectionChange(DeviceDirection deviceDirection) {
QueryResult queryResult = new QueryResult();
ArrayList arrayList = new ArrayList();
arrayList.add(new JimuSensor(JimuSensor.SensorType.Phone, 1, deviceDirection.getType()));
queryResult.setPhone(arrayList);
SensorObservable.getInstance().setData(queryResult);
}
private void right() {
log("右倾斜");
DeviceDirection deviceDirection = DeviceDirection.RIGHT;
this.dd = deviceDirection;
notifyDirectionChange(deviceDirection);
ActionListener actionListener = this.listener;
if (actionListener != null) {
actionListener.onRightUp();
}
}
private void top() {
log("上倾斜");
DeviceDirection deviceDirection = DeviceDirection.UP;
this.dd = deviceDirection;
notifyDirectionChange(deviceDirection);
ActionListener actionListener = this.listener;
if (actionListener != null) {
actionListener.onTopUp();
}
}
public boolean directionNotChange() {
return this.dd == DeviceDirection.NONE;
}
public DeviceDirection getDeviceDirection() {
return this.dd;
}
public boolean isShaking() {
return this.isShaking;
}
@Override // android.hardware.SensorEventListener
public void onAccuracyChanged(Sensor sensor, int i) {
}
@Override // android.hardware.SensorEventListener
public void onSensorChanged(SensorEvent sensorEvent) {
this.rotation = ((WindowManager) JimuApplication.l().getSystemService("window")).getDefaultDisplay().getRotation();
this.currentUpdateTime = System.currentTimeMillis();
long j = this.currentUpdateTime;
if (j - this.lastUpdateTime < 100) {
return;
}
this.lastUpdateTime = j;
float[] fArr = sensorEvent.values;
float f = fArr[0];
float f2 = fArr[1];
float f3 = fArr[2];
double degrees = Math.toDegrees(Math.tan(f / mGravity));
double degrees2 = Math.toDegrees(Math.tan(f2 / mGravity));
double degrees3 = Math.toDegrees(Math.tan(f3 / mGravity));
log("X轴 " + f + " y轴 " + f2 + " z轴 " + f3);
log("x轴 " + degrees + " y轴 " + degrees2 + " z轴 " + degrees3 + "----方向:" + this.rotation);
if (Math.abs(f) >= 12.0f || Math.abs(f2) >= 12.0f || Math.abs(f3) >= 12.0f) {
DeviceDirection deviceDirection = DeviceDirection.SWING;
this.dd = deviceDirection;
this.isShaking = true;
notifyDirectionChange(deviceDirection);
this.listener.onShake(this.currentUpdateTime, sensorEvent.values);
return;
}
this.isShaking = false;
if (Math.abs(degrees) >= Math.abs(degrees2) && Math.abs(degrees) > mDegress) {
log("X坐标大于Y坐标");
int i = this.rotation;
if (i != 0) {
if (i != 1) {
if (i != 2) {
if (i == 3) {
if (degrees > 0.0d) {
top();
} else {
bottom();
}
}
} else if (degrees > 0.0d) {
right();
} else {
left();
}
} else if (degrees > 0.0d) {
bottom();
} else {
top();
}
} else if (degrees > 0.0d) {
left();
} else {
right();
}
} else if (Math.abs(degrees) >= Math.abs(degrees2) || Math.abs(degrees2) <= mDegress) {
normal();
} else {
log("Y坐标大于X坐标");
int i2 = this.rotation;
if (i2 != 0) {
if (i2 != 1) {
if (i2 != 2) {
if (i2 == 3) {
if (degrees2 > 0.0d) {
left();
} else {
right();
}
}
} else if (degrees2 > 0.0d) {
top();
} else {
bottom();
}
} else if (degrees2 > 0.0d) {
right();
} else {
left();
}
} else if (degrees2 > 0.0d) {
bottom();
} else {
top();
}
}
if (Math.abs(f2) >= CHANGE_RADIO || Math.abs(f) >= CHANGE_RADIO) {
return;
}
this.dd = DeviceDirection.NONE;
}
}

View File

@@ -0,0 +1,48 @@
package com.ubt.jimu.blockly.feature.sensor;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import java.util.Iterator;
import java.util.List;
/* loaded from: classes.dex */
public class ManagerHelper {
private Context context;
private SensorManager manager;
public ManagerHelper(Context context) {
this.context = context;
this.manager = (SensorManager) context.getSystemService("sensor");
}
private boolean hasSensor(SensorManager sensorManager, int i) {
List<Sensor> sensorList;
if (sensorManager == null || (sensorList = sensorManager.getSensorList(-1)) == null || sensorList.size() == 0) {
return false;
}
Iterator<Sensor> it = sensorList.iterator();
while (it.hasNext()) {
if (it.next().getType() == i) {
return true;
}
}
return false;
}
public boolean registerListener(SensorEventListener sensorEventListener, int i, int i2) {
Sensor defaultSensor;
if (hasSensor(this.manager, i) && (defaultSensor = this.manager.getDefaultSensor(i)) != null) {
return this.manager.registerListener(sensorEventListener, defaultSensor, i2);
}
return false;
}
public void unRegisterListener(SensorEventListener sensorEventListener) {
SensorManager sensorManager = this.manager;
if (sensorManager != null) {
sensorManager.unregisterListener(sensorEventListener);
}
}
}

View File

@@ -0,0 +1,53 @@
package com.ubt.jimu.blockly.feature.sensor;
import com.ubt.jimu.blockly.command.result.QueryResult;
import com.ubtrobot.log.ALog;
import java.util.Observable;
import java.util.Observer;
/* loaded from: classes.dex */
public class SensorObservable extends Observable {
private static SensorObservable instance;
private final String TAG = SensorObservable.class.getSimpleName();
private Observer activedObserver;
private QueryResult data;
public static synchronized SensorObservable getInstance() {
SensorObservable sensorObservable;
synchronized (SensorObservable.class) {
if (instance == null) {
instance = new SensorObservable();
}
sensorObservable = instance;
}
return sensorObservable;
}
public void clearActiveObserver() {
this.activedObserver = null;
}
@Override // java.util.Observable
public synchronized void deleteObserver(Observer observer) {
super.deleteObserver(observer);
reActiveObserver();
this.activedObserver = observer;
}
public void reActiveObserver() {
if (this.activedObserver != null) {
ALog.a(this.TAG).d("重新监听观察者:");
addObserver(this.activedObserver);
this.activedObserver = null;
}
}
public void setData(QueryResult queryResult) {
if (countObservers() < 1) {
return;
}
this.data = queryResult;
setChanged();
notifyObservers(queryResult);
}
}

View File

@@ -0,0 +1,323 @@
package com.ubt.jimu.blockly.feature.sensor;
import android.text.TextUtils;
import android.util.Log;
import com.ubt.jimu.blockly.command.result.QueryResult;
import com.ubt.jimu.blockly.exception.BlocklyEvent;
import com.ubt.jimu.blockly.feature.blockly.ColorSensor;
import com.ubt.jimu.blockly.feature.blockly.JimuSensor;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Observable;
import java.util.Observer;
import org.greenrobot.eventbus.EventBus;
/* loaded from: classes.dex */
public class SensorObserver implements Observer {
private final String TAG = SensorObserver.class.getSimpleName();
private String branchId;
private String callback;
private String operator;
private String result;
private String sensorId;
private String sensorType;
private String value;
public static class Compareration {
public static final String OP_EQUALS = "EQ";
public static final String OP_GREATER_THAN = "GTE";
public static final String OP_LESS_THAN = "LTE";
public static final String OP_NOT_EQUALS = "NEQ";
/* JADX WARN: Code restructure failed: missing block: B:13:0x004e, code lost:
if (r1 == 1) goto L35;
*/
/* JADX WARN: Code restructure failed: missing block: B:14:0x0050, code lost:
if (r1 == 2) goto L32;
*/
/* JADX WARN: Code restructure failed: missing block: B:15:0x0052, code lost:
if (r1 == 3) goto L29;
*/
/* JADX WARN: Code restructure failed: missing block: B:17:0x0057, code lost:
if (r7 == r9) goto L45;
*/
/* JADX WARN: Code restructure failed: missing block: B:20:?, code lost:
return false;
*/
/* JADX WARN: Code restructure failed: missing block: B:21:?, code lost:
return false;
*/
/* JADX WARN: Code restructure failed: missing block: B:23:0x005d, code lost:
if (r7 > r9) goto L47;
*/
/* JADX WARN: Code restructure failed: missing block: B:24:?, code lost:
return false;
*/
/* JADX WARN: Code restructure failed: missing block: B:26:0x0062, code lost:
if (r7 != r9) goto L48;
*/
/* JADX WARN: Code restructure failed: missing block: B:27:?, code lost:
return false;
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
public static boolean compare(java.lang.String r7, java.lang.String r8, java.lang.String r9) {
/*
r0 = 0
float r7 = java.lang.Float.parseFloat(r7) // Catch: java.lang.NumberFormatException -> L6a
float r9 = java.lang.Float.parseFloat(r9) // Catch: java.lang.NumberFormatException -> L6a
r1 = -1
int r2 = r8.hashCode() // Catch: java.lang.NumberFormatException -> L6a
r3 = 2220(0x8ac, float:3.111E-42)
r4 = 3
r5 = 2
r6 = 1
if (r2 == r3) goto L43
r3 = 70904(0x114f8, float:9.9358E-41)
if (r2 == r3) goto L39
r3 = 75709(0x127bd, float:1.06091E-40)
if (r2 == r3) goto L2f
r3 = 77178(0x12d7a, float:1.0815E-40)
if (r2 == r3) goto L25
goto L4c
L25:
java.lang.String r2 = "NEQ"
boolean r8 = r8.equals(r2) // Catch: java.lang.NumberFormatException -> L6a
if (r8 == 0) goto L4c
r1 = 3
goto L4c
L2f:
java.lang.String r2 = "LTE"
boolean r8 = r8.equals(r2) // Catch: java.lang.NumberFormatException -> L6a
if (r8 == 0) goto L4c
r1 = 2
goto L4c
L39:
java.lang.String r2 = "GTE"
boolean r8 = r8.equals(r2) // Catch: java.lang.NumberFormatException -> L6a
if (r8 == 0) goto L4c
r1 = 0
goto L4c
L43:
java.lang.String r2 = "EQ"
boolean r8 = r8.equals(r2) // Catch: java.lang.NumberFormatException -> L6a
if (r8 == 0) goto L4c
r1 = 1
L4c:
if (r1 == 0) goto L65
if (r1 == r6) goto L60
if (r1 == r5) goto L5b
if (r1 == r4) goto L55
goto L77
L55:
int r7 = (r7 > r9 ? 1 : (r7 == r9 ? 0 : -1))
if (r7 == 0) goto L77
L59:
r0 = 1
goto L77
L5b:
int r7 = (r7 > r9 ? 1 : (r7 == r9 ? 0 : -1))
if (r7 > 0) goto L77
goto L59
L60:
int r7 = (r7 > r9 ? 1 : (r7 == r9 ? 0 : -1))
if (r7 != 0) goto L77
goto L59
L65:
int r7 = (r7 > r9 ? 1 : (r7 == r9 ? 0 : -1))
if (r7 < 0) goto L77
goto L59
L6a:
r7 = move-exception
r7.printStackTrace()
java.lang.String r7 = r7.getMessage()
java.lang.String r8 = "Comparation"
android.util.Log.e(r8, r7)
L77:
return r0
*/
throw new UnsupportedOperationException("Method not decompiled: com.ubt.jimu.blockly.feature.sensor.SensorObserver.Compareration.compare(java.lang.String, java.lang.String, java.lang.String):boolean");
}
}
private void check(Observable observable, QueryResult queryResult) {
if (TextUtils.isEmpty(this.sensorId)) {
return;
}
if (JimuSensor.SensorType.Infrared.sameSensor(this.sensorType)) {
checkInfrared(observable, queryResult);
return;
}
if (JimuSensor.SensorType.Gyroscope.sameSensor(this.sensorType)) {
checkGyroscope(observable, queryResult);
return;
}
if (JimuSensor.SensorType.Touch.sameSensor(this.sensorType)) {
checkTouch(observable, queryResult);
return;
}
if (JimuSensor.SensorType.Phone.sameSensor(this.sensorType)) {
checkPhone(observable, queryResult);
} else if (JimuSensor.SensorType.ULTRASONIC.sameSensor(this.sensorType)) {
checkUltrasonic(observable, queryResult);
} else if (JimuSensor.SensorType.COLOR.sameSensor(this.sensorType)) {
checkColor(observable, queryResult);
}
}
private void checkColor(Observable observable, QueryResult queryResult) {
List<ColorSensor> color = queryResult.getColor();
if (color == null || color.size() == 0) {
return;
}
for (ColorSensor colorSensor : color) {
if (!TextUtils.isEmpty(this.sensorId) && this.sensorId.equals(String.valueOf(colorSensor.getId()))) {
if (Compareration.OP_EQUALS.equals(this.operator)) {
if (!TextUtils.isEmpty(colorSensor.getColor()) && colorSensor.getColor().equals(this.value)) {
setJSResult(this.callback, this.branchId, colorSensor.getColor());
observable.deleteObserver(this);
return;
}
} else if (Compareration.OP_NOT_EQUALS.equals(this.operator) && !TextUtils.isEmpty(colorSensor.getColor()) && !colorSensor.getColor().equals(this.value)) {
setJSResult(this.callback, this.branchId, colorSensor.getColor());
observable.deleteObserver(this);
return;
}
}
}
}
private void checkGyroscope(Observable observable, QueryResult queryResult) {
}
private void checkInfrared(Observable observable, QueryResult queryResult) {
List<JimuSensor> infrared = queryResult.getInfrared();
if (infrared == null || infrared.size() < 1) {
return;
}
Iterator<JimuSensor> it = infrared.iterator();
while (it.hasNext() && !setResult(observable, it.next())) {
}
}
private void checkPhone(Observable observable, QueryResult queryResult) {
List<JimuSensor> phone = queryResult.getPhone();
if (phone == null || phone.size() < 1) {
return;
}
this.result = phone.get(0).getResult() + "";
int i = -1;
DeviceDirection[] values = DeviceDirection.values();
int length = values.length;
int i2 = 0;
while (true) {
if (i2 >= length) {
break;
}
DeviceDirection deviceDirection = values[i2];
if (deviceDirection.getValue().equals(this.value)) {
i = deviceDirection.getType();
break;
}
i2++;
}
if (Compareration.compare(this.result, this.operator, i + "")) {
setJSResult(this.callback, this.branchId, this.result);
observable.deleteObserver(this);
}
}
private void checkTouch(Observable observable, QueryResult queryResult) {
List<JimuSensor> touch = queryResult.getTouch();
if (touch == null || touch.size() < 1) {
return;
}
for (JimuSensor jimuSensor : touch) {
if (this.sensorId.equals(jimuSensor.getId() + "")) {
this.result = jimuSensor.getResult() + "";
if (Compareration.compare(this.result, this.operator, this.value)) {
setJSResult(this.callback, this.branchId, this.result);
if (observable instanceof SensorObservable) {
((SensorObservable) observable).reActiveObserver();
return;
}
return;
}
return;
}
}
}
private void checkUltrasonic(Observable observable, QueryResult queryResult) {
List<JimuSensor> ultrasonic = queryResult.getUltrasonic();
if (ultrasonic == null || ultrasonic.size() < 1) {
return;
}
Iterator<JimuSensor> it = ultrasonic.iterator();
while (it.hasNext() && !setResult(observable, it.next())) {
}
}
private void setJSResult(String str, String... strArr) {
StringBuilder sb = new StringBuilder();
sb.append("javascript:");
sb.append(str);
sb.append("(");
if (strArr != null && strArr.length > 0) {
for (int i = 0; i < strArr.length; i++) {
sb.append("'");
sb.append(strArr[i]);
sb.append("'");
if (i < strArr.length - 1) {
sb.append(",");
}
}
}
sb.append(")");
String sb2 = sb.toString();
Log.i(this.TAG, sb2);
EventBus.b().b(new BlocklyEvent(1004, sb2));
}
private boolean setResult(Observable observable, JimuSensor jimuSensor) {
if (!this.sensorId.equals(jimuSensor.getId() + "")) {
return false;
}
this.result = jimuSensor.getResult() + "";
if (Compareration.compare(this.result, this.operator, this.value)) {
setJSResult(this.callback, this.branchId, this.result);
observable.deleteObserver(this);
}
return true;
}
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof SensorObserver)) {
return false;
}
SensorObserver sensorObserver = (SensorObserver) obj;
return !TextUtils.isEmpty(sensorObserver.branchId) && sensorObserver.branchId.equals(this.branchId);
}
public int hashCode() {
return Objects.hash(this.branchId);
}
@Override // java.util.Observer
public void update(Observable observable, Object obj) {
check(observable, (QueryResult) obj);
}
}