From ff7886765f0fe925f19be7664eea5cd9df3f1e69 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Tue, 13 Aug 2019 22:04:52 +0200 Subject: [PATCH] Add Swimming to sport activity types, rename some AmazfitBip stuff to Huami (these were things introduced with the bip but working with other devices now also) --- ...Type.java => HuamiSportsActivityType.java} | 24 +++++++++++-------- .../huami/amazfitbip/AmazfitBipSupport.java | 8 ++----- .../FetchSportsSummaryOperation.java | 4 ++-- .../HuamiFetchDebugLogsOperation.java} | 13 +++++----- 4 files changed, 24 insertions(+), 25 deletions(-) rename app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/{amazfitbip/BipActivityType.java => HuamiSportsActivityType.java} (77%) rename app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/{amazfitbip/operations/AmazfitBipFetchLogsOperation.java => operations/HuamiFetchDebugLogsOperation.java} (89%) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip/BipActivityType.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSportsActivityType.java similarity index 77% rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip/BipActivityType.java rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSportsActivityType.java index f3ade44bb..bd08fd488 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip/BipActivityType.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSportsActivityType.java @@ -14,20 +14,20 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ -package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip; +package nodomain.freeyourgadget.gadgetbridge.service.devices.huami; import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; -public enum BipActivityType { +public enum HuamiSportsActivityType { Outdoor(1), Treadmill(2), Walking(3), Cycling(4), - Exercise(5); - + Exercise(5), + Swimming(6); private final int code; - BipActivityType(final int code) { + HuamiSportsActivityType(final int code) { this.code = code; } @@ -43,20 +43,22 @@ public enum BipActivityType { return ActivityKind.TYPE_WALKING; case Exercise: return ActivityKind.TYPE_EXERCISE; + case Swimming: + return ActivityKind.TYPE_SWIMMING; } throw new RuntimeException("Not mapped activity kind for: " + this); } - public static BipActivityType fromCode(int bipCode) { - for (BipActivityType type : values()) { - if (type.code == bipCode) { + public static HuamiSportsActivityType fromCode(int huamiCode) { + for (HuamiSportsActivityType type : values()) { + if (type.code == huamiCode) { return type; } } - throw new RuntimeException("No matching BipActivityType for code: " + bipCode); + throw new RuntimeException("No matching HuamiSportsActivityType for code: " + huamiCode); } - public static BipActivityType fromActivityKind(int activityKind) { + public static HuamiSportsActivityType fromActivityKind(int activityKind) { switch (activityKind) { case ActivityKind.TYPE_RUNNING: return Outdoor; @@ -68,6 +70,8 @@ public enum BipActivityType { return Walking; case ActivityKind.TYPE_EXERCISE: return Exercise; + case ActivityKind.TYPE_SWIMMING: + return Swimming; } throw new RuntimeException("No matching activity activityKind: " + activityKind); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip/AmazfitBipSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip/AmazfitBipSupport.java index 967f48076..e67c6532e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip/AmazfitBipSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip/AmazfitBipSupport.java @@ -30,13 +30,11 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import java.util.Locale; import java.util.Set; import java.util.SimpleTimeZone; import java.util.UUID; import cyanogenmod.weather.util.WeatherUtils; -import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService; @@ -44,7 +42,6 @@ import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiWeatherConditions import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipService; import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst; -import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.CallSpec; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; @@ -53,13 +50,12 @@ import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes; import nodomain.freeyourgadget.gadgetbridge.model.Weather; import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; -import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.ConditionalWriteAction; import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertCategory; import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertNotificationProfile; import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.NewAlert; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiIcon; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport; -import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.operations.AmazfitBipFetchLogsOperation; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.HuamiFetchDebugLogsOperation; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchActivityOperation; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchSportsSummaryOperation; import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.NotificationStrategy; @@ -442,7 +438,7 @@ public class AmazfitBipSupport extends HuamiSupport { } else if (dataTypes == RecordedDataTypes.TYPE_GPS_TRACKS) { new FetchSportsSummaryOperation(this).perform(); } else if (dataTypes == RecordedDataTypes.TYPE_DEBUGLOGS) { - new AmazfitBipFetchLogsOperation(this).perform(); + new HuamiFetchDebugLogsOperation(this).perform(); } else { LOG.warn("fetching multiple data types at once is not supported yet"); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/FetchSportsSummaryOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/FetchSportsSummaryOperation.java index 537a4c774..a47cc445a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/FetchSportsSummaryOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/FetchSportsSummaryOperation.java @@ -44,7 +44,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport; -import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.BipActivityType; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSportsActivityType; import nodomain.freeyourgadget.gadgetbridge.util.GB; /** @@ -170,7 +170,7 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation { int activityKind = ActivityKind.TYPE_UNKNOWN; try { int rawKind = BLETypeConversions.toUnsigned(buffer.getShort()); - BipActivityType activityType = BipActivityType.fromCode(rawKind); + HuamiSportsActivityType activityType = HuamiSportsActivityType.fromCode(rawKind); activityKind = activityType.toActivityKind(); } catch (Exception ex) { LOG.error("Error mapping acivity kind: " + ex.getMessage(), ex); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip/operations/AmazfitBipFetchLogsOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/HuamiFetchDebugLogsOperation.java similarity index 89% rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip/operations/AmazfitBipFetchLogsOperation.java rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/HuamiFetchDebugLogsOperation.java index eb4a7c8b8..3d4471321 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip/operations/AmazfitBipFetchLogsOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/HuamiFetchDebugLogsOperation.java @@ -15,7 +15,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ -package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.operations; +package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations; import android.widget.Toast; @@ -36,18 +36,17 @@ import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipS import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.AmazfitBipSupport; -import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.AbstractFetchOperation; import nodomain.freeyourgadget.gadgetbridge.util.FileUtils; import nodomain.freeyourgadget.gadgetbridge.util.GB; -public class AmazfitBipFetchLogsOperation extends AbstractFetchOperation { - private static final Logger LOG = LoggerFactory.getLogger(AmazfitBipFetchLogsOperation.class); +public class HuamiFetchDebugLogsOperation extends AbstractFetchOperation { + private static final Logger LOG = LoggerFactory.getLogger(HuamiFetchDebugLogsOperation.class); private FileOutputStream logOutputStream; - public AmazfitBipFetchLogsOperation(AmazfitBipSupport support) { + public HuamiFetchDebugLogsOperation(AmazfitBipSupport support) { super(support); - setName("fetch logs"); + setName("fetch debug logs"); } @Override @@ -60,7 +59,7 @@ public class AmazfitBipFetchLogsOperation extends AbstractFetchOperation { } SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss", Locale.US); - String filename = "amazfitbip_" + dateFormat.format(new Date()) + ".log"; + String filename = "huamidebug_" + dateFormat.format(new Date()) + ".log"; File outputFile = new File(dir, filename ); try {