package com.ubt.jimu.controller; import android.app.Dialog; import android.content.DialogInterface; import android.content.Intent; import android.hardware.input.InputManager; import android.os.Bundle; import android.os.SystemClock; import android.text.TextUtils; import android.util.Log; import android.view.InputDevice; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; import com.alibaba.android.arouter.facade.Postcard; import com.alibaba.android.arouter.launcher.ARouter; import com.ubt.jimu.BaseActivity; import com.ubt.jimu.JimuApplication; import com.ubt.jimu.R; import com.ubt.jimu.base.EngineManager; import com.ubt.jimu.base.cache.Cache; import com.ubt.jimu.base.data.ServoMode; import com.ubt.jimu.base.entities.RobotLite; import com.ubt.jimu.connect.model.Component; import com.ubt.jimu.controller.ControllerActivity; import com.ubt.jimu.controller.component.ActionView; import com.ubt.jimu.controller.component.SteeringWheelView; import com.ubt.jimu.controller.data.command.AccumulatorGear; import com.ubt.jimu.controller.data.command.Gear; import com.ubt.jimu.controller.data.config.AccumulatorConfig; import com.ubt.jimu.controller.data.config.HSliderConfig; import com.ubt.jimu.controller.data.config.JockstickConfig; import com.ubt.jimu.controller.data.config.SliderConfig; import com.ubt.jimu.controller.data.config.WidgetConfig; import com.ubt.jimu.controller.data.keymap.ButtonKey; import com.ubt.jimu.controller.data.keymap.JoyStick; import com.ubt.jimu.controller.data.keymap.KeyMap; import com.ubt.jimu.controller.data.keymap.entity.Key; import com.ubt.jimu.controller.data.widget.AccumulatorData; import com.ubt.jimu.controller.data.widget.ActionWidgetData; import com.ubt.jimu.controller.data.widget.ControllerData; import com.ubt.jimu.controller.data.widget.HSliderWidgetData; import com.ubt.jimu.controller.data.widget.ItemBaseData; import com.ubt.jimu.controller.data.widget.JockstickData; import com.ubt.jimu.controller.data.widget.MoveBaseData; import com.ubt.jimu.controller.data.widget.SliderWidgetData; import com.ubt.jimu.controller.manager.CommandManager; import com.ubt.jimu.controller.presenter.ControllerPresenter; import com.ubt.jimu.controller.view.ControllerState; import com.ubt.jimu.controller.view.IControllerView; import com.ubt.jimu.controller.view.RemoteControlManagementView; import com.ubt.jimu.controller.view.control.ControlEditEvent; import com.ubt.jimu.controller.view.control.ControllerStateChangeListener; import com.ubt.jimu.controller.view.control.OnControllerClickListener; import com.ubt.jimu.controller.view.control.OnGameControllerConfigResultListener; import com.ubt.jimu.controller.view.control.SuperControlView; import com.ubt.jimu.unity.bluetooth.UnityActivity; import com.ubt.jimu.utils.LogUtils; import com.ubt.jimu.widgets.JAlertDialog; import com.ubtech.utils.XLog; import com.ubtech.view.dialog.SimpleDialog; import com.ubtech.view.widget.ToastView; import com.ubtrobot.jimu.bluetooth.ConnectionState; import com.ubtrobot.jimu.exception.RobotActiveException; import com.ubtrobot.jimu.robotapi.BatteryInfo; import com.ubtrobot.jimu.robotapi.IPowerStateListener; import com.ubtrobot.jimu.robotapi.JimuManager; import com.ubtrobot.log.ALog; import com.ubtrobot.ubtlib.analytics.JimuAnalytics; import java.util.Iterator; import java.util.List; import java.util.Map; /* loaded from: classes.dex */ public class ControllerActivity extends BaseActivity implements IControllerView, ControlEditEvent, RemoteControlManagementView.UpdateCommandParameterListener { private ControllerPresenter a; private RelativeLayout b; private RelativeLayout c; private TextView d; private TextView e; private TextView f; private RemoteControlManagementView g; private ImageView h; private ImageView i; private RelativeLayout j; private String k; private String m; RobotLite mRobotLite; private Dialog n; private JAlertDialog o; private ImageView r; private ImageView s; private ImageView t; private InputManager u; private Dialog x; private boolean l = false; private boolean p = false; private IPowerStateListener q = new AnonymousClass1(); private InputManager.InputDeviceListener v = new InputManager.InputDeviceListener() { // from class: com.ubt.jimu.controller.ControllerActivity.2 @Override // android.hardware.input.InputManager.InputDeviceListener public void onInputDeviceAdded(int i) { ControllerState state = ControllerActivity.this.g.getState(); if (state == ControllerState.STATE_NORMAL || state == ControllerState.STATE_PHYSICAL_CONTROLLER_CONFIG) { ControllerActivity.this.E0(); } } @Override // android.hardware.input.InputManager.InputDeviceListener public void onInputDeviceChanged(int i) { } @Override // android.hardware.input.InputManager.InputDeviceListener public void onInputDeviceRemoved(int i) { ControllerState state = ControllerActivity.this.g.getState(); if ((state == ControllerState.STATE_NORMAL || state == ControllerState.STATE_PHYSICAL_CONTROLLER_CONFIG) && ControllerActivity.this.P0()) { ControllerActivity.this.W0(); } } }; /* renamed from: com.ubt.jimu.controller.ControllerActivity$1, reason: invalid class name */ class AnonymousClass1 implements IPowerStateListener { AnonymousClass1() { } public /* synthetic */ void a() { ToastView.a(ControllerActivity.this, R.string.bluetooth_disconnected).a(); } @Override // com.ubtrobot.jimu.robotapi.IPowerStateListener public void onConnectionStateChange(String str, ConnectionState connectionState) { XLog.a("woo", "connection state changed mac: %s, state: %s", str, connectionState.toString()); if (!TextUtils.isEmpty(str) && str.equals(ControllerActivity.this.k) && connectionState == ConnectionState.STATE_DISCONNECTED) { if (ControllerActivity.this.a != null) { ControllerActivity.this.a.y(); } ControllerActivity.this.runOnUiThread(new Runnable() { // from class: com.ubt.jimu.controller.q @Override // java.lang.Runnable public final void run() { ControllerActivity.AnonymousClass1.this.a(); } }); ControllerActivity.this.f(true); } } @Override // com.ubtrobot.jimu.robotapi.IPowerStateListener public void onPowerStateChanged(BatteryInfo batteryInfo) { ControllerActivity.this.a(batteryInfo); } } private boolean F0() { if (!this.a.e()) { return false; } new SimpleDialog.Builder(this).b(R.string.charge_protect).d(R.string.ok).b(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.controller.t @Override // android.content.DialogInterface.OnClickListener public final void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }).a().show(); return true; } private boolean G0() { if (this.a.r()) { return false; } i(true); return true; } private void H0() { JAlertDialog.Builder builder = new JAlertDialog.Builder(this); builder.b(false); builder.a(R.drawable.ic_loading); builder.a(true); this.o = builder.a(); this.o.show(); } private void I0() { JAlertDialog jAlertDialog = this.o; if (jAlertDialog == null || !jAlertDialog.isShowing()) { return; } this.o.dismiss(); } private void J0() { LogUtils.c("enableEdit:"); JimuAnalytics.b().a("click_P9_1"); this.a.y(); this.b.setVisibility(4); this.g.setState(ControllerState.STATE_EDIT); } private SuperControlView K0() { Iterator> it = this.g.getControlViewMap().entrySet().iterator(); while (it.hasNext()) { SuperControlView value = it.next().getValue(); if (value.c()) { return value; } } return null; } private void L0() { this.a.u(); this.a.y(); this.b.setVisibility(4); this.g.setState(ControllerState.STATE_PHYSICAL_CONTROLLER_CONFIG); } private void M0() { getWindow().getDecorView().setSystemUiVisibility(4102); } private void N0() { this.g.setControlEvent(this); } private void O0() { this.a = new ControllerPresenter(this, this.mRobotLite); } /* JADX INFO: Access modifiers changed from: private */ public boolean P0() { boolean s = this.a.s(); if (s || !this.p) { this.p = s; return false; } this.p = s; return true; } private void Q0() { if (this.a != null) { if ("local".equals(Cache.getInstance().getUserId()) || !this.mRobotLite.isOfficial()) { this.a.a(this.mRobotLite, Cache.getInstance().getUserId()); } else { this.a.e(this.mRobotLite); } } } private void R0() { if (!this.a.r()) { ToastView.a(getApplicationContext(), R.string.bluetooth_not_connect).a(); } else { this.a.v(); ToastView.a(getApplicationContext(), R.string.soft_power_down).a(); } } private void S0() { JimuManager f = JimuApplication.l().f(); ConnectionState b = f.b(this.mRobotLite.getModelId()); if (b == null || b != ConnectionState.STATE_CONNECTED) { f(true); this.k = null; } else { this.k = f.d(); this.a.w(); } } private void T0() { JimuManager f = JimuApplication.l().f(); if (f != null) { f.a(this.q); } } private void U0() { this.u = (InputManager) getSystemService("input"); this.u.registerInputDeviceListener(this.v, null); } private void V0() { JimuManager f = JimuApplication.l().f(); if (f != null) { f.b(this.q); } } /* JADX INFO: Access modifiers changed from: private */ public void W0() { if (this.x == null) { this.x = new SimpleDialog.Builder(this).b(R.string.game_controller_disconnect).d(R.string.button_ok).b(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.controller.ControllerActivity.3 @Override // android.content.DialogInterface.OnClickListener public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); if (ControllerActivity.this.g.getState() == ControllerState.STATE_PHYSICAL_CONTROLLER_CONFIG) { ControllerActivity.this.g.setState(ControllerState.STATE_NORMAL); ControllerActivity.this.a.k(); } else { ControllerState controllerState = ControllerState.STATE_NORMAL; } ControllerActivity.this.E0(); } }).a(false).a(); } if (isFinishing() || isDestroyed() || this.x.isShowing()) { return; } this.x.show(); } private void X0() { this.i.setVisibility(8); Iterator> it = this.g.getControlViewMap().entrySet().iterator(); while (it.hasNext()) { SuperControlView value = it.next().getValue(); if (value != null && (value instanceof ActionView)) { ((ActionView) value).f(); } } g(false); } private void h(boolean z) { this.r.setEnabled(!z); this.s.setEnabled(!z); this.t.setEnabled(!z); this.h.setEnabled(!z); this.i.setEnabled(!z); } private void i(boolean z) { if (z) { this.a.l(); } else { this.a.n(); } } private void initView() { this.b = (RelativeLayout) findViewById(R.id.rl_title); this.j = (RelativeLayout) findViewById(R.id.rl_prompt_not_turn_off_screen); this.g = (RemoteControlManagementView) findViewById(R.id.control_management_view); this.g.setOnControllerClickListener(new OnControllerClickListener(this) { // from class: com.ubt.jimu.controller.ControllerActivity.4 @Override // com.ubt.jimu.controller.view.control.OnControllerClickListener public void a(ActionWidgetData actionWidgetData, SuperControlView superControlView) { } }); this.g.setOnAddClickListener(new RemoteControlManagementView.OnMenuItemClickListener() { // from class: com.ubt.jimu.controller.ControllerActivity.5 @Override // com.ubt.jimu.controller.view.RemoteControlManagementView.OnMenuItemClickListener public void a(ItemBaseData itemBaseData) { ControllerActivity.this.a(itemBaseData); } @Override // com.ubt.jimu.controller.view.RemoteControlManagementView.OnMenuItemClickListener public void b(ItemBaseData itemBaseData) { ControllerActivity.this.b(itemBaseData); } }); this.g.setGameControllerConfigResultListener(new OnGameControllerConfigResultListener() { // from class: com.ubt.jimu.controller.ControllerActivity.6 @Override // com.ubt.jimu.controller.view.control.OnGameControllerConfigResultListener public void onCancel() { ControllerActivity.this.a.k(); } @Override // com.ubt.jimu.controller.view.control.OnGameControllerConfigResultListener public void onOk() { ControllerActivity.this.a.x(); } }); this.g.setControllerStateChangeListener(new ControllerStateChangeListener() { // from class: com.ubt.jimu.controller.ControllerActivity.7 @Override // com.ubt.jimu.controller.view.control.ControllerStateChangeListener public void a(ControllerState controllerState) { if (controllerState == ControllerState.STATE_NORMAL) { ControllerActivity.this.E0(); } else if (controllerState == ControllerState.STATE_EDIT || controllerState == ControllerState.STATE_PHYSICAL_CONTROLLER_CONFIG) { ControllerActivity.this.g(false); } } }); this.s = (ImageView) findViewById(R.id.btn_edit); this.s.setBackgroundResource(R.mipmap.btn_edit); this.s.setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.controller.s @Override // android.view.View.OnClickListener public final void onClick(View view) { ControllerActivity.this.a(view); } }); this.t = (ImageView) findViewById(R.id.btn_power_down); this.t.setBackgroundResource(R.mipmap.btn_power_down); this.t.setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.controller.c0 @Override // android.view.View.OnClickListener public final void onClick(View view) { ControllerActivity.this.b(view); } }); this.h = (ImageView) findViewById(R.id.btn_connect); this.h.setBackgroundResource(R.mipmap.btn_disconnect); this.h.setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.controller.r @Override // android.view.View.OnClickListener public final void onClick(View view) { ControllerActivity.this.c(view); } }); this.r = (ImageView) findViewById(R.id.btn_back); this.r.setBackgroundResource(R.mipmap.icon_round_back); this.r.setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.controller.z @Override // android.view.View.OnClickListener public final void onClick(View view) { ControllerActivity.this.d(view); } }); this.g.setVSliderViewUpdateCommandParameterListener(this); this.i = (ImageView) findViewById(R.id.btn_physical_controller_connect_state); this.i.setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.controller.u @Override // android.view.View.OnClickListener public final void onClick(View view) { ControllerActivity.this.e(view); } }); this.c = (RelativeLayout) findViewById(R.id.rl_status); this.d = (TextView) findViewById(R.id.tv_status_left); this.e = (TextView) findViewById(R.id.tv_status_center); this.f = (TextView) findViewById(R.id.tv_status_right); } private void o(String str) { if (TextUtils.isEmpty(str)) { return; } Iterator> it = this.g.getControlViewMap().entrySet().iterator(); while (it.hasNext()) { SuperControlView value = it.next().getValue(); if (!value.c() && (value instanceof ActionView)) { ActionView actionView = (ActionView) value; if (str.equals(actionView.getText())) { actionView.f(); } } } } private void p(String str) { if (TextUtils.isEmpty(str) || !this.mRobotLite.getModelId().equals(str)) { return; } this.k = JimuApplication.l().f().d(); f(false); this.a.w(); } private void q(String str) { if (TextUtils.isEmpty(str) || !this.mRobotLite.getModelId().equals(str)) { return; } this.k = null; f(true); } private void r(String str) { RemoteControlManagementView remoteControlManagementView = this.g; if (remoteControlManagementView != null) { remoteControlManagementView.e(); if (TextUtils.isEmpty(str)) { return; } this.g.b(str); } } public void D0() { RemoteControlManagementView remoteControlManagementView = this.g; if (remoteControlManagementView != null) { remoteControlManagementView.d(); if (TextUtils.isEmpty(this.m)) { return; } this.g.a(this.m); this.m = null; } } public void E0() { boolean s = this.a.s(); if (s) { this.i.setVisibility(0); List o = this.a.o(); List q = this.a.q(); if ((o == null || o.isEmpty()) && (q == null || q.isEmpty())) { return; } Iterator> it = this.g.getControlViewMap().entrySet().iterator(); boolean z = false; while (it.hasNext()) { SuperControlView value = it.next().getValue(); if (value != null) { if (value instanceof SteeringWheelView) { if (q != null && !q.isEmpty()) { JockstickData data = ((SteeringWheelView) value).getData(); Iterator it2 = q.iterator(); while (it2.hasNext()) { if (it2.next().a().equals(data.getConfigID())) { z = true; } } } } else if ((value instanceof ActionView) && o != null && !o.isEmpty()) { ActionView actionView = (ActionView) value; ActionWidgetData data2 = actionView.getData(); if (data2 == null) { actionView.f(); } else { KeyMap keyMap = null; boolean z2 = false; for (KeyMap keyMap2 : o) { if (keyMap2.a().equals(data2.getActionID())) { keyMap = keyMap2; z2 = true; } } if (z2) { actionView.b(keyMap.b()); z = true; } else { actionView.f(); } } } } } g(z); } else { X0(); } this.p = s; } @Override // com.ubt.jimu.controller.view.RemoteControlManagementView.UpdateCommandParameterListener public void a(JockstickData jockstickData) { } @Override // android.app.Activity, android.view.Window.Callback public boolean dispatchGenericMotionEvent(MotionEvent motionEvent) { if ((motionEvent.getSource() & 16777232) != 16777232 || motionEvent.getAction() != 2) { return super.dispatchGenericMotionEvent(motionEvent); } int historySize = motionEvent.getHistorySize(); for (int i = 0; i < historySize; i++) { a(motionEvent, i); } a(motionEvent, -1); return true; } @Override // androidx.appcompat.app.AppCompatActivity, androidx.core.app.ComponentActivity, android.app.Activity, android.view.Window.Callback public boolean dispatchKeyEvent(KeyEvent keyEvent) { if (a(keyEvent)) { return true; } return super.dispatchKeyEvent(keyEvent); } public void f(final boolean z) { runOnUiThread(new Runnable() { // from class: com.ubt.jimu.controller.x @Override // java.lang.Runnable public final void run() { ControllerActivity.this.e(z); } }); } public void g(boolean z) { if (z) { this.j.setVisibility(0); } else { this.j.setVisibility(8); } } @Override // com.ubt.jimu.controller.view.RemoteControlManagementView.UpdateCommandParameterListener public void g0() { J0(); } @Override // com.ubt.jimu.controller.view.IControllerView public void j() { LogUtils.c("关闭加载视图"); a(false); } @Override // androidx.fragment.app.FragmentActivity, android.app.Activity protected void onActivityResult(int i, int i2, Intent intent) { super.onActivityResult(i, i2, intent); LogUtils.c("ControllerActivity:" + i + " " + i2); if (i2 == -1) { if (i == 103) { r(null); return; } if (i == 104) { if (intent != null) { String stringExtra = intent.getStringExtra("configId"); r(stringExtra); this.g.f(); this.a.a(stringExtra); return; } return; } if (i == 101) { p(intent.getStringExtra("KEY_MODEL_ID")); } else if (i == 102) { q(intent.getStringExtra("KEY_MODEL_ID")); } } } @Override // com.ubt.jimu.BaseActivity, com.ubt.jimu.ScreenRotationManageActivity, androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, androidx.core.app.ComponentActivity, android.app.Activity protected void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.activity_control); ARouter.b().a(this); Object[] objArr = new Object[1]; RobotLite robotLite = this.mRobotLite; objArr[0] = robotLite != null ? robotLite.toString() : "null"; XLog.c("woo", "autowired robot: %s", objArr); if (this.mRobotLite == null) { finish(); return; } initView(); N0(); O0(); this.a.d(this.mRobotLite); Q0(); } @Override // com.ubt.jimu.BaseActivity, com.ubt.jimu.ScreenRotationManageActivity, androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, android.app.Activity protected void onDestroy() { ControllerPresenter controllerPresenter = this.a; if (controllerPresenter != null) { controllerPresenter.h(); } super.onDestroy(); } @Override // androidx.fragment.app.FragmentActivity, android.app.Activity protected void onNewIntent(Intent intent) { super.onNewIntent(intent); D0(); if (intent != null) { this.m = intent.getStringExtra(UnityActivity.KEY_ACTION_ID); XLog.a("woo", "modified actionId: " + this.m); } } @Override // com.ubt.jimu.BaseActivity, com.ubt.jimu.ScreenRotationManageActivity, androidx.fragment.app.FragmentActivity, android.app.Activity protected void onPause() { JimuAnalytics.b().b(this, "P9"); V0(); this.a.j(); super.onPause(); } @Override // com.ubt.jimu.BaseActivity, com.ubt.jimu.ScreenRotationManageActivity, androidx.fragment.app.FragmentActivity, android.app.Activity protected void onResume() { super.onResume(); M0(); JimuAnalytics.b().a(this, "P9"); EngineManager c = this.a.c(); if (c != null) { CommandManager.a(getApplicationContext()).a(c); } this.a.i(); S0(); T0(); this.a.g(); U0(); } @Override // com.ubt.jimu.controller.view.IControllerView public void z() { this.c.setVisibility(8); this.b.setVisibility(0); } @Override // com.ubt.jimu.controller.view.IControllerView public void c() { LogUtils.c("打开加载视图"); a(true); } public /* synthetic */ void d(View view) { finish(); } public /* synthetic */ void e(View view) { L0(); } public /* synthetic */ void a(View view) { J0(); } public /* synthetic */ void b(View view) { R0(); } public /* synthetic */ void e(boolean z) { if (z) { this.h.setBackgroundResource(R.mipmap.btn_disconnect); } } public /* synthetic */ void i(List list) { if (list == null || list.size() <= 0) { return; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < list.size(); i++) { String format = String.format(getResources().getString(R.string.servo_mode_servo_index), list.get(i)); if (i == 0) { sb.append(format); } else { sb.append(","); sb.append(format); } } ToastView.a(this, String.format(getResources().getString(R.string.control_servo_mode_error), sb.toString())).a(); } private void a(WidgetConfig widgetConfig) { if (widgetConfig instanceof JockstickConfig) { LogUtils.c("ID:" + widgetConfig.getConfigID()); Postcard a = ARouter.b().a("/controller/jocksticksettings"); a.a("robotLite", this.mRobotLite); a.a("config_id_key", widgetConfig.getConfigID()); a.a(this, 104); return; } if (widgetConfig instanceof HSliderConfig) { Postcard a2 = ARouter.b().a("/controller/anglesettings"); a2.a("robotLite", this.mRobotLite); a2.a("config_id_key", widgetConfig.getConfigID()); a2.a(this, 104); return; } if (widgetConfig instanceof SliderConfig) { Postcard a3 = ARouter.b().a("/controller/vslidersettings"); a3.a("robotLite", this.mRobotLite); a3.a("config_id_key", widgetConfig.getConfigID()); a3.a(this, 104); return; } if (widgetConfig instanceof AccumulatorConfig) { Postcard a4 = ARouter.b().a("/controller/accumulatorsettings"); a4.a("robotLite", this.mRobotLite); a4.a("config_id_key", widgetConfig.getConfigID()); a4.a(this, 104); } } /* JADX INFO: Access modifiers changed from: private */ public void b(ItemBaseData itemBaseData) { if (itemBaseData instanceof MoveBaseData) { WidgetConfig config = ((MoveBaseData) itemBaseData).getConfig(); if (config != null) { if (config.getConfigType() == 2) { a(config); return; } else { ToastView.a(this, R.string.control_config_official).a(); return; } } return; } if (itemBaseData instanceof ActionWidgetData) { ActionWidgetData actionWidgetData = (ActionWidgetData) itemBaseData; if (actionWidgetData.getActionSequence().j()) { ToastView.a(this, getResources().getString(R.string.control_config_official)).a(); } else { if (this.mRobotLite == null || F0()) { return; } UnityActivity.startActionUnity(this, this.mRobotLite, 2, 5, actionWidgetData.getActionID()); } } } public /* synthetic */ void c(View view) { i(!this.a.r()); } private void c(ActionWidgetData actionWidgetData) { if (this.a == null || actionWidgetData == null || G0() || F0()) { return; } this.a.b(actionWidgetData.getActionSequence()); } private void b(ActionWidgetData actionWidgetData) { ControllerPresenter controllerPresenter = this.a; if (controllerPresenter == null || actionWidgetData == null || !controllerPresenter.r() || this.a.e()) { return; } this.a.a(actionWidgetData.getActionSequence()); } public /* synthetic */ void b(BatteryInfo batteryInfo) { if (batteryInfo != null) { if (batteryInfo.d()) { if (batteryInfo.c()) { this.h.setBackgroundResource(R.drawable.ic_power_high); return; } else { this.h.setBackgroundResource(R.drawable.ic_power_charging); return; } } if (batteryInfo.a() <= 20.0f) { this.h.setBackgroundResource(R.drawable.ic_power_low); return; } if (batteryInfo.a() < 50.0f) { this.h.setBackgroundResource(R.drawable.ic_power_one); } else if (batteryInfo.a() < 75.0f) { this.h.setBackgroundResource(R.drawable.ic_power_two); } else { this.h.setBackgroundResource(R.drawable.ic_power_high); } } } /* JADX INFO: Access modifiers changed from: private */ public void a(ItemBaseData itemBaseData) { if (itemBaseData instanceof MoveBaseData) { if (this.mRobotLite != null) { Postcard a = ARouter.b().a("/controller/adddirect"); a.a("robotLite", this.mRobotLite); a.a(this, 103); return; } XLog.b("woo", "robot shouldn't be null"); return; } if (!(itemBaseData instanceof ActionWidgetData) || this.mRobotLite == null || F0()) { return; } UnityActivity.startActionUnity(this, this.mRobotLite, 2, 5, ""); } public /* synthetic */ void b(String str, final RobotActiveException robotActiveException, final List list, boolean z) { Dialog dialog = this.n; if (dialog == null || !dialog.isShowing()) { SimpleDialog.Builder builder = new SimpleDialog.Builder(this); SimpleDialog.Builder b = builder.a((CharSequence) str).d(R.string.ok).b(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.controller.y @Override // android.content.DialogInterface.OnClickListener public final void onClick(DialogInterface dialogInterface, int i) { ControllerActivity.this.a(robotActiveException, list, dialogInterface, i); } }); b.b(false); b.a(false); if (z) { builder.a(R.string.cancel, true).a(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.controller.v @Override // android.content.DialogInterface.OnClickListener public final void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }); } this.n = builder.a(); this.n.show(); } } @Override // com.ubt.jimu.controller.view.IControllerView public void a(final ControllerData controllerData) { runOnUiThread(new Runnable() { // from class: com.ubt.jimu.controller.ControllerActivity.8 @Override // java.lang.Runnable public void run() { ControllerActivity.this.g.setData(controllerData); ControllerActivity.this.g.f(); ControllerActivity.this.E0(); ControllerActivity.this.a(false); LogUtils.c("关闭加载视图"); } }); } @Override // com.ubt.jimu.controller.view.IControllerView public void a(final BatteryInfo batteryInfo) { runOnUiThread(new Runnable() { // from class: com.ubt.jimu.controller.b0 @Override // java.lang.Runnable public final void run() { ControllerActivity.this.b(batteryInfo); } }); } @Override // com.ubt.jimu.controller.view.IControllerView public void a(final List list, ServoMode servoMode) { runOnUiThread(new Runnable() { // from class: com.ubt.jimu.controller.a0 @Override // java.lang.Runnable public final void run() { ControllerActivity.this.i(list); } }); } @Override // com.ubt.jimu.controller.view.IBaseControllerView public void a(final String str, final RobotActiveException robotActiveException, final List list, final boolean z) { runOnUiThread(new Runnable() { // from class: com.ubt.jimu.controller.e0 @Override // java.lang.Runnable public final void run() { ControllerActivity.this.b(str, robotActiveException, list, z); } }); } public /* synthetic */ void a(RobotActiveException robotActiveException, List list, DialogInterface dialogInterface, int i) { this.a.a(robotActiveException, (List) list); dialogInterface.dismiss(); } @Override // com.ubt.jimu.controller.view.IBaseControllerView public void a(boolean z) { XLog.a("woo", "loading: %b", Boolean.valueOf(z)); if (z) { JAlertDialog jAlertDialog = this.o; if ((jAlertDialog != null && jAlertDialog.isShowing()) || isFinishing() || isDestroyed()) { return; } H0(); return; } I0(); } @Override // com.ubt.jimu.controller.view.IBaseControllerView public void b(List list) { this.a.a(list); } @Override // com.ubt.jimu.controller.view.control.ControlEditEvent public void b(ControllerData controllerData) { this.b.setVisibility(0); ControllerPresenter controllerPresenter = this.a; if (controllerPresenter != null) { controllerPresenter.z(); this.a.a(controllerData); } } @Override // com.ubt.jimu.controller.view.IBaseControllerView public void a(Throwable th) { th.printStackTrace(); ToastView.a(this, R.string.control_request_error).a(); } @Override // com.ubt.jimu.controller.view.IBaseControllerView public void a(List list) { if (list == null || list.size() <= 0) { return; } new SimpleDialog.Builder(this).a((CharSequence) this.a.a(this, list)).d(R.string.ok).a(R.string.cancel, true).b(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.controller.w @Override // android.content.DialogInterface.OnClickListener public final void onClick(DialogInterface dialogInterface, int i) { ControllerActivity.this.a(dialogInterface, i); } }).a(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.controller.d0 @Override // android.content.DialogInterface.OnClickListener public final void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }).a().show(); } @Override // com.ubt.jimu.controller.view.RemoteControlManagementView.UpdateCommandParameterListener public void b(float f, SliderWidgetData sliderWidgetData) { SliderConfig config; ControllerPresenter controllerPresenter; LogUtils.c("onVSliderViewCancelCommandParameterListener:松手"); z(); if (G0() || F0() || sliderWidgetData == null || sliderWidgetData.getConfig() == null || (config = sliderWidgetData.getConfig()) == null || (controllerPresenter = this.a) == null) { return; } controllerPresenter.a(config, Gear.EMPTY, 0); } @Override // com.ubt.jimu.controller.view.RemoteControlManagementView.UpdateCommandParameterListener public void b(float f, AccumulatorData accumulatorData) { if (!this.a.r() || this.a.e() || accumulatorData == null || accumulatorData.getConfig() == null) { return; } AccumulatorConfig config = accumulatorData.getConfig(); if (!this.l) { this.l = true; this.a.a(config); } int a = AccumulatorGear.a(f / 100.0f, Math.abs(config.getLaunchAngle() - config.getStartAngle())); int abs = a > 0 ? (Math.abs(config.getLaunchAngle() - config.getStartAngle()) * 1000) / a : 0; a(getResources().getString(R.string.default_value) + ": " + config.getStartAngle() + "°", String.format(getResources().getString(R.string.servo_mode_servo_index), Integer.valueOf(config.getServoID())) + ": " + abs + "°/s", getResources().getString(R.string.ejector_value) + ": " + config.getLaunchAngle() + "°"); } public /* synthetic */ void a(DialogInterface dialogInterface, int i) { this.a.f(); dialogInterface.dismiss(); } @Override // com.ubt.jimu.controller.view.IControllerView public void a(String str, String str2, String str3) { if (!TextUtils.isEmpty(str)) { this.d.setText(str); } else { this.d.setText(""); } if (!TextUtils.isEmpty(str2)) { this.e.setText(str2); } else { this.e.setText(""); } if (!TextUtils.isEmpty(str3)) { this.f.setText(str3); } else { this.f.setText(""); } this.b.setVisibility(8); this.c.setVisibility(0); } private boolean b(KeyEvent keyEvent) { SuperControlView K0 = K0(); if (K0 == null) { Log.w(this.TAG, ""); return false; } if (!(K0 instanceof ActionView)) { Log.w(this.TAG, ""); return false; } if (keyEvent.getAction() != 0) { return false; } return a(ButtonKey.a(keyEvent.getKeyCode())); } @Override // com.ubt.jimu.controller.view.RemoteControlManagementView.UpdateCommandParameterListener public void a(float f, SliderWidgetData sliderWidgetData) { LogUtils.c("onVSliderViewUpdateCommandParameterListener:" + f); if (!this.a.r() || this.a.e() || sliderWidgetData == null || sliderWidgetData.getConfig() == null) { return; } this.a.a(f, sliderWidgetData.getConfig()); } @Override // com.ubt.jimu.controller.view.RemoteControlManagementView.UpdateCommandParameterListener public void a(float f, AccumulatorData accumulatorData) { this.l = false; z(); if (G0() || F0() || accumulatorData == null || accumulatorData.getConfig() == null) { return; } this.a.a(f, accumulatorData.getConfig()); } @Override // com.ubt.jimu.controller.view.RemoteControlManagementView.UpdateCommandParameterListener public void a(float f, HSliderWidgetData hSliderWidgetData) { LogUtils.c("onUpdateHSliderViewCommandParameterListener" + f); if (!this.a.r() || this.a.e() || hSliderWidgetData == null || hSliderWidgetData.getConfig() == null) { return; } this.a.a(f, hSliderWidgetData.getConfig()); } @Override // com.ubt.jimu.controller.view.RemoteControlManagementView.UpdateCommandParameterListener public void a(HSliderWidgetData hSliderWidgetData) { LogUtils.c("onCancelHSliderViewCommandParameterListener:松手"); z(); if (G0() || F0()) { } } @Override // com.ubt.jimu.controller.view.RemoteControlManagementView.UpdateCommandParameterListener public void a(float f, float f2, float f3, JockstickData jockstickData) { if (this.r.isEnabled()) { h(true); } if (!this.a.r() || this.a.e() || jockstickData == null || jockstickData.getConfig() == null) { return; } this.a.a(f, f2, f3, jockstickData.getConfig()); } @Override // com.ubt.jimu.controller.view.RemoteControlManagementView.UpdateCommandParameterListener public void a(JockstickData jockstickData, SuperControlView.MotionEventState motionEventState) { ControllerPresenter controllerPresenter; h(false); if (G0() || F0() || jockstickData == null || jockstickData.getConfig() == null || (controllerPresenter = this.a) == null) { return; } Gear gear = Gear.EMPTY; controllerPresenter.a(0, gear, 0, gear, jockstickData.getConfig()); } @Override // com.ubt.jimu.controller.view.RemoteControlManagementView.UpdateCommandParameterListener public void a(ActionWidgetData actionWidgetData) { h(true); b(actionWidgetData); LogUtils.c("operationActionOnDown"); } @Override // com.ubt.jimu.controller.view.RemoteControlManagementView.UpdateCommandParameterListener public void a(ActionWidgetData actionWidgetData, SuperControlView.MotionEventState motionEventState) { h(false); c(actionWidgetData); } private boolean a(ControllerState controllerState, float f, float f2, MotionEvent motionEvent) { if (Float.compare(f, 0.0f) == 0 && Float.compare(f2, 0.0f) == 0) { return false; } if (controllerState == ControllerState.STATE_PHYSICAL_CONTROLLER_CONFIG) { a(a(f, f2)); return true; } if (controllerState != ControllerState.STATE_NORMAL) { return true; } a(a(f, f2), 0, motionEvent.getMetaState()); return true; } private Key a(float f, float f2) { if (Float.compare(f, 0.0f) == 0 && Float.compare(f2, -1.0f) == 0) { return ButtonKey.a(19); } if (Float.compare(f, 0.0f) == 0 && Float.compare(f2, 1.0f) == 0) { return ButtonKey.a(20); } if (Float.compare(f, -1.0f) == 0 && Float.compare(f2, 0.0f) == 0) { return ButtonKey.a(21); } if (Float.compare(f, 1.0f) == 0 && Float.compare(f2, 0.0f) == 0) { return ButtonKey.a(22); } return null; } private void a(ControllerState controllerState, MotionEvent motionEvent, int i) { InputDevice device = motionEvent.getDevice(); float a = a(motionEvent, device, 17, i); float a2 = a(motionEvent, device, 17, i); float a3 = a(motionEvent, device, 0, i); float a4 = a(motionEvent, device, 1, i); float a5 = a(motionEvent, device, 11, i); float a6 = a(motionEvent, device, 14, i); float a7 = a(motionEvent, device, 15, i); float a8 = a(motionEvent, device, 16, i); Log.i(this.TAG, "l2Axis:" + a + " r2Axis:" + a2); Log.i(this.TAG, "leftJoystickX:" + a3 + " leftJoystickY:" + a4); Log.i(this.TAG, "rightJoystickX:" + a5 + " rightJoystickY:" + a6); Log.i(this.TAG, "dpadX:" + a7 + " dpadY:" + a8); if (a <= 0.01d && a2 <= 0.01d) { if (a(controllerState, a7, a8, motionEvent)) { return; } if (controllerState == ControllerState.STATE_PHYSICAL_CONTROLLER_CONFIG) { SuperControlView K0 = K0(); if (K0 != null && (K0 instanceof SteeringWheelView)) { SteeringWheelView steeringWheelView = (SteeringWheelView) K0; if (a3 == 0.0f && a4 == 0.0f) { if (a5 != 0.0f || a6 != 0.0f) { JockstickData data = steeringWheelView.getData(); if (data == null || data.getConfig() == null || data.getConfig().getConfigID() == null) { return; } this.a.a(new KeyMap(new JoyStick("RS"), data.getConfig().getConfigID())); } a(motionEvent, steeringWheelView, a5, a6); return; } JockstickData data2 = steeringWheelView.getData(); if (data2 == null || data2.getConfig() == null || data2.getConfig().getConfigID() == null) { return; } this.a.a(new KeyMap(new JoyStick("LS"), data2.getConfig().getConfigID())); a(motionEvent, steeringWheelView, a3, a4); return; } return; } if (controllerState == ControllerState.STATE_NORMAL) { String a9 = this.a.a((Key) new JoyStick("LS")); SuperControlView a10 = a(a9, SteeringWheelView.class); if (a3 != 0.0f || a4 != 0.0f) { if (a9 == null || a10 == null) { return; } a(motionEvent, a10, a3, a4); return; } String a11 = this.a.a((Key) new JoyStick("RS")); SuperControlView a12 = a(a11, SteeringWheelView.class); if (a5 != 0.0f || a6 != 0.0f) { if (a11 == null || a12 == null) { return; } a(motionEvent, a12, a5, a6); return; } if (a10 != null && a10.isPressed()) { a(motionEvent, a10, a5, a6); } if (a12 != null && a12.isPressed()) { a(motionEvent, a12, a5, a6); } SuperControlView a13 = a(this.a.a((Key) ButtonKey.a(19)), ActionView.class); if (a13 != null && a13.isPressed()) { ALog.a(this.TAG).d("is pressed:" + a13.isPressed()); a(motionEvent, a13, a5, a6); } SuperControlView a14 = a(this.a.a((Key) ButtonKey.a(20)), ActionView.class); if (a14 != null && a14.isPressed()) { ALog.a(this.TAG).d("is pressed:" + a14.isPressed()); a(motionEvent, a14, a5, a6); } SuperControlView a15 = a(this.a.a((Key) ButtonKey.a(21)), ActionView.class); if (a15 != null && a15.isPressed()) { ALog.a(this.TAG).d("is pressed:" + a15.isPressed()); a(motionEvent, a15, a5, a6); } SuperControlView a16 = a(this.a.a((Key) ButtonKey.a(22)), ActionView.class); if (a16 == null || !a16.isPressed()) { return; } ALog.a(this.TAG).d("is pressed:" + a16.isPressed()); a(motionEvent, a16, a5, a6); return; } ALog.a(this.TAG).d("Do nothing on normal state"); return; } ALog.a(this.TAG).d("L2 or R2 is pressed. l2Axis:" + a + " r2Axis:" + a2); } private void a(MotionEvent motionEvent, SuperControlView superControlView, float f, float f2) { if ((superControlView instanceof SteeringWheelView) || (superControlView instanceof ActionView)) { int action = motionEvent.getAction(); int i = (Math.abs(f) >= 0.01f || Math.abs(f2) >= 0.01f || action != 2) ? action : 1; float[] viewCenterXY = superControlView.getViewCenterXY(); float viewWidth = f * (superControlView.getViewWidth() / 2.0f); float viewHeight = f2 * (superControlView.getViewHeight() / 2.0f); long uptimeMillis = SystemClock.uptimeMillis(); MotionEvent obtain = MotionEvent.obtain(uptimeMillis, uptimeMillis, i, viewCenterXY[0] + viewWidth, viewCenterXY[1] + viewHeight, motionEvent.getMetaState()); obtain.setSource(4098); superControlView.onTouchEvent(obtain); } } private boolean a(MotionEvent motionEvent, int i) { a(this.g.getState(), motionEvent, i); return true; } private static float a(MotionEvent motionEvent, InputDevice inputDevice, int i, int i2) { float historicalAxisValue; InputDevice.MotionRange motionRange = inputDevice.getMotionRange(i, motionEvent.getSource()); if (motionRange == null) { return 0.0f; } float flat = motionRange.getFlat(); if (i2 < 0) { historicalAxisValue = motionEvent.getAxisValue(i); } else { historicalAxisValue = motionEvent.getHistoricalAxisValue(i, i2); } if (Math.abs(historicalAxisValue) > flat) { return historicalAxisValue; } return 0.0f; } private boolean a(KeyEvent keyEvent) { if ((keyEvent.getSource() & 1025) != 1025) { return false; } ButtonKey a = ButtonKey.a(keyEvent.getKeyCode()); if (a == null) { return true; } ControllerState state = this.g.getState(); if (state == ControllerState.STATE_NORMAL) { a(a, keyEvent.getAction(), keyEvent.getMetaState()); } else { if (state != ControllerState.STATE_PHYSICAL_CONTROLLER_CONFIG) { return true; } b(keyEvent); } return true; } private void a(Key key, int i, int i2) { ActionWidgetData data; if (key == null) { return; } Map controlViewMap = this.g.getControlViewMap(); String a = this.a.a(key); Iterator> it = controlViewMap.entrySet().iterator(); while (it.hasNext()) { SuperControlView value = it.next().getValue(); if ((value instanceof ActionView) && (data = ((ActionView) value).getData()) != null && data.getActionID() != null && data.getActionID().equals(a)) { if (value.isPressed() && i == 0) { return; } float[] viewCenterXY = value.getViewCenterXY(); long uptimeMillis = SystemClock.uptimeMillis(); MotionEvent obtain = MotionEvent.obtain(uptimeMillis, uptimeMillis, i, viewCenterXY[0], viewCenterXY[1], i2); obtain.setSource(4098); value.onTouchEvent(obtain); return; } } } private SuperControlView a(String str, Class cls) { if (TextUtils.isEmpty(str)) { return null; } Iterator> it = this.g.getControlViewMap().entrySet().iterator(); while (it.hasNext()) { SuperControlView value = it.next().getValue(); if (value != null && value.getClass().equals(cls)) { if (value instanceof SteeringWheelView) { JockstickData data = ((SteeringWheelView) value).getData(); if (data != null && data.getConfig() != null && data.getConfig().getConfigID() != null && str.equals(data.getConfig().getConfigID())) { return value; } } else if ((value instanceof ActionView) && str.equals(((ActionView) value).getData().getActionID())) { return value; } } } return null; } private boolean a(Key key) { if (key == null) { return false; } SuperControlView K0 = K0(); if (K0 == null) { Log.w(this.TAG, ""); return false; } if (!(K0 instanceof ActionView)) { Log.w(this.TAG, ""); return false; } ActionView actionView = (ActionView) K0; actionView.b(key.a()); o(key.a()); ActionWidgetData data = actionView.getData(); if (data != null) { this.a.a(new KeyMap(key, data.getActionID())); } return false; } }