Java Code Examples for com.polidea.rxandroidble2.RxBleClient#create()

The following examples show how to use com.polidea.rxandroidble2.RxBleClient#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From Mi365Locker with GNU General Public License v3.0 6 votes vote down vote up
private void stopScan() {
    for (Map.Entry<String, DeviceConnection> device_entry: this.devices_connections.entrySet())
    {
        device_entry.getValue().dispose();
    }
    bluetoothLeScanner.stopScan(this.mLeScanCallback);

    this.rxBleClient = RxBleClient.create(getApplicationContext());
    this.devicesAdapter = new DeviceAdapter(this, R.layout.list_device_item, new ArrayList<>());
    this.lv_scan.setAdapter(this.devicesAdapter);


    this.btManager= (BluetoothManager) this.getSystemService(Context.BLUETOOTH_SERVICE);
    mBTAdapter = this.btManager.getAdapter();

    bluetoothLeScanner = this.mBTAdapter.getBluetoothLeScanner();


    this.devices_connections = new HashMap<>();
    this.devices_to_attack = new ConcurrentLinkedQueue<>();
    this.scanning = false;
    this.updateStatus();

    this.devicesAdapter.notifyDataSetChanged();
}
 
Example 2
Source File: SampleApplication.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    rxBleClient = RxBleClient.create(this);
    RxBleClient.updateLogOptions(new LogOptions.Builder()
            .setLogLevel(LogConstants.INFO)
            .setMacAddressLogSetting(LogConstants.MAC_ADDRESS_FULL)
            .setUuidsLogSetting(LogConstants.UUIDS_FULL)
            .setShouldLogAttributeValues(true)
            .build()
    );
    RxJavaPlugins.setErrorHandler(throwable -> {
        if (throwable instanceof UndeliverableException && throwable.getCause() instanceof BleException) {
            Log.v("SampleApplication", "Suppressed UndeliverableException: " + throwable.toString());
            return; // ignore BleExceptions as they were surely delivered at least once
        }
        // add other custom handlers if needed
        throw new RuntimeException("Unexpected Throwable in RxJavaPlugins error handler", throwable);
    });
}
 
Example 3
Source File: RxBleProvider.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static synchronized RxBleClient getSingleton(final String name) {
    final RxBleClient cached = singletons.get(name);
    if (cached != null) return cached;
    //UserError.Log.wtf("RxBleProvider", "Creating new instance for: " + name); // TODO DEBUG ONLY
    final RxBleClient created = RxBleClient.create(xdrip.getAppContext());
    singletons.put(name, created);
    return created;
}
 
Example 4
Source File: RxBleProvider.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static synchronized RxBleClient getSingleton(final String name) {
    final RxBleClient cached = singletons.get(name);
    if (cached != null) return cached;
    //UserError.Log.wtf("RxBleProvider", "Creating new instance for: " + name); // TODO DEBUG ONLY
    final RxBleClient created = RxBleClient.create(xdrip.getAppContext());
    singletons.put(name, created);
    RxJavaPlugins.setErrorHandler(e -> UserError.Log.d("RXBLE" + name, "RxJavaError: " + e.getMessage()));
    return created;
}
 
Example 5
Source File: RxBleProvider.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static synchronized RxBleClient getSingleton(final String name) {
    final RxBleClient cached = singletons.get(name);
    if (cached != null) return cached;
    //UserError.Log.wtf("RxBleProvider", "Creating new instance for: " + name); // TODO DEBUG ONLY
    final RxBleClient created = RxBleClient.create(xdrip.getAppContext());
    singletons.put(name, created);
    return created;
}
 
Example 6
Source File: RxBleProvider.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static synchronized RxBleClient getSingleton(final String name) {
    final RxBleClient cached = singletons.get(name);
    if (cached != null) return cached;
    //UserError.Log.wtf("RxBleProvider", "Creating new instance for: " + name); // TODO DEBUG ONLY
    final RxBleClient created = RxBleClient.create(xdrip.getAppContext());
    singletons.put(name, created);
    RxJavaPlugins.setErrorHandler(e -> UserError.Log.d("RXBLE" + name, "RxJavaError: " + e.getMessage()));
    return created;
}
 
Example 7
Source File: DeviceActivity.java    From M365-Power with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.MyAppTheme);
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_device);


    voltageMeter = this.findViewById(R.id.voltageMeter);
    voltageMeter.setType(RequestType.VOLTAGE);
    textViews.add(voltageMeter);

    ampMeter = this.findViewById(R.id.ampMeter);
    ampMeter.setType(RequestType.AMEPERE);
    textViews.add(ampMeter);

    speedMeter = this.findViewById(R.id.speedMeter);
    speedMeter.setType(RequestType.SPEED);
    textViews.add(speedMeter);

    powerMeter = this.findViewById(R.id.powerMeter);

    minPowerView = this.findViewById(R.id.minPowerView);

    maxPowerView = this.findViewById(R.id.maxPowerView);

    efficiencyMeter = this.findViewById(R.id.efficiencyMeter);

    rangeMeter = this.findViewById(R.id.rangeMeter);

    recoveredPower = this.findViewById(R.id.recoveredPower);

    startHandlerButton = this.findViewById(R.id.start_handler_button);

    spentPower = this.findViewById(R.id.spentPower);

    battTemp = this.findViewById(R.id.battTemp);

    distance = this.findViewById(R.id.distanceMeter);

    capacity = this.findViewById(R.id.remainingAmps);

    averageEfficiency = this.findViewById(R.id.AverageEfficiencyMeter);

    averageSpeed = this.findViewById(R.id.averageSpeedMeter);

    motorTemp = this.findViewById(R.id.motorTemp);

    time = this.findViewById(R.id.time);
    life = this.findViewById(R.id.life);
    life.setType(RequestType.BATTERYLIFE);
    textViews.add(life);


    final Intent intent = getIntent();
    mDeviceName = intent.getStringExtra(EXTRAS_DEVICE_NAME);
    mDeviceAddress = intent.getStringExtra(EXTRAS_DEVICE_ADDRESS);

    rxBleClient = RxBleClient.create(this);
    bleDevice = rxBleClient.getBleDevice(mDeviceAddress);
    connectionObservable = prepareConnectionObservable();

    requestTypes.put(RequestType.VOLTAGE, new VoltageRequest());
    requestTypes.put(RequestType.AMEPERE, new AmpereRequest());
    requestTypes.put(RequestType.BATTERYLIFE, new BatteryLifeRequest());
    requestTypes.put(RequestType.SPEED, new SpeedRequest());
    requestTypes.put(RequestType.DISTANCE, new DistanceRequest());
    requestTypes.put(RequestType.SUPERMASTER, new SuperMasterRequest());
    requestTypes.put(RequestType.SUPERBATTERY, new SuperBatteryRequest());

    requestTypes.put(RequestType.LOCK,new CheckLock());
    requestTypes.put(RequestType.CRUISE,new CheckCruise());
    requestTypes.put(RequestType.LIGHT,new CheckLight());
    requestTypes.put(RequestType.RECOVERY,new CheckRecovery());

    fillCheckFirstList();

    lastTimeStamp = System.nanoTime();
    mRootView= findViewById(R.id.root);

    handlerThread=new HandlerThread("RequestThread");
    handlerThread.start();
    handler=new Handler(handlerThread.getLooper());
    handlerThread1=new HandlerThread("LoggingThread");
    handlerThread1.start();
    handler1=new Handler(handlerThread1.getLooper());

    if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {
        requestStoragePermission();
    }
    else{
        storagePermission=true;
    }
}