434 lines
17 KiB
Java
434 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.AngleSetView;
|
|
import com.ubt.jimu.controller.data.config.HSliderConfig;
|
|
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.AngleSettingPresenter;
|
|
import com.ubt.jimu.controller.view.IAngleSettingView;
|
|
import com.ubt.jimu.utils.LogUtils;
|
|
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 AngleSettingActivity extends SuperActivity implements View.OnClickListener, AngleSetListAdapter.SteerEngineListItemOnClickListener, AngleSetView.AngleUpdateListener, IAngleSettingView {
|
|
private AngleSetListAdapter a;
|
|
ImageView angle_delete;
|
|
ImageView angle_ok;
|
|
AngleSetView angle_set_view;
|
|
private HSliderConfig b;
|
|
private int c = 118;
|
|
private int d = WidgetConfig.MIN_ANGLE;
|
|
private int e;
|
|
private MoveConfigManager f;
|
|
private View g;
|
|
private Dialog h;
|
|
private JAlertDialog i;
|
|
ImageView im_back;
|
|
ImageView im_select_engine;
|
|
private AngleSettingPresenter j;
|
|
private SparseArray<HSliderConfig> k;
|
|
RelativeLayout layout_default_page;
|
|
String mConfigId;
|
|
RobotLite mRobotLite;
|
|
RecyclerView rv_angle_list;
|
|
|
|
private boolean D0() {
|
|
List<Servo> b = this.j.b(true);
|
|
for (int i = 0; i < b.size(); i++) {
|
|
if (!b.get(i).isConfigged()) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private void E0() {
|
|
JAlertDialog.Builder builder = new JAlertDialog.Builder(this);
|
|
builder.b(false);
|
|
builder.a(R.drawable.ic_loading);
|
|
builder.a(true);
|
|
this.i = builder.a();
|
|
this.i.show();
|
|
}
|
|
|
|
private void F0() {
|
|
UniversalPopupWindow.a(this).c(getResources().getString(R.string.delete_data_remind)).a(getResources().getString(R.string.cancel)).b(getResources().getString(R.string.ok)).a(new UniversalPopupWindow.UniversalPopupWindowListener() { // from class: com.ubt.jimu.controller.AngleSettingActivity.1
|
|
@Override // com.ubt.jimu.widgets.UniversalPopupWindow.UniversalPopupWindowListener
|
|
public void a() {
|
|
AngleSettingActivity.this.j.a(AngleSettingActivity.this.b);
|
|
AngleSettingActivity angleSettingActivity = AngleSettingActivity.this;
|
|
ToastView.a(angleSettingActivity, angleSettingActivity.getResources().getString(R.string.delete_success), ToastView.Type.NORMAL).a();
|
|
AngleSettingActivity.this.H0();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.UniversalPopupWindow.UniversalPopupWindowListener
|
|
public void onCancel() {
|
|
}
|
|
}).a(this.g);
|
|
}
|
|
|
|
private void G0() {
|
|
JAlertDialog jAlertDialog = this.i;
|
|
if (jAlertDialog == null || !jAlertDialog.isShowing()) {
|
|
return;
|
|
}
|
|
this.i.dismiss();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void H0() {
|
|
if (TextUtils.isEmpty(this.mConfigId)) {
|
|
setResult(-1);
|
|
} else {
|
|
Intent intent = new Intent();
|
|
intent.putExtra("configId", this.mConfigId);
|
|
setResult(-1, intent);
|
|
}
|
|
finish();
|
|
}
|
|
|
|
private void I0() {
|
|
HSliderConfig hSliderConfig;
|
|
List<Servo> b = this.j.b(false);
|
|
if (b == null || b.size() <= 0) {
|
|
return;
|
|
}
|
|
this.k = new SparseArray<>(b.size());
|
|
for (Servo servo : b) {
|
|
if (servo != null) {
|
|
int i = this.e;
|
|
if (i <= 0 || i != servo.getId()) {
|
|
hSliderConfig = new HSliderConfig();
|
|
hSliderConfig.setServoID((byte) servo.getId());
|
|
hSliderConfig.setMinAngle(WidgetConfig.MIN_ANGLE);
|
|
hSliderConfig.setMaxAngle(118);
|
|
} else {
|
|
hSliderConfig = new HSliderConfig(this.b.getConfigID(), this.b.getServoID(), this.b.getMinAngle(), this.b.getMaxAngle());
|
|
}
|
|
this.k.put(servo.getId(), hSliderConfig);
|
|
}
|
|
}
|
|
this.j.a(b.size());
|
|
}
|
|
|
|
private void J0() {
|
|
int i = this.e;
|
|
if (i <= 0) {
|
|
XLog.b("woo", "saveData Servo Id should be %d", Integer.valueOf(i));
|
|
return;
|
|
}
|
|
this.b.setMaxAngle(this.c);
|
|
this.b.setMinAngle(this.d);
|
|
this.b.setServoID(this.e);
|
|
this.f.a(this.b);
|
|
this.f.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.IAngleSettingView
|
|
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.n
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
AngleSettingActivity.this.b(dialogInterface, i);
|
|
}
|
|
}).a(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.controller.j
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
dialogInterface.dismiss();
|
|
}
|
|
}).a().show();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.controller.view.IAngleSettingView
|
|
public void g(List<ServoAngleReadInfo> list) {
|
|
HSliderConfig hSliderConfig;
|
|
if (list == null || list.size() <= 0) {
|
|
return;
|
|
}
|
|
for (ServoAngleReadInfo servoAngleReadInfo : list) {
|
|
if (servoAngleReadInfo != null && servoAngleReadInfo.b() > 0 && this.e != servoAngleReadInfo.b() && (hSliderConfig = this.k.get(servoAngleReadInfo.b())) != null) {
|
|
hSliderConfig.setMinAngle((int) servoAngleReadInfo.a());
|
|
hSliderConfig.setMaxAngle((int) servoAngleReadInfo.a());
|
|
this.k.put(servoAngleReadInfo.b(), hSliderConfig);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.SuperActivity
|
|
public void initData() {
|
|
ARouter.b().a(this);
|
|
this.j = new AngleSettingPresenter(this, this.mRobotLite);
|
|
this.f = MoveConfigManager.a(getApplicationContext());
|
|
if (TextUtils.isEmpty(this.mConfigId)) {
|
|
this.b = new HSliderConfig();
|
|
this.angle_delete.setVisibility(8);
|
|
this.layout_default_page.setVisibility(0);
|
|
if (!D0()) {
|
|
LogUtils.c("没有可配置的舵机");
|
|
ToastView.a(this, getResources().getString(R.string.no_configuration_servo), ToastView.Type.NORMAL).a();
|
|
}
|
|
} else {
|
|
this.b = (HSliderConfig) this.f.a(this.mConfigId);
|
|
if (this.b != null) {
|
|
this.angle_delete.setVisibility(0);
|
|
this.layout_default_page.setVisibility(8);
|
|
this.c = this.b.getMaxAngle();
|
|
this.d = this.b.getMinAngle();
|
|
this.e = this.b.getServoID();
|
|
this.angle_set_view.a(this.d, this.c);
|
|
}
|
|
LogUtils.c("configId:" + this.mConfigId + " " + this.b);
|
|
}
|
|
this.a = new AngleSetListAdapter(this);
|
|
this.rv_angle_list.setLayoutManager(new LinearLayoutManager(this));
|
|
this.rv_angle_list.setAdapter(this.a);
|
|
this.a.a(this.b);
|
|
this.im_back.setBackgroundResource(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);
|
|
I0();
|
|
}
|
|
|
|
@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_set_view.setAngleUpdateListener(this);
|
|
this.angle_delete.setOnClickListener(this);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.SuperActivity
|
|
public View initView() {
|
|
this.g = View.inflate(this, R.layout.activity_angle_setting, null);
|
|
return this.g;
|
|
}
|
|
|
|
@Override // android.view.View.OnClickListener
|
|
public void onClick(View view) {
|
|
switch (view.getId()) {
|
|
case R.id.angle_delete /* 2131296319 */:
|
|
F0();
|
|
break;
|
|
case R.id.angle_ok /* 2131296320 */:
|
|
J0();
|
|
H0();
|
|
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.j.h();
|
|
super.onDestroy();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.BaseActivity, com.ubt.jimu.ScreenRotationManageActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
|
|
protected void onPause() {
|
|
this.j.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.j.b(true));
|
|
EngineManager c = this.j.c();
|
|
if (c != null) {
|
|
CommandManager.a(getApplicationContext()).a(c);
|
|
}
|
|
int i = this.e;
|
|
if (i > 0) {
|
|
this.j.a(i, ServoMode.SERVO_MODE_ANGLE);
|
|
}
|
|
this.j.g();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.controller.adapter.AngleSetListAdapter.SteerEngineListItemOnClickListener
|
|
public void a(Servo servo) {
|
|
if (servo != null) {
|
|
this.layout_default_page.setVisibility(8);
|
|
this.e = (byte) servo.getId();
|
|
HSliderConfig hSliderConfig = this.k.get(this.e);
|
|
if (hSliderConfig != null) {
|
|
int l = l(hSliderConfig.getMinAngle());
|
|
int l2 = l(hSliderConfig.getMaxAngle());
|
|
this.angle_set_view.a(l, l2);
|
|
this.d = l;
|
|
this.c = l2;
|
|
}
|
|
}
|
|
}
|
|
|
|
@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.AngleSetView.AngleUpdateListener
|
|
public void c(double d) {
|
|
this.d = (int) d;
|
|
HSliderConfig hSliderConfig = this.k.get(this.e);
|
|
if (hSliderConfig != null) {
|
|
hSliderConfig.setMinAngle(this.d);
|
|
}
|
|
this.j.a(this.mRobotLite, this.e, this.d);
|
|
}
|
|
|
|
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.view.IBaseControllerView
|
|
public void b(List<Component> list) {
|
|
this.j.a(list);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.controller.component.AngleSetView.AngleUpdateListener
|
|
public void a(double d) {
|
|
this.c = (int) d;
|
|
HSliderConfig hSliderConfig = this.k.get(this.e);
|
|
if (hSliderConfig != null) {
|
|
hSliderConfig.setMaxAngle(this.c);
|
|
}
|
|
this.j.a(this.mRobotLite, this.e, 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.m
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
AngleSettingActivity.this.a(str, z, robotActiveException, list);
|
|
}
|
|
});
|
|
}
|
|
|
|
public /* synthetic */ void a(String str, boolean z, final RobotActiveException robotActiveException, final List list) {
|
|
Dialog dialog = this.h;
|
|
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, z).a(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.controller.i
|
|
@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.l
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
AngleSettingActivity.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.k
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
dialogInterface.dismiss();
|
|
}
|
|
});
|
|
}
|
|
this.h = builder.a();
|
|
this.h.show();
|
|
}
|
|
}
|
|
|
|
public /* synthetic */ void a(RobotActiveException robotActiveException, List list, DialogInterface dialogInterface, int i) {
|
|
this.j.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.i;
|
|
if ((jAlertDialog != null && jAlertDialog.isShowing()) || isFinishing() || isDestroyed()) {
|
|
return;
|
|
}
|
|
E0();
|
|
return;
|
|
}
|
|
G0();
|
|
}
|
|
|
|
@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.j.a(this, list)).d(R.string.ok).a(R.string.cancel, true).b(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.controller.p
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
AngleSettingActivity.this.a(dialogInterface, i);
|
|
}
|
|
}).a(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.controller.o
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public final void onClick(DialogInterface dialogInterface, int i) {
|
|
dialogInterface.dismiss();
|
|
}
|
|
}).a().show();
|
|
}
|
|
|
|
public /* synthetic */ void a(DialogInterface dialogInterface, int i) {
|
|
this.j.f();
|
|
dialogInterface.dismiss();
|
|
}
|
|
}
|