Skip to content

Commit

Permalink
Merge pull request #416 from Polidea/release/2.2.0
Browse files Browse the repository at this point in the history
Release 2.2.0
  • Loading branch information
mikolak authored Feb 17, 2020
2 parents 70f6795 + 9ee1603 commit 7a5e301
Show file tree
Hide file tree
Showing 90 changed files with 2,014 additions and 385 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ _android_job_template: &android_job_template
android:
components:
- tools
- build-tools-28.0.3
- android-28
- android-29
- build-tools-28.0.3
- build-tools-29.0.5
- extra-android-m2repository
licenses:
- 'android-sdk-license-.+'
env:
global:
- GRADLE_OPTS="-Xms128m"
Expand Down
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Example (debug)",
"request": "launch",
"type": "dart",
"flutterMode": "debug"
}
]
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 2.2.0

* **NEW** operations on descriptors
* **BREAKING FOR BLEMULATOR** BLEmulator versions lower than 1.1.0 are not supported from this release
* Support for AndroidX
* Support for Swift 5
* Lower iOS deployment target to 8.0

## 2.1.0

* **BREAKING** ScanResult.AdvertisementData.ManufacturerData has changed type from Int8List to Uint8List
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ For more informations, see [REFERENCE](https://github.com/Polidea/FlutterBleLib/
### Initialising
```dart
BleManager bleManager = BleManager();
bleManager.createClient(); //ready to go!
await bleManager.createClient(); //ready to go!
// your peripheral logic
bleManager.destroyClient(); //remember to release native resources when you're done!
```
Expand Down Expand Up @@ -81,6 +81,8 @@ bleManager.startPeripheralScan(
The snippet above starts peripheral scan and stops it after receiving first result.
It filters the scan results to those that advertise a service with specified UUID.

**NOTE:** `isConnectable` and `overflowServiceUuids` fields of `ScanResult` are iOS-only and remain `null` on Android.

### Connecting to peripheral
First you must obtain a _ScanResult_ from _BleManager.startPeripheralScan()_.
```dart
Expand Down
3 changes: 2 additions & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ Releases native resources. Should be called once there's no further need for BLE
bool allowDuplicates,
});
```
Returns a stream of objects containing advertisement data of the peripheral and the peripheral itself.
`scanMode` and `callbackType` are Android-specific. [More information in Android documentation](https://developer.android.com/reference/android/bluetooth/le/ScanSettings)
`allowDuplicates` is iOS-specific. [More information in iOS documentation](https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerscanoptionallowduplicateskey)
`uuids` is used to filter peripherals to only return those containing services with specified UUIDs.

Returns a stream of objects containing advertisement data of the peripheral and the peripheral itself called `ScanResult`. The object has two iOS-only fields: `isConnectable` and `overflowServiceUuids`.

```dart
Future<void> stopDeviceScan();
```
Expand Down
8 changes: 4 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.polidea.flutter_ble_lib'
version '1.0'
version '2.2.0'

buildscript {
repositories {
Expand All @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.5.3'
}
}

Expand All @@ -35,6 +35,6 @@ android {
}

dependencies {
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.github.Polidea:MultiPlatformBleAdapter:0.1.0'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'com.github.Polidea:MultiPlatformBleAdapter:0.1.4'
}
4 changes: 2 additions & 2 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
org.gradle.jvmargs=-Xmx1536M

android.useAndroidX=false
android.enableJetifier=false
android.useAndroidX=true
android.enableJetifier=true
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
import com.polidea.multiplatformbleadapter.Characteristic;
import com.polidea.multiplatformbleadapter.Service;

import java.util.List;

public class CharacteristicsResponse {
private final Characteristic[] characteristics;
private final List<Characteristic> characteristics;
private final Service service;

public CharacteristicsResponse(Characteristic[] characteristics, Service service) {
public CharacteristicsResponse(List<Characteristic> characteristics, Service service) {
this.characteristics = characteristics;
this.service = service;
}

public Characteristic[] getCharacteristics() {
public List<Characteristic> getCharacteristics() {
return characteristics;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.polidea.flutter_ble_lib;

import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;

import com.polidea.flutter_ble_lib.constant.ArgumentKey;
Expand All @@ -10,6 +9,7 @@
import com.polidea.flutter_ble_lib.delegate.BluetoothStateDelegate;
import com.polidea.flutter_ble_lib.delegate.CallDelegate;
import com.polidea.flutter_ble_lib.delegate.CharacteristicsDelegate;
import com.polidea.flutter_ble_lib.delegate.DescriptorsDelegate;
import com.polidea.flutter_ble_lib.delegate.DeviceConnectionDelegate;
import com.polidea.flutter_ble_lib.delegate.DevicesDelegate;
import com.polidea.flutter_ble_lib.delegate.LogLevelDelegate;
Expand All @@ -31,6 +31,7 @@
import java.util.LinkedList;
import java.util.List;

import androidx.annotation.NonNull;
import io.flutter.plugin.common.EventChannel;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
Expand Down Expand Up @@ -86,6 +87,7 @@ private void setupAdapter(Context context) {
delegates.add(new MtuDelegate(bleAdapter));
delegates.add(new CharacteristicsDelegate(bleAdapter, characteristicsMonitorStreamHandler));
delegates.add(new DevicesDelegate(bleAdapter));
delegates.add(new DescriptorsDelegate(bleAdapter));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,35 @@
import com.polidea.multiplatformbleadapter.Characteristic;
import com.polidea.multiplatformbleadapter.Service;

import java.util.List;
import java.util.UUID;

public class MultiCharacteristicsResponse {
private final Characteristic[] characteristics;
private Service service;
private final List<Characteristic> characteristics;
private int serviceId;
private UUID serviceUuid;

public MultiCharacteristicsResponse(Characteristic[] characteristics, Service service) {
public MultiCharacteristicsResponse(List<Characteristic> characteristics, Service service) {
this.characteristics = characteristics;
this.service = service;
this.serviceId = service.getId();
this.serviceUuid = service.getUuid();
}

public Characteristic[] getCharacteristics() {
public MultiCharacteristicsResponse(List<Characteristic> characteristics, int serviceId, UUID serviceUuid) {
this.characteristics = characteristics;
this.serviceId = serviceId;
this.serviceUuid = serviceUuid;
}

public List<Characteristic> getCharacteristics() {
return characteristics;
}

public Service getService() {
return service;
public int getServiceId() {
return serviceId;
}

public UUID getServiceUuid() {
return serviceUuid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import java.util.concurrent.atomic.AtomicBoolean;

public class SafeMainThreadResolver<T> {
public class SafeMainThreadResolver<T> implements OnSuccessCallback<T>, OnErrorCallback {

private OnErrorCallback onErrorCallback = null;
private OnSuccessCallback<T> onSuccessCallback = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public interface ArgumentKey {
String SERVICE_IDENTIFIER = "serviceId";
String CHARACTERISTIC_UUID = "characteristicUuid";
String CHARACTERISTIC_IDENTIFIER = "characteristicIdentifier";
String DESCRIPTOR_UUID = "descriptorUuid";
String DESCRIPTOR_IDENTIFIER = "descriptorIdentifier";
String VALUE = "value";
String WITH_RESPONSE = "withResponse";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public interface MethodName {
String GET_SERVICES = "services";
String GET_CHARACTERISTICS = "characteristics";
String GET_CHARACTERISTICS_FOR_SERVICE = "characteristicsForService";
String GET_DESCRIPTORS_FOR_DEVICE = "descriptorsForDevice";
String GET_DESCRIPTORS_FOR_CHARACTERISTIC = "descriptorsForCharacteristic";
String GET_DESCRIPTORS_FOR_SERVICE = "descriptorsForService";

String LOG_LEVEL = "logLevel";
String SET_LOG_LEVEL = "setLogLevel";
Expand All @@ -45,4 +48,14 @@ public interface MethodName {
String MONITOR_CHARACTERISTIC_FOR_IDENTIFIER = "monitorCharacteristicForIdentifier";
String MONITOR_CHARACTERISTIC_FOR_DEVICE = "monitorCharacteristicForDevice";
String MONITOR_CHARACTERISTIC_FOR_SERVICE = "monitorCharacteristicForService";

String READ_DESCRIPTOR_FOR_IDENTIFIER = "readDescriptorForIdentifier";
String READ_DESCRIPTOR_FOR_CHARACTERISTIC = "readDescriptorForCharacteristic";
String READ_DESCRIPTOR_FOR_SERVICE = "readDescriptorForService";
String READ_DESCRIPTOR_FOR_DEVICE = "readDescriptorForDevice";

String WRITE_DESCRIPTOR_FOR_IDENTIFIER = "writeDescriptorForIdentifier";
String WRITE_DESCRIPTOR_FOR_CHARACTERISTIC = "writeDescriptorForCharacteristic";
String WRITE_DESCRIPTOR_FOR_SERVICE = "writeDescriptorForService";
String WRITE_DESCRIPTOR_FOR_DEVICE = "writeDescriptorForDevice";
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.polidea.flutter_ble_lib.converter;

import android.support.annotation.Nullable;

import com.polidea.multiplatformbleadapter.errors.BleError;

import org.json.JSONException;
import org.json.JSONObject;

import androidx.annotation.Nullable;

public class BleErrorJsonConverter implements JsonConverter<BleError> {

public static final int MAX_ATT_ERROR = 0x80;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

public class CharacteristicJsonConverter implements JsonConverter<Characteristic> {

private interface Metadata {
Expand All @@ -25,11 +27,11 @@ public String toJson(Characteristic characteristic) throws JSONException {
return toJsonObject(characteristic).toString();
}

public String toJson(Characteristic[] characteristics) throws JSONException {
public String toJson(List<Characteristic> characteristics) throws JSONException {
return toJsonArray(characteristics).toString();
}

public JSONArray toJsonArray(Characteristic[] characteristics) throws JSONException {
public JSONArray toJsonArray(List<Characteristic> characteristics) throws JSONException {
JSONArray jsonArray = new JSONArray();
for (Characteristic characteristic : characteristics) {
jsonArray.put(toJsonObject(characteristic));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.polidea.flutter_ble_lib.converter;

import android.support.annotation.Nullable;

import com.polidea.flutter_ble_lib.ConnectionStateChange;

import org.json.JSONException;
import org.json.JSONObject;

import androidx.annotation.Nullable;

public class ConnectionStateChangeJsonConverter implements JsonConverter<ConnectionStateChange> {

private interface Metadata {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.polidea.flutter_ble_lib.converter;

import com.polidea.multiplatformbleadapter.Descriptor;
import com.polidea.multiplatformbleadapter.utils.Base64Converter;

import org.json.JSONException;
import org.json.JSONObject;

public class DescriptorJsonConverter implements JsonConverter<Descriptor> {


private interface Metadata {
String SERVICE_UUID = "serviceUuid";
String SERVICE_ID = "serviceId";
String CHARACTERISTIC_UUID = "characteristicUuid";
String CHARACTERISTIC_ID = "id";
String DESCRIPTOR_UUID = "descriptorUuid";
String DESCRIPTOR_ID = "descriptorId";
String DESCRIPTOR_VALUE = "value";
}

@Override
public String toJson(Descriptor descriptor) throws JSONException {
JSONObject jsonObject = toJsonObject(descriptor);

jsonObject.put(Metadata.SERVICE_ID, descriptor.getServiceId());
jsonObject.put(Metadata.SERVICE_UUID, descriptor.getServiceUuid());
jsonObject.put(Metadata.CHARACTERISTIC_ID, descriptor.getCharacteristicId());
jsonObject.put(Metadata.CHARACTERISTIC_UUID, descriptor.getCharacteristicUuid());

return jsonObject.toString();
}

public JSONObject toJsonObject(Descriptor descriptor) throws JSONException {
JSONObject jsonObject = new JSONObject();


jsonObject.put(Metadata.DESCRIPTOR_ID, descriptor.getId());
jsonObject.put(Metadata.DESCRIPTOR_UUID, descriptor.getUuid());
jsonObject.put(Metadata.DESCRIPTOR_VALUE,
descriptor.getValue() != null ?
Base64Converter.encode(descriptor.getValue())
: JSONObject.NULL);

return jsonObject;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.polidea.flutter_ble_lib.converter;

import android.support.annotation.Nullable;
import android.util.Log;

import com.polidea.multiplatformbleadapter.Device;
Expand All @@ -9,6 +8,8 @@
import org.json.JSONException;
import org.json.JSONObject;

import androidx.annotation.Nullable;

public class DevicesResultJsonConverter implements JsonConverter<Device[]> {

public static String TAG = DevicesResultJsonConverter.class.getName();
Expand Down
Loading

0 comments on commit 7a5e301

Please sign in to comment.