| | |
| | | import android.support.v4.content.ContextCompat; |
| | | import android.support.v7.widget.LinearLayoutManager; |
| | | import android.support.v7.widget.RecyclerView; |
| | | import android.util.Log; |
| | | import android.view.View; |
| | | import android.widget.ImageView; |
| | | import android.widget.LinearLayout; |
| | |
| | | import com.clj.fastble.data.ScanResult; |
| | | import com.moral.andbrickslib.baseadapter.headandfooter.DividerItemDecoration; |
| | | import com.moral.andbrickslib.baseadapter.recyclerview.MultiItemTypeAdapter; |
| | | import com.moral.andbrickslib.utils.ActivityManager; |
| | | import com.moral.yunfushao.MainApp; |
| | | import com.moral.yunfushao.R; |
| | | import com.moral.yunfushao.adapter.BleDeviceAdapter; |
| | |
| | | super.onDestroy(); |
| | | if (mBluetoothService != null) |
| | | unbindService(); |
| | | EventMessage msg = new EventMessage(); |
| | | msg.setType(AppConfig.SET_MAIN_CALL); |
| | | EventBus.getDefault().postSticky(msg); |
| | | } |
| | | |
| | | @Override |
| | |
| | | /** |
| | | * 如果连接状态,断开重新连接 |
| | | */ |
| | | if(MainApp.theApp.bleManager!=null&&MainApp.theApp.bleManager.isConnected()){ |
| | | mBluetoothService.closeConnect(); |
| | | if (MainApp.theApp.bleManager != null) { |
| | | MainApp.theApp.bleManager.closeBluetoothGatt(); |
| | | } |
| | | mBluetoothService.connectDevice(scanResultList.get(position)); |
| | | } |
| | |
| | | } |
| | | |
| | | private void unbindService() { |
| | | // mBluetoothService.setScanCallback(null); |
| | | this.unbindService(mFhrSCon); |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public void onServiceDisconnected(ComponentName name) { |
| | | mBluetoothService = null; |
| | | if (mBluetoothService != null) { |
| | | mBluetoothService.cancelScan(); |
| | | mBluetoothService.closeConnect(); |
| | | mBluetoothService = null; |
| | | } |
| | | } |
| | | }; |
| | | |
| | |
| | | |
| | | @Override |
| | | public void onConnecting() { |
| | | progressDialog.setTitleText("正在连接..."); |
| | | progressDialog.show(); |
| | | if (ActivityManager.getActivityManager().isActivityExist(BLESearchActivity.this.getClass().getName())) { |
| | | progressDialog.setTitleText("正在连接..."); |
| | | progressDialog.show(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onConnectFail() { |
| | | progressDialog.dismiss(); |
| | | if (ActivityManager.getActivityManager().isActivityExist(BLESearchActivity.this.getClass().getName())) { |
| | | progressDialog.dismiss(); |
| | | } |
| | | // Log.d("chonglian","连接失败"); |
| | | mToatUtils.showSingletonToast("连接失败"); |
| | | EventMessage msg = new EventMessage(); |
| | | msg.setType(AppConfig.GET_BLE_DISCONNECT); |
| | | EventBus.getDefault().postSticky(msg); |
| | | } |
| | | |
| | | @Override |
| | | public void onDisConnected() { |
| | | progressDialog.dismiss(); |
| | | mToatUtils.showSingletonToast("连接断开"); |
| | | if (ActivityManager.getActivityManager().isActivityExist(BLESearchActivity.this.getClass().getName())) { |
| | | progressDialog.dismiss(); |
| | | } |
| | | Log.d("chonglian","孕妇哨连接断开"); |
| | | mToatUtils.showSingletonToast("孕妇哨连接断开"); |
| | | EventMessage msg = new EventMessage(); |
| | | msg.setType(AppConfig.GET_BLE_DISCONNECT); |
| | | EventBus.getDefault().postSticky(msg); |
| | | } |
| | | |
| | | @Override |
| | | public void onServicesDiscovered() { |
| | | progressDialog.dismiss(); |
| | | Log.d("chonglian","孕妇哨连接成功"); |
| | | EventMessage msg = new EventMessage(); |
| | | msg.setType(AppConfig.GET_BLE_SERVICE); |
| | | EventBus.getDefault().post(msg); |
| | | finish(); |
| | | EventBus.getDefault().postSticky(msg); |
| | | if (ActivityManager.getActivityManager().isActivityExist(BLESearchActivity.this.getClass().getName())) { |
| | | progressDialog.dismiss(); |
| | | finish(); |
| | | } |
| | | |
| | | } |
| | | }; |
| | | |