From fdffe813f2c97a4007eea26e77cec164eb7d6b6a Mon Sep 17 00:00:00 2001 From: Cre3per Date: Tue, 8 Oct 2019 13:37:25 +0200 Subject: [PATCH] makibes hr3. download progress notification (needs to be tested). --- .../gadgetbridge/service/btle/BtLEQueue.java | 2 + .../makibeshr3/MakibesHR3DeviceSupport.java | 45 +++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BtLEQueue.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BtLEQueue.java index 52b6e96d3..92b56bb33 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BtLEQueue.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BtLEQueue.java @@ -242,6 +242,7 @@ public final class BtLEQueue { mBluetoothGattServer.addService(service); } } + synchronized (mGattMonitor) { // connectGatt with true doesn't really work ;( too often connection problems if (GBApplication.isRunningMarshmallowOrLater()) { @@ -259,6 +260,7 @@ public final class BtLEQueue { private void setDeviceConnectionState(State newState) { LOG.debug("new device connection state: " + newState); + mGbDevice.setState(newState); mGbDevice.sendDeviceUpdateIntent(mContext); if (mConnectionLatch != null && newState == State.CONNECTED) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/makibeshr3/MakibesHR3DeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/makibeshr3/MakibesHR3DeviceSupport.java index 675a4627a..e3b92f7f6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/makibeshr3/MakibesHR3DeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/makibeshr3/MakibesHR3DeviceSupport.java @@ -1,11 +1,10 @@ // TODO: GB sometimes fails to connect until a connection with WearFit was made. This must be caused -// TODO: by GB, not by makibes hr3 support. +// TODO: by GB, not by makibes hr3 support. Charging the watch or attempting to pair might also +// TODO: help. This needs further research. // TODO: Where can I view today's steps in GB? // TODO: GB accumulates all step samples, even if they're part of the same day. -// TODO: Activity history download progress. - // TODO: All the commands that aren't supported by GB should be added to device specific settings. // TODO: It'd be cool if we could change the language. There's no official way to do so, but the @@ -20,6 +19,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.os.Build; +import android.os.CountDownTimer; import android.os.Handler; import android.os.VibrationEffect; import android.os.Vibrator; @@ -38,6 +38,7 @@ import java.util.GregorianCalendar; import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.GBApplication; +import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo; @@ -76,6 +77,19 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement private Handler mVibrationHandler = new Handler(); private Vibrator mVibrator; + private CountDownTimer mFetchCountDown = new CountDownTimer(1000, 1000) { + @Override + public void onTick(long millisUntilFinished) { + + } + + @Override + public void onFinish() { + LOG.debug("download finished"); + GB.updateTransferNotification(null, "", false, 100, getContext()); + } + }; + private BluetoothGattCharacteristic mControlCharacteristic = null; private BluetoothGattCharacteristic mReportCharacteristic = null; @@ -86,6 +100,20 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement addSupportedService(MakibesHR3Constants.UUID_SERVICE); } + /** + * Called whenever data is received to postpone the removing of the progress notification. + * @param start Start showing the notification + */ + private void fetch(boolean start) { + if (start) { + // We don't know how long the watch is going to take to reply. Keep progress at 0. + GB.updateTransferNotification(null, getContext().getString(R.string.busy_task_fetch_activity_data), true, 0, getContext()); + } + + this.mFetchCountDown.cancel(); + this.mFetchCountDown.start(); + } + @Override public boolean useAutoConnect() { return false; @@ -434,7 +462,7 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement } private MakibesHR3DeviceSupport sendUserInfo(TransactionBuilder builder) { - syncPreferences(builder); + this.syncPreferences(builder); return this; } @@ -455,11 +483,14 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement activityUser.getWeightKg(), activityUser.getStepsGoal() / 1000); + // setLanguage(transaction); // setScreenTime(transaction); // setUnit(transaction); // setAllDayHeart(transaction); + this.fetch(true); + return this; } @@ -482,6 +513,8 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement @Override protected TransactionBuilder initializeDevice(TransactionBuilder builder) { + GB.updateTransferNotification(null, getContext().getString(R.string.busy_task_fetch_activity_data), true, 0, getContext()); + gbDevice.setState(GBDevice.State.INITIALIZING); gbDevice.sendDeviceUpdateIntent(getContext()); @@ -644,6 +677,8 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement if (data.length < 6) return true; + this.fetch(false); + UUID characteristicUuid = characteristic.getUuid(); if (characteristicUuid.equals(mReportCharacteristic.getUuid())) { @@ -791,6 +826,8 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement int yearHeartRateAfter, int monthHeartRateAfter, int dayHeartRateAfter, int hourHeartRateAfter, int minuteHeartRateAfter) { + this.fetch(true); + byte[] data = this.craftData(MakibesHR3Constants.CMD_REQUEST_FITNESS, new byte[]{ (byte) 0x00,