From 34378a4a1191fcb745ce85af7106735d13f36ae3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Mon, 12 Aug 2024 19:41:50 +0100 Subject: [PATCH] Refactor ActivityKind into an enum --- .../activities/ActivitySummariesActivity.java | 19 +- .../activities/ActivitySummariesFilter.java | 28 +- .../activities/ActivitySummaryDetail.java | 6 +- .../activities/ControlCenterv2.java | 2 +- .../activities/DashboardFragment.java | 5 +- .../charts/AbstractActivityChartFragment.java | 51 ++- .../activities/charts/ActivityAnalysis.java | 22 +- .../charts/ActivityListingAdapter.java | 4 +- .../activities/charts/SleepAnalysis.java | 12 +- .../activities/charts/SleepChartFragment.java | 11 +- .../activities/charts/SleepUtils.java | 28 -- .../activities/charts/SpeedZonesFragment.java | 2 +- .../activities/charts/StepAnalysis.java | 16 +- .../charts/WeekSleepChartFragment.java | 12 +- .../dashboard/DashboardTodayWidget.java | 72 ++--- .../adapter/ActivitySummariesAdapter.java | 16 +- .../devices/AbstractSampleProvider.java | 82 +---- .../gadgetbridge/devices/SampleProvider.java | 15 +- .../devices/UnknownDeviceCoordinator.java | 11 +- .../banglejs/BangleJSSampleProvider.java | 11 +- .../gbx100/CasioGBX100SampleProvider.java | 29 +- .../samples/CmfActivitySampleProvider.java | 35 +- .../workout/CmfWorkoutSummaryParser.java | 4 +- .../devices/fitpro/FitProSampleProvider.java | 19 +- .../garmin/GarminActivitySampleProvider.java | 43 ++- .../hplus/HPlusHealthSampleProvider.java | 77 ++--- .../huami/HuamiActivitySummaryParser.java | 22 +- .../devices/huami/HuamiConst.java | 28 +- .../huami/HuamiExtendedSampleProvider.java | 30 +- .../zeppos/ZeppOsActivitySummaryParser.java | 6 +- .../devices/huawei/HuaweiSampleProvider.java | 19 +- .../devices/id115/ID115SampleProvider.java | 9 +- .../devices/jyou/JYouSampleProvider.java | 9 +- .../devices/lefun/LefunSampleProvider.java | 18 +- .../watchxplus/WatchXPlusSampleProvider.java | 84 ++--- .../makibeshr3/MakibesHR3SampleProvider.java | 16 +- .../devices/miband/MiBand2SampleProvider.java | 12 +- .../devices/miband/MiBandSampleProvider.java | 26 +- .../devices/no1f1/No1F1SampleProvider.java | 9 +- .../pebble/PebbleHealthSampleProvider.java | 21 +- .../pebble/PebbleMisfitSampleProvider.java | 9 +- .../pebble/PebbleMorpheuzSampleProvider.java | 9 +- .../PineTimeActivitySampleProvider.java | 18 +- .../HybridHRActivitySampleProvider.java | 23 +- .../devices/qhybrid/QHybridConstants.java | 10 +- .../SonyWena3ActivitySampleProvider.java | 38 +-- .../sonyswr12/SonySWR12SampleProvider.java | 22 +- .../test/samples/TestSampleProvider.java | 24 +- .../devices/tlw64/TLW64SampleProvider.java | 9 +- .../vivomovehr/VivomoveHrSampleProvider.java | 68 ++-- .../WithingsSteelHRSampleProvider.java | 41 +-- .../devices/xiaomi/XiaomiSampleProvider.java | 44 +-- .../devices/xwatch/XWatchSampleProvider.java | 6 +- .../devices/zetime/ZeTimeSampleProvider.java | 9 +- .../entities/AbstractActivitySample.java | 9 +- .../AbstractPebbleHealthActivitySample.java | 2 +- .../AbstractPebbleMisfitActivitySample.java | 10 +- .../AbstractPebbleMorpheuzActivitySample.java | 8 +- .../opentracks/OpenTracksController.java | 14 +- .../gadgetbridge/model/ActivityAmount.java | 20 +- .../gadgetbridge/model/ActivityKind.java | 299 +++++------------- .../gadgetbridge/model/ActivitySample.java | 4 +- .../gadgetbridge/model/ActivitySession.java | 8 +- .../gadgetbridge/model/DailyTotals.java | 6 +- .../banglejs/BangleJSActivityTrack.java | 24 +- .../gbx100/FetchStepCountDataOperation.java | 8 +- .../devices/cmfwatchpro/CmfActivitySync.java | 2 +- .../devices/cmfwatchpro/CmfActivityType.java | 42 +-- .../support/CyclingSensorSupport.java | 2 +- .../devices/fitpro/FitProDeviceSupport.java | 4 +- .../devices/garmin/fit/FitImporter.java | 50 +-- .../devices/hplus/HPlusDataRecord.java | 13 +- .../hplus/HPlusDataRecordRealtime.java | 12 +- .../devices/hplus/HPlusDataRecordSleep.java | 4 +- .../devices/hplus/HPlusHandlerThread.java | 10 +- .../huami/HuamiSportsActivityType.java | 84 ++--- .../service/devices/huami/HuamiSupport.java | 8 +- .../huami/HuamiWorkoutTrackActivityType.java | 24 +- .../fetch/FetchSportsDetailsOperation.java | 15 +- .../huami/zeppos/ZeppOsActivityType.java | 44 +-- .../devices/huami/zeppos/ZeppOsSupport.java | 4 +- .../devices/huawei/HuaweiWorkoutGbParser.java | 46 +-- .../devices/id115/FetchActivityOperation.java | 8 +- .../service/devices/jyou/JYouDataRecord.java | 81 ----- .../watchxplus/WatchXPlusDeviceSupport.java | 8 +- .../makibeshr3/MakibesHR3DeviceSupport.java | 14 +- .../service/devices/no1f1/No1F1Support.java | 13 +- .../devices/pinetime/PineTimeJFSupport.java | 4 +- .../devices/qhybrid/parser/ActivityEntry.java | 19 +- .../workout/WorkoutRequestHandler.java | 14 +- .../service/devices/tlw64/TLW64Support.java | 18 +- .../WithingsSteelHRDeviceSupport.java | 4 +- .../activity/SleepActivitySampleHelper.java | 13 +- .../activity/WithingsActivityType.java | 76 ++--- .../conversation/ActivitySampleHandler.java | 48 +-- .../message/incoming/LiveWorkoutHandler.java | 2 +- .../xiaomi/activity/XiaomiActivityParser.java | 2 +- .../activity/impl/WorkoutGpsParser.java | 3 +- .../activity/impl/WorkoutSummaryParser.java | 16 +- .../impl/XiaomiSimpleActivityParser.java | 6 +- .../xiaomi/services/XiaomiHealthService.java | 16 +- .../service/devices/xwatch/XWatchSupport.java | 2 +- .../devices/zetime/ZeTimeDeviceSupport.java | 8 +- .../freeyourgadget/gadgetbridge/util/GB.java | 4 +- app/src/main/res/values/strings.xml | 1 + .../database/SampleProviderTest.java | 34 +- .../gadgetbridge/model/ActivityKindTest.java | 20 ++ 107 files changed, 1016 insertions(+), 1465 deletions(-) delete mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/SleepUtils.java delete mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/jyou/JYouDataRecord.java create mode 100644 app/src/test/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityKindTest.java diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesActivity.java index bd001f9d0..ead0e87c3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesActivity.java @@ -46,9 +46,6 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.floatingactionbutton.FloatingActionButton; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.File; import java.io.Serializable; import java.util.ArrayList; @@ -75,8 +72,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.GB; public class ActivitySummariesActivity extends AbstractListActivity { static final int ACTIVITY_FILTER = 1; static final int ACTIVITY_DETAIL = 11; - private static final Logger LOG = LoggerFactory.getLogger(ActivitySummariesActivity.class); - HashMap activityKindMap = new HashMap<>(0); + HashMap activityKindMap = new HashMap<>(0); int activityFilter = 0; long dateFromFilter = 0; long dateToFilter = 0; @@ -326,15 +322,14 @@ public class ActivitySummariesActivity extends AbstractListActivity newMap = new LinkedHashMap<>(0); //reset + private LinkedHashMap fillKindMap() { + LinkedHashMap newMap = new LinkedHashMap<>(0); //reset - newMap.put(getString(R.string.activity_summaries_all_activities), 0); + newMap.put(getString(R.string.activity_summaries_all_activities), ActivityKind.UNKNOWN); for (BaseActivitySummary item : getItemAdapter().getItems()) { - String activityName = ActivityKind.asString(item.getActivityKind(), this); + String activityName = ActivityKind.fromCode(item.getActivityKind()).getLabel(this); if (!newMap.containsKey(activityName) && item.getActivityKind() != 0) { - newMap.put(activityName, item.getActivityKind()); - + newMap.put(activityName, ActivityKind.fromCode(item.getActivityKind())); } } return newMap; @@ -395,7 +390,7 @@ public class ActivitySummariesActivity extends AbstractListActivity 0) { + if (!uris.isEmpty()) { final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE); intent.setType("application/gpx+xml"); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesFilter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesFilter.java index 552b46c67..abaab74d1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesFilter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesFilter.java @@ -75,7 +75,7 @@ public class ActivitySummariesFilter extends AbstractGBActivity { long dateFromFilter = 0; long dateToFilter = 0; String nameContainsFilter; - HashMap activityKindMap = new HashMap<>(1); + HashMap activityKindMap = new HashMap<>(1); List itemsFilter; long deviceFilter; long initial_deviceFilter; @@ -87,7 +87,7 @@ public class ActivitySummariesFilter extends AbstractGBActivity { super.onCreate(savedInstanceState); Bundle bundle = this.getIntent().getExtras(); - activityKindMap = (HashMap) bundle.getSerializable("activityKindMap"); + activityKindMap = (HashMap) bundle.getSerializable("activityKindMap"); itemsFilter = (List) bundle.getSerializable("itemsFilter"); activityFilter = bundle.getInt("activityFilter", 0); dateFromFilter = bundle.getLong("dateFromFilter", 0); @@ -120,13 +120,13 @@ public class ActivitySummariesFilter extends AbstractGBActivity { final Spinner filterKindSpinner = findViewById(R.id.select_kind); ArrayList kindArray = new ArrayList<>(); - for (Map.Entry item : activityKindMap.entrySet()) { - if (item.getValue() == 0) continue; //do not put here All devices, but we do need them in the array - kindArray.add(new SpinnerWithIconItem(item.getKey(), new Long(item.getValue()), ActivityKind.getIconId(item.getValue()))); + for (Map.Entry item : activityKindMap.entrySet()) { + if (item.getValue() == ActivityKind.UNKNOWN) continue; //do not put here All devices, but we do need them in the array + kindArray.add(new SpinnerWithIconItem(item.getKey(), (long) item.getValue().getCode(), item.getValue().getIcon())); } //ensure that all items is always first in the list, this is an issue on old android - SpinnerWithIconItem allActivities = new SpinnerWithIconItem(getString(R.string.activity_summaries_all_activities), new Long(0), ActivityKind.getIconId(0)); + SpinnerWithIconItem allActivities = new SpinnerWithIconItem(getString(R.string.activity_summaries_all_activities), (long) ActivityKind.UNKNOWN.getCode(), ActivityKind.UNKNOWN.getIcon()); kindArray.add(0, allActivities); SpinnerWithIconAdapter adapter = new SpinnerWithIconAdapter(this, @@ -407,12 +407,14 @@ public class ActivitySummariesFilter extends AbstractGBActivity { return newMap; } - public SpinnerWithIconItem getKindByValue(Integer value) { - for (Map.Entry entry : activityKindMap.entrySet()) { - if (Objects.equals(value, entry.getValue())) { - return new SpinnerWithIconItem(entry.getKey(), - new Long(entry.getValue()), - ActivityKind.getIconId(entry.getValue())); + public SpinnerWithIconItem getKindByValue(int value) { + for (Map.Entry entry : activityKindMap.entrySet()) { + if (value == entry.getValue().getCode()) { + return new SpinnerWithIconItem( + entry.getKey(), + (long) entry.getValue().getCode(), + entry.getValue().getIcon() + ); } } return null; @@ -434,7 +436,7 @@ public class ActivitySummariesFilter extends AbstractGBActivity { public void onItemSelected(AdapterView parent, View view, int pos, long id) { SpinnerWithIconItem selectedItem = (SpinnerWithIconItem) parent.getItemAtPosition(pos); String activity = selectedItem.getText(); - activityFilter = activityKindMap.get(activity); + activityFilter = activityKindMap.get(activity).getCode(); update_filter_fields(); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummaryDetail.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummaryDetail.java index b1c91702d..7f95284de 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummaryDetail.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummaryDetail.java @@ -345,7 +345,7 @@ public class ActivitySummaryDetail extends AbstractGBActivity { private void makeSummaryHeader(BaseActivitySummary item) { //make view of data from main part of item - String activitykindname = ActivityKind.asString(item.getActivityKind(), getApplicationContext()); + String activitykindname = ActivityKind.fromCode(item.getActivityKind()).getLabel(getApplicationContext()); String activityname = item.getName(); Date starttime = item.getStartTime(); Date endtime = item.getEndTime(); @@ -354,7 +354,7 @@ public class ActivitySummaryDetail extends AbstractGBActivity { String durationhms = DateTimeUtils.formatDurationHoursMinutes((endtime.getTime() - starttime.getTime()), TimeUnit.MILLISECONDS); ImageView activity_icon = findViewById(R.id.item_image); - activity_icon.setImageResource(ActivityKind.getIconId(item.getActivityKind())); + activity_icon.setImageResource(ActivityKind.fromCode(item.getActivityKind()).getIcon()); TextView activity_kind = findViewById(R.id.activitykind); activity_kind.setText(activitykindname); @@ -594,7 +594,7 @@ public class ActivitySummaryDetail extends AbstractGBActivity { int height = layout.getChildAt(0).getWidth(); Bitmap screenShot = getScreenShot(layout, width, height, context); - String fileName = FileUtils.makeValidFileName("Screenshot-" + ActivityKind.asString(currentItem.getActivityKind(), context).toLowerCase() + "-" + DateTimeUtils.formatIso8601(currentItem.getStartTime()) + ".png"); + String fileName = FileUtils.makeValidFileName("Screenshot-" + ActivityKind.fromCode(currentItem.getActivityKind()).getLabel(context).toLowerCase() + "-" + DateTimeUtils.formatIso8601(currentItem.getStartTime()) + ".png"); try { File targetFile = new File(FileUtils.getExternalFilesDir(), fileName); FileOutputStream fOut = new FileOutputStream(targetFile); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java index e6911455f..d6fe983af 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java @@ -261,7 +261,7 @@ public class ControlCenterv2 extends AppCompatActivity // Signal DeviceCommunicationService to fetch activity for all connected devices Intent intent = new Intent(getApplicationContext(), DeviceCommunicationService.class); intent.setAction(DeviceService.ACTION_FETCH_RECORDED_DATA) - .putExtra(DeviceService.EXTRA_RECORDED_DATA_TYPES, ActivityKind.TYPE_ACTIVITY); + .putExtra(DeviceService.EXTRA_RECORDED_DATA_TYPES, ActivityKind.ACTIVITY); startService(intent); // Hide 'refreshing' animation immediately if no health devices are connected List devices1 = GBApplication.app().getDeviceManager().getDevices(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DashboardFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DashboardFragment.java index d5b7af412..328087cff 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DashboardFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DashboardFragment.java @@ -63,6 +63,7 @@ import nodomain.freeyourgadget.gadgetbridge.activities.dashboard.DashboardSleepW import nodomain.freeyourgadget.gadgetbridge.activities.dashboard.DashboardStepsWidget; import nodomain.freeyourgadget.gadgetbridge.activities.dashboard.DashboardTodayWidget; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; +import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; import nodomain.freeyourgadget.gadgetbridge.util.DashboardUtils; import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils; import nodomain.freeyourgadget.gadgetbridge.util.Prefs; @@ -422,11 +423,11 @@ public class DashboardFragment extends Fragment { } public static class GeneralizedActivity implements Serializable { - public int activityKind; + public ActivityKind activityKind; public long timeFrom; public long timeTo; - public GeneralizedActivity(int activityKind, long timeFrom, long timeTo) { + public GeneralizedActivity(ActivityKind activityKind, long timeFrom, long timeTo) { this.activityKind = activityKind; this.timeFrom = timeFrom; this.timeTo = timeTo; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractActivityChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractActivityChartFragment.java index 0dab39da6..3b0ad3cf3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractActivityChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractActivityChartFragment.java @@ -45,12 +45,13 @@ import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample; -import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper; import nodomain.freeyourgadget.gadgetbridge.util.Prefs; public abstract class AbstractActivityChartFragment extends AbstractChartFragment { private static final Logger LOG = LoggerFactory.getLogger(AbstractActivityChartFragment.class); + public static final float Y_VALUE_DEEP_SLEEP = 0.01f; + public boolean supportsHeartrate(GBDevice device) { DeviceCoordinator coordinator = device.getDeviceCoordinator(); return coordinator != null && coordinator.supportsHeartRateMeasurement(device); @@ -62,11 +63,11 @@ public abstract class AbstractActivityChartFragment extend } protected static final class ActivityConfig { - public final int type; + public final ActivityKind type; public final String label; public final Integer color; - public ActivityConfig(int kind, String label, Integer color) { + public ActivityConfig(ActivityKind kind, String label, Integer color) { this.type = kind; this.label = label; this.color = color; @@ -122,22 +123,22 @@ public abstract class AbstractActivityChartFragment extend HEARTRATE_LABEL = getContext().getString(R.string.charts_legend_heartrate); HEARTRATE_AVERAGE_LABEL = getContext().getString(R.string.charts_legend_heartrate_average); - akActivity = new ActivityConfig(ActivityKind.TYPE_ACTIVITY, getString(R.string.abstract_chart_fragment_kind_activity), AK_ACTIVITY_COLOR); - akLightSleep = new ActivityConfig(ActivityKind.TYPE_LIGHT_SLEEP, getString(R.string.abstract_chart_fragment_kind_light_sleep), AK_LIGHT_SLEEP_COLOR); - akDeepSleep = new ActivityConfig(ActivityKind.TYPE_DEEP_SLEEP, getString(R.string.abstract_chart_fragment_kind_deep_sleep), AK_DEEP_SLEEP_COLOR); - akRemSleep = new ActivityConfig(ActivityKind.TYPE_REM_SLEEP, getString(R.string.abstract_chart_fragment_kind_rem_sleep), AK_REM_SLEEP_COLOR); - akNotWorn = new ActivityConfig(ActivityKind.TYPE_NOT_WORN, getString(R.string.abstract_chart_fragment_kind_not_worn), AK_NOT_WORN_COLOR); + akActivity = new ActivityConfig(ActivityKind.ACTIVITY, getString(R.string.abstract_chart_fragment_kind_activity), AK_ACTIVITY_COLOR); + akLightSleep = new ActivityConfig(ActivityKind.LIGHT_SLEEP, getString(R.string.abstract_chart_fragment_kind_light_sleep), AK_LIGHT_SLEEP_COLOR); + akDeepSleep = new ActivityConfig(ActivityKind.DEEP_SLEEP, getString(R.string.abstract_chart_fragment_kind_deep_sleep), AK_DEEP_SLEEP_COLOR); + akRemSleep = new ActivityConfig(ActivityKind.REM_SLEEP, getString(R.string.abstract_chart_fragment_kind_rem_sleep), AK_REM_SLEEP_COLOR); + akNotWorn = new ActivityConfig(ActivityKind.NOT_WORN, getString(R.string.abstract_chart_fragment_kind_not_worn), AK_NOT_WORN_COLOR); } - protected Integer getColorFor(int activityKind) { + protected Integer getColorFor(ActivityKind activityKind) { switch (activityKind) { - case ActivityKind.TYPE_DEEP_SLEEP: + case DEEP_SLEEP: return akDeepSleep.color; - case ActivityKind.TYPE_LIGHT_SLEEP: + case LIGHT_SLEEP: return akLightSleep.color; - case ActivityKind.TYPE_REM_SLEEP: + case REM_SLEEP: return akRemSleep.color; - case ActivityKind.TYPE_ACTIVITY: + case ACTIVITY: return akActivity.color; } return akActivity.color; @@ -166,12 +167,6 @@ public abstract class AbstractActivityChartFragment extend return provider.getActivitySamples(tsFrom, tsTo); } - - protected List getSleepSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) { - SampleProvider provider = getProvider(db, device); - return provider.getSleepSamples(tsFrom, tsTo); - } - public DefaultChartsData refresh(GBDevice gbDevice, List samples) { // Calendar cal = GregorianCalendar.getInstance(); // cal.clear(); @@ -187,7 +182,7 @@ public abstract class AbstractActivityChartFragment extend boolean annotate = true; boolean use_steps_as_movement; - int last_type = ActivityKind.TYPE_UNKNOWN; + ActivityKind last_type = ActivityKind.UNKNOWN; int numEntries = samples.size(); List activityEntries = new ArrayList<>(numEntries); @@ -203,7 +198,7 @@ public abstract class AbstractActivityChartFragment extend for (int i = 0; i < numEntries; i++) { ActivitySample sample = samples.get(i); - int type = sample.getKind(); + ActivityKind type = sample.getKind(); int ts = tsTranslation.shorten(sample.getTimestamp()); // System.out.println(ts); @@ -223,7 +218,7 @@ public abstract class AbstractActivityChartFragment extend float value = movement; switch (type) { - case ActivityKind.TYPE_DEEP_SLEEP: + case DEEP_SLEEP: if (last_type != type) { //FIXME: this is ugly but it works (repeated in each case) deepSleepEntries.add(createLineEntry(0, ts - 1)); @@ -232,9 +227,9 @@ public abstract class AbstractActivityChartFragment extend notWornEntries.add(createLineEntry(0, ts)); activityEntries.add(createLineEntry(0, ts)); } - deepSleepEntries.add(createLineEntry(value + SleepUtils.Y_VALUE_DEEP_SLEEP, ts)); + deepSleepEntries.add(createLineEntry(value + Y_VALUE_DEEP_SLEEP, ts)); break; - case ActivityKind.TYPE_LIGHT_SLEEP: + case LIGHT_SLEEP: if (last_type != type) { lightSleepEntries.add(createLineEntry(0, ts - 1)); @@ -245,7 +240,7 @@ public abstract class AbstractActivityChartFragment extend } lightSleepEntries.add(createLineEntry(value, ts)); break; - case ActivityKind.TYPE_REM_SLEEP: + case REM_SLEEP: if (last_type != type) { remSleepEntries.add(createLineEntry(0, ts - 1)); @@ -256,7 +251,7 @@ public abstract class AbstractActivityChartFragment extend } remSleepEntries.add(createLineEntry(value, ts)); break; - case ActivityKind.TYPE_NOT_WORN: + case NOT_WORN: if (last_type != type) { notWornEntries.add(createLineEntry(0, ts - 1)); @@ -265,7 +260,7 @@ public abstract class AbstractActivityChartFragment extend remSleepEntries.add(createLineEntry(0, ts)); activityEntries.add(createLineEntry(0, ts)); } - notWornEntries.add(createLineEntry(SleepUtils.Y_VALUE_DEEP_SLEEP, ts)); //a small value, just to show something on the graphs + notWornEntries.add(createLineEntry(Y_VALUE_DEEP_SLEEP, ts)); //a small value, just to show something on the graphs break; default: // short steps = sample.getSteps(); @@ -284,7 +279,7 @@ public abstract class AbstractActivityChartFragment extend } activityEntries.add(createLineEntry(value, ts)); } - if (hr && sample.getKind() != ActivityKind.TYPE_NOT_WORN && heartRateUtilsInstance.isValidHeartRateValue(sample.getHeartRate())) { + if (hr && sample.getKind() != ActivityKind.NOT_WORN && heartRateUtilsInstance.isValidHeartRateValue(sample.getHeartRate())) { if (lastHrSampleIndex > -1 && ts - lastHrSampleIndex > 1800*HeartRateUtils.MAX_HR_MEASUREMENTS_GAP_MINUTES) { heartrateEntries.add(createLineEntry(0, lastHrSampleIndex + 1)); heartrateEntries.add(createLineEntry(0, ts - 1)); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityAnalysis.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityAnalysis.java index 28b82b77b..311e11702 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityAnalysis.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityAnalysis.java @@ -37,30 +37,30 @@ public class ActivityAnalysis { private int maxSpeed = 0; public ActivityAmounts calculateActivityAmounts(List samples) { - ActivityAmount deepSleep = new ActivityAmount(ActivityKind.TYPE_DEEP_SLEEP); - ActivityAmount lightSleep = new ActivityAmount(ActivityKind.TYPE_LIGHT_SLEEP); - ActivityAmount remSleep = new ActivityAmount(ActivityKind.TYPE_REM_SLEEP); - ActivityAmount notWorn = new ActivityAmount(ActivityKind.TYPE_NOT_WORN); - ActivityAmount activity = new ActivityAmount(ActivityKind.TYPE_ACTIVITY); + ActivityAmount deepSleep = new ActivityAmount(ActivityKind.DEEP_SLEEP); + ActivityAmount lightSleep = new ActivityAmount(ActivityKind.LIGHT_SLEEP); + ActivityAmount remSleep = new ActivityAmount(ActivityKind.REM_SLEEP); + ActivityAmount notWorn = new ActivityAmount(ActivityKind.NOT_WORN); + ActivityAmount activity = new ActivityAmount(ActivityKind.ACTIVITY); ActivityAmount previousAmount = null; ActivitySample previousSample = null; for (ActivitySample sample : samples) { ActivityAmount amount; switch (sample.getKind()) { - case ActivityKind.TYPE_DEEP_SLEEP: + case DEEP_SLEEP: amount = deepSleep; break; - case ActivityKind.TYPE_LIGHT_SLEEP: + case LIGHT_SLEEP: amount = lightSleep; break; - case ActivityKind.TYPE_REM_SLEEP: + case REM_SLEEP: amount = remSleep; break; - case ActivityKind.TYPE_NOT_WORN: + case NOT_WORN: amount = notWorn; break; - case ActivityKind.TYPE_ACTIVITY: + case ACTIVITY: default: amount = activity; break; @@ -82,7 +82,7 @@ public class ActivityAnalysis { } // add time - if (steps > 0 && sample.getKind() == ActivityKind.TYPE_ACTIVITY) { + if (steps > 0 && sample.getKind() == ActivityKind.ACTIVITY) { if (steps > maxSpeed) { maxSpeed = steps; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityListingAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityListingAdapter.java index 024539edc..08f3b36fa 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityListingAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityListingAdapter.java @@ -254,7 +254,7 @@ public class ActivityListingAdapter extends AbstractActivityListingAdapter heartRateValues = new ArrayList<>(); HeartRateUtils heartRateUtilsInstance = HeartRateUtils.getInstance(); for (ActivitySample sample : samples) { - if (sample.getKind() == ActivityKind.TYPE_LIGHT_SLEEP || sample.getKind() == ActivityKind.TYPE_DEEP_SLEEP) { + if (sample.getKind() == ActivityKind.LIGHT_SLEEP || sample.getKind() == ActivityKind.DEEP_SLEEP) { int heartRate = sample.getHeartRate(); if (heartRateUtilsInstance.isValidHeartRateValue(heartRate)) { heartRateValues.add(heartRate); @@ -309,7 +309,7 @@ public class SleepChartFragment extends AbstractActivityChartFragment allIntensities = new ArrayList<>(); for (ActivitySample s : samples) { - if (s.getKind() == ActivityKind.TYPE_LIGHT_SLEEP || s.getKind() == ActivityKind.TYPE_DEEP_SLEEP) { + if (s.getKind() == ActivityKind.LIGHT_SLEEP || s.getKind() == ActivityKind.DEEP_SLEEP) { float intensity = s.getIntensity(); allIntensities.add(intensity); } @@ -477,7 +477,6 @@ public class SleepChartFragment extends AbstractActivityChartFragment getSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) { // temporary fix for totally wrong sleep amounts -// return super.getSleepSamples(db, device, tsFrom, tsTo); return super.getAllSamples(db, device, tsFrom, tsTo); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/SleepUtils.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/SleepUtils.java deleted file mode 100644 index 1b4fcbbce..000000000 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/SleepUtils.java +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright (C) 2015-2024 Carsten Pfeiffer - - This file is part of Gadgetbridge. - - Gadgetbridge is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Gadgetbridge is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . */ -package nodomain.freeyourgadget.gadgetbridge.activities.charts; - -import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; - -public class SleepUtils { - public static final float Y_VALUE_DEEP_SLEEP = 0.01f; - public static final float Y_VALUE_LIGHT_SLEEP = 0.016f; - - public static boolean isSleep(byte type) { - return type == ActivityKind.TYPE_DEEP_SLEEP || type == ActivityKind.TYPE_LIGHT_SLEEP; - } -} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/SpeedZonesFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/SpeedZonesFragment.java index 74fd2ae64..74986cb48 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/SpeedZonesFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/SpeedZonesFragment.java @@ -79,7 +79,7 @@ public class SpeedZonesFragment extends AbstractActivityChartFragment heartRateSum = new ArrayList<>(); List heartRateBetweenActivePeriodsSum = new ArrayList<>(); @@ -67,7 +67,7 @@ public class StepAnalysis { totalDailySteps += steps; } - if (sample.getKind() != ActivityKind.TYPE_SLEEP //anything but sleep counts + if (!ActivityKind.isSleep(sample.getKind()) //anything but sleep counts && !(sample instanceof TrailingActivitySample)) { //trailing samples have wrong date and make trailing activity have 0 duration if (sessionStart == null) { @@ -178,7 +178,7 @@ public class StepAnalysis { endTime = new Date(durationSum); ActivitySession stepSessionSummary = new ActivitySession(startTime, endTime, - stepsSum, heartRateAverage, intensitySum, distanceSum, 0); + stepsSum, heartRateAverage, intensitySum, distanceSum, ActivityKind.UNKNOWN); stepSessionSummary.setSessionCount(sessionCount); stepSessionSummary.setSessionType(ActivitySession.SESSION_SUMMARY); @@ -207,19 +207,19 @@ public class StepAnalysis { return result; } - private int detect_activity_kind(int session_length, int activeSteps, int heartRateAverage, float intensity) { + private ActivityKind detect_activity_kind(int session_length, int activeSteps, int heartRateAverage, float intensity) { final int MIN_STEPS_PER_MINUTE_FOR_RUN = GBApplication.getPrefs().getInt("chart_list_min_steps_per_minute_for_run", 120); int spm = (int) (activeSteps / (session_length / 60)); if (spm > MIN_STEPS_PER_MINUTE_FOR_RUN) { - return ActivityKind.TYPE_RUNNING; + return ActivityKind.RUNNING; } if (activeSteps > 200) { - return ActivityKind.TYPE_WALKING; + return ActivityKind.WALKING; } if (heartRateAverage > 90 && intensity > 15) { //needs tuning - return ActivityKind.TYPE_EXERCISE; + return ActivityKind.EXERCISE; } - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; } private Date getDateFromSample(ActivitySample sample) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekSleepChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekSleepChartFragment.java index 01b5569bf..4a9f11224 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekSleepChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/WeekSleepChartFragment.java @@ -197,9 +197,9 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment { long balance = 0; for (ActivityAmount amount : activityAmounts.getAmounts()) { - if (amount.getActivityKind() == ActivityKind.TYPE_DEEP_SLEEP || - amount.getActivityKind() == ActivityKind.TYPE_LIGHT_SLEEP || - amount.getActivityKind() == ActivityKind.TYPE_REM_SLEEP) { + if (amount.getActivityKind() == ActivityKind.DEEP_SLEEP || + amount.getActivityKind() == ActivityKind.LIGHT_SLEEP || + amount.getActivityKind() == ActivityKind.REM_SLEEP) { balance += amount.getTotalSeconds(); } } @@ -224,11 +224,11 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment { long totalSecondsLightSleep = 0; long totalSecondsRemSleep = 0; for (ActivityAmount amount : activityAmounts.getAmounts()) { - if (amount.getActivityKind() == ActivityKind.TYPE_DEEP_SLEEP) { + if (amount.getActivityKind() == ActivityKind.DEEP_SLEEP) { totalSecondsDeepSleep += amount.getTotalSeconds(); - } else if (amount.getActivityKind() == ActivityKind.TYPE_LIGHT_SLEEP) { + } else if (amount.getActivityKind() == ActivityKind.LIGHT_SLEEP) { totalSecondsLightSleep += amount.getTotalSeconds(); - } else if (amount.getActivityKind() == ActivityKind.TYPE_REM_SLEEP) { + } else if (amount.getActivityKind() == ActivityKind.REM_SLEEP) { totalSecondsRemSleep += amount.getTotalSeconds(); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/dashboard/DashboardTodayWidget.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/dashboard/DashboardTodayWidget.java index 865d03560..7b996cf54 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/dashboard/DashboardTodayWidget.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/dashboard/DashboardTodayWidget.java @@ -246,27 +246,27 @@ public class DashboardTodayWidget extends AbstractDashboardWidget { } float start_angle = startAngle + (activity.timeFrom - dashboardData.timeFrom) / degreeFactor; float sweep_angle = (activity.timeTo - activity.timeFrom) / degreeFactor; - if (activity.activityKind == ActivityKind.TYPE_NOT_MEASURED) { + if (activity.activityKind == ActivityKind.NOT_MEASURED) { paint.setStrokeWidth(barWidth / 3f); paint.setColor(color_worn); canvas.drawArc(margin, margin, width - margin, height - margin, start_angle, sweep_angle, false, paint); - } else if (activity.activityKind == ActivityKind.TYPE_NOT_WORN) { + } else if (activity.activityKind == ActivityKind.NOT_WORN) { paint.setStrokeWidth(barWidth / 3f); paint.setColor(color_not_worn); canvas.drawArc(margin, margin, width - margin, height - margin, start_angle, sweep_angle, false, paint); - } else if (activity.activityKind == ActivityKind.TYPE_LIGHT_SLEEP || activity.activityKind == ActivityKind.TYPE_SLEEP) { + } else if (activity.activityKind == ActivityKind.LIGHT_SLEEP || activity.activityKind == ActivityKind.SLEEP_ANY) { paint.setStrokeWidth(barWidth); paint.setColor(color_light_sleep); canvas.drawArc(margin, margin, width - margin, height - margin, start_angle, sweep_angle, false, paint); - } else if (activity.activityKind == ActivityKind.TYPE_REM_SLEEP) { + } else if (activity.activityKind == ActivityKind.REM_SLEEP) { paint.setStrokeWidth(barWidth); paint.setColor(color_rem_sleep); canvas.drawArc(margin, margin, width - margin, height - margin, start_angle, sweep_angle, false, paint); - } else if (activity.activityKind == ActivityKind.TYPE_DEEP_SLEEP) { + } else if (activity.activityKind == ActivityKind.DEEP_SLEEP) { paint.setStrokeWidth(barWidth); paint.setColor(color_deep_sleep); canvas.drawArc(margin, margin, width - margin, height - margin, start_angle, sweep_angle, false, paint); - } else if (activity.activityKind == ActivityKind.TYPE_EXERCISE) { + } else if (activity.activityKind == ActivityKind.EXERCISE) { paint.setStrokeWidth(barWidth); paint.setColor(color_exercise); canvas.drawArc(margin, margin, width - margin, height - margin, start_angle, sweep_angle, false, paint); @@ -334,9 +334,9 @@ public class DashboardTodayWidget extends AbstractDashboardWidget { } private class FillDataAsyncTask extends AsyncTask { - private final TreeMap activityTimestamps = new TreeMap<>(); + private final TreeMap activityTimestamps = new TreeMap<>(); - private void addActivity(long timeFrom, long timeTo, int activityKind) { + private void addActivity(long timeFrom, long timeTo, ActivityKind activityKind) { for (long i = timeFrom; i<=timeTo; i++) { // If the current timestamp isn't saved yet, do so immediately if (activityTimestamps.get(i) == null) { @@ -346,36 +346,36 @@ public class DashboardTodayWidget extends AbstractDashboardWidget { // If the current timestamp is already saved, compare the activity kinds and // keep the most 'important' one switch (activityTimestamps.get(i)) { - case ActivityKind.TYPE_EXERCISE: + case EXERCISE: break; - case ActivityKind.TYPE_ACTIVITY: - if (activityKind == ActivityKind.TYPE_EXERCISE) + case ACTIVITY: + if (activityKind == ActivityKind.EXERCISE) activityTimestamps.put(i, activityKind); break; - case ActivityKind.TYPE_DEEP_SLEEP: - if (activityKind == ActivityKind.TYPE_EXERCISE || - activityKind == ActivityKind.TYPE_ACTIVITY) + case DEEP_SLEEP: + if (activityKind == ActivityKind.EXERCISE || + activityKind == ActivityKind.ACTIVITY) activityTimestamps.put(i, activityKind); break; - case ActivityKind.TYPE_LIGHT_SLEEP: - if (activityKind == ActivityKind.TYPE_EXERCISE || - activityKind == ActivityKind.TYPE_ACTIVITY || - activityKind == ActivityKind.TYPE_DEEP_SLEEP) + case LIGHT_SLEEP: + if (activityKind == ActivityKind.EXERCISE || + activityKind == ActivityKind.ACTIVITY || + activityKind == ActivityKind.DEEP_SLEEP) activityTimestamps.put(i, activityKind); break; - case ActivityKind.TYPE_REM_SLEEP: - if (activityKind == ActivityKind.TYPE_EXERCISE || - activityKind == ActivityKind.TYPE_ACTIVITY || - activityKind == ActivityKind.TYPE_DEEP_SLEEP || - activityKind == ActivityKind.TYPE_LIGHT_SLEEP) + case REM_SLEEP: + if (activityKind == ActivityKind.EXERCISE || + activityKind == ActivityKind.ACTIVITY || + activityKind == ActivityKind.DEEP_SLEEP || + activityKind == ActivityKind.LIGHT_SLEEP) activityTimestamps.put(i, activityKind); break; - case ActivityKind.TYPE_SLEEP: - if (activityKind == ActivityKind.TYPE_EXERCISE || - activityKind == ActivityKind.TYPE_ACTIVITY || - activityKind == ActivityKind.TYPE_DEEP_SLEEP || - activityKind == ActivityKind.TYPE_LIGHT_SLEEP || - activityKind == ActivityKind.TYPE_REM_SLEEP) + case SLEEP_ANY: + if (activityKind == ActivityKind.EXERCISE || + activityKind == ActivityKind.ACTIVITY || + activityKind == ActivityKind.DEEP_SLEEP || + activityKind == ActivityKind.LIGHT_SLEEP || + activityKind == ActivityKind.REM_SLEEP) activityTimestamps.put(i, activityKind); break; default: @@ -395,7 +395,7 @@ public class DashboardTodayWidget extends AbstractDashboardWidget { if (lastTimestamp == 0) lastTimestamp = sample.getTimestamp(); if ((sample.getHeartRate() < 10 || sample.getTimestamp() > lastTimestamp + dashboardData.hrIntervalSecs) && firstTimestamp != lastTimestamp) { LOG.debug("Registered worn session from {} to {}", firstTimestamp, lastTimestamp); - addActivity(firstTimestamp, lastTimestamp, ActivityKind.TYPE_NOT_MEASURED); + addActivity(firstTimestamp, lastTimestamp, ActivityKind.NOT_MEASURED); if (sample.getHeartRate() < 10) { firstTimestamp = 0; lastTimestamp = 0; @@ -409,16 +409,16 @@ public class DashboardTodayWidget extends AbstractDashboardWidget { } if (firstTimestamp != lastTimestamp) { LOG.debug("Registered worn session from {} to {}", firstTimestamp, lastTimestamp); - addActivity(firstTimestamp, lastTimestamp, ActivityKind.TYPE_NOT_MEASURED); + addActivity(firstTimestamp, lastTimestamp, ActivityKind.NOT_MEASURED); } } private void createGeneralizedActivities() { DashboardFragment.DashboardData.GeneralizedActivity previous = null; long midDaySecond = dashboardData.timeFrom + (12 * 60 * 60); - for (Map.Entry activity : activityTimestamps.entrySet()) { + for (Map.Entry activity : activityTimestamps.entrySet()) { long timestamp = activity.getKey(); - int activityKind = activity.getValue(); + ActivityKind activityKind = activity.getValue(); if (previous == null || previous.activityKind != activityKind || (!mode_24h && timestamp == midDaySecond) || previous.timeTo < timestamp - 60) { previous = new DashboardFragment.DashboardData.GeneralizedActivity(activityKind, timestamp, timestamp); dashboardData.generalizedActivities.add(previous); @@ -457,18 +457,18 @@ public class DashboardTodayWidget extends AbstractDashboardWidget { // Integrate various data from multiple devices for (ActivitySample sample : allActivitySamples) { // Handle only TYPE_NOT_WORN and TYPE_SLEEP (including variants) here - if (sample.getKind() != ActivityKind.TYPE_NOT_WORN && (sample.getKind() == ActivityKind.TYPE_NOT_MEASURED || (sample.getKind() & ActivityKind.TYPE_SLEEP) == 0)) + if (sample.getKind() != ActivityKind.NOT_WORN && (sample.getKind() == ActivityKind.NOT_MEASURED || !ActivityKind.isSleep(sample.getKind()))) continue; // Add to day results addActivity(sample.getTimestamp(), sample.getTimestamp() + 60, sample.getKind()); } if (activitySummaries != null) { for (BaseActivitySummary baseActivitySummary : activitySummaries) { - addActivity(baseActivitySummary.getStartTime().getTime() / 1000, baseActivitySummary.getEndTime().getTime() / 1000, ActivityKind.TYPE_EXERCISE); + addActivity(baseActivitySummary.getStartTime().getTime() / 1000, baseActivitySummary.getEndTime().getTime() / 1000, ActivityKind.EXERCISE); } } for (ActivitySession session : stepSessions) { - addActivity(session.getStartTime().getTime() / 1000, session.getEndTime().getTime() / 1000, ActivityKind.TYPE_ACTIVITY); + addActivity(session.getStartTime().getTime() / 1000, session.getEndTime().getTime() / 1000, ActivityKind.ACTIVITY); } createGeneralizedActivities(); return null; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/ActivitySummariesAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/ActivitySummariesAdapter.java index b24b20d91..70ef278b1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/ActivitySummariesAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/ActivitySummariesAdapter.java @@ -235,13 +235,15 @@ public class ActivitySummariesAdapter extends AbstractActivityListingAdapter i @NonNull @Override public List getAllActivitySamples(int timestamp_from, int timestamp_to) { - return getGBActivitySamples(timestamp_from, timestamp_to, ActivityKind.TYPE_ALL); + return getGBActivitySamples(timestamp_from, timestamp_to); } @NonNull @Override public List getActivitySamples(int timestamp_from, int timestamp_to) { if (getRawKindSampleProperty() != null) { - return getGBActivitySamples(timestamp_from, timestamp_to, ActivityKind.TYPE_ACTIVITY); + return getGBActivitySamples(timestamp_from, timestamp_to); } else { - return getActivitySamplesByActivityFilter(timestamp_from, timestamp_to, ActivityKind.TYPE_ACTIVITY); - } - } - - @NonNull - @Override - public List getSleepSamples(int timestamp_from, int timestamp_to) { - final DeviceCoordinator coordinator = getDevice().getDeviceCoordinator(); - - // If the device does not support REM sleep, we need to exclude its bit from the activity type - int sleepActivityType = ActivityKind.TYPE_SLEEP; - if (!coordinator.supportsRemSleep()) { - sleepActivityType &= ~ActivityKind.TYPE_REM_SLEEP; - } - - if (getRawKindSampleProperty() != null) { - return getGBActivitySamples(timestamp_from, timestamp_to, sleepActivityType); - } else { - return getActivitySamplesByActivityFilter(timestamp_from, timestamp_to, sleepActivityType); + return getActivitySamplesByActivityFilter(timestamp_from, timestamp_to, Collections.singleton(ActivityKind.ACTIVITY)); } } @@ -152,11 +135,7 @@ public abstract class AbstractSampleProvider i return sample; } - protected List getGBActivitySamples(int timestamp_from, int timestamp_to, int activityType) { - if (getRawKindSampleProperty() == null && activityType != ActivityKind.TYPE_ALL) { - // if we do not have a raw kind property we cannot query anything else then TYPE_ALL - return Collections.emptyList(); - } + protected List getGBActivitySamples(int timestamp_from, int timestamp_to) { QueryBuilder qb = getSampleDao().queryBuilder(); Property timestampProperty = getTimestampSampleProperty(); Device dbDevice = DBHelper.findDevice(getDevice(), getSession()); @@ -166,7 +145,7 @@ public abstract class AbstractSampleProvider i } Property deviceProperty = getDeviceIdentifierSampleProperty(); qb.where(deviceProperty.eq(dbDevice.getId()), timestampProperty.ge(timestamp_from)) - .where(timestampProperty.le(timestamp_to), getClauseForActivityType(qb, activityType)); + .where(timestampProperty.le(timestamp_to)); List samples = qb.build().list(); for (T sample : samples) { sample.setProvider(this); @@ -185,51 +164,12 @@ public abstract class AbstractSampleProvider i getSampleDao().detachAll(); } - private WhereCondition[] getClauseForActivityType(QueryBuilder qb, int activityTypes) { - if (activityTypes == ActivityKind.TYPE_ALL) { - return NO_CONDITIONS; - } - - int[] dbActivityTypes = ActivityKind.mapToDBActivityTypes(activityTypes, this); - WhereCondition activityTypeCondition = getActivityTypeConditions(qb, dbActivityTypes); - return new WhereCondition[] { activityTypeCondition }; - } - - private WhereCondition getActivityTypeConditions(QueryBuilder qb, int[] dbActivityTypes) { - // What a crappy QueryBuilder API ;-( QueryBuilder.or(WhereCondition[]) with a runtime array length - // check would have worked just fine. - if (dbActivityTypes.length == 0) { - return null; - } - Property rawKindProperty = getRawKindSampleProperty(); - if (rawKindProperty == null) { - return null; - } - - if (dbActivityTypes.length == 1) { - return rawKindProperty.eq(dbActivityTypes[0]); - } - if (dbActivityTypes.length == 2) { - return qb.or(rawKindProperty.eq(dbActivityTypes[0]), - rawKindProperty.eq(dbActivityTypes[1])); - } - final int offset = 2; - int len = dbActivityTypes.length - offset; - WhereCondition[] trailingConditions = new WhereCondition[len]; - for (int i = 0; i < len; i++) { - trailingConditions[i] = rawKindProperty.eq(dbActivityTypes[i + offset]); - } - return qb.or(rawKindProperty.eq(dbActivityTypes[0]), - rawKindProperty.eq(dbActivityTypes[1]), - trailingConditions); - } - - private List getActivitySamplesByActivityFilter(int timestamp_from, int timestamp_to, int activityFilter) { + private List getActivitySamplesByActivityFilter(int timestamp_from, int timestamp_to, Set activityFilter) { List samples = getAllActivitySamples(timestamp_from, timestamp_to); List filteredSamples = new ArrayList<>(); for (T sample : samples) { - if ((sample.getKind() & activityFilter) != 0) { + if (activityFilter.contains(sample.getKind())) { filteredSamples.add(sample); } } @@ -324,7 +264,7 @@ public abstract class AbstractSampleProvider i for (int ts = timestamp_from; ts <= firstTimestamp + 60; ts += 60) { final T dummySample = createActivitySample(); dummySample.setTimestamp(ts); - dummySample.setRawKind(ActivityKind.TYPE_UNKNOWN); + dummySample.setRawKind(ActivityKind.UNKNOWN.getCode()); dummySample.setRawIntensity(ActivitySample.NOT_MEASURED); dummySample.setSteps(ActivitySample.NOT_MEASURED); dummySample.setProvider(this); @@ -338,7 +278,7 @@ public abstract class AbstractSampleProvider i for (int ts = lastTimestamp + 60; ts <= timestamp_to; ts += 60) { final T dummySample = createActivitySample(); dummySample.setTimestamp(ts); - dummySample.setRawKind(ActivityKind.TYPE_UNKNOWN); + dummySample.setRawKind(ActivityKind.UNKNOWN.getCode()); dummySample.setRawIntensity(ActivitySample.NOT_MEASURED); dummySample.setSteps(ActivitySample.NOT_MEASURED); dummySample.setProvider(this); @@ -356,7 +296,7 @@ public abstract class AbstractSampleProvider i for (int ts = previousSample.getTimestamp() + 60; ts < sample.getTimestamp(); ts += 60) { final T dummySample = createActivitySample(); dummySample.setTimestamp(ts); - dummySample.setRawKind(ActivityKind.TYPE_UNKNOWN); + dummySample.setRawKind(ActivityKind.UNKNOWN.getCode()); dummySample.setRawIntensity(ActivitySample.NOT_MEASURED); dummySample.setSteps(ActivitySample.NOT_MEASURED); dummySample.setProvider(this); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/SampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/SampleProvider.java index c38abf634..7b008d21d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/SampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/SampleProvider.java @@ -22,6 +22,7 @@ import java.util.List; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample; +import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; /** * Interface to retrieve samples from the database, and also create and add samples to the database. @@ -38,9 +39,9 @@ public interface SampleProvider { int PROVIDER_PEBBLE_MISFIT = 3; int PROVIDER_PEBBLE_HEALTH = 4; - int normalizeType(int rawType); + ActivityKind normalizeType(int rawType); - int toRawActivityKind(int activityKind); + int toRawActivityKind(ActivityKind activityKind); float normalizeIntensity(int rawIntensity); @@ -63,16 +64,6 @@ public interface SampleProvider { @NonNull List getActivitySamples(int timestamp_from, int timestamp_to); - /** - * Returns the list of all samples that represent "sleeping", within the - * given time span. - * @param timestamp_from the start timestamp - * @param timestamp_to the end timestamp - * @return the list of samples of type sleep - */ - @NonNull - List getSleepSamples(int timestamp_from, int timestamp_to); - /** * Adds the given sample to the database. An existing sample with the same * timestamp will be overwritten. diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/UnknownDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/UnknownDeviceCoordinator.java index 628509cb0..2e41fbe43 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/UnknownDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/UnknownDeviceCoordinator.java @@ -45,12 +45,12 @@ public class UnknownDeviceCoordinator extends AbstractDeviceCoordinator { private static final class UnknownSampleProvider implements SampleProvider { @Override - public int normalizeType(int rawType) { - return ActivityKind.TYPE_UNKNOWN; + public ActivityKind normalizeType(int rawType) { + return ActivityKind.UNKNOWN; } @Override - public int toRawActivityKind(int activityKind) { + public int toRawActivityKind(ActivityKind activityKind) { return 0; } @@ -69,11 +69,6 @@ public class UnknownDeviceCoordinator extends AbstractDeviceCoordinator { return null; } - @Override - public List getSleepSamples(int timestamp_from, int timestamp_to) { - return null; - } - @Override public void addGBActivitySample(AbstractActivitySample activitySample) { } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/banglejs/BangleJSSampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/banglejs/BangleJSSampleProvider.java index 608e2c9aa..6a7b0c559 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/banglejs/BangleJSSampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/banglejs/BangleJSSampleProvider.java @@ -66,17 +66,17 @@ public class BangleJSSampleProvider extends AbstractSampleProvider nearSamples = getGBActivitySamples( sample.getTimestamp() - 60 * 2, - sample.getTimestamp() + 60 * 2, - normalizeType(sample.getRawKind()) + sample.getTimestamp() + 60 * 2 ); if (nearSamples.isEmpty()) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gbx100/CasioGBX100SampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gbx100/CasioGBX100SampleProvider.java index fe6cdf8c1..50d0f0a21 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gbx100/CasioGBX100SampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/gbx100/CasioGBX100SampleProvider.java @@ -19,11 +19,6 @@ package nodomain.freeyourgadget.gadgetbridge.devices.casio.gbx100; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; - import de.greenrobot.dao.AbstractDao; import de.greenrobot.dao.Property; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider; @@ -31,22 +26,21 @@ import nodomain.freeyourgadget.gadgetbridge.entities.CasioGBX100ActivitySample; import nodomain.freeyourgadget.gadgetbridge.entities.CasioGBX100ActivitySampleDao; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; +import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; public class CasioGBX100SampleProvider extends AbstractSampleProvider { - private static final Logger LOG = LoggerFactory.getLogger(CasioGBX100SampleProvider.class); - public CasioGBX100SampleProvider(GBDevice device, DaoSession session) { super(device, session); } @Override - public int normalizeType(int rawType) { - return rawType; + public ActivityKind normalizeType(int rawType) { + return ActivityKind.fromCode(rawType); } @Override - public int toRawActivityKind(int activityKind) { - return activityKind; + public int toRawActivityKind(ActivityKind activityKind) { + return activityKind.getCode(); } @Override @@ -83,17 +77,4 @@ public class CasioGBX100SampleProvider extends AbstractSampleProvider getActivitySamples(int timestamp_from, int timestamp_to) { - return super.getActivitySamples(timestamp_from, timestamp_to); - } - - @NonNull - @Override - public List getAllActivitySamples(int timestamp_from, int timestamp_to) { - return super.getActivitySamples(timestamp_from, timestamp_to); - } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/cmfwatchpro/samples/CmfActivitySampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/cmfwatchpro/samples/CmfActivitySampleProvider.java index 2709efaff..c6a66307d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/cmfwatchpro/samples/CmfActivitySampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/cmfwatchpro/samples/CmfActivitySampleProvider.java @@ -72,13 +72,13 @@ public class CmfActivitySampleProvider extends AbstractSampleProvider getGBActivitySamples(final int timestamp_from, final int timestamp_to, final int activityType) { + protected List getGBActivitySamples(final int timestamp_from, final int timestamp_to) { LOG.trace( - "Getting cmf activity samples for {} between {} and {}", - String.format("0x%08x", activityType), + "Getting cmf activity samples between {} and {}", timestamp_from, timestamp_to ); final long nanoStart = System.nanoTime(); - final List samples = super.getGBActivitySamples(timestamp_from, timestamp_to, activityType); + final List samples = super.getGBActivitySamples(timestamp_from, timestamp_to); if (!samples.isEmpty()) { convertCumulativeSteps(samples, CmfActivitySampleDao.Properties.Steps); @@ -165,17 +164,17 @@ public class CmfActivitySampleProvider extends AbstractSampleProvider getGBActivitySamples(final int timestamp_from, final int timestamp_to, final int activityType) { + protected List getGBActivitySamples(final int timestamp_from, final int timestamp_to) { LOG.trace( - "Getting garmin activity samples for {} between {} and {}", - String.format("0x%08x", activityType), + "Getting garmin activity samples between {} and {}", timestamp_from, timestamp_to ); @@ -99,7 +98,7 @@ public class GarminActivitySampleProvider extends AbstractSampleProvider samples = fillGaps( - super.getGBActivitySamples(timestamp_from, timestamp_to, activityType), + super.getGBActivitySamples(timestamp_from, timestamp_to), timestamp_from, timestamp_to ); @@ -121,7 +120,7 @@ public class GarminActivitySampleProvider extends AbstractSampleProvider samples, final int timestamp_from, final int timestamp_to) { // The samples provided by Garmin are upper-bound timestamps of the sleep stage - final RangeMap stagesMap = new RangeMap<>(RangeMap.Mode.UPPER_BOUND); + final RangeMap stagesMap = new RangeMap<>(RangeMap.Mode.UPPER_BOUND); final GarminEventSampleProvider eventSampleProvider = new GarminEventSampleProvider(getDevice(), getSession()); final List sleepEventSamples = eventSampleProvider.getSleepEvents( @@ -134,7 +133,7 @@ public class GarminActivitySampleProvider extends AbstractSampleProvider { - - private GBDevice mDevice; - private DaoSession mSession; - public HPlusHealthSampleProvider(GBDevice device, DaoSession session) { super(device, session); - - mSession = session; - mDevice = device; } - public int normalizeType(int rawType) { + public ActivityKind normalizeType(int rawType) { switch (rawType) { case HPlusDataRecord.TYPE_DAY_SLOT: case HPlusDataRecord.TYPE_DAY_SUMMARY: case HPlusDataRecord.TYPE_REALTIME: case HPlusDataRecord.TYPE_SLEEP: case HPlusDataRecord.TYPE_UNKNOWN: - return ActivityKind.TYPE_UNKNOWN; + return ActivityKind.UNKNOWN; default: - return rawType; + return ActivityKind.fromCode(rawType); } } - public int toRawActivityKind(int activityKind) { - switch (activityKind){ - case ActivityKind.TYPE_DEEP_SLEEP: - return ActivityKind.TYPE_DEEP_SLEEP; - case ActivityKind.TYPE_LIGHT_SLEEP: - return ActivityKind.TYPE_LIGHT_SLEEP; + public int toRawActivityKind(ActivityKind activityKind) { + switch (activityKind) { + case DEEP_SLEEP: + case LIGHT_SLEEP: + return activityKind.getCode(); default: return HPlusDataRecord.TYPE_DAY_SLOT; } @@ -113,20 +106,10 @@ public class HPlusHealthSampleProvider extends AbstractSampleProvider getActivityamples(int timestamp_from, int timestamp_to) { - return getAllActivitySamples(timestamp_from, timestamp_to); - } - - @NonNull - public List getSleepSamples(int timestamp_from, int timestamp_to) { - return getAllActivitySamples(timestamp_from, timestamp_to); - } - @NonNull @Override public List getAllActivitySamples(int timestamp_from, int timestamp_to) { - List samples = super.getGBActivitySamples(timestamp_from, timestamp_to, ActivityKind.TYPE_ALL); + List samples = super.getGBActivitySamples(timestamp_from, timestamp_to); Device dbDevice = DBHelper.findDevice(getDevice(), getSession()); if (dbDevice == null) { @@ -143,7 +126,6 @@ public class HPlusHealthSampleProvider extends AbstractSampleProvider overlayRecords = qb.build().list(); - //Apply Overlays for (HPlusHealthActivityOverlay overlay : overlayRecords) { @@ -167,22 +149,22 @@ public class HPlusHealthSampleProvider extends AbstractSampleProvider= overlay.getTimestampFrom() && sample.getTimestamp() < overlay.getTimestampTo()) { - if (overlay.getRawKind() == ActivityKind.TYPE_NOT_WORN || overlay.getRawKind() == ActivityKind.TYPE_LIGHT_SLEEP || overlay.getRawKind() == ActivityKind.TYPE_DEEP_SLEEP) { - if (sample.getRawKind() == HPlusDataRecord.TYPE_DAY_SLOT && sample.getSteps() > 0){ + if (overlay.getRawKind() == ActivityKind.NOT_WORN.getCode() || overlay.getRawKind() == ActivityKind.LIGHT_SLEEP.getCode() || overlay.getRawKind() == ActivityKind.DEEP_SLEEP.getCode()) { + if (sample.getRawKind() == HPlusDataRecord.TYPE_DAY_SLOT && sample.getSteps() > 0) { nonSleepTimeEnd = sample.getTimestamp() + 10 * 60; // 10 minutes continue; - }else if(sample.getRawKind() == HPlusDataRecord.TYPE_REALTIME && sample.getTimestamp() <= nonSleepTimeEnd){ + } else if (sample.getRawKind() == HPlusDataRecord.TYPE_REALTIME && sample.getTimestamp() <= nonSleepTimeEnd) { continue; } - if (overlay.getRawKind() == ActivityKind.TYPE_NOT_WORN) + if (overlay.getRawKind() == ActivityKind.NOT_WORN.getCode()) sample.setHeartRate(0); - if (sample.getRawKind() != ActivityKind.TYPE_NOT_WORN) + if (sample.getRawKind() != ActivityKind.NOT_WORN.getCode()) sample.setRawKind(overlay.getRawKind()); sample.setRawIntensity(10); @@ -192,7 +174,6 @@ public class HPlusHealthSampleProvider extends AbstractSampleProvider= today.getTimeInMillis() / 1000) { + for (HPlusHealthActivitySample sample : samples) { + if (sample.getTimestamp() >= today.getTimeInMillis() / 1000) { - /**Strategy is: + /* Strategy is: * Calculate max steps from realtime messages * Calculate sum of steps from day 10 minute slot summaries */ - if(sample.getRawKind() == HPlusDataRecord.TYPE_REALTIME) { + if (sample.getRawKind() == HPlusDataRecord.TYPE_REALTIME) { stepsTodayMax = Math.max(stepsTodayMax, sample.getSteps()); - }else if(sample.getRawKind() == HPlusDataRecord.TYPE_DAY_SLOT) { - stepsTodayCount += sample.getSteps(); - } + } else if (sample.getRawKind() == HPlusDataRecord.TYPE_DAY_SLOT) { + stepsTodayCount += sample.getSteps(); + } sample.setSteps(ActivitySample.NOT_MEASURED); lastSample = sample; @@ -230,7 +211,7 @@ public class HPlusHealthSampleProvider extends AbstractSampleProvider insertVirtualItem(List samples, int timestamp, long deviceId, long userId) { + private void insertVirtualItem(List samples, int timestamp, long deviceId, long userId) { HPlusHealthActivitySample sample = new HPlusHealthActivitySample( timestamp, // ts deviceId, userId, // User id null, // Raw Data - ActivityKind.TYPE_UNKNOWN, + ActivityKind.UNKNOWN.getCode(), 1, // Intensity ActivitySample.NOT_MEASURED, // Steps ActivitySample.NOT_MEASURED, // HR @@ -254,8 +235,6 @@ public class HPlusHealthSampleProvider extends AbstractSampleProvider getGBActivitySamples(final int timestamp_from, final int timestamp_to, final int activityType) { - final List samples = super.getGBActivitySamples(timestamp_from, timestamp_to, activityType); + protected List getGBActivitySamples(final int timestamp_from, final int timestamp_to) { + final List samples = super.getGBActivitySamples(timestamp_from, timestamp_to); postProcess(samples); return samples; } @@ -108,34 +108,34 @@ public class HuamiExtendedSampleProvider extends AbstractSampleProvider getGBActivitySamples(int timestamp_from, int timestamp_to, int activityType) { + protected List getGBActivitySamples(int timestamp_from, int timestamp_to) { // Note that the result of this function has to be sorted by timestamp! List rawSamples = getRawOrderedActivitySamples(timestamp_from, timestamp_to); @@ -337,7 +335,6 @@ public class HuaweiSampleProvider extends AbstractSampleProvider { public ID115SampleProvider(GBDevice device, DaoSession session) { @@ -55,13 +56,13 @@ public class ID115SampleProvider extends AbstractSampleProvider { @@ -42,13 +43,13 @@ public class JYouSampleProvider extends AbstractSampleProvider checkActivityData(List samples, int notMeasuredTS, int notWornTS) { int oldTS = 0; @@ -116,13 +116,13 @@ public class WatchXPlusSampleProvider extends AbstractSampleProvider notMeasuredTS) && ((newTS - oldTS) < notWornTS)) { //set data to ActivityKind.TYPE_NOT_MEASURED) if timestamp diff is more than 15 min - samples.get(i-1).setRawKind(ActivityKind.TYPE_NOT_MEASURED); - samples.get(i).setRawKind(ActivityKind.TYPE_NOT_MEASURED); + } else if (((newTS - oldTS) > notMeasuredTS) && ((newTS - oldTS) < notWornTS)) { //set data to ActivityKind.NOT_MEASURED) if timestamp diff is more than 15 min + samples.get(i-1).setRawKind(ActivityKind.NOT_MEASURED.getCode()); + samples.get(i).setRawKind(ActivityKind.NOT_MEASURED.getCode()); oldTS = samples.get(i).getTimestamp(); - } else if ((newTS - oldTS) > notWornTS) { //set data to ActivityKind.TYPE_NOT_WORN if timestamp diff is more than 60 min - samples.get(i-1).setRawKind(ActivityKind.TYPE_NOT_WORN); - samples.get(i).setRawKind(ActivityKind.TYPE_NOT_WORN); + } else if ((newTS - oldTS) > notWornTS) { //set data to ActivityKind.NOT_WORN if timestamp diff is more than 60 min + samples.get(i-1).setRawKind(ActivityKind.NOT_WORN.getCode()); + samples.get(i).setRawKind(ActivityKind.NOT_WORN.getCode()); oldTS = samples.get(i).getTimestamp(); } } @@ -137,9 +137,9 @@ public class WatchXPlusSampleProvider extends AbstractSampleProvider getAllActivitySamples(int timestamp_from, int timestamp_to) { boolean showRawData = GBApplication.getDeviceSpecificSharedPrefs(mDevice.getAddress()).getBoolean(WatchXPlusConstants.PREF_SHOW_RAW_GRAPH, false); if (showRawData) { - return getGBActivitySamples(timestamp_from, timestamp_to, ActivityKind.TYPE_ALL); + return getGBActivitySamples(timestamp_from, timestamp_to); } - List samples = getGBActivitySamples(timestamp_from, timestamp_to, ActivityKind.TYPE_ALL); + List samples = getGBActivitySamples(timestamp_from, timestamp_to); int numEntries = samples.size(); if (numEntries < 3) { return samples; @@ -151,14 +151,14 @@ public class WatchXPlusSampleProvider extends AbstractSampleProvider 100)) { @@ -250,9 +250,9 @@ public class WatchXPlusSampleProvider extends AbstractSampleProvider 0) { if (samples.get(i - 1).getHeartRate() > 0) { samples.get(i).setHeartRate(samples.get(i - 1).getHeartRate()); @@ -314,7 +314,7 @@ public class WatchXPlusSampleProvider extends AbstractSampleProvider sleepStopIndex_1)) { + if ((samples.get(i).getRawKind() == ActivityKind.LIGHT_SLEEP.getCode()) && (i > sleepStopIndex_1)) { samples.get(i).setRawIntensity(600); resultList.add(samples.get(i)); } @@ -324,7 +324,7 @@ public class WatchXPlusSampleProvider extends AbstractSampleProvider 100)) { @@ -335,9 +335,9 @@ public class WatchXPlusSampleProvider extends AbstractSampleProvider 0) { if (samples.get(i - 1).getHeartRate() > 0) { samples.get(i).setHeartRate(samples.get(i - 1).getHeartRate()); @@ -406,7 +406,7 @@ public class WatchXPlusSampleProvider extends AbstractSampleProvider sleepStopIndex_2)) { + if ((samples.get(i).getRawKind() == ActivityKind.LIGHT_SLEEP.getCode()) && (i > sleepStopIndex_2)) { samples.get(i).setRawIntensity(600); resultList.add(samples.get(i)); } @@ -415,7 +415,7 @@ public class WatchXPlusSampleProvider extends AbstractSampleProvider 100)) { @@ -427,9 +427,9 @@ public class WatchXPlusSampleProvider extends AbstractSampleProvider 0) { totalSteps = totalSteps + resultList.get(i).getSteps(); } @@ -470,7 +470,7 @@ public class WatchXPlusSampleProvider extends AbstractSampleProvider 0) { stepsPerActivity = totalIntensity / totalSteps; for (int i = 0; i < numEntries - 1; i++) { - if (resultList.get(i).getRawKind() == ActivityKind.TYPE_ACTIVITY) { + if (resultList.get(i).getRawKind() == ActivityKind.ACTIVITY.getCode()) { if (stepsPerActivity > 0.0f) { correctedSteps = (int) (resultList.get(i).getRawIntensity() / stepsPerActivity); resultList.get(i).setSteps(correctedSteps); @@ -525,7 +525,7 @@ public class WatchXPlusSampleProvider extends AbstractSampleProvider { - - private GBDevice mDevice; - private DaoSession mSession; - public MakibesHR3SampleProvider(GBDevice device, DaoSession session) { super(device, session); - - mSession = session; - mDevice = device; } @Override - public int normalizeType(int rawType) { - return rawType; + public ActivityKind normalizeType(int rawType) { + return ActivityKind.fromCode(rawType); } @Override - public int toRawActivityKind(int activityKind) { - return activityKind; + public int toRawActivityKind(ActivityKind activityKind) { + return activityKind.getCode(); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBand2SampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBand2SampleProvider.java index b2ba40d16..9b5238eed 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBand2SampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBand2SampleProvider.java @@ -25,6 +25,7 @@ import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySample; import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySampleDao; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; +import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.TYPE_IGNORE; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.TYPE_NO_CHANGE; @@ -37,15 +38,14 @@ public class MiBand2SampleProvider extends AbstractMiBandSampleProvider { } @Override - protected List getGBActivitySamples(int timestamp_from, int timestamp_to, int activityType) { - List samples = super.getGBActivitySamples(timestamp_from, timestamp_to, activityType); + protected List getGBActivitySamples(int timestamp_from, int timestamp_to) { + List samples = super.getGBActivitySamples(timestamp_from, timestamp_to); postprocess(samples); return samples; } /** * "Temporary" runtime post processing of activity kinds. - * @param samples */ private void postprocess(List samples) { if (samples.isEmpty()) { @@ -83,19 +83,19 @@ public class MiBand2SampleProvider extends AbstractMiBandSampleProvider { qb.orderDesc(MiBandActivitySampleDao.Properties.Timestamp); qb.limit(1); List result = qb.build().list(); - if (result.size() > 0) { + if (!result.isEmpty()) { return result.get(0).getRawKind() & 0xf; } return TYPE_UNSET; } @Override - public int normalizeType(int rawType) { + public ActivityKind normalizeType(int rawType) { return HuamiConst.toActivityKind(rawType); } @Override - public int toRawActivityKind(int activityKind) { + public int toRawActivityKind(ActivityKind activityKind) { return HuamiConst.toRawActivityType(activityKind); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandSampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandSampleProvider.java index 93afce049..0f7474976 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandSampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandSampleProvider.java @@ -42,36 +42,36 @@ public class MiBandSampleProvider extends AbstractMiBandSampleProvider { } @Override - public int normalizeType(int rawType) { + public ActivityKind normalizeType(int rawType) { switch (rawType) { case TYPE_DEEP_SLEEP: - return ActivityKind.TYPE_DEEP_SLEEP; + return ActivityKind.DEEP_SLEEP; case TYPE_LIGHT_SLEEP: - return ActivityKind.TYPE_LIGHT_SLEEP; + return ActivityKind.LIGHT_SLEEP; case TYPE_ACTIVITY: - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; case TYPE_NONWEAR: - return ActivityKind.TYPE_NOT_WORN; + return ActivityKind.NOT_WORN; case TYPE_CHARGING: - return ActivityKind.TYPE_NOT_WORN; //I believe it's a safe assumption + return ActivityKind.NOT_WORN; //I believe it's a safe assumption default: // case TYPE_UNKNOWN: // fall through - return ActivityKind.TYPE_UNKNOWN; + return ActivityKind.UNKNOWN; } } @Override - public int toRawActivityKind(int activityKind) { + public int toRawActivityKind(ActivityKind activityKind) { switch (activityKind) { - case ActivityKind.TYPE_ACTIVITY: + case ACTIVITY: return TYPE_ACTIVITY; - case ActivityKind.TYPE_DEEP_SLEEP: + case DEEP_SLEEP: return TYPE_DEEP_SLEEP; - case ActivityKind.TYPE_LIGHT_SLEEP: + case LIGHT_SLEEP: return TYPE_LIGHT_SLEEP; - case ActivityKind.TYPE_NOT_WORN: + case NOT_WORN: return TYPE_NONWEAR; - case ActivityKind.TYPE_UNKNOWN: // fall through + case UNKNOWN: // fall through default: return TYPE_UNKNOWN; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/no1f1/No1F1SampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/no1f1/No1F1SampleProvider.java index 6e6ccaa96..8110fba6b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/no1f1/No1F1SampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/no1f1/No1F1SampleProvider.java @@ -25,6 +25,7 @@ import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.entities.No1F1ActivitySample; import nodomain.freeyourgadget.gadgetbridge.entities.No1F1ActivitySampleDao; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; +import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; public class No1F1SampleProvider extends AbstractSampleProvider { @@ -39,13 +40,13 @@ public class No1F1SampleProvider extends AbstractSampleProvider getAllActivitySamples(int timestamp_from, int timestamp_to) { - List samples = super.getGBActivitySamples(timestamp_from, timestamp_to, ActivityKind.TYPE_ALL); + List samples = super.getGBActivitySamples(timestamp_from, timestamp_to); Device dbDevice = DBHelper.findDevice(getDevice(), getSession()); if (dbDevice == null) { @@ -112,32 +112,31 @@ public class PebbleHealthSampleProvider extends AbstractSampleProvider { @@ -35,13 +36,13 @@ public class PebbleMisfitSampleProvider extends AbstractSampleProvider { @@ -68,12 +69,12 @@ public class PebbleMorpheuzSampleProvider extends AbstractSampleProvider { - private GBDevice mDevice; - private DaoSession mSession; - public PineTimeActivitySampleProvider(GBDevice device, DaoSession session) { super(device, session); - - mSession = session; - mDevice = device; } @Override @@ -66,13 +60,13 @@ public class PineTimeActivitySampleProvider extends AbstractSampleProvider getSampleForTimestamp(int timestamp) { - List foundSamples = this.getGBActivitySamples(timestamp, timestamp, ActivityKind.TYPE_ALL); - if (foundSamples.size() == 0) { + List foundSamples = this.getGBActivitySamples(timestamp, timestamp); + if (foundSamples.isEmpty()) { return Optional.empty(); } return Optional.of(foundSamples.get(0)); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRActivitySampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRActivitySampleProvider.java index 88dcad729..a5eed76cd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRActivitySampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRActivitySampleProvider.java @@ -19,8 +19,6 @@ package nodomain.freeyourgadget.gadgetbridge.devices.qhybrid; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import java.util.List; - import de.greenrobot.dao.AbstractDao; import de.greenrobot.dao.Property; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider; @@ -28,6 +26,7 @@ import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.entities.HybridHRActivitySample; import nodomain.freeyourgadget.gadgetbridge.entities.HybridHRActivitySampleDao; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; +import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.parser.ActivityEntry; public class HybridHRActivitySampleProvider extends AbstractSampleProvider { @@ -59,13 +58,13 @@ public class HybridHRActivitySampleProvider extends AbstractSampleProvider getActivitySamples(int timestamp_from, int timestamp_to) { - return super.getActivitySamples(timestamp_from, timestamp_to); - } - - @NonNull - @Override - public List getAllActivitySamples(int timestamp_from, int timestamp_to) { - return super.getAllActivitySamples(timestamp_from, timestamp_to); - } -} \ No newline at end of file +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridConstants.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridConstants.java index f96695343..52f36f53f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridConstants.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridConstants.java @@ -43,12 +43,12 @@ public final class QHybridConstants { } }; - public static Map WORKOUT_TYPES_TO_ACTIVITY_KIND = new HashMap() { + public static Map WORKOUT_TYPES_TO_ACTIVITY_KIND = new HashMap() { { - put(1, ActivityKind.TYPE_RUNNING); - put(2, ActivityKind.TYPE_CYCLING); - put(8, ActivityKind.TYPE_WALKING); - put(12, ActivityKind.TYPE_HIKING); + put(1, ActivityKind.RUNNING); + put(2, ActivityKind.CYCLING); + put(8, ActivityKind.WALKING); + put(12, ActivityKind.HIKING); } }; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/wena3/SonyWena3ActivitySampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/wena3/SonyWena3ActivitySampleProvider.java index 3ae8d8866..7a499d52d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/wena3/SonyWena3ActivitySampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sony/wena3/SonyWena3ActivitySampleProvider.java @@ -58,53 +58,53 @@ public class SonyWena3ActivitySampleProvider extends AbstractSampleProvider= BehaviorSample.Type.LUT.length) return ActivityKind.TYPE_UNKNOWN; + public ActivityKind normalizeType(int rawType) { + if(rawType < 0 || rawType >= BehaviorSample.Type.LUT.length) return ActivityKind.UNKNOWN; BehaviorSample.Type internalType = BehaviorSample.Type.LUT[rawType]; switch(internalType) { case NOT_WEARING: - return ActivityKind.TYPE_NOT_WORN; + return ActivityKind.NOT_WORN; case WALK: - return ActivityKind.TYPE_WALKING; + return ActivityKind.WALKING; case RUN: - return ActivityKind.TYPE_RUNNING; + return ActivityKind.RUNNING; case EXERCISE: - return ActivityKind.TYPE_EXERCISE; + return ActivityKind.EXERCISE; case SLEEP_LIGHT: - return ActivityKind.TYPE_LIGHT_SLEEP; + return ActivityKind.LIGHT_SLEEP; case SLEEP_REM: - return ActivityKind.TYPE_REM_SLEEP; + return ActivityKind.REM_SLEEP; case SLEEP_DEEP: - return ActivityKind.TYPE_DEEP_SLEEP; + return ActivityKind.DEEP_SLEEP; case STATIC: case SLEEP_AWAKE: case UNKNOWN: default: - return ActivityKind.TYPE_UNKNOWN; + return ActivityKind.UNKNOWN; } } @Override - public int toRawActivityKind(int activityKind) { + public int toRawActivityKind(ActivityKind activityKind) { switch(activityKind) { - case ActivityKind.TYPE_NOT_MEASURED: - case ActivityKind.TYPE_NOT_WORN: + case NOT_MEASURED: + case NOT_WORN: return BehaviorSample.Type.NOT_WEARING.ordinal(); - case ActivityKind.TYPE_WALKING: + case WALKING: return BehaviorSample.Type.WALK.ordinal(); - case ActivityKind.TYPE_RUNNING: + case RUNNING: return BehaviorSample.Type.RUN.ordinal(); - case ActivityKind.TYPE_LIGHT_SLEEP: + case LIGHT_SLEEP: return BehaviorSample.Type.SLEEP_LIGHT.ordinal(); - case ActivityKind.TYPE_REM_SLEEP: + case REM_SLEEP: return BehaviorSample.Type.SLEEP_REM.ordinal(); - case ActivityKind.TYPE_DEEP_SLEEP: + case DEEP_SLEEP: return BehaviorSample.Type.SLEEP_DEEP.ordinal(); - case ActivityKind.TYPE_EXERCISE: + case EXERCISE: return BehaviorSample.Type.EXERCISE.ordinal(); default: return BehaviorSample.Type.UNKNOWN.ordinal(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sonyswr12/SonySWR12SampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sonyswr12/SonySWR12SampleProvider.java index d9dedd65f..a7fdaf420 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sonyswr12/SonySWR12SampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/sonyswr12/SonySWR12SampleProvider.java @@ -58,30 +58,30 @@ public class SonySWR12SampleProvider extends AbstractSampleProvider getGBActivitySamples(final int timestamp_from, final int timestamp_to, final int activityType) { + protected List getGBActivitySamples(final int timestamp_from, final int timestamp_to) { final List samples = new ArrayList<>(); int[] sleepStages = new int[] { - ActivityKind.TYPE_LIGHT_SLEEP, - ActivityKind.TYPE_DEEP_SLEEP, + ActivityKind.LIGHT_SLEEP.getCode(), + ActivityKind.DEEP_SLEEP.getCode(), }; if (getDevice().getDeviceCoordinator().supportsRemSleep()) { - sleepStages = ArrayUtils.add(sleepStages, ActivityKind.TYPE_REM_SLEEP); + sleepStages = ArrayUtils.add(sleepStages, ActivityKind.REM_SLEEP.getCode()); } int sleepStageCurrent = 0; int sleepStageDirection = 1; @@ -141,7 +141,7 @@ public class TestSampleProvider extends AbstractSampleProvider getProvider() { return TestSampleProvider.this; } @@ -222,8 +222,8 @@ public class TestSampleProvider extends AbstractSampleProvider { @@ -63,13 +64,13 @@ public class TLW64SampleProvider extends AbstractSampleProvider { - private static final Logger logger = LoggerFactory.getLogger(WithingsSteelHRSampleProvider.class); - public WithingsSteelHRSampleProvider(GBDevice device, DaoSession session) { super(device, session); } @@ -70,28 +56,29 @@ public class WithingsSteelHRSampleProvider extends AbstractSampleProvider getActivitySamples(int timestamp_from, int timestamp_to) { - return super.getGBActivitySamples(timestamp_from, timestamp_to, ActivityKind.TYPE_ALL); + public ActivityKind normalizeType(int rawType) { + switch (rawType) { + case 1: + return ActivityKind.LIGHT_SLEEP; + case 2: + return ActivityKind.DEEP_SLEEP; + default: + return ActivityKind.fromCode(rawType); + } } @Override - public int normalizeType(int rawType) { - return rawType; - } - - @Override - public int toRawActivityKind(int activityKind) { + public int toRawActivityKind(ActivityKind activityKind) { switch (activityKind) { - case ActivityKind.TYPE_UNKNOWN: + case UNKNOWN: return 0; - case ActivityKind.TYPE_LIGHT_SLEEP: + case LIGHT_SLEEP: return 1; - case ActivityKind.TYPE_DEEP_SLEEP: + case DEEP_SLEEP: return 2; default: - return activityKind; + return activityKind.getCode(); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xiaomi/XiaomiSampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xiaomi/XiaomiSampleProvider.java index 5e9a49672..ca9654d44 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xiaomi/XiaomiSampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xiaomi/XiaomiSampleProvider.java @@ -67,15 +67,15 @@ public class XiaomiSampleProvider extends AbstractSampleProvider getGBActivitySamples(final int timestamp_from, final int timestamp_to, final int activityType) { - final List samples = super.getGBActivitySamples(timestamp_from, timestamp_to, activityType); + protected List getGBActivitySamples(final int timestamp_from, final int timestamp_to) { + final List samples = super.getGBActivitySamples(timestamp_from, timestamp_to); overlaySleep(samples, timestamp_from, timestamp_to); @@ -100,16 +100,16 @@ public class XiaomiSampleProvider extends AbstractSampleProvider samples, final int timestamp_from, final int timestamp_to) { - final RangeMap stagesMap = new RangeMap<>(); + final RangeMap stagesMap = new RangeMap<>(); final XiaomiSleepStageSampleProvider sleepStagesSampleProvider = new XiaomiSleepStageSampleProvider(getDevice(), getSession()); @@ -157,8 +157,8 @@ public class XiaomiSampleProvider extends AbstractSampleProvider { @@ -40,13 +41,13 @@ public class ZeTimeSampleProvider extends AbstractSampleProvider mProvider; @Override - public SampleProvider getProvider() { + public SampleProvider getProvider() { return mProvider; } @@ -33,7 +34,7 @@ public abstract class AbstractActivitySample implements ActivitySample { } @Override - public int getKind() { + public ActivityKind getKind() { return getProvider().normalizeType(getRawKind()); } @@ -90,7 +91,7 @@ public abstract class AbstractActivitySample implements ActivitySample { @Override public String toString() { - int kind = getProvider() != null ? getKind() : ActivitySample.NOT_MEASURED; + ActivityKind kind = getProvider() != null ? getKind() : ActivityKind.NOT_MEASURED; float intensity = getProvider() != null ? getIntensity() : ActivitySample.NOT_MEASURED; return getClass().getSimpleName() + "{" + "timestamp=" + DateTimeUtils.formatDateTime(DateTimeUtils.parseTimeStamp(getTimestamp())) + diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/entities/AbstractPebbleHealthActivitySample.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/entities/AbstractPebbleHealthActivitySample.java index 4a7ac5f93..d18015bb7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/entities/AbstractPebbleHealthActivitySample.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/entities/AbstractPebbleHealthActivitySample.java @@ -21,7 +21,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; public abstract class AbstractPebbleHealthActivitySample extends AbstractActivitySample { abstract public byte[] getRawPebbleHealthData(); - private transient int rawActivityKind = ActivityKind.TYPE_UNKNOWN; + private transient int rawActivityKind = ActivityKind.UNKNOWN.getCode(); @Override public int getRawKind() { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/entities/AbstractPebbleMisfitActivitySample.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/entities/AbstractPebbleMisfitActivitySample.java index 3683010eb..a1b482e33 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/entities/AbstractPebbleMisfitActivitySample.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/entities/AbstractPebbleMisfitActivitySample.java @@ -23,7 +23,7 @@ public abstract class AbstractPebbleMisfitActivitySample extends AbstractActivit private transient int intensity = 0; private transient int steps = 0; - private transient int activityKind = ActivityKind.TYPE_UNKNOWN; + private transient ActivityKind activityKind = ActivityKind.UNKNOWN; private void calculate() { int sample = getRawPebbleMisfitSample(); @@ -33,10 +33,10 @@ public abstract class AbstractPebbleMisfitActivitySample extends AbstractActivit intensity = (sample & 0x7c00) >>> 10; // 9-18 decimal after shift if (intensity <= 13) { - activityKind = ActivityKind.TYPE_DEEP_SLEEP; + activityKind = ActivityKind.DEEP_SLEEP; } else { // FIXME: this leads to too much false positives, ignore for now - //activityKind = ActivityKind.TYPE_LIGHT_SLEEP; + //activityKind = ActivityKind.LIGHT_SLEEP; //intensity *= 2; // better visual distinction } } else { @@ -46,7 +46,7 @@ public abstract class AbstractPebbleMisfitActivitySample extends AbstractActivit steps = (sample & 0x000e); } intensity = steps; - activityKind = ActivityKind.TYPE_ACTIVITY; + activityKind = ActivityKind.ACTIVITY; } } @@ -57,7 +57,7 @@ public abstract class AbstractPebbleMisfitActivitySample extends AbstractActivit } @Override - public int getKind() { + public ActivityKind getKind() { calculate(); return activityKind; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/entities/AbstractPebbleMorpheuzActivitySample.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/entities/AbstractPebbleMorpheuzActivitySample.java index b9ce056f8..7e3a28a9b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/entities/AbstractPebbleMorpheuzActivitySample.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/entities/AbstractPebbleMorpheuzActivitySample.java @@ -21,13 +21,13 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; public abstract class AbstractPebbleMorpheuzActivitySample extends AbstractActivitySample { @Override - public int getKind() { + public ActivityKind getKind() { int rawIntensity = getRawIntensity(); if (rawIntensity <= 120) { - return ActivityKind.TYPE_DEEP_SLEEP; + return ActivityKind.DEEP_SLEEP; } else if (rawIntensity <= 1000) { - return ActivityKind.TYPE_LIGHT_SLEEP; + return ActivityKind.LIGHT_SLEEP; } - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/opentracks/OpenTracksController.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/opentracks/OpenTracksController.java index 8d256d24f..eee0ce33d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/opentracks/OpenTracksController.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/opentracks/OpenTracksController.java @@ -112,22 +112,22 @@ public class OpenTracksController extends Activity { sendIntent(context, "de.dennisguse.opentracks.publicapi.StartRecording", null, null); } - public static void startRecording(Context context, int activityKind) { - final String category = ActivityKind.asString(activityKind, context); + public static void startRecording(Context context, ActivityKind activityKind) { + final String category = activityKind.getLabel(context); final String icon; switch (activityKind) { - case ActivityKind.TYPE_CYCLING: + case CYCLING: icon = "BIKE"; break; - case ActivityKind.TYPE_HIKING: - case ActivityKind.TYPE_WALKING: + case HIKING: + case WALKING: icon = "WALK"; break; - case ActivityKind.TYPE_RUNNING: + case RUNNING: icon = "RUN"; break; default: - LOG.warn("Unmapped activity kind icon for {}", String.format("0x%X", activityKind)); + LOG.warn("Unmapped activity kind icon for {}", activityKind); icon = null; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityAmount.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityAmount.java index 444b35d9f..c49f88ed7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityAmount.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityAmount.java @@ -16,21 +16,17 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.model; -import android.content.Context; - import java.util.Date; -import nodomain.freeyourgadget.gadgetbridge.R; - public class ActivityAmount { - private final int activityKind; + private final ActivityKind activityKind; private short percent; private long totalSeconds; private long totalSteps; private Date startDate = null; private Date endDate = null; - public ActivityAmount(int activityKind) { + public ActivityAmount(ActivityKind activityKind) { this.activityKind = activityKind; } @@ -50,7 +46,7 @@ public class ActivityAmount { return totalSteps; } - public int getActivityKind() { + public ActivityKind getActivityKind() { return activityKind; } @@ -62,16 +58,6 @@ public class ActivityAmount { this.percent = percent; } - public String getName(Context context) { - switch (activityKind) { - case ActivityKind.TYPE_DEEP_SLEEP: - return context.getString(R.string.abstract_chart_fragment_kind_deep_sleep); - case ActivityKind.TYPE_LIGHT_SLEEP: - return context.getString(R.string.abstract_chart_fragment_kind_light_sleep); - } - return context.getString(R.string.abstract_chart_fragment_kind_activity); - } - public Date getStartDate() { return startDate; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityKind.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityKind.java index 44927aa92..3730a15df 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityKind.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityKind.java @@ -20,238 +20,97 @@ package nodomain.freeyourgadget.gadgetbridge.model; import android.content.Context; import androidx.annotation.DrawableRes; - -import java.util.Arrays; +import androidx.annotation.StringRes; import nodomain.freeyourgadget.gadgetbridge.R; -import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; -public class ActivityKind { - public static final int TYPE_NOT_MEASURED = -1; - public static final int TYPE_UNKNOWN = 0x00000000; - public static final int TYPE_ACTIVITY = 0x00000001; - public static final int TYPE_LIGHT_SLEEP = 0x00000002; - public static final int TYPE_DEEP_SLEEP = 0x00000004; - public static final int TYPE_NOT_WORN = 0x00000008; - public static final int TYPE_RUNNING = 0x00000010; - public static final int TYPE_WALKING = 0x00000020; - public static final int TYPE_SWIMMING = 0x00000040; - public static final int TYPE_CYCLING = 0x00000080; - public static final int TYPE_TREADMILL = 0x00000100; - public static final int TYPE_EXERCISE = 0x00000200; - public static final int TYPE_SWIMMING_OPENWATER = 0x00000400; - public static final int TYPE_INDOOR_CYCLING = 0x00000800; - public static final int TYPE_ELLIPTICAL_TRAINER = 0x00001000; - public static final int TYPE_JUMP_ROPING = 0x00002000; - public static final int TYPE_YOGA = 0x00004000; - public static final int TYPE_SOCCER = 0x00008000; - public static final int TYPE_ROWING_MACHINE = 0x00010000; - public static final int TYPE_CRICKET = 0x00020000; - public static final int TYPE_BASKETBALL = 0x00040000; - public static final int TYPE_PINGPONG = 0x00080000; - public static final int TYPE_BADMINTON = 0x00100000; - public static final int TYPE_STRENGTH_TRAINING = 0x00200000; - public static final int TYPE_HIKING = 0x00400000; - public static final int TYPE_CLIMBING = 0x00800000; - public static final int TYPE_REM_SLEEP = 0x01000000; - public static final int TYPE_AWAKE_SLEEP = 0x02000000; +public enum ActivityKind { + NOT_MEASURED(-1, R.string.activity_type_not_measured, R.drawable.ic_activity_not_measured), + UNKNOWN(0x00000000, R.string.activity_type_unknown), + ACTIVITY(0x00000001, R.string.activity_type_activity), + LIGHT_SLEEP(0x00000002, R.string.activity_type_light_sleep, R.drawable.ic_activity_sleep), + DEEP_SLEEP(0x00000004, R.string.activity_type_deep_sleep, R.drawable.ic_activity_sleep), + NOT_WORN(0x00000008, R.string.activity_type_not_worn), + RUNNING(0x00000010, R.string.activity_type_running, R.drawable.ic_activity_running), + WALKING(0x00000020, R.string.activity_type_walking, R.drawable.ic_activity_walking), + SWIMMING(0x00000040, R.string.activity_type_swimming, R.drawable.ic_activity_swimming), + CYCLING(0x00000080, R.string.activity_type_biking, R.drawable.ic_activity_biking), + TREADMILL(0x00000100, R.string.activity_type_treadmill, R.drawable.ic_activity_threadmill), + EXERCISE(0x00000200, R.string.activity_type_exercise, R.drawable.ic_activity_exercise), + SWIMMING_OPENWATER(0x00000400, R.string.activity_type_swimming_openwater, R.drawable.ic_activity_swimming), + INDOOR_CYCLING(0x00000800, R.string.activity_type_indoor_cycling, R.drawable.ic_activity_bike_trainer), + ELLIPTICAL_TRAINER(0x00001000, R.string.activity_type_elliptical_trainer, R.drawable.ic_activity_eliptical), + JUMP_ROPING(0x00002000, R.string.activity_type_jump_roping, R.drawable.ic_activity_rope_jump), + YOGA(0x00004000, R.string.activity_type_yoga, R.drawable.ic_activity_yoga), + SOCCER(0x00008000, R.string.activity_type_soccer, R.drawable.ic_activity_soccer), + ROWING_MACHINE(0x00010000, R.string.activity_type_rowing_machine, R.drawable.ic_activity_rowing), + CRICKET(0x00020000, R.string.activity_type_cricket, R.drawable.ic_activity_cricket), + BASKETBALL(0x00040000, R.string.activity_type_basketball, R.drawable.ic_activity_basketball), + PINGPONG(0x00080000, R.string.activity_type_pingpong, R.drawable.ic_activity_pingpong), + BADMINTON(0x00100000, R.string.activity_type_badminton, R.drawable.ic_activity_badmington), + STRENGTH_TRAINING(0x00200000, R.string.activity_type_strength_training), + HIKING(0x00400000, R.string.activity_type_hiking, R.drawable.ic_activity_hiking), + CLIMBING(0x00800000, R.string.activity_type_climbing, R.drawable.ic_activity_climbing), + REM_SLEEP(0x01000000, R.string.abstract_chart_fragment_kind_rem_sleep, R.drawable.ic_activity_sleep), + SLEEP_ANY(0x00000002 | 0x00000004 | 0x01000000 | 0x02000000, R.string.menuitem_sleep, R.drawable.ic_activity_sleep), + AWAKE_SLEEP(0x02000000, R.string.abstract_chart_fragment_kind_awake_sleep, R.drawable.ic_activity_sleep), - private static final int TYPES_COUNT = 26; + // FIXME: Deprecate these - they're just kept around while we do not support reading from the old db + VIVOMOVE_HR_TRANSITION(0x00000001 | 0x00000010 | 0x00000020 | 0x00000200 | 0x00000040, R.string.transition), + ; - public static final int TYPE_SLEEP = TYPE_LIGHT_SLEEP | TYPE_DEEP_SLEEP | TYPE_REM_SLEEP | TYPE_AWAKE_SLEEP; - public static final int TYPE_ALL = TYPE_ACTIVITY | TYPE_SLEEP | TYPE_NOT_WORN; + private final int code; + private final int label; + private final int icon; - public static int[] mapToDBActivityTypes(int types, SampleProvider provider) { - int[] result = new int[TYPES_COUNT]; - int i = 0; - if ((types & ActivityKind.TYPE_ACTIVITY) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_ACTIVITY); - } - if ((types & ActivityKind.TYPE_DEEP_SLEEP) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_DEEP_SLEEP); - } - if ((types & ActivityKind.TYPE_LIGHT_SLEEP) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_LIGHT_SLEEP); - } - if ((types & ActivityKind.TYPE_NOT_WORN) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_NOT_WORN); - } - if ((types & ActivityKind.TYPE_RUNNING) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_RUNNING); - } - if ((types & ActivityKind.TYPE_WALKING) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_WALKING); - } - if ((types & ActivityKind.TYPE_HIKING) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_HIKING); - } - if ((types & ActivityKind.TYPE_CLIMBING) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_CLIMBING); - } - if ((types & ActivityKind.TYPE_SWIMMING) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_SWIMMING); - } - if ((types & ActivityKind.TYPE_CYCLING) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_CYCLING); - } - if ((types & ActivityKind.TYPE_TREADMILL) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_TREADMILL); - } - if ((types & ActivityKind.TYPE_EXERCISE) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_EXERCISE); - } - if ((types & ActivityKind.TYPE_SWIMMING_OPENWATER) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_SWIMMING_OPENWATER); - } - if ((types & ActivityKind.TYPE_INDOOR_CYCLING) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_INDOOR_CYCLING); - } - if ((types & ActivityKind.TYPE_ELLIPTICAL_TRAINER) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_ELLIPTICAL_TRAINER); - } - if ((types & ActivityKind.TYPE_JUMP_ROPING) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_JUMP_ROPING); - } - if ((types & ActivityKind.TYPE_YOGA) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_YOGA); - } - if ((types & ActivityKind.TYPE_ROWING_MACHINE) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_ROWING_MACHINE); - } - if ((types & ActivityKind.TYPE_CRICKET) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_CRICKET); - } - if ((types & ActivityKind.TYPE_BASKETBALL) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_BASKETBALL); - } - if ((types & ActivityKind.TYPE_PINGPONG) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_PINGPONG); - } - if ((types & ActivityKind.TYPE_BADMINTON) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_BADMINTON); - } - if ((types & ActivityKind.TYPE_STRENGTH_TRAINING) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_STRENGTH_TRAINING); - } - if ((types & ActivityKind.TYPE_REM_SLEEP) != 0) { - result[i++] = provider.toRawActivityKind(TYPE_REM_SLEEP); - } - - return Arrays.copyOf(result, i); + ActivityKind(final int code) { + this(code, R.string.activity_type_unknown); } - public static String asString(int kind, Context context) { - switch (kind) { - case TYPE_NOT_MEASURED: - return context.getString(R.string.activity_type_not_measured); - case TYPE_ACTIVITY: - return context.getString(R.string.activity_type_activity); - case TYPE_LIGHT_SLEEP: - return context.getString(R.string.activity_type_light_sleep); - case TYPE_DEEP_SLEEP: - return context.getString(R.string.activity_type_deep_sleep); - case TYPE_NOT_WORN: - return context.getString(R.string.activity_type_not_worn); - case TYPE_RUNNING: - return context.getString(R.string.activity_type_running); - case TYPE_WALKING: - return context.getString(R.string.activity_type_walking); - case TYPE_HIKING: - return context.getString(R.string.activity_type_hiking); - case TYPE_CLIMBING: - return context.getString(R.string.activity_type_climbing); - case TYPE_SWIMMING: - return context.getString(R.string.activity_type_swimming); - case TYPE_CYCLING: - return context.getString(R.string.activity_type_biking); - case TYPE_TREADMILL: - return context.getString(R.string.activity_type_treadmill); - case TYPE_EXERCISE: - return context.getString(R.string.activity_type_exercise); - case TYPE_SWIMMING_OPENWATER: - return context.getString(R.string.activity_type_swimming_openwater); - case TYPE_INDOOR_CYCLING: - return context.getString(R.string.activity_type_indoor_cycling); - case TYPE_ELLIPTICAL_TRAINER: - return context.getString(R.string.activity_type_elliptical_trainer); - case TYPE_JUMP_ROPING: - return context.getString(R.string.activity_type_jump_roping); - case TYPE_YOGA: - return context.getString(R.string.activity_type_yoga); - case TYPE_SOCCER: - return context.getString(R.string.activity_type_soccer); - case TYPE_ROWING_MACHINE: - return context.getString(R.string.activity_type_rowing_machine); - case TYPE_CRICKET: - return context.getString(R.string.activity_type_cricket); - case TYPE_BASKETBALL: - return context.getString(R.string.activity_type_basketball); - case TYPE_PINGPONG: - return context.getString(R.string.activity_type_pingpong); - case TYPE_BADMINTON: - return context.getString(R.string.activity_type_badminton); - case TYPE_STRENGTH_TRAINING: - return context.getString(R.string.activity_type_strength_training); - case TYPE_UNKNOWN: - default: - return context.getString(R.string.activity_type_unknown); - } + ActivityKind(final int code, @StringRes final int label) { + this(code, label, R.drawable.ic_activity_unknown_small); + } + + ActivityKind(final int code, @StringRes final int label, @DrawableRes final int icon) { + this.code = code; + this.label = label; + this.icon = icon; + } + + public int getCode() { + return code; + } + + @StringRes + public int getLabel() { + return label; + } + + public String getLabel(final Context context) { + return context.getString(label); } @DrawableRes - public static int getIconId(int kind) { - switch (kind) { - case TYPE_NOT_MEASURED: - return R.drawable.ic_activity_not_measured; - case TYPE_LIGHT_SLEEP: - case TYPE_DEEP_SLEEP: - case TYPE_REM_SLEEP: - return R.drawable.ic_activity_sleep; - case TYPE_RUNNING: - return R.drawable.ic_activity_running; - case TYPE_WALKING: - return R.drawable.ic_activity_walking; - case TYPE_HIKING: - return R.drawable.ic_activity_hiking; - case TYPE_CLIMBING: - return R.drawable.ic_activity_climbing; - case TYPE_CYCLING: - return R.drawable.ic_activity_biking; - case TYPE_TREADMILL: - return R.drawable.ic_activity_threadmill; - case TYPE_EXERCISE: - return R.drawable.ic_activity_exercise; - case TYPE_SWIMMING: - case TYPE_SWIMMING_OPENWATER: - return R.drawable.ic_activity_swimming; - case TYPE_INDOOR_CYCLING: - return R.drawable.ic_activity_bike_trainer; - case TYPE_ELLIPTICAL_TRAINER: - return R.drawable.ic_activity_eliptical; - case TYPE_JUMP_ROPING: - return R.drawable.ic_activity_rope_jump; - case TYPE_YOGA: - return R.drawable.ic_activity_yoga; - case TYPE_SOCCER: - return R.drawable.ic_activity_soccer; - case TYPE_ROWING_MACHINE: - return R.drawable.ic_activity_rowing; - case TYPE_CRICKET: - return R.drawable.ic_activity_cricket; - case TYPE_BASKETBALL: - return R.drawable.ic_activity_basketball; - case TYPE_PINGPONG: - return R.drawable.ic_activity_pingpong; - case TYPE_BADMINTON: - return R.drawable.ic_activity_badmington; - case TYPE_STRENGTH_TRAINING: - return R.drawable.ic_activity_unknown_small; //FIXME: find icon + public int getIcon() { + return icon; + } - case TYPE_NOT_WORN: // fall through - case TYPE_ACTIVITY: // fall through - case TYPE_UNKNOWN: // fall through - default: - return R.drawable.ic_activity_unknown_small; + public static ActivityKind fromCode(final int code) { + for (final ActivityKind kind : ActivityKind.values()) { + if (kind.code == code) { + return kind; + } } + + //throw new IllegalArgumentException("Unknown ActivityKind code " + code); + return UNKNOWN; + } + + public static boolean isSleep(final ActivityKind activityKind) { + return activityKind == ActivityKind.SLEEP_ANY + || activityKind == ActivityKind.LIGHT_SLEEP + || activityKind == ActivityKind.DEEP_SLEEP + || activityKind == ActivityKind.REM_SLEEP + || activityKind == ActivityKind.AWAKE_SLEEP; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySample.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySample.java index bc5ec3419..4c55fa7f4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySample.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySample.java @@ -43,7 +43,7 @@ public interface ActivitySample extends TimeStamped { * * @return who created the sample data */ - SampleProvider getProvider(); + SampleProvider getProvider(); /** * Returns the raw activity kind value as recorded by the SampleProvider @@ -55,7 +55,7 @@ public interface ActivitySample extends TimeStamped { * * @see ActivityKind */ - int getKind(); + ActivityKind getKind(); /** * Returns the raw intensity value as recorded by the SampleProvider diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySession.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySession.java index 6db9e7e9a..6f379c45d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySession.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivitySession.java @@ -34,7 +34,7 @@ public class ActivitySession implements Serializable { private final int heartRateAverage; private final float intensity; private final float distance; - private final int activityKind; + private final ActivityKind activityKind; // following is related to step session, we hold it here for the listview // it is identified by SESSION_SUMMARY private int sessionCount = 0; @@ -45,7 +45,7 @@ public class ActivitySession implements Serializable { public ActivitySession(Date startTime, Date endTime, - int steps, int heartRateAverage, float intensity, float distance, int activityKind) { + int steps, int heartRateAverage, float intensity, float distance, ActivityKind activityKind) { this.startTime = startTime; this.endTime = endTime; this.activeSteps = steps; @@ -62,7 +62,7 @@ public class ActivitySession implements Serializable { this.heartRateAverage = 0; this.intensity = 0; this.distance = 0; - this.activityKind = 0; + this.activityKind = ActivityKind.UNKNOWN; }; public Date getStartTime() { @@ -81,7 +81,7 @@ public class ActivitySession implements Serializable { return heartRateAverage; } - public int getActivityKind() { + public ActivityKind getActivityKind() { return activityKind; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DailyTotals.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DailyTotals.java index 7b132dac5..ffbd6d213 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DailyTotals.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DailyTotals.java @@ -93,11 +93,11 @@ public class DailyTotals { long totalSecondsLightSleep = 0; long totalSecondsRemSleep = 0; for (ActivityAmount amount : activityAmounts.getAmounts()) { - if (amount.getActivityKind() == ActivityKind.TYPE_DEEP_SLEEP) { + if (amount.getActivityKind() == ActivityKind.DEEP_SLEEP) { totalSecondsDeepSleep += amount.getTotalSeconds(); - } else if (amount.getActivityKind() == ActivityKind.TYPE_LIGHT_SLEEP) { + } else if (amount.getActivityKind() == ActivityKind.LIGHT_SLEEP) { totalSecondsLightSleep += amount.getTotalSeconds(); - } else if (amount.getActivityKind() == ActivityKind.TYPE_REM_SLEEP) { + } else if (amount.getActivityKind() == ActivityKind.REM_SLEEP) { totalSecondsRemSleep += amount.getTotalSeconds(); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSActivityTrack.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSActivityTrack.java index 8637bfd2c..1900a5959 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSActivityTrack.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSActivityTrack.java @@ -390,17 +390,17 @@ class BangleJSActivityTrack { summary.setName(log); summary.setStartTime(startTime); summary.setEndTime(endTime); - int activityKind; + ActivityKind activityKind; if (analyticsObject.has("Speed")) { if ((float) 3 > averageOfJSONArray(analyticsObject.getJSONArray("Speed"))) { - activityKind = ActivityKind.TYPE_WALKING; + activityKind = ActivityKind.WALKING; } else { - activityKind = ActivityKind.TYPE_RUNNING; + activityKind = ActivityKind.RUNNING; } } else { - activityKind = ActivityKind.TYPE_ACTIVITY; + activityKind = ActivityKind.ACTIVITY; } - summary.setActivityKind(activityKind); // TODO: Make this depend on info from watch (currently this info isn't supplied in Bangle.js recorder logs). + summary.setActivityKind(activityKind.getCode()); // TODO: Make this depend on info from watch (currently this info isn't supplied in Bangle.js recorder logs). summary.setRawDetailsPath(String.valueOf(inputFile)); @@ -577,23 +577,23 @@ class BangleJSActivityTrack { ActivityTrackExporter exporter = createExporter(); String trackType = "track"; - switch (summary.getActivityKind()) { - case ActivityKind.TYPE_CYCLING: + switch (ActivityKind.fromCode(summary.getActivityKind())) { + case CYCLING: trackType = context.getString(R.string.activity_type_biking); break; - case ActivityKind.TYPE_RUNNING: + case RUNNING: trackType = context.getString(R.string.activity_type_running); break; - case ActivityKind.TYPE_WALKING: + case WALKING: trackType = context.getString(R.string.activity_type_walking); break; - case ActivityKind.TYPE_HIKING: + case HIKING: trackType = context.getString(R.string.activity_type_hiking); break; - case ActivityKind.TYPE_CLIMBING: + case CLIMBING: trackType = context.getString(R.string.activity_type_climbing); break; - case ActivityKind.TYPE_SWIMMING: + case SWIMMING: trackType = context.getString(R.string.activity_type_swimming); break; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/FetchStepCountDataOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/FetchStepCountDataOperation.java index a83c1dc9d..f0afe9a8a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/FetchStepCountDataOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/FetchStepCountDataOperation.java @@ -225,9 +225,9 @@ public class FetchStepCountDataOperation extends AbstractBTLEOperation 0) { - stepCountData.get(packetIndex / 2).setRawKind(ActivityKind.TYPE_ACTIVITY); + stepCountData.get(packetIndex / 2).setRawKind(ActivityKind.ACTIVITY.getCode()); } else { - stepCountData.get(packetIndex / 2).setRawKind(ActivityKind.TYPE_NOT_MEASURED); + stepCountData.get(packetIndex / 2).setRawKind(ActivityKind.NOT_MEASURED.getCode()); } if(ts > ts_from && ts < ts_to) { stepsToday += count; @@ -269,9 +269,9 @@ public class FetchStepCountDataOperation extends AbstractBTLEOperation 0) - sample.setRawKind(ActivityKind.TYPE_ACTIVITY); + sample.setRawKind(ActivityKind.ACTIVITY.getCode()); else - sample.setRawKind(ActivityKind.TYPE_NOT_MEASURED); + sample.setRawKind(ActivityKind.NOT_MEASURED.getCode()); stepCountData.add(0, sample); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/cmfwatchpro/CmfActivitySync.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/cmfwatchpro/CmfActivitySync.java index 901f98d55..9f8665d2f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/cmfwatchpro/CmfActivitySync.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/cmfwatchpro/CmfActivitySync.java @@ -405,7 +405,7 @@ public class CmfActivitySync { BaseActivitySummary summary = new BaseActivitySummary(); summary.setRawSummaryData(summaryBytes); - summary.setActivityKind(ActivityKind.TYPE_UNKNOWN); + summary.setActivityKind(ActivityKind.UNKNOWN.getCode()); try { summary = summaryParser.parseBinaryData(summary); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/cmfwatchpro/CmfActivityType.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/cmfwatchpro/CmfActivityType.java index fe2c7f040..c146399c7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/cmfwatchpro/CmfActivityType.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/cmfwatchpro/CmfActivityType.java @@ -24,28 +24,28 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; public enum CmfActivityType { // Core (non-removable in official app) - INDOOR_RUNNING(0x03, R.string.activity_type_indoor_running, ActivityKind.TYPE_RUNNING), - OUTDOOR_RUNNING(0x02, R.string.activity_type_outdoor_running, ActivityKind.TYPE_RUNNING), + INDOOR_RUNNING(0x03, R.string.activity_type_indoor_running, ActivityKind.RUNNING), + OUTDOOR_RUNNING(0x02, R.string.activity_type_outdoor_running, ActivityKind.RUNNING), // Fitness - OUTDOOR_WALKING(0x01, R.string.activity_type_outdoor_walking, ActivityKind.TYPE_WALKING), - INDOOR_WALKING(0x19, R.string.activity_type_indoor_walking, ActivityKind.TYPE_WALKING), - OUTDOOR_CYCLING(0x05, R.string.activity_type_outdoor_cycling, ActivityKind.TYPE_CYCLING), - INDOOR_CYCLING(0x72, R.string.activity_type_indoor_cycling, ActivityKind.TYPE_INDOOR_CYCLING), - MOUNTAIN_HIKE(0x04, R.string.activity_type_mountain_hike, ActivityKind.TYPE_HIKING), - HIKING(0x1A, R.string.activity_type_hiking, ActivityKind.TYPE_HIKING), + OUTDOOR_WALKING(0x01, R.string.activity_type_outdoor_walking, ActivityKind.WALKING), + INDOOR_WALKING(0x19, R.string.activity_type_indoor_walking, ActivityKind.WALKING), + OUTDOOR_CYCLING(0x05, R.string.activity_type_outdoor_cycling, ActivityKind.CYCLING), + INDOOR_CYCLING(0x72, R.string.activity_type_indoor_cycling, ActivityKind.INDOOR_CYCLING), + MOUNTAIN_HIKE(0x04, R.string.activity_type_mountain_hike, ActivityKind.HIKING), + HIKING(0x1A, R.string.activity_type_hiking, ActivityKind.HIKING), CROSS_TRAINER(0x18, R.string.activity_type_cross_trainer), - FREE_TRAINING(0x10, R.string.activity_type_free_training, ActivityKind.TYPE_STRENGTH_TRAINING), - STRENGTH_TRAINING(0x13, R.string.activity_type_strength_training, ActivityKind.TYPE_STRENGTH_TRAINING), - YOGA(0x0F, R.string.activity_type_yoga, ActivityKind.TYPE_YOGA), + FREE_TRAINING(0x10, R.string.activity_type_free_training, ActivityKind.STRENGTH_TRAINING), + STRENGTH_TRAINING(0x13, R.string.activity_type_strength_training, ActivityKind.STRENGTH_TRAINING), + YOGA(0x0F, R.string.activity_type_yoga, ActivityKind.YOGA), BOXING(0x21, R.string.activity_type_boxing), - ROWER(0x0E, R.string.activity_type_rower, ActivityKind.TYPE_ROWING_MACHINE), + ROWER(0x0E, R.string.activity_type_rower, ActivityKind.ROWING_MACHINE), DYNAMIC_CYCLE(0x0D, R.string.activity_type_dynamic_cycle), STAIR_STEPPER(0x73, R.string.activity_type_stair_stepper), - TREADMILL(0x26, R.string.activity_type_treadmill, ActivityKind.TYPE_TREADMILL), + TREADMILL(0x26, R.string.activity_type_treadmill, ActivityKind.TREADMILL), KICKBOXING(0x35, R.string.activity_type_kickboxing), HIIT(0x5C, R.string.activity_type_hiit), FITNESS_EXERCISES(0x4E, R.string.activity_type_fitness_exercises), - JUMP_ROPING(0x06, R.string.activity_type_jump_roping, ActivityKind.TYPE_JUMP_ROPING), // moved to leisure sports in watch 2 + JUMP_ROPING(0x06, R.string.activity_type_jump_roping, ActivityKind.JUMP_ROPING), // moved to leisure sports in watch 2 PILATES(0x2C, R.string.activity_type_pilates), CROSSFIT(0x74, R.string.activity_type_crossfit), FUNCTIONAL_TRAINING(0x2E, R.string.activity_type_functional_training), @@ -106,7 +106,7 @@ public enum CmfActivityType { KARTING(0xA0, R.string.activity_type_karting), // Ball sports BADMINTON(0x09, R.string.activity_type_badminton), - TABLE_TENNIS(0x0A, R.string.activity_type_table_tennis, ActivityKind.TYPE_PINGPONG), + TABLE_TENNIS(0x0A, R.string.activity_type_table_tennis, ActivityKind.PINGPONG), TENNIS(0x0C, R.string.activity_type_tennis), BILLIARDS(0x7C, R.string.activity_type_billiards), BOWLING(0x3B, R.string.activity_type_bowling), @@ -120,8 +120,8 @@ public enum CmfActivityType { HOCKEY(0x1E, R.string.activity_type_hockey), SQUASH(0x3C, R.string.activity_type_squash), DODGEBALL(0x81, R.string.activity_type_dodgeball), - SOCCER(0x07, R.string.activity_type_soccer, ActivityKind.TYPE_SOCCER), - BASKETBALL(0x08, R.string.activity_type_basketball, ActivityKind.TYPE_BASKETBALL), + SOCCER(0x07, R.string.activity_type_soccer, ActivityKind.SOCCER), + BASKETBALL(0x08, R.string.activity_type_basketball, ActivityKind.BASKETBALL), AUSTRALIAN_FOOTBALL(0x37, R.string.activity_type_australian_football), GOLF(0x45, R.string.activity_type_golf), PICKLEBALL(0x5B, R.string.activity_type_pickleball), @@ -157,13 +157,13 @@ public enum CmfActivityType { private final byte code; @StringRes private final int nameRes; - private final int activityKind; + private final ActivityKind activityKind; CmfActivityType(final int code, final int nameRes) { - this(code, nameRes, ActivityKind.TYPE_UNKNOWN); + this(code, nameRes, ActivityKind.UNKNOWN); } - CmfActivityType(final int code, final int nameRes, final int activityKind) { + CmfActivityType(final int code, final int nameRes, final ActivityKind activityKind) { this.code = (byte) code; this.nameRes = nameRes; this.activityKind = activityKind; @@ -173,7 +173,7 @@ public enum CmfActivityType { return code; } - public int getActivityKind() { + public ActivityKind getActivityKind() { return activityKind; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/cycling_sensor/support/CyclingSensorSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/cycling_sensor/support/CyclingSensorSupport.java index bdf5b0f88..aceb4d361 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/cycling_sensor/support/CyclingSensorSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/cycling_sensor/support/CyclingSensorSupport.java @@ -1,6 +1,6 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.cycling_sensor.support; -import static nodomain.freeyourgadget.gadgetbridge.model.ActivityKind.TYPE_CYCLING; +import static nodomain.freeyourgadget.gadgetbridge.model.ActivityKind.CYCLING; import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGattCharacteristic; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/fitpro/FitProDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/fitpro/FitProDeviceSupport.java index a3b057f00..c9641dd45 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/fitpro/FitProDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/fitpro/FitProDeviceSupport.java @@ -1355,7 +1355,7 @@ public class FitProDeviceSupport extends AbstractBTLEDeviceSupport { sample.setSpo2Percent(spo2); sample.setTimestamp((int) (date.getTimeInMillis() / 1000)); - sample.setRawKind(ActivityKind.TYPE_ACTIVITY); + sample.setRawKind(ActivityKind.ACTIVITY.getCode()); addGBActivitySample(sample); broadcastSample(sample); @@ -1394,7 +1394,7 @@ public class FitProDeviceSupport extends AbstractBTLEDeviceSupport { sample.setSteps(newSteps); sample.setDistanceMeters(distance); sample.setCaloriesBurnt(calories); - sample.setRawKind(ActivityKind.TYPE_ACTIVITY); + sample.setRawKind(ActivityKind.ACTIVITY); sample.setRawIntensity(1); addGBActivitySample(sample); broadcastSample(sample); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/fit/FitImporter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/fit/FitImporter.java index 29f1085ec..cc17e38e1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/fit/FitImporter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/fit/FitImporter.java @@ -285,18 +285,18 @@ public class FitImporter { LOG.debug("Persisting workout for {}", fileId); final BaseActivitySummary summary = new BaseActivitySummary(); - summary.setActivityKind(ActivityKind.TYPE_UNKNOWN); + summary.setActivityKind(ActivityKind.UNKNOWN.getCode()); final ActivitySummaryData summaryData = new ActivitySummaryData(); - final int activityKind; + final ActivityKind activityKind; if (sport != null) { summary.setName(sport.getName()); activityKind = getActivityKind(sport.getSport(), sport.getSubSport()); } else { activityKind = getActivityKind(session.getSport(), session.getSubSport()); } - summary.setActivityKind(activityKind); + summary.setActivityKind(activityKind.getCode()); if (session.getStartTime() == null) { LOG.error("No session start time for {}", fileId); return; @@ -355,11 +355,11 @@ public class FitImporter { } } - private int getActivityKind(final Integer sport, final Integer subsport) { + private ActivityKind getActivityKind(final Integer sport, final Integer subsport) { final Optional garminSport = GarminSport.fromCodes(sport, subsport); if (garminSport.isEmpty()) { LOG.warn("Unknown garmin sport {}/{}", sport, subsport); - return ActivityKind.TYPE_UNKNOWN; + return ActivityKind.UNKNOWN; } switch (garminSport.get()) { @@ -367,48 +367,48 @@ public class FitImporter { case PUSH_RUN_SPEED: case INDOOR_PUSH_RUN_SPEED: case INDOOR_TRACK: - return ActivityKind.TYPE_RUNNING; + return ActivityKind.RUNNING; case TREADMILL: - return ActivityKind.TYPE_TREADMILL; + return ActivityKind.TREADMILL; case E_BIKE: case BIKE: case BIKE_COMMUTE: - return ActivityKind.TYPE_CYCLING; + return ActivityKind.CYCLING; case BIKE_INDOOR: - return ActivityKind.TYPE_INDOOR_CYCLING; + return ActivityKind.INDOOR_CYCLING; case ELLIPTICAL: - return ActivityKind.TYPE_ELLIPTICAL_TRAINER; + return ActivityKind.ELLIPTICAL_TRAINER; case STAIR_STEPPER: case PILATES: case CARDIO: - return ActivityKind.TYPE_EXERCISE; + return ActivityKind.EXERCISE; case POOL_SWIM: - return ActivityKind.TYPE_SWIMMING; + return ActivityKind.SWIMMING; case OPEN_WATER: - return ActivityKind.TYPE_SWIMMING_OPENWATER; + return ActivityKind.SWIMMING_OPENWATER; case SOCCER: - return ActivityKind.TYPE_SOCCER; + return ActivityKind.SOCCER; case STRENGTH: - return ActivityKind.TYPE_STRENGTH_TRAINING; + return ActivityKind.STRENGTH_TRAINING; case YOGA: - return ActivityKind.TYPE_YOGA; + return ActivityKind.YOGA; case WALK: case WALK_INDOOR: case PUSH_WALK_SPEED: case INDOOR_PUSH_WALK_SPEED: - return ActivityKind.TYPE_WALKING; + return ActivityKind.WALKING; case HIKE: - return ActivityKind.TYPE_HIKING; + return ActivityKind.HIKING; case CLIMB_INDOOR: case BOULDERING: - return ActivityKind.TYPE_CLIMBING; + return ActivityKind.CLIMBING; case BASKETBALL: - return ActivityKind.TYPE_BASKETBALL; + return ActivityKind.BASKETBALL; case JUMP_ROPE: - return ActivityKind.TYPE_JUMP_ROPING; + return ActivityKind.JUMP_ROPING; } - return ActivityKind.TYPE_UNKNOWN; + return ActivityKind.UNKNOWN; } private void reset() { @@ -440,7 +440,7 @@ public class FitImporter { final Map stepsPerActivity = new HashMap<>(); final int THRESHOLD_NOT_WORN = 10 * 60; // 10 min gap between samples = not-worn - int prevActivityKind = ActivityKind.TYPE_UNKNOWN; + int prevActivityKind = ActivityKind.UNKNOWN.getCode(); int prevTs = -1; for (final int ts : activitySamplesPerTimestamp.keySet()) { @@ -449,7 +449,7 @@ public class FitImporter { for (int i = prevTs; i < ts; i += 60) { final GarminActivitySample sample = new GarminActivitySample(); sample.setTimestamp(i); - sample.setRawKind(ts - prevTs > THRESHOLD_NOT_WORN ? ActivityKind.TYPE_NOT_WORN : prevActivityKind); + sample.setRawKind(ts - prevTs > THRESHOLD_NOT_WORN ? ActivityKind.NOT_WORN.getCode() : prevActivityKind); sample.setRawIntensity(ActivitySample.NOT_MEASURED); sample.setSteps(ActivitySample.NOT_MEASURED); activitySamples.add(sample); @@ -460,7 +460,7 @@ public class FitImporter { final GarminActivitySample sample = new GarminActivitySample(); sample.setTimestamp(ts); - sample.setRawKind(ActivityKind.TYPE_ACTIVITY); + sample.setRawKind(ActivityKind.ACTIVITY.getCode()); sample.setRawIntensity(ActivitySample.NOT_MEASURED); sample.setSteps(ActivitySample.NOT_MEASURED); sample.setHeartRate(ActivitySample.NOT_MEASURED); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusDataRecord.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusDataRecord.java index bc2d3c566..5e05bb7e8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusDataRecord.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusDataRecord.java @@ -18,11 +18,9 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.hplus; import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; -/* +/** * @author João Paulo Barraca <jpbarraca@gmail.com> */ - - public class HPlusDataRecord { public final static int TYPE_UNKNOWN = 0; public final static int TYPE_SLEEP = 100; @@ -31,7 +29,7 @@ public class HPlusDataRecord { public final static int TYPE_REALTIME = 103; public int type = TYPE_UNKNOWN; - public int activityKind = ActivityKind.TYPE_UNKNOWN; + public int activityKindRaw = ActivityKind.UNKNOWN.getCode(); /** * Time of this record in seconds @@ -53,11 +51,10 @@ public class HPlusDataRecord { } public byte[] getRawData() { - return rawData; } - public class RecordInterval { + public static class RecordInterval { /** * Start time of this interval in seconds */ @@ -71,9 +68,9 @@ public class HPlusDataRecord { /** * Type of activity {@link ActivityKind} */ - public int activityKind; + public ActivityKind activityKind; - RecordInterval(int timestampFrom, int timestampTo, int activityKind) { + RecordInterval(int timestampFrom, int timestampTo, ActivityKind activityKind) { this.timestampFrom = timestampFrom; this.timestampTo = timestampTo; this.activityKind = activityKind; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusDataRecordRealtime.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusDataRecordRealtime.java index e22f507e6..630dd267c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusDataRecordRealtime.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusDataRecordRealtime.java @@ -21,6 +21,8 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.hplus; */ +import androidx.annotation.NonNull; + import java.util.GregorianCalendar; import java.util.Locale; @@ -87,16 +89,16 @@ class HPlusDataRecordRealtime extends HPlusDataRecord { battery = ActivitySample.NOT_MEASURED; heartRate = ActivitySample.NOT_MEASURED; intensity = 0; - activityKind = ActivityKind.TYPE_NOT_WORN; + activityKindRaw = ActivityKind.NOT_WORN.getCode(); } else { heartRate = data[11] & 0xFF; // BPM if (heartRate == 255) { intensity = 0; - activityKind = ActivityKind.TYPE_NOT_MEASURED; + activityKindRaw = ActivityKind.NOT_MEASURED.getCode(); heartRate = ActivitySample.NOT_MEASURED; } else { intensity = (int) ((100 * heartRate) / (208 - 0.7 * age)); - activityKind = HPlusDataRecord.TYPE_REALTIME; + activityKindRaw = HPlusDataRecord.TYPE_REALTIME; } } } @@ -118,7 +120,7 @@ class HPlusDataRecordRealtime extends HPlusDataRecord { double speed = deltaDistance / deltaTime; if(speed >= 1.6) // ~6 KM/h - activityKind = ActivityKind.TYPE_ACTIVITY; + activityKindRaw = ActivityKind.ACTIVITY.getCode(); } public boolean same(HPlusDataRecordRealtime other){ @@ -128,8 +130,8 @@ class HPlusDataRecordRealtime extends HPlusDataRecord { return steps == other.steps && distance == other.distance && calories == other.calories && heartRate == other.heartRate && battery == other.battery; } + @NonNull public String toString(){ return String.format(Locale.US, "Distance: %d Steps: %d Calories: %d HeartRate: %d Battery: %d ActiveTime: %d Intensity: %d", distance, steps, calories, heartRate, battery, activeTime, intensity); } - } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusDataRecordSleep.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusDataRecordSleep.java index 172ea0e07..7a5f690ab 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusDataRecordSleep.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusDataRecordSleep.java @@ -128,8 +128,8 @@ public class HPlusDataRecordSleep extends HPlusDataRecord { List intervals = new ArrayList<>(); int ts = bedTimeStart + lightSleepMinutes * 60; - intervals.add(new RecordInterval(bedTimeStart, ts, ActivityKind.TYPE_LIGHT_SLEEP)); - intervals.add(new RecordInterval(ts, bedTimeEnd, ActivityKind.TYPE_DEEP_SLEEP)); + intervals.add(new RecordInterval(bedTimeStart, ts, ActivityKind.LIGHT_SLEEP)); + intervals.add(new RecordInterval(ts, bedTimeEnd, ActivityKind.DEEP_SLEEP)); return intervals; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusHandlerThread.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusHandlerThread.java index 36e44222d..f1e28cdbe 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusHandlerThread.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/hplus/HPlusHandlerThread.java @@ -321,7 +321,7 @@ class HPlusHandlerThread extends GBDeviceIoThread { //If it is the last of the samples or of the interruption period if (timestamp - lastSlotTimestamp > 10 * 60) { - overlayList.add(new HPlusHealthActivityOverlay(firstSlotTimestamp, lastSlotTimestamp, ActivityKind.TYPE_NOT_WORN, deviceId, userId, null)); + overlayList.add(new HPlusHealthActivityOverlay(firstSlotTimestamp, lastSlotTimestamp, ActivityKind.NOT_WORN.getCode(), deviceId, userId, null)); firstSlotTimestamp = timestamp; } @@ -330,7 +330,7 @@ class HPlusHandlerThread extends GBDeviceIoThread { } if (firstSlotTimestamp != lastSlotTimestamp) - overlayList.add(new HPlusHealthActivityOverlay(firstSlotTimestamp, lastSlotTimestamp, ActivityKind.TYPE_NOT_WORN, deviceId, userId, null)); + overlayList.add(new HPlusHealthActivityOverlay(firstSlotTimestamp, lastSlotTimestamp, ActivityKind.NOT_WORN.getCode(), deviceId, userId, null)); overlayDao.insertOrReplaceInTx(overlayList); } @@ -379,7 +379,7 @@ class HPlusHandlerThread extends GBDeviceIoThread { List intervals = record.getIntervals(); for (HPlusDataRecord.RecordInterval interval : intervals) { - overlayList.add(new HPlusHealthActivityOverlay(interval.timestampFrom, interval.timestampTo, interval.activityKind, deviceId, userId, null)); + overlayList.add(new HPlusHealthActivityOverlay(interval.timestampFrom, interval.timestampTo, interval.activityKind.getCode(), deviceId, userId, null)); } overlayDao.insertOrReplaceInTx(overlayList); @@ -387,7 +387,7 @@ class HPlusHandlerThread extends GBDeviceIoThread { //Store the data HPlusHealthActivitySample sample = createSample(dbHandler, record.timestamp); sample.setRawHPlusHealthData(record.getRawData()); - sample.setRawKind(record.activityKind); + sample.setRawKind(record.activityKindRaw); sample.setProvider(provider); @@ -631,7 +631,7 @@ class HPlusHandlerThread extends GBDeviceIoThread { timestamp, // ts deviceId, userId, // User id null, // Raw Data - ActivityKind.TYPE_UNKNOWN, + ActivityKind.UNKNOWN.getCode(), 0, // Intensity ActivitySample.NOT_MEASURED, // Steps ActivitySample.NOT_MEASURED, // HR diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSportsActivityType.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSportsActivityType.java index 8b6827d54..4dfff7f59 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSportsActivityType.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSportsActivityType.java @@ -47,48 +47,48 @@ public enum HuamiSportsActivityType { this.code = code; } - public int toActivityKind() { + public ActivityKind toActivityKind() { switch (this) { case OutdoorRunning: - return ActivityKind.TYPE_RUNNING; + return ActivityKind.RUNNING; case OutdoorHiking: - return ActivityKind.TYPE_HIKING; + return ActivityKind.HIKING; case Climbing: - return ActivityKind.TYPE_CLIMBING; + return ActivityKind.CLIMBING; case Treadmill: - return ActivityKind.TYPE_TREADMILL; + return ActivityKind.TREADMILL; case Cycling: - return ActivityKind.TYPE_CYCLING; + return ActivityKind.CYCLING; case Walking: - return ActivityKind.TYPE_WALKING; + return ActivityKind.WALKING; case Exercise: - return ActivityKind.TYPE_EXERCISE; + return ActivityKind.EXERCISE; case Swimming: - return ActivityKind.TYPE_SWIMMING; + return ActivityKind.SWIMMING; case OpenWaterSwimming: - return ActivityKind.TYPE_SWIMMING_OPENWATER; + return ActivityKind.SWIMMING_OPENWATER; case IndoorCycling: - return ActivityKind.TYPE_INDOOR_CYCLING; + return ActivityKind.INDOOR_CYCLING; case EllipticalTrainer: - return ActivityKind.TYPE_ELLIPTICAL_TRAINER; + return ActivityKind.ELLIPTICAL_TRAINER; case Soccer: - return ActivityKind.TYPE_SOCCER; + return ActivityKind.SOCCER; case JumpRope: - return ActivityKind.TYPE_JUMP_ROPING; + return ActivityKind.JUMP_ROPING; case RowingMachine: - return ActivityKind.TYPE_ROWING_MACHINE; + return ActivityKind.ROWING_MACHINE; case Yoga: - return ActivityKind.TYPE_YOGA; + return ActivityKind.YOGA; case Cricket: - return ActivityKind.TYPE_CRICKET; + return ActivityKind.CRICKET; case Basketball: - return ActivityKind.TYPE_BASKETBALL; + return ActivityKind.BASKETBALL; case PingPong: - return ActivityKind.TYPE_PINGPONG; + return ActivityKind.PINGPONG; case Badminton: - return ActivityKind.TYPE_BADMINTON; + return ActivityKind.BADMINTON; case StrengthTraining: - return ActivityKind.TYPE_STRENGTH_TRAINING; + return ActivityKind.STRENGTH_TRAINING; } throw new RuntimeException("Not mapped activity kind for: " + this); } @@ -102,47 +102,47 @@ public enum HuamiSportsActivityType { throw new RuntimeException("No matching HuamiSportsActivityType for code: " + huamiCode); } - public static HuamiSportsActivityType fromActivityKind(int activityKind) { + public static HuamiSportsActivityType fromActivityKind(ActivityKind activityKind) { switch (activityKind) { - case ActivityKind.TYPE_RUNNING: + case RUNNING: return OutdoorRunning; - case ActivityKind.TYPE_HIKING: + case HIKING: return OutdoorHiking; - case ActivityKind.TYPE_CLIMBING: + case CLIMBING: return Climbing; - case ActivityKind.TYPE_TREADMILL: + case TREADMILL: return Treadmill; - case ActivityKind.TYPE_CYCLING: + case CYCLING: return Cycling; - case ActivityKind.TYPE_WALKING: + case WALKING: return Walking; - case ActivityKind.TYPE_EXERCISE: + case EXERCISE: return Exercise; - case ActivityKind.TYPE_SWIMMING: + case SWIMMING: return Swimming; - case ActivityKind.TYPE_SWIMMING_OPENWATER: + case SWIMMING_OPENWATER: return OpenWaterSwimming; - case ActivityKind.TYPE_INDOOR_CYCLING: + case INDOOR_CYCLING: return IndoorCycling; - case ActivityKind.TYPE_ELLIPTICAL_TRAINER: + case ELLIPTICAL_TRAINER: return EllipticalTrainer; - case ActivityKind.TYPE_SOCCER: + case SOCCER: return Soccer; - case ActivityKind.TYPE_JUMP_ROPING: + case JUMP_ROPING: return JumpRope; - case ActivityKind.TYPE_ROWING_MACHINE: + case ROWING_MACHINE: return RowingMachine; - case ActivityKind.TYPE_YOGA: + case YOGA: return Yoga; - case ActivityKind.TYPE_CRICKET: + case CRICKET: return Cricket; - case ActivityKind.TYPE_BASKETBALL: + case BASKETBALL: return Basketball; - case ActivityKind.TYPE_PINGPONG: + case PINGPONG: return PingPong; - case ActivityKind.TYPE_BADMINTON: + case BADMINTON: return Badminton; - case ActivityKind.TYPE_STRENGTH_TRAINING: + case STRENGTH_TRAINING: return StrengthTraining; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java index fea20d6c1..8d4cebbc4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java @@ -1945,11 +1945,11 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements break; case HuamiDeviceEvent.WORKOUT_STARTING: final HuamiWorkoutTrackActivityType activityType = HuamiWorkoutTrackActivityType.fromCode(value[3]); - final int activityKind; + final ActivityKind activityKind; if (activityType == null) { LOG.warn("Unknown workout activity type {}", String.format("0x%02x", value[3])); - activityKind = ActivityKind.TYPE_UNKNOWN; + activityKind = ActivityKind.UNKNOWN; } else { activityKind = activityType.toActivityKind(); } @@ -1975,14 +1975,14 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements /** * Track the {@link nodomain.freeyourgadget.gadgetbridge.model.ActivityKind} that was opened, for the same reasons as {@code workoutNeedsGps}. */ - private int workoutActivityKind = ActivityKind.TYPE_UNKNOWN; + private ActivityKind workoutActivityKind = ActivityKind.UNKNOWN; /** * Track the last time we actually sent a gps location. We need to signal that GPS as re-acquired if the last update was too long ago. */ private long lastPhoneGpsSent = 0; - protected void onWorkoutOpen(final boolean needsGps, final int activityKind) { + protected void onWorkoutOpen(final boolean needsGps, final ActivityKind activityKind) { this.workoutNeedsGps = needsGps; this.workoutActivityKind = activityKind; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiWorkoutTrackActivityType.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiWorkoutTrackActivityType.java index aa0b10056..25129ffd1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiWorkoutTrackActivityType.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiWorkoutTrackActivityType.java @@ -46,31 +46,31 @@ public enum HuamiWorkoutTrackActivityType { return code; } - public int toActivityKind() { + public ActivityKind toActivityKind() { switch (this) { case Elliptical: - return ActivityKind.TYPE_ELLIPTICAL_TRAINER; + return ActivityKind.ELLIPTICAL_TRAINER; case IndoorCycling: - return ActivityKind.TYPE_INDOOR_CYCLING; + return ActivityKind.INDOOR_CYCLING; case JumpRope: - return ActivityKind.TYPE_JUMP_ROPING; + return ActivityKind.JUMP_ROPING; case OutdoorCycling: - return ActivityKind.TYPE_CYCLING; + return ActivityKind.CYCLING; case OutdoorRunning: - return ActivityKind.TYPE_RUNNING; + return ActivityKind.RUNNING; case PoolSwimming: - return ActivityKind.TYPE_SWIMMING; + return ActivityKind.SWIMMING; case RowingMachine: - return ActivityKind.TYPE_ROWING_MACHINE; + return ActivityKind.ROWING_MACHINE; case Treadmill: - return ActivityKind.TYPE_TREADMILL; + return ActivityKind.TREADMILL; case Walking: - return ActivityKind.TYPE_WALKING; + return ActivityKind.WALKING; case Yoga: - return ActivityKind.TYPE_YOGA; + return ActivityKind.YOGA; } - return ActivityKind.TYPE_UNKNOWN; + return ActivityKind.UNKNOWN; } public static HuamiWorkoutTrackActivityType fromCode(final byte code) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/fetch/FetchSportsDetailsOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/fetch/FetchSportsDetailsOperation.java index 0f23a3508..deea6d5cd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/fetch/FetchSportsDetailsOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/fetch/FetchSportsDetailsOperation.java @@ -99,23 +99,23 @@ public class FetchSportsDetailsOperation extends AbstractFetchOperation { final ActivityTrack track = detailsParser.parse(buffer.toByteArray()); final ActivityTrackExporter exporter = createExporter(); final String trackType; - switch (summary.getActivityKind()) { - case ActivityKind.TYPE_CYCLING: + switch (ActivityKind.fromCode(summary.getActivityKind())) { + case CYCLING: trackType = getContext().getString(R.string.activity_type_biking); break; - case ActivityKind.TYPE_RUNNING: + case RUNNING: trackType = getContext().getString(R.string.activity_type_running); break; - case ActivityKind.TYPE_WALKING: + case WALKING: trackType = getContext().getString(R.string.activity_type_walking); break; - case ActivityKind.TYPE_HIKING: + case HIKING: trackType = getContext().getString(R.string.activity_type_hiking); break; - case ActivityKind.TYPE_CLIMBING: + case CLIMBING: trackType = getContext().getString(R.string.activity_type_climbing); break; - case ActivityKind.TYPE_SWIMMING: + case SWIMMING: trackType = getContext().getString(R.string.activity_type_swimming); break; default: @@ -207,6 +207,7 @@ public class FetchSportsDetailsOperation extends AbstractFetchOperation { try { final File targetFolder = new File(FileUtils.getExternalFilesDir(), "rawDetails"); + //noinspection ResultOfMethodCallIgnored targetFolder.mkdirs(); final File targetFile = new File(targetFolder, fileName); outputStream = new FileOutputStream(targetFile); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/zeppos/ZeppOsActivityType.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/zeppos/ZeppOsActivityType.java index e950e110e..a425b9364 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/zeppos/ZeppOsActivityType.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/zeppos/ZeppOsActivityType.java @@ -159,55 +159,55 @@ public enum ZeppOsActivityType { return code; } - public int toActivityKind() { + public ActivityKind toActivityKind() { switch (this) { case Badminton: - return ActivityKind.TYPE_BADMINTON; + return ActivityKind.BADMINTON; case Basketball: - return ActivityKind.TYPE_BASKETBALL; + return ActivityKind.BASKETBALL; case Cricket: - return ActivityKind.TYPE_CRICKET; + return ActivityKind.CRICKET; case Elliptical: - return ActivityKind.TYPE_ELLIPTICAL_TRAINER; + return ActivityKind.ELLIPTICAL_TRAINER; case Freestyle: case IndoorFitness: - return ActivityKind.TYPE_EXERCISE; + return ActivityKind.EXERCISE; case IndoorCycling: - return ActivityKind.TYPE_INDOOR_CYCLING; + return ActivityKind.INDOOR_CYCLING; case JumpRope: - return ActivityKind.TYPE_JUMP_ROPING; + return ActivityKind.JUMP_ROPING; case OutdoorCycling: - return ActivityKind.TYPE_CYCLING; + return ActivityKind.CYCLING; case OutdoorHiking: - return ActivityKind.TYPE_HIKING; + return ActivityKind.HIKING; case OutdoorRunning: - return ActivityKind.TYPE_RUNNING; + return ActivityKind.RUNNING; case OutdoorSwimming: - return ActivityKind.TYPE_SWIMMING_OPENWATER; + return ActivityKind.SWIMMING_OPENWATER; case PoolSwimming: - return ActivityKind.TYPE_SWIMMING; + return ActivityKind.SWIMMING; case RockClimbing: - return ActivityKind.TYPE_CLIMBING; + return ActivityKind.CLIMBING; case Rowing: - return ActivityKind.TYPE_ROWING_MACHINE; + return ActivityKind.ROWING_MACHINE; case Soccer: - return ActivityKind.TYPE_SOCCER; + return ActivityKind.SOCCER; case TableTennis: - return ActivityKind.TYPE_PINGPONG; + return ActivityKind.PINGPONG; case Treadmill: - return ActivityKind.TYPE_TREADMILL; + return ActivityKind.TREADMILL; case Walking: case RaceWalking: - return ActivityKind.TYPE_WALKING; + return ActivityKind.WALKING; case Strength: - return ActivityKind.TYPE_STRENGTH_TRAINING; + return ActivityKind.STRENGTH_TRAINING; case Yoga: - return ActivityKind.TYPE_YOGA; + return ActivityKind.YOGA; } LOG.warn("Unmapped workout type {}", this); - return ActivityKind.TYPE_UNKNOWN; + return ActivityKind.UNKNOWN; } public static ZeppOsActivityType fromCode(final byte code) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/zeppos/ZeppOsSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/zeppos/ZeppOsSupport.java index 8a90accd0..702db42c2 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/zeppos/ZeppOsSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/zeppos/ZeppOsSupport.java @@ -1409,11 +1409,11 @@ public class ZeppOsSupport extends HuamiSupport implements ZeppOsFileTransferSer case WORKOUT_CMD_APP_OPEN: final ZeppOsActivityType activityType = ZeppOsActivityType.fromCode(payload[3]); final boolean workoutNeedsGps = (payload[2] == 1); - final int activityKind; + final ActivityKind activityKind; if (activityType == null) { LOG.warn("Unknown workout activity type {}", String.format("0x%x", payload[3])); - activityKind = ActivityKind.TYPE_UNKNOWN; + activityKind = ActivityKind.UNKNOWN; } else { activityKind = activityType.toActivityKind(); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiWorkoutGbParser.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiWorkoutGbParser.java index 267052ca0..e2381cded 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiWorkoutGbParser.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiWorkoutGbParser.java @@ -122,46 +122,46 @@ public class HuaweiWorkoutGbParser { } } - public static int huaweiTypeToGbType(byte huaweiType) { + public static ActivityKind huaweiTypeToGbType(byte huaweiType) { int type = huaweiType & 0xFF; switch (type) { case 1: - return ActivityKind.TYPE_RUNNING; + return ActivityKind.RUNNING; case 2: case 13: - return ActivityKind.TYPE_WALKING; + return ActivityKind.WALKING; case 6: - return ActivityKind.TYPE_SWIMMING; + return ActivityKind.SWIMMING; case 3: - return ActivityKind.TYPE_CYCLING; + return ActivityKind.CYCLING; case 7: - return ActivityKind.TYPE_INDOOR_CYCLING; + return ActivityKind.INDOOR_CYCLING; case 129: - return ActivityKind.TYPE_BADMINTON; + return ActivityKind.BADMINTON; case 130: - return ActivityKind.TYPE_EXERCISE; // TODO: Tennis + return ActivityKind.EXERCISE; // TODO: Tennis case 131: - return ActivityKind.TYPE_SOCCER; + return ActivityKind.SOCCER; case 132: - return ActivityKind.TYPE_BASKETBALL; + return ActivityKind.BASKETBALL; case 133: - return ActivityKind.TYPE_EXERCISE; // TODO: Volleyball + return ActivityKind.EXERCISE; // TODO: Volleyball case 134: - return ActivityKind.TYPE_ELLIPTICAL_TRAINER; + return ActivityKind.ELLIPTICAL_TRAINER; case 135: - return ActivityKind.TYPE_ROWING_MACHINE; + return ActivityKind.ROWING_MACHINE; case 163: - return ActivityKind.TYPE_EXERCISE; // TODO: Roller skating + return ActivityKind.EXERCISE; // TODO: Roller skating case 173: - return ActivityKind.TYPE_EXERCISE; // TODO: Laser tag + return ActivityKind.EXERCISE; // TODO: Laser tag case 177: - return ActivityKind.TYPE_EXERCISE; // TODO: stair climbing + return ActivityKind.EXERCISE; // TODO: stair climbing case 196: - return ActivityKind.TYPE_EXERCISE; // TODO: fishing + return ActivityKind.EXERCISE; // TODO: fishing case 216: - return ActivityKind.TYPE_EXERCISE; // TODO: motor racing + return ActivityKind.EXERCISE; // TODO: motor racing default: - return ActivityKind.TYPE_UNKNOWN; + return ActivityKind.UNKNOWN; } } @@ -204,7 +204,7 @@ public class HuaweiWorkoutGbParser { if (!duplicates.isEmpty()) previous = duplicates.get(0); - int type = huaweiTypeToGbType(summary.getType()); + ActivityKind type = huaweiTypeToGbType(summary.getType()); JSONObject jsonObject = new JSONObject(); @@ -274,7 +274,7 @@ public class HuaweiWorkoutGbParser { } boolean unknownData = false; - if (dataSamples.size() != 0) { + if (!dataSamples.isEmpty()) { int speed = 0; int speedCount = 0; boolean stepRatePresent = false; @@ -712,7 +712,7 @@ public class HuaweiWorkoutGbParser { "Workout " + summary.getWorkoutNumber(), start, end, - type, + type.getCode(), null, null, null, @@ -729,7 +729,7 @@ public class HuaweiWorkoutGbParser { previous.getName(), start, end, - type, + type.getCode(), previous.getBaseLongitude(), previous.getBaseLatitude(), previous.getBaseAltitude(), diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/id115/FetchActivityOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/id115/FetchActivityOperation.java index 4eff90206..c5a7564be 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/id115/FetchActivityOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/id115/FetchActivityOperation.java @@ -60,7 +60,7 @@ public class FetchActivityOperation extends AbstractID115Operation { outputStream.write(0x01); outputStream.write(0x00); outputStream.write(0x00); - byte cmd[] = outputStream.toByteArray(); + byte[] cmd = outputStream.toByteArray(); expectedCmd = ID115Constants.CMD_KEY_FETCH_ACTIVITY_TODAY; expectedSeq = 1; @@ -74,7 +74,7 @@ public class FetchActivityOperation extends AbstractID115Operation { @Override void handleResponse(byte[] data) { if (!isOperationRunning()) { - LOG.error("ignoring notification because operation is not running. Data length: " + data.length); + LOG.error("ignoring notification because operation is not running. Data length: {}", data.length); getSupport().logMessageContent(data); return; } @@ -97,7 +97,7 @@ public class FetchActivityOperation extends AbstractID115Operation { } expectedSeq += 1; - byte payload[] = new byte[data.length - 4]; + byte[] payload = new byte[data.length - 4]; System.arraycopy(data, 4, payload, 0, payload.length); packets.add(payload); } @@ -129,7 +129,7 @@ public class FetchActivityOperation extends AbstractID115Operation { ID115ActivitySample sample = parseSample(sampleData); if (sample != null) { sample.setTimestamp(ts); - sample.setRawKind(ActivityKind.TYPE_ACTIVITY); + sample.setRawKind(ActivityKind.ACTIVITY.getCode()); samples.add(sample); } ts += dt; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/jyou/JYouDataRecord.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/jyou/JYouDataRecord.java deleted file mode 100644 index cc4fb93d8..000000000 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/jyou/JYouDataRecord.java +++ /dev/null @@ -1,81 +0,0 @@ -/* Copyright (C) 2018-2024 Pavel Elagin - - This file is part of Gadgetbridge. - - Gadgetbridge is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Gadgetbridge is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - 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.jyou; - -/* - * @author Pavel Elagin <elagin.pasha@gmail.com> - */ - -import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; - -public class JYouDataRecord { - public final static int TYPE_UNKNOWN = 0; - public final static int TYPE_SLEEP = 100; - public final static int TYPE_DAY_SUMMARY = 101; - public final static int TYPE_DAY_SLOT = 102; - public final static int TYPE_REALTIME = 103; - - public int type = TYPE_UNKNOWN; - public int activityKind = ActivityKind.TYPE_UNKNOWN; - - /** - * Time of this record in seconds - */ - public int timestamp; - - /** - * Raw data as sent from the device - */ - public byte[] rawData; - - protected JYouDataRecord(){ - - } - - protected JYouDataRecord(byte[] data, int type){ - this.rawData = data; - this.type = type; - } - - public byte[] getRawData() { - - return rawData; - } - - public class RecordInterval { - /** - * Start time of this interval in seconds - */ - public int timestampFrom; - - /** - * End time of this interval in seconds - */ - public int timestampTo; - - /** - * Type of activity {@link ActivityKind} - */ - public int activityKind; - - RecordInterval(int timestampFrom, int timestampTo, int activityKind) { - this.timestampFrom = timestampFrom; - this.timestampTo = timestampTo; - this.activityKind = activityKind; - } - } -} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/lenovo/watchxplus/WatchXPlusDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/lenovo/watchxplus/WatchXPlusDeviceSupport.java index dcdd4d465..41d820308 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/lenovo/watchxplus/WatchXPlusDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/lenovo/watchxplus/WatchXPlusDeviceSupport.java @@ -1633,7 +1633,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { sample.setTimestamp(tsWithOffset); sample.setProvider(provider); sample.setRawIntensity(val); - sample.setRawKind(val == 0 ? ActivityKind.TYPE_DEEP_SLEEP : ActivityKind.TYPE_LIGHT_SLEEP); + sample.setRawKind((val == 0 ? ActivityKind.DEEP_SLEEP : ActivityKind.LIGHT_SLEEP).getCode()); samples.add(sample); overlayList.add(new WatchXPlusHealthActivityOverlay(sample.getTimestamp(), sample.getTimestamp()+300, sample.getRawKind(), sample.getDeviceId(), sample.getUserId(), sample.getRawWatchXPlusHealthData())); } @@ -1655,7 +1655,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { sample.setTimestamp(tsWithOffset); sample.setHeartRate(val); sample.setProvider(provider); - sample.setRawKind(ActivityKind.TYPE_ACTIVITY); + sample.setRawKind(ActivityKind.ACTIVITY.getCode()); samples.add(sample); } provider.addGBActivitySamples(samples.toArray(new WatchXPlusActivitySample[0])); @@ -1777,7 +1777,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { WatchXPlusActivitySample sample = createSample(dbHandler, timestamp); sample.setTimestamp(timestamp); // sample.setRawKind(record.type); - sample.setRawKind(ActivityKind.TYPE_ACTIVITY); + sample.setRawKind(ActivityKind.ACTIVITY.getCode()); sample.setSteps(newSteps); // sample.setDistance(record.distance); // sample.setCalories(record.calories); @@ -1846,7 +1846,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { timestamp, // ts deviceId, userId, // User id null, // Raw Data - ActivityKind.TYPE_UNKNOWN, // rawKind + ActivityKind.UNKNOWN.getCode(), // rawKind ActivitySample.NOT_MEASURED, // rawIntensity ActivitySample.NOT_MEASURED, // Steps ActivitySample.NOT_MEASURED, // HR 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 695f9b195..f06234a2d 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 @@ -580,12 +580,12 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement if (heartRate > 0) { sample.setHeartRate(heartRate); sample.setTimestamp((int) (System.currentTimeMillis() / 1000)); - sample.setRawKind(ActivityKind.TYPE_ACTIVITY); + sample.setRawKind(ActivityKind.ACTIVITY.getCode()); } else { if (heartRate == MakibesHR3Constants.ARG_HEARTRATE_NO_TARGET) { - sample.setRawKind(ActivityKind.TYPE_NOT_WORN); + sample.setRawKind(ActivityKind.NOT_WORN.getCode()); } else if (heartRate == MakibesHR3Constants.ARG_HEARTRATE_NO_READING) { - sample.setRawKind(ActivityKind.TYPE_NOT_MEASURED); + sample.setRawKind(ActivityKind.NOT_MEASURED.getCode()); } else { LOG.warn("invalid heart rate reading: " + heartRate); return; @@ -608,7 +608,7 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement sample.setHeartRate(heartRate); sample.setTimestamp(timeStamp); - sample.setRawKind(ActivityKind.TYPE_ACTIVITY); + sample.setRawKind(ActivityKind.ACTIVITY.getCode()); this.addGBActivitySample(sample); } @@ -622,12 +622,12 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement int newSteps = (steps - dayStepCount); if (newSteps > 0) { - LOG.debug("adding " + newSteps + " steps"); + LOG.debug("adding {} steps", newSteps); sample.setSteps(steps - dayStepCount); sample.setTimestamp(timeStamp); - sample.setRawKind(ActivityKind.TYPE_ACTIVITY); + sample.setRawKind(ActivityKind.ACTIVITY.getCode()); this.addGBActivitySample(sample); } @@ -637,7 +637,7 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement * The time is the start of the measurement. Each measurement lasts 1h. */ private void onReceiveStepsSample(int year, int month, int day, int hour, int minute, int steps) { - LOG.debug("received steps sample " + year + "-" + month + "-" + day + " " + hour + ":" + minute + " " + steps); + LOG.debug("received steps sample {}-{}-{} {}:{} {}", year, month, day, hour, minute, steps); Calendar calendar = new GregorianCalendar(year, month - 1, day, hour + 1, minute); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/no1f1/No1F1Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/no1f1/No1F1Support.java index 30159156c..e4bbf413d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/no1f1/No1F1Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/no1f1/No1F1Support.java @@ -484,7 +484,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport { private void handleActivityData(byte[] data) { if (data[1] == (byte) 0xfd) { - LOG.info("CRC received: " + (data[2] & 0xff) + ", calculated: " + (crc & 0xff)); + LOG.info("CRC received: {}, calculated: {}", data[2] & 0xff, crc & 0xff); if (data[2] != crc) { GB.toast(getContext(), "Incorrect CRC. Try fetching data again.", Toast.LENGTH_LONG, GB.ERROR); GB.updateTransferNotification(null,"Data transfer failed", false, 0, getContext()); @@ -492,7 +492,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport { getDevice().unsetBusyTask(); getDevice().sendDeviceUpdateIntent(getContext()); } - } else if (samples.size() > 0) { + } else if (!samples.isEmpty()) { try (DBHandler dbHandler = GBApplication.acquireDB()) { Long userId = DBHelper.getUser(dbHandler.getDaoSession()).getId(); Long deviceId = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession()).getId(); @@ -501,13 +501,13 @@ public class No1F1Support extends AbstractBTLEDeviceSupport { samples.get(i).setDeviceId(deviceId); samples.get(i).setUserId(userId); if (data[0] == No1F1Constants.CMD_FETCH_STEPS) { - samples.get(i).setRawKind(ActivityKind.TYPE_ACTIVITY); + samples.get(i).setRawKind(ActivityKind.ACTIVITY.getCode()); samples.get(i).setRawIntensity(samples.get(i).getSteps()); } else if (data[0] == No1F1Constants.CMD_FETCH_SLEEP) { if (samples.get(i).getRawIntensity() < 7) - samples.get(i).setRawKind(ActivityKind.TYPE_DEEP_SLEEP); + samples.get(i).setRawKind(ActivityKind.DEEP_SLEEP.getCode()); else - samples.get(i).setRawKind(ActivityKind.TYPE_LIGHT_SLEEP); + samples.get(i).setRawKind(ActivityKind.LIGHT_SLEEP.getCode()); } provider.addGBActivitySample(samples.get(i)); } @@ -542,15 +542,18 @@ public class No1F1Support extends AbstractBTLEDeviceSupport { if (data[0] == No1F1Constants.CMD_FETCH_STEPS) { timestamp.set(Calendar.MINUTE, 0); sample.setSteps(data[6] * 256 + (data[7] & 0xff)); + //noinspection lossy-conversions crc ^= (data[6] ^ data[7]); } else if (data[0] == No1F1Constants.CMD_FETCH_SLEEP) { timestamp.set(Calendar.MINUTE, data[6] & 0xff); sample.setRawIntensity(data[7] * 256 + (data[8] & 0xff)); + //noinspection lossy-conversions crc ^= (data[7] ^ data[8]); startProgress = 33; } else if (data[0] == No1F1Constants.CMD_FETCH_HEARTRATE) { timestamp.set(Calendar.MINUTE, data[6] & 0xff); sample.setHeartRate(data[7] & 0xff); + //noinspection lossy-conversions crc ^= (data[6] ^ data[7]); startProgress = 66; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pinetime/PineTimeJFSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pinetime/PineTimeJFSupport.java index 7498650e9..fd474ea99 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pinetime/PineTimeJFSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pinetime/PineTimeJFSupport.java @@ -1126,7 +1126,7 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL sample.setTimestamp(timeStamp); // since it's a local timestamp, it should NOT be treated as Activity because it will spoil activity charts - sample.setRawKind(ActivityKind.TYPE_UNKNOWN); + sample.setRawKind(ActivityKind.UNKNOWN.getCode()); this.addGBActivitySample(sample); @@ -1152,7 +1152,7 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL sample.setHeartRate(heartrate); sample.setTimestamp(timeStamp); // since it's a local timestamp, it should NOT be treated as Activity because it will spoil activity charts - sample.setRawKind(ActivityKind.TYPE_UNKNOWN); + sample.setRawKind(ActivityKind.UNKNOWN.getCode()); this.addGBActivitySample(sample); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/parser/ActivityEntry.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/parser/ActivityEntry.java index 7c46f0e4e..235225d0a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/parser/ActivityEntry.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/parser/ActivityEntry.java @@ -16,7 +16,6 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.parser; -import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; import nodomain.freeyourgadget.gadgetbridge.entities.HybridHRActivitySample; import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; @@ -35,7 +34,7 @@ public class ActivityEntry { public WEARING_STATE wearingState; public HybridHRActivitySample toDAOActivitySample(long userId, long deviceId) { - HybridHRActivitySample sample = new HybridHRActivitySample( + return new HybridHRActivitySample( timestamp, deviceId, userId, @@ -48,24 +47,22 @@ public class ActivityEntry { wearingState.value, heartRate ); - - return sample; } public enum WEARING_STATE{ - WEARING((byte) 0, ActivityKind.TYPE_NOT_MEASURED), - NOT_WEARING((byte) 1, ActivityKind.TYPE_NOT_WORN), - UNKNOWN((byte) 2, ActivityKind.TYPE_UNKNOWN); + WEARING((byte) 0, ActivityKind.NOT_MEASURED), + NOT_WEARING((byte) 1, ActivityKind.NOT_WORN), + UNKNOWN((byte) 2, ActivityKind.UNKNOWN); - byte value; - int activityKind; + final byte value; + final ActivityKind activityKind; - WEARING_STATE(byte value, int activityKind){ + WEARING_STATE(byte value, ActivityKind activityKind){ this.value = value; this.activityKind = activityKind; } - public int getActivityKind() { + public ActivityKind getActivityKind() { return activityKind; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/workout/WorkoutRequestHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/workout/WorkoutRequestHandler.java index 8b6300b6f..6e3879470 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/workout/WorkoutRequestHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/workout/WorkoutRequestHandler.java @@ -43,19 +43,15 @@ public class WorkoutRequestHandler { JSONObject workoutResponse = new JSONObject(); if (workoutRequest.optString("state").equals("started") && workoutRequest.optString("gps").equals("on")) { int activityType = workoutRequest.optInt("activity", -1); - final int activityKind; - if (QHybridConstants.WORKOUT_TYPES_TO_ACTIVITY_KIND.containsKey(activityType)) { - activityKind = QHybridConstants.WORKOUT_TYPES_TO_ACTIVITY_KIND.get(activityType); - } else { - activityKind = ActivityKind.TYPE_UNKNOWN; - } - LOG.info("Workout started, activity type is " + activityType + "/" + activityKind); + final ActivityKind activityKind = QHybridConstants.WORKOUT_TYPES_TO_ACTIVITY_KIND.getOrDefault(activityType, ActivityKind.UNKNOWN); + LOG.info("Workout started, activity type is {}/{}", activityType, activityKind); addStateResponse(workoutResponse, "success", ""); + //noinspection DataFlowIssue fp, never null OpenTracksController.startRecording(context, activityKind); } else if (workoutRequest.optString("type").equals("req_distance")) { long timeSecs = Math.round(GBApplication.app().getOpenTracksObserver().getTimeMillisChange() / 1000f); float distanceCM = GBApplication.app().getOpenTracksObserver().getDistanceMeterChange() * 100; - LOG.info("Workout distance requested, returning " + distanceCM + " cm, " + timeSecs + " sec"); + LOG.info("Workout distance requested, returning {} cm, {} sec", distanceCM, timeSecs); workoutResponse.put("workoutApp._.config.gps", new JSONObject() .put("distance", distanceCM) .put("duration", timeSecs) @@ -85,4 +81,4 @@ public class WorkoutRequestHandler { } return workoutResponse; } -} \ No newline at end of file +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/tlw64/TLW64Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/tlw64/TLW64Support.java index 18867baa5..5c3f3ff81 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/tlw64/TLW64Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/tlw64/TLW64Support.java @@ -19,7 +19,6 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.tlw64; import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGattCharacteristic; -import android.net.Uri; import android.text.format.DateFormat; import android.widget.Toast; @@ -49,13 +48,8 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser; import nodomain.freeyourgadget.gadgetbridge.model.Alarm; -import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec; import nodomain.freeyourgadget.gadgetbridge.model.CallSpec; -import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec; -import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec; -import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; -import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec; import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAction; @@ -514,7 +508,7 @@ public class TLW64Support extends AbstractBTLEDeviceSupport { private void handleActivityData(byte[] data) { if (data[1] == (byte) 0xfd) { - LOG.info("CRC received: " + (data[2] & 0xff) + ", calculated: " + (crc & 0xff)); + LOG.info("CRC received: {}, calculated: {}", data[2] & 0xff, crc & 0xff); if (data[2] != crc) { GB.toast(getContext(), "Incorrect CRC. Try fetching data again.", Toast.LENGTH_LONG, GB.ERROR); GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext()); @@ -522,7 +516,7 @@ public class TLW64Support extends AbstractBTLEDeviceSupport { getDevice().unsetBusyTask(); getDevice().sendDeviceUpdateIntent(getContext()); } - } else if (samples.size() > 0) { + } else if (!samples.isEmpty()) { try (DBHandler dbHandler = GBApplication.acquireDB()) { Long userId = DBHelper.getUser(dbHandler.getDaoSession()).getId(); Long deviceId = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession()).getId(); @@ -531,13 +525,13 @@ public class TLW64Support extends AbstractBTLEDeviceSupport { samples.get(i).setDeviceId(deviceId); samples.get(i).setUserId(userId); if (data[0] == TLW64Constants.CMD_FETCH_STEPS) { - samples.get(i).setRawKind(ActivityKind.TYPE_ACTIVITY); + samples.get(i).setRawKind(ActivityKind.ACTIVITY.getCode()); samples.get(i).setRawIntensity(samples.get(i).getSteps()); } else if (data[0] == TLW64Constants.CMD_FETCH_SLEEP) { if (samples.get(i).getRawIntensity() < 7) { - samples.get(i).setRawKind(ActivityKind.TYPE_DEEP_SLEEP); + samples.get(i).setRawKind(ActivityKind.DEEP_SLEEP.getCode()); } else - samples.get(i).setRawKind(ActivityKind.TYPE_LIGHT_SLEEP); + samples.get(i).setRawKind(ActivityKind.LIGHT_SLEEP.getCode()); } provider.addGBActivitySample(samples.get(i)); } @@ -571,10 +565,12 @@ public class TLW64Support extends AbstractBTLEDeviceSupport { if (data[0] == TLW64Constants.CMD_FETCH_STEPS) { timestamp.set(Calendar.MINUTE, 0); sample.setSteps(data[6] * 256 + (data[7] & 0xff)); + //noinspection lossy-conversions crc ^= (data[6] ^ data[7]); } else if (data[0] == TLW64Constants.CMD_FETCH_SLEEP) { timestamp.set(Calendar.MINUTE, data[6] & 0xff); sample.setRawIntensity(data[7] * 256 + (data[8] & 0xff)); + //noinspection lossy-conversions crc ^= (data[7] ^ data[8]); startProgress = 33; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/WithingsSteelHRDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/WithingsSteelHRDeviceSupport.java index c9a7588a0..997067b24 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/WithingsSteelHRDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/WithingsSteelHRDeviceSupport.java @@ -699,7 +699,7 @@ public class WithingsSteelHRDeviceSupport extends AbstractBTLEDeviceSupport { message.addDataStructure(imageMetaData); ImageData imageData = new ImageData(); - final int drawableId = ActivityKind.getIconId(withingsActivityType.toActivityKind()); + final int drawableId = withingsActivityType.toActivityKind().getIcon(); Drawable drawable = getContext().getDrawable(drawableId); imageData.setImageData(IconHelper.getIconBytesFromDrawable(drawable)); message.addDataStructure(imageData); @@ -719,7 +719,7 @@ public class WithingsSteelHRDeviceSupport extends AbstractBTLEDeviceSupport { String localeString = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()) .getString(PREF_LANGUAGE, PREF_LANGUAGE_AUTO); - if (localeString == null || localeString.equals(PREF_LANGUAGE_AUTO)) { + if (localeString.equals(PREF_LANGUAGE_AUTO)) { localeString = java.util.Locale.getDefault().getLanguage(); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/activity/SleepActivitySampleHelper.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/activity/SleepActivitySampleHelper.java index 4c5e3e28f..8bde32bbf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/activity/SleepActivitySampleHelper.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/activity/SleepActivitySampleHelper.java @@ -16,9 +16,6 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.service.devices.withingssteelhr.activity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.List; import nodomain.freeyourgadget.gadgetbridge.devices.withingssteelhr.WithingsSteelHRSampleProvider; @@ -30,10 +27,6 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; * This leads to breaking the sleep session in the sleep calculation of GB. */ public class SleepActivitySampleHelper { - - private static Logger logger = LoggerFactory.getLogger(SleepActivitySampleHelper.class); - private static int mergeCount; - public static WithingsSteelHRActivitySample mergeIfNecessary(WithingsSteelHRSampleProvider provider, WithingsSteelHRActivitySample sample) { if (!shouldMerge(sample)) { return sample; @@ -55,7 +48,7 @@ public class SleepActivitySampleHelper { for (int i = samples.size()-1; i >= 0; i--) { WithingsSteelHRActivitySample lastSample = samples.get(i); - if (isNotHeartRateOnly(lastSample, (int) timestamp)) { + if (isNotHeartRateOnly(lastSample)) { return lastSample; } } @@ -63,8 +56,8 @@ public class SleepActivitySampleHelper { return null; } - private static boolean isNotHeartRateOnly(WithingsSteelHRActivitySample lastSample, int timestamp) { - return lastSample.getRawKind() != ActivityKind.TYPE_NOT_MEASURED; // && lastSample.getTimestamp() <= timestamp && (lastSample.getTimestamp() + lastSample.getDuration()) >= timestamp); + private static boolean isNotHeartRateOnly(WithingsSteelHRActivitySample lastSample) { + return lastSample.getRawKind() != ActivityKind.NOT_MEASURED.getCode(); // && lastSample.getTimestamp() <= timestamp && (lastSample.getTimestamp() + lastSample.getDuration()) >= timestamp); } private static boolean shouldMerge(WithingsSteelHRActivitySample sample) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/activity/WithingsActivityType.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/activity/WithingsActivityType.java index 68ce92da5..3ea2eb0bb 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/activity/WithingsActivityType.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/activity/WithingsActivityType.java @@ -61,7 +61,7 @@ public enum WithingsActivityType { RIDING(26), OTHER(36); - private int code; + private final int code; WithingsActivityType(int typeCode) { this.code = typeCode; @@ -80,80 +80,80 @@ public enum WithingsActivityType { return code; } - public int toActivityKind() { + public ActivityKind toActivityKind() { switch (this) { case WALKING: - return ActivityKind.TYPE_WALKING; + return ActivityKind.WALKING; case RUNNING: - return ActivityKind.TYPE_RUNNING; + return ActivityKind.RUNNING; case HIKING: - return ActivityKind.TYPE_HIKING; + return ActivityKind.HIKING; case BIKING: - return ActivityKind.TYPE_CYCLING; + return ActivityKind.CYCLING; case SWIMMING: - return ActivityKind.TYPE_SWIMMING; + return ActivityKind.SWIMMING; case SURFING: - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; case KITESURFING: - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; case WINDSURFING: - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; case TENNIS: - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; case PINGPONG: - return ActivityKind.TYPE_PINGPONG; + return ActivityKind.PINGPONG; case SQUASH: - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; case BADMINTON: - return ActivityKind.TYPE_BADMINTON; + return ActivityKind.BADMINTON; case WEIGHTLIFTING: - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; case GYMNASTICS: - return ActivityKind.TYPE_EXERCISE; + return ActivityKind.EXERCISE; case ELLIPTICAL: - return ActivityKind.TYPE_ELLIPTICAL_TRAINER; + return ActivityKind.ELLIPTICAL_TRAINER; case PILATES: - return ActivityKind.TYPE_YOGA; + return ActivityKind.YOGA; case BASKETBALL: - return ActivityKind.TYPE_BASKETBALL; + return ActivityKind.BASKETBALL; case SOCCER: - return ActivityKind.TYPE_SOCCER; + return ActivityKind.SOCCER; case FOOTBALL: - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; case RUGBY: - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; case VOLLEYBALL: - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; case GOLFING: - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; case YOGA: - return ActivityKind.TYPE_YOGA; + return ActivityKind.YOGA; case DANCING: - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; case BOXING: - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; case SKIING: - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; case SNOWBOARDING: - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; case ROWING: - return ActivityKind.TYPE_ROWING_MACHINE; + return ActivityKind.ROWING_MACHINE; case ZUMBA: - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; case BASEBALL: - return ActivityKind.TYPE_CRICKET; + return ActivityKind.CRICKET; case HANDBALL: - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; case HOCKEY: - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; case ICEHOCKEY: - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; case CLIMBING: - return ActivityKind.TYPE_CLIMBING; + return ActivityKind.CLIMBING; case ICESKATING: - return ActivityKind.TYPE_ACTIVITY; + return ActivityKind.ACTIVITY; default: - return ActivityKind.TYPE_UNKNOWN; + return ActivityKind.UNKNOWN; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/communication/conversation/ActivitySampleHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/communication/conversation/ActivitySampleHandler.java index 76969c9b0..dbbe0ec44 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/communication/conversation/ActivitySampleHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/communication/conversation/ActivitySampleHandler.java @@ -59,7 +59,7 @@ public class ActivitySampleHandler extends AbstractResponseHandler { @Override public void handleResponse(Message response) { List data = response.getDataStructures(); - if (data != null) { + if (data != null) { handleActivityData(data, response.getType()); } } @@ -106,7 +106,7 @@ public class ActivitySampleHandler extends AbstractResponseHandler { handleWorkoutType(data); break; default: - logger.info("Received yet unhandled activity data of type '" + data.getType() + "' with data '" + GB.hexdump(data.getRawData()) + "'."); + logger.info("Received yet unhandled activity data of type '{}' with data '{}'.", data.getType(), GB.hexdump(data.getRawData())); } } @@ -123,71 +123,71 @@ public class ActivitySampleHandler extends AbstractResponseHandler { activityEntry = new ActivityEntry(); activityEntry.setIsHeartrate(activityType == WithingsMessageType.GET_HEARTRATE_SAMPLES); - activityEntry.setTimestamp((int)(((ActivitySampleTime)data).getDate().getTime()/1000)); + activityEntry.setTimestamp((int) (((ActivitySampleTime) data).getDate().getTime() / 1000)); } private void handleWorkoutType(WithingsStructure data) { - WithingsActivityType activityType = WithingsActivityType.fromCode(((WorkoutType)data).getActivityType()); - activityEntry.setRawKind(activityType.toActivityKind()); + WithingsActivityType activityType = WithingsActivityType.fromCode(((WorkoutType) data).getActivityType()); + activityEntry.setRawKind(activityType.toActivityKind().getCode()); } private void handleDuration(WithingsStructure data) { - activityEntry.setDuration(((ActivitySampleDuration)data).getDuration()); + activityEntry.setDuration(((ActivitySampleDuration) data).getDuration()); } private void handleHeartrate(WithingsStructure data) { - activityEntry.setIsHeartrate(((ActivityHeartrate)data).getHeartrate()); + activityEntry.setIsHeartrate(((ActivityHeartrate) data).getHeartrate()); } private void handleMovement(WithingsStructure data) { - activityEntry.setRawKind(ActivityKind.TYPE_UNKNOWN); - activityEntry.setSteps(((ActivitySampleMovement)data).getSteps()); - activityEntry.setDistance(((ActivitySampleMovement)data).getDistance()); + activityEntry.setRawKind(ActivityKind.UNKNOWN.getCode()); + activityEntry.setSteps(((ActivitySampleMovement) data).getSteps()); + activityEntry.setDistance(((ActivitySampleMovement) data).getDistance()); } private void handleWalk(WithingsStructure data) { - activityEntry.setRawKind(ActivityKind.TYPE_WALKING); + activityEntry.setRawKind(ActivityKind.WALKING.getCode()); } private void handleRun(WithingsStructure data) { - activityEntry.setRawKind(ActivityKind.TYPE_RUNNING); + activityEntry.setRawKind(ActivityKind.RUNNING.getCode()); } private void handleSwim(WithingsStructure data) { - activityEntry.setRawKind(ActivityKind.TYPE_SWIMMING); + activityEntry.setRawKind(ActivityKind.SWIMMING.getCode()); } private void handleSleep(WithingsStructure data) { - int sleepType; - switch (((ActivitySampleSleep)data).getSleepType()) { + ActivityKind sleepType; + switch (((ActivitySampleSleep) data).getSleepType()) { case 0: - sleepType = ActivityKind.TYPE_LIGHT_SLEEP; + sleepType = ActivityKind.LIGHT_SLEEP; activityEntry.setRawIntensity(10); break; case 2: - sleepType = ActivityKind.TYPE_DEEP_SLEEP; + sleepType = ActivityKind.DEEP_SLEEP; activityEntry.setRawIntensity(70); break; case 3: - sleepType = ActivityKind.TYPE_REM_SLEEP; + sleepType = ActivityKind.REM_SLEEP; activityEntry.setRawIntensity(80); break; default: - sleepType = ActivityKind.TYPE_LIGHT_SLEEP; + sleepType = ActivityKind.LIGHT_SLEEP; activityEntry.setRawIntensity(50); } - activityEntry.setRawKind(sleepType); + activityEntry.setRawKind(sleepType.getCode()); } private void handleCalories1(WithingsStructure data) { - activityEntry.setRawIntensity(((ActivitySampleCalories)data).getMet()); - activityEntry.setCalories(((ActivitySampleCalories)data).getCalories()); + activityEntry.setRawIntensity(((ActivitySampleCalories) data).getMet()); + activityEntry.setCalories(((ActivitySampleCalories) data).getCalories()); } private void handleCalories2(WithingsStructure data) { - activityEntry.setRawIntensity(((ActivitySampleCalories2)data).getMet()); - activityEntry.setCalories(((ActivitySampleCalories2)data).getCalories()); + activityEntry.setRawIntensity(((ActivitySampleCalories2) data).getMet()); + activityEntry.setCalories(((ActivitySampleCalories2) data).getCalories()); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/communication/message/incoming/LiveWorkoutHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/communication/message/incoming/LiveWorkoutHandler.java index d11745606..16c042905 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/communication/message/incoming/LiveWorkoutHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/communication/message/incoming/LiveWorkoutHandler.java @@ -119,7 +119,7 @@ public class LiveWorkoutHandler implements IncomingMessageHandler { baseActivitySummary = new BaseActivitySummary(); } - baseActivitySummary.setActivityKind(withingsWorkoutType.toActivityKind()); + baseActivitySummary.setActivityKind(withingsWorkoutType.toActivityKind().getCode()); } private void sendGpsState() { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/XiaomiActivityParser.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/XiaomiActivityParser.java index 2143377ef..801cd2783 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/XiaomiActivityParser.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/XiaomiActivityParser.java @@ -62,7 +62,7 @@ public abstract class XiaomiActivityParser { // These will be set later, once we parse the summary summary.setEndTime(fileId.getTimestamp()); - summary.setActivityKind(ActivityKind.TYPE_UNKNOWN); + summary.setActivityKind(ActivityKind.UNKNOWN.getCode()); return summary; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/WorkoutGpsParser.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/WorkoutGpsParser.java index 6d9253593..a3e5d5c71 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/WorkoutGpsParser.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/WorkoutGpsParser.java @@ -111,7 +111,7 @@ public class WorkoutGpsParser extends XiaomiActivityParser { // Set the info on the activity track activityTrack.setUser(user); activityTrack.setDevice(device); - activityTrack.setName(ActivityKind.asString(summary.getActivityKind(), support.getContext())); + activityTrack.setName(ActivityKind.fromCode(summary.getActivityKind()).getLabel(support.getContext())); // Save the raw bytes final String rawBytesPath = saveRawBytes(fileId, bytes); @@ -149,6 +149,7 @@ public class WorkoutGpsParser extends XiaomiActivityParser { private String saveRawBytes(final XiaomiActivityFileId fileId, final byte[] bytes) { try { final File targetFolder = new File(FileUtils.getExternalFilesDir(), "rawDetails"); + //noinspection ResultOfMethodCallIgnored targetFolder.mkdirs(); final File targetFile = new File(targetFolder, fileId.getFilename()); FileOutputStream outputStream = new FileOutputStream(targetFile); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/WorkoutSummaryParser.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/WorkoutSummaryParser.java index 81d62215a..63cd06c3a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/WorkoutSummaryParser.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/WorkoutSummaryParser.java @@ -100,7 +100,7 @@ public class WorkoutSummaryParser extends XiaomiActivityParser implements Activi summary.setStartTime(fileId.getTimestamp()); // due to a bug this has to be set summary.setEndTime(fileId.getTimestamp()); // due to a bug this has to be set - summary.setActivityKind(ActivityKind.TYPE_UNKNOWN); + summary.setActivityKind(ActivityKind.UNKNOWN.getCode()); summary.setRawSummaryData(bytes); try { @@ -172,31 +172,31 @@ public class WorkoutSummaryParser extends XiaomiActivityParser implements Activi switch (fileId.getSubtype()) { case SPORTS_OUTDOOR_WALKING_V1: - summary.setActivityKind(ActivityKind.TYPE_WALKING); + summary.setActivityKind(ActivityKind.WALKING.getCode()); parser = getOutdoorWalkingV1Parser(fileId); break; case SPORTS_OUTDOOR_RUNNING: - summary.setActivityKind(ActivityKind.TYPE_RUNNING); + summary.setActivityKind(ActivityKind.RUNNING.getCode()); parser = getOutdoorWalkingV1Parser(fileId); break; case SPORTS_INDOOR_CYCLING: - summary.setActivityKind(ActivityKind.TYPE_INDOOR_CYCLING); + summary.setActivityKind(ActivityKind.INDOOR_CYCLING.getCode()); parser = getIndoorCyclingParser(fileId); break; case SPORTS_FREESTYLE: - summary.setActivityKind(ActivityKind.TYPE_STRENGTH_TRAINING); + summary.setActivityKind(ActivityKind.STRENGTH_TRAINING.getCode()); parser = getFreestyleParser(fileId); break; case SPORTS_POOL_SWIMMING: - summary.setActivityKind(ActivityKind.TYPE_SWIMMING); + summary.setActivityKind(ActivityKind.SWIMMING.getCode()); parser = getPoolSwimmingParser(fileId); break; case SPORTS_HIIT: - summary.setActivityKind(ActivityKind.TYPE_EXERCISE); + summary.setActivityKind(ActivityKind.EXERCISE.getCode()); parser = getHiitParser(fileId); break; case SPORTS_ELLIPTICAL: - summary.setActivityKind(ActivityKind.TYPE_ELLIPTICAL_TRAINER); + summary.setActivityKind(ActivityKind.ELLIPTICAL_TRAINER.getCode()); // TODO break; case SPORTS_OUTDOOR_WALKING_V2: diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/XiaomiSimpleActivityParser.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/XiaomiSimpleActivityParser.java index 2a0e85a72..a37b01d42 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/XiaomiSimpleActivityParser.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/XiaomiSimpleActivityParser.java @@ -102,13 +102,13 @@ public class XiaomiSimpleActivityParser { // TODO use XiaomiWorkoutType switch (value.intValue()) { case 2: - summary.setActivityKind(ActivityKind.TYPE_WALKING); + summary.setActivityKind(ActivityKind.WALKING.getCode()); break; case 6: - summary.setActivityKind(ActivityKind.TYPE_CYCLING); + summary.setActivityKind(ActivityKind.CYCLING.getCode()); break; default: - summary.setActivityKind(ActivityKind.TYPE_UNKNOWN); + summary.setActivityKind(ActivityKind.UNKNOWN.getCode()); } } else { summaryData.add(dataEntry.getKey(), value.floatValue(), dataEntry.getUnit()); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiHealthService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiHealthService.java index 66b12f8ed..c8f695d50 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiHealthService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiHealthService.java @@ -752,23 +752,23 @@ public class XiaomiHealthService extends AbstractXiaomiService { } } - private int sportToActivityKind(final int sport) { + private ActivityKind sportToActivityKind(final int sport) { switch (sport) { case 1: // outdoor run case 5: // trail run - return ActivityKind.TYPE_RUNNING; + return ActivityKind.RUNNING; case 2: - return ActivityKind.TYPE_WALKING; + return ActivityKind.WALKING; case 3: // hiking case 4: // trekking - return ActivityKind.TYPE_HIKING; + return ActivityKind.HIKING; case 6: - return ActivityKind.TYPE_CYCLING; + return ActivityKind.CYCLING; } LOG.warn("Unknown sport {}", sport); - return ActivityKind.TYPE_UNKNOWN; + return ActivityKind.UNKNOWN; } public XiaomiActivityFileFetcher getActivityFetcher() { @@ -931,10 +931,10 @@ public class XiaomiHealthService extends AbstractXiaomiService { sample.setTimestamp(ts); sample.setHeartRate(realTimeStats.getHeartRate()); sample.setSteps(realTimeStats.getSteps() - previousSteps); - sample.setRawKind(ActivityKind.TYPE_UNKNOWN); + sample.setRawKind(ActivityKind.UNKNOWN.getCode()); sample.setHeartRate(realTimeStats.getHeartRate()); sample.setRawIntensity(ActivitySample.NOT_MEASURED); - sample.setRawKind(ActivityKind.TYPE_UNKNOWN); + sample.setRawKind(ActivityKind.UNKNOWN.getCode()); } catch (final Exception e) { LOG.error("Error creating activity sample", e); return; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xwatch/XWatchSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xwatch/XWatchSupport.java index 1058bffdf..bda8fa765 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xwatch/XWatchSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xwatch/XWatchSupport.java @@ -359,7 +359,7 @@ public class XWatchSupport extends AbstractBTLEDeviceSupport { value[5] ); - category = ActivityKind.TYPE_ACTIVITY; + category = ActivityKind.ACTIVITY.getCode(); intensity = (value[7] & 255) + ((value[8] & 255) << 8); steps = (value[9] & 255) + ((value[10] & 255) << 8); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/zetime/ZeTimeDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/zetime/ZeTimeDeviceSupport.java index 7808ac42a..cbe08bbaa 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/zetime/ZeTimeDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/zetime/ZeTimeDeviceSupport.java @@ -1152,7 +1152,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport { sample.setCaloriesBurnt((msg[18] << 24) & 0xff000000 | (msg[17] << 16) & 0xff0000 | (msg[16] << 8) & 0xff00 | (msg[15] & 0xff)); sample.setDistanceMeters((msg[22] << 24) & 0xff000000 | (msg[21] << 16) & 0xff0000 | (msg[20] << 8) & 0xff00 | (msg[19] & 0xff)); sample.setActiveTimeMinutes((msg[26] << 24) & 0xff000000 | (msg[25] << 16) & 0xff0000 | (msg[24] << 8) & 0xff00 | (msg[23] & 0xff)); - sample.setRawKind(ActivityKind.TYPE_ACTIVITY); + sample.setRawKind(ActivityKind.ACTIVITY.getCode()); sample.setRawIntensity(sample.getSteps()); try (DBHandler dbHandler = GBApplication.acquireDB()) { @@ -1195,11 +1195,11 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport { timestamp -= ((now.get(Calendar.ZONE_OFFSET) / 1000) + (now.get(Calendar.DST_OFFSET) / 1000)); // TimeZone hour + daylight saving sample.setTimestamp(timestamp); if (msg[11] == 0) { - sample.setRawKind(ActivityKind.TYPE_DEEP_SLEEP); + sample.setRawKind(ActivityKind.DEEP_SLEEP.getCode()); } else if (msg[11] == 1) { - sample.setRawKind(ActivityKind.TYPE_LIGHT_SLEEP); + sample.setRawKind(ActivityKind.LIGHT_SLEEP.getCode()); } else { - sample.setRawKind(ActivityKind.TYPE_UNKNOWN); + sample.setRawKind(ActivityKind.UNKNOWN.getCode()); } try (DBHandler dbHandler = GBApplication.acquireDB()) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GB.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GB.java index 8036c01e8..a20e84a76 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GB.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GB.java @@ -220,7 +220,7 @@ public class GB { builder.addAction(R.drawable.ic_notification_disconnected, context.getString(R.string.controlcenter_disconnect), disconnectPendingIntent); if (device.getDeviceCoordinator().supportsActivityDataFetching()) { deviceCommunicationServiceIntent.setAction(DeviceService.ACTION_FETCH_RECORDED_DATA); - deviceCommunicationServiceIntent.putExtra(EXTRA_RECORDED_DATA_TYPES, ActivityKind.TYPE_ACTIVITY); + deviceCommunicationServiceIntent.putExtra(EXTRA_RECORDED_DATA_TYPES, ActivityKind.ACTIVITY); PendingIntent fetchPendingIntent = PendingIntentUtils.getService(context, 1, deviceCommunicationServiceIntent, PendingIntent.FLAG_ONE_SHOT, false); builder.addAction(R.drawable.ic_refresh, context.getString(R.string.controlcenter_fetch_activity_data), fetchPendingIntent); } @@ -269,7 +269,7 @@ public class GB { Intent deviceCommunicationServiceIntent = new Intent(context, DeviceCommunicationService.class); deviceCommunicationServiceIntent.setPackage(BuildConfig.APPLICATION_ID); deviceCommunicationServiceIntent.setAction(DeviceService.ACTION_FETCH_RECORDED_DATA); - deviceCommunicationServiceIntent.putExtra(EXTRA_RECORDED_DATA_TYPES, ActivityKind.TYPE_ACTIVITY); + deviceCommunicationServiceIntent.putExtra(EXTRA_RECORDED_DATA_TYPES, ActivityKind.ACTIVITY); PendingIntent fetchPendingIntent = PendingIntentUtils.getService(context, 1, deviceCommunicationServiceIntent, PendingIntent.FLAG_ONE_SHOT, false); builder.addAction(R.drawable.ic_refresh, context.getString(R.string.controlcenter_fetch_activity_data), fetchPendingIntent); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d98e8bccb..4bc4978fd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -965,6 +965,7 @@ - Lowest HR Highest HR + Transition %1$s - %2$s You did not sleep Lowest heart rate: %1$d \nHighest heart rate: %2$d \nMovement intensity: %3$s diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/database/SampleProviderTest.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/database/SampleProviderTest.java index 77a8bb1bb..bb9e5f173 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/database/SampleProviderTest.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/database/SampleProviderTest.java @@ -44,17 +44,17 @@ public class SampleProviderTest extends TestBase { @Test public void testActivityKind() { MiBandSampleProvider sampleProvider = new MiBandSampleProvider(dummyGBDevice, daoSession); - int type = sampleProvider.normalizeType(MiBandSampleProvider.TYPE_ACTIVITY); - assertEquals(ActivityKind.TYPE_ACTIVITY, type); + ActivityKind type = sampleProvider.normalizeType(MiBandSampleProvider.TYPE_ACTIVITY); + assertEquals(ActivityKind.ACTIVITY, type); type = sampleProvider.normalizeType(MiBandSampleProvider.TYPE_DEEP_SLEEP); - assertEquals(ActivityKind.TYPE_DEEP_SLEEP, type); + assertEquals(ActivityKind.DEEP_SLEEP, type); type = sampleProvider.normalizeType(MiBandSampleProvider.TYPE_LIGHT_SLEEP); - assertEquals(ActivityKind.TYPE_LIGHT_SLEEP, type); + assertEquals(ActivityKind.LIGHT_SLEEP, type); type = sampleProvider.normalizeType(MiBandSampleProvider.TYPE_NONWEAR); - assertEquals(ActivityKind.TYPE_NOT_WORN, type); + assertEquals(ActivityKind.NOT_WORN, type); } @Test @@ -78,16 +78,6 @@ public class SampleProviderTest extends TestBase { samples = sampleProvider.getActivitySamples(1, -1); assertEquals(0, samples.size()); - - // and sleep - samples = sampleProvider.getSleepSamples(0, 0); - assertEquals(0, samples.size()); - - samples = sampleProvider.getSleepSamples(-1, 1); - assertEquals(0, samples.size()); - - samples = sampleProvider.getSleepSamples(1, -1); - assertEquals(0, samples.size()); } private T createSample(SampleProvider sampleProvider, int rawKind, int timestamp, int rawIntensity, int heartRate, int steps, User user, Device device) { @@ -144,30 +134,16 @@ public class SampleProviderTest extends TestBase { samples = sampleProvider.getActivitySamples(1, -1); assertEquals(0, samples.size()); - // and sleep - samples = sampleProvider.getSleepSamples(0, 0); - assertEquals(0, samples.size()); - - samples = sampleProvider.getSleepSamples(-1, 1); - assertEquals(0, samples.size()); - - samples = sampleProvider.getSleepSamples(1, -1); - assertEquals(0, samples.size()); - // finally checks for existing timestamps List allSamples = sampleProvider.getAllActivitySamples(0, 10000); assertEquals(4, allSamples.size()); List activitySamples = sampleProvider.getActivitySamples(0, 10000); assertEquals(2, activitySamples.size()); - List sleepSamples = sampleProvider.getSleepSamples(0, 10000); - assertEquals(2, sleepSamples.size()); // now with more strict time ranges allSamples = sampleProvider.getAllActivitySamples(0, 1300); assertEquals(3, allSamples.size()); activitySamples = sampleProvider.getActivitySamples(10, 150); assertEquals(1, activitySamples.size()); - sleepSamples = sampleProvider.getSleepSamples(1500, 2500); - assertEquals(1, sleepSamples.size()); } } diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityKindTest.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityKindTest.java new file mode 100644 index 000000000..269a7df56 --- /dev/null +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityKindTest.java @@ -0,0 +1,20 @@ +package nodomain.freeyourgadget.gadgetbridge.model; + +import static org.junit.Assert.assertNull; + +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +public class ActivityKindTest { + @Test + public void enumCheckNoOverlap() { + // Ensure that no 2 activity kind overlap in codes + final Map knownCodes = new HashMap<>(); + for (final ActivityKind kind : ActivityKind.values()) { + final Boolean existingCode = knownCodes.put(kind.getCode(), true); + assertNull("ActivityKind with overlapping codes: " + kind, existingCode); + } + } +}