Make the Operations classes BLE-generic

live-activity-data
cpfeiffer 2015-08-18 00:28:17 +02:00
parent c0323339e8
commit dbb92b55bc
5 changed files with 15 additions and 24 deletions

View File

@ -80,7 +80,7 @@ public abstract class AbstractBTLEDeviceSupport extends AbstractDeviceSupport im
* @see #performConnected(Transaction)
* @see #initializeDevice(TransactionBuilder)
*/
protected TransactionBuilder performInitialized(String taskName) throws IOException {
public TransactionBuilder performInitialized(String taskName) throws IOException {
if (!isConnected()) {
if (!connect()) {
throw new IOException("1: Unable to connect to device: " + getDevice());

View File

@ -1,4 +1,4 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations;
package nodomain.freeyourgadget.gadgetbridge.service.btle;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
@ -9,33 +9,29 @@ import java.io.IOException;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEQueue;
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattCallback;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.MiBandSupport;
/**
* Abstract base class for a MiBandOperation, i.e. an operation that does more than
* just sending a few bytes to the band. It typically involves exchanging many messages
* between the mobile and the band.
* Abstract base class for a BTLEOperation, i.e. an operation that does more than
* just sending a few bytes to the device. It typically involves exchanging many messages
* between the mobile and the device.
*
* One operation may execute multiple @{link Transaction transactions} with each
* multiple @{link BTLEAction actions}.
*
* This class implements GattCallback so that subclasses may override those methods
* to handle those events.
* Note: by default all Gatt events are forwarded to MiBandSupport, subclasses may override
* Note: by default all Gatt events are forwarded to AbstractBTLEDeviceSupport, subclasses may override
* this behavior.
*/
public abstract class AbstractMiBandOperation implements GattCallback, MiBandOperation {
private final MiBandSupport mSupport;
public abstract class AbstractBTLEOperation<T extends AbstractBTLEDeviceSupport> implements GattCallback, BTLEOperation {
private final T mSupport;
protected AbstractMiBandOperation(MiBandSupport support) {
protected AbstractBTLEOperation(T support) {
mSupport = support;
}
/**
* Delegates to MiBandSupport and additionally sets this instance as the Gatt
* Delegates to the DeviceSupport instance and additionally sets this instance as the Gatt
* callback for the transaction.
* @param taskName
* @return
@ -68,7 +64,7 @@ public abstract class AbstractMiBandOperation implements GattCallback, MiBandOpe
getDevice().sendDeviceUpdateIntent(getContext());
}
public MiBandSupport getSupport() {
public T getSupport() {
return mSupport;
}

View File

@ -1,9 +1,9 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations;
package nodomain.freeyourgadget.gadgetbridge.service.btle;
import java.io.IOException;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.MiBandSupport;
public interface MiBandOperation {
public interface BTLEOperation {
public void perform() throws IOException;
}

View File

@ -917,10 +917,4 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
}
return true;
}
// overridden to make visible to operations
@Override
public TransactionBuilder performInitialized(String taskName) throws IOException {
return super.performInitialized(taskName);
}
}

View File

@ -20,13 +20,14 @@ import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandService;
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEOperation;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAction;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.MiBandSupport;
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class FetchActivityOperation extends AbstractMiBandOperation {
public class FetchActivityOperation extends AbstractBTLEOperation<MiBandSupport> {
private static final Logger LOG = LoggerFactory.getLogger(FetchActivityOperation.class);
private static final byte[] fetch = new byte[]{MiBandService.COMMAND_FETCH_DATA};