From fc9dc236266700d61e3538bee669f2f4abb242f2 Mon Sep 17 00:00:00 2001 From: 陈奇 <1650699704@qq.com> Date: Tue, 13 Nov 2018 14:14:22 +0800 Subject: [PATCH] 1.0.3-1测试版本 [*]修改重新连接的方式 [*]修改商城连接 [*]修改心跳机制 [*]主要针对oppo和vivo机型添加开启定位服务 --- app/src/main/java/com/moral/yunfushao/fragment/FragmentMonitor.java | 65 ++++++++++++++++++++++---------- 1 files changed, 44 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..6c4ee08 100644 --- a/app/src/main/java/com/moral/yunfushao/fragment/FragmentMonitor.java +++ b/app/src/main/java/com/moral/yunfushao/fragment/FragmentMonitor.java @@ -98,11 +98,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 +127,16 @@ 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() { //������ - if (FragmentMonitor.this.mBluetoothService == null) { + if (mBluetoothService == null) { return; } String mac = MainApp.theApp.sharedPreferencesUtil.getBLE(); @@ -142,10 +144,8 @@ if (MainApp.theApp.bleManager.isConnectingOrConnected()) { return; } - Log.d(TGA, "������������"); - FragmentMonitor.this.mBluetoothService.scanAndConnect5(mac); + mBluetoothService.scanAndConnect5(mac); } - reconnect(); } }; @@ -196,11 +196,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 +211,8 @@ mBluetoothService.setService(service); break; } - } - //������������ + + }//������������ for (BluetoothGattCharacteristic characteristic : mBluetoothService.getService().getCharacteristics()) { int charaProp = characteristic.getProperties(); if ((charaProp & BluetoothGattCharacteristic.PROPERTY_READ) > 0) { @@ -249,26 +249,25 @@ @Override public void onFailure(final BleException exception) { + } @Override public void onInitiatedResult(boolean result) { } }); - /** - * ������������������ - */ -// handler.postDelayed(runnable, 5000); + //������handler + HEARTTIMES = 2; + //������������ 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 +303,7 @@ } } else if (msg.getType() == AppConfig.BLUETOOCH_CHANGE_CONNECT) { showStatus(-1); + stopReconnect(); } } @@ -339,18 +339,28 @@ @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; textShowMac(); + } + + @Override + public void onPause() { + super.onPause(); + System.out.println("chenqi onPause"); + isMySelfPage = false; + stopReconnect(); } @Override public void onDestroy() { super.onDestroy(); + System.out.println("chenqi onDestroy"); EventBus.getDefault().unregister(this); if (timer != null) { timer.cancel(); @@ -404,6 +414,7 @@ } }); showStatus(-1); + } @Override @@ -502,14 +513,26 @@ 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); } private void resetHandler() { handler.removeCallbacks(reconnectRunnable); handler.removeCallbacks(heartRunnable); - HEARTTIMES = 2; } private void submitData() { @@ -637,7 +660,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