wangzhibo
2026-08-30 af6b816e29ebe329c59cfdd368bf41d2a4940946
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.jsbogang.womp.health;
 
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
 
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SwitchCompat;
 
import com.jsbogang.womp.android.R;
import com.jsbogang.womp.ble.AlarmPrefs;
import com.jsbogang.womp.ble.VeepooBleManager;
import com.jsbogang.womp.workbench.UploadPolicy;
import com.jsbogang.womp.workbench.WompKeepAliveService;
 
public class AlarmSettingsActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alarm_settings);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setTitle(R.string.alarm_settings);
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }
 
        SwitchCompat swHr = findViewById(R.id.sw_hr);
        SwitchCompat swBp = findViewById(R.id.sw_bp);
        SwitchCompat swSpo2 = findViewById(R.id.sw_spo2);
        EditText etHrLow = findViewById(R.id.et_hr_low);
        EditText etHrHigh = findViewById(R.id.et_hr_high);
        EditText etBpHigh = findViewById(R.id.et_bp_high);
        EditText etBpLow = findViewById(R.id.et_bp_low);
        EditText etSpo2 = findViewById(R.id.et_spo2_low);
        SwitchCompat swReportAllDay = findViewById(R.id.sw_report_all_day);
        Button save = findViewById(R.id.btn_save);
 
        swHr.setChecked(AlarmPrefs.hrOn(this));
        swBp.setChecked(AlarmPrefs.bpOn(this));
        swSpo2.setChecked(AlarmPrefs.spo2On(this));
        swReportAllDay.setChecked(UploadPolicy.reportAllDay(this));
        etHrLow.setText(String.valueOf(AlarmPrefs.hrLow(this)));
        etHrHigh.setText(String.valueOf(AlarmPrefs.hrHigh(this)));
        etBpHigh.setText(String.valueOf(AlarmPrefs.bpHigh(this)));
        etBpLow.setText(String.valueOf(AlarmPrefs.bpLow(this)));
        etSpo2.setText(String.valueOf(AlarmPrefs.spo2Low(this)));
 
        save.setOnClickListener(v -> {
            try {
                AlarmPrefs.save(this,
                        swHr.isChecked(),
                        parseInt(etHrLow, 50),
                        parseInt(etHrHigh, 140),
                        swBp.isChecked(),
                        parseInt(etBpHigh, 140),
                        parseInt(etBpLow, 60),
                        swSpo2.isChecked(),
                        parseFloat(etSpo2, 90f));
                AlarmPrefs.writeToWatch(this);
                UploadPolicy.setReportAllDay(this, swReportAllDay.isChecked());
                WompKeepAliveService.onAttendanceChanged(this);
                String reportHint = swReportAllDay.isChecked() ? "已改为全天同步" : "仅上班打卡后同步";
                Toast.makeText(this, (VeepooBleManager.get().isReady()
                        ? "已保存并写入手表," : "已保存(手表未连接,下次连接后写入),") + reportHint,
                        Toast.LENGTH_SHORT).show();
                finish();
            } catch (Exception e) {
                Toast.makeText(this, "请填写有效数字", Toast.LENGTH_SHORT).show();
            }
        });
    }
 
    @Override
    public boolean onSupportNavigateUp() {
        finish();
        return true;
    }
 
    private int parseInt(EditText et, int def) {
        String t = et.getText().toString().trim();
        return t.isEmpty() ? def : Integer.parseInt(t);
    }
 
    private float parseFloat(EditText et, float def) {
        String t = et.getText().toString().trim();
        return t.isEmpty() ? def : Float.parseFloat(t);
    }
}