Properly check support for heartrate measurements
This commit is contained in:
parent
8772631087
commit
45fa930ac3
|
@ -84,7 +84,6 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
|||
}
|
||||
};
|
||||
private boolean mChartDirty = true;
|
||||
private boolean supportsHeartrateChart = true;
|
||||
private AsyncTask refreshTask;
|
||||
|
||||
public boolean isChartDirty() {
|
||||
|
@ -93,8 +92,9 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
|||
|
||||
public abstract String getTitle();
|
||||
|
||||
public boolean supportsHeartrate() {
|
||||
return supportsHeartrateChart;
|
||||
public boolean supportsHeartrate(GBDevice device) {
|
||||
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
||||
return coordinator != null && coordinator.supportsHeartRateMeasurement(device);
|
||||
}
|
||||
|
||||
protected static final class ActivityConfig {
|
||||
|
@ -420,7 +420,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
|||
int numEntries = samples.size();
|
||||
List<String> xLabels = new ArrayList<>(numEntries);
|
||||
List<BarEntry> activityEntries = new ArrayList<>(numEntries);
|
||||
boolean hr = supportsHeartrate();
|
||||
boolean hr = supportsHeartrate(gbDevice);
|
||||
List<Entry> heartrateEntries = hr ? new ArrayList<Entry>(numEntries) : null;
|
||||
List<Integer> colors = new ArrayList<>(numEntries); // this is kinda inefficient...
|
||||
int lastHrSampleIndex = -1;
|
||||
|
|
|
@ -80,7 +80,7 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
|
|||
|
||||
YAxis yAxisRight = mChart.getAxisRight();
|
||||
yAxisRight.setDrawGridLines(false);
|
||||
yAxisRight.setEnabled(supportsHeartrate());
|
||||
yAxisRight.setEnabled(supportsHeartrate(getChartsHost().getDevice()));
|
||||
yAxisRight.setDrawLabels(true);
|
||||
yAxisRight.setDrawTopYLabelEntry(true);
|
||||
yAxisRight.setTextColor(CHART_TEXT_COLOR);
|
||||
|
@ -134,7 +134,7 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
|
|||
legendLabels.add(akDeepSleep.label);
|
||||
legendColors.add(akNotWorn.color);
|
||||
legendLabels.add(akNotWorn.label);
|
||||
if (supportsHeartrate()) {
|
||||
if (supportsHeartrate(getChartsHost().getDevice())) {
|
||||
legendColors.add(HEARTRATE_COLOR);
|
||||
legendLabels.add(HEARTRATE_LABEL);
|
||||
}
|
||||
|
|
|
@ -171,7 +171,7 @@ public class SleepChartFragment extends AbstractChartFragment {
|
|||
|
||||
YAxis yAxisRight = mActivityChart.getAxisRight();
|
||||
yAxisRight.setDrawGridLines(false);
|
||||
yAxisRight.setEnabled(supportsHeartrate());
|
||||
yAxisRight.setEnabled(supportsHeartrate(getChartsHost().getDevice()));
|
||||
yAxisRight.setDrawLabels(true);
|
||||
yAxisRight.setDrawTopYLabelEntry(true);
|
||||
yAxisRight.setTextColor(CHART_TEXT_COLOR);
|
||||
|
@ -186,7 +186,7 @@ public class SleepChartFragment extends AbstractChartFragment {
|
|||
legendLabels.add(akLightSleep.label);
|
||||
legendColors.add(akDeepSleep.color);
|
||||
legendLabels.add(akDeepSleep.label);
|
||||
if (supportsHeartrate()) {
|
||||
if (supportsHeartrate(getChartsHost().getDevice())) {
|
||||
legendColors.add(HEARTRATE_COLOR);
|
||||
legendLabels.add(HEARTRATE_LABEL);
|
||||
}
|
||||
|
|
|
@ -112,6 +112,12 @@ public interface DeviceCoordinator {
|
|||
*/
|
||||
boolean supportsAlarmConfiguration();
|
||||
|
||||
/**
|
||||
* Returns true if the given device supports heart rate measurements.
|
||||
* @return
|
||||
*/
|
||||
boolean supportsHeartRateMeasurement(GBDevice device);
|
||||
|
||||
int getTapString();
|
||||
|
||||
/**
|
||||
|
|
|
@ -135,6 +135,11 @@ public class UnknownDeviceCoordinator extends AbstractDeviceCoordinator {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsHeartRateMeasurement(GBDevice device) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTapString() {
|
||||
return 0;
|
||||
|
|
|
@ -166,4 +166,18 @@ public class MiBandCoordinator extends AbstractDeviceCoordinator {
|
|||
Prefs prefs = GBApplication.getPrefs();
|
||||
return prefs.getInt(MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsHeartRateMeasurement(GBDevice device) {
|
||||
String hwVersion = device.getHardwareVersion();
|
||||
return isMi1S(hwVersion) || isMiPro(hwVersion);
|
||||
}
|
||||
|
||||
private boolean isMi1S(String hardwareVersion) {
|
||||
return MiBandConst.MI_1S.equals(hardwareVersion);
|
||||
}
|
||||
|
||||
private boolean isMiPro(String hardwareVersion) {
|
||||
return MiBandConst.MI_PRO.equals(hardwareVersion);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,6 +84,11 @@ public class PebbleCoordinator extends AbstractDeviceCoordinator {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsHeartRateMeasurement(GBDevice device) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTapString() {
|
||||
return R.string.tap_connected_device_for_app_mananger;
|
||||
|
|
Loading…
Reference in New Issue