| | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.ServiceConnection; |
| | | import android.content.pm.PackageManager; |
| | | import android.graphics.Color; |
| | | import android.graphics.drawable.ColorDrawable; |
| | | import android.os.AsyncTask; |
| | |
| | | import com.moral.yunfushao.model.EventMessage; |
| | | import com.moral.yunfushao.model.User; |
| | | import com.moral.yunfushao.update.UpdateManager; |
| | | import com.moral.yunfushao.utils.PermissionUtil; |
| | | |
| | | import org.greenrobot.eventbus.EventBus; |
| | | import org.json.JSONException; |
| | |
| | | private int index = 0; |
| | | private boolean islogin = false; |
| | | |
| | | private BluetoothService mBluetoothService; |
| | | public static BluetoothService mBluetoothService; |
| | | |
| | | @Override |
| | | protected void getBundleExtras(Bundle extras) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | protected void onStart() { |
| | | super.onStart(); |
| | | bindService(); |
| | | PermissionUtil.verifyStoragePermissions(this); |
| | | } |
| | | |
| | | @Override |
| | | protected void onStop() { |
| | | super.onStop(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | protected void initData() { |
| | | prepare(); |
| | | //验证微信登陆 |
| | | wxLoadingOutTime(); |
| | | // prepare(); |
| | | if (MainApp.theApp.bleManager != null) { |
| | | if (MainApp.theApp.bleManager.isSupportBle()) { |
| | | MainApp.theApp.bleManager.enableBluetooth(); |
| | |
| | | mToatUtils.showSingletonToast("对不起,您的手机不支持BLE!"); |
| | | } |
| | | getAd(); |
| | | } |
| | | |
| | | /** |
| | | * 判断是否已经是最后期限 |
| | | */ |
| | | private void wxLoadingOutTime() { |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | // Do not have permissions, request them now |
| | | EasyPermissions.requestPermissions(this, "温馨提示,版本升级需要写存储权限!", |
| | | WRITE_EXTERNAL_STORAGE, perms); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { |
| | | super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
| | | |
| | | if (requestCode == 1) { |
| | | for (int i = 0; i < permissions.length; i++) { |
| | | if (grantResults[i] != PackageManager.PERMISSION_GRANTED) { |
| | | //申请失败 |
| | | PermissionUtil.verifyStoragePermissions(this); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | mBluetoothService = ((BluetoothService.BluetoothBinder) service).getService(); |
| | | mBluetoothService.setScanCallback(callback); |
| | | String mac = MainApp.theApp.sharedPreferencesUtil.getBLE(); |
| | | System.out.println("BleGattCallback init"); |
| | | if (!TextUtils.isEmpty(mac)) { |
| | | mBluetoothService.scanAndConnect5(mac); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void onServiceDisconnected(ComponentName name) { |
| | | System.out.println("BleGattCallback onServiceDisconnected"); |
| | | mBluetoothService = null; |
| | | } |
| | | |
| | | |
| | | }; |
| | | |
| | | private BluetoothService.Callback callback = new BluetoothService.Callback() { |
| | | @Override |
| | | public void onStartScan() { |
| | | |
| | | System.out.println("MainActivity onStartScan"); |
| | | } |
| | | |
| | | @Override |
| | | public void onScanning(ScanResult result) { |
| | | |
| | | System.out.println("MainActivity onScanning"); |
| | | } |
| | | |
| | | @Override |
| | | public void onScanComplete() { |
| | | |
| | | System.out.println("MainActivity onScanComplete"); |
| | | } |
| | | |
| | | @Override |
| | | public void onConnecting() { |
| | | System.out.println("MainActivity onConnecting"); |
| | | progressDialog.setTitleText("正在连接..."); |
| | | progressDialog.show(); |
| | | } |
| | | |
| | | @Override |
| | | public void onConnectFail() { |
| | | System.out.println("MainActivity onConnectFail"); |
| | | progressDialog.dismiss(); |
| | | mToatUtils.showSingletonToast("连接失败"); |
| | | mBluetoothService.closeConnect(); |
| | | EventMessage msg = new EventMessage(); |
| | | msg.setType(AppConfig.GET_BLE_DISCONNECT); |
| | | EventBus.getDefault().postSticky(msg); |
| | |
| | | |
| | | @Override |
| | | public void onDisConnected() { |
| | | System.out.println("MainActivity onDisConnected"); |
| | | progressDialog.dismiss(); |
| | | mToatUtils.showSingletonToast("孕妇哨连接断开"); |
| | | EventMessage msg = new EventMessage(); |
| | |
| | | |
| | | @Override |
| | | public void onServicesDiscovered() { |
| | | System.out.println("MainActivity onServicesDiscovered"); |
| | | progressDialog.dismiss(); |
| | | EventMessage msg = new EventMessage(); |
| | | msg.setType(AppConfig.GET_BLE_SERVICE); |