From 17d97f58265510ceda0b38959a90424ee07b6910 Mon Sep 17 00:00:00 2001
From: 陈奇 <1650699704@qq.com>
Date: Tue, 13 Nov 2018 11:42:07 +0800
Subject: [PATCH] 1.0.3-1测试版本 [*]修改重新连接的方式 [*]修改商城连接 [*]修改心跳机制 [*]主要针对oppo和vivo机型添加开启定位服务
---
app/src/main/java/com/moral/yunfushao/fragment/FragmentMonitor.java | 71 +++++++++++++++++++++++++----------
1 files changed, 50 insertions(+), 21 deletions(-)
diff --git a/app/src/main/java/com/moral/yunfushao/fragment/FragmentMonitor.java b/app/src/main/java/com/moral/yunfushao/fragment/FragmentMonitor.java
index c4c4445..86ef576 100644
--- a/app/src/main/java/com/moral/yunfushao/fragment/FragmentMonitor.java
+++ b/app/src/main/java/com/moral/yunfushao/fragment/FragmentMonitor.java
@@ -55,6 +55,7 @@
import com.moral.yunfushao.ui.PanelView;
import com.moral.yunfushao.utils.AudioUtils;
import com.moral.yunfushao.utils.DebugUtils;
+import com.moral.yunfushao.utils.T;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -98,11 +99,12 @@
//������������
private int HEARTTIMES = 2;
- //������������
- private int RECONNECTTIMES = 8000;
+
+ //������������������
+ private boolean isMySelfPage = false;
+
//handler������������
private Handler handler = new Handler();
-
private Runnable heartRunnable = new Runnable() {
@Override
@@ -126,15 +128,17 @@
FragmentMonitor.this.mBluetoothService.write(FragmentMonitor.this.mBluetoothService.getWirteCharacteristic().getService().getUuid().toString(),
FragmentMonitor.this.mBluetoothService.getWirteCharacteristic().getUuid().toString(),
BLECommon.BLE_HEART, null);
- Log.d(TGA, "������������");
heart();
}
};
+
+
private Runnable reconnectRunnable = new Runnable() {
@Override
public void run() {
+ System.out.println("chenqi ������������");
//������
- if (FragmentMonitor.this.mBluetoothService == null) {
+ if (mBluetoothService == null) {
return;
}
String mac = MainApp.theApp.sharedPreferencesUtil.getBLE();
@@ -142,10 +146,8 @@
if (MainApp.theApp.bleManager.isConnectingOrConnected()) {
return;
}
- Log.d(TGA, "������������");
- FragmentMonitor.this.mBluetoothService.scanAndConnect5(mac);
+ mBluetoothService.scanAndConnect5(mac);
}
- reconnect();
}
};
@@ -196,11 +198,11 @@
*/
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
public void eventComing(EventMessage msg) {
+ mBluetoothService = ((MainActivity) getActivity()).getBluetoothService();
if (msg.getType() == AppConfig.GET_BLE_SERVICE) {
resetHandler();
pv.setStatusStr("���������");
//������������
- mBluetoothService = ((MainActivity) getActivity()).getBluetoothService();
((MainActivity) getActivity()).resetBLECallBack();
if (mBluetoothService != null) {
BluetoothGatt gatt = mBluetoothService.getGatt();
@@ -211,8 +213,8 @@
mBluetoothService.setService(service);
break;
}
- }
- //������������
+
+ }//������������
for (BluetoothGattCharacteristic characteristic : mBluetoothService.getService().getCharacteristics()) {
int charaProp = characteristic.getProperties();
if ((charaProp & BluetoothGattCharacteristic.PROPERTY_READ) > 0) {
@@ -249,26 +251,25 @@
@Override
public void onFailure(final BleException exception) {
+
}
@Override
public void onInitiatedResult(boolean result) {
}
});
- /**
- * ������������������
- */
-// handler.postDelayed(runnable, 5000);
+ //������handler
+ resetHandler();
+ //������������
heart();
}
} else if (msg.getType() == AppConfig.GET_BLE_DISCONNECT) {
preLevel = -1;
showStatus(-1);
- handler.postDelayed(reconnectRunnable, RECONNECTTIMES);
+ reconnect();
stop();
isVirating = false;
AudioUtils.virateCancle(getActivity());
-
} else if (msg.getType() == AppConfig.CHANGE_SETTING) {
if (timer != null) {
timer.cancel();
@@ -304,6 +305,7 @@
}
} else if (msg.getType() == AppConfig.BLUETOOCH_CHANGE_CONNECT) {
showStatus(-1);
+ stopReconnect();
}
}
@@ -339,13 +341,24 @@
@Override
public void onAttach(Context context) {
super.onAttach(context);
- FragmentMonitor.this.mBluetoothService = ((MainActivity) getActivity()).getBluetoothService();
+ mBluetoothService = ((MainActivity) getActivity()).getBluetoothService();
}
@Override
public void onResume() {
super.onResume();
+ isMySelfPage = true;
+ reconnect();
textShowMac();
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ //������������������������
+ T.show("onPause");
+ isMySelfPage = false;
+ stopReconnect();
}
@Override
@@ -404,6 +417,7 @@
}
});
showStatus(-1);
+
}
@Override
@@ -502,14 +516,29 @@
handler.postDelayed(heartRunnable, 1000 * HEARTTIMES);
}
+ /**
+ * ������������
+ */
private void reconnect() {
- handler.postDelayed(reconnectRunnable, RECONNECTTIMES);
+ if (isMySelfPage) {
+ stopReconnect();
+ //���������������������
+ handler.postDelayed(reconnectRunnable, 0);
+ }
+ }
+
+ /**
+ * ������������
+ */
+ private void stopReconnect() {
+ handler.removeCallbacks(reconnectRunnable);
+ if (mBluetoothService != null)
+ mBluetoothService.closeConnect();
}
private void resetHandler() {
handler.removeCallbacks(reconnectRunnable);
handler.removeCallbacks(heartRunnable);
- HEARTTIMES = 2;
}
private void submitData() {
@@ -637,7 +666,7 @@
private void textShowMac() {
if (BuildConfig.BUILD_TYPE.equals(VersionConstants.DEBUG)) {
- final TextView tv_text_mac = (TextView) findView(R.id.tv_text_mac);
+ final TextView tv_text_mac = findView(R.id.tv_text_mac);
tv_desc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
--
Gitblit v1.8.0