Initial commit
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.ubt.jimu.blockly.feature.audio;
|
||||
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class AndroidManufacturer {
|
||||
public static final String ASUS = "asus";
|
||||
public static final String SAMSUNG = "samsung";
|
||||
public static final String VIVO = "vivo";
|
||||
public static final String XIAO_MI = "Xiaomi";
|
||||
|
||||
public static boolean match(String str) {
|
||||
if (TextUtils.isEmpty(str)) {
|
||||
return false;
|
||||
}
|
||||
return Build.MANUFACTURER.toLowerCase().equals(str.toLowerCase());
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
package com.ubt.jimu.blockly.feature.audio;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class AudioParams {
|
||||
public static final String AAC = ".aac";
|
||||
public static final String MP3 = ".mp3";
|
||||
public static final String WAV = ".wav";
|
||||
public static final String gpp = ".3gp";
|
||||
}
|
195
sources/com/ubt/jimu/blockly/feature/audio/AudioPlayer.java
Normal file
195
sources/com/ubt/jimu/blockly/feature/audio/AudioPlayer.java
Normal file
@@ -0,0 +1,195 @@
|
||||
package com.ubt.jimu.blockly.feature.audio;
|
||||
|
||||
import android.media.MediaPlayer;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class AudioPlayer {
|
||||
private static AudioPlayer player;
|
||||
private MediaPlayer mPlayer;
|
||||
private String source;
|
||||
private Timer timer;
|
||||
private final String TAG = AudioPlayer.class.getSimpleName();
|
||||
private boolean isPausing = false;
|
||||
private int progress = -1;
|
||||
|
||||
public interface IProgressListener {
|
||||
void onError();
|
||||
|
||||
void onFinished();
|
||||
}
|
||||
|
||||
private class MyTimerTask extends TimerTask {
|
||||
private long future;
|
||||
|
||||
public MyTimerTask(long j) {
|
||||
this.future = j;
|
||||
}
|
||||
|
||||
@Override // java.util.TimerTask, java.lang.Runnable
|
||||
public void run() {
|
||||
if (AudioPlayer.this.mPlayer == null || AudioPlayer.this.mPlayer.getCurrentPosition() < this.future) {
|
||||
return;
|
||||
}
|
||||
AudioPlayer.this.stop();
|
||||
AudioPlayer.this.timer.cancel();
|
||||
AudioPlayer.this.timer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private AudioPlayer() {
|
||||
this.mPlayer = null;
|
||||
this.mPlayer = new MediaPlayer();
|
||||
this.mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { // from class: com.ubt.jimu.blockly.feature.audio.AudioPlayer.1
|
||||
@Override // android.media.MediaPlayer.OnCompletionListener
|
||||
public void onCompletion(MediaPlayer mediaPlayer) {
|
||||
Log.i(AudioPlayer.this.TAG, "onCompletion");
|
||||
}
|
||||
});
|
||||
this.mPlayer.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() { // from class: com.ubt.jimu.blockly.feature.audio.AudioPlayer.2
|
||||
@Override // android.media.MediaPlayer.OnSeekCompleteListener
|
||||
public void onSeekComplete(MediaPlayer mediaPlayer) {
|
||||
Log.i(AudioPlayer.this.TAG, "onSeekComplete");
|
||||
}
|
||||
});
|
||||
this.mPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { // from class: com.ubt.jimu.blockly.feature.audio.AudioPlayer.3
|
||||
@Override // android.media.MediaPlayer.OnErrorListener
|
||||
public boolean onError(MediaPlayer mediaPlayer, int i, int i2) {
|
||||
Log.e(AudioPlayer.this.TAG, "播放onError:what=" + i + " extra=" + i2);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
this.mPlayer.setOnInfoListener(new MediaPlayer.OnInfoListener() { // from class: com.ubt.jimu.blockly.feature.audio.AudioPlayer.4
|
||||
@Override // android.media.MediaPlayer.OnInfoListener
|
||||
public boolean onInfo(MediaPlayer mediaPlayer, int i, int i2) {
|
||||
Log.e(AudioPlayer.this.TAG, "onInfo:what=" + i + " extra=" + i2);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static synchronized AudioPlayer getInstance() {
|
||||
AudioPlayer audioPlayer;
|
||||
synchronized (AudioPlayer.class) {
|
||||
if (player == null) {
|
||||
player = new AudioPlayer();
|
||||
}
|
||||
audioPlayer = player;
|
||||
}
|
||||
return audioPlayer;
|
||||
}
|
||||
|
||||
private void startTimer(long j) {
|
||||
Timer timer = this.timer;
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
}
|
||||
this.timer = new Timer();
|
||||
this.timer.schedule(new MyTimerTask(j), 0L, 50L);
|
||||
}
|
||||
|
||||
public long getAudioDuration(String str) {
|
||||
try {
|
||||
this.mPlayer.reset();
|
||||
this.mPlayer.setDataSource(str);
|
||||
this.mPlayer.prepare();
|
||||
return this.mPlayer.getDuration();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
try {
|
||||
this.progress = this.mPlayer.getCurrentPosition();
|
||||
this.isPausing = true;
|
||||
this.mPlayer.pause();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean play(String str) {
|
||||
if (!new File(str).exists()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
this.mPlayer.reset();
|
||||
this.mPlayer.setDataSource(str);
|
||||
this.mPlayer.prepare();
|
||||
if (TextUtils.isEmpty(this.source)) {
|
||||
this.source = str;
|
||||
this.progress = -1;
|
||||
this.isPausing = false;
|
||||
} else if (this.source.equals(str)) {
|
||||
if (!this.isPausing) {
|
||||
this.source = str;
|
||||
this.progress = -1;
|
||||
this.isPausing = false;
|
||||
} else if (this.progress > -1) {
|
||||
this.mPlayer.seekTo(this.progress);
|
||||
this.progress = -1;
|
||||
this.isPausing = false;
|
||||
}
|
||||
}
|
||||
this.mPlayer.start();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.mPlayer.release();
|
||||
this.mPlayer = null;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
try {
|
||||
this.source = null;
|
||||
this.mPlayer.stop();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean play(String str, final IProgressListener iProgressListener) {
|
||||
this.mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { // from class: com.ubt.jimu.blockly.feature.audio.AudioPlayer.5
|
||||
@Override // android.media.MediaPlayer.OnCompletionListener
|
||||
public void onCompletion(MediaPlayer mediaPlayer) {
|
||||
IProgressListener iProgressListener2 = iProgressListener;
|
||||
if (iProgressListener2 != null) {
|
||||
iProgressListener2.onFinished();
|
||||
}
|
||||
AudioPlayer.this.mPlayer.setOnCompletionListener(null);
|
||||
}
|
||||
});
|
||||
this.mPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { // from class: com.ubt.jimu.blockly.feature.audio.AudioPlayer.6
|
||||
@Override // android.media.MediaPlayer.OnErrorListener
|
||||
public boolean onError(MediaPlayer mediaPlayer, int i, int i2) {
|
||||
Log.e(AudioPlayer.this.TAG, "MediaPlayer onError:what=" + i + " extra=" + i2);
|
||||
IProgressListener iProgressListener2 = iProgressListener;
|
||||
if (iProgressListener2 != null) {
|
||||
iProgressListener2.onError();
|
||||
}
|
||||
AudioPlayer.this.mPlayer.setOnErrorListener(null);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return play(str);
|
||||
}
|
||||
|
||||
public void play(String str, long j, IProgressListener iProgressListener) {
|
||||
if (!play(str, iProgressListener) || j <= 0) {
|
||||
return;
|
||||
}
|
||||
startTimer(j);
|
||||
}
|
||||
}
|
159
sources/com/ubt/jimu/blockly/feature/audio/AudioRecoder.java
Normal file
159
sources/com/ubt/jimu/blockly/feature/audio/AudioRecoder.java
Normal file
@@ -0,0 +1,159 @@
|
||||
package com.ubt.jimu.blockly.feature.audio;
|
||||
|
||||
import android.media.MediaRecorder;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.ubtech.utils.FileHelper;
|
||||
import java.io.File;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class AudioRecoder {
|
||||
private static AudioRecoder audioRecoder = null;
|
||||
public static boolean recoding = false;
|
||||
private String fileName;
|
||||
private MediaRecorder recorder;
|
||||
private final String TAG = AudioRecoder.class.getSimpleName();
|
||||
private int sampleRateInHz = 16000;
|
||||
private long lastRecordTime = 0;
|
||||
|
||||
private class RecorderInfoListener implements MediaRecorder.OnInfoListener {
|
||||
private RecorderInfoListener() {
|
||||
}
|
||||
|
||||
@Override // android.media.MediaRecorder.OnInfoListener
|
||||
public void onInfo(MediaRecorder mediaRecorder, int i, int i2) {
|
||||
if (i == 1) {
|
||||
Log.e(AudioRecoder.this.TAG, "OnInfo: MEDIA_RECORDER_INFO_UNKNOWN");
|
||||
return;
|
||||
}
|
||||
if (i == 800) {
|
||||
AudioRecoder.recoding = false;
|
||||
Log.e(AudioRecoder.this.TAG, "OnInfo: MEDIA_RECORDER_INFO_MAX_DURATION_REACHED");
|
||||
} else {
|
||||
if (i != 801) {
|
||||
return;
|
||||
}
|
||||
AudioRecoder.recoding = false;
|
||||
Log.e(AudioRecoder.this.TAG, "OnInfo: MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class RecorderOnErrorListener implements MediaRecorder.OnErrorListener {
|
||||
private RecorderOnErrorListener() {
|
||||
}
|
||||
|
||||
@Override // android.media.MediaRecorder.OnErrorListener
|
||||
public void onError(MediaRecorder mediaRecorder, int i, int i2) {
|
||||
AudioRecoder.recoding = false;
|
||||
Log.e(AudioRecoder.this.TAG, "录音失败:what=" + i + " extra=" + i2);
|
||||
File file = new File(AudioRecoder.this.fileName);
|
||||
if (file.exists()) {
|
||||
FileHelper.a(file.getParentFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AudioRecoder() {
|
||||
}
|
||||
|
||||
private boolean aacLibRecord(String str) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean aacRecord(String str) throws Exception {
|
||||
try {
|
||||
release();
|
||||
File parentFile = new File(str).getParentFile();
|
||||
if (!parentFile.exists()) {
|
||||
parentFile.mkdirs();
|
||||
}
|
||||
this.fileName = str;
|
||||
this.recorder = new MediaRecorder();
|
||||
this.recorder.setAudioSource(1);
|
||||
this.recorder.setOutputFormat(6);
|
||||
this.recorder.setAudioEncoder(3);
|
||||
this.recorder.setAudioSamplingRate(8000);
|
||||
this.recorder.setAudioChannels(1);
|
||||
this.recorder.setOutputFile(str);
|
||||
this.recorder.setOnErrorListener(new RecorderOnErrorListener());
|
||||
this.recorder.setOnInfoListener(new RecorderInfoListener());
|
||||
this.recorder.prepare();
|
||||
this.recorder.start();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
onRecordFailed(str);
|
||||
e.printStackTrace();
|
||||
release();
|
||||
Log.e(this.TAG, "prepare() failed");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized AudioRecoder getInstance() {
|
||||
AudioRecoder audioRecoder2;
|
||||
synchronized (AudioRecoder.class) {
|
||||
if (audioRecoder == null) {
|
||||
audioRecoder = new AudioRecoder();
|
||||
}
|
||||
audioRecoder2 = audioRecoder;
|
||||
}
|
||||
return audioRecoder2;
|
||||
}
|
||||
|
||||
private void onRecordFailed(String str) {
|
||||
File parentFile = new File(str).getParentFile();
|
||||
if (parentFile.exists()) {
|
||||
FileHelper.a(parentFile);
|
||||
try {
|
||||
FileHelper.a(parentFile);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return this.fileName;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
if (TextUtils.isEmpty(this.fileName)) {
|
||||
return null;
|
||||
}
|
||||
String str = this.fileName;
|
||||
String substring = str.substring(str.lastIndexOf(File.separator) + 1, this.fileName.length());
|
||||
return substring.substring(0, substring.lastIndexOf("."));
|
||||
}
|
||||
|
||||
public void release() {
|
||||
MediaRecorder mediaRecorder = this.recorder;
|
||||
if (mediaRecorder != null) {
|
||||
try {
|
||||
try {
|
||||
mediaRecorder.release();
|
||||
} catch (IllegalStateException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} finally {
|
||||
this.recorder = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean startRecord(String str) throws Exception {
|
||||
recoding = true;
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
if (currentTimeMillis - this.lastRecordTime < 500) {
|
||||
return false;
|
||||
}
|
||||
Log.i(this.TAG, "调用录音:" + str);
|
||||
this.lastRecordTime = currentTimeMillis;
|
||||
return aacRecord(str);
|
||||
}
|
||||
|
||||
public void stopRecod() {
|
||||
recoding = false;
|
||||
release();
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
package com.ubt.jimu.blockly.feature.blockly;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BlocklyEmotion {
|
||||
private boolean islightLock;
|
||||
private List<Emotion> lightArray;
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || BlocklyEmotion.class != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
BlocklyEmotion blocklyEmotion = (BlocklyEmotion) obj;
|
||||
return this.islightLock == blocklyEmotion.islightLock && Objects.equals(this.lightArray, blocklyEmotion.lightArray);
|
||||
}
|
||||
|
||||
public List<Emotion> getLightArray() {
|
||||
return this.lightArray;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return Objects.hash(Boolean.valueOf(this.islightLock), this.lightArray);
|
||||
}
|
||||
|
||||
public boolean islightLock() {
|
||||
return this.islightLock;
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
package com.ubt.jimu.blockly.feature.blockly;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BlocklyLight {
|
||||
private boolean islightLock;
|
||||
private List<Light> lightArray;
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || BlocklyLight.class != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
BlocklyLight blocklyLight = (BlocklyLight) obj;
|
||||
return this.islightLock == blocklyLight.islightLock && Objects.equals(getLightArray(), blocklyLight.getLightArray());
|
||||
}
|
||||
|
||||
public List<Light> getLightArray() {
|
||||
return this.lightArray;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return Objects.hash(Boolean.valueOf(this.islightLock), getLightArray());
|
||||
}
|
||||
|
||||
public boolean islightLock() {
|
||||
return this.islightLock;
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package com.ubt.jimu.blockly.feature.blockly;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class ColorSensor {
|
||||
private String color;
|
||||
private int id;
|
||||
private String realColor;
|
||||
|
||||
public ColorSensor() {
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getRealColor() {
|
||||
return this.realColor;
|
||||
}
|
||||
|
||||
public ColorSensor(int i, String str) {
|
||||
this.id = i;
|
||||
this.color = str;
|
||||
}
|
||||
}
|
37
sources/com/ubt/jimu/blockly/feature/blockly/Emotion.java
Normal file
37
sources/com/ubt/jimu/blockly/feature/blockly/Emotion.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package com.ubt.jimu.blockly.feature.blockly;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class Emotion {
|
||||
private String color;
|
||||
private int emotionIndex;
|
||||
private int id;
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof Emotion)) {
|
||||
return false;
|
||||
}
|
||||
Emotion emotion = (Emotion) obj;
|
||||
return this.id == emotion.id && this.emotionIndex == emotion.emotionIndex;
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public int getEmotionIndex() {
|
||||
return this.emotionIndex;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return Objects.hash(Integer.valueOf(this.id), Integer.valueOf(this.emotionIndex));
|
||||
}
|
||||
}
|
25
sources/com/ubt/jimu/blockly/feature/blockly/Gyroscope.java
Normal file
25
sources/com/ubt/jimu/blockly/feature/blockly/Gyroscope.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.ubt.jimu.blockly.feature.blockly;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class Gyroscope {
|
||||
private int id;
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package com.ubt.jimu.blockly.feature.blockly;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class JimuAction {
|
||||
public String icon;
|
||||
public String id;
|
||||
public String name;
|
||||
}
|
100
sources/com/ubt/jimu/blockly/feature/blockly/JimuSensor.java
Normal file
100
sources/com/ubt/jimu/blockly/feature/blockly/JimuSensor.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package com.ubt.jimu.blockly.feature.blockly;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class JimuSensor {
|
||||
private int id;
|
||||
private float result;
|
||||
private String type;
|
||||
|
||||
public enum SensorType {
|
||||
Phone("phone", 99),
|
||||
Infrared("Infrared", 101),
|
||||
Touch("Touch", 102),
|
||||
Gyroscope("Gyroscope", 103),
|
||||
Light("Light", 104),
|
||||
Gravity("Gravity", 105),
|
||||
Ultrasonic("Ultrasonic", 106),
|
||||
DigitalTube("DigitalTube", 107),
|
||||
Speaker("Speaker", 108),
|
||||
ULTRASONIC("ultrasonic", 109),
|
||||
COLOR("color", 110);
|
||||
|
||||
private String name;
|
||||
private int type;
|
||||
|
||||
SensorType(String str, int i) {
|
||||
this.name = str;
|
||||
this.type = i;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public boolean sameSensor(String str) {
|
||||
return this.name.toLowerCase().equals(str.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
public JimuSensor() {
|
||||
}
|
||||
|
||||
public static float convertInfraredValueToLevel2(float f) {
|
||||
int i;
|
||||
double d;
|
||||
double d2;
|
||||
float f2 = f - 850.0f;
|
||||
if (f2 < 0.0f) {
|
||||
i = 0;
|
||||
} else {
|
||||
if (f2 < 70.0f) {
|
||||
d = f2 - 15.0f;
|
||||
d2 = 13.5d;
|
||||
} else if (f2 < 1210.0f) {
|
||||
d = f2 + 1134.0f;
|
||||
d2 = 288.0d;
|
||||
} else if (f2 < 1565.0f) {
|
||||
i = (int) ((f2 + 206.0f) / 177.0f);
|
||||
} else if (f2 < 1821.0f) {
|
||||
d = f2 - 1033.0f;
|
||||
d2 = 53.75d;
|
||||
} else if (f2 < 2200.0f) {
|
||||
d = f2 - 1462.0f;
|
||||
d2 = 22.75d;
|
||||
} else {
|
||||
i = 20;
|
||||
}
|
||||
i = (int) (d / d2);
|
||||
}
|
||||
if (i > 20) {
|
||||
i = 20;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public float getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setResult(float f) {
|
||||
this.result = f;
|
||||
}
|
||||
|
||||
public JimuSensor(SensorType sensorType, int i, int i2) {
|
||||
this.type = sensorType.getName();
|
||||
this.id = i;
|
||||
this.result = i2;
|
||||
}
|
||||
}
|
45
sources/com/ubt/jimu/blockly/feature/blockly/Light.java
Normal file
45
sources/com/ubt/jimu/blockly/feature/blockly/Light.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package com.ubt.jimu.blockly.feature.blockly;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class Light {
|
||||
private int id;
|
||||
private List<String> lights;
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj != null && (obj instanceof Light)) {
|
||||
Light light = (Light) obj;
|
||||
if (this.id != light.id) {
|
||||
return false;
|
||||
}
|
||||
if (this.lights == null && light.lights == null) {
|
||||
return true;
|
||||
}
|
||||
List<String> list = this.lights;
|
||||
if (list == null || light.lights == null || list.size() != light.lights.size()) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < this.lights.size(); i++) {
|
||||
if (!this.lights.get(i).toLowerCase().equals(light.lights.get(i).toLowerCase())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public List<String> getLights() {
|
||||
return this.lights;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return Objects.hash(Integer.valueOf(this.id), this.lights);
|
||||
}
|
||||
}
|
@@ -0,0 +1,338 @@
|
||||
package com.ubt.jimu.blockly.feature.course;
|
||||
|
||||
import com.ubt.jimu.blockly.bean.JimuSound;
|
||||
import com.ubt.jimu.blockly.feature.blockly.BlocklyEmotion;
|
||||
import com.ubt.jimu.blockly.feature.blockly.BlocklyLight;
|
||||
import com.ubt.jimu.controller.data.widget.JockstickDataConverter;
|
||||
import com.ubt.jimu.utils.JsonHelper;
|
||||
import com.ubtech.utils.XmlHelper;
|
||||
import com.unity3d.ads.metadata.MediationMetaData;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BlocklyDomCompare {
|
||||
private final String TAG = BlocklyDomCompare.class.getSimpleName();
|
||||
public final String correct = "0";
|
||||
public final String error = "-1";
|
||||
public final String attri = "x,y,id,SceneLight,PROGRAM_BRANCH";
|
||||
|
||||
private String checkProgramDocument(Node node, Node node2) {
|
||||
if (node == null || node2 == null) {
|
||||
return "-1";
|
||||
}
|
||||
if (!node.hasChildNodes() && !node2.hasChildNodes()) {
|
||||
return node.getNodeType() != node2.getNodeType() ? "-1" : node.getNodeType() == 3 ? !compareTextNode(node, node2) ? getNodeId(node2) : "0" : compareAttribute(node, node2) ? "0" : getNodeId(node2);
|
||||
}
|
||||
NodeList childNodes = node.getChildNodes();
|
||||
NodeList childNodes2 = node2.getChildNodes();
|
||||
if (childNodes == null && childNodes2 == null) {
|
||||
return "0";
|
||||
}
|
||||
if (childNodes == null || childNodes2 == null || childNodes.getLength() == 0 || childNodes2.getLength() == 0) {
|
||||
return getNodeId(node2);
|
||||
}
|
||||
int i = 0;
|
||||
String str = "0";
|
||||
while (true) {
|
||||
if (i < childNodes.getLength()) {
|
||||
if (i < childNodes2.getLength()) {
|
||||
Node item = childNodes.item(i);
|
||||
Node item2 = childNodes2.item(i);
|
||||
if (!compareAttribute(item, item2)) {
|
||||
str = getNodeId(item2);
|
||||
break;
|
||||
}
|
||||
if (item != null && !item.getNodeName().equals(item2.getNodeName())) {
|
||||
str = getNodeId(item2);
|
||||
break;
|
||||
}
|
||||
str = checkProgramDocument(item, item2);
|
||||
if (!"0".equals(str)) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
} else {
|
||||
str = getNodeId(childNodes2.item(childNodes2.getLength() - 1));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (i == childNodes.getLength() && "0".equals(str) && childNodes.getLength() < childNodes2.getLength()) ? getNodeId(childNodes2.item(i)) : str;
|
||||
}
|
||||
|
||||
private boolean compareAttribute(Node node, Node node2) {
|
||||
if (node == null && node2 == null) {
|
||||
return true;
|
||||
}
|
||||
if (node != null && node2 != null) {
|
||||
NamedNodeMap attributes = node.getAttributes();
|
||||
NamedNodeMap attributes2 = node2.getAttributes();
|
||||
if (attributes == null && attributes2 == null) {
|
||||
return true;
|
||||
}
|
||||
if (attributes != null && attributes2 != null && attributes.getLength() == attributes2.getLength()) {
|
||||
HashMap hashMap = new HashMap();
|
||||
HashMap hashMap2 = new HashMap();
|
||||
for (int i = 0; i < attributes.getLength(); i++) {
|
||||
Node item = attributes.item(i);
|
||||
if (!"x,y,id,SceneLight,PROGRAM_BRANCH".contains(item.getNodeName())) {
|
||||
hashMap.put(item.getNodeName(), item.getNodeValue());
|
||||
}
|
||||
}
|
||||
for (int i2 = 0; i2 < attributes2.getLength(); i2++) {
|
||||
Node item2 = attributes2.item(i2);
|
||||
if (!"x,y,id,SceneLight,PROGRAM_BRANCH".contains(item2.getNodeName())) {
|
||||
hashMap2.put(item2.getNodeName(), item2.getNodeValue());
|
||||
}
|
||||
}
|
||||
if (hashMap.size() != hashMap2.size()) {
|
||||
return false;
|
||||
}
|
||||
for (String str : hashMap.keySet()) {
|
||||
if (!((String) hashMap.get(str)).equals(hashMap2.get(str))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean compareEmotion(Node node, Node node2) {
|
||||
BlocklyEmotion blocklyEmotion = (BlocklyEmotion) JsonHelper.a(node.getNodeValue(), (Class<?>) BlocklyEmotion.class);
|
||||
BlocklyEmotion blocklyEmotion2 = (BlocklyEmotion) JsonHelper.a(node2.getNodeValue(), (Class<?>) BlocklyEmotion.class);
|
||||
if (blocklyEmotion == null && blocklyEmotion2 == null) {
|
||||
return true;
|
||||
}
|
||||
if (blocklyEmotion == null || blocklyEmotion2 == null) {
|
||||
return false;
|
||||
}
|
||||
return blocklyEmotion.equals(blocklyEmotion2);
|
||||
}
|
||||
|
||||
private boolean compareLight(Node node, Node node2) {
|
||||
BlocklyLight blocklyLight = (BlocklyLight) JsonHelper.a(node.getNodeValue(), (Class<?>) BlocklyLight.class);
|
||||
BlocklyLight blocklyLight2 = (BlocklyLight) JsonHelper.a(node2.getNodeValue(), (Class<?>) BlocklyLight.class);
|
||||
if (blocklyLight == null && blocklyLight2 == null) {
|
||||
return true;
|
||||
}
|
||||
if (blocklyLight == null || blocklyLight2 == null) {
|
||||
return false;
|
||||
}
|
||||
return blocklyLight.equals(blocklyLight2);
|
||||
}
|
||||
|
||||
private boolean compareSound(Node node, Node node2) {
|
||||
JimuSound jimuSound = (JimuSound) JsonHelper.a(node.getNodeValue(), (Class<?>) JimuSound.class);
|
||||
JimuSound jimuSound2 = (JimuSound) JsonHelper.a(node2.getNodeValue(), (Class<?>) JimuSound.class);
|
||||
if (jimuSound == null && jimuSound2 == null) {
|
||||
return true;
|
||||
}
|
||||
if (jimuSound == null || jimuSound2 == null) {
|
||||
return false;
|
||||
}
|
||||
return jimuSound.equals(jimuSound2);
|
||||
}
|
||||
|
||||
private boolean compareTextNode(Node node, Node node2) {
|
||||
NamedNodeMap attributes = node.getParentNode().getAttributes();
|
||||
for (int i = 0; i < attributes.getLength(); i++) {
|
||||
Node item = attributes.item(i);
|
||||
if (MediationMetaData.KEY_NAME.equals(item.getNodeName()) && "PROGRAM_BRANCH".equals(item.getNodeValue())) {
|
||||
return true;
|
||||
}
|
||||
if (MediationMetaData.KEY_NAME.equals(item.getNodeName()) && "Effect".equals(item.getNodeValue())) {
|
||||
return compareSound(node, node2);
|
||||
}
|
||||
if (MediationMetaData.KEY_NAME.equals(item.getNodeName()) && "Light".equals(item.getNodeValue())) {
|
||||
return compareLight(node, node2);
|
||||
}
|
||||
if (MediationMetaData.KEY_NAME.equals(item.getNodeName()) && "Emotion".equals(item.getNodeValue())) {
|
||||
return compareEmotion(node, node2);
|
||||
}
|
||||
}
|
||||
return node.getNodeValue().equals(node2.getNodeValue());
|
||||
}
|
||||
|
||||
private String getNodeId(Node node) {
|
||||
if (node == null) {
|
||||
return "-1";
|
||||
}
|
||||
if (!node.hasAttributes()) {
|
||||
return getNodeId(node.getParentNode());
|
||||
}
|
||||
NamedNodeMap attributes = node.getAttributes();
|
||||
for (int i = 0; i < attributes.getLength(); i++) {
|
||||
Node item = attributes.item(i);
|
||||
if (JockstickDataConverter.ID.equals(item.getNodeName())) {
|
||||
return item.getNodeValue();
|
||||
}
|
||||
}
|
||||
return getNodeId(node.getParentNode());
|
||||
}
|
||||
|
||||
public static void main(String[] strArr) {
|
||||
System.out.println(new BlocklyDomCompare().check(new File("C:\\Users\\lenovo\\Desktop\\2018\\Jimu-开发设计文档\\Jimu3.0-android\\课程\\standarXml.xml"), new File("C:\\Users\\lenovo\\Desktop\\2018\\Jimu-开发设计文档\\Jimu3.0-android\\课程\\currentXml.xml")));
|
||||
System.out.println("-------华丽的分割线-----------");
|
||||
}
|
||||
|
||||
private void traverse(Node node) {
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
if (node.hasChildNodes()) {
|
||||
NodeList childNodes = node.getChildNodes();
|
||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||
Node item = childNodes.item(i);
|
||||
if (item.hasChildNodes()) {
|
||||
System.out.println(item.getNodeName());
|
||||
NamedNodeMap attributes = item.getAttributes();
|
||||
if (attributes != null) {
|
||||
for (int i2 = 0; i2 < attributes.getLength(); i2++) {
|
||||
Node item2 = attributes.item(i2);
|
||||
System.out.println("属性:" + item2.getNodeName() + ":" + item2.getNodeValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
traverse(item);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (node.getNodeType() == 3) {
|
||||
System.out.println("文本节点:" + node.getNodeName() + ":" + node.getNodeValue());
|
||||
return;
|
||||
}
|
||||
if (node.getNodeValue() != null && !"".equals(node.getNodeValue().trim())) {
|
||||
System.out.println("非文本节点:" + node.getNodeName() + ":" + node.getNodeValue());
|
||||
}
|
||||
NamedNodeMap attributes2 = node.getAttributes();
|
||||
if (attributes2 != null) {
|
||||
for (int i3 = 0; i3 < attributes2.getLength(); i3++) {
|
||||
Node item3 = attributes2.item(i3);
|
||||
System.out.println("属性:" + item3.getNodeName() + ":" + item3.getNodeValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String check(File file, File file2) {
|
||||
try {
|
||||
Document a = XmlHelper.a(file);
|
||||
Document a2 = XmlHelper.a(file2);
|
||||
Element documentElement = a.getDocumentElement();
|
||||
Element documentElement2 = a2.getDocumentElement();
|
||||
removeWhiteSpaceTextElement(documentElement);
|
||||
removeWhiteSpaceTextElement(documentElement2);
|
||||
return checkProgramDocument(documentElement, documentElement2);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "-1";
|
||||
}
|
||||
}
|
||||
|
||||
public int removeWhiteSpaceTextElement(Node node) {
|
||||
int i = 0;
|
||||
if (node == null) {
|
||||
return 0;
|
||||
}
|
||||
if (node.getNodeType() == 1) {
|
||||
Node firstChild = node.getFirstChild();
|
||||
while (firstChild != null) {
|
||||
Node nextSibling = firstChild.getNextSibling();
|
||||
i += removeWhiteSpaceTextElement(firstChild);
|
||||
firstChild = nextSibling;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
if (node.getNodeType() != 3) {
|
||||
return 0;
|
||||
}
|
||||
Text text = (Text) node;
|
||||
if (!text.getData().trim().isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
text.getParentNode().removeChild(text);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* JADX ERROR: Types fix failed
|
||||
jadx.core.utils.exceptions.JadxOverflowException: Type inference error: updates count limit reached
|
||||
at jadx.core.utils.ErrorsCounter.addError(ErrorsCounter.java:59)
|
||||
at jadx.core.utils.ErrorsCounter.error(ErrorsCounter.java:31)
|
||||
at jadx.core.dex.attributes.nodes.NotificationAttrNode.addError(NotificationAttrNode.java:19)
|
||||
at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:96)
|
||||
*/
|
||||
public java.lang.String check(java.lang.String r8, java.lang.String r9) {
|
||||
/*
|
||||
r7 = this;
|
||||
java.lang.String r0 = "-1"
|
||||
org.w3c.dom.Document r8 = com.ubtech.utils.XmlHelper.a(r8) // Catch: java.lang.Exception -> L61
|
||||
org.w3c.dom.Document r9 = com.ubtech.utils.XmlHelper.a(r9) // Catch: java.lang.Exception -> L61
|
||||
org.w3c.dom.Element r8 = r8.getDocumentElement() // Catch: java.lang.Exception -> L61
|
||||
org.w3c.dom.Element r9 = r9.getDocumentElement() // Catch: java.lang.Exception -> L61
|
||||
r7.removeWhiteSpaceTextElement(r8) // Catch: java.lang.Exception -> L61
|
||||
r7.removeWhiteSpaceTextElement(r9) // Catch: java.lang.Exception -> L61
|
||||
org.w3c.dom.NodeList r1 = r8.getChildNodes() // Catch: java.lang.Exception -> L61
|
||||
org.w3c.dom.NodeList r2 = r9.getChildNodes() // Catch: java.lang.Exception -> L61
|
||||
int r3 = r1.getLength() // Catch: java.lang.Exception -> L61
|
||||
r4 = 1
|
||||
if (r3 != r4) goto L2c
|
||||
java.lang.String r8 = r7.checkProgramDocument(r8, r9) // Catch: java.lang.Exception -> L61
|
||||
goto L66
|
||||
L2c:
|
||||
r8 = 0
|
||||
r9 = 0
|
||||
L2e:
|
||||
int r3 = r1.getLength() // Catch: java.lang.Exception -> L61
|
||||
if (r9 >= r3) goto L65
|
||||
org.w3c.dom.Node r3 = r1.item(r9) // Catch: java.lang.Exception -> L61
|
||||
r5 = r0
|
||||
r0 = 0
|
||||
L3a:
|
||||
int r6 = r2.getLength() // Catch: java.lang.Exception -> L5e
|
||||
if (r0 >= r6) goto L55
|
||||
org.w3c.dom.Node r6 = r2.item(r0) // Catch: java.lang.Exception -> L5e
|
||||
java.lang.String r5 = r7.checkProgramDocument(r3, r6) // Catch: java.lang.Exception -> L5e
|
||||
java.lang.String r6 = "0"
|
||||
boolean r6 = r6.equals(r5) // Catch: java.lang.Exception -> L5e
|
||||
if (r6 == 0) goto L52
|
||||
r0 = 1
|
||||
goto L56
|
||||
L52:
|
||||
int r0 = r0 + 1
|
||||
goto L3a
|
||||
L55:
|
||||
r0 = 0
|
||||
L56:
|
||||
if (r0 == 0) goto L5c
|
||||
int r9 = r9 + 1
|
||||
r0 = r5
|
||||
goto L2e
|
||||
L5c:
|
||||
r8 = r5
|
||||
goto L66
|
||||
L5e:
|
||||
r8 = move-exception
|
||||
r0 = r5
|
||||
goto L62
|
||||
L61:
|
||||
r8 = move-exception
|
||||
L62:
|
||||
r8.printStackTrace()
|
||||
L65:
|
||||
r8 = r0
|
||||
L66:
|
||||
return r8
|
||||
*/
|
||||
throw new UnsupportedOperationException("Method not decompiled: com.ubt.jimu.blockly.feature.course.BlocklyDomCompare.check(java.lang.String, java.lang.String):java.lang.String");
|
||||
}
|
||||
}
|
25
sources/com/ubt/jimu/blockly/feature/course/Rule.java
Normal file
25
sources/com/ubt/jimu/blockly/feature/course/Rule.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.ubt.jimu.blockly.feature.course;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class Rule {
|
||||
private String id;
|
||||
private List<String> name;
|
||||
|
||||
public Rule() {
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public List<String> getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Rule(String str, List<String> list) {
|
||||
this.id = str;
|
||||
this.name = list;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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();
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
323
sources/com/ubt/jimu/blockly/feature/sensor/SensorObserver.java
Normal file
323
sources/com/ubt/jimu/blockly/feature/sensor/SensorObserver.java
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user