jimu-decompiled/sources/com/ubt/jimu/unity/bluetooth/UnityActivity.java
2025-05-13 19:24:51 +02:00

1704 lines
68 KiB
Java

package com.ubt.jimu.unity.bluetooth;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.DialogFragment;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import com.google.gson.reflect.TypeToken;
import com.liulishuo.filedownloader.model.FileDownloadModel;
import com.ubt.jimu.JimuApplication;
import com.ubt.jimu.R;
import com.ubt.jimu.base.UbtActivityStack;
import com.ubt.jimu.base.cache.Cache;
import com.ubt.jimu.base.cache.SharePreferenceHelper;
import com.ubt.jimu.base.db.diy.DiyDBModel;
import com.ubt.jimu.base.db.diy.DiyHelper;
import com.ubt.jimu.base.db.diy.DiyStep2Helper;
import com.ubt.jimu.base.db.diy.DiyStep2Model;
import com.ubt.jimu.base.db.robot.FirmwareVersionDbHandler;
import com.ubt.jimu.base.dialog.WaitDialogSupport;
import com.ubt.jimu.base.entities.Constant;
import com.ubt.jimu.base.entities.Course;
import com.ubt.jimu.base.entities.FirmwareVersion;
import com.ubt.jimu.base.entities.Robot;
import com.ubt.jimu.base.entities.RobotLite;
import com.ubt.jimu.base.entities.User;
import com.ubt.jimu.base.home.HomeWatcherReceiver;
import com.ubt.jimu.base.networkstate.NetworkStateObserver;
import com.ubt.jimu.base.networkstate.NetworkType;
import com.ubt.jimu.blockly.Utils;
import com.ubt.jimu.blockly.bean.BlocklyProject;
import com.ubt.jimu.blockly.command.UnityCommandController;
import com.ubt.jimu.blockly.dao.BlocklyProjectDbHandler;
import com.ubt.jimu.blockly.exception.JimuRobotMessage;
import com.ubt.jimu.blockly.view.HelpFragmentCompact;
import com.ubt.jimu.course.repository.JimuCourseMission;
import com.ubt.jimu.diy.DiyRobotDbHandler;
import com.ubt.jimu.diy.model.DiyDetailsModel;
import com.ubt.jimu.diy.model.FinalModel;
import com.ubt.jimu.diy.view.DiyFanActivity;
import com.ubt.jimu.diy.view.popupwindow.ExchangeDialog;
import com.ubt.jimu.transport.model.TransportFile;
import com.ubt.jimu.transport3.UnityFileOperator;
import com.ubt.jimu.transport3.dao.DiyDBModelDBHandler;
import com.ubt.jimu.unity.ModelType;
import com.ubt.jimu.unity.UnityEvent;
import com.ubt.jimu.unity.bluetooth.UnityActivity;
import com.ubt.jimu.utils.DeviceUtils;
import com.ubt.jimu.utils.GsonUtil;
import com.ubt.jimu.utils.JsonHelper;
import com.ubt.jimu.utils.LocaleUtils;
import com.ubt.jimu.utils.LogUtils;
import com.ubt.jimu.utils.SPUtils;
import com.ubt.jimu.utils.UiUtils;
import com.ubt.jimu.widgets.choosePhotos.AlbumActivity;
import com.ubt.jimu.widgets.choosePhotos.media.HPMedia;
import com.ubt.unity.UnityPlayerNativeActivity;
import com.ubtech.permission.JimuPermissionRequest;
import com.ubtech.permission.PermissionRationalListener;
import com.ubtech.permission.PermissionRequestListener;
import com.ubtech.utils.StringUtils;
import com.ubtech.utils.ThreadExecutor;
import com.ubtech.utils.XLog;
import com.ubtech.view.widget.ToastView;
import com.ubtrobot.jimu.bluetooth.ConnectionState;
import com.ubtrobot.jimu.bluetooth.ConnectionStateListener;
import com.ubtrobot.jimu.bluetooth.DataReceiveListener;
import com.ubtrobot.jimu.bluetooth.JimuBluetoothManager;
import com.ubtrobot.jimu.robotapi.JimuManager;
import com.ubtrobot.log.ALog;
import com.ubtrobot.ubtlib.analytics.IAnalytics;
import com.ubtrobot.ubtlib.analytics.JimuAnalytics;
import com.unity3d.player.UnityPlayer;
import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONException;
import org.json.JSONObject;
@SuppressLint({"HandlerLeak"})
/* loaded from: classes2.dex */
public class UnityActivity extends UnityPlayerNativeActivity implements View.OnLayoutChangeListener, NetworkStateObserver {
public static final String BLOCKLY_HELP = "blocklyHelp";
public static final int BLOCKLY_TYPE_COURSE = 8194;
public static final int BLOCKLY_TYPE_DIY = 8195;
public static final int BLOCKLY_TYPE_DIY_PREVIEW = 8196;
public static final int BLOCKLY_TYPE_MAIN = 8193;
public static final int BLOCKLY_TYPE_NONE = 8192;
public static final int BLOCKLY_TYPE_STAR_TREK = 8197;
public static final int CODE_ACTION = 1002;
public static final int CODE_AR_GAME = 1016;
public static final int CODE_BROWSE_PROGRAM = 1007;
public static final int CODE_CLOSE_CONNECT_PAGE = 7;
public static final int CODE_COURSE = 1001;
public static final int CODE_ENGINE = 1006;
public static final int CODE_FROM_CONNECT_FAIL_PAGE = 8;
public static final int CODE_MODEL = -1;
public static final int CODE_MODULE = 2;
public static final int CODE_PREVIEW = 1005;
public static final int CODE_PROGRAM = 1004;
public static final int CODE_SERVO_ID = 1;
public static final int CONNECTION_STATE_RESULT_CONNECTED = 1;
public static final int CONNECTION_STATE_RESULT_DISCONNECTED = 0;
public static final String CONNECT_BLE_CALLBACK = "ConnectBLECallBack";
public static final int CallUnityFunc = 11;
public static final int ChangeModelName = 9;
public static final int ConnenctSpeakerCallBack = 13;
public static final int DIY_OFFICAL = 0;
public static final int DIY_SELF = 1;
public static final int DeleteModel = 10;
public static final int DownLoadModel = 8;
public static final int FinishUnityActivity = 12;
public static final int Goto_Unity = 7;
public static final String KEY_ACTION_ID = "actionId";
private static final String MODEL_SERVERID_KEY = "modelServerId";
public static final int MODULE_TYPE_ACTION = 5;
public static final int MODULE_TYPE_AR_GAME_FLOWER_WORLD = 17;
public static final int MODULE_TYPE_AR_GAME_RAINBOW_WORLD = 16;
public static final int MODULE_TYPE_BLOCKLY = 3;
public static final int MODULE_TYPE_BUILD = 2;
public static final int MODULE_TYPE_CLOSE_CONNECT_PAGE = 7;
public static final int MODULE_TYPE_CONTROL = 4;
public static final int MODULE_TYPE_COURSE_BLOCKLY = 1;
public static final int MODULE_TYPE_COURSE_BUILD = 0;
public static final int MODULE_TYPE_DEFAULT = -1;
public static final int MODULE_TYPE_FROM_CONNECT_FAIL_PAGE = 8;
public static final int OnDisConnenct = 3;
public static final int OnMsgAck = 1;
public static final int PhotographBack = 6;
public static final int REQUEST_EXCHANGE = 106;
public static final int REQUEST_IMAGE = 105;
public static final int REQUEST_RECORD_AUDIO_PERMISSION = 19;
public static final int REQUEST_SET_SERVO_MODE = 107;
public static final String RESULT = "result";
public static final int RequestCameraPermissionCallBack = 16;
public static final int SRC_MINI = 1;
public static final int SRC_NON = 0;
private static final String TAG = "UnityActivity";
public static final int TimerForUnity = 5;
public static final String UNITY_ACTIVITY_RUNNING = "UnityActivityRunning";
public static final int WORLD_FROM_CODE = 3;
public static final int WORLD_FROM_CONTROL = 8;
public static final int WORLD_FROM_COURSE = 7;
public static final int WORLD_FROM_CUSTOME = 0;
public static final int WORLD_FROM_FACTORY = 1;
public static final int WORLD_FROM_FEEDBACK = 9;
public static final int WORLD_FROM_TEST = 2;
private static StaticHandler handler = null;
private static String mAckGameObjectName = "MainClient";
public static DiyDetailsModel modelBrowse = null;
public static final String modelId = "modelID";
public static final String pEdit = "edit";
public static final String pModelName = "modelName";
public static final String pModelType = "modelType";
public static final String ppicpath = "picPath";
private Course course;
private int currentStep;
private DialogFragment dialogWait;
private boolean edit;
private int from;
private HelpFragmentCompact helpFragment;
private String mActionId;
private JimuBluetoothManager mBluetoothManager;
private ExchangeDialog mExchangeDialog;
private HomeWatcherReceiver mHomeWatcherReceiver;
private Intent mIntent;
private JimuManager mJimuManager;
private String m_connenctDevice;
private DiyDBModel model;
private String modelID;
private String modelName;
private long modelServerId;
private int modelType;
private BroadcastReceiverMgr phonecallBroadcastReceiver;
private String picPath;
private MyUnityListener sUnityListener;
private int totalStep;
private UnityCommandController unityCallback;
public boolean resumeUnityActivity = false;
public int size = 0;
public int code = -1;
private int moduleType = -1;
private int blocklyType = BLOCKLY_TYPE_NONE;
private boolean connectBLE = false;
private boolean disConnectBLE = false;
private boolean m_haveBluetooth = false;
private boolean isBack = true;
private boolean isForeground = false;
private DataReceiveListener mDataReceiveListener = new DataReceiveListener() { // from class: com.ubt.jimu.unity.bluetooth.UnityActivity.1
@Override // com.ubtrobot.jimu.bluetooth.DataReceiveListener
public void onDataAvailable(String str, byte b, byte[] bArr) {
XLog.c("B-onReceiveData", "mac= " + str + " cmd= " + ((int) b) + " param=" + Arrays.toString(bArr));
if (b != 3) {
byte[] bArr2 = {(byte) bArr.length, b};
byte[] bytes = str.getBytes();
byte[] bArr3 = new byte[bArr.length + 3 + bytes.length];
bArr3[0] = (byte) bytes.length;
System.arraycopy(bytes, 0, bArr3, 1, bytes.length);
System.arraycopy(bArr2, 0, bArr3, bytes.length + 1, 2);
System.arraycopy(bArr, 0, bArr3, bytes.length + 3, bArr.length);
UnityActivity.handler.sendMessage(UnityActivity.handler.obtainMessage(1, new String(Base64.encode(bArr3, 0))));
}
}
public void onReceiveDataException(String str, Exception exc) {
}
public void onStopReceiveData() {
}
};
private ConnectionStateListener mConnectionStateListener = new AnonymousClass2();
private final String FIRMWARE_UPDATE = "hardwareProgramVersion";
private final String CLEAR_FIRMWARE_UPDATE = "clearHardwareProgramVersion";
private Runnable mDelayHideWaitDialog = new Runnable() { // from class: com.ubt.jimu.unity.bluetooth.c
@Override // java.lang.Runnable
public final void run() {
UnityActivity.this.b();
}
};
private final String USER_ID = "userId";
private final String LANGUAGE = "language";
private final String PROGRAM = TransportFile.TYPE_PROGRAM;
private final String DIY_STEP = "diyStepData";
private final String GUIDE_STATE = "guideState";
private boolean connectFromCourse = false;
private IAnalytics mAnalytics = JimuAnalytics.b();
/* renamed from: com.ubt.jimu.unity.bluetooth.UnityActivity$2 */
class AnonymousClass2 implements ConnectionStateListener {
AnonymousClass2() {
}
public /* synthetic */ void a(ConnectionState connectionState, String str) {
UnityActivity unityActivity = UnityActivity.this;
unityActivity.notifyBluetoothState(connectionState, str, unityActivity.modelID, UnityActivity.this.modelName, String.valueOf(UnityActivity.this.modelType));
}
public /* synthetic */ void b(ConnectionState connectionState, String str) {
UnityActivity unityActivity = UnityActivity.this;
unityActivity.notifyBluetoothState(connectionState, str, unityActivity.modelID, UnityActivity.this.modelName, String.valueOf(UnityActivity.this.modelType));
}
@Override // com.ubtrobot.jimu.bluetooth.ConnectionStateListener
public void onConnectionStateChange(final String str, final ConnectionState connectionState) {
if (connectionState == ConnectionState.STATE_DISCONNECTED) {
XLog.a(UnityActivity.TAG, "onConnectionChange STATE_DISCONNECTED");
UnityActivity.handler.sendMessage(UnityActivity.handler.obtainMessage(3, str));
UnityActivity.this.m_connenctDevice = null;
UnityActivity.handler.post(new Runnable() { // from class: com.ubt.jimu.unity.bluetooth.b
@Override // java.lang.Runnable
public final void run() {
UnityActivity.AnonymousClass2.this.a(connectionState, str);
}
});
return;
}
if (connectionState == ConnectionState.STATE_CONNECTED) {
XLog.a(UnityActivity.TAG, "onConnectionChange STATE_CONNECTED");
UnityActivity.this.m_connenctDevice = str;
UnityActivity.handler.post(new Runnable() { // from class: com.ubt.jimu.unity.bluetooth.a
@Override // java.lang.Runnable
public final void run() {
UnityActivity.AnonymousClass2.this.b(connectionState, str);
}
});
}
}
}
private class BroadcastReceiverMgr extends BroadcastReceiver {
private BroadcastReceiverMgr() {
}
@Override // android.content.BroadcastReceiver
public void onReceive(Context context, Intent intent) {
if ("android.intent.action.PHONE_STATE".equals(intent.getAction())) {
String stringExtra = intent.getStringExtra("incoming_number");
int callState = ((TelephonyManager) context.getSystemService("phone")).getCallState();
if (callState == 0) {
XLog.c(UnityActivity.TAG, "电话挂断=" + stringExtra);
return;
}
if (callState == 1) {
XLog.c(UnityActivity.TAG, "等待接电话=" + stringExtra);
UnityActivity.this.unityCallback.stopBlockly();
return;
}
if (callState != 2) {
return;
}
XLog.c(UnityActivity.TAG, "通话中=" + stringExtra);
}
}
}
public interface IWaitDialogListener {
void onDismiss();
}
private static class StaticHandler extends Handler {
private WeakReference<UnityActivity> reference;
public StaticHandler(UnityActivity unityActivity) {
this.reference = new WeakReference<>(unityActivity);
}
public WeakReference<UnityActivity> getReference() {
return this.reference;
}
@Override // android.os.Handler
public void handleMessage(Message message) {
UnityActivity unityActivity;
super.handleMessage(message);
if (message == null || getReference() == null || (unityActivity = getReference().get()) == null) {
return;
}
if (Looper.getMainLooper() == Looper.myLooper()) {
Log.i(UnityActivity.TAG, "unity send message handler run in main thread. msg.what:" + message.what);
} else {
Log.i(UnityActivity.TAG, "unity send message handler run not in main thread. msg.what:" + message.what);
}
int i = message.what;
if (i == 1) {
UnityPlayer.UnitySendMessage(UnityActivity.mAckGameObjectName, "OnMsgAck", message.obj.toString());
return;
}
if (i == 3) {
if (message.obj == null) {
XLog.b(UnityActivity.TAG, "OnDisConnenct");
return;
} else if (unityActivity.isForeground()) {
UnityPlayer.UnitySendMessage(UnityActivity.mAckGameObjectName, "OnDisConnenct", message.obj.toString());
return;
} else {
ALog.a(UnityActivity.TAG).d("Not in foreground, do not notify bluetooth disconnect to unity");
return;
}
}
if (i == 16) {
UnityActivity.CallUnityFunc("onCallbackCameraPermissionRequestResult", message.obj);
return;
}
switch (i) {
case 5:
UnityPlayer.UnitySendMessage(UnityActivity.mAckGameObjectName, "TimerForUnity", message.obj.toString());
break;
case 6:
UnityPlayer.UnitySendMessage(UnityActivity.mAckGameObjectName, "PhotographBack", message.obj.toString());
break;
case 7:
UnityPlayer.UnitySendMessage(UnityActivity.mAckGameObjectName, "GotoScene", message.obj.toString());
break;
case 8:
UnityPlayer.UnitySendMessage(UnityActivity.mAckGameObjectName, "DownloadModel", message.obj.toString());
break;
case 10:
UnityPlayer.UnitySendMessage(UnityActivity.mAckGameObjectName, "DeleteModel", message.obj.toString());
break;
case 11:
XLog.c(UnityActivity.TAG, "CallUnityFunc 390:" + message.obj.toString());
break;
case 12:
unityActivity.finish();
break;
case 13:
UnityPlayer.UnitySendMessage(UnityActivity.mAckGameObjectName, "ConnenctSpeakerCallBack", message.obj.toString());
break;
}
}
}
public static void CallUnityFunc(String str, Object obj) {
HashMap hashMap = new HashMap();
hashMap.put("funcName", str);
hashMap.put("arg", obj);
String a = JsonHelper.a(hashMap);
XLog.c(TAG, str + a);
UnityPlayer.UnitySendMessage(mAckGameObjectName, "CallUnityFunc", a);
}
private void backgroundPic() {
this.model = DiyHelper.getInstance().queryForUUid(DiyFanActivity.uuid);
DiyStep2Model queryForUUid = DiyStep2Helper.getInstance().queryForUUid(DiyFanActivity.uuid);
DiyDBModel diyDBModel = this.model;
if (diyDBModel == null) {
this.picPath = "";
} else if (!StringUtils.e(diyDBModel.getActionPath())) {
this.picPath = this.model.getActionPath();
} else if (queryForUUid != null && !StringUtils.e(queryForUUid.getPicJson())) {
List list = (List) GsonUtil.a(queryForUUid.getPicJson(), new TypeToken<List<FinalModel>>() { // from class: com.ubt.jimu.unity.bluetooth.UnityActivity.3
});
if (StringUtils.e(((FinalModel) list.get(0)).getPicPath())) {
this.picPath = ((FinalModel) list.get(1)).getPicPath();
} else {
this.picPath = ((FinalModel) list.get(0)).getPicPath();
}
} else if (StringUtils.e(this.model.getFilePath())) {
this.picPath = "";
} else {
this.picPath = this.model.getFilePath();
}
PhotographBack(this, this.picPath);
}
private void callAndroidFunc(String str) {
this.unityCallback.blocklyCallUnity(str);
try {
JSONObject jSONObject = new JSONObject(str);
if (BLOCKLY_HELP.equals(jSONObject.has("funcName") ? jSONObject.getString("funcName") : null)) {
LogUtils.c("块介绍页面H5:" + Utils.getBlocklyHelpUrl());
showHelpFragment(Utils.getBlocklyHelpUrl(), getString(R.string.title_blockly_help), R.color.theme_background);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
public static void communityWithUnity(String str) {
EventBus.b().b(new UnityEvent(102, "", str));
}
private ConnectionState getConnectionState() {
String b = this.mBluetoothManager.b();
return !TextUtils.isEmpty(b) ? this.mBluetoothManager.getConnectionState(b) : ConnectionState.STATE_DISCONNECTED;
}
private String getLanguage() {
return LocaleUtils.a();
}
private String getProgram(String str) {
if (TextUtils.isEmpty(str)) {
return "[]";
}
String str2 = "";
try {
JSONObject jSONObject = new JSONObject(str);
List<BlocklyProject> projects = BlocklyProjectDbHandler.getProjects(Cache.getInstance().getUserId(), jSONObject.getString(modelId), jSONObject.getInt(pModelType) + 1);
String language = getLanguage();
for (BlocklyProject blocklyProject : projects) {
if (blocklyProject.xmlNameLang != null) {
try {
blocklyProject.setXmlName(blocklyProject.xmlNameLang.get(language));
} catch (Exception e) {
e.printStackTrace();
}
}
}
str2 = JsonHelper.a(projects);
XLog.a(TAG, str2);
return str2;
} catch (JSONException e2) {
e2.printStackTrace();
return str2;
}
}
private String getUserId() {
User user = Cache.getInstance().getUser();
if (user == null) {
return "local";
}
return user.getUserId() + "";
}
private void goToEngine() {
HashMap hashMap = new HashMap();
hashMap.put(modelId, this.modelID);
hashMap.put(pModelName, this.modelName);
CallUnityFunc("diyServoSetting", hashMap);
}
private void gotoCourseList() {
gotoModule(this.modelID, this.modelName, this.modelType, this.moduleType, -1L);
}
private void gotoDiyAction() {
gotoScene(getIntent().getStringExtra(modelId), getIntent().getStringExtra(pModelName), getIntent().getStringExtra(ppicpath), getIntent().getBooleanExtra(pEdit, false), this.modelType);
}
public static void gotoFlowerWorldGamePage(Activity activity, Robot robot) {
startUnityActivity(activity, robot, CODE_AR_GAME, 17, 0, 0, false, 0);
}
private void gotoModule(String str, String str2, int i, int i2, long j) {
gotoModule(str, str2, i, i2, j, 0, null);
}
public static void gotoRainbowWorldGamePage(Activity activity, Robot robot) {
startUnityActivity(activity, robot, CODE_AR_GAME, 16, 0, 0, false, 0);
}
private void gotoScene(String str, String str2, String str3, boolean z, int i) {
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put(modelId, str);
jSONObject.put(pModelName, str2);
jSONObject.put(ppicpath, str3);
jSONObject.put(pEdit, z);
jSONObject.put(pModelType, i);
} catch (JSONException e) {
e.printStackTrace();
}
UnityPlayer.UnitySendMessage(mAckGameObjectName, "GotoScene", jSONObject.toString());
}
private boolean initBluetooth() {
XLog.a(TAG, "initBluetooth");
this.m_haveBluetooth = this.mBluetoothManager.supportsBluetooth(this);
return this.m_haveBluetooth;
}
private void initData(Intent intent) {
if (intent.getIntExtra(Course.TYPE_BLOCKLY, -1) == 7) {
XLog.a(TAG, " close connect page");
XLog.c(TAG, "set isBack to false");
this.isBack = false;
notifyBluetoothState(this.modelID, this.modelName, String.valueOf(this.modelType));
return;
}
this.modelID = intent.getStringExtra(modelId);
this.modelServerId = intent.getLongExtra(MODEL_SERVERID_KEY, -1L);
this.modelName = intent.getStringExtra(pModelName);
this.code = intent.getIntExtra(Course.TYPE_BLOCKLY, -1);
this.modelType = intent.getIntExtra(pModelType, 0);
this.moduleType = intent.getIntExtra("moduleType", -1);
this.course = (Course) intent.getSerializableExtra("course");
this.picPath = intent.getStringExtra(ppicpath);
this.currentStep = intent.getIntExtra("current", 0);
this.totalStep = intent.getIntExtra(FileDownloadModel.TOTAL, 0);
this.edit = intent.getBooleanExtra(pEdit, true);
this.blocklyType = intent.getIntExtra("blocklyType", BLOCKLY_TYPE_NONE);
this.size = intent.getIntExtra(FileDownloadModel.TOTAL, 0);
this.from = intent.getIntExtra(MyUnityListener.CALLER, 0);
String stringExtra = intent.getStringExtra(MyUnityListener.CALLBACK);
this.mActionId = intent.getStringExtra(KEY_ACTION_ID);
this.sUnityListener = new MyUnityListener(this.modelName, this.modelID);
this.unityCallback.setServerModelId(this.modelServerId);
this.unityCallback.setModuleType(this.moduleType);
this.unityCallback.setCourse(this.course);
this.unityCallback.setCode(this.code);
initUnity();
if (this.mJimuManager.g() && this.modelID != null) {
if (!this.modelID.equals(this.mJimuManager.e())) {
XLog.c(TAG, "Connected robot is not select model, disconnect");
this.mJimuManager.c();
}
}
notifyBluetoothState(this.modelID, this.modelName, String.valueOf(this.modelType));
int i = this.code;
if (i == -1) {
gotoScene(this.modelID, this.modelName, this.picPath, this.modelType, true);
new DiyActionDownloader(this, Cache.getInstance().getUserId(), this.modelServerId, this.modelID, this.modelName, this.modelType).downloadAction();
DiyActionDownloader.reloadServos(this, this.modelID, this.modelName, this.modelType);
return;
}
if (i == 1) {
setupSteeringEngineId();
return;
}
if (i == 2) {
Course course = this.course;
gotoModule(this.modelID, this.modelName, this.modelType, this.moduleType, course == null ? -1L : course.getId(), this.from, stringExtra);
return;
}
if (i == 1001) {
gotoCourseList();
return;
}
if (i == 1002) {
this.isBack = false;
backgroundPic();
gotoDiyAction();
PhotographBack(this, this.picPath);
new DiyActionDownloader(this, Cache.getInstance().getUserId(), this.modelServerId, this.modelID, this.modelName, this.modelType).downloadAction();
DiyActionDownloader.reloadServos(this, this.modelID, this.modelName, this.modelType);
return;
}
if (i == 1004) {
backgroundPic();
gotoModule(getIntent().getStringExtra(modelId), getIntent().getStringExtra(pModelName), this.modelType, 3, -1L);
PhotographBack(this, this.picPath);
return;
}
if (i == 1005) {
closeBlockly();
gotoScene(this.modelID, this.modelName, this.picPath, this.modelType, false);
return;
}
if (i == 1006) {
backgroundPic();
PhotographBack(this, this.picPath);
goToEngine();
DiyActionDownloader.reloadServos(this, this.modelID, this.modelName, this.modelType);
return;
}
if (i == 1007) {
backgroundPic();
gotoModule(getIntent().getStringExtra(modelId), getIntent().getStringExtra(pModelName), 1, 3, -1L);
PhotographBack(this, this.picPath);
} else if (i == 1016) {
gotoModule(this.modelID, this.modelName, 0, this.moduleType, -1L);
}
}
private void initUnity() {
int i = 1;
boolean booleanValue = Cache.getInstance().getSettings().getBoolean(SharePreferenceHelper.SP_KEY_ELECTRICITY_PROTECT, true).booleanValue();
boolean booleanValue2 = Cache.getInstance().getSettings().getBoolean(SharePreferenceHelper.SP_KEY_AUTO_CONNECT, true).booleanValue();
try {
CallUnityFunc("ChargeProtection", Integer.valueOf(booleanValue ? 1 : 0));
if (!booleanValue2) {
i = 0;
}
CallUnityFunc("autoConnect", Integer.valueOf(i));
CallUnityFunc("skipGuide", "");
} catch (Exception e) {
e.printStackTrace();
}
sensorUpdate();
}
/* JADX INFO: Access modifiers changed from: private */
public boolean isForeground() {
return this.isForeground;
}
private void notifyBluetoothState(String str, String str2, String str3) {
XLog.a(TAG, "CallUnityFunc notifyBluetoothState");
String b = this.mBluetoothManager.b();
ConnectionState connectionState = ConnectionState.STATE_DISCONNECTED;
if (!TextUtils.isEmpty(b)) {
connectionState = this.mBluetoothManager.getConnectionState(b);
}
notifyBluetoothState(connectionState, b, str, str2, str3);
}
private void onRequestImage(final int i, int i2, Intent intent) {
List list;
if (i2 != -1 || (list = (List) intent.getSerializableExtra("result_data")) == null || list.size() == 0) {
return;
}
final HPMedia hPMedia = (HPMedia) list.get(0);
if (i2 == -1) {
ThreadExecutor.a().a(new Runnable() { // from class: com.ubt.jimu.unity.bluetooth.UnityActivity.7
@Override // java.lang.Runnable
public void run() {
String logPath = DiyRobotDbHandler.getLogPath(ModelType.PLAYER_DATA, UnityActivity.this.model.getCustomModelId());
if (DiyDBModelDBHandler.saveModelLogoFile(JimuApplication.l(), UnityActivity.this.model.getCustomModelId(), hPMedia.getPath())) {
new UnityFileOperator((int) UnityActivity.this.modelServerId, UnityActivity.this.modelID, UnityActivity.this.modelType, logPath, 2).operateFile();
if (i == 106) {
UnityActivity.this.picPath = logPath;
UnityActivity.this.model.setActionPath(UnityActivity.this.picPath);
DiyHelper.getInstance().insertData(UnityActivity.this.model);
UnityActivity unityActivity = UnityActivity.this;
unityActivity.PhotographBack(unityActivity, unityActivity.picPath);
}
UnityActivity unityActivity2 = UnityActivity.this;
unityActivity2.PhotographBack(unityActivity2, unityActivity2.picPath);
}
}
});
} else {
PhotographBack(this, "");
}
}
private ConnectionStatus parseJson(String str) {
ConnectionStatus connectionStatus = ConnectionStatus.DIS_CONNECT;
if (!TextUtils.isDigitsOnly(str)) {
return ConnectionStatus.DIS_CONNECT;
}
int parseInt = Integer.parseInt(str);
for (ConnectionStatus connectionStatus2 : ConnectionStatus.values()) {
if (connectionStatus2.getStatus() == parseInt) {
return connectionStatus2;
}
}
return connectionStatus;
}
private void register() {
this.mHomeWatcherReceiver = new HomeWatcherReceiver();
registerReceiver(this.mHomeWatcherReceiver, new IntentFilter("android.intent.action.CLOSE_SYSTEM_DIALOGS"));
}
private void registerPhonecalBroadcastReceiver() {
if (this.phonecallBroadcastReceiver == null) {
this.phonecallBroadcastReceiver = new BroadcastReceiverMgr();
}
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.intent.action.PHONE_STATE");
intentFilter.setPriority(Integer.MAX_VALUE);
registerReceiver(this.phonecallBroadcastReceiver, intentFilter);
}
private void sensorUpdate() {
List<FirmwareVersion> selectAll = FirmwareVersionDbHandler.getInstance().selectAll();
if (selectAll == null || selectAll.size() == 0) {
return;
}
ArrayList arrayList = new ArrayList();
for (FirmwareVersion firmwareVersion : selectAll) {
firmwareVersion.setVersionPath(FirmwareVersion.getPath(this, firmwareVersion));
arrayList.add(firmwareVersion);
}
CallUnityFunc("hardwareProgramVersion", arrayList);
}
private void setRobot() {
if (this.modelType == 1) {
Robot robot = new Robot();
robot.setModelId(this.modelServerId);
robot.setModelName(this.modelName);
robot.setModelType(this.modelType + "");
Cache.getInstance().setRobot(robot);
}
}
private void setupSteeringEngineId() {
XLog.c(TAG, "修改舵机ID");
showWaitDialog();
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("funcName", "UnitySetupSteeringEngineID");
jSONObject.put("arg", "");
} catch (JSONException e) {
e.printStackTrace();
}
UnityPlayer.UnitySendMessage(mAckGameObjectName, "CallUnityFunc", jSONObject.toString());
}
public static void start(Context context) {
context.startActivity(new Intent(context, (Class<?>) UnityActivity.class));
}
public static void startActionUnity(Activity activity, RobotLite robotLite, int i, int i2, String str) {
if (robotLite != null) {
Intent intent = new Intent(activity, (Class<?>) UnityActivity.class);
intent.putExtra(modelId, robotLite.getModelId());
intent.putExtra(MODEL_SERVERID_KEY, robotLite.getServeId());
intent.putExtra(pModelName, robotLite.getModelName());
intent.putExtra(ppicpath, robotLite.getPicPath());
intent.putExtra(pModelType, !robotLite.isOfficial() ? 1 : 0);
intent.putExtra(Course.TYPE_BLOCKLY, i);
intent.putExtra("moduleType", i2);
intent.putExtra(pEdit, true);
intent.putExtra(KEY_ACTION_ID, str);
activity.startActivity(intent);
}
}
public static void startRunningUnityActivity(Context context) {
Intent intent = new Intent(context, (Class<?>) UnityActivity.class);
intent.addFlags(268435456);
intent.putExtra(UNITY_ACTIVITY_RUNNING, true);
context.startActivity(intent);
}
public static void startUnityActivity(Activity activity, Robot robot, int i, int i2, String str) {
if (i != 0) {
if (i == 1) {
startUnityActivity(activity, robot, 2, 2, BLOCKLY_TYPE_NONE, i2, str);
return;
}
if (i == 2) {
startUnityActivity(activity, robot, -1, -1, BLOCKLY_TYPE_NONE);
return;
}
if (i == 3) {
startUnityActivity(activity, robot, 2, 3, BLOCKLY_TYPE_MAIN);
} else {
if (i == 7 || i != 8) {
return;
}
startUnityActivity(activity, robot, 2, 4, BLOCKLY_TYPE_NONE);
}
}
}
private void unregisterPhonecallBroadcastReceiver() {
try {
if (this.phonecallBroadcastReceiver != null) {
unregisterReceiver(this.phonecallBroadcastReceiver);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void ActivationRobot(String str, String str2) {
MyUnityListener myUnityListener = this.sUnityListener;
if (myUnityListener != null) {
myUnityListener.ActivationRobot(this, str, str2);
}
}
public void ActivityFinish() {
XLog.a(TAG, "ActivityFinish");
MyUnityListener myUnityListener = this.sUnityListener;
if (myUnityListener != null) {
if (this.connectFromCourse) {
this.connectFromCourse = false;
} else {
myUnityListener.BackThirdApp(this, this.code, this.moduleType);
}
this.isBack = true;
XLog.c(TAG, "set isBack to true");
}
closeBlockly();
}
public void CallPlatformFunc(String str, String str2) {
int i;
XLog.d(TAG, str + ":" + str2, new Object[0]);
if (MyUnityListener.POWER_STATUS_CHANGE.equals(str)) {
this.unityCallback.updateBluetoothState(str2);
new SharePreferenceHelper().put(SharePreferenceHelper.SP_KEY_CONNECTION_STATUS, Integer.valueOf(parseJson(str2).getStatus()));
}
if (this.connectBLE && ("ConnectBLECallBack".equals(str) || MyUnityListener.DISCONNECT_BLE_CALLBACK.equals(str))) {
this.connectBLE = false;
this.isBack = true;
this.sUnityListener.BackThirdApp(this, this.code, this.moduleType);
return;
}
if (this.connectFromCourse && "ConnectBLECallBack".equals(str)) {
this.connectFromCourse = false;
parseJson(str2);
} else if (MyUnityListener.DISCONNECT_BLE_CALLBACK.equals(str) && (this.code == 1001 || (i = this.moduleType) == 1 || i == 3)) {
this.unityCallback.onUnityCallback(str, str2);
} else {
if (this.sUnityListener.CallPlatformFuncDiy(this, str, str2) || this.sUnityListener.CallPlatformFunc(this, str, str2)) {
return;
}
this.unityCallback.onUnityCallback(str, str2);
}
}
public void DisConnectBuletooth() {
XLog.a(TAG, "DisConnectBuletooth");
}
public void DisConnenct() {
this.mBluetoothManager.disconnect();
this.m_connenctDevice = null;
if (this.disConnectBLE) {
this.isBack = true;
this.disConnectBLE = false;
if (this.connectFromCourse) {
return;
}
this.sUnityListener.BackThirdApp(this, this.code, this.moduleType);
}
}
public void Photograph(String str, String str2) {
if (this.model == null) {
return;
}
if (StringUtils.e(str2)) {
JimuPermissionRequest.c(this, new PermissionRequestListener() { // from class: com.ubt.jimu.unity.bluetooth.UnityActivity.8
@Override // com.ubtech.permission.PermissionRequestListener
public void onDenied() {
}
@Override // com.ubtech.permission.PermissionRequestListener
public void onGranted() {
AlbumActivity.a(UnityActivity.this, 106, 1, null, 1, "UNITERMING_IMAGE");
}
});
} else {
runOnUiThread(new Runnable() { // from class: com.ubt.jimu.unity.bluetooth.UnityActivity.9
@Override // java.lang.Runnable
public void run() {
if (UnityActivity.this.mExchangeDialog == null) {
UnityActivity unityActivity = UnityActivity.this;
unityActivity.mExchangeDialog = new ExchangeDialog(unityActivity);
UnityActivity.this.mExchangeDialog.setInteraction(new ExchangeDialog.DialogInteraction() { // from class: com.ubt.jimu.unity.bluetooth.UnityActivity.9.1
@Override // com.ubt.jimu.diy.view.popupwindow.ExchangeDialog.DialogInteraction
public void onChangeModelLogo() {
UnityActivity.this.isBack = true;
AlbumActivity.a(UnityActivity.this, 106, 1, null, 1, "UNITERMING_IMAGE");
}
});
}
UnityActivity.this.mExchangeDialog.show();
}
});
}
}
public void PhotographBack(Context context, String str) {
handler.sendMessage(handler.obtainMessage(6, str));
}
public void SendMsg(byte b, byte[] bArr, int i) throws UnsupportedEncodingException {
String str = this.m_connenctDevice;
if (str != null) {
this.mBluetoothManager.a(str, b, bArr);
}
}
public void SetSendXTState(int i) {
Log.e(TAG, "Unity shouldn't call SetSendXTState!");
}
public /* synthetic */ void a() {
DialogFragment dialogFragment = this.dialogWait;
if (dialogFragment != null) {
try {
try {
dialogFragment.dismiss();
} catch (Exception e) {
e.printStackTrace();
}
} finally {
this.dialogWait = null;
}
}
}
public /* synthetic */ void b() {
ALog.a(TAG).d("6s timeout, hideWaitDialog");
hideWaitDialog();
}
public /* synthetic */ void c() {
getFragmentManager().beginTransaction().remove(this.helpFragment).commitAllowingStateLoss();
this.unityCallback.showBlockly();
this.helpFragment = null;
ALog.a(TAG).d("back from help fragment");
CallUnityFunc("closeHelpWeb", "");
}
public void closeBlockly() {
this.unityCallback.closeBlockly();
}
public /* synthetic */ void d() {
DialogFragment dialogFragment = this.dialogWait;
if (dialogFragment != null && !dialogFragment.isDetached()) {
this.dialogWait.dismiss();
}
this.dialogWait = WaitDialogSupport.newInstance("");
try {
this.dialogWait.show(getFragmentManager(), "");
} catch (Exception e) {
e.printStackTrace();
}
}
public void finishSelf() {
XLog.a(TAG, "finishSelf");
handler.post(new Runnable() { // from class: com.ubt.jimu.unity.bluetooth.UnityActivity.6
@Override // java.lang.Runnable
public void run() {
try {
if (((UnityPlayerNativeActivity) UnityActivity.this).mUnityPlayer != null) {
((UnityPlayerNativeActivity) UnityActivity.this).mUnityPlayer.quit();
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public int getBlocklyType() {
return this.blocklyType;
}
public int getCode() {
return this.code;
}
public Course getCourse() {
return this.course;
}
public int getCurrentStep() {
return this.currentStep;
}
public String getData(String str, String str2) {
char c;
int hashCode = str.hashCode();
if (hashCode == -926533302) {
if (str.equals("diyStepData")) {
c = 1;
}
c = 65535;
} else if (hashCode != -309387644) {
if (hashCode == 54466293 && str.equals("guideState")) {
c = 2;
}
c = 65535;
} else {
if (str.equals(TransportFile.TYPE_PROGRAM)) {
c = 0;
}
c = 65535;
}
if (c == 0) {
return getProgram(str2);
}
if (c == 1) {
return getDiyStep();
}
if (c != 2) {
return "";
}
SPUtils.a(Constant.NoviceGuide.IS_SKIP_ALL_GUIDE_KEY);
return isSkipGuide(0);
}
public String getDiyStep() {
HashMap hashMap = new HashMap();
hashMap.put("nowStep", Integer.valueOf(this.currentStep));
hashMap.put("totalStep", Integer.valueOf(this.totalStep));
return JsonHelper.a(hashMap);
}
public String getModelID() {
return this.modelID;
}
public String getModelName() {
return this.modelName;
}
public String getModelPath() {
if (ModelType.DEFAULT.getType() - 1 == this.modelType) {
return DiyRobotDbHandler.getDefaultModelPath() + this.modelID;
}
return DiyRobotDbHandler.getCustomModelPath() + this.modelID;
}
public long getModelServerId() {
return this.modelServerId;
}
public int getModelType() {
return this.modelType;
}
public int getModuleType() {
return this.moduleType;
}
public String getPicPath() {
return this.picPath;
}
public int getTotalStep() {
return this.totalStep;
}
public UnityCommandController getUnityCallback() {
return this.unityCallback;
}
public MyUnityListener getUnityListener() {
return this.sUnityListener;
}
public String getUserData(String str) {
if (TextUtils.isEmpty(str)) {
return "null";
}
char c = 65535;
int hashCode = str.hashCode();
if (hashCode != -1613589672) {
if (hashCode == -836030906 && str.equals("userId")) {
c = 0;
}
} else if (str.equals("language")) {
c = 1;
}
return c != 0 ? c != 1 ? "null" : getLanguage() : getUserId();
}
public void hideWaitDialog() {
XLog.a(TAG, "关闭对话框调用的线程" + Thread.currentThread().getName());
StaticHandler staticHandler = handler;
if (staticHandler == null) {
return;
}
staticHandler.post(new Runnable() { // from class: com.ubt.jimu.unity.bluetooth.f
@Override // java.lang.Runnable
public final void run() {
UnityActivity.this.a();
}
});
}
public boolean isBack() {
return this.isBack;
}
public boolean isCanEdit() {
return this.edit;
}
public boolean isDiy() {
return 1 == this.modelType;
}
public String isSkipGuide(int i) {
HashMap hashMap = new HashMap();
hashMap.put("isGuide", Integer.valueOf(i));
return JsonHelper.a(hashMap);
}
@Override // android.app.Activity
protected void onActivityResult(int i, int i2, Intent intent) {
super.onActivityResult(i, i2, intent);
switch (i) {
case 105:
onRequestImage(i, i2, intent);
break;
case 106:
this.isBack = false;
onRequestImage(i, i2, intent);
break;
case 107:
if (i2 == -1) {
this.unityCallback.openRefreshAllServo(intent.getStringExtra("servo_mode"));
break;
}
break;
}
}
@Override // com.ubt.unity.UnityPlayerNativeActivity, android.app.Activity, android.content.ComponentCallbacks
public void onConfigurationChanged(Configuration configuration) {
XLog.a(TAG, "onConfigurationChanged");
super.onConfigurationChanged(configuration);
}
@Override // com.ubt.unity.UnityPlayerNativeActivity, android.app.Activity
protected void onCreate(Bundle bundle) {
XLog.c(TAG, "------------------onCreate------------------------");
if (Build.VERSION.SDK_INT >= 26 && UiUtils.b(this)) {
UiUtils.a(this);
}
handler = new StaticHandler(this);
super.onCreate(bundle);
DeviceUtils.a((Activity) this);
showWaitDialog();
this.mIntent = getIntent();
this.unityCallback = new UnityCommandController(this);
JimuApplication.l().a(this);
EventBus.b().c(this);
register();
this.mBluetoothManager = JimuBluetoothManager.d();
initBluetooth();
this.mJimuManager = JimuApplication.l().f();
}
@Override // com.ubt.unity.UnityPlayerNativeActivity, android.app.Activity
protected void onDestroy() {
XLog.c(TAG, "------------------onDestroy------------------------");
XLog.c(TAG, "onDestroy");
EventBus.b().d(this);
unregisterReceiver(this.mHomeWatcherReceiver);
this.mBluetoothManager.b(this.mConnectionStateListener);
this.mBluetoothManager.removeDataReceiveListener(this.mDataReceiveListener);
hideWaitDialog();
this.dialogWait = null;
handler.removeCallbacksAndMessages(null);
handler = null;
super.onDestroy();
}
@Override // com.ubt.unity.UnityPlayerNativeActivity, android.app.Activity, android.view.KeyEvent.Callback
public boolean onKeyDown(int i, KeyEvent keyEvent) {
return super.onKeyDown(i, keyEvent);
}
@Override // android.view.View.OnLayoutChangeListener
public void onLayoutChange(View view, int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8) {
if (this.unityCallback == null) {
return;
}
getWindow().getDecorView().getWindowVisibleDisplayFrame(new Rect());
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(UnityEvent unityEvent) {
int type = unityEvent.getType();
if (type == 101) {
UnityPlayer.UnitySendMessage(mAckGameObjectName, "CallUnityFunc", unityEvent.getData());
callAndroidFunc(unityEvent.getData());
} else {
if (type != 102) {
return;
}
callAndroidFunc(unityEvent.getData());
}
}
@Override // com.ubt.jimu.base.networkstate.NetworkStateObserver
public void onNetworkConnected(NetworkType networkType) {
}
@Override // com.ubt.jimu.base.networkstate.NetworkStateObserver
public void onNetworkDisconnected() {
}
@Override // com.ubt.unity.UnityPlayerNativeActivity, android.app.Activity
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
UbtActivityStack.getInstance().addActivity(this);
setIntent(intent);
this.mIntent = intent;
XLog.c(TAG, "------------------onNewIntent------------------------");
}
@Override // com.ubt.unity.UnityPlayerNativeActivity, android.app.Activity
protected void onPause() {
ExchangeDialog exchangeDialog = this.mExchangeDialog;
if (exchangeDialog != null) {
exchangeDialog.dismiss();
this.mExchangeDialog = null;
}
this.resumeUnityActivity = false;
XLog.c(TAG, "------------------onPause------------------------");
this.isForeground = false;
hideWaitDialog();
this.unityCallback.stopBlockly();
unregisterPhonecallBroadcastReceiver();
this.mBluetoothManager.b(this.mConnectionStateListener);
this.mBluetoothManager.removeDataReceiveListener(this.mDataReceiveListener);
this.mJimuManager.b(false);
super.onPause();
}
@Override // android.app.Activity
protected void onRestart() {
super.onRestart();
}
@Override // com.ubt.unity.UnityPlayerNativeActivity, android.app.Activity
protected void onResume() {
this.resumeUnityActivity = true;
super.onResume();
JimuApplication.l().a();
this.isForeground = true;
this.mIntent = getIntent();
if (this.mIntent.getBooleanExtra(UNITY_ACTIVITY_RUNNING, false)) {
notifyBluetoothState(this.modelID, this.modelName, String.valueOf(this.modelType));
} else {
initData(this.mIntent);
}
registerPhonecalBroadcastReceiver();
this.mBluetoothManager.a(this.mConnectionStateListener);
this.mBluetoothManager.a(this.mDataReceiveListener);
this.mJimuManager.b(true);
}
@Override // android.app.Activity
protected void onSaveInstanceState(Bundle bundle) {
XLog.c(TAG, "------------------onSaveInstanceState------------------------");
bundle.putLong(MODEL_SERVERID_KEY, this.modelServerId);
bundle.putInt("current", this.currentStep);
bundle.putInt(FileDownloadModel.TOTAL, this.totalStep);
bundle.putBoolean(pEdit, this.edit);
bundle.putInt("blocklyType", this.blocklyType);
bundle.putInt(FileDownloadModel.TOTAL, this.size);
bundle.putString(modelId, this.modelID);
bundle.putInt(Course.TYPE_BLOCKLY, this.code);
bundle.putInt(pModelType, this.modelType);
bundle.putInt("moduleType", this.moduleType);
bundle.putSerializable("course", this.course);
bundle.putString(pModelName, this.modelName);
bundle.putString(ppicpath, this.picPath);
bundle.putInt(MyUnityListener.CALLER, this.from);
super.onSaveInstanceState(bundle);
bundle.putBoolean("background", true);
}
@Override // com.ubt.unity.UnityPlayerNativeActivity, android.app.Activity
public void onStart() {
super.onStart();
}
@Override // com.ubt.unity.UnityPlayerNativeActivity, android.app.Activity
public void onStop() {
XLog.a(TAG, " ---------- onStop ------------- ");
super.onStop();
}
public boolean operateFile(String str, int i, String str2, int i2) {
LogUtils.c("~~~filePath:" + str2);
LogUtils.c("~~~modelServerId:" + this.modelServerId + " modelId:" + str + " modelType:" + i + " oType:" + i2);
new UnityFileOperator((int) this.modelServerId, str, i, str2, i2).operateFile();
return true;
}
public void platformDestroy() {
XLog.a(TAG, " ---------- platformDestroy ------------- ");
}
public void platformInit(String str) {
XLog.a(TAG, " ---------- platformInit ------------- ");
mAckGameObjectName = str;
}
public void recordContentViewEnd(String str) {
this.mAnalytics.b(this, str);
}
public void recordContentViewStart(String str) {
this.mAnalytics.a(this, str);
}
public void recordEvent(String str, Map<String, String> map) {
this.mAnalytics.a(str, map);
}
public void requestCameraPermission() {
JimuPermissionRequest.a(this, new PermissionRequestListener() { // from class: com.ubt.jimu.unity.bluetooth.UnityActivity.4
@Override // com.ubtech.permission.PermissionRequestListener
public void onDenied() {
ALog.a(UnityActivity.TAG).d("User denied camera permission");
HashMap hashMap = new HashMap();
hashMap.put(UnityActivity.RESULT, String.valueOf(-1));
UnityActivity.handler.sendMessage(UnityActivity.handler.obtainMessage(16, hashMap));
}
@Override // com.ubtech.permission.PermissionRequestListener
public void onGranted() {
HashMap hashMap = new HashMap();
hashMap.put(UnityActivity.RESULT, String.valueOf(0));
UnityActivity.handler.sendMessage(UnityActivity.handler.obtainMessage(16, hashMap));
}
}, new PermissionRationalListener() { // from class: com.ubt.jimu.unity.bluetooth.UnityActivity.5
public void onCancel() {
}
public void onOk() {
ALog.a(UnityActivity.TAG).d("Need goto system permission activity, set isBack to true");
UnityActivity.this.setIsBack(true);
}
public void rationale() {
}
});
}
public void setConnectFromCourse(boolean z) {
this.connectFromCourse = z;
}
public void setDisConnectBLE(boolean z) {
this.disConnectBLE = z;
}
public void setIsBack(boolean z) {
this.isBack = z;
}
@Override // android.app.Activity
public void setRequestedOrientation(int i) {
if (Build.VERSION.SDK_INT < 26 || !UiUtils.b(this)) {
super.setRequestedOrientation(i);
}
}
public void showHelpFragment(String str, String str2, int i) {
if (this.helpFragment == null) {
ALog.a(TAG).d("get new help fragment");
this.helpFragment = HelpFragmentCompact.newInstance(str, str2, i);
this.helpFragment.setListener(new HelpFragmentCompact.OnHelpFragmentInteractionListener() { // from class: com.ubt.jimu.unity.bluetooth.d
@Override // com.ubt.jimu.blockly.view.HelpFragmentCompact.OnHelpFragmentInteractionListener
public final void onHelpPageBack() {
UnityActivity.this.c();
}
});
}
if (this.helpFragment.isAdded()) {
return;
}
ALog.a(TAG).d("show help fragment");
getFragmentManager().beginTransaction().add(android.R.id.content, this.helpFragment).show(this.helpFragment).commit();
}
public void showToast(final JimuRobotMessage jimuRobotMessage) {
if (jimuRobotMessage == null) {
return;
}
ALog.a(TAG).d("showToast msg:" + jimuRobotMessage.getMsg());
final ToastView.Type type = 2 == jimuRobotMessage.getLevel() ? ToastView.Type.ERROR : jimuRobotMessage.getLevel() == 0 ? ToastView.Type.NORMAL : ToastView.Type.SUCCESS;
runOnUiThread(new Runnable() { // from class: com.ubt.jimu.unity.bluetooth.UnityActivity.10
@Override // java.lang.Runnable
public void run() {
ToastView.a(UnityActivity.this, jimuRobotMessage.getMsg(), type).a();
}
});
}
public void showWaitDialog() {
ALog.a(TAG).d("showWaitDialog");
handler.post(new Runnable() { // from class: com.ubt.jimu.unity.bluetooth.e
@Override // java.lang.Runnable
public final void run() {
UnityActivity.this.d();
}
});
handler.removeCallbacks(this.mDelayHideWaitDialog);
handler.postDelayed(this.mDelayHideWaitDialog, 6000L);
}
public void startMission(JimuCourseMission jimuCourseMission) {
this.code = 2;
gotoModule(this.modelID, this.modelName, this.modelType, this.moduleType, (int) jimuCourseMission.getId());
}
public void unityLog(int i, String str, String str2) {
if (i == 0) {
XLog.b(str, str2);
return;
}
if (i == 1) {
XLog.c(str, str2);
} else if (i != 2) {
XLog.d(str, str2);
} else {
XLog.a(str, str2);
}
}
private void gotoModule(String str, String str2, int i, int i2, long j, int i3, String str3) {
if (this.isBack) {
XLog.c(TAG, "isBack == true");
XLog.c(TAG, "set isBack to false");
this.isBack = false;
} else if (i2 != 1) {
XLog.c(TAG, "[return]module type %s", Integer.valueOf(i2));
XLog.c(TAG, "isBack == false");
return;
}
ALog.a(TAG).d("gotoModule showWaitDialog");
showWaitDialog();
HashMap hashMap = new HashMap();
hashMap.put(modelId, str);
hashMap.put(pModelName, str2);
hashMap.put(pModelType, Integer.valueOf(i));
hashMap.put("moduleType", Integer.valueOf(i2));
hashMap.put(pEdit, Boolean.valueOf(this.edit));
hashMap.put(KEY_ACTION_ID, this.mActionId);
hashMap.put(MyUnityListener.CALLER, Integer.valueOf(i3));
if (!TextUtils.isEmpty(str3)) {
hashMap.put(MyUnityListener.CALLBACK, str3);
}
if (!StringUtils.e(this.picPath)) {
hashMap.put(ppicpath, this.picPath);
}
if (j > 0) {
hashMap.put("courseId", Long.valueOf(j));
}
CallUnityFunc("gotoModule", hashMap);
}
public void recordEvent(String str) {
this.mAnalytics.a(str);
}
public static void communityWithUnity(Context context, String str) {
EventBus.b().b(new UnityEvent(101, "", str));
}
public static void start(Context context, int i) {
Intent intent = new Intent(context, (Class<?>) UnityActivity.class);
intent.putExtra("blocklyType", i);
context.startActivity(intent);
}
public static void communityWithUnity(Context context, String str, String str2) {
XLog.c(TAG, str + ":" + str2);
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("funcName", str);
jSONObject.put("arg", str2);
EventBus.b().b(new UnityEvent(101, "", jSONObject.toString()));
} catch (JSONException e) {
e.printStackTrace();
}
}
public static void startUnityActivity(Activity activity, Robot robot, int i, int i2, int i3, int i4, boolean z, int i5) {
startUnityActivity(activity, null, robot, i, i2, i3, i4, z, i5);
}
public static void start(Context context, int i, String str, String str2, String str3, boolean z, int i2) {
if (i2 == 1) {
str3 = DiyRobotDbHandler.getLogPath(ModelType.PLAYER_DATA, str);
}
Intent intent = new Intent(context, (Class<?>) UnityActivity.class);
intent.addFlags(8388608);
intent.putExtra(Course.TYPE_BLOCKLY, i);
intent.putExtra(modelId, str);
intent.putExtra(pModelName, str2);
intent.putExtra(ppicpath, str3);
intent.putExtra(pEdit, z);
intent.putExtra(pModelType, i2);
context.startActivity(intent);
}
public static void startUnityActivity(Activity activity, DiyDetailsModel diyDetailsModel, Robot robot, int i, int i2, int i3, int i4, boolean z, int i5) {
startUnityActivity(activity, diyDetailsModel, robot, i, i2, i3, i4, z, i5, 0, null);
}
/* JADX INFO: Access modifiers changed from: private */
/* JADX WARN: Removed duplicated region for block: B:13:0x0038 */
/* JADX WARN: Removed duplicated region for block: B:15:0x003d */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
public void notifyBluetoothState(com.ubtrobot.jimu.bluetooth.ConnectionState r6, java.lang.String r7, java.lang.String r8, java.lang.String r9, java.lang.String r10) {
/*
r5 = this;
java.lang.String r0 = "UnityActivity"
java.lang.String r1 = "CallUnityFunc notifyBluetoothState include state"
com.ubtech.utils.XLog.a(r0, r1)
boolean r1 = r5.isForeground()
if (r1 != 0) goto L17
com.orhanobut.logger.Printer r6 = com.ubtrobot.log.ALog.a(r0)
java.lang.String r7 = "Not in foreground, do not notify bluetooth state to unity"
r6.d(r7)
return
L17:
r1 = 0
com.ubt.jimu.base.cache.Cache r2 = com.ubt.jimu.base.cache.Cache.getInstance()
com.ubtrobot.jimu.robotapi.BoardInfo r2 = r2.getBoardInfo()
java.lang.String r3 = ""
if (r2 == 0) goto L33
byte[] r2 = r2.f()
java.lang.String r0 = com.ubt.jimu.utils.EncryptUtils.a(r2) // Catch: java.io.UnsupportedEncodingException -> L2d
goto L34
L2d:
r2 = move-exception
java.lang.String r4 = "Encodeing motherboard info fail"
com.ubtech.utils.XLog.a(r0, r4, r2)
L33:
r0 = r3
L34:
com.ubtrobot.jimu.bluetooth.ConnectionState r2 = com.ubtrobot.jimu.bluetooth.ConnectionState.STATE_CONNECTED
if (r6 != r2) goto L3b
r1 = 1
r5.m_connenctDevice = r7
L3b:
if (r1 != 0) goto L3e
r0 = r3
L3e:
java.util.HashMap r6 = new java.util.HashMap
r6.<init>()
java.lang.Integer r1 = java.lang.Integer.valueOf(r1)
java.lang.String r2 = "result"
r6.put(r2, r1)
java.lang.String r1 = "motherboardData"
r6.put(r1, r0)
java.lang.String r0 = "mac"
r6.put(r0, r7)
java.lang.String r7 = "modelID"
r6.put(r7, r8)
java.lang.String r7 = "modelName"
r6.put(r7, r9)
java.lang.String r7 = "modelType"
r6.put(r7, r10)
java.lang.String r7 = "bluetoothConnectResult"
CallUnityFunc(r7, r6)
return
*/
throw new UnsupportedOperationException("Method not decompiled: com.ubt.jimu.unity.bluetooth.UnityActivity.notifyBluetoothState(com.ubtrobot.jimu.bluetooth.ConnectionState, java.lang.String, java.lang.String, java.lang.String, java.lang.String):void");
}
public static void startUnityActivity(Activity activity, DiyDetailsModel diyDetailsModel, Robot robot, int i, int i2, int i3, int i4, boolean z, int i5, int i6, String str) {
Intent intent = new Intent(activity, (Class<?>) UnityActivity.class);
if (robot != null) {
intent.putExtra(modelId, robot.getModelName());
if (diyDetailsModel != null) {
intent.putExtra("model", diyDetailsModel);
}
intent.putExtra(pModelName, TextUtils.isEmpty(robot.getModelDescriptionLangeage()) ? robot.getModelDescription() : robot.getModelDescriptionLangeage());
intent.putExtra(ppicpath, robot.getFilePath());
intent.putExtra(pModelType, Integer.parseInt(robot.getModelType()) - 1);
intent.putExtra(MODEL_SERVERID_KEY, robot.getModelId());
}
intent.putExtra(Course.TYPE_BLOCKLY, i);
intent.putExtra("moduleType", i2);
intent.putExtra("current", i3);
intent.putExtra(FileDownloadModel.TOTAL, i4);
intent.putExtra(pEdit, z);
intent.putExtra("blocklyType", i5);
intent.putExtra(MyUnityListener.CALLER, i6);
intent.putExtra(MyUnityListener.CALLBACK, str);
activity.startActivity(intent);
}
private void gotoScene(String str, String str2, String str3, int i, boolean z) {
if (!this.isBack) {
XLog.c(TAG, "isBack = false");
return;
}
XLog.c(TAG, "isBack = true");
this.isBack = false;
showWaitDialog();
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put(modelId, str);
jSONObject.put(pModelName, str2);
jSONObject.put(ppicpath, str3);
jSONObject.put(pModelType, i);
jSONObject.put(pEdit, z);
} catch (JSONException e) {
e.printStackTrace();
}
UnityPlayer.UnitySendMessage(mAckGameObjectName, "GotoScene", jSONObject.toString());
}
public static void start(Context context, int i, String str, String str2, String str3, boolean z, int i2, long j) {
if (i2 == 1) {
str3 = DiyRobotDbHandler.getLogPath(ModelType.PLAYER_DATA, str);
}
Intent intent = new Intent(context, (Class<?>) UnityActivity.class);
intent.addFlags(8388608);
intent.putExtra(Course.TYPE_BLOCKLY, i);
intent.putExtra(modelId, str);
intent.putExtra(pModelName, str2);
intent.putExtra(ppicpath, str3);
intent.putExtra(pEdit, z);
intent.putExtra(pModelType, i2);
intent.putExtra(MODEL_SERVERID_KEY, j);
context.startActivity(intent);
}
public static void startUnityActivity(Activity activity, Robot robot, Course course, int i, int i2, int i3) {
Intent intent = new Intent(activity, (Class<?>) UnityActivity.class);
if (robot != null) {
intent.putExtra(modelId, robot.getModelName());
intent.putExtra(pModelName, TextUtils.isEmpty(robot.getModelDescriptionLangeage()) ? robot.getModelDescription() : robot.getModelDescriptionLangeage());
intent.putExtra(ppicpath, robot.getFilePath());
intent.putExtra(pModelType, Integer.parseInt(robot.getModelType()) - 1);
intent.putExtra("model", robot);
}
intent.putExtra(Course.TYPE_BLOCKLY, i);
intent.putExtra("moduleType", i2);
intent.putExtra("course", course);
intent.putExtra(pEdit, true);
intent.putExtra("blocklyType", i3);
activity.startActivity(intent);
}
public static void start(Context context, int i, String str, String str2, String str3, int i2, long j) {
Intent intent = new Intent(context, (Class<?>) UnityActivity.class);
intent.addFlags(8388608);
intent.putExtra(modelId, str);
intent.putExtra(pModelName, str2);
intent.putExtra(ppicpath, str3);
intent.putExtra(Course.TYPE_BLOCKLY, i);
intent.putExtra("blocklyType", i2);
intent.putExtra(MODEL_SERVERID_KEY, j);
if (i == 1004) {
intent.putExtra(pModelType, 1);
} else {
intent.putExtra(pModelType, 0);
}
context.startActivity(intent);
}
public static void startUnityActivity(Activity activity, Robot robot, int i, int i2, int i3) {
startUnityActivity(activity, robot, i, i2, i3, 0, null);
}
public static void startUnityActivity(Activity activity, Robot robot, int i, int i2, int i3, int i4, String str) {
startUnityActivity(activity, null, robot, i, i2, 0, 0, true, i3, i4, str);
}
}