mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Huawei: Stress calibration fixes
This commit is contained in:
+7
-2
@@ -55,10 +55,15 @@ public class HuaweiStressScoreCalculation {
|
||||
|
||||
public static float calibrateScoreFactor(float calibrationScore, float scoreFactor) {
|
||||
calibrationScore = Math.max(40, Math.min(calibrationScore, 70));
|
||||
|
||||
float calibrationScoreFactor = (float) (((calibrationScore - 1) * 7.0) / 98.0);
|
||||
float clampedCalibrationScoreFactor = Math.max(MIN_SCORE, Math.min(calibrationScoreFactor, MAX_SCORE));
|
||||
|
||||
return (float) ((clampedCalibrationScoreFactor * 0.8) + (scoreFactor * 0.2));
|
||||
}
|
||||
|
||||
public static byte calculateLevel(int score) {
|
||||
if (score <= 29) return 1;
|
||||
if (score <= 59) return 2;
|
||||
if (score <= 79) return 3;
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
+27
-2
@@ -57,6 +57,7 @@ public class HuaweiStressCalibrationFragment extends AbstractGBFragment {
|
||||
|
||||
private RelativeLayout layoutResult;
|
||||
private TextView score;
|
||||
private TextView level;
|
||||
private CheckBox isCalibrate;
|
||||
private Slider calibrateSlider;
|
||||
|
||||
@@ -84,16 +85,19 @@ public class HuaweiStressCalibrationFragment extends AbstractGBFragment {
|
||||
|
||||
layoutResult = rootView.findViewById(R.id.huawei_stress_result);
|
||||
score = rootView.findViewById(R.id.huawei_stress_score);
|
||||
level = rootView.findViewById(R.id.huawei_stress_level);
|
||||
isCalibrate = rootView.findViewById(R.id.huawei_stress_calibrate);
|
||||
calibrateSlider = rootView.findViewById(R.id.huawei_stress_calibrate_slider);
|
||||
Button finish = rootView.findViewById(R.id.huawei_stress_calibrate_finish);
|
||||
Button again = rootView.findViewById(R.id.huawei_stress_calibrate_again);
|
||||
|
||||
|
||||
calibrateSlider.setEnabled(false);
|
||||
|
||||
start.setOnClickListener(view -> {
|
||||
start.setVisibility(View.GONE);
|
||||
startCalibration();
|
||||
layoutMeasure.setKeepScreenOn(true);
|
||||
});
|
||||
|
||||
again.setOnClickListener(view -> {
|
||||
@@ -122,6 +126,22 @@ public class HuaweiStressCalibrationFragment extends AbstractGBFragment {
|
||||
countdownTime.setText(formatTime(j));
|
||||
}
|
||||
|
||||
private String getLevelDescription(byte level) {
|
||||
switch (level) {
|
||||
case 1:
|
||||
return getString(R.string.stress_relaxed);
|
||||
case 2:
|
||||
return getString(R.string.stress_mild);
|
||||
case 3:
|
||||
return getString(R.string.stress_moderate);
|
||||
case 4:
|
||||
return getString(R.string.stress_high);
|
||||
default:
|
||||
return getString(R.string.n_a);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void calculateScore() {
|
||||
if(data == null) {
|
||||
return;
|
||||
@@ -137,8 +157,9 @@ public class HuaweiStressCalibrationFragment extends AbstractGBFragment {
|
||||
calibrateSlider.setEnabled(false);
|
||||
data.score = HuaweiStressScoreCalculation.calculateNormalizedFinalScore(data.scoreFactor);
|
||||
}
|
||||
data.level = HuaweiStressScoreCalculation.calculateLevel(data.score);
|
||||
score.setText(String.format(Locale.ROOT, "%02d", data.score));
|
||||
|
||||
level.setText(getLevelDescription(data.level));
|
||||
}
|
||||
|
||||
public HuaweiStressParser.StressData getStressData(final Intent intent) {
|
||||
@@ -164,6 +185,9 @@ public class HuaweiStressCalibrationFragment extends AbstractGBFragment {
|
||||
editor.putBoolean(HuaweiConstants.PREF_HUAWEI_STRESS_SWITCH, true);
|
||||
editor.apply();
|
||||
GBApplication.deviceService(device).onSendConfiguration(HuaweiConstants.PREF_HUAWEI_STRESS_SWITCH);
|
||||
if(getActivity() != null) {
|
||||
getActivity().finish();
|
||||
}
|
||||
}
|
||||
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@@ -181,13 +205,14 @@ public class HuaweiStressCalibrationFragment extends AbstractGBFragment {
|
||||
setProgress(currentCountDownTime);
|
||||
break;
|
||||
case ACTION_STRESS_RESULT:
|
||||
layoutMeasure.setKeepScreenOn(false);
|
||||
boolean isError = intent.getBooleanExtra(EXTRA_STRESS_ERROR, true);
|
||||
if(isError) {
|
||||
setProgress(60000);
|
||||
start.setVisibility(View.VISIBLE);
|
||||
Snackbar.make(layoutMeasure, context.getString(R.string.huawei_stress_calibrate_error), Snackbar.LENGTH_LONG).show();
|
||||
} else {
|
||||
data = getStressData(intent);
|
||||
data = getStressData(intent);
|
||||
layoutMeasure.setVisibility(View.GONE);
|
||||
layoutResult.setVisibility(View.VISIBLE);
|
||||
calculateScore();
|
||||
|
||||
+1
@@ -194,6 +194,7 @@ public class HuaweiStressCalibration {
|
||||
stressData.endTime = endTime;
|
||||
stressData.score = stressScore;
|
||||
stressData.scoreFactor = scoreFactor;
|
||||
stressData.level = HuaweiStressScoreCalculation.calculateLevel(stressScore);
|
||||
|
||||
if (this.callback != null) {
|
||||
callback.onFinish(stressData);
|
||||
|
||||
@@ -65,18 +65,29 @@
|
||||
android:layout_centerInParent="true"
|
||||
android:text="@string/n_a"
|
||||
android:textSize="80sp" />
|
||||
<TextView
|
||||
android:id="@+id/huawei_stress_level"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:text="@string/n_a"
|
||||
android:layout_below="@+id/huawei_stress_score"
|
||||
android:layout_marginTop="20dp"
|
||||
android:textSize="15sp"/>
|
||||
<CheckBox
|
||||
android:id="@+id/huawei_stress_calibrate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/huawei_stress_score"
|
||||
android:layout_below="@+id/huawei_stress_level"
|
||||
android:checked="false"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/huawei_stress_calibrate_adjust_score" />
|
||||
<com.google.android.material.slider.Slider
|
||||
android:id="@+id/huawei_stress_calibrate_slider"
|
||||
android:layout_below="@+id/huawei_stress_calibrate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:labelBehavior="gone"
|
||||
android:valueFrom="40"
|
||||
android:valueTo="70"
|
||||
android:value="55"
|
||||
|
||||
Reference in New Issue
Block a user