423 lines
17 KiB
Java
423 lines
17 KiB
Java
package com.ubt.jimu.controller;
|
|
|
|
import android.app.Dialog;
|
|
import android.content.DialogInterface;
|
|
import android.content.Intent;
|
|
import android.text.TextUtils;
|
|
import android.util.SparseArray;
|
|
import android.view.View;
|
|
import android.widget.ImageView;
|
|
import android.widget.RelativeLayout;
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import com.alibaba.android.arouter.facade.Postcard;
|
|
import com.alibaba.android.arouter.launcher.ARouter;
|
|
import com.ubt.jimu.R;
|
|
import com.ubt.jimu.base.EngineManager;
|
|
import com.ubt.jimu.base.SuperActivity;
|
|
import com.ubt.jimu.base.data.Servo;
|
|
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.adapter.AngleSetListAdapter;
|
|
import com.ubt.jimu.controller.component.TensionAngleSetView;
|
|
import com.ubt.jimu.controller.data.config.AccumulatorConfig;
|
|
import com.ubt.jimu.controller.data.config.WidgetConfig;
|
|
import com.ubt.jimu.controller.manager.CommandManager;
|
|
import com.ubt.jimu.controller.manager.MoveConfigManager;
|
|
import com.ubt.jimu.controller.presenter.AccumulatorSettingPresenter;
|
|
import com.ubt.jimu.controller.view.IAccumulatorSettingView;
|
|
import com.ubt.jimu.widgets.JAlertDialog;
|
|
import com.ubt.jimu.widgets.UniversalPopupWindow;
|
|
import com.ubtech.utils.XLog;
|
|
import com.ubtech.view.dialog.SimpleDialog;
|
|
import com.ubtech.view.widget.ToastView;
|
|
import com.ubtrobot.jimu.exception.RobotActiveException;
|
|
import com.ubtrobot.jimu.robotapi.ServoAngleReadInfo;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class AccumulatorSettingActivity extends SuperActivity implements View.OnClickListener, AngleSetListAdapter.SteerEngineListItemOnClickListener, TensionAngleSetView.AngleUpdateListener, IAccumulatorSettingView {
|
|
private AngleSetListAdapter a;
|
|
ImageView angle_delete;
|
|
ImageView angle_ok;
|
|
TensionAngleSetView angle_set_view;
|
|
private int b = WidgetConfig.MIN_ANGLE;
|
|
private int c = 118;
|
|
private int d;
|
|
private MoveConfigManager e;
|
|
private AccumulatorConfig f;
|
|
private Dialog g;
|
|
private JAlertDialog h;
|
|
private AccumulatorSettingPresenter i;
|
|
ImageView im_back;
|
|
ImageView im_select_engine;
|
|
private SparseArray<AccumulatorConfig> j;
|
|
RelativeLayout layout_default_page;
|
|
String mConfigId;
|
|
RobotLite mRobotLite;
|
|
RecyclerView rv_angle_list;
|
|
|
|
private void D0() {
|
|
JAlertDialog.Builder builder = new JAlertDialog.Builder(this);
|
|
builder.b(false);
|
|
builder.a(R.drawable.ic_loading);
|
|
builder.a(true);
|
|
this.h = builder.a();
|
|
this.h.show();
|
|
}
|
|
|
|
private void E0() {
|
|
UniversalPopupWindow.a(this).c(getResources().getString(R.string.delete_data_remind)).a(getResources().getString(R.string.btn_cancel_publish)).b(getResources().getString(R.string.ok)).a(new UniversalPopupWindow.UniversalPopupWindowListener() { // from class: com.ubt.jimu.controller.AccumulatorSettingActivity.1
|
|
@Override // com.ubt.jimu.widgets.UniversalPopupWindow.UniversalPopupWindowListener
|
|
public void a() {
|
|
AccumulatorSettingActivity.this.i.a(AccumulatorSettingActivity.this.f);
|
|
AccumulatorSettingActivity accumulatorSettingActivity = AccumulatorSettingActivity.this;
|
|
ToastView.a(accumulatorSettingActivity, accumulatorSettingActivity.getResources().getString(R.string.delete_success), ToastView.Type.NORMAL).a();
|
|
AccumulatorSettingActivity.this.G0();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.UniversalPopupWindow.UniversalPopupWindowListener
|
|
public void onCancel() {
|
|
}
|
|
}).a(this.mRootView);
|
|
}
|
|
|
|
private void F0() {
|
|
JAlertDialog jAlertDialog = this.h;
|
|
if (jAlertDialog == null || !jAlertDialog.isShowing()) {
|
|
return;
|
|
}
|
|
this.h.dismiss();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void G0() {
|
|
if (TextUtils.isEmpty(this.mConfigId)) {
|
|
setResult(-1);
|
|
} else {
|
|
Intent intent = new Intent();
|
|
intent.putExtra("configId", this.mConfigId);
|
|
setResult(-1, intent);
|
|
}
|
|
finish();
|
|
}
|
|
|
|
private void H0() {
|
|
AccumulatorConfig accumulatorConfig;
|
|
List<Servo> b = this.i.b(false);
|
|
if (b == null || b.size() <= 0) {
|
|
return;
|
|
}
|
|
this.j = new SparseArray<>(b.size());
|
|
for (Servo servo : b) {
|
|
if (servo != null) {
|
|
int i = this.d;
|
|
if (i <= 0 || i != servo.getId()) {
|
|
accumulatorConfig = new AccumulatorConfig();
|
|
accumulatorConfig.setServoID((byte) servo.getId());
|
|
accumulatorConfig.setStartAngle(WidgetConfig.MIN_ANGLE);
|
|
accumulatorConfig.setLaunchAngle(118);
|
|
} else {
|
|
accumulatorConfig = new AccumulatorConfig(this.f.getConfigID(), this.f.getServoID(), this.f.getStartAngle(), this.f.getLaunchAngle());
|
|
}
|
|
this.j.put(servo.getId(), accumulatorConfig);
|
|
}
|
|
}
|
|
this.i.a(b.size());
|
|
}
|
|
|
|
private void I0() {
|
|
int i = this.d;
|
|
if (i <= 0) {
|
|
XLog.b("woo", "saveData Servo Id should be %d", Integer.valueOf(i));
|
|
return;
|
|
}
|
|
if (this.f == null) {
|
|
this.f = new AccumulatorConfig();
|
|
}
|
|
this.f.setServoID(this.d);
|
|
this.f.setStartAngle(this.b);
|
|
this.f.setLaunchAngle(this.c);
|
|
this.e.a(this.f);
|
|
this.e.a(true);
|
|
}
|
|
|
|
private int l(int i) {
|
|
if (i < -118) {
|
|
return WidgetConfig.MIN_ANGLE;
|
|
}
|
|
if (i > 118) {
|
|
return 118;
|
|
}
|
|
return i;
|
|
}
|
|
|
|
@Override // com.ubt.jimu.controller.view.IAccumulatorSettingView
|
|
public void Y() {
|
|
ToastView.a(this, getResources().getString(R.string.no_configuration_servo), ToastView.Type.NORMAL).a();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.controller.view.IAccumulatorSettingView
|
|
public void d(String str) {
|
|
new SimpleDialog.Builder(this).a((CharSequence) str).d(R.string.ok).a(R.string.cancel, true).b(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.controller.b
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
AccumulatorSettingActivity.this.b(dialogInterface, i);
|
|
}
|
|
}).a(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.controller.d
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
dialogInterface.dismiss();
|
|
}
|
|
}).a().show();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.controller.view.IAccumulatorSettingView
|
|
public void g(List<ServoAngleReadInfo> list) {
|
|
AccumulatorConfig accumulatorConfig;
|
|
if (list == null || list.size() <= 0) {
|
|
return;
|
|
}
|
|
for (ServoAngleReadInfo servoAngleReadInfo : list) {
|
|
if (servoAngleReadInfo != null && servoAngleReadInfo.b() > 0 && this.d != servoAngleReadInfo.b() && (accumulatorConfig = this.j.get(servoAngleReadInfo.b())) != null) {
|
|
accumulatorConfig.setStartAngle((int) servoAngleReadInfo.a());
|
|
accumulatorConfig.setLaunchAngle((int) servoAngleReadInfo.a());
|
|
this.j.put(servoAngleReadInfo.b(), accumulatorConfig);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.SuperActivity
|
|
public void initData() {
|
|
ARouter.b().a(this);
|
|
this.i = new AccumulatorSettingPresenter(this, this.mRobotLite);
|
|
this.a = new AngleSetListAdapter(this);
|
|
this.rv_angle_list.setLayoutManager(new LinearLayoutManager(this));
|
|
this.rv_angle_list.setAdapter(this.a);
|
|
this.e = MoveConfigManager.a(getApplicationContext());
|
|
if (TextUtils.isEmpty(this.mConfigId)) {
|
|
this.f = new AccumulatorConfig();
|
|
this.angle_delete.setVisibility(8);
|
|
this.layout_default_page.setVisibility(0);
|
|
this.i.a(this.mRobotLite);
|
|
} else {
|
|
this.f = (AccumulatorConfig) this.e.a(this.mConfigId);
|
|
if (this.f != null) {
|
|
this.angle_delete.setVisibility(0);
|
|
this.layout_default_page.setVisibility(8);
|
|
this.c = this.f.getLaunchAngle();
|
|
this.b = this.f.getStartAngle();
|
|
this.d = this.f.getServoID();
|
|
this.angle_set_view.a(this.f.getStartAngle(), this.f.getLaunchAngle());
|
|
}
|
|
}
|
|
this.a.a(this.f);
|
|
this.im_back.setImageResource(R.mipmap.btn_cancel);
|
|
this.im_select_engine.setBackgroundResource(R.mipmap.select_engine);
|
|
this.angle_ok.setBackgroundResource(R.mipmap.affirm_controller);
|
|
this.angle_delete.setBackgroundResource(R.mipmap.control_delete_icon);
|
|
H0();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.SuperActivity
|
|
public void initEvent() {
|
|
this.im_back.setOnClickListener(this);
|
|
this.angle_ok.setOnClickListener(this);
|
|
this.a.a(this);
|
|
this.angle_delete.setOnClickListener(this);
|
|
this.angle_set_view.setAngleUpdateListener(this);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.SuperActivity
|
|
public View initView() {
|
|
return View.inflate(this, R.layout.activity_tension_angle_setting, null);
|
|
}
|
|
|
|
@Override // android.view.View.OnClickListener
|
|
public void onClick(View view) {
|
|
switch (view.getId()) {
|
|
case R.id.angle_delete /* 2131296319 */:
|
|
E0();
|
|
break;
|
|
case R.id.angle_ok /* 2131296320 */:
|
|
I0();
|
|
G0();
|
|
break;
|
|
case R.id.im_back /* 2131296709 */:
|
|
finish();
|
|
break;
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.BaseActivity, com.ubt.jimu.ScreenRotationManageActivity, androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
|
|
protected void onDestroy() {
|
|
this.i.h();
|
|
super.onDestroy();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.BaseActivity, com.ubt.jimu.ScreenRotationManageActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
|
|
protected void onPause() {
|
|
this.i.j();
|
|
super.onPause();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.BaseActivity, com.ubt.jimu.ScreenRotationManageActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
|
|
protected void onResume() {
|
|
super.onResume();
|
|
this.a.a(this.i.b(true));
|
|
EngineManager c = this.i.c();
|
|
if (c != null) {
|
|
CommandManager.a(getApplicationContext()).a(c);
|
|
}
|
|
int i = this.d;
|
|
if (i > 0) {
|
|
this.i.a(i, ServoMode.SERVO_MODE_ANGLE);
|
|
}
|
|
this.i.g();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.controller.adapter.AngleSetListAdapter.SteerEngineListItemOnClickListener
|
|
public void a(Servo servo) {
|
|
this.layout_default_page.setVisibility(8);
|
|
this.d = (byte) servo.getId();
|
|
AccumulatorConfig accumulatorConfig = this.j.get(this.d);
|
|
if (accumulatorConfig != null) {
|
|
int l = l(accumulatorConfig.getStartAngle());
|
|
int l2 = l(accumulatorConfig.getLaunchAngle());
|
|
this.angle_set_view.a(l, l2);
|
|
this.b = l;
|
|
this.c = l2;
|
|
}
|
|
}
|
|
|
|
public /* synthetic */ void b(DialogInterface dialogInterface, int i) {
|
|
Postcard a = ARouter.b().a("/controller/servosettings");
|
|
a.a("robotLite", this.mRobotLite);
|
|
a.t();
|
|
dialogInterface.dismiss();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.controller.adapter.AngleSetListAdapter.SteerEngineListItemOnClickListener
|
|
public void b(Servo servo) {
|
|
if (this.mRobotLite.isOfficial()) {
|
|
ToastView.a(this, R.string.control_config_official).a();
|
|
} else {
|
|
d(getResources().getString(R.string.nonsupport));
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.controller.component.TensionAngleSetView.AngleUpdateListener
|
|
public void b(double d) {
|
|
this.b = (int) d;
|
|
AccumulatorConfig accumulatorConfig = this.j.get(this.d);
|
|
if (accumulatorConfig != null) {
|
|
accumulatorConfig.setStartAngle(this.b);
|
|
}
|
|
this.i.a(this.mRobotLite, this.d, this.b);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.controller.component.TensionAngleSetView.AngleUpdateListener
|
|
public void d(double d) {
|
|
this.c = (int) d;
|
|
AccumulatorConfig accumulatorConfig = this.j.get(this.d);
|
|
if (accumulatorConfig != null) {
|
|
accumulatorConfig.setLaunchAngle(this.c);
|
|
}
|
|
this.i.a(this.mRobotLite, this.d, this.c);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.controller.view.IBaseControllerView
|
|
public void a(final String str, final RobotActiveException robotActiveException, final List<Integer> list, final boolean z) {
|
|
runOnUiThread(new Runnable() { // from class: com.ubt.jimu.controller.e
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
AccumulatorSettingActivity.this.b(str, robotActiveException, list, z);
|
|
}
|
|
});
|
|
}
|
|
|
|
public /* synthetic */ void a(RobotActiveException robotActiveException, List list, DialogInterface dialogInterface, int i) {
|
|
this.i.a(robotActiveException, (List<Integer>) 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.h;
|
|
if ((jAlertDialog != null && jAlertDialog.isShowing()) || isFinishing() || isDestroyed()) {
|
|
return;
|
|
}
|
|
D0();
|
|
return;
|
|
}
|
|
F0();
|
|
}
|
|
|
|
public /* synthetic */ void b(String str, final RobotActiveException robotActiveException, final List list, boolean z) {
|
|
Dialog dialog = this.g;
|
|
if (dialog == null || !dialog.isShowing()) {
|
|
SimpleDialog.Builder builder = new SimpleDialog.Builder(this);
|
|
SimpleDialog.Builder b = builder.a((CharSequence) str).d(R.string.ok).a(R.string.cancel, true).a(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.controller.h
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
dialogInterface.dismiss();
|
|
}
|
|
}).b(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.controller.g
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
AccumulatorSettingActivity.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.c
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
dialogInterface.dismiss();
|
|
}
|
|
});
|
|
}
|
|
this.g = builder.a();
|
|
this.g.show();
|
|
}
|
|
}
|
|
|
|
@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<Component> list) {
|
|
if (list == null || list.size() <= 0) {
|
|
return;
|
|
}
|
|
new SimpleDialog.Builder(this).a((CharSequence) this.i.a(this, list)).d(R.string.ok).a(R.string.cancel, true).b(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.controller.a
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
AccumulatorSettingActivity.this.a(dialogInterface, i);
|
|
}
|
|
}).a(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.controller.f
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
dialogInterface.dismiss();
|
|
}
|
|
}).a().show();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.controller.view.IBaseControllerView
|
|
public void b(List<Component> list) {
|
|
this.i.a(list);
|
|
}
|
|
|
|
public /* synthetic */ void a(DialogInterface dialogInterface, int i) {
|
|
this.i.f();
|
|
dialogInterface.dismiss();
|
|
}
|
|
}
|