| | |
| | | import android.content.Intent; |
| | | import android.content.ServiceConnection; |
| | | import android.os.AsyncTask; |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | | import android.os.IBinder; |
| | | import android.os.Looper; |
| | |
| | | |
| | | @Override |
| | | protected void initListener() { |
| | | |
| | | // registerBoradcastReceiver(); |
| | | // bleHeart(); |
| | | } |
| | | |
| | | @Override |
| | | protected void initData() { |
| | | // prepare(); |
| | | prepare(); |
| | | if(MainApp.theApp.bleManager!=null){ |
| | | if(MainApp.theApp.bleManager.isSupportBle()){ |
| | | MainApp.theApp.bleManager.enableBluetooth(); |
| | |
| | | /** |
| | | * 版本更新 |
| | | */ |
| | | if (Build.VERSION.SDK_INT >= 11) { |
| | | new checkUpdateTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| | | } else { |
| | | new checkUpdateTask().execute(); |
| | | } |
| | | // if (Build.VERSION.SDK_INT >= 11) { |
| | | // new checkUpdateTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| | | // } else { |
| | | // new checkUpdateTask().execute(); |
| | | // } |
| | | if (islogin) |
| | | return; |
| | | String url = API.GET_INFO; |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("userID", MainApp.userId); |
| | | params.put("phone",MainApp.theApp.sharedPreferencesUtil.getLoginInfo().getPhone()); |
| | | HttpUtils.doPost(url, params, CacheMode.DEFAULT, false, new HttpCallBack() { |
| | | @Override |
| | | public void onSuccess(String res, String msg) { |
| | | User user = FastJsonTools.getJson(res, User.class); |
| | | if (user != null) { |
| | | MainApp.theApp.sharedPreferencesUtil.saveLoginInfo(user); |
| | | // MainApp.theApp.userId = user.get_id(); |
| | | MainApp.theApp.userId = user.get_id(); |
| | | } |
| | | } |
| | | |
| | |
| | | public void onConnectFail() { |
| | | progressDialog.dismiss(); |
| | | mToatUtils.showSingletonToast("连接失败"); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onDisConnected() { |
| | | progressDialog.dismiss(); |
| | | mToatUtils.showSingletonToast("连接断开"); |
| | | EventMessage msg = new EventMessage(); |
| | | msg.setType(AppConfig.GET_BLE_DISCONNECT); |
| | | EventBus.getDefault().post(msg); |
| | | } |
| | | |
| | | @Override |
| | |
| | | EventBus.getDefault().post(msg); |
| | | } |
| | | }; |
| | | |
| | | // private void registerBoradcastReceiver() { |
| | | // IntentFilter stateChangeFilter = new IntentFilter( |
| | | // BluetoothAdapter.ACTION_STATE_CHANGED); |
| | | // IntentFilter connectedFilter = new IntentFilter( |
| | | // BluetoothDevice.ACTION_ACL_CONNECTED); |
| | | // IntentFilter disConnectedFilter = new IntentFilter( |
| | | // BluetoothDevice.ACTION_ACL_DISCONNECTED); |
| | | // registerReceiver(stateChangeReceiver, stateChangeFilter); |
| | | // registerReceiver(stateChangeReceiver, connectedFilter); |
| | | // registerReceiver(stateChangeReceiver, disConnectedFilter); |
| | | // } |
| | | // |
| | | // private BroadcastReceiver stateChangeReceiver = new BroadcastReceiver() { |
| | | // @Override |
| | | // public void onReceive(Context context, Intent intent) { |
| | | // String action = intent.getAction(); |
| | | // if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { |
| | | // mToatUtils.showSingletonToast("xxx连接OK"); |
| | | // } |
| | | // if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) { |
| | | // mToatUtils.showSingletonToast("xxx连接断开"); |
| | | // } |
| | | // if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) { |
| | | // mToatUtils.showSingletonToast("xxx连接变化"); |
| | | // } |
| | | // } |
| | | // }; |
| | | |
| | | // private boolean isFinish = false; |
| | | // Timer timer; |
| | | // |
| | | // private void bleHeart() { |
| | | // timer = new Timer(); |
| | | // timer.schedule(new TimerTask() { |
| | | // @Override |
| | | // public void run() { |
| | | // if (!isFinish) { |
| | | // if(!MainApp.theApp.bleManager.isConnected()){ |
| | | // runOnUiThread(new Runnable() { |
| | | // @Override |
| | | // public void run() { |
| | | // mToatUtils.showSingletonToast("TMD连接断了"); |
| | | // } |
| | | // }); |
| | | // } |
| | | // } |
| | | // } |
| | | // }, 0, 10000); |
| | | // } |
| | | } |