949 lines
42 KiB
Java
949 lines
42 KiB
Java
package com.ubt.jimu.connect.view;
|
|
|
|
import android.app.Dialog;
|
|
import android.bluetooth.BluetoothAdapter;
|
|
import android.bluetooth.BluetoothDevice;
|
|
import android.content.Context;
|
|
import android.content.DialogInterface;
|
|
import android.content.Intent;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.text.SpannableStringBuilder;
|
|
import android.text.TextUtils;
|
|
import android.text.style.ForegroundColorSpan;
|
|
import android.util.Log;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.animation.OvershootInterpolator;
|
|
import android.view.animation.TranslateAnimation;
|
|
import android.widget.AdapterView;
|
|
import android.widget.ArrayAdapter;
|
|
import android.widget.Button;
|
|
import android.widget.FrameLayout;
|
|
import android.widget.ImageView;
|
|
import android.widget.ListAdapter;
|
|
import android.widget.ListView;
|
|
import android.widget.ProgressBar;
|
|
import android.widget.RelativeLayout;
|
|
import android.widget.TextView;
|
|
import androidx.fragment.app.FragmentActivity;
|
|
import com.bumptech.glide.Glide;
|
|
import com.bumptech.glide.RequestBuilder;
|
|
import com.bumptech.glide.request.RequestOptions;
|
|
import com.ubt.jimu.R;
|
|
import com.ubt.jimu.base.HelpActivity;
|
|
import com.ubt.jimu.base.cache.Cache;
|
|
import com.ubt.jimu.base.cache.SharePreferenceHelper;
|
|
import com.ubt.jimu.base.dialog.UpdateDialog;
|
|
import com.ubt.jimu.blockly.exception.JimuConnectionException;
|
|
import com.ubt.jimu.connect.ConnectActivity;
|
|
import com.ubt.jimu.connect.contract.ConnectContract$Presenter;
|
|
import com.ubt.jimu.connect.contract.ConnectContract$View;
|
|
import com.ubt.jimu.widgets.NavigationBarView;
|
|
import com.ubtech.utils.DisplayUtil;
|
|
import com.ubtech.utils.XLog;
|
|
import com.ubtech.view.dialog.SimpleDialog;
|
|
import com.ubtech.view.fragment.BaseFragment;
|
|
import com.ubtrobot.jimu.bluetooth.base.discover.ScanResult;
|
|
import com.ubtrobot.jimu.robotapi.ServoAngleReadInfo;
|
|
import com.ubtrobot.log.ALog;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Comparator;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.Executors;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class ConnectFragment extends BaseFragment implements ConnectContract$View {
|
|
private Dialog A;
|
|
private boolean B;
|
|
private WaveView a;
|
|
private NavigationBarView b;
|
|
private ImageView c;
|
|
private ImageView d;
|
|
private ProgressBar e;
|
|
private RelativeLayout f;
|
|
private CircleProgressBar g;
|
|
private Button i;
|
|
private ListView j;
|
|
private RobotsScanedAdapter k;
|
|
private FrameLayout l;
|
|
private Dialog m;
|
|
private ExecutorService n;
|
|
private ConnectContract$Presenter p;
|
|
private String r;
|
|
private int s;
|
|
private String t;
|
|
private Handler u;
|
|
private SharePreferenceHelper x;
|
|
private int h = -10;
|
|
private List<ScanResult> o = new ArrayList();
|
|
private boolean q = false;
|
|
private Runnable v = new Runnable() { // from class: com.ubt.jimu.connect.view.ConnectFragment.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ALog.a("ConnectFragment").d("scan timeout. ListRobot.isEmpty:" + ConnectFragment.this.o.isEmpty());
|
|
if (ConnectFragment.this.o.isEmpty()) {
|
|
ConnectFragment.this.x();
|
|
} else {
|
|
ConnectFragment.this.q();
|
|
}
|
|
}
|
|
};
|
|
private volatile boolean y = false;
|
|
private Runnable z = new Runnable() { // from class: com.ubt.jimu.connect.view.ConnectFragment.7
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ConnectFragment.this.y = true;
|
|
if (ConnectFragment.this.isAdded() && !ConnectFragment.this.o.isEmpty()) {
|
|
ConnectFragment connectFragment = ConnectFragment.this;
|
|
if (connectFragment.j((List<ScanResult>) connectFragment.o)) {
|
|
return;
|
|
}
|
|
ConnectFragment.this.A();
|
|
}
|
|
}
|
|
};
|
|
|
|
class ProgressRunable implements Runnable {
|
|
ProgressRunable() {
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
while (ConnectFragment.this.h < 75 && ConnectFragment.this.h >= 0) {
|
|
ConnectFragment.this.h++;
|
|
ConnectFragment.this.g.setProgress(ConnectFragment.this.h);
|
|
try {
|
|
Thread.sleep(100L);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private class RobotsScanedAdapter extends ArrayAdapter {
|
|
private final int a;
|
|
|
|
public RobotsScanedAdapter(Context context, int i, List<ScanResult> list) {
|
|
super(context, i, list);
|
|
this.a = i;
|
|
}
|
|
|
|
@Override // android.widget.ArrayAdapter, android.widget.Adapter
|
|
public View getView(int i, View view, ViewGroup viewGroup) {
|
|
ScanResult scanResult = (ScanResult) getItem(i);
|
|
View inflate = LayoutInflater.from(getContext()).inflate(this.a, (ViewGroup) null);
|
|
ImageView imageView = (ImageView) inflate.findViewById(R.id.iv_robot_rssi);
|
|
TextView textView = (TextView) inflate.findViewById(R.id.tv_robot_name);
|
|
if (scanResult != null && scanResult.a() != null) {
|
|
String name = scanResult.a().getName();
|
|
if (TextUtils.isEmpty(name)) {
|
|
Log.e("ConnectFragment", "Device name is empty! show empty. deviceName:" + name);
|
|
} else {
|
|
Log.i("ConnectFragment", "DeviceName:" + name);
|
|
int i2 = 0;
|
|
if (name.toLowerCase().startsWith("My_Jimu_".toLowerCase())) {
|
|
i2 = 8;
|
|
} else if (name.toLowerCase().startsWith("Jimu_".toLowerCase())) {
|
|
i2 = 5;
|
|
}
|
|
if (i2 != 0) {
|
|
ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(ConnectFragment.this.getResources().getColor(R.color.color_txt_red));
|
|
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(name);
|
|
spannableStringBuilder.setSpan(foregroundColorSpan, i2, name.length(), 18);
|
|
textView.setText(spannableStringBuilder);
|
|
} else {
|
|
textView.setText(name);
|
|
}
|
|
}
|
|
imageView.setImageResource(ConnectFragment.this.e(scanResult.b()));
|
|
}
|
|
return inflate;
|
|
}
|
|
}
|
|
|
|
class SortByRssi implements Comparator {
|
|
SortByRssi(ConnectFragment connectFragment) {
|
|
}
|
|
|
|
@Override // java.util.Comparator
|
|
public int compare(Object obj, Object obj2) {
|
|
return ((ScanResult) obj).b() < ((ScanResult) obj2).b() ? 1 : -1;
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void A() {
|
|
if (getActivity() == null) {
|
|
return;
|
|
}
|
|
getActivity().runOnUiThread(new Runnable() { // from class: com.ubt.jimu.connect.view.ConnectFragment.8
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
if (ConnectFragment.this.p.m() != 0) {
|
|
Log.i("ConnectFragment", "Bluetooth not in scan state, not show robot scaned view");
|
|
return;
|
|
}
|
|
ConnectFragment.this.a.c();
|
|
ConnectFragment.this.a.setVisibility(8);
|
|
ConnectFragment.this.c.setVisibility(8);
|
|
if (ConnectFragment.this.j.getVisibility() != 0) {
|
|
TranslateAnimation translateAnimation = new TranslateAnimation(0.0f, 0.0f, 0.0f, ConnectFragment.this.d.getMeasuredHeight());
|
|
translateAnimation.setDuration(300L);
|
|
ConnectFragment.this.d.startAnimation(translateAnimation);
|
|
ConnectFragment.this.d.setVisibility(4);
|
|
}
|
|
ConnectFragment.this.e.setVisibility(0);
|
|
ConnectFragment.this.l.setVisibility(8);
|
|
ConnectFragment.this.f.setVisibility(8);
|
|
ConnectFragment.this.b.setTitle(R.string.select_jimu_model);
|
|
ConnectFragment.this.i.setVisibility(8);
|
|
ConnectFragment.this.j.setVisibility(0);
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public int e(int i) {
|
|
return i < -90 ? R.mipmap.signal1 : i < -80 ? R.mipmap.signal2 : i < -70 ? R.mipmap.signal3 : R.mipmap.signal4;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void x() {
|
|
ALog.a("ConnectFragment").d("gotoSearchFailPage");
|
|
String valueOf = String.valueOf(JimuConnectionException.NOT_FOUND_DEVICE.getType());
|
|
if (getActivity() == null) {
|
|
return;
|
|
}
|
|
String url = JimuConnectionException.getUrl(valueOf);
|
|
if (TextUtils.isEmpty(url)) {
|
|
return;
|
|
}
|
|
HelpActivity.startForResultFromFragment(101, this, getActivity(), url, " ", R.color.theme_background, false);
|
|
}
|
|
|
|
private void y() {
|
|
ALog.a("ConnectFragment").d("onNotConnect");
|
|
if (b()) {
|
|
this.i.setVisibility(0);
|
|
this.i.setText(R.string.click_to_scan);
|
|
this.i.setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.connect.view.ConnectFragment.3
|
|
@Override // android.view.View.OnClickListener
|
|
public void onClick(View view) {
|
|
if (ConnectFragment.this.p == null) {
|
|
Log.e("ConnectFragment", "Present is null");
|
|
return;
|
|
}
|
|
if (ConnectFragment.this.p.d()) {
|
|
Log.w("ConnectFragment", "Bluetooth connected, disconnect bluetooth.");
|
|
ConnectFragment.this.p.a();
|
|
}
|
|
ConnectFragment.this.p.k();
|
|
}
|
|
});
|
|
this.a.setVisibility(8);
|
|
this.a.c();
|
|
this.c.setVisibility(0);
|
|
this.d.setVisibility(8);
|
|
this.j.setVisibility(8);
|
|
this.e.setVisibility(8);
|
|
this.l.setVisibility(0);
|
|
this.f.setVisibility(8);
|
|
this.g.setVisibility(0);
|
|
this.h = -10;
|
|
this.g.setProgress(this.h);
|
|
this.b.setTitle(R.string.search_jimu_roobot);
|
|
this.b.setRightIvVisibility(4);
|
|
this.b.setListener(new NavigationBarView.OnActionClickListener() { // from class: com.ubt.jimu.connect.view.ConnectFragment.4
|
|
public void a(View view) {
|
|
ConnectFragment.this.d(0);
|
|
}
|
|
|
|
public void b(View view) {
|
|
ConnectFragment.this.p.k();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.NavigationBarView.OnActionClickListener
|
|
public void onClick(View view) {
|
|
int id = view.getId();
|
|
if (id == R.id.iv_left) {
|
|
a(view);
|
|
} else if (id == R.id.iv_right || id == R.id.tv_right) {
|
|
b(view);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.connect.contract.ConnectContract$View
|
|
public void G() {
|
|
ALog.a("ConnectFragment").d("onShowNotAnyPeripherals");
|
|
if (b() && getActivity() != null) {
|
|
getActivity().runOnUiThread(new Runnable() { // from class: com.ubt.jimu.connect.view.ConnectFragment.16
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
SimpleDialog.Builder builder = new SimpleDialog.Builder(ConnectFragment.this.getContext());
|
|
builder.a((CharSequence) ConnectFragment.this.getString(R.string.err_msg_not_any_peripheral)).b(ConnectFragment.this.getString(R.string.retry)).b(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.connect.view.ConnectFragment.16.1
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
dialogInterface.dismiss();
|
|
ConnectFragment.this.p.k();
|
|
}
|
|
});
|
|
builder.a().show();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.connect.contract.ConnectContract$View
|
|
public void J() {
|
|
if (b() && getActivity() != null) {
|
|
getActivity().runOnUiThread(new Runnable() { // from class: com.ubt.jimu.connect.view.ConnectFragment.13
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ConnectFragment.this.e.setVisibility(8);
|
|
ConnectFragment.this.j.setVisibility(4);
|
|
ConnectFragment.this.l.setVisibility(8);
|
|
ConnectFragment.this.l.setVisibility(0);
|
|
ConnectFragment.this.c.setVisibility(0);
|
|
ConnectFragment.this.l.setVisibility(0);
|
|
ConnectFragment.this.f.setVisibility(8);
|
|
ConnectFragment.this.g.setVisibility(0);
|
|
ConnectFragment.this.h = 85;
|
|
ConnectFragment.this.g.setProgress(ConnectFragment.this.h);
|
|
ConnectFragment.this.b.setTitle(R.string.connecting_to_jimu);
|
|
ConnectFragment.this.b.setListener(new NavigationBarView.OnActionClickListener() { // from class: com.ubt.jimu.connect.view.ConnectFragment.13.1
|
|
public void a(View view) {
|
|
ConnectFragment.this.h = -10;
|
|
ConnectFragment.this.g.setProgress(ConnectFragment.this.h);
|
|
ConnectFragment.this.p.a();
|
|
ConnectFragment.this.p.b(false);
|
|
ConnectFragment.this.p.k();
|
|
}
|
|
|
|
public void b(View view) {
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.NavigationBarView.OnActionClickListener
|
|
public void onClick(View view) {
|
|
int id = view.getId();
|
|
if (id == R.id.iv_left) {
|
|
a(view);
|
|
} else if (id == R.id.iv_right || id == R.id.tv_right) {
|
|
b(view);
|
|
}
|
|
}
|
|
});
|
|
ConnectFragment.this.i.setVisibility(8);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.connect.contract.ConnectContract$View
|
|
public void O() {
|
|
ALog.a("ConnectFragment").d("onPeripheralsTooMuchForModifyId");
|
|
if (b() && getActivity() != null) {
|
|
getActivity().runOnUiThread(new Runnable() { // from class: com.ubt.jimu.connect.view.ConnectFragment.14
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
SimpleDialog.Builder builder = new SimpleDialog.Builder(ConnectFragment.this.getContext());
|
|
builder.a((CharSequence) ConnectFragment.this.getString(R.string.err_msg_only_can_modify)).b(ConnectFragment.this.getString(R.string.retry)).b(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.connect.view.ConnectFragment.14.1
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
dialogInterface.dismiss();
|
|
ConnectFragment.this.p.k();
|
|
}
|
|
});
|
|
builder.a().show();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.connect.contract.ConnectContract$View
|
|
public void R() {
|
|
if (BluetoothAdapter.getDefaultAdapter().isEnabled()) {
|
|
return;
|
|
}
|
|
startActivityForResult(new Intent("android.bluetooth.adapter.action.REQUEST_ENABLE"), 102);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.connect.contract.ConnectContract$View
|
|
public void U() {
|
|
if (b() && getActivity() != null) {
|
|
getActivity().runOnUiThread(new Runnable() { // from class: com.ubt.jimu.connect.view.ConnectFragment.6
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
Log.e("ConnectFragment", "onScanStart");
|
|
ConnectFragment.this.y = false;
|
|
ConnectFragment.this.o.clear();
|
|
ConnectFragment.this.k.notifyDataSetChanged();
|
|
ConnectFragment.this.u.removeCallbacks(ConnectFragment.this.v);
|
|
ConnectFragment.this.u.postDelayed(ConnectFragment.this.v, 20000L);
|
|
ConnectFragment.this.u.removeCallbacks(ConnectFragment.this.z);
|
|
ConnectFragment.this.u.postDelayed(ConnectFragment.this.z, 2500L);
|
|
ConnectFragment.this.i.setVisibility(8);
|
|
ConnectFragment.this.a.setVisibility(0);
|
|
ConnectFragment.this.a.b();
|
|
ConnectFragment.this.c.setVisibility(0);
|
|
ConnectFragment.this.d.setVisibility(0);
|
|
ConnectFragment.this.d.post(new Runnable() { // from class: com.ubt.jimu.connect.view.ConnectFragment.6.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
TranslateAnimation translateAnimation = new TranslateAnimation(0.0f, 0.0f, ConnectFragment.this.d.getMeasuredHeight(), 0.0f);
|
|
translateAnimation.setDuration(1000L);
|
|
translateAnimation.setInterpolator(new OvershootInterpolator());
|
|
ConnectFragment.this.d.startAnimation(translateAnimation);
|
|
}
|
|
});
|
|
ConnectFragment.this.j.setVisibility(8);
|
|
ConnectFragment.this.e.setVisibility(8);
|
|
ConnectFragment.this.l.setVisibility(0);
|
|
ConnectFragment.this.f.setVisibility(8);
|
|
ConnectFragment.this.g.setVisibility(0);
|
|
ConnectFragment.this.h = -10;
|
|
ConnectFragment.this.g.setProgress(ConnectFragment.this.h);
|
|
ConnectFragment.this.b.setTitle(R.string.search_for_jimu);
|
|
ConnectFragment.this.b.setRightIvSrc(R.mipmap.rescan);
|
|
ConnectFragment.this.b.setListener(new NavigationBarView.OnActionClickListener() { // from class: com.ubt.jimu.connect.view.ConnectFragment.6.2
|
|
public void a(View view) {
|
|
ConnectFragment.this.d(0);
|
|
}
|
|
|
|
public void b(View view) {
|
|
ConnectFragment.this.p.k();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.NavigationBarView.OnActionClickListener
|
|
public void onClick(View view) {
|
|
int id = view.getId();
|
|
if (id == R.id.iv_left) {
|
|
a(view);
|
|
} else if (id == R.id.iv_right || id == R.id.tv_right) {
|
|
b(view);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.connect.contract.ConnectContract$View
|
|
public void Y() {
|
|
ALog.a("ConnectFragment").d("onShowForbitChangeId");
|
|
if (b() && getActivity() != null) {
|
|
getActivity().runOnUiThread(new Runnable() { // from class: com.ubt.jimu.connect.view.ConnectFragment.15
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
SimpleDialog.Builder builder = new SimpleDialog.Builder(ConnectFragment.this.getContext());
|
|
builder.a((CharSequence) ConnectFragment.this.getString(R.string.forbit_modify_component_id)).b(ConnectFragment.this.getString(R.string.retry)).b(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.connect.view.ConnectFragment.15.1
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
dialogInterface.dismiss();
|
|
ConnectFragment.this.p.k();
|
|
}
|
|
});
|
|
builder.a().show();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
public boolean b() {
|
|
return true;
|
|
}
|
|
|
|
@Override // com.ubt.jimu.connect.contract.ConnectContract$View
|
|
public void b0() {
|
|
Log.i("ConnectFragment", "onConnectFail");
|
|
this.u.removeCallbacks(this.z);
|
|
this.u.removeCallbacks(this.v);
|
|
if (b() && getActivity() != null) {
|
|
getActivity().runOnUiThread(new Runnable() { // from class: com.ubt.jimu.connect.view.ConnectFragment.12
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ConnectFragment.this.a.setVisibility(8);
|
|
ConnectFragment.this.a.c();
|
|
ConnectFragment.this.e.setVisibility(8);
|
|
ConnectFragment.this.j.setVisibility(4);
|
|
ConnectFragment.this.l.setVisibility(0);
|
|
ConnectFragment.this.f.setVisibility(0);
|
|
ConnectFragment.this.c.setVisibility(0);
|
|
ConnectFragment.this.d.setVisibility(8);
|
|
ConnectFragment.this.g.setVisibility(8);
|
|
ConnectFragment.this.h = -10;
|
|
ConnectFragment.this.g.setProgress(ConnectFragment.this.h);
|
|
ConnectFragment.this.b.setTitle(R.string.connect_fail);
|
|
ConnectFragment.this.b.setRightIvSrc(R.mipmap.connect_help);
|
|
ConnectFragment.this.b.setRightIvVisibility(0);
|
|
ConnectFragment.this.b.setListener(new NavigationBarView.OnActionClickListener() { // from class: com.ubt.jimu.connect.view.ConnectFragment.12.1
|
|
public void a(View view) {
|
|
ConnectFragment.this.d(0);
|
|
}
|
|
|
|
public void b(View view) {
|
|
ConnectFragment.this.v();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.NavigationBarView.OnActionClickListener
|
|
public void onClick(View view) {
|
|
int id = view.getId();
|
|
if (id == R.id.iv_left) {
|
|
a(view);
|
|
} else if (id == R.id.iv_right || id == R.id.tv_right) {
|
|
b(view);
|
|
}
|
|
}
|
|
});
|
|
ConnectFragment.this.i.setText(R.string.reconnect);
|
|
ConnectFragment.this.i.setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.connect.view.ConnectFragment.12.2
|
|
@Override // android.view.View.OnClickListener
|
|
public void onClick(View view) {
|
|
ConnectFragment.this.p.k();
|
|
}
|
|
});
|
|
ConnectFragment.this.i.setVisibility(0);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
public void o() {
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onActivityResult(int i, int i2, Intent intent) {
|
|
XLog.a("ConnectFragment", "onActivityResult requestCode:" + i + " resultCode:" + i2);
|
|
if (i == 102) {
|
|
if (i2 == -1) {
|
|
ALog.a("ConnectFragment").d("BlueTooth is now Enabled");
|
|
ConnectContract$Presenter connectContract$Presenter = this.p;
|
|
if (connectContract$Presenter != null) {
|
|
connectContract$Presenter.p();
|
|
}
|
|
}
|
|
if (i2 == 0) {
|
|
ALog.a("ConnectFragment").d("Error occured while enabling.");
|
|
o();
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
if (i == 103) {
|
|
ConnectContract$Presenter connectContract$Presenter2 = this.p;
|
|
if (connectContract$Presenter2 != null) {
|
|
connectContract$Presenter2.k();
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
if (i == 101) {
|
|
ConnectContract$Presenter connectContract$Presenter3 = this.p;
|
|
if (connectContract$Presenter3 != null) {
|
|
connectContract$Presenter3.k();
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
if (i != 100) {
|
|
return;
|
|
}
|
|
if (this.p == null) {
|
|
d(i2);
|
|
return;
|
|
}
|
|
if (i2 != -1) {
|
|
XLog.a("ConnectFragment", "Match fail, scan robot");
|
|
if (this.p.d()) {
|
|
Log.w("ConnectFragment", "Bluetooth connected, disconnect bluetooth.");
|
|
this.p.a();
|
|
}
|
|
this.p.r();
|
|
d(0);
|
|
return;
|
|
}
|
|
XLog.a("ConnectFragment", "Match success, back to busiess page.");
|
|
BluetoothDevice l = this.p.l();
|
|
if (l != null && l.getAddress() != null) {
|
|
this.p.c(l.getAddress(), this.r);
|
|
}
|
|
this.p.a(getContext(), Cache.getInstance().getBoardInfo(), this.r, this.q);
|
|
d(-1);
|
|
}
|
|
|
|
@Override // com.ubtech.view.fragment.BaseFragment, androidx.fragment.app.Fragment
|
|
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
|
|
String str;
|
|
ALog.a("ConnectFragment").d("onCreateView");
|
|
this.u = new Handler();
|
|
this.x = new SharePreferenceHelper();
|
|
this.n = Executors.newSingleThreadExecutor();
|
|
Bundle arguments = getArguments();
|
|
if (arguments != null) {
|
|
str = arguments.getString("KEY_PIC_PATH");
|
|
this.q = arguments.getBoolean("KEY_IS_DIY_MODEL", false);
|
|
this.r = arguments.getString("KEY_MODEL_ID", "");
|
|
this.s = arguments.getInt("KEY_MODEL_CODE", -10);
|
|
this.t = arguments.getString("KEY_MODEL_NAME", "");
|
|
} else {
|
|
Log.i("ConnectFragment", "Not bundle arguments");
|
|
str = null;
|
|
}
|
|
View a = a(layoutInflater, str);
|
|
y();
|
|
ConnectContract$Presenter connectContract$Presenter = this.p;
|
|
if (connectContract$Presenter == null) {
|
|
Log.e("ConnectFragment", "Present is null");
|
|
return a;
|
|
}
|
|
connectContract$Presenter.a(this.q);
|
|
this.p.a(this.s);
|
|
if (this.p.d()) {
|
|
Log.w("ConnectFragment", "Bluetooth connected, disconnect bluetooth.");
|
|
this.p.a();
|
|
}
|
|
this.p.k();
|
|
return a;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onDestroyView() {
|
|
this.a.c();
|
|
ConnectContract$Presenter connectContract$Presenter = this.p;
|
|
if (connectContract$Presenter != null) {
|
|
connectContract$Presenter.q();
|
|
}
|
|
Dialog dialog = this.m;
|
|
if (dialog != null && dialog.isShowing()) {
|
|
this.m.dismiss();
|
|
}
|
|
this.m = null;
|
|
this.n.shutdown();
|
|
this.u.removeCallbacks(this.v);
|
|
this.u.removeCallbacks(this.z);
|
|
this.u.removeCallbacksAndMessages(null);
|
|
super.onDestroyView();
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onResume() {
|
|
ALog.a("ConnectFragment").d("onResume");
|
|
super.onResume();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.connect.contract.ConnectContract$View
|
|
public void z() {
|
|
if (isAdded() && Build.VERSION.SDK_INT >= 23) {
|
|
if (this.A == null) {
|
|
this.A = new SimpleDialog.Builder(getActivity()).a(false).a((CharSequence) getResources().getString(R.string.not_open_gps_tips)).b(getResources().getString(R.string.goto_setting)).a(getResources().getString(R.string.cancel), true).a(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.connect.view.ConnectFragment.19
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
dialogInterface.dismiss();
|
|
ALog.a("ConnectFragment").d("dismiss setting dialog");
|
|
ConnectFragment.this.B = false;
|
|
}
|
|
}).b(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.connect.view.ConnectFragment.18
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
dialogInterface.dismiss();
|
|
ConnectFragment.this.B = false;
|
|
ConnectFragment.this.startActivityForResult(new Intent("android.settings.LOCATION_SOURCE_SETTINGS"), 103);
|
|
}
|
|
}).a();
|
|
}
|
|
if (!this.A.isShowing()) {
|
|
this.A.show();
|
|
}
|
|
ALog.a("ConnectFragment").d("show setting dialog");
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void d(int i) {
|
|
FragmentActivity activity = getActivity();
|
|
if (b() && activity != null) {
|
|
if (activity instanceof ConnectActivity) {
|
|
((ConnectActivity) activity).l(i);
|
|
} else {
|
|
Log.e("ConnectFragment", "Should not to this!");
|
|
activity.finish();
|
|
}
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public boolean j(List<ScanResult> list) {
|
|
String string;
|
|
if (this.y && this.p.g() && (string = this.x.getString(this.r, null)) != null) {
|
|
for (ScanResult scanResult : list) {
|
|
if (string.equals(scanResult.a().getAddress())) {
|
|
ALog.a("ConnectFragment").d("Auto connect to mac " + string);
|
|
this.p.a(scanResult.a());
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void v() {
|
|
ALog.a("ConnectFragment").d("gotoConnectFailPage");
|
|
c(String.valueOf(JimuConnectionException.CONNECT_FAIL.getType()));
|
|
}
|
|
|
|
public /* synthetic */ void h(final List list) {
|
|
if (this.m == null) {
|
|
UpdateDialog.Builder builder = new UpdateDialog.Builder();
|
|
builder.backAble(false).canceledOnTouchOutside(false).title(getString(R.string.hand_damp_warming)).content(getString(R.string.hand_damp_warming_tips)).ok(getString(R.string.ok)).interactionListener(new UpdateDialog.InteractionListner() { // from class: com.ubt.jimu.connect.view.ConnectFragment.17
|
|
@Override // com.ubt.jimu.base.dialog.UpdateDialog.InteractionListner
|
|
public void onCancelClick(UpdateDialog updateDialog) {
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.dialog.UpdateDialog.InteractionListner
|
|
public void onLeftImgClick(UpdateDialog updateDialog) {
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.dialog.UpdateDialog.InteractionListner
|
|
public void onOkClick(UpdateDialog updateDialog) {
|
|
if (ConnectFragment.this.p != null) {
|
|
ConnectFragment.this.p.a(list);
|
|
}
|
|
updateDialog.dismiss();
|
|
ConnectFragment.this.c(-1);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.dialog.UpdateDialog.InteractionListner
|
|
public void onRightImgClick(UpdateDialog updateDialog) {
|
|
}
|
|
});
|
|
this.m = new UpdateDialog(getActivity(), builder);
|
|
this.m.setCancelable(false);
|
|
}
|
|
if (!b() || this.m.isShowing()) {
|
|
return;
|
|
}
|
|
this.m.show();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.connect.contract.ConnectContract$View
|
|
public void i() {
|
|
this.u.removeCallbacks(this.v);
|
|
this.u.removeCallbacks(this.z);
|
|
if (b() && getActivity() != null) {
|
|
getActivity().runOnUiThread(new Runnable() { // from class: com.ubt.jimu.connect.view.ConnectFragment.11
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ConnectFragment.this.e.setVisibility(8);
|
|
ConnectFragment.this.j.setVisibility(4);
|
|
ConnectFragment.this.a.c();
|
|
ConnectFragment.this.a.setVisibility(8);
|
|
ConnectFragment.this.i.setVisibility(8);
|
|
ConnectFragment.this.c.setVisibility(0);
|
|
ConnectFragment.this.l.setVisibility(0);
|
|
ConnectFragment.this.f.setVisibility(8);
|
|
ConnectFragment.this.h = 0;
|
|
ConnectFragment.this.g.setVisibility(0);
|
|
ConnectFragment.this.d.setVisibility(0);
|
|
TranslateAnimation translateAnimation = new TranslateAnimation(0.0f, 0.0f, ConnectFragment.this.d.getMeasuredHeight(), 0.0f);
|
|
translateAnimation.setDuration(500L);
|
|
translateAnimation.setInterpolator(new OvershootInterpolator());
|
|
ConnectFragment.this.d.startAnimation(translateAnimation);
|
|
ConnectFragment.this.n.execute(ConnectFragment.this.new ProgressRunable());
|
|
ConnectFragment.this.b.setTitle(R.string.connecting_to_jimu);
|
|
ConnectFragment.this.b.setRightIvVisibility(8);
|
|
ConnectFragment.this.b.setListener(new NavigationBarView.OnActionClickListener() { // from class: com.ubt.jimu.connect.view.ConnectFragment.11.1
|
|
public void a(View view) {
|
|
ConnectFragment.this.h = -10;
|
|
ConnectFragment.this.g.setProgress(ConnectFragment.this.h);
|
|
ConnectFragment.this.p.a();
|
|
ConnectFragment.this.p.b(false);
|
|
ConnectFragment.this.p.k();
|
|
}
|
|
|
|
public void b(View view) {
|
|
}
|
|
|
|
@Override // com.ubt.jimu.widgets.NavigationBarView.OnActionClickListener
|
|
public void onClick(View view) {
|
|
int id = view.getId();
|
|
if (id == R.id.iv_left) {
|
|
a(view);
|
|
} else if (id == R.id.iv_right || id == R.id.tv_right) {
|
|
b(view);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
public void q() {
|
|
if (getActivity() != null) {
|
|
getActivity().runOnUiThread(new Runnable() { // from class: com.ubt.jimu.connect.view.ConnectFragment.10
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ConnectFragment.this.e.setVisibility(8);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
private void c(String str) {
|
|
if (getActivity() == null) {
|
|
return;
|
|
}
|
|
String url = JimuConnectionException.getUrl(str);
|
|
if (TextUtils.isEmpty(url)) {
|
|
return;
|
|
}
|
|
HelpActivity.start(getActivity(), url, " ", R.color.theme_background, false);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.connect.contract.ConnectContract$View
|
|
public void a(ConnectContract$Presenter connectContract$Presenter) {
|
|
this.p = connectContract$Presenter;
|
|
}
|
|
|
|
private View a(LayoutInflater layoutInflater, String str) {
|
|
View inflate = layoutInflater.inflate(R.layout.frag_connect, (ViewGroup) null);
|
|
this.l = (FrameLayout) inflate.findViewById(R.id.fl_connect_state);
|
|
this.l.setVisibility(0);
|
|
this.g = (CircleProgressBar) inflate.findViewById(R.id.pb_connecting);
|
|
this.e = (ProgressBar) inflate.findViewById(R.id.pb_progress);
|
|
this.i = (Button) inflate.findViewById(R.id.btn_multi_function);
|
|
this.f = (RelativeLayout) inflate.findViewById(R.id.rl_connect_fail);
|
|
this.d = (ImageView) inflate.findViewById(R.id.iv_connect_hand);
|
|
this.b = (NavigationBarView) inflate.findViewById(R.id.nbv_bar);
|
|
this.b.setLeftIvSrc(R.drawable.community_cancel);
|
|
this.c = (ImageView) inflate.findViewById(R.id.iv_robot);
|
|
FragmentActivity activity = getActivity();
|
|
if (activity == null) {
|
|
return inflate;
|
|
}
|
|
RequestOptions N = RequestOptions.N();
|
|
N.a(Integer.MIN_VALUE, Integer.MIN_VALUE);
|
|
if (!TextUtils.isEmpty(str)) {
|
|
RequestBuilder<Drawable> a = Glide.a(this).a(str);
|
|
a.a(N);
|
|
a.a(this.c);
|
|
} else {
|
|
RequestBuilder<Drawable> d = Glide.a(this).d(activity.getResources().getDrawable(R.drawable.controller_small, null));
|
|
d.a(RequestOptions.P());
|
|
d.a(this.c);
|
|
}
|
|
this.a = (WaveView) inflate.findViewById(R.id.wave);
|
|
int a2 = DisplayUtil.a((Context) activity, R.dimen.searching_wave_width);
|
|
int a3 = DisplayUtil.a((Context) activity, R.dimen.searching_wave_image_radius);
|
|
int a4 = DisplayUtil.a((Context) activity, R.dimen.searching_wave_max_radius);
|
|
this.a.setWidth(a2);
|
|
this.a.setImageRadius(a3);
|
|
this.a.setMaxRadius(a4);
|
|
this.a.setFill(false);
|
|
this.a.a();
|
|
this.j = (ListView) inflate.findViewById(R.id.lv_robots_scaned);
|
|
this.k = new RobotsScanedAdapter(getContext(), R.layout.item_robot_info_scaned, this.o);
|
|
this.j.setAdapter((ListAdapter) this.k);
|
|
this.j.setOnItemClickListener(new AdapterView.OnItemClickListener() { // from class: com.ubt.jimu.connect.view.ConnectFragment.2
|
|
@Override // android.widget.AdapterView.OnItemClickListener
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
|
|
ScanResult scanResult = (ScanResult) ConnectFragment.this.o.get(i);
|
|
if (scanResult == null || scanResult.a() == null) {
|
|
return;
|
|
}
|
|
if (scanResult.a().getAddress() == null) {
|
|
Log.e("ConnectFragment", "click an device that address is null!");
|
|
return;
|
|
}
|
|
ConnectFragment.this.o.clear();
|
|
ConnectFragment.this.k.notifyDataSetChanged();
|
|
ConnectFragment.this.p.a(scanResult.a());
|
|
}
|
|
});
|
|
return inflate;
|
|
}
|
|
|
|
@Override // com.ubt.jimu.connect.contract.ConnectContract$View
|
|
public void c(int i) {
|
|
ALog.a("ConnectFragment").d("onBackToBusinessPage");
|
|
d(i);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.connect.contract.ConnectContract$View
|
|
public void a(final ScanResult scanResult) {
|
|
if (!b() || scanResult.a() == null || TextUtils.isEmpty(scanResult.a().getName()) || getActivity() == null) {
|
|
return;
|
|
}
|
|
getActivity().runOnUiThread(new Runnable() { // from class: com.ubt.jimu.connect.view.ConnectFragment.9
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ALog.a("ConnectFragment").d("scaned robot:" + scanResult.a().getAddress());
|
|
Iterator it = ConnectFragment.this.o.iterator();
|
|
while (it.hasNext()) {
|
|
ScanResult scanResult2 = (ScanResult) it.next();
|
|
if (TextUtils.isEmpty(scanResult2.a().getName())) {
|
|
it.remove();
|
|
} else if (scanResult.a().getName().equals(scanResult2.a().getName())) {
|
|
return;
|
|
}
|
|
}
|
|
ConnectFragment.this.o.add(scanResult);
|
|
ConnectFragment.this.k.notifyDataSetChanged();
|
|
ConnectFragment connectFragment = ConnectFragment.this;
|
|
if (connectFragment.j((List<ScanResult>) connectFragment.o)) {
|
|
return;
|
|
}
|
|
ALog.a("ConnectFragment").d("sort scaned robot by RSSI!");
|
|
Collections.sort(ConnectFragment.this.o, new SortByRssi(ConnectFragment.this));
|
|
ConnectFragment.this.k.notifyDataSetChanged();
|
|
if (ConnectFragment.this.y) {
|
|
ConnectFragment.this.A();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override // com.ubt.jimu.connect.contract.ConnectContract$View
|
|
public void a(String str, boolean z) {
|
|
ALog.a("ConnectFragment").d("onMatchErrorOrNeedUpdate");
|
|
this.h = 100;
|
|
this.g.setProgress(this.h);
|
|
if (getContext() == null) {
|
|
return;
|
|
}
|
|
Intent intent = new Intent(getContext(), (Class<?>) ComponentsListActivity.class);
|
|
intent.putExtra("KEY_IS_DIY_MODEL", z);
|
|
intent.putExtra("KEY_MODEL_ID", str);
|
|
intent.putExtra("KEY_MODEL_NAME", this.t);
|
|
if (this.p.l() != null) {
|
|
intent.putExtra("KEY_DEVICE_NAME", this.p.l().getName());
|
|
}
|
|
startActivityForResult(intent, 100);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.connect.contract.ConnectContract$View
|
|
public void a(final List<ServoAngleReadInfo> list) {
|
|
if (list == null || list.size() == 0 || !b() || getActivity() == null) {
|
|
return;
|
|
}
|
|
getActivity().runOnUiThread(new Runnable() { // from class: com.ubt.jimu.connect.view.l
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
ConnectFragment.this.h(list);
|
|
}
|
|
});
|
|
}
|
|
}
|