From b0a0a29bcbbc7aa66dcd5c7ecaa377b732a6ed95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20B=C3=B6hler?= Date: Mon, 23 Nov 2020 22:52:30 +0100 Subject: [PATCH] Casio GB-5600B/GB-6900B: Add configurable disconnect notification --- .../gb6900/CasioGB6900DeviceCoordinator.java | 9 ++++++++- .../devices/casio/CasioGB6900DeviceSupport.java | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gb6900/CasioGB6900DeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gb6900/CasioGB6900DeviceCoordinator.java index fb609c829..6d50eaa71 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gb6900/CasioGB6900DeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gb6900/CasioGB6900DeviceCoordinator.java @@ -47,7 +47,7 @@ public class CasioGB6900DeviceCoordinator extends AbstractDeviceCoordinator { public DeviceType getSupportedType(GBDeviceCandidate candidate) { String name = candidate.getDevice().getName(); if (name != null) { - if (name.startsWith("CASIO") && (name.endsWith("6900B") || name.endsWith("5600B"))) { + if (name.startsWith("CASIO") && (name.contains("6900B") || name.contains("5600B"))) { return DeviceType.CASIOGB6900; } } @@ -149,4 +149,11 @@ public class CasioGB6900DeviceCoordinator extends AbstractDeviceCoordinator { protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException { } + + @Override + public int[] getSupportedDeviceSpecificSettings(GBDevice device) { + return new int[] { + R.xml.devicesettings_disconnectnotification_noshed + }; + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/CasioGB6900DeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/CasioGB6900DeviceSupport.java index 7f7b21559..3658d2f9f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/CasioGB6900DeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/CasioGB6900DeviceSupport.java @@ -22,6 +22,7 @@ import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattDescriptor; import android.bluetooth.BluetoothGattService; +import android.content.SharedPreferences; import android.net.Uri; import android.widget.Toast; @@ -35,6 +36,7 @@ import java.util.Calendar; import java.util.UUID; import java.util.concurrent.TimeUnit; +import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl; @@ -57,6 +59,8 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.operations.Ini import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DISCONNECTNOTIF_NOSHED; + public class CasioGB6900DeviceSupport extends AbstractBTLEDeviceSupport { private static final Logger LOG = LoggerFactory.getLogger(CasioGB6900DeviceSupport.class); @@ -184,13 +188,21 @@ public class CasioGB6900DeviceSupport extends AbstractBTLEDeviceSupport { return mModel; } - // FIXME: Replace hardcoded values by configuration private void configureWatch(TransactionBuilder builder) { if (mBtGatt == null) { return; } - byte[] value = new byte[]{GattCharacteristic.MILD_ALERT}; + SharedPreferences sharedPreferences = GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress()); + + boolean enable = sharedPreferences.getBoolean(PREF_DISCONNECTNOTIF_NOSHED, false); + + byte[] value = new byte[1]; + + if(enable) + value[0] = GattCharacteristic.MILD_ALERT; + else + value[0] = GattCharacteristic.NO_ALERT; BluetoothGattService llService = mBtGatt.getService(CasioConstants.LINK_LOSS_SERVICE); BluetoothGattCharacteristic charact = llService.getCharacteristic(CasioConstants.ALERT_LEVEL_CHARACTERISTIC_UUID);