mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-26 03:46:49 +01:00
Add setting heart rate alarm values. Make the settings of the wearside and screen on duration interactive - give them their own activity. Also make the auto heart rate measurement work.
This commit is contained in:
parent
59a73d47af
commit
6617c45fec
@ -61,6 +61,10 @@
|
|||||||
android:name=".devices.miband.MiBandPreferencesActivity"
|
android:name=".devices.miband.MiBandPreferencesActivity"
|
||||||
android:label="@string/preferences_miband_settings"
|
android:label="@string/preferences_miband_settings"
|
||||||
android:parentActivityName=".activities.SettingsActivity" />
|
android:parentActivityName=".activities.SettingsActivity" />
|
||||||
|
<activity
|
||||||
|
android:name=".devices.zetime.ZeTimePreferenceActivity"
|
||||||
|
android:label="@string/zetime_title_settings"
|
||||||
|
android:parentActivityName=".activities.SettingsActivity" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.ActivitySummariesActivity"
|
android:name=".activities.ActivitySummariesActivity"
|
||||||
android:label="@string/activity_summaries"
|
android:label="@string/activity_summaries"
|
||||||
|
@ -55,6 +55,7 @@ import nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandPreferencesActivity;
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandPreferencesActivity;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.devices.zetime.ZeTimePreferenceActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||||
@ -113,6 +114,15 @@ public class SettingsActivity extends AbstractSettingsActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
pref = findPreference("pref_key_zetime");
|
||||||
|
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
|
Intent enableIntent = new Intent(SettingsActivity.this, ZeTimePreferenceActivity.class);
|
||||||
|
startActivity(enableIntent);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
pref = findPreference("pref_key_blacklist");
|
pref = findPreference("pref_key_blacklist");
|
||||||
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
|
@ -117,4 +117,7 @@ public class ZeTimeConstants {
|
|||||||
|
|
||||||
public static final String PREF_ZETIME_DONT_DEL_ACTDATA = "zetime_dont_del_actdata";
|
public static final String PREF_ZETIME_DONT_DEL_ACTDATA = "zetime_dont_del_actdata";
|
||||||
|
|
||||||
|
public static final String PREF_ZETIME_MAX_HEARTRATE = "alarm_max_heart_rate";
|
||||||
|
public static final String PREF_ZETIME_MIN_HEARTRATE = "alarm_min_heart_rate";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,77 @@
|
|||||||
|
package nodomain.freeyourgadget.gadgetbridge.devices.zetime;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.Preference;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractSettingsActivity;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||||
|
|
||||||
|
public class ZeTimePreferenceActivity extends AbstractSettingsActivity {
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
|
||||||
|
//addTryListeners();
|
||||||
|
|
||||||
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
|
|
||||||
|
final Preference heartrateMeasurementInterval = findPreference("heartrate_measurement_interval");
|
||||||
|
heartrateMeasurementInterval.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
||||||
|
GBApplication.deviceService().onSetHeartRateMeasurementInterval(Integer.parseInt((String) newVal));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
final Preference screenOnDuration = findPreference(ZeTimeConstants.PREF_SCREENTIME);
|
||||||
|
screenOnDuration.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
||||||
|
GBApplication.deviceService().onSendConfiguration(ZeTimeConstants.PREF_SCREENTIME);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
final Preference wearSide = findPreference(ZeTimeConstants.PREF_WRIST);
|
||||||
|
wearSide.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
||||||
|
GBApplication.deviceService().onSendConfiguration(ZeTimeConstants.PREF_WRIST);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// private void addTryListeners() {
|
||||||
|
// for (final NotificationType type : NotificationType.values()) {
|
||||||
|
// String prefKey = "zetime_try_" + type.getGenericType();
|
||||||
|
// final Preference tryPref = findPreference(prefKey);
|
||||||
|
// if (tryPref != null) {
|
||||||
|
// tryPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
|
// @Override
|
||||||
|
// public boolean onPreferenceClick(Preference preference) {
|
||||||
|
// tryVibration(type);
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// } else {
|
||||||
|
// GB.toast(getBaseContext(), "Unable to find preference key: " + prefKey + ", trying the vibration won't work", Toast.LENGTH_LONG, GB.WARN);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// private void tryVibration(NotificationType type) {
|
||||||
|
// NotificationSpec spec = new NotificationSpec();
|
||||||
|
// spec.type = type;
|
||||||
|
// GBApplication.deviceService().onNotification(spec);
|
||||||
|
// }
|
||||||
|
}
|
@ -58,6 +58,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.Weather;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.Transaction;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
@ -126,17 +127,10 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
setWrist(builder);
|
setWrist(builder);
|
||||||
setScreenTime(builder);
|
setScreenTime(builder);
|
||||||
setUserGoals(builder);
|
setUserGoals(builder);
|
||||||
|
setHeartRateLimits(builder);
|
||||||
requestActivityInfo(builder);
|
requestActivityInfo(builder);
|
||||||
synchronizeTime(builder);
|
synchronizeTime(builder);
|
||||||
|
initMusicVolume(builder);
|
||||||
replyMsgToWatch(builder, new byte[]{ZeTimeConstants.CMD_PREAMBLE,
|
|
||||||
ZeTimeConstants.CMD_MUSIC_CONTROL,
|
|
||||||
ZeTimeConstants.CMD_REQUEST_RESPOND,
|
|
||||||
0x02,
|
|
||||||
0x00,
|
|
||||||
0x02,
|
|
||||||
volume,
|
|
||||||
ZeTimeConstants.CMD_END});
|
|
||||||
|
|
||||||
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
|
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
|
||||||
LOG.info("Initialization Done");
|
LOG.info("Initialization Done");
|
||||||
@ -145,14 +139,20 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSendConfiguration(String config) {
|
public void onSendConfiguration(String config) {
|
||||||
switch(config)
|
try {
|
||||||
{
|
TransactionBuilder builder = performInitialized("sendConfiguration");
|
||||||
case ZeTimeConstants.PREF_WRIST:
|
switch(config)
|
||||||
break;
|
{
|
||||||
case ZeTimeConstants.PREF_SCREENTIME:
|
case ZeTimeConstants.PREF_WRIST:
|
||||||
break;
|
setWrist(builder);
|
||||||
case "heartrate_measurement_interval":
|
break;
|
||||||
break;
|
case ZeTimeConstants.PREF_SCREENTIME:
|
||||||
|
setScreenTime(builder);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
builder.queue(getQueue());
|
||||||
|
} catch (IOException e) {
|
||||||
|
GB.toast(getContext(), "Error sending configuration: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1403,4 +1403,34 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
sendMsgToWatch(builder, goal_activeTime);
|
sendMsgToWatch(builder, goal_activeTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setHeartRateLimits(TransactionBuilder builder)
|
||||||
|
{
|
||||||
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
|
|
||||||
|
int maxHR = prefs.getInt(ZeTimeConstants.PREF_ZETIME_MAX_HEARTRATE, 180);
|
||||||
|
int minHR = prefs.getInt(ZeTimeConstants.PREF_ZETIME_MIN_HEARTRATE, 60);
|
||||||
|
|
||||||
|
byte[] heartrateAlarm = {ZeTimeConstants.CMD_PREAMBLE,
|
||||||
|
ZeTimeConstants.CMD_HEARTRATE_ALARM_LIMITS,
|
||||||
|
ZeTimeConstants.CMD_SEND,
|
||||||
|
(byte)0x3,
|
||||||
|
(byte)0x0,
|
||||||
|
(byte)(maxHR & 0xff),
|
||||||
|
(byte)(minHR & 0xff),
|
||||||
|
(byte)0x1, // activate alarm
|
||||||
|
ZeTimeConstants.CMD_END};
|
||||||
|
sendMsgToWatch(builder, heartrateAlarm);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initMusicVolume(TransactionBuilder builder)
|
||||||
|
{
|
||||||
|
replyMsgToWatch(builder, new byte[]{ZeTimeConstants.CMD_PREAMBLE,
|
||||||
|
ZeTimeConstants.CMD_MUSIC_CONTROL,
|
||||||
|
ZeTimeConstants.CMD_REQUEST_RESPOND,
|
||||||
|
0x02,
|
||||||
|
0x00,
|
||||||
|
0x02,
|
||||||
|
volume,
|
||||||
|
ZeTimeConstants.CMD_END});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -578,5 +578,7 @@
|
|||||||
<!-- ZeTime Preferences -->
|
<!-- ZeTime Preferences -->
|
||||||
<string name="zetime_title_settings">ZeTime Einstellungen</string>
|
<string name="zetime_title_settings">ZeTime Einstellungen</string>
|
||||||
<string name="zetime_title_screentime">Bildschirm-An-Dauer in Sekunden</string>
|
<string name="zetime_title_screentime">Bildschirm-An-Dauer in Sekunden</string>
|
||||||
|
<string name="activity_prefs_alarm_max_heart_rate">Max Puls Alarm</string>
|
||||||
|
<string name="activity_prefs_alarm_min_heart_rate">Min Puls Alarm</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -208,6 +208,8 @@
|
|||||||
<!-- ZeTime Preferences -->
|
<!-- ZeTime Preferences -->
|
||||||
<string name="zetime_title_settings">ZeTime settings</string>
|
<string name="zetime_title_settings">ZeTime settings</string>
|
||||||
<string name="zetime_title_screentime">Screen on duration in seconds</string>
|
<string name="zetime_title_screentime">Screen on duration in seconds</string>
|
||||||
|
<string name="activity_prefs_alarm_max_heart_rate">Max heart rate alarm</string>
|
||||||
|
<string name="activity_prefs_alarm_min_heart_rate">Min heart rate alarm</string>
|
||||||
|
|
||||||
<!-- Auto export preferences -->
|
<!-- Auto export preferences -->
|
||||||
<string name="pref_header_auto_export">Auto export</string>
|
<string name="pref_header_auto_export">Auto export</string>
|
||||||
|
@ -750,6 +750,19 @@
|
|||||||
android:key="heartrate_measurement_interval"
|
android:key="heartrate_measurement_interval"
|
||||||
android:summary="%s"
|
android:summary="%s"
|
||||||
android:title="@string/prefs_title_heartrate_measurement_interval" />
|
android:title="@string/prefs_title_heartrate_measurement_interval" />
|
||||||
|
<EditTextPreference
|
||||||
|
android:inputType="number"
|
||||||
|
android:key="alarm_max_heart_rate"
|
||||||
|
android:maxLength="3"
|
||||||
|
android:defaultValue="180"
|
||||||
|
android:title="@string/activity_prefs_alarm_max_heart_rate" />
|
||||||
|
|
||||||
|
<EditTextPreference
|
||||||
|
android:inputType="number"
|
||||||
|
android:key="alarm_min_heart_rate"
|
||||||
|
android:maxLength="3"
|
||||||
|
android:defaultValue="60"
|
||||||
|
android:title="@string/activity_prefs_alarm_min_heart_rate" />
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="zetime_dont_del_actdata"
|
android:key="zetime_dont_del_actdata"
|
||||||
android:title="@string/pref_title_keep_data_on_device"
|
android:title="@string/pref_title_keep_data_on_device"
|
||||||
|
Loading…
Reference in New Issue
Block a user