绑定跳转问题

This commit is contained in:
jia 2024-09-22 15:18:36 +08:00
parent 2cf9e2feda
commit 1e0ab35f46
4 changed files with 347 additions and 618 deletions

View File

@ -5,7 +5,6 @@ import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.content.DialogInterface;
@ -18,10 +17,10 @@ import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
@ -35,7 +34,6 @@ import com.clj.fastble.callback.BleScanCallback;
import com.clj.fastble.callback.BleWriteCallback;
import com.clj.fastble.data.BleDevice;
import com.clj.fastble.exception.BleException;
import com.clj.fastble.scan.BleScanRuleConfig;
import com.ifish.activity.BindCameraActivity;
import com.ifish.activity.BindTankActivity;
import com.ifish.activity.BindTankPetActivity;
@ -66,7 +64,6 @@ import com.ifish.tcp.BackFunctionCode7_11;
import com.ifish.tcp.ModelCodec;
import com.ifish.tcp.OrderDeviceConnectModel;
import com.ifish.tcp.OrderModel;
import com.ifish.tcp.QueryTempeSettingModel;
import com.ifish.tcp.ResetDeviceModel;
import com.ifish.utils.ActivityManager;
import com.ifish.utils.AnimationUtil;
@ -74,7 +71,6 @@ import com.ifish.utils.BlueToothUtil;
import com.ifish.utils.ByteUtil;
import com.ifish.utils.ClickUtil;
import com.ifish.utils.Commons;
import com.ifish.utils.DialogUtil;
import com.ifish.utils.HttpListener;
import com.ifish.utils.HttpManager;
import com.ifish.utils.L;
@ -86,7 +82,6 @@ import com.lidroid.xutils.util.LogUtils;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;
import java.util.UUID;
import de.greenrobot.event.EventBus;
@ -109,6 +104,8 @@ public class NewBindDeviceActivity extends AppCompatActivity {
private TextView tvOtherConnect;
private TextView tvClickButton;
private TextView tvConnectVideo;
private RelativeLayout layoutLoading;
private TextView dialogHint;
private int nofity_type = 0;
@ -216,6 +213,8 @@ public class NewBindDeviceActivity extends AppCompatActivity {
tvTips3 = (TextView) findViewById(R.id.tv_tips3);
tvOtherConnect = (TextView) findViewById(R.id.tv_other_connect);
tvClickButton = (TextView) findViewById(R.id.tv_click_button);
layoutLoading = (RelativeLayout) findViewById(R.id.layout_loading);
dialogHint = (TextView) findViewById(R.id.tv_hint);
}
@ -434,8 +433,7 @@ public class NewBindDeviceActivity extends AppCompatActivity {
if (TextUtils.isEmpty(type)){
blueScan();
}else {
DialogUtil.Companion.showLoadingDialog(activity,true,"开始连接蓝牙设备");
// showProgressDialogCancelble("开始连接蓝牙设备");
showDialog("开始连接蓝牙设备");
connectBle();
}
}else {
@ -483,16 +481,14 @@ public class NewBindDeviceActivity extends AppCompatActivity {
connectBle();
}else {
ToastUtil.show(NewBindDeviceActivity.this,"扫描结束,没有搜索到可用设备");
// dismissProgressDialogCancelble();
DialogUtil.Companion.setLoadingDialogDismiss(activity);
dismissDialog();
}
}
@Override
public void onScanStarted(boolean success) {
// ToastUtil.show(NewBindDeviceActivity.this,"开始扫描");
DialogUtil.Companion.showLoadingDialog(activity,true,"正在搜索附近设备,请确保设备处于配网状态");
// showProgressDialogCancelble("正在搜索附近设备,请确保设备处于配网状态");
showDialog("正在搜索附近设备,请确保设备处于配网状态");
}
@SuppressLint("MissingPermission")
@ -601,7 +597,7 @@ public class NewBindDeviceActivity extends AppCompatActivity {
@Override
public void onNotifyFailure(BleException exception) {
// dismissProgressDialogCancelble();
DialogUtil.Companion.setLoadingDialogDismiss(activity);
dismissDialog();
}
@Override
@ -621,25 +617,14 @@ public class NewBindDeviceActivity extends AppCompatActivity {
String status = ByteUtil.toHex(model.getStatus());
device_mac = ByteUtil.bytesToHexString(model.getSrc());
DialogUtil.Companion.setLoadingDialogDismiss(activity);
dismissDialog();
if (!TextUtils.isEmpty(device_mac)){
// dismissProgressDialogCancelble();
DialogUtil.Companion.setLoadingDialogDismiss(activity);
// showProgressDialogCancelble("正在绑定设备,请稍等...");
DialogUtil.Companion.showLoadingDialog(activity,true,"正在绑定设备...");
showDialog("正在绑定设备...");
connectDevice.cancel();
connectDevice.start();
}
// checkoutMac(device_mac);
} else {
DialogUtil.Companion.setLoadingDialogDismiss(activity);
// dismissProgressDialogCancelble();
// BackFunctionCode7_11 model = (BackFunctionCode7_11) object;
// String status = ByteUtil.toHex(model.getStatus());
// if ("01".equals(status)) {
// L.i("jjia-------重启成功-"+status);
// }
}
L.i("jjia-------check_code-"+check_code);
L.i("jjia-------length-"+length);
@ -649,54 +634,6 @@ public class NewBindDeviceActivity extends AppCompatActivity {
});
}
// private void checkoutMac(String mac){
//
// if (!TextUtils.isEmpty(mac)){
// boolean isSameName = false;
// devicePosition = 0;
// try {
// if (Commons.DEVICE != null) {
// if (Commons.DEVICE.size() != 0) {
// for (int i = 0; i < Commons.DEVICE.size(); i++) {
// if (mac.equals(Commons.DEVICE.get(i).getMacAddress())) {
// devicePosition = i;
// isSameName = true;
// break;
// }
// }
// }
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
//
//
// if (isSameName){
// L.i("jjia-------------不包含");
// runOnUiThread(new Runnable() {
// @Override
// public void run() {
// resetDevice(1);
// }
// });
// }else {
// L.i("jjia-------------不包含");
// runOnUiThread(new Runnable() {
// @Override
// public void run() {
// isContinue = true;
// resetDevice(2);
// }
// });
// }
// }else {
// dismissProgressDialogCancelble();
// }
//
//
//
//
// }
int devicePosition = 0;
private void sendBleData(){
@ -737,39 +674,8 @@ public class NewBindDeviceActivity extends AppCompatActivity {
}
});
}
private void resetDevice(int type){
DialogUtil.Companion.setLoadingDialogDismiss(activity);
if (1==type){
toDevice();
}else if (2==type){
connectDevice.cancel();
connectDevice.start();
}
// ResetDeviceModel model = OrderModel.resetDevice();//设置正式环境域名
// byte[] data = ModelCodec.enCode(model);//解析数据
// L.i("jjia----------------开始重启设备"+type);
// BleManager.getInstance().write(currentDevice, SERVICE_UUID, WRITE_UUID, data,false, new BleWriteCallback() {
// @Override
// public void onWriteSuccess(int current, int total, byte[] justWrite) {
//
// L.i("jjia----------------设备重启成功");
// if (1==type){
// toDevice();
// }else if (2==type){
// connectDevice.cancel();
// connectDevice.start();
// }
// }
//
// @Override
// public void onWriteFailure(BleException exception) {
// L.i("jjia----------------设备重启写失败");
// }
// });
}
public static final String SERVICE_UUID = "000000ff-0000-1000-8000-00805f9b34fb"; //蓝牙通讯服务
public static final String READ_UUID = "0000ff01-0000-1000-8000-00805f9b34fb"; //读特征
public static final String WRITE_UUID = "0000ff01-0000-1000-8000-00805f9b34fb"; //写特征
@ -778,13 +684,13 @@ public class NewBindDeviceActivity extends AppCompatActivity {
BleManager.getInstance().connect(currentDevice, new BleGattCallback() {
@Override
public void onStartConnect() {
DialogUtil.Companion.showLoadingDialog(activity,true,"开始连接蓝牙设备");
showDialog("开始连接蓝牙设备");
}
@Override
public void onConnectFail(BleDevice bleDevice, BleException exception) {
ToastUtil.show(NewBindDeviceActivity.this,"连接蓝牙设备失败,请重试");
DialogUtil.Companion.setLoadingDialogDismiss(activity);
dismissDialog();
}
@Override
@ -795,7 +701,7 @@ public class NewBindDeviceActivity extends AppCompatActivity {
@Override
public void onSetMTUFailure(BleException exception) {
L.i("jjia-------MTU--"+exception.toString());
DialogUtil.Companion.setLoadingDialogDismiss(activity);
dismissDialog();
}
@Override
@ -812,14 +718,274 @@ public class NewBindDeviceActivity extends AppCompatActivity {
}
});
}
private Activity act;
private ConnectDevice connectDevice;
private boolean isContinue = true;
public class ConnectDevice extends CountDownTimer {
public void toDevice() {
public ConnectDevice(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onTick(long millisUntilFinished) {
long sum = millisUntilFinished / 1000 % 2;
if (sum == 0) {
if (!act.isFinishing() && isContinue) {
isNetWorkAvailable("www.baidu.com", new Comparable<Boolean>() {
@Override
public int compareTo(Boolean available) {
if (available) {
toReset();
isContinue = false;
connectDevice.cancel();
L.i("jjia-----------调用绑定接口---");
doPostBindDevice();
}
return 0;
}
});
}
}
}
@Override
public void onFinish() {
if (isContinue) {
dismissDialog();
}
}
}
public static void isNetWorkAvailable(final String address, final Comparable<Boolean> callback) {
final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (callback != null) {
callback.compareTo(msg.arg1 == 0);
}
}
};
new Thread(new Runnable() {
@Override
public void run() {
Runtime runtime = Runtime.getRuntime();
Message msg = new Message();
try {
Process pingProcess = runtime.exec("/system/bin/ping -c 1 " + address);
InputStreamReader isr = new InputStreamReader(pingProcess.getInputStream());
BufferedReader buf = new BufferedReader(isr);
if (buf.readLine() == null) {
msg.arg1 = -1;
} else {
msg.arg1 = 0;
}
buf.close();
isr.close();
} catch (Exception e) {
msg.arg1 = -1;
e.printStackTrace();
} finally {
runtime.gc();
handler.sendMessage(msg);
}
}
}).start();
}
private Device deviceObj;
private HttpManager hm = HttpManager.getInstance();
private boolean deviceIsNull = false;///当服务器返回的设备控制器数和定时器数为null的时候 改变标记的值 不跳转进入主界面
private int deviceIsNullNum = 0;//循环请求次数
private CountDownTimer deviceIsNullTimer;
private void doPostBindDevice() {
try {
hm.bindDevice(new HttpListener<BaseBean<Device>>() {
private int result;
@Override
public void success(BaseBean<Device> baseBean) {
result = baseBean.result;
if (result == Commons.NetWork.Success) {
deviceObj = baseBean.data;
deviceObj.setMacAddress(device_mac);
/**
//当服务器返回的设备控制器数和定时器数为null的时候 不跳转进入主界面
*/
if (deviceObj.getControlAmount() == null || deviceObj.getTimerAmount() == null) {
L.i("第一次获取空");
deviceIsNull = true;
deviceIsNullNum = 0;
startDeviceIsNullTimer();//启动倒计时
}else {
doPostBindDeviceHandler.sendEmptyMessage(result);
}
}else {
doPostBindDeviceHandler.sendEmptyMessage(result);
}
}
@Override
public void finish() {
dismissDialog();
}
@Override
public void error(Exception e, String msg) {
result = Commons.NetWork.ERROR;
doPostBindDeviceHandler.sendEmptyMessage(result);
}
}, Commons.USER.getUserId(), device_mac);
} catch (Exception e) {
e.printStackTrace();
}
}
public void startDeviceIsNullTimer() {
if (deviceIsNullTimer == null) {
showDialog("获取设备信息中...");
deviceIsNullTimer = new CountDownTimer(2000, 1000) {
@Override
public void onTick(long arg0) {
}
@Override
public void onFinish() {
L.i("重新请求");
//拿到设备id 去服务器查询 看看是否为空
try {
hm.getSingleDeviceInf(new HttpListener<BaseBean<Device>>() {
private int result;
@Override
public void success(BaseBean<Device> baseBean) {
result = baseBean.result;
deviceObj = baseBean.data;
}
@Override
public void finish() {
dismissDialog();
deviceIsNullHandler.sendEmptyMessage(result);
}
@Override
public void error(Exception e, String msg) {
dismissDialog();
result = Commons.NetWork.ERROR;
}
}, deviceObj.getDeviceId(), Commons.USER.getUserId());
} catch (Exception e) {
e.printStackTrace();
dismissDialog();
}
}
};
}
deviceIsNullTimer.start();
}
@SuppressLint("HandlerLeak")
Handler doPostBindDeviceHandler = new Handler() {
public void handleMessage(Message msg) {
dismissDialog();
switch (msg.what) {
/**
* 1绑定成功
0绑定失败
-4请求验证失败请重新登陆
-5请求被舍弃未执行
*/
case Commons.NetWork.Success:
if (deviceIsNull) {//当服务器返回的设备控制器数和定时器数为null的时候 不跳转进入主界面
return;
}
List<Device> allDevices = Commons.DEVICE;
Device deviceBean = null;
int index =0 ;
if (deviceObj!=null && deviceObj.getMacAddress()!=null && allDevices!=null && allDevices.size()>0){
for (int i = 0;i<allDevices.size();i++){
Device item = allDevices.get(i);
if (item!=null && deviceObj.getMacAddress().equals(item.getMacAddress())){
deviceBean = item;
// Commons.DevicePosition = i;
index = i;
break;
}
}
}
if (deviceBean ==null){ // 新设备
Commons.DEVICE.add(deviceObj);
index = Commons.DEVICE.size() - 1;
}else {
Commons.IS_EventBus = true;
Commons.HAVE_DEVICE = true;//改变判断是否绑定的变量
Commons.IS_CAMERA = false;
sp.putBoolean(Commons.LoginSPKey.IS_CAMERA, Commons.IS_CAMERA);
}
try {
sp.putInt(Commons.LoginSPKey.Position, index);
Commons.DevicePosition = index;
} catch (Exception e) {
L.i("jjia-------"+e.toString());
}
ToastUtil.show(NewBindDeviceActivity.this, "设备序号" + Commons.DevicePosition + "---" + Commons.DEVICE.size());
if (deviceObj!=null){
toIntent(deviceObj);
}
break;
case Commons.NetWork.Fail:
ToastUtil.show(NewBindDeviceActivity.this, "绑定设备失败 请重试");
EventBus.getDefault().post(new ConnectMessageEvent(-1, "fail"));
finish();
break;
case Commons.NetWork.DEVICETYPEERROR:
ToastUtil.show(NewBindDeviceActivity.this, "设备类型不匹配,请重新选择入口绑定");
finish();
break;
case Commons.NetWork.ReLogin:
ToastUtil.show(getApplicationContext(), "请求验证失败 请重新登陆");
Commons.clean();
startActivity(new Intent(NewBindDeviceActivity.this, LoadingActivity.class));
finish();
break;
case Commons.NetWork.ERROR:
ToastUtil.show(getApplicationContext(), Commons.Text.ERROR);
finish();
break;
case Commons.NetWork.NotImplemented:
ToastUtil.show(getApplicationContext(), Commons.Text.Unknown);
finish();
break;
default:
ToastUtil.show(getApplicationContext(), Commons.Text.ServerException);
finish();
break;
}
}
};
private void toIntent(Device device){
Intent i = new Intent();
try {
Integer controlAmount = Commons.DEVICE.get(devicePosition).getControlAmount();
Integer timerAmount = Commons.DEVICE.get(devicePosition).getTimerAmount();
String type = Commons.DEVICE.get(devicePosition).type;
if (Commons.FishKey.On.equals(Commons.DEVICE.get(devicePosition).isBlacklist)) {//黑名单
Integer controlAmount = device.getControlAmount();
Integer timerAmount = device.getTimerAmount();
String type = device.type;
if (Commons.FishKey.On.equals(device.isBlacklist)) {//黑名单
i.setClass(NewBindDeviceActivity.this, BlackListActivity.class);
} else {
if (Device.TYPE_1C.equals(type)) {
@ -883,340 +1049,21 @@ public class NewBindDeviceActivity extends AppCompatActivity {
}
}
}
}
} catch (Exception e) {
i.setClass(NewBindDeviceActivity.this, MainThreeControlActivity.class);
}
dismissDialog();
i.putExtra(BaseGradeActivity.BINDDEVICE, true);//绑定成功增加经验
ToastUtil.show(NewBindDeviceActivity.this, "绑定设备成功");
startActivity(i);
AnimationUtil.startAnimation(NewBindDeviceActivity.this);
EventBus.getDefault().post(new ConnectMessageEvent(1, "test"));
finish();
L.i("===================绑定设备成功=" + device_mac);
}
private Activity act;
private ConnectDevice connectDevice;
private boolean isContinue = true;
public class ConnectDevice extends CountDownTimer {
public ConnectDevice(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onTick(long millisUntilFinished) {
long sum = millisUntilFinished / 1000 % 2;
if (sum == 0) {
if (!act.isFinishing() && isContinue) {
isNetWorkAvailable("www.baidu.com", new Comparable<Boolean>() {
@Override
public int compareTo(Boolean available) {
if (available) {
toReset();
isContinue = false;
connectDevice.cancel();
L.i("jjia-----------调用绑定接口---");
doPostBindDevice();
}
return 0;
}
});
}
}
}
@Override
public void onFinish() {
if (isContinue) {
DialogUtil.Companion.setLoadingDialogDismiss(activity);
}
}
}
public static void isNetWorkAvailable(final String address, final Comparable<Boolean> callback) {
final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (callback != null) {
callback.compareTo(msg.arg1 == 0);
}
}
};
new Thread(new Runnable() {
@Override
public void run() {
Runtime runtime = Runtime.getRuntime();
Message msg = new Message();
try {
Process pingProcess = runtime.exec("/system/bin/ping -c 1 " + address);
InputStreamReader isr = new InputStreamReader(pingProcess.getInputStream());
BufferedReader buf = new BufferedReader(isr);
if (buf.readLine() == null) {
msg.arg1 = -1;
} else {
msg.arg1 = 0;
}
buf.close();
isr.close();
} catch (Exception e) {
msg.arg1 = -1;
e.printStackTrace();
} finally {
runtime.gc();
handler.sendMessage(msg);
}
}
}).start();
}
private Device deviceObj;
private HttpManager hm = HttpManager.getInstance();
private boolean deviceIsNull = false;///当服务器返回的设备控制器数和定时器数为null的时候 改变标记的值 不跳转进入主界面
private int deviceIsNullNum = 0;//循环请求次数
private CountDownTimer deviceIsNullTimer;
private void doPostBindDevice() {
try {
hm.bindDevice(new HttpListener<BaseBean<Device>>() {
private int result;
@Override
public void success(BaseBean<Device> baseBean) {
result = baseBean.result;
if (result == Commons.NetWork.Success) {
deviceObj = baseBean.data;
deviceObj.setMacAddress(device_mac);
/**
//当服务器返回的设备控制器数和定时器数为null的时候 不跳转进入主界面
*/
if (deviceObj.getControlAmount() == null || deviceObj.getTimerAmount() == null) {
L.i("第一次获取空");
deviceIsNull = true;
deviceIsNullNum = 0;
startDeviceIsNullTimer();//启动倒计时
}
}
}
@Override
public void finish() {
doPostBindDeviceHandler.sendEmptyMessage(result);
}
@Override
public void error(Exception e, String msg) {
result = Commons.NetWork.ERROR;
}
}, Commons.USER.getUserId(), device_mac);
} catch (Exception e) {
e.printStackTrace();
}
}
public void startDeviceIsNullTimer() {
if (deviceIsNullTimer == null) {
deviceIsNullTimer = new CountDownTimer(2000, 1000) {
@Override
public void onTick(long arg0) {
}
@Override
public void onFinish() {
L.i("重新请求");
//拿到设备id 去服务器查询 看看是否为空
try {
hm.getSingleDeviceInf(new HttpListener<BaseBean<Device>>() {
private int result;
@Override
public void success(BaseBean<Device> baseBean) {
result = baseBean.result;
deviceObj = baseBean.data;
}
@Override
public void finish() {
DialogUtil.Companion.setLoadingDialogDismiss(activity);
deviceIsNullHandler.sendEmptyMessage(result);
}
@Override
public void error(Exception e, String msg) {
DialogUtil.Companion.setLoadingDialogDismiss(activity);
result = Commons.NetWork.ERROR;
}
}, deviceObj.getDeviceId(), Commons.USER.getUserId());
} catch (Exception e) {
e.printStackTrace();
DialogUtil.Companion.setLoadingDialogDismiss(activity);
}
}
};
}
deviceIsNullTimer.start();
}
@SuppressLint("HandlerLeak")
Handler doPostBindDeviceHandler = new Handler() {
public void handleMessage(Message msg) {
// dismissProgressDialog();
switch (msg.what) {
/**
* 1绑定成功
0绑定失败
-4请求验证失败请重新登陆
-5请求被舍弃未执行
*/
case Commons.NetWork.Success:
if (deviceIsNull) {//当服务器返回的设备控制器数和定时器数为null的时候 不跳转进入主界面
return;
}
List<Device> allDevices = Commons.DEVICE;
Boolean isHasDev = false;
if (deviceObj!=null && deviceObj.getMacAddress()!=null && allDevices!=null && allDevices.size()>0){
for (int i = 0;i<allDevices.size();i++){
Device item = allDevices.get(i);
if (item!=null && deviceObj.getMacAddress().equals(item.getMacAddress())){
Commons.DevicePosition = i;
isHasDev = true;
break;
}
}
}
if (!isHasDev){
Commons.DEVICE.add(deviceObj);
try {
sp.putInt(Commons.LoginSPKey.Position, Commons.DEVICE.size() - 1);
Commons.DevicePosition = Commons.DEVICE.size() - 1;
} catch (Exception e) {
}
}
ToastUtil.show(NewBindDeviceActivity.this, "设备序号" + Commons.DevicePosition + "---" + Commons.DEVICE.size());
Commons.IS_EventBus = true;
Commons.HAVE_DEVICE = true;//改变判断是否绑定的变量
Commons.IS_CAMERA = false;
sp.putBoolean(Commons.LoginSPKey.IS_CAMERA, Commons.IS_CAMERA);
Intent i = new Intent();
try {
Integer controlAmount = Commons.DEVICE.get(Commons.DevicePosition).getControlAmount();
Integer timerAmount = Commons.DEVICE.get(Commons.DevicePosition).getTimerAmount();
String type = Commons.DEVICE.get(Commons.DevicePosition).type;
if (Commons.FishKey.On.equals(Commons.DEVICE.get(Commons.DevicePosition).isBlacklist)) {//黑名单
i.setClass(NewBindDeviceActivity.this, BlackListActivity.class);
} else {
if (Device.TYPE_1C.equals(type)) {
i.setClass(NewBindDeviceActivity.this, MainThree1CControlActivity.class);
} else if (Device.TYPE_AA.equals(type)) {
i.setClass(NewBindDeviceActivity.this, MainFiveControlActivity.class);
} else if (Device.TYPE_BD.equals(type)) {
i.setClass(NewBindDeviceActivity.this, MainFiveBDControlActivity.class);
} else if (Device.TYPE_2A.equals(type)) {
i.setClass(NewBindDeviceActivity.this, MainSix_2A_ControlActivity.class);
} else if (Device.TYPE_2B.equals(type)) {
i.setClass(NewBindDeviceActivity.this, MainFour_2B_ControlActivity.class);
} else if (Device.TYPE_3A.equals(type)) {
i.setClass(NewBindDeviceActivity.this, MainHot_3A_ControlActivity.class);
} else if (Device.TYPE_2F.equals(type)) {
i.setClass(NewBindDeviceActivity.this, MainSeven_2F_ControlActivity.class);
} else if (Device.TYPE_3F.equals(type)) {
i.setClass(NewBindDeviceActivity.this, MainFour_3F_ControlActivity.class);
} else if (Device.TYPE_4F.equals(type) || Device.TYPE_5F.equals(type)){
i.setClass(NewBindDeviceActivity.this, MainSix_4F_ControlActivity.class);
} else {
if (controlAmount == null) {//如果控制器返回空 则默认给三控的页面
i.setClass(NewBindDeviceActivity.this, MainThreeControlActivity.class);
} else {
i.setClass(NewBindDeviceActivity.this, MainThreeControlActivity.class);
switch (controlAmount) {
case 0: {
i.setClass(NewBindDeviceActivity.this, MainZeroControlActivity.class);
break;
}
case 2: {
i.setClass(NewBindDeviceActivity.this, MainTwoControlActivity.class);
break;
}
case 3: {
i.setClass(NewBindDeviceActivity.this, MainThreeControlActivity.class);
break;
}
case 4: {
if (timerAmount == 6) { // 可丽爱
i.setClass(NewBindDeviceActivity.this, MainFiveControlActivity.class);
} else {//4控
i.setClass(NewBindDeviceActivity.this, MainFourControlActivity.class);
}
break;
}
case 5: {
if (6 == timerAmount) {//5控六定时器 询多页面
i.setClass(NewBindDeviceActivity.this, MainSixControlActivity.class);
}
break;
}
case 8: {
i.setClass(NewBindDeviceActivity.this, MainEightControlActivity.class);
break;
}
default: {
i.setClass(NewBindDeviceActivity.this, MainThreeControlActivity.class);
break;
}
}
}
}
}
} catch (Exception e) {
i.setClass(NewBindDeviceActivity.this, MainThreeControlActivity.class);
}
DialogUtil.Companion.setLoadingDialogDismiss(activity);
i.putExtra(BaseGradeActivity.BINDDEVICE, true);//绑定成功增加经验
ToastUtil.show(NewBindDeviceActivity.this, "绑定设备成功");
startActivity(i);
AnimationUtil.startAnimation(NewBindDeviceActivity.this);
EventBus.getDefault().post(new ConnectMessageEvent(1, "test"));
finish();
L.i("===================绑定设备成功=" + device_mac);
break;
case Commons.NetWork.Fail:
ToastUtil.show(NewBindDeviceActivity.this, "绑定设备失败 请重试");
EventBus.getDefault().post(new ConnectMessageEvent(-1, "fail"));
finish();
break;
case Commons.NetWork.DEVICETYPEERROR:
ToastUtil.show(NewBindDeviceActivity.this, "设备类型不匹配,请重新选择入口绑定");
finish();
break;
case Commons.NetWork.ReLogin:
ToastUtil.show(getApplicationContext(), "请求验证失败 请重新登陆");
Commons.clean();
startActivity(new Intent(NewBindDeviceActivity.this, LoadingActivity.class));
finish();
break;
case Commons.NetWork.ERROR:
ToastUtil.show(getApplicationContext(), Commons.Text.ERROR);
finish();
break;
case Commons.NetWork.NotImplemented:
ToastUtil.show(getApplicationContext(), Commons.Text.Unknown);
finish();
break;
default:
ToastUtil.show(getApplicationContext(), Commons.Text.ServerException);
finish();
break;
}
}
};
@SuppressLint("HandlerLeak")
Handler deviceIsNullHandler = new Handler() {
@ -1420,4 +1267,12 @@ public class NewBindDeviceActivity extends AppCompatActivity {
super.onActivityResult(requestCode, resultCode, data);
L.i(requestCode+"jjia--------result---"+resultCode);
}
private void showDialog(String msg){
layoutLoading.setVisibility(View.VISIBLE);
dialogHint.setText(msg);
}
private void dismissDialog(){
layoutLoading.setVisibility(View.GONE);
}
}

View File

@ -1891,176 +1891,7 @@ public class DeviceFragment extends BaseV4Fragment implements ObservableScrollVi
}
firstResult = firstResult + HttpManager.PAGESIZE;
}
public static final String SERVICE_UUID = "000000ff-0000-1000-8000-00805f9b34fb"; //蓝牙通讯服务
public static final String READ_UUID = "0000ff01-0000-1000-8000-00805f9b34fb"; //读特征
public static final String WRITE_UUID = "0000ff01-0000-1000-8000-00805f9b34fb"; //写特征
String device_mac=null;
// private void sendBleData(){
//
//// String ssid = tvWifiName.getText().toString();
//// String pwd = tvWifiPwd.getText().toString();
//
// WifiAdmin wifiAdmin = new WifiAdmin(requireContext());
// String wifissid = wifiAdmin.getSSID();
// L.i("jjia 获取当前连接的wifi:" + wifissid);
// wifissid = wifiAdmin.updateSsid(wifissid);
// String wifiname = wifissid;
// if (TextUtils.isEmpty(wifissid)) {
// wifiname = "";
// } else {
// if ("0x".equals(wifissid)) {//上次连接过wifi但是中途断开则会出现0x
// wifiname = "";
// }
// }
//// tvWifiName.setText(wifiname);
// L.i("jjia----------------wifiname="+wifiname);
// String pwd = null;
// if (!TextUtils.isEmpty(wifiname)) {
//// String pwd = KVUtil.getString(wifiname, "");
// pwd = sp.getString(wifiname, "");
//
// }
// L.i(wifiname+"jjia---------name--1-"+pwd);
//
//
//
// OrderDeviceConnectModel model = OrderModel.OrderDeviceConnectModel(wifiname, pwd);//设置正式环境域名
// byte[] data = ModelCodec.enCode(model);
// BleManager.getInstance().write(currentDevice, SERVICE_UUID, WRITE_UUID, data,false, new BleWriteCallback() {
// @Override
// public void onWriteSuccess(int current, int total, byte[] justWrite) {
// L.i("jjia-------------ssid 发送");
// }
//
// @Override
// public void onWriteFailure(BleException exception) {
//
// }
// });
// }
// private void checkoutMac(String mac){
//
// if (!TextUtils.isEmpty(mac)){
// boolean isSameName = false;
// devicePosition = 0;
// try {
// if (Commons.DEVICE != null) {
// if (Commons.DEVICE.size() != 0) {
// for (int i = 0; i < Commons.DEVICE.size(); i++) {
// if (mac.equals(Commons.DEVICE.get(i).getMacAddress())) {
// devicePosition = i;
// isSameName = true;
// break;
// }
// }
// }
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
//
//
// if (!isSameName){
// L.i("jjia-------------不包含");
// requireActivity().runOnUiThread(new Runnable() {
// @Override
// public void run() {
// // 检测页面
// AlertDialog.Builder dialog = new AlertDialog.Builder(requireContext(), AlertDialog.THEME_HOLO_LIGHT);
// dialog.setCancelable(true);
// dialog.setTitle("提示");
// dialog.setMessage("发现一个新设备是否去添加");
// dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface arg0, int arg1) {
// arg0.dismiss();
// }
// });
// dialog.setPositiveButton("确定", (dialog1, which) -> {
// dialog1.dismiss();
// Intent intent = new Intent();
// intent.setClass(requireActivity(), NewBindDeviceActivity.class);
// intent.putExtra("title", "连接水族箱");
// intent.putExtra("type", "bluetooth");
// intent.putExtra("device", currentDevice);
// startActivity(intent);
// AnimationUtil.finishAnimation(requireActivity());
// });
// dialog.show();
// }
// });
// }
// }
// }
// private void openNotify(){
// BleManager.getInstance().notify(currentDevice, SERVICE_UUID, WRITE_UUID, new BleNotifyCallback() {
// @Override
// public void onNotifySuccess() {
// sendBleData();
// }
//
// @Override
// public void onNotifyFailure(BleException exception) {
// dismissProgressDialogCancelble();
// }
//
// @Override
// public void onCharacteristicChanged(byte[] data) {
//
// if (data!=null && data.length>0){
// int check_code = data[1];
// int length = data[14];
// byte[] dataByte = new byte[length];
// for (int i = 0; i < dataByte.length; i++) {
// dataByte[i] = data[i];
// }
//
// Object object = ModelCodec.deCode(dataByte);
// if (object!=null && object instanceof BackFunctionCode7_11){
// BackFunctionCode7_11 model = (BackFunctionCode7_11) object;
// device_mac = ByteUtil.bytesToHexString(model.getSrc());
// checkoutMac(device_mac);
// } else {
// }
// L.i("jjia-------device_mac-"+device_mac);
// }
// }
// });
// }
// private void connectBle(){
// BleManager.getInstance().connect(currentDevice, new BleGattCallback() {
// @Override
// public void onStartConnect() {
//
// L.i("jjia---------conne------");
// }
//
// @Override
// public void onConnectFail(BleDevice bleDevice, BleException exception) {
// }
//
// @Override
// public void onConnectSuccess(BleDevice bleDevice, BluetoothGatt gatt, int status) {
//// ToastUtil.show(NewBindDeviceActivity.this,"蓝牙连接成功");
// BleManager.getInstance().setMtu(bleDevice, 512, new BleMtuChangedCallback() {
// @Override
// public void onSetMTUFailure(BleException exception) {
// }
//
// @Override
// public void onMtuChanged(int mtu) {
// openNotify();
// }
// });
// }
//
// @Override
// public void onDisConnected(boolean isActiveDisConnected, BleDevice device, BluetoothGatt gatt, int status) {
// }
// });
// }
private void initBooth(){
boolean enable = BleManager.getInstance().isBlueEnable();
if (enable) {

View File

@ -7,23 +7,26 @@ import com.ifish.baseclass.BaseActivity
* Created by achang on 2018/10/6.
*/
class DialogUtil {
class DialogUtil1 {
companion object {
var mLoadingDialog: LoadingDialog? = null
var showDialog:Boolean=false
var hint:String?="正在加载中,请稍等片刻..."
fun showLoadingDialog(activity: Activity?, showDialog:Boolean, hint:String?="正在加载中,请稍等片刻..."): LoadingDialog {
this.showDialog= showDialog
if (mLoadingDialog == null && activity !=null) {
mLoadingDialog = LoadingDialog(activity,hint)
if (!mLoadingDialog!!.isShowing && !activity.isFinishing) {
mLoadingDialog!!.show()
}
} else {
if (!mLoadingDialog!!.isShowing && activity != null && !activity.isFinishing) {
mLoadingDialog!!.show()
if (activity!=null){
if (mLoadingDialog == null) {
mLoadingDialog = LoadingDialog(activity,hint)
if (!mLoadingDialog!!.isShowing && !activity.isFinishing) {
mLoadingDialog!!.show()
}
} else {
if (!mLoadingDialog!!.isShowing && !activity.isFinishing) {
mLoadingDialog!!.show()
}
}
}
return mLoadingDialog!!
}

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -13,6 +13,7 @@
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/in_daohang"
android:background="@color/white"
android:orientation="vertical">
@ -210,5 +211,44 @@
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="@+id/layout_loading"
android:layout_width="match_parent"
android:visibility="gone"
android:layout_height="match_parent">
<LinearLayout
android:background="@drawable/shape_white_radius15"
android:gravity="center"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:minWidth="150dp"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"
android:orientation="vertical"
android:layout_height="150dp">
</LinearLayout>
<ProgressBar
android:id="@+id/dg_pb_loading"
android:layout_width="38dp"
android:layout_height="38dp"
android:indeterminateBehavior="repeat"
android:indeterminateDrawable="@drawable/shape_loading_anim"
android:indeterminateOnly="true" />
<TextView
android:id="@+id/tv_hint"
android:layout_marginTop="10dp"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:layout_width="wrap_content"
android:gravity="center"
android:text="正在加载中..."
android:textSize="16sp"
android:textColor="@color/white"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>