张海江
2017-08-07 957b8e9d4bc63524dad27c2f8458856da0bf5c06
app/src/main/java/com/moral/yunfushao/MainActivity.java
@@ -6,7 +6,6 @@
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;
@@ -118,12 +117,13 @@
    @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();
@@ -234,23 +234,23 @@
            /**
             * 版本更新
             */
            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();
                    }
                }
@@ -324,12 +324,16 @@
        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
@@ -340,4 +344,54 @@
            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);
//    }
}