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);
|
}
|
}
|