package com.phlx.anchor_collect_flutter;


import cn.wandersnail.ble.EasyBLE;
import cn.wandersnail.ble.ScanConfiguration;
import cn.wandersnail.ble.ScannerType;
import cn.wandersnail.commons.poster.ThreadMode;
import io.flutter.embedding.android.FlutterActivity;

import android.bluetooth.le.ScanSettings;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;

import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodCall;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class MainActivity extends FlutterActivity {

    EasyBLE ble;

    @Override
    public void configureFlutterEngine(FlutterEngine flutterEngine) {
        super.configureFlutterEngine(flutterEngine);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            ScanConfiguration scanConfig = new ScanConfiguration()
                    .setScanSettings(new ScanSettings.Builder()
                            .setScanMode(ScanSettings.SCAN_MODE_BALANCED)
                            .build())
                    .setScanPeriodMillis(15000)//搜索一次的毫秒值
                    .setAcceptSysConnectedDevice(true)
                    .setOnlyAcceptBleDevice(true);
            if(ble==null){
             ble = EasyBLE.getBuilder().setScanConfiguration(scanConfig)
                     .setObserveAnnotationRequired(true)
                     .setMethodDefaultThreadMode(ThreadMode.BACKGROUND)//指定回调方法和观察者方法的默认线程
                     .setScannerType(ScannerType.LEGACY)
                     .build();
                ble.setLogEnabled(true);
                ble.initialize(getApplication());
            }
        }else {
            EasyBLE.getInstance().initialize(getApplication());
        }

        flutterEngine.getPlugins().add(new RfidPlugin());
        GeneratedPluginRegistrant.registerWith(flutterEngine);

    }
}



